Page 1 of 2

Linking Elmer solver with OpenCalphad

Posted: 19 May 2016, 11:33
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

Re: Linking Elmer solver with OpenCalphad

Posted: 20 May 2016, 05:41
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

Re: Linking Elmer solver with OpenCalphad

Posted: 23 May 2016, 11:04
by Franz Pichler
Very interesting,

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

best regards
Franz

Re: Linking Elmer solver with OpenCalphad

Posted: 24 May 2016, 05:12
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

Re: Linking Elmer solver with OpenCalphad

Posted: 08 Jun 2016, 19:22
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.

Re: Linking Elmer solver with OpenCalphad

Posted: 09 Jun 2016, 13:37
by serge_13
If it's critical for your work I may try link OpenCalpad to Elmer Package on MinGW64 platform...

B.r.,
Serge

Re: Linking Elmer solver with OpenCalphad

Posted: 10 Jun 2016, 12:13
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

Re: Linking Elmer solver with OpenCalphad

Posted: 10 Jun 2016, 13:28
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.

Re: Linking Elmer solver with OpenCalphad

Posted: 10 Jun 2016, 14:12
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.

Re: Linking Elmer solver with OpenCalphad

Posted: 10 Jun 2016, 15:14
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