User defined subroutine format for SIF files

Numerical methods and mathematical models of Elmer
Post Reply
ekmek
Posts: 2
Joined: 06 Feb 2017, 12:59
Antispam: Yes

User defined subroutine format for SIF files

Post by ekmek »

In the Elmer programming tutorial it says that the general format for subroutines is ---

Code: Select all

SUBROUTINE MySolver( Model,Solver,dt,TransientSimulation )
USE DefUtils
TYPE(Model_t) :: Model
TYPE(Solver_t) :: Solver
REAL(KIND=dp) :: dt
LOGICAL :: TransientSimulation
... FUNCTION BODY ...
END SUBROUTINE MySolver
my question is do you need all those inputs even if you don't use them in the function body?
For example, say I wanted to return 2*dt only, do I need have the inputs Model, Solver and, TransientSimulation?
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: User defined subroutine format for SIF files

Post by raback »

Hi

Yes, the API is fixed.

Note that this is a Solver API so it cannot just return a value. Maybe you're looking for the function API.

-Peter
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined subroutine format for SIF files

Post by annier »

Hi ekmek,
  • 1. As Peter says, you need to write the user defined functions (UDF) as in Chapter 1 of the Elmer Programmer's Tutorial to return the values of 2*dt (http://www.nic.funet.fi/pub/sci/physics ... torial.pdf).

    Code: Select all

    !-------------------------------------------------------------------------------
    !> File: MyLibrary.f90
    !> Written by: ML, 5 May 2010
    !> Modified by: -
    !-------------------------------------------------------------------------------
    FUNCTION MyFunction(Model, n, f) RESULT(g)
    USE DefUtils
    TYPE(Model_t) :: Model
    INTEGER :: n
    REAL(KIND=dp) :: f, g
    ! code
    END FUNCTION MyFunction
    To use such mathematical expressions as functions of time, you also can use the MATC libraries as well (http://www.nic.funet.fi/pub/sci/physics ... Manual.pdf).

    Code: Select all

    parameterA = Variable  time
      Real MATC "2.0*tx"
    where parameterA e.g. density, thermal conductivity, heat transfer coefficient, mass transfer coefficient etc. is the Result(g) of MyFunction in the above model. Thus, parameter A is a function of variable tx.
    For parameterB of three variables, you can write it as expression of variables tx(0), tx(1) and tx(2):

    Code: Select all

    parameterB = Variable  time, coordinate 1, temperature
      Real MATC "2.0*tx(1)(1.0 + sin(0.0174*tx(0)))/(5.0-tx(2))"
    if you mean to evaluate parameterB = 2x*(1.0+ sin(t*pi/180))/(5.0-T) with x- x-coordinate, t -time and T -temperature.

    2. The illustration which you have given in the post 1 is the format for User Defined Solver or in general all the pre-compiled solver subroutines coming with Elmer (Chapter 2 of Elmer Programmer's Tutorial and it provides the solutions of PDEs) .
Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
ekmek
Posts: 2
Joined: 06 Feb 2017, 12:59
Antispam: Yes

Re: User defined subroutine format for SIF files

Post by ekmek »

Thanks Anil and Peter this is starting to make more sense.

But regarding this example:

Code: Select all

FUNCTION MyFunction(Model, n, f) RESULT(g)
USE DefUtils
TYPE(Model_t) :: Model
INTEGER :: n
REAL(KIND=dp) :: f, g
! code
END FUNCTION MyFunction
the manual says that the return value is in h, is that just a typo they mean to say g right?
annier
Posts: 1168
Joined: 27 Aug 2013, 13:51
Antispam: Yes

Re: User defined subroutine format for SIF files

Post by annier »

Hi Ekmek,
The function (MyFunction) obviously returns the value of a material parameter 'g' in terms of Result(g).
For example, g is viscosity.
If viscosity is temperature (T) dependent or is constant with T; and T is variable, then the context might be such that f = T in the Elmer Programmer's Tutorial.
Elmer Programmer's Tutorial wrote:The function then returns the value of the material parameter in variable h.
Then, 'h' should be replaced by 'f' as 'f' is the variable.

We call viscosity in Material n section from solver input file as:

Code: Select all

viscosity  = Variable f
Procedure "MyFunctionFileName" "MyFunction"
For more details on user defined functions , you can study Chapter 18 of Elmer Solver Manual on Basic Programming.
http://www.nic.funet.fi/pub/sci/physics ... chapter.18

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Faculty of Mechanical Engineering, Silesian University of Technology, Gliwice
Post Reply