Linking Elmer solver with OpenCalphad

Numerical methods and mathematical models of Elmer
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Linking Elmer solver with OpenCalphad

Post by annier »

Dear Peter and All,
In our conversation in the thread entitled Chemical Reaction, you had prescribed the idea of developing dynamically linked solvers to coupled chemistry transport and reaction equations using FORTRAN interface.

Some preliminary findings for coupling OpenCalphad(www.opencalphad.com), hereafter refererred as OC, with Elmer
  • 1. The OC software has a OpenCalphad Application Software Interface (OCASI) module written in FORTRAN. liboctq.F90
    2. What can we do to make this coupled with the Elmer Interface ? Use it as a User Defined Function or User Defined Solver.
Note
http://www.opencalphad.com/downloads/TM ... ations.pdf
https://github.com/sundmanbo

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by annier »

Hi All,
With a big help from Peter (Elmer forum username of Peter = "raback"), I could compile shared object of an OpenCalphad(OC) wrapper file.

Steps:
1. The essential OC files(listed in step 2) are available at https://github.com/sundmanbo/opencalphad.
2. Essential OC files: liboceq.a, liboceqplus.mod, filename.TDB and liboctq.F90.
3. Compile the liboctq.F90 file with elmerf90 compiler.

Code: Select all

$ elmerf90 -c liboctq.F90
This will result in liboctq.mod and liboctq.o files.
4. Create an OCviaElmer.F90 fortran FUNCTION. It should have the basic structure of the User Defined Function of Elmer as prescriped in ElmerProgrammers Tutorial.It necessarily uses the liboctq module. This is the wrapper file. Compile this OCviaElmer.F90 file with elmerf90 compiler.

Code: Select all

$ elmerf90 -o OCviaElmer.so OCviaElmer.F90 
This will yield or produce a file with name OCviaElmer.so.

Cheers.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
Franz Pichler
Posts: 196
Joined: 29 Sep 2011, 12:25
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by Franz Pichler »

Very interesting,

could you provide a small sample function file that uses the library?

best regards
Franz
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by annier »

Hi Franz,
When i created a sif file that uses the shared object of application code - OCwrapper.so (OCviaElmer.so), it could not read the OC modules. So, i could not proceed as it might require a greater effort for linking OpenCalphad in a FEM software.
OpenCalphad has already been linked with OpenPhase software(http://www.OpenPhase.de), the latter being a FDM software. The ElmerSolver run of the following package produces the following error:

Code: Select all

ElmerSolver
ELMER SOLVER (v 8.1) STARTED AT: 2016/05/24 11:04:43
ParCommInit:  Initialize #PEs:            1
WARNING:: MAIN: OMP_NUM_THREADS not set. Using only 1 thread.
MAIN: 
MAIN: =============================================================
MAIN: ElmerSolver finite element software, Welcome!
MAIN: This program is free software licensed under (L)GPL
MAIN: Copyright 1st April 1995 - , CSC - IT Center for Science Ltd.
MAIN: Webpage http://www.csc.fi/elmer, Email elmeradm@csc.fi
MAIN: Version: 8.1 (Rev: 0ec5889, Compiled: 2016-02-22)
MAIN: =============================================================
MAIN: 
MAIN: 
MAIN: -------------------------------------
MAIN: Reading Model: 1d.sif
TEST CASE 1
Loading user function library: [Source]...[Source]
TEST CASE 1
Loading user function library: [Poisson]...[PoissonSolver_Init0]
Loading user function library: [OCwrapper]...[OCwrapper_Init0]
OCwrapper: cannot open shared object file: No such file or directory
OCwrapper.so: undefined symbol: __general_thermodynamic_package_MOD_gx
./OCwrapper: cannot open shared object file: No such file or directory
./OCwrapper.so: undefined symbol: __general_thermodynamic_package_MOD_gx
/home/username/elmer8/install/share/elmersolver/lib/OCwrapper: cannot open shared object file: No such file or directory
/home/username/elmer8/install/share/elmersolver/lib/OCwrapper.so: cannot open shared object file: No such file or directory
Do i need to describe the path of working OpenCalphad software when making the OCwrapper.so?

The OCASI application sample downloaded from https://github.com/sundmanbo/opencalphad is also attached along with. The file TQ1-crfe.F90 is compiled with gfortran compiler to produce the executable ./tqex1.
Do you have any idea how ElmerSolver could not read the __general_thermodynamic_package_MOD_gx whereas an external fortran code through TQ1-crfe.F90 can read the same thing?

Yours Sincerely,
Anil Kunwar
Attachments
test1_standalone.tar.gz
the procedure for compilation are described in linktqex1.txt file
(1.6 MiB) Downloaded 332 times
1d_test.tar.gz
sample 1dtests available in Elmer tests directory
(990.42 KiB) Downloaded 338 times
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
serge_13
Posts: 24
Joined: 16 Oct 2015, 17:15
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by serge_13 »

Hi,

I think the problem of dynamic linking takes place. There are at least two reasons:
i) The imported name of the function is not of Elmer's naming rool. It depends on compiler that linked the outer chemical library. For example Intel Fortran compiler naming rools are different from GNU fortran naming rools.
ii) When you try to activate an 'alien' library you need to find all the dependencies. The task may be hard. You need to analyse the dependencies by means of debugger. On my opinion the task is simplified when you compile your application on MinGW64 platform. Here you may use 2 types of debuggers: GDB & Microsoft System Debugger.

May be the article 'Realization of 3d Anisotropic Model of Turbulence in the Elmer Software Package' will helps you too.

Best regards,
Serge.
serge_13
Posts: 24
Joined: 16 Oct 2015, 17:15
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by serge_13 »

If it's critical for your work I may try link OpenCalpad to Elmer Package on MinGW64 platform...

B.r.,
Serge
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by annier »

Hi Serge,
- Both Elmer and OpenCalphad can be compiled with GNU fortran.
- The article in www.T-Flow.ru i.e. http://www.t-flow.ru/index.php?option=c ... =3&lang=en is very wonderful. (http://www.t-flow.ru/images/pdf_article ... er_eng.pdf).
- Can you give an idea on how to compile it in linux?
-In my opinion, i need to develop some more codes to interface OC and Elmer.

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
serge_13
Posts: 24
Joined: 16 Oct 2015, 17:15
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by serge_13 »

Dear Anil !

What kind of Linux OS are you used (distributive type & version) ?

The Elmer Packet was compiled by means of CMake tool in your Linux?

The OpenCalphad was fully compiled there too as outer shared library ?

W.b.r,
Serge.
serge_13
Posts: 24
Joined: 16 Oct 2015, 17:15
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by serge_13 »

Dear Anil !

Try compile and link with your *.so the additional Fortran module gtp3.f90. Here MODULE GENERAL_THERMODYNAMIC_PACKAGE (the first part before _MOD_ delimeter between module & function (or variable) in decorative name). I think the next conformal error may popup.

So I've got additional information now. The static library liboceq.a in example 1 must be linked as below:
gfortran -o tqex1 TQ1-crfe.F90 liboctq.o liboceq.a . Large module gtp3.f90 is transformed to liboceq.a (see Makefile of OpenCalhpad)...

Serge.
Last edited by serge_13 on 10 Jun 2016, 15:17, edited 1 time in total.
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: Linking Elmer solver with OpenCalphad

Post by annier »

Hi Serge,
- I am using Ubuntu 14.04 linux OS.
- As per the suggestion of Bo Sundman (core developer of OC software), i am trying to use the OCASI interface. The opencalphad software is compiled first and the compiled archived library (liboceq.a) is used along with the interface code (liboctq.F90) for use with an external program, say Elmer here.
https://github.com/sundmanbo/opencalpha ... /F90/test1

Since OpenCalphad is a continually growing software, using the complete system may be advantageous in my thought. In accordance to it we have to follow the TQ interface standards. This will be slightly bigger work but it is quite fruitful. How do you opine on it?
Cheers.

Yours Sincerely,
Anil Kunwar
Last edited by annier on 10 Jun 2016, 15:34, edited 2 times in total.
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
Post Reply