Please review and test the refactoring work on FEM (merged with latest master)

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by bernd »

sgrogan wrote:
bernd wrote:Fem test is fine for my branch
Are you sure that for instance MechanicalAnalysis.py isn't in the build directory, left over from a previous build?
I will directly build your branch. Thanks for looking.
Man this FEM moves fast! Thanks for all you guys coding, it makes it very interesting to follow :ugeek:
you are right. Yeah you where right. On clean build the FEM Test fails ...

Code: Select all

Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Test/qtunittest.py", line 82, in runClicked
    test = unittest.defaultTestLoader.loadTestsFromName(testName)
  File "/usr/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Fem/TestFem.py", line 30, in <module>
    import MechanicalAnalysis
ImportError: No module named MechanicalAnalysis
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by bernd »

TestFem was not fixed by qingfeng, that is why it is broken. OK I can make an CalculiX analysis and it gives correct results.

Right click to activate an analysis is broken. Double click on an analysis I get an error message

Code: Select all

Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Fem/CaeAnalysis.py", line 107, in getIcon
    return self.icon
<type 'exceptions.AttributeError'>: ViewProviderCaeAnalysis instance has no attribute 'icon'
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Fem/CaeAnalysis.py", line 124, in doubleClicked
    if not FemGui.getActiveAnalysis() == self.Object:
<type 'exceptions.NameError'>: global name 'FemGui' is not defined
@qingfeng:
Why is the CalculiX solver object outside of CaculixAnalysis? My understanding would be the CalculiX solver object should be inside the CalculiAnalysis. We could have OpenFoam and CalcuiX Analysis in one Document.
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by qingfeng.xia »

Thanks for help.

I am not aware FemTest, is that in Test Module? there is API change, makeMechanicalAnalysis -> makeCaeAnalysis. to accomendate CAE picture, although C++ kernel will still named as Fem::

Solver should go into Analysis, but Mesh will not, I correct some naming in last night commit. Also correct one bug, old *.py was still referred. In my PC it is working without deprecated py.

Currently, One solver one mesh on one Analysis. You can make more Analyses, like Fluid mech coupling in the future.
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: Please review and test the refactoring work on FEM (step to CFD functions)

Post by bernd »

bernd wrote: @qingfeng:
Why is the CalculiX solver object outside of CaculixAnalysis? My understanding would be the CalculiX solver object should be inside the CalculiAnalysis. We could have OpenFoam and CalcuiX Analysis in one Document.
Found it. The Solverobject should be added to the Analysis. It is just a bug in CalculiXAnalysis.

made another few fixes or better hacks to get the code running see obove ... https://github.com/berndhahnebach/FreeC ... amsolver01

It is now possible to add one CalculiX Analysis and the CalculiX solver object is added to Calculix Analysis. Calculix Calculation could be made with this Analysis the way we already do it in FEM. But if second Analysis object is added again some error occurs in shell.

Code: Select all

Running the Python command 'Fem_NewMechanicalAnalysis' failed:
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Fem/CaeAnalysis.py", line 193, in Activated
    _CreateCaeAnalysis('Calculix')
  File "/home/hugo/Documents/dev/freecad/freecadbhb_przemo/build/Mod/Fem/CaeAnalysis.py", line 150, in _CreateCaeAnalysis
    FreeCADGui.doCommand("CaeSolver.makeCaeSolver('{}')".format(solverName))
  File "<string>", line 1, in <module>

class CaeSolver has no attribute 'makeCaeSolver'
I really appreciate the work you have done and I would like to see this stuff in FreeCAD but how should the code be tested and reviewed if the code does not run?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by bernd »

CrossPost
qingfeng.xia wrote:I am not aware FemTest, is that in Test Module?
yes See Module src/Mod/Fem/TestFem.py it should be self-explanatory what happens.

To run the test change to WorkBench TestFramwork, click on Self-test, in combobox only select TestFem and click on Start. But would you fix the CAEAnalysisObject Errors first. They are essential to test your code.
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by qingfeng.xia »

FemTest.py has been fixed , thanks.

One CFD and One FEM is possible and tested.

I have not tried at adding 2nd analysis, yes, I found error too. Just wonder why the error does not come out at the first analysis.
This command still import "MechanicalAnalysis" comment it out, I can get the second Analysis.

I just realised, why FemTools needs to be new each time it is called. Once I save and reload, all my Python saved to obj.Proxy lost.

I may need to play same trick to make CfdTools, or using singleton model, or create it at the first time accessed.

==================
CFD + FEM works and also works on reload saved file.
but let me to compile it on diff PC, to make the github is same with my local PC.
I did not use "git commit -a -m " to commit in last several commit. What a shame, I suspect this introduce a lot of bugs as some newly modified existent files are not update. I just "git add . --all" once long ago, and add newly created file one by one.
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: Please review and test the refactoring work on FEM (step to CFD functions)

Post by bernd »

https://github.com/qingfengxia/FreeCAD/ ... foamsolver latest commit a5e29e "using git commit -a to make sure all modified files are commit"
does not compile on my debian jessie:

Code: Select all

 82%] Built target InspectionGui
[ 83%] Built target Arch
make[2]: *** No rule to make target '../src/Mod/Fem/MechanicalAnalysis.ui', needed by 'Mod/Fem/MechanicalAnalysis.ui'.  Schluss.
CMakeFiles/Makefile2:3506: recipe for target 'src/Mod/Fem/App/CMakeFiles/Fem.dir/all' failed
make[1]: *** [src/Mod/Fem/App/CMakeFiles/Fem.dir/all] Error 2
Makefile:117: recipe for target 'all' failed
make: *** [all] Error 2
seams some cmakestuff regarding MechanicalAnalysis.ui
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Please review and test the refactoring work on FEM (step to CFD functions)

Post by qingfeng.xia »

thanks bernd,

I found the error, by testing on another PC

===============================

1) I am not aware the Fem/App/CMakeList.txt also keep a list of py files.

SET(FemScripts_SRCS

which I think Fem/CMakeList.txt should do

2) multiple analysis , is possible with careful operation, I tests 1 cfd and 2 fem. I just can not attach screenshot on this thread.

select the new geometry and add new mesh and then new analysis.
double click to activate one Analysis and then click toolbar show result

3) UnitTest failed at comparing inp file, but this /tmp/FEM_static/Mesh.inp file is good to solve

Comparing /home/qingfeng/FreeCAD/build/Mod/Fem/test_files/cube_static.inp to /tmp/FEM_static/Mesh.inp

4) test without make install may fail to load python commands, I tested after make install, or do another copy all
GUI paste example is working.

================================

As my new PC can not set output debug info from "prefereence", so I just can not locate the error. Generally. It is fine now.


==== diff of my fork and official master cube-static.inp ==

470c470
< *NSET,NSET=FemConstraintForce
---
> ** no point load on vertices --> no set for node loads
507d506
< ** FemConstraintForce
509c508,509
< ** node loads on element face: Box.Face2
---
> ** FemConstraintForce
> ** node loads on element Face: Box:Face2
596,597c596,597
< ** written by --> FreeCAD 0.16.5604 (Git)
< ** written on --> Mon Sep 21 16:46:15 2015
---
> ** written by --> FreeCAD 0.16.5838 +1 (Git)
> ** written on --> Mon Oct 26 18:28:42 2015

============================================
it seems only the cube_static.inp generator can pass the unittest.
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
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Please review and test the refactoring work on FEM (merged with latest master)

Post by PrzemoF »

@qingfeng.xia: I want to help you with the code, but I ask for something in return.

1. Try to split your code into small commits. Adding test files -> separate commit. Adding icons -> separate commit. Renaming a_funcion into b_function -> separate commit. Renaming file -> separate commit. "git reset" and "git add -p" are really good for it.
2. Please use good commit messages. "using git commit -a to make sure all modified files are commit" is great in your personal repository, but for me it's _wrong_ if I have to do anything with that commit. I tried to split your code into small logical chunks and I had to start with squashing all your changes into one big commit because of that type of commits.
3. Adding comments like in your personal repo is OK, but for a reviewer it's just a distraction

Code: Select all

-        def IsActive(self):
+        def IsActive(self): # bad naming, need reconsidering
4. There are a lot of that kind of functions in the code:

Code: Select all

      def write_solver_control(self):
          pass
It's not any good for the person reviewing the code. Just skip the function completely including the call of the function. Add a comment that something should be added in the future, but do not add a mock function.
5. Please use file name corresponding the python class name.

Code: Select all

$ grep "class.*:" src/Mod/Fem/ccxFemSolver.py 
class CaeSolver():
class ViewProviderCaeSolver:
class _SolverControlTaskPanel:
fedora:/home/przemo/software/FreeCAD/freecad
$ grep "class.*:" src/Mod/Fem/CaeSolver.py 
class _CommandNewCaeSolver:
File CaeSolver doesn't contain CaeSolver class, but CaeSolver class is defined in ccxFemSolver.py?
6. flake8 throws syntax error on src/Mod/Fem/FoamCaseWriter.py in line 73. Please make sure that the code is correct at the minimum.
7. Merging master on top of your changes doesn't help with anything. Please use "git rebase master" on you feature branch (master is the FreeCAD master for me)
qingfeng.xia
Posts: 227
Joined: Tue Sep 22, 2015 1:47 pm
Location: Oxford UK/Shenzhen China
Contact:

Re: Please review and test the refactoring work on FEM (merged with latest master)

Post by qingfeng.xia »

@PrzemoP: Thanks very much for testing.

First of all, is my fork compiling without error?

I can do all your to-do list, except for the first. It may take several days to do it from scratch for my current git level and I have run out all my annual leave to do this task. I can provide a detailed changelog (which can also provide kind of roadmap manual for CAE funtionally). Some commit is not logical/compilable due to I have not got the whole picture of compiling system at that time. The time saving way to do the work will be squash, I did not know how to squash. Basically, all my work can be squashed into 3:

Adding FemSolver -> OpenFoam skeleton and all other Cae* functions, until the commit "test passed on a new PC" + "apply PeP8", it is then a compilable commit -> merged the master change on Oct 30

maybe another clean up of comments and immature code before pull request. maybe on another fork called "foamsolverclean"

==============
CaeSolver, should define Abstract class CaeSolver. I plan to apply a factory pattern just and make/create concrete solver from registered solver module and string solver name, as it is Python there is no need declare a class doing nothing.

For Pep8, Bernd give me a command line to check, Thanks Bernd. I found there are a lot warnings in FemExample.py and CfdExample.py, should I make it into macro instead to suppress warning. Or just leave it, as convert2TetGen.py, which throws a lot warning, due to it is of diff characteristiss/source

Thanks very much for your help.
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
Post Reply