CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   What's the Eigen library setup for OpenFOAM? (https://www.cfd-online.com/Forums/openfoam-programming-development/253439-whats-eigen-library-setup-openfoam.html)

klausb December 10, 2023 09:18

What's the Eigen library setup for OpenFOAM?
 
I want to use the Eigen header file library in an OpenFOAM preconditioner but I keep getting compiler errors telling me, that Eigen is not found.

Eigen is "installed" i.e. header files are located in the directory: /home/klaus/Programme/eigen-3.4.0/Eigen

I added the Eigen3_ROOT to the .bashrc and rebooted as shown below

Code:

# set Eigen3_ROOT
export Eigen3_ROOT=/home/klaus/Programme/eigen-3.4.0

I added
Code:

#include <Eigen/Sparse>
at the top of the source code

Online instructions tell me to add
Code:

EXTERNAL_LIBS += -lEigen3
to the Make/options file, I tried but I keep getting the same error:

Code:

MYPreconditioner.C:32:10: Fatal error: Eigen/: File or directory not found
  32 | #include <Eigen/Sparse>

| ^~~~~~~~~~~~~~


Eigen can be found at:
HTML Code:

https://eigen.tuxfamily.org/index.php?title=Main_Page
What's the setup needed to be able to use Eigen within OpenFOAM?

E.g. how to adjust the Make/options file:

Code:

EXE_INC = \
    -I$(OBJECTS_DIR)

LIB_LIBS = \
    $(FOAM_LIBBIN)/libOSspecific.o

ifeq (libo,$(FOAM_LINK_DUMMY_PSTREAM))
    LIB_LIBS += $(FOAM_LIBBIN)/dummy/libPstream.o
else
    LIB_LIBS += -L$(FOAM_LIBBIN)/dummy -lPstream
endif

/* libz */
EXE_INC += -DHAVE_LIBZ

LIB_LIBS += -lz


/* Project lib dependencies. Never self-link (WM_PROJECT == OpenFOAM) */
PROJECT_LIBS =


dlahaye December 11, 2023 14:14

1/ Distinguish between compile and link stage.

2/ For compile stage: -I<dir> where <dir> is the directory where header files are located.

3/ For link stage: -L<dir> where <dir> is the directory where library files are located.

olesen December 12, 2023 15:06

Quote:

Originally Posted by klausb (Post 861390)
I want to use the Eigen header file library in an OpenFOAM preconditioner but I keep getting compiler errors telling me, that Eigen is not found.

Eigen is "installed" i.e. header files are located in the directory: /home/klaus/Programme/eigen-3.4.0/Eigen

I added the Eigen3_ROOT to the .bashrc and rebooted as shown below

Code:

# set Eigen3_ROOT
 export Eigen3_ROOT=/home/klaus/Programme/eigen-3.4.0

...

From my knowledge, Eigen is header-only. Please take a look at wmake/scripts/have_eigen and wmake/rules/General/eigen

Typically you would try something like
"sh wmake/scripts/have_eigen -test" from the command-line to see how things work (or not). If you take a look through the file, you will see that it also likes to find its preferences via config.sh/eigen file, where it possibly obtains an EIGEN_ARCH_PATH.

If this detection works OK, then you would add this detection in an src/OpenFOAM/Allwmake script (you need inject this yourself) and then pass through (see src/renumber/Allwmake for an example).

Of course, you could also just define it all yourself in the OpenFOAM/Make/options (might actually be easier). For example (not tested):

OpenFOAM/Make/options
Code:

EXE_INC = \
    -I$(OBJECTS_DIR)

 ifneq (,$(Eigen3_ROOT))
    EXE_INC += -DHAVE_EIGEN -I$(Eigen3_ROOT)/include
endif
 ...

Then, similar to the HAVE_LIBZ handling, selectively include and enable in your code.

klausb December 12, 2023 16:37

I followed the setup for an OpenFOAM solver I found online:

Add the following to the .bashrc file:
Code:

# set Eigen3_ROOT and EIGEN_LIBRARY_PATH
export Eigen3_ROOT=$HOME/Programme/eigen-3.4.0
export EIGEN_LIBRARY_PATH=$HOME/Programme/eigen-3.4.0

Include -I$(EIGEN_LIBRARY_PATH) into the Make/options file as shown below

Code:

EXE_INC = \
    -I$(OBJECTS_DIR) \
    -I$(EIGEN_LIBRARY_PATH)



All times are GMT -4. The time now is 02:41.