defining conditional constant above Simulation section

Numerical methods and mathematical models of Elmer
Post Reply
mark smith
Posts: 215
Joined: 26 Aug 2009, 18:20
Location: Peterborough, England

defining conditional constant above Simulation section

Post by mark smith »

Hi All,
I want to define a constant which depends on the value of other per-defined constants in the sif file above the Simulation section, i.e.

Header
CHECK KEYWORDS Warn
Mesh DB "." "."
Include Path ""
Results Directory ""
End

!! parameters all in SI units
$ w=6.0e-003 !width of channel
$ t=2.00e-003 !thickness of channel
$ q=1.00e-006 !flow rate at each inlet =1cm^3/sec at v_in
$ v_in = q/(w*t) !average inlet velocity v, gives inflow of ~60 mL/min

! for fully developed velocity profile over rectangular channel. ref: Shah and London, "Laminar Flow Forced Convection in Ducts", 1978, Eqn. 335-338
$ x10 = 0.000 ! x coord of center of inlet face BC1
$ y10 = 0.000 ! y coord of center of inlet face BC1
$ z10 = 0.000 ! z coord of center of inlet face BC1
$ x30 = 0.000 ! x coord of center of inlet face BC3
$ y30 = 0.004 ! y coord of center of inlet face BC3
$ z30 = 0.130 ! z coord of center of inlet face BC3
$ a = w/2
$ b = t/2
$ alpha = b/a !channel aspect ratio, w must be > t
$ m = 1.7 + 0.5*alpha^(-1.4)
$ n = MATC "if(alpha <= 1/3) {2.0} else {2 + 0.3*(alpha - 1/3)}"


Now the last line defining n throws an error when ElmerSolver is run, is it possible to use MATC in this part of a sif file & if so how do I make my example run?

I've checked the elmerfem test files but can't find any examples of using if() in defining constants above the simulation section.
BR Mark
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: defining conditional constant above Simulation section

Post by mzenker »

Hi,

the "$" sign does also invoke MATC. See viewtopic.php?f=3&t=4916&p=17655#p17654 for an explanation. So I would try

Code: Select all

$ n = if(alpha <= 1/3) {2.0} else {2 + 0.3*(alpha - 1/3)}
for your last line.

HTH,

Matthias
mark smith
Posts: 215
Joined: 26 Aug 2009, 18:20
Location: Peterborough, England

Re: defining conditional constant above Simulation section

Post by mark smith »

Hi Matthias,
Thanks for the suggestion but I still get an error see below.


ELMER SOLVER (v 8.3) STARTED AT: 2018/03/26 14:48:58
ParCommInit: Initialize #PEs: 1
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.3 (Rev: unknown, Compiled: 2018-03-10)
MAIN: Running one task without MPI parallelization.
MAIN: Running with just one thread per task.
MAIN: HYPRE library linked in.
MAIN: MUMPS library linked in.
MAIN: =============================================================
MAIN:
MAIN:
MAIN: -------------------------------------
MAIN: Reading Model: IBmixer_fd.sif
LoadInputFile: Scanning input file: IBmixer_fd.sif
Solver input file error: MATC ERROR: Expecting identifier, constant or leftpar.

...offending input line: n = if(alpha <= 1/3) {2.0} else {2 + 0.3*(alpha - 1/3)}

Any suggestions?
BR Mark
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: defining conditional constant above Simulation section

Post by mzenker »

I was too hasty and didn't notice the syntax.
How about

Code: Select all

$ n = if(alpha <= 1/3) 2.0; else 2 + 0.3*(alpha - 1/3);
(see manual...)


HTH,

Matthias
mark smith
Posts: 215
Joined: 26 Aug 2009, 18:20
Location: Peterborough, England

Re: defining conditional constant above Simulation section

Post by mark smith »

Hi Matthias,
Unfortunately I get a similar error:

Solver input file error: MATC ERROR: Expecting identifier, constant or leftpar.

...offending input line: n = if(alpha <= 1/3) 2.0; else 2 + 0.3*(alpha - 1/3);

Regards
Mark
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: defining conditional constant above Simulation section

Post by mzenker »

Hmmm, I begin to run out of ideas...
Maybe it doesn't like the "if" statement in a "$" expression?
What does the solver say if you write something like

Code: Select all

n = Real MATC "if(alpha <= 1/3) 2.0; else 2 + 0.3*(alpha - 1/3);"
inside the section where you need n?
Or else put the whole bunch of MATC statements in the header section and say

Code: Select all

MATC "n = if(alpha <= 1/3) 2.0; else 2 + 0.3*(alpha - 1/3);"
If that doesn't help, this is a question for the real experts... ;)

Matthias
mark smith
Posts: 215
Joined: 26 Aug 2009, 18:20
Location: Peterborough, England

Re: defining conditional constant above Simulation section

Post by mark smith »

Hi Matthias,
Your first suggestion gives the following:
ERROR:: Model Input: Unknown input section name: n

whereas your second suggestion generates this:
ERROR:: Model Input: Unknown input section name: matc n = if(alpha <= 1/3) 2.0; else 2 + 0.3*(alpha - 1/3);

Thank you for the suggestions and trying to help, maybe it isn't possible to do what I want above the simulation section? Maybe someone from the Elmer team will chip in?

BR Mark.
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: defining conditional constant above Simulation section

Post by mzenker »

Hi Mark,

you cannot put a "MATC" statement outside a section, that is why I was suggesting to put the lines with "MATC" _inside_ an appropriate section (e.g. Header). You can only put statements with "$" outside a section.

HTH,

Matthias
Post Reply