MakePermUsingMask

Discussion about coding and new developments
ehooi
Posts: 156
Joined: 20 Aug 2013, 16:02
Antispam: Yes

Re: MakePermUsingMask

Post by ehooi »

Hi Peter,
THank you. I will try them out. In the mean time, I was googling for additional information and I came across one of your presentation slides. I am wondering whether I can use SaveScalar to evaluate the maximum temperature (because this is basically my threshold) and then use MATC in my Boundary Condition section to prescribe my BC. In other words, I will have:

Code: Select all

!***************************************************************************************!
Solver 1
!***************************************************************************************!
	Equation = SaveScalars
	Procedure = "SaveData" "SaveScalars"
	Operator 1 = max
	Variable 1 = Temperature
	Procedure = "SaveData" "SaveScalars"
	Target Variable 1 = string maxTemp
	Exec Solver = before timestep
	Filename = File "scalar_data.txt"
!***************************************************************************************!
End
!***************************************************************************************!
and

Code: Select all

!***************************************************************************************!
Boundary Condition 2
!***************************************************************************************!
	Target Boundaries(12) = 5 6 7 8 9 11 12 13 14 15 16 17
	Name = "ZeroFlux"
	Heat Flux BC = True
	Heat Flux =  0.0
	Potential = Variable maxTemp
	Real MATC "if (tx > 373) Potential = 30; else Potential = 25"
	Save Scalars = Logical True
!***************************************************************************************!
End
!***************************************************************************************!

It seems simpler but I am still not able to run. First of all, I get Model Input: Unlisted keyword: [target variable 1] .... [solver 1] and

ERROR: ListGetReal: Can't find INDEPENDENT variable: [maxTemp] for dependent variable: [potential].

One of the thread (viewtopic.php?f=7&t=2014&start=10) seems to talk about this and the problem can be avoided by using "Initialize Dirichlet Conditions = False" in the Simulation Section. While this is true, when the solver finishes assembling, I get the error: Fortran runtime error: End of file

Does this mean that in the Boundary Condition section, the MATC is reading the maxTemp variable from the file saved in SaveScalars? Is there a way to make the variable from the SaveScalars accessible globally (I doubt this is possible based on previous threads but maybe revised version can do it?). The runtime error seems to tell me that the file is saved in an incorrect format for fortran to read. Am I correct? How can I rectify this?


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

Re: MakePermUsingMask

Post by raback »

Hi

The SaveScalars with the Target Variable creates the variable to the memory. So I think the problem is in

Code: Select all

Potential = Variable maxTemp
   Real MATC "if (tx > 373) Potential = 30; else Potential = 25"
Personally I never use MATC like this. I know it can be done but don't remember the syntax by heart. The following should work though (and be faster):

Code: Select all

Potential = Variable maxTemp
   Real 
     0          25.0
     373.0   25.0
     373.1   30.0
     1000.0 30.0
  End 
-Peter
ehooi
Posts: 156
Joined: 20 Aug 2013, 16:02
Antispam: Yes

Re: MakePermUsingMask

Post by ehooi »

Hi Peter,
THank you for your patience and replies. I found out that the problem with the MATC statement was the wrong syntax. It should instead be written as:

Real MATC "if (tx > 373) 30; else 25"

With the statement above, it works. I also tried your suggestion in the hope that it will run faster, but I obtained Fortran Runtime error: Bad Real Number in item 1 of list input.

Just to check with you, those data are placed in the Boundary Condition section as in:

!***************************************************************************************!
Boundary Condition 2
!***************************************************************************************!
Target Boundaries(12) = 5 6 7 8 9 11 12 13 14 15 16 17
Name = "ZeroFlux"
Heat Flux BC = True
Heat Flux = 0.0
Potential = Variable maxTemp
Real
0 30.0
373.0 30.0
373.1 25.0
1000.0 25.0
End
Save Scalars = Logical True
!***************************************************************************************!
End
!***************************************************************************************!

On another matter, the UDF that you helped me with works fine after some changes to undeclared variables. It is working as I would expect!!! Thank you again for your help. Just a curious note, of the three options:

1. With the UDF using MakePermUsingMask
2. With SaveScalars + MATC
3. With SaveScalars + data (as per your previous post assuming I can eventually get it to work)

which of these would be the fastest and consume the least memory? I would think that option 3 will be the best given that I am not running any UDFs. AM I right?


Thank you.

Best wishes,
EH
ehooi
Posts: 156
Joined: 20 Aug 2013, 16:02
Antispam: Yes

Re: MakePermUsingMask

Post by ehooi »

Okay, the problem with option 3 is solved now. I had a commented line in the original code that I didnt realize was causing problems. Anyway, Peter, do you know which of the three options will require the least computational effort?

You have helped a lot. THank you.

Best wishes,
EH
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: MakePermUsingMask

Post by mzenker »

Hi,

there was a comparison of the speed of using a table vs. MATC vs. UDF in this post viewtopic.php?f=3&t=2345&p=7142#p7142, although with a slightly different context. Conclusion was that MATC is slower than table and UDF, which seem to be evaluated at about the same speed. With the UDF, you have more freedom, but also more coding effort.

HTH,

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

Re: MakePermUsingMask

Post by raback »

Matthias said as it is. Generally as we are only working with boundaries there should not be much difference. Assembly for bodies takes more time and then you should try to avoid MATC more. In the UDF it is critical that you do the max search only once and not for each node. -Peter
ehooi
Posts: 156
Joined: 20 Aug 2013, 16:02
Antispam: Yes

Re: MakePermUsingMask

Post by ehooi »

Hi Peter and Matthias,
Thank you guys for your replies. They are very helpful and have improved my skills on using Elmer. It is indeed a wonderful piece of software.

Thank you!!!


Best wishes,
EH
Post Reply