Skip to content

Add mean velocity force GUI support#244

Open
kevinsmia1939 wants to merge 2 commits intojaheyns:masterfrom
kevinsmia1939:add_meanvelocityforce
Open

Add mean velocity force GUI support#244
kevinsmia1939 wants to merge 2 commits intojaheyns:masterfrom
kevinsmia1939:add_meanvelocityforce

Conversation

@kevinsmia1939
Copy link
Contributor

@kevinsmia1939 kevinsmia1939 commented Mar 9, 2026

This PR introduce initial implementation of adding meanVelocityForce into fvOptions. The new option is meanVelocityForce which apply constant mean velocity.
The example usage of meanvelocityforce is to impose a flow where there is no inlet boundary, in this example, a periodic boundaries are use, since imposing flow on periodic boundary is not allowed.
test4.FCStd.txt

This is the generated fvOptions inside case/constant

/*--------------------------------*- C++ -*----------------------------------*\
|                                                                             |
|                Generated by the CfdOF workbench for FreeCAD                 |
|                      https://github.com/jaheyns/CfdOF                       |
|                                                                             |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


momentumSource
{
    type            meanVelocityForce;
    selectionMode   all;
    active          yes;
    meanVelocityForceCoeffs
    {
        selectionMode   all;
        fields          (U);
        direction       (1.0 0.0 0.0);
        Ubar            (0.05 0.0 0.0);
        relaxation      0.2;
    }
}

//************************************************************************ //

Current implementation has limitations:
Only constant velocity
selectionMode set to all, future work can support cellZone

Things that I noticed. Data/Templates/case/constant/fvOptions has settings for porousZones but if porous zones were added, the file porosityProperties will be generated instead of the one in fvOptions, is this the same thing?

There was also fvOptions_OF10 inside Data/Templates/case/Allrun for scalar transport, this might conflict, we might need to unify them in the future.

%}
%{%(scalarTransportFunctionsEnabled%)
%:True
# Enable fvOption source for scalar transport in OpenFOAM v10+
if [ -z ${FOAM_API+x} ] && [ "$WM_PROJECT_VERSION" -ge 10 ]
then
    cp system/fvOptions_OF10 system/fvOptions
fi

Note that majority of the code was generated with OpenAI Codex since I am not so familar with the code here. I practice my due diligence and test this new feature to validate the code.
Screenshot_20260309_215138
Screenshot_20260309_215121
Screenshot_20260309_223141

There are test that failed, but it look like you tried to fix it in the previous commit, not sure why it fail again.

Comparing /home/kevin/.local/share/FreeCAD/Mod/CfdOF/Data/TestFiles/cases/Propeller/meshCase/pvScriptMesh.py to /tmp/meshCasePropeller/./pvScriptMesh.py 
Comparing /home/kevin/.local/share/FreeCAD/Mod/CfdOF/Data/TestFiles/cases/Propeller/meshCase/constant/triSurface/Cut_Geometry.stl to /tmp/meshCasePropeller/constant/triSurface/Cut_Geometry.stl 
FAILED: test_run (TestCfdOF.PropellerTest.test_run)
Traceback (most recent call last):
  File "/tmp/.mount_FreeCAkhNhoJ/usr/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/tmp/.mount_FreeCAkhNhoJ/usr/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/tmp/.mount_FreeCAkhNhoJ/usr/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/home/kevin/.local/share/FreeCAD/Mod/CfdOF/./TestCfdOF.py", line 467, in test_run
    self.runTest(self.__class__.__dir_name, self.__class__.__macros)
  File "/home/kevin/.local/share/FreeCAD/Mod/CfdOF/./TestCfdOF.py", line 324, in runTest
    comparePaths(mesh_ref_dir, mesh_case_dir, self.child_instance)
  File "/home/kevin/.local/share/FreeCAD/Mod/CfdOF/./TestCfdOF.py", line 515, in comparePaths
    unit_test.assertFalse(ret, "File \'{}\' test failed.\n{}".format(file, ret))
AssertionError: 'Comparing /home/kevin/.local/share/FreeCAD/Mod/CfdOF/Data/TestFiles/cases/Propeller/meshCase/constant/triSurface/Cut_Geometry.stl to /tmp/meshCasePropeller/constant/triSurface/Cut_Geometry.stl failed!

@oliveroxtoby
Copy link
Collaborator

Thank you, this looks good! I'll just look into your queries and get back to you.

@oliveroxtoby
Copy link
Collaborator

oliveroxtoby commented Mar 13, 2026

Things that I noticed. Data/Templates/case/constant/fvOptions has settings for porousZones but if porous zones were added, the file porosityProperties will be generated instead of the one in fvOptions, is this the same thing?

porosityProperties is used and generated for the porousSimpleFoam solver (if the flow is incompressible/steady-state) and fvOptions is used for the other solvers.

There was also fvOptions_OF10 inside Data/Templates/case/Allrun for scalar transport, this might conflict, we might need to unify them in the future.

You're right. I have unified these two, so that we only have a single fvOptions in system/. Please could you update your code accordingly?

There are test that failed, but it look like you tried to fix it in the previous commit, not sure why it fail again.

This is probably a minor difference caused by different versions of FreeCAD or OpenCascade or similar. I'll investigate at some point, but for now we can ignore this.

If you feel like making your test case into a macro and adding it to the CfdOF tests, that would be really helpful, since at the moment we don't have any test coverage for the periodic boundaries (or this new mean velocity force).

@kevinsmia1939 kevinsmia1939 force-pushed the add_meanvelocityforce branch 3 times, most recently from 34497aa to 207188b Compare March 14, 2026 00:56
@kevinsmia1939
Copy link
Contributor Author

Hi, I incorporated your changes, verify that codes works and test pass (other than that propeller test). I will be adding test to periodic boundary and mean velocity force in the next PR.

@kevinsmia1939 kevinsmia1939 force-pushed the add_meanvelocityforce branch 2 times, most recently from 124d822 to 39f03c2 Compare March 14, 2026 20:40
oliveroxtoby and others added 2 commits March 14, 2026 21:54
Add mean velocity force GUI support

fix ui

incorporate changes

fix ui

fix icon

initial periodic test

initial periodic test

remove unuse file

add screenshot

add screenshot

add screenshot

add screenshot
@kevinsmia1939 kevinsmia1939 force-pushed the add_meanvelocityforce branch from d81f6d6 to 5a237b2 Compare March 14, 2026 20:55
@kevinsmia1939
Copy link
Contributor Author

I add test case, but it is a simple test that compare the case file output and known good value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants