Test request: OpenFOAM solver for FemWorkbench

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by makkemal »

@qingfeng.xia please try: bash -i -c "echo $WM_PROJECT_VERSION" in your terminal.

Code: Select all

makke@ubuntu:~/freecad$ bash -i -c "echo $WM_PROJECT_VERSION"
4.0
makke@ubuntu:~/freecad$ 
Updated snippti does not change things.

Code: Select all

OS: Ubuntu 16.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.8378 (Git)
Build type: Unknown
Branch: foam/foambuilder1,origin/rtd_hindlemp
Hash: 1024ed5f777c0cf18a3186e2aaac271c1023e5e7
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by bernd »

I have been browsing your code. Correct me if I'm wrong. You are not integrating in FEM module of FreeCAD at all. All your CFD is like an own module inside the FEM module, like a parallel world of FEM in FEM module. Why would you like it to see it inside the FEM module?

Have you ever been thinking of making an own CFD module. From an own module you could still access all Fem objects. You could still add the constraint objects to the FEM module code because they are based on FEM constraints. But the whole Workflow of writing CFD input file running the solver and reading the input files would be in CFD module. With this you are totally independent from FEM module. Since your code does not integrate and does not use any of FEM python modules it could makes sense.

I do not know if it make sense to have multiple module workflows in one module?!

May be some more opinions of FreeCAD cracks are needed?!

cheers bernd
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by qingfeng.xia »

makkemal wrote:
@qingfeng.xia please try: bash -i -c "echo $WM_PROJECT_VERSION" in your terminal.

Code: Select all

makke@ubuntu:~/freecad$ bash -i -c "echo $WM_PROJECT_VERSION"
4.0
makke@ubuntu:~/freecad$ 
I mean try this snippet:

Code: Select all

def _detectFoamVersion():
    return _DEFAULT_FOAM_VERSION
Also, I tried both python3 and python2 on the following, it seems subprocess output differently

Code: Select all

from __future__ import print_function

import subprocess
_DEFAULT_FOAM_VERSION = (4,0,0)

#https://docs.python.org/2/library/subprocess.html
def _detectFoamVersion():
    #foam_ver = subprocess.check_output('bash -i -c "echo $WM_PROJECT_VERSION"')
    proc = subprocess.Popen('bash -i -c "echo $WM_PROJECT_VERSION"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    (foam_ver, err) = proc.communicate()
    if foam_ver: print("stdout:", foam_ver)
    if err: print("stderror:", err)
    if foam_ver:
        print("echo output:", foam_ver)
        return tuple([int(s) for s in str(foam_ver).split('.')])
    else:
        print("""environment var 'WM_PROJECT_VERSION' is not defined,
              fallback to default {}""".format(_DEFAULT_FOAM_VERSION))
        return _DEFAULT_FOAM_VERSION

print(_detectFoamVersion())


python3 return
b'4.0\n'
python2 return:
4.0
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by qingfeng.xia »

bernd wrote:I have been browsing your code. Correct me if I'm wrong. You are not integrating in FEM module of FreeCAD at all. All your CFD is like an own module inside the FEM module, like a parallel world of FEM in FEM module. Why would you like it to see it inside the FEM module?

Have you ever been thinking of making an own CFD module. From an own module you could still access all Fem objects. You could still add the constraint objects to the FEM module code because they are based on FEM constraints. But the whole Workflow of writing CFD input file running the solver and reading the input files would be in CFD module. With this you are totally independent from FEM module. Since your code does not integrate and does not use any of FEM python modules it could makes sense.

I do not know if it make sense to have multiple module workflows in one module?!

May be some more opinions of FreeCAD cracks are needed?!

cheers bernd
Yes, CFD is parallel with FEM in python level, but cpp code are shared. I may have some special requirement on meshing. They are of different physical domain, in the future we could dome some FEM and CFD coupling analysis. I may also need to share post-processing by VTK.

To make an independent CFD module could be possible, actually puting CFD function in FEM workbench, sounds a bit misleading. However, I am not sure it is worth of splitting, only a few python files. I will wait and see more suggestion.

Thanks
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
User avatar
makkemal
Posts: 395
Joined: Wed Apr 29, 2015 12:41 pm
Location: South Africa
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by makkemal »

Code: Select all

def _detectFoamVersion():
    return _DEFAULT_FOAM_VERSION
This does work.
I have to start the simpleFoam command manually in the command line.

Code: Select all

simpleFoam -case /tmp//TestCase > /tmp//TestCase/log.simpleFoam
How do I view results in paraview ?
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Test request: OpenFOAM solver for FemWorkbench

Post by sgrogan »

qingfeng.xia wrote:I do not know if it make sense to have multiple module workflows in one module?!

May be some more opinions of FreeCAD cracks are needed?!
I vote for more modular is more better.
Now it seems not to matter, but in the future if the dependencies diverge it would be beneficial to tweak the build. Since the SMESH upgrade, everyone here knows my problems with Netgen on Win, but there are also issues with VTK and libmedC-dev on some Linux distros that extend beyond FEM into the Mesh WB, that effects the 3D printing crowd.
I'm not a developer, only a package manager, but the more independent the better. If CFD is split now FEM would be a dependency of CFD, ideally they could share a computational engine and a post processing engine.
All that said, FreeCAD's computational ability is great. In most solvers the geometry portion is an after thought, which makes it hard for the user. FreeCAD is much simpler for the user.
Keep up the great work :D
"fight the good fight"
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by qingfeng.xia »

makkemal wrote:

Code: Select all

def _detectFoamVersion():
    return _DEFAULT_FOAM_VERSION
This does work.
I have to start the simpleFoam command manually in the command line.

Code: Select all

simpleFoam -case /tmp//TestCase > /tmp//TestCase/log.simpleFoam
How do I view results in paraview ?

Great to hear that, start in new terminal since CFD takes ages to converge, several days is common for us.
May be QProcess instead Popen, to get the solver exit signal , could be a better choice, I will look at QProcess, to see if that is portable to Qt5 and Python3.

Code: Select all

 paraFoam -case /tmp/TestCase 
If you are familar with paraview, you can build up the pipe line, paraview is not quite straight-forwards.
I am think about writing @CfdResultObject.py@ and CfdReaderVTK.py to show Temperature, Pressure and Velocity using current facility in FEM.
Last edited by qingfeng.xia on Thu Sep 08, 2016 8:40 am, edited 1 time in total.
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by qingfeng.xia »

sgrogan wrote:
qingfeng.xia wrote:I do not know if it make sense to have multiple module workflows in one module?!

May be some more opinions of FreeCAD cracks are needed?!
I vote for more modular is more better.
Now it seems not to matter, but in the future if the dependencies diverge it would be beneficial to tweak the build. Since the SMESH upgrade, everyone here knows my problems with Netgen on Win, but there are also issues with VTK and libmedC-dev on some Linux distros that extend beyond FEM into the Mesh WB, that effects the 3D printing crowd.
I'm not a developer, only a package manager, but the more independent the better. If CFD is split now FEM would be a dependency of CFD, ideally they could share a computational engine and a post processing engine.
All that said, FreeCAD's computational ability is great. In most solvers the geometry portion is an after thought, which makes it hard for the user. FreeCAD is much simpler for the user.
Keep up the great work :D

Yes, they will share meshing render and post-processing. I list the possible route for split, please correct me.

1. Do you means create a CFD workbench? , that sounds challenging to me, I am not sure how to create Gui/Resource part, maybe I leave the icon still in Fem module (not sure as we did not specify icon path, but icon name),

2. then CMakeLists.txt, Init.py and InitGui.py should be make a pure python module?

3 . If I need the post-processing and creat-meshing command, can I just import from "_CommandFemMesh.py" or I must copy into new module?

4. I think I need a SelectionObserver python class.

5. To add new command MenuItem/ToolbarItem to workbench, I need to add into Fem/Gui/Workbench.cpp. Is that possible to add into InitGui.py now? Or I should make Cfd/Gui/ cpp files.

6. python ViewProvider file needs renaming, Fem->Cfd

more...

Thanks very much
Ubuntu 18.04 LTS 64bit, python3, always work with latest FreeCAD daily build
Working on Cfd module for FreeCAD, FreeCAD_Module_Develop_Guide
https://github.com/ukaea/parallel-preprocessor/
https://github.com/qingfengxia/Cfd
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by bernd »

qingfeng.xia wrote: 1. Do you means create a CFD workbench? , that sounds challenging to me, I am not sure how to create Gui/Resource part, maybe I leave the icon still in Fem module (not sure as we did not specify icon path, but icon name),

2. then CMakeLists.txt, Init.py and InitGui.py should be make a pure python module?
You could start the new workbench not in FreeCAD src but in your ./FreeCAD Mod directory in your home directory.With this you need just a few files to start. See https://github.com/berndhahnebach/FreeC ... aster/MyWB for my simple template for a new workbench in Mod directory of your ./FreeCAD folder in your home directory. It has just two simple tools. With this there is no Cmake needed, because no installation is needed.
Later if you would like to go for a PullRequest to integrate it in FreeCAD source you could add the Cmake stuff.

qingfeng.xia wrote:3 . If I need the post-processing and creat-meshing command, can I just import from "_CommandFemMesh.py" or I must copy into new module?
You can use any module and any object from any module in any other module. It just need to be available and of couse you need to import the module.

qingfeng.xia wrote:4. I think I need a SelectionObserver python class.
I have one small just for FEM you could import it. Arch has an own python selection observer class. Assambly2 has one too.

qingfeng.xia wrote:5. To add new command MenuItem/ToolbarItem to workbench, I need to add into Fem/Gui/Workbench.cpp. Is that possible to add into InitGui.py now? Or I should make Cfd/Gui/ cpp files.
Yes you could just add it to InitGui.py See my small template.

There are dozens of modules around which are installed in your user Mod. You could have a look at the code if you need something. One of the best is lattice2. I truelly can recomend installing it.

bernd
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Test request: OpenFOAM solver for FemWorkbench

Post by bernd »

sgrogan wrote:
May be some more opinions of FreeCAD cracks are needed?!
I vote for more modular is more better. ... I'm not a developer, only a package manager, but the more independent the better. If CFD is split now FEM would be a dependency of CFD, ideally they could share a computational engine and a post processing engine.
Good point, if CFD is integrated in FEM, FEM relies on CFD, means more depencies.
Post Reply