import a constant value from a file

General discussion about Elmer
Post Reply
felixelmer
Posts: 9
Joined: 30 Nov 2020, 16:19
Antispam: Yes

import a constant value from a file

Post by felixelmer »

Dear Elmer gurus:

How do I import/read constant value from a file before the Header section of a sif file?
That is, rather than writing
#rho = 2000
$A1 = 10
how would you import the values 2000 and 10 from two .dat files, and assign them to the constants?

I wish to use MATLAB to run a sif file many times, each time with different conditions (as defined by the constants).

Best wishes,
Felix
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: import a constant value from a file

Post by kevinarden »

one approach is to create a user procedure which is a fortran program, this example is in a file named myprocedure.f90

FUNCTION density( Model, n, x ) RESULT( d )
USE Types
TYPE(Model_t) :: Model
INTEGER :: n
REAL(KIND=dp) :: d

open (unit = 1, file="mydensity")

read(1,*) d

END FUNCTION density

you would compile the procedure from the command line with
elmerf90 myprocedure.f90 -o myprocedure

this creates a callable procedure, in the sif file you could use, in this example myprocedure is in the same directory as the sif

Material 1
Youngd Modulus = 10.0
Viscosity = 0.5
Poisson Ratio = 0.3

Density = Variable time
Real Procedure "myprocedure" "density"
End
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: import a constant value from a file

Post by kevinarden »

raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: import a constant value from a file

Post by raback »

In addition to command-line arguments you could use use environment variables:
viewtopic.php?f=3&t=5091&p=18045&hilit=matc+env#p18045
felixelmer
Posts: 9
Joined: 30 Nov 2020, 16:19
Antispam: Yes

Re: import a constant value from a file

Post by felixelmer »

Hi Kevin and Peter,

Many thanks for your super helpful answers, providing several solutions!
I have now gotten it to work, both by using a user function and an environmental variable.

Best wishes, Felix
Post Reply