Making FEM run on linux fedora 21

About the development of the FEM module/workbench.

Moderator: bernd

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

Re: Making FEM run on linux fedora 21

Postby bernd » Fri Apr 03, 2015 10:19 am

Thanks. Did not know it's that easy. What I did on Debian Jessie. Download the binary (version 2.8) for Linux from http://www.dhondt.de/ unpack the file make the binary executable and start it in a shell by providing a *.frd result file of CalculiX. :D
Attachments
screen10.jpg
screen10.jpg (72.15 KiB) Viewed 823 times
User avatar
PrzemoF
Posts: 2654
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Making FEM run on linux fedora 21

Postby PrzemoF » Fri Apr 03, 2015 1:23 pm

I'm not getting the colours and left panel is empty in cgx.
User avatar
bernd
Posts: 8439
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Making FEM run on linux fedora 21

Postby bernd » Mon Apr 06, 2015 3:58 pm

PrzemoF wrote:I'm not getting the colours and left panel is empty in cgx.
I get them if I go on "menue datasets --> entitiy --> 4 all" for all displacements. Works on Linux and on Windows. Do you get any erromessage? Ahh and found some cool short introduction in cgx https://mechanicalhacks.wordpress.com/2 ... ts-in-cgx/
User avatar
PrzemoF
Posts: 2654
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Making FEM run on linux fedora 21

Postby PrzemoF » Mon Apr 06, 2015 4:34 pm

Thanks! That works!
stanos4
Posts: 5
Joined: Mon Nov 07, 2016 7:04 am

Re: Making FEM run on linux fedora 21

Postby stanos4 » Sun Nov 13, 2016 11:14 am

Hi all. I've been playing around and got working FEM with calculix on Fedora 24 in both parallel and serial. CalculiX and Spooles are compiled from source and Arpack is installed from the official system repositories. I couldn't get parallel version of CalculiX running but I found this guide http://www.libremechanics.com/?q=node/9 where I got some help (then I realized everything is there :D). Important "improvements" over the guide in the first post:
1) No executable is downloaded from external source - everything is either installed from the official repositories or compiled from the source code
2) Installation can be done in any folder - no need to bring non-managed programs to your /bin or any other system root directories
3) Eventually allows to run CalculiX (FEM) module in parallel - unleash the beast power of your CPU :)

install prerequisites (which of I know about):
arpack, arpack-devel, blas, blas-devel, lapack, lapack-devel, gfortran

Code: Select all

dnf install arpack-devel blas-devel lapack-devel gcc-gfortran
now create your installation directory and change to it in terminal. I will use "$HOME/install/FreeCAD-utils", and since I refer to it in make files we need to export it in terminal:

Code: Select all

mkrid $HOME/install/FreeCAD-utils
export FCAD_UTIL=$HOME/install/FreeCAD-utils
cd $FCAD_UTIL
Spooles:
download and extract Spooles:

Code: Select all

mkdir spooles
cd spooles
wget http://www.netlib.org/linalg/spooles/spooles.2.2.tgz
tar xf spooles.2.2.tgz
now we need to make some changes to the "Make.inc" makefile:
- look for all lines that begin with "CC=" and comment them with "#" if they are not (it was only line 15 for me). Then uncomment/create variable "CC=gcc", (optionally) uncomment line 33 or 34 to let compiler better optimize the code and build library:

Code: Select all

CC=gcc
#CC=/usr/lang-4.0/bin/cc
OPTLEVEL = -O3

Code: Select all

make -j4 lib
Spooles in parallel:
- go to the directory MT/src and run make:

Code: Select all

cd $FCAD_UTIL/spooles/MT/src
make
CalculiX
that was the easier part, now comes the CalculiX build process. Create new directory, download and extract CalculiX

Code: Select all

cd $FCAD_UTIL
wget http://www.dhondt.de/ccx_2.11.src.tar.bz2
tar xf ccx_2.11.src.tar.bz2
cd CalculiX/ccx_2.11/src/
Serial version
-change "Makefile" (possibly one of the other makefiles that you'd like to use):
- change variable "CFLAGS" point to the path of the Spooles that we just built
- change variable "DIR" to point to the correct Spooles directory
- change the variable "LIBS" to following

Code: Select all

CFLAGS = -Wall -O3 -fopenmp -I $FCAD_UTIL/spooles -DARCH="Linux" -DSPOOLES -DARPACK -DMATRIXSTORAGE -DNETWORKOUT
DIR=$FCAD_UTIL/spooles
LIBS = $(DIR)/spooles.a -larpack -llapack -lpthread -lm -lc
- change line starting with "./date.pl" (make sure that the blank space at the beginning of line is single "tab" not two spaces):

Code: Select all

#  ./date.pl; $(CC) $(CFLAGS) -c ccx_2.11.c; $(FC) -fopenmp -Wall -O3 -o $@ $(OCCXMAIN) ccx_2.11.a $(LIBS)
  ./date.pl; $(CC) $(CFLAGS) -lgfortran -c ccx_2.11.c; $(FC) -fopenmp -Wall -O3 -o $@ $(OCCXMAIN) ccx_2.11.a $(LIBS) -lgfortran
and build it:

Code: Select all

make -j4
Parallel version
modify the same lines as in the serial version to following:

Code: Select all

CFLAGS = -Wall -O3 -fopenmp -I $(FCAD_UTIL)/spooles -DARCH="Linux" -DSPOOLES -DARPACK -DMATRIXSTORAGE -DUSE_MT=1
DIR=$(FCAD_UTIL)/spooles
LIBS = $(DIR)/MT/src/spoolesMT.a $(DIR)/spooles.a -larpack -llapack -lpthread -lm -lc
  ./date.pl; $(CC) $(CFLAGS) -c ccx_2.11.c; $(FC) -fopenmp -Wall -O3 -o $@ $(OCCXMAIN) ccx_2.11.a $(LIBS) -lgfortran
and build it:

Code: Select all

make -j4
This creates "ccx_2.11" executable that is needed by the FreeCAD. Few more steps are needed to make it available to FreeCAD. At first, your "PATH" environment variable needs to be modified so that the system knows where it can find the new executable. This can be done in several ways, but since we want it to be persistent and available to all programs (not only those started from the terminal) we need to change it in the "$HOME/.bash_profile" file. In my case, I created a "$HOME/install/bin" directory where I store all the executables that I prepare myself. Therefore, I add the following line to the ".bash_profile":

Code: Select all

export PATH=$PATH:$HOME/install/bin
Then you need to copy the the "ccx_2.11" executable file to that directory. Also, it must be renamed to "ccx" so that the FreeCAD can recognize it.

Code: Select all

cp $FCAD_UTIL/CalculiX/ccx_2.11/src/ccx_2.11 $HOME/install/bin/ccx
Now you need to log out and log in to apply changes in the ".bash_profile".

Basically, that's it. However, FreeCAD is not prepared to start CalculiX in parallel when it is not started from the command line. To make it run in parallel open terminal and type:

Code: Select all

export OMP_NUM_THREADS=4
where 4 can be replaced by any number of threads (cores) that you want to use. Now, in the same terminal run FreeCAD with:

Code: Select all

FreeCAD

Changes to the FreeCAD source - not recommended
If you don't like starting FreeCAD from the terminal and you're too lazy to wait for the official changes in the source, you can do it yourself. Go the the "/usr/lib64/freecad/Mod/Fem" and change "_TaskPanelFemSolverCalculix.py" file (this requires administrator privileges:
- find "def runCalculix(self):" method and add the following lines before the "self.Calculix.start(self.CalculixBinary, ['-i', fi.baseName()])" line:

Code: Select all

        from multiprocessing import cpu_count
        omp_num_threads = self.fem_prefs.GetInt("NumThreads", cpu_count())
        env = QtCore.QProcessEnvironment.systemEnvironment()
        env.insert("OMP_NUM_THREADS", str(omp_num_threads))
        self.Calculix.setProcessEnvironment(env)
Save changes and exit. FreeCAD will now use all of your available cores for the CalculiX call. If you want to change it start FreeCAD (you can start it normally now, no need to use terminal). From the top panel select "Tools -> Edit parameters ...". New window "Parameter Editor" with left and right panel appears. In the left tree-panel go the the "Preferences -> Mod -> Fem". Variables corresponding to the "FEM" modules are now shown, so for example, there is variable "ccxBinaryPath" ("T" in front of it is not part of the variable name, but symbolizes that it is Text variable) with value that should point to the "ccx" binary that we just built. If you now right-click anywhere, you can select "New -> New integer item" - do it. Into the "Enter the name" enter "NumThreads" and for "Enter your number" you specify the number of cores you want to use. Voila.
cpme
Posts: 1
Joined: Mon Dec 10, 2018 5:44 am

Re: Making FEM run on linux fedora 21

Postby cpme » Mon Dec 10, 2018 6:10 am

I can confirm this process (parallel) worked in Fedora 29 (granted with ccx.2.14). Multithreading does not appear to be working for gmsh or Calculix, so I'll have to keep digging into that. So far for very fine meshes I have received this error:

Code: Select all

CalculiX failed ccx finished with error -9
I will share if I find a fix for either of these issues.