How to Run OpenFOAM CFD Simulations in FreeCAD
Setting up computational fluid dynamics (CFD) simulations using OpenFOAM directly within FreeCAD is accomplished via the CfdOF workbench. This workflow bridges FreeCAD's 3D parametric CAD modeling capabilities with OpenFOAM’s powerful numerical solver, handling fluid domain definition, meshing, boundary conditions, solver execution, and post-processing within a unified interface.
Step 1: Install Prerequisites and the CfdOF Workbench
- Install OpenFOAM: Install a compatible version of OpenFOAM (such as OpenFOAM v2012+ or OpenFOAM-dev) on your operating system. Windows users typically install OpenFOAM via Windows Subsystem for Linux (WSL) or Docker.
- Install ParaView: Install ParaView for data visualization and post-processing.
- Install CfdOF in FreeCAD:
- Open FreeCAD.
- Go to Tools > Addon Manager.
- Locate CfdOF in the Workbenches tab and click Install.
- Restart FreeCAD.
Step 2: Configure CfdOF Preferences
- In FreeCAD, switch to the CfdOF workbench from the workbench dropdown.
- Navigate to Edit > Preferences > CFD.
- Under the OpenFOAM tab, specify the installation path for your OpenFOAM installation (or set the execution mode to WSL/Docker if on Windows).
- Verify the executable paths for meshing utilities (such as
cfMeshorsnappyHexMesh) and ParaView. - Click Apply and OK.
Step 3: Prepare the Fluid Domain Geometry
- Model your part or import an existing STEP/IGES file using the Part or Part Design workbench.
- Ensure you are modeling the fluid domain (the space the fluid occupies), not the solid vessel walls, unless performing conjugate heat transfer. If necessary, use boolean operations in the Part workbench to subtract solid objects from a surrounding enclosure box to create the internal or external flow volume.
Step 4: Create a CFD Analysis Container
- Select the fluid domain solid in the tree view.
- Click the CFD Analysis container button on the CfdOF toolbar. This creates an analysis folder containing the physics model, fluid properties, mesh, and boundary conditions.
- Double-click the PhysicsModel object in the tree:
- Select the Time model (Steady or Transient).
- Choose the Flow regime (Incompressible or Compressible).
- Choose the Turbulence model (Laminar, RANS such as \(k\)-\(\omega\) SST, or LES).
- Click OK.
Step 5: Assign Fluid Properties
- Double-click the FluidProperties object in the tree view.
- Select a predefined fluid (such as Air or Water) from the library, or specify custom kinematic viscosity (\(\nu\)) and density (\(\rho\)).
- Click OK.
Step 6: Define Boundary Conditions
For each flow boundary, create a boundary condition:
- Click the CFD Boundary Condition tool.
- Select the relevant face on your 3D model and click Add.
- Choose the boundary type:
- Inlet: Define a uniform velocity (e.g., fixed value along an axis) or volumetric flow rate.
- Outlet: Define a static pressure condition (typically zero gauge pressure).
- Wall: Set no-slip, slip, or moving wall conditions, along with surface roughness if applicable.
- Click OK and repeat for all boundaries in the domain.
Step 7: Generate the Mesh
- Select the fluid geometry and click the CFD Mesh button.
- Select the meshing utility: cfMesh (recommended for beginners) or snappyHexMesh.
- Set the Base Element Size to define the overall mesh resolution.
- (Optional) Add local surface refinements or boundary layers (viscous layers) to accurately capture near-wall shear stresses (\(y^+\)).
- Click Write Mesh, then click Run Mesh. Inspect the output log to confirm clean mesh generation without non-orthogonal or inverted cells.
Step 8: Run the OpenFOAM Solver
- Double-click the CfdSolver object in the tree view.
- Review parallel processing options: set the number of CPU cores for parallel computation.
- Set simulation convergence criteria and iteration limits (e.g., number of time steps or steady-state iterations).
- Click Write Case to generate standard OpenFOAM
directories (
0/,constant/,system/). - Click Run to launch the OpenFOAM solver (e.g.,
simpleFoamfor steady incompressible flow). - Monitor the residual plot directly inside FreeCAD to ensure the simulation converges.
Step 9: Post-Process Results
- Once the solver finishes, click the ParaView button within the solver dialog.
- In ParaView, click Apply in the Properties panel.
- Visualize velocity vectors, pressure contours, and streamlines across slices or internal clip planes to evaluate your fluid dynamics results.