Installation/Compilation of a user defined function

Discussion about building and installing Elmer
Post Reply
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Installation/Compilation of a user defined function

Post by ScientistRenzo »

The SIF video tutorial and ElmerProgrammer's tutorial have instructed me to use something of the form:

Heat Source = Variable coordinate 1, coordinate 2, coordinate 3, time
Procedure "MyLibrary" "MyFunction"

where "MyLibrary" is a .f90 file and ""MyFunction" is a FUNCTION in fortran90

Then compile with
$ elmerf90 -o MyLibrary.so MyLibrary.f90 or
> elmerf90 -o MyLibrary.dll MyLibrary.f90

Can you help me by sharing a test file "MyLibrary.so" or "MyLibrary.dll", so that I can learn to compile a .f90 file with elmer in this fashion and test if everything is working?

Thanks :D
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by kevinarden »

heat.F90
(386 Bytes) Downloaded 221 times
case.sif
(1.63 KiB) Downloaded 211 times
An example of heat as a function of time. You can make whatever functions you need inside the If statements, or make your own branch conditions.
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by ScientistRenzo »

Thank you so much.

Wow!

I opened your heat.90 on atom the text editor and I'm glad to see the similarities between your code and the fortran tutorial I was watching! I'll review.

In case.sif I understood how you sourced "heat" and "HeatSource" within "heat"

Your help is perfect.

Could you please help me try to compile this on the command line (I'll try Git Bash, Cygwin, and cmd if either do not work)

I have the project ready in a directory /Elmer 9.0-Release/Projects/heatproject

I wonder if I have to save heat.f90 in a specific directory, /heatproject, or if the command-line will be able to find it in /Downloads

Similar question: I wonder if I have to navigate to a specific directory to type $ elmerf90 -o heat.so heat.f90
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by kevinarden »

If the user function is in the working directory with the case.sif then the way it is called out in the case.sif will work. Otherwise you have to put the directory path in like

Heat Source = Variable Time
Procedure "/home/myfiles/fea/heat" "HeatSource"

elmerf90 -o heat.so heat.f90 is the compiler supplied by Elmer and must be used for user functions
the elmerf90 is an executable and your path has to be set correctly for the OS to fined it, or you have to fully qualify it

C:\elmer\bin\elmerf90 -o heat.so heat.f90

where C:\elmer\bin is rplaced with the location of the Elmer exectuble files.
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by ScientistRenzo »

This was perfect kevinarden!
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by ScientistRenzo »

Ok hope you can help me.

I built heat.f90 and placed in in Elmer 9.0 Release/Projects/proj1

I opened Git Bash and navigated to Elmer/bin

I typed elmerf90 heat.f90 -o heat.so

and I get the error
/d/Elmer 9.0-Release/Bin/elmerf90: line 5: syntax error near unexpected token `('
/d/Elmer 9.0-Release/Bin/elmerf90: line 5: ` LIBDIR=C:/Program Files (x86)/Elmer/share/elmersolver/../../lib/elmersolver'

Please help. Thanks!
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by kevinarden »

/d/Elmer 9.0-Release/Bin/elmerf90: line 5: syntax error near unexpected token `('
/d/Elmer 9.0-Release/Bin/elmerf90: line 5: ` LIBDIR=C:/Program Files (x86)/Elmer/share/elmersolver/../../lib/elmersolver'

one line 5 it can't read the (x86) as part of the file name. adding quatations around the filename may work.
LIBDIR="C:/Program Files (x86)/Elmer/share/elmersolver/../../lib/elmersolver"
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by ScientistRenzo »

I don't know why C:/Program Files (x86)/Elmer/share/elmersolver/../../lib/elmersolver is being referenced. I do not have a Elmer file in Program Files (x86).
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by kevinarden »

depending on how elmer was installed on what system the executable files may be located there, elmer90 is trying to find a library named LIBDIR=C:/Program Files (x86)/Elmer/share/elmersolver/../../lib/elmersolver
it can't find it because it can't decipher a file name with () in it.
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Re: Installation/Compilation of a user defined function

Post by ScientistRenzo »

Solved: I uninstalled everything, then followed https://www.youtube.com/watch?v=xPDzlGYK_kM. Thanks for helping.
Post Reply