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

Including PETSc in an OF solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2017, 08:59
Default Including PETSc in an OF solver
  #1
New Member
 
Basel Abu-sinni
Join Date: Mar 2017
Posts: 6
Rep Power: 9
BaselAS is on a distinguished road
Hello friends,

I'd like to include PETSc's headers in my solver but I can't figure out how to make it compile.

A PETSc program's makefile is as follows:
Code:
include ${PETSC_DIR}/lib/petsc/conf/variables
include ${PETSC_DIR}/lib/petsc/conf/rules

all: src/LinearSystemSolver.o chkopts 
	-${CLINKER} -o LinearSystemSolver src/LinearSystemSolver.o  ${PETSC_KSP_LIB} 
	${RM} LinearSystemSolver.o
And OF's solver's makefile is, as you may already know, split into two files('options' and 'files') under a directory called 'Make':
'options':
Code:
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude
    
EXE_LIBS = 	-lfiniteVolume \
			-lmeshTools
'files':
Code:
myLaplacianFoam.C

EXE = App/myLaplacianFoam
How am I supposed to edit 'options' and 'files' to make it work?

I appreciate your time and thanks in advance!
Basel
BaselAS is offline   Reply With Quote

Old   April 1, 2019, 21:28
Default
  #2
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
Hi Basel,


I am trying to do the same thing. Have you been able to link petsc with your solver?
DoQuocVu is offline   Reply With Quote

Old   April 1, 2019, 22:41
Default
  #3
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
For someone who might need the answer, I was able to link the icoFoam solver with petsc by doing the following steps:


Note: I am using petsc-3.4.5 and it is installed in my /home directory.

1. Create a shared library of petsc by invoking the following command from any directory in the PETSc source
Code:
make BOPT=O shared
This command will generate libpetsc.so in the folder arch-linux-cxx-opt/lib and it will be included into Make/options.


2. Include petsc.h into icoFoam.C
Code:
#include "petsc.h"
3. Change the Make/options to:
Code:
PETSC_DIR=$(HOME)/petsc/petsc-3.4.5
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(PETSC_DIR)/include \
    -I$(PETSC_DIR)/include/mpiuni \
    -I$(PETSC_DIR)/$(PETSC_ARCH)/include

EXE_LIBS = \
    -lfiniteVolume \
    -lmeshTools \
    -L$(PETSC_DIR)/$(PETSC_ARCH)/lib -lpetsc
4. Compile:
Code:
export PETSC_ARCH=arch-linux-cxx-opt
wmake
I have no idea why putting the line PETSC_ARCH=arch-linux-cxx-opt into Make/options does not work. That's why I have to define the PETSC_ARCH variable explicitly and then wmake.


Hope this can helps
DoQuocVu is offline   Reply With Quote

Old   April 10, 2019, 04:04
Default
  #4
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
I am sorry, eventhough the solver was successfully compiled, it does not work.


The error is that libpetsc.so could not be found, even though it is still exist in my $PETSC_ARCH/lib directory:


Code:
icoPetscFoam: error while loading shared libraries: libpetsc.so: cannot open shared object file: No such file or directory
I have been struggling with this problem for weeks but I have not been able to find a clue to fix it. I would appreciate any suggestion to help me solve this.
DoQuocVu is offline   Reply With Quote

Old   April 10, 2019, 20:24
Default
  #5
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 9
DoQuocVu is on a distinguished road
Problem solved!


Just need to define the LD_LIBRARY_PATH environmental variable in $HOME/.bashrc



Code:
echo "export LD_LIBRARY_PATH=\$PETSC_DIR/\$PETSC_ARCH/lib">>$HOME/.bashrc
DoQuocVu 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
Radiation Modeling Using Discrete Ordinates Method and Parallel Solver malicemethods FLUENT 3 May 25, 2018 14:25
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 00:01
thobois class engineTopoChangerMesh error Peter_600 OpenFOAM 4 August 2, 2014 09:52
Parallel solver for Poisson equation using PETSc JackNapier Main CFD Forum 0 July 5, 2012 16:53
why the solver reject it? Anyone with experience? bearcat CFX 6 April 28, 2008 14:08


All times are GMT -4. The time now is 13:35.