CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

What's the Eigen library setup for OpenFOAM?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 10, 2023, 09:18
Default What's the Eigen library setup for OpenFOAM?
  #1
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22
klausb will become famous soon enough
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 =
klausb is offline   Reply With Quote

Old   December 11, 2023, 14:14
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 722
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
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.
dlahaye is offline   Reply With Quote

Old   December 12, 2023, 15:06
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,684
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by klausb View Post
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.
olesen is offline   Reply With Quote

Old   December 12, 2023, 16:37
Default
  #4
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22
klausb will become famous soon enough
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)
klausb is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate library entries when running a solver with custom library francescomarra OpenFOAM Programming & Development 3 May 17, 2022 08:37
[OpenFOAM.com] Compiling Scotch library error fedez91 OpenFOAM Installation 6 March 2, 2022 23:25
[Other] Multi species mass transport library [update] novyno OpenFOAM Community Contributions 111 November 9, 2021 23:37
Unable to use .so library in other folder than in $FOAM_USER_LIBBIN Saideep OpenFOAM Programming & Development 1 September 15, 2021 09:22
[swak4Foam] Installing swak4Foam to OpenFOAM in mac Kaquesang OpenFOAM Community Contributions 22 January 21, 2013 11:51


All times are GMT -4. The time now is 17:31.