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

Include my own library in sprayFOAM

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree8Likes
  • 8 Post By floquation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 16, 2014, 17:28
Default Include my own library in sprayFOAM
  #1
New Member
 
Stefanie
Join Date: Oct 2014
Posts: 7
Rep Power: 11
SprayStef is on a distinguished road
Hi,

I'm a total newbie to OpenFOAM and need some help...

This should be easy but I can't seem to find the answer anywhere...

I'm modifying SprayFOAM in various ways. For now I've started by adding a new member function to reactingCloudI.H and I'm going to implement a new evaporation model. --> All changes in lagrangian/intermediate...
After making my changes I successfully compiled my library --> libmylagrangianIntermediate.so , which is now be stored in $(FOAM_USER_LIBBIN).

I included the library with:
-I$(FOAM_USER_LIBBIN)/libmylagrangianIntermediate

When I compile mySprayFoam (that's my modified solver), it doesn't see the library because it gives an error that the member function (the one, I defined in my library) does not exist.

Can anybody help?

Thanks so much,
Stef
SprayStef is offline   Reply With Quote

Old   October 17, 2014, 05:48
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
Hi,


I'm reasonably new (8 weeks) to OpenFOAM (and C/C++ for that matter) as well, but I figured your question would be a nice exercise to understanding libraries in C.


In the past 2.5 hours I came to the following conclusions:
  1. When you're trying to compile code 'myExe' which uses library 'myLib', the compiler for myExe will need to have access to the header file originally used to generate myLib. This is done using the -I compiler flag, linking to the directory in which the included .H file is contained, e.g.: foo.H.
    • If this is not done, you get the following error:
      • Code:
        myExe.c:2:17: fatal error: foo.h: No such file or directory
         #include "foo.h"
    • It needs this, since myLib contains solely machine code, which myExe can execute. However, at this point (compile-time) you still have a .C code which cannot read the machine code. --> You need a header file containing the declarations for methods/function of myLib which myExe wants to use.
      • Anyone knows why it cannot just read the machine code? After all, it does so in the next step as well:
  2. Additionally, you need to specify the library using the -lLibName compiler flag (and possibly -LlibDir), from which your myExe-compiler can see that the declared methods are indeed implemented -> ?it reads machine code now?
    • If this is not done, you get one of the following errors (where "foo" is the name of the function to be called).
      • You did not include the library (-lLibName)
        Code:
        /tmp/ccUxHJpQ.o: In function `main':
        myExe.c:(.text+0xf): undefined reference to `foo'
        collect2: error: ld returned 1 exit status
      • You forgot -LlibDir->
        Code:
        /usr/bin/ld: cannot find -lfoo
        collect2: error: ld returned 1 exit status
  3. Then, at run-time, your executed myExe will need to relocate the library (shared object files are dynamically linked). It does so by reading your $LD_LIBRARY_PATH environment variable. The path containing your library (probably $FOAM_USER_LIBBIN) should be included in that environment variable.
    • If this is not done, you get the following error:
      • Code:
        ./myExe: error while loading shared libraries: libfoo.so: cannot open shared object file: No such file or directory


So, for your specific question, you will need the following statements in Make/options:
Code:
-L$(FOAM_USER_LIBBIN)
-lmylagrangianIntermediate
-I$YOUR_HEADER_DIR
For my test code, this would look like:
Code:
Make/files
myExe.c

EXE = testWMake                             

Make/options
EXE_INC = \
    -I../fooLib

EXE_LIBS = \
    -L$(FOAM_USER_LIBBIN) \
    -lfoo
(That creates an executable. If you want to create a library, use "LIB" and "LIB_LIBS" instead.)


Good refs:
http://www.openfoam.org/docs/user/co...plications.php
http://www.cprogramming.com/tutorial...linux-gcc.html


~ Kevin
salehi144, pavelow, daire6 and 5 others like this.
floquation is offline   Reply With Quote

Old   October 17, 2014, 17:51
Default
  #3
New Member
 
Stefanie
Join Date: Oct 2014
Posts: 7
Rep Power: 11
SprayStef is on a distinguished road
Hey Kevin,

thanks so much!!!
That help me with my problem AND helped me understand libraries in C++ a little better.

Stef
SprayStef is offline   Reply With Quote

Old   October 29, 2014, 17:13
Default
  #4
New Member
 
Stefanie
Join Date: Oct 2014
Posts: 7
Rep Power: 11
SprayStef is on a distinguished road
Hi again,

now I've sucessfully added some functions to the ReactingCloud Template in my library, but a new issue arouse...

I added a new Evaporation Model / PhaseChangeModel.

added the following lines to intermediate/parcels/include/makeReactingParcelPhaseChangeModels.H:

#include "MyEvaporation.H"

and

makePhaseChangeModelType(MyEvaporation, CloudType);

When I run my case with the myEvaporation option I get the following error message:


--> FOAM FATAL ERROR:
Unknown phase change model type myEvaporation

Valid phase change model types are:

3
(
liquidEvaporation
liquidEvaporationBoil
none
)


From function PhaseChangeModel<CloudType>::New(const dictionary&, CloudType&)
in file /home/astefani/OpenFOAM/astefani-2.1.1/run/../lib_myLagrangian/intermediate/lnInclude/PhaseChangeModelNew.C at line 54.


Why is my PhaseChangeModel not in the list yet?
Any ideas on what I could have done wrong or forgotten?


Thanks,
Stef
SprayStef is offline   Reply With Quote

Old   October 30, 2014, 02:54
Default
  #5
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 20
floquation will become famous soon enough
Is this line in your "myEvaporation.H" file?

Code:
public:

    //- Runtime type information
    TypeName("myEvaporation");
Alternatively... Did you recompile the C-file which calls intermediate/parcels/include/makeReactingParcelPhaseChangeModels.H?
I.e. lagrangian/intermediate/parcels/derived/basicReactingParcel/makeBasicReactingParcelSubmodels.C (and similar for the other possible cloudTypes).
floquation is offline   Reply With Quote

Old   April 11, 2018, 03:52
Default
  #6
New Member
 
Join Date: Jun 2017
Posts: 12
Rep Power: 8
ms6918 is on a distinguished road
Hello,
I am trying to add some of the Openfoam libraries(like lagrangian etc.) in flameletFoam. My openfoam and flameletfoam are compiled seperately. My solver did compile but when i ran solver it gave error stating Duplicate entries.

I am starting to wonder that i may have not compiled the libraries correctly. I started by copying my openfoam libraries in flameletfoam and compiling them in flameletfoam. Then in my solver in flameletfoam, i called some of the libraries from flameletfoam and some(like meshTools, sampling etc.) from Openfoam.

Is this the correct approach?

Kindly consider my request. It would be a great help.

Sincelery,
beginner
ms6918 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
cyclic boundary conditions for FSI kanuk OpenFOAM Programming & Development 10 April 25, 2014 02:52
OpenFoam install script Error during paraFoam installation SePe OpenFOAM Installation 10 June 19, 2010 15:15
critical error during installation of openfoam Fabio88 OpenFOAM Installation 21 June 2, 2010 03:01
Problems in compiling paraview in Suse 10.3 platform chiven OpenFOAM Installation 3 December 1, 2009 07:21
OpenFOAM15 paraFoam bug koen OpenFOAM Bugs 19 June 30, 2009 10:46


All times are GMT -4. The time now is 00:57.