## Functions in .sif file with MATC

Numerical methods and mathematical models of Elmer
mauc
Posts: 14
Joined: 17 Mar 2015, 17:03
Antispam: Yes

### Functions in .sif file with MATC

I am currently trying to overcome the limit of 128 signs for a MATC function in the .sif file.
To test it, I want to calculate the temperature dependent conductivity with a function.
I just cannot make it work Therefore I guess, that I have a fundamental error in my code.
I followed (at least I tried to) the instructions that can be found in the "ElmerSolverAndIputFile and in the ParamProgrammers tutorial

Code: Select all

``````!------------------------------------------------------------------
! MATC Funktion für  temp abh. Heat Conductivity --- Verwendung in Material 1
!------------------------------------------------------------------

! decalare
!\$ function stemp(X) {\_stemp = 49.13 + 273.16 - 0.7576*X(0) - 7.992E-03*X(1)}
! call
! Temp = Variable Latitude, Coordinate 3 Real MATC “stemp(tx)”

Material 1
Name = a-SiH dependent
! Heat Conductivity = 1.56
! Heat Conductivity = 57
!Heat Conductivity = Variable Temperature; MATC(1.3e-11*(tx(0)-900)^3+1.3e-9*(tx(0)-900)^2+1e-6*(tx(0)-900)+1e-2)*100
Heat Conductivity = Variable Temperature, Coordinate 2;	Real MATC “lambdadep(tx)”
Heat Capacity = 1000
Density = 2.15E3
End``````
It would be great if someone could tel me, where the mistake in my code is. And my second question would be if this is the right methode to overcome the limit of 128 digits in a MATC funciton or if I have to use a Fortran function for it

Thanx a lot

mauc
Attachments error_function.JPG (62.7 KiB) Viewed 3837 times

annier
Posts: 1135
Joined: 27 Aug 2013, 13:51
Antispam: Yes

### Re: Functions in .sif file with MATC

Hi Mauc,
- For complex mathematical expressions, User Defined Fortran Subroutines seem more relevant and some experts on MATC code can suggest you more on details of your code.
- Have you referred the MATC manual?

Yours Sincerely
Anil Kunwar
Anil Kunwar
Department of Materials Engineering, KU Leuven, Belgium

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

### Re: Functions in .sif file with MATC

Hi mauc

Personally I almost always use UDF for complex expressions. Its faster and probably easier to debug.

Here it seems that you have large caps argument X but refer to small caps variable x. Maybe that's the reason.

-Peter

mauc
Posts: 14
Joined: 17 Mar 2015, 17:03
Antispam: Yes

### Re: Functions in .sif file with MATC

Hi Annier, Peter

Yes, I did refer to the MATC Manual and others.
Thanks for the hint with the UDF, Peter. I am trying to avoid that, as I am not good in programming and never used Fortran in my whole lifetime However I finially found why it did not work....

1st the backslashes \ are not allowed in the code
2nd I put the funtion in brackets ()
3rd I used x instead of X

and now it works Though I have to admit, that I do not know if all of these three steps are neccessary.

here my working code

Code: Select all

``````!------------------------------------------------------------------
!Funktion
!------------------------------------------------------------------

\$ function test(x) { mu1 = 5e-9; mu2 = 10e-9; sigma = ((5e-9)/4);a = 1e7; _test = ((exp(-((x(2)-(mu1))^2)/(2*sigma^2))*1.8e6*a)+(exp(-((x(2)-(mu2))^2)/(2*sigma^2))*1.8e6*a))*exp(-a*x(1))}

//call the function
Body Force 1
Name = "Laser Edgewave"
Heat Source = Variable Coordinate 1, Coordinate 2, Time; Real MATC    "test(tx)"
End

``````
by the way, if you declare a varialbe p.ex. mu1 it has to be done in the { } of the function. If they are declared elsewhere in the .sif it does not work neither.

I hope this post will help others encountering the same problems as I did.

mauc

pavel
Posts: 34
Joined: 17 Apr 2014, 17:08
Antispam: Yes

### Re: Functions in .sif file with MATC

Hello,

I try to define a function using MATC, but getting the same error
Solver input file error: MATC ERROR: Expecting identifier, constant or leftpar.

...offending input line: function Ja(t) { import Nct,Iq,Id,w_el,Acoilside; _Ja = (Nct*(-Iq*cos(w_el*t(0)-2*pi/3)-Id*sin(w_el*t(0)-2*pi/3))/Acoilside); }
The function is defined as follows, where parameters Nct, Iq, Id, w_el, Acoilside are defined earlier in the SIF.

Code: Select all

``````! Current density function
\$function Ja(t) { import Nct,Iq,Id,w_el,Acoilside; _Ja = (Nct*(-Iq*cos(w_el*t(0)-2*pi/3)-Id*sin(w_el*t(0)-2*pi/3))/Acoilside); }

Body Force 1
Name = Aplus
Current Density 3 = Real \$ Ja(0)
End``````
Can you help identify where might be the problem?

BR, Pavel

pavel
Posts: 34
Joined: 17 Apr 2014, 17:08
Antispam: Yes

### Re: Functions in .sif file with MATC

And the answer is googled immediately)) The bracket must be after the importing.

Code: Select all

``\$function Ja(t)  import Nct,Iq,Id,w_el,Acoilside { _Ja = (Nct*(-Iq*cos(w_el*t(0)-2*pi/3)-Id*sin(w_el*t(0)-2*pi/3))/Acoilside); }``
BR, Pavel

annier
Posts: 1135
Joined: 27 Aug 2013, 13:51
Antispam: Yes

### Re: Functions in .sif file with MATC

As a note for this important discussion, the MATC function statement in section 5 of Elmer MATC manual can be referred.
http://www.nic.funet.fi/pub/sci/physics ... Manual.pdf

Yours Sincerely,
Anil Kunwar
Anil Kunwar
Department of Materials Engineering, KU Leuven, Belgium