Define output file name using variable

Numerical methods and mathematical models of Elmer
Post Reply
dodo
Posts: 3
Joined: 05 Aug 2019, 03:39
Antispam: Yes

Define output file name using variable

Post by dodo » 05 Aug 2019, 03:53

Hello,

First of all, thank you very much to everyone collaborating in this amazing open tool.

I wanted to ask if it was possible to use a user-defined variable to parameterize file names in the ".sif" file.
In particular I would like to do this with the aim of obtaining different output files for different simulation frequencies in an acoustic problem.

So, if in my Header section I have:

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "."
  Include Path ""
  Results Directory ""
  $ Frequency = 1.1e3
End
I am thinking of using something like this in the output solver definition:

Code: Select all

Solver 2
  Equation = Result Output
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Exec Solver = After Simulation
  Output File Name = "open_end_" + $ Frequency + "Hz"
  Output Format = Vtu
  Scalar Field 1 = "Press_dB"
End
What would be the correct way to do it?

Please let me know if I was not clear enough.
Thanks in advance!

Rafa

mzenker
Posts: 1957
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Define output file name using variable

Post by mzenker » 05 Aug 2019, 11:05

Hi,

you can use sprintf() as in C, see MATC manual.

HTH,
Matthias

dodo
Posts: 3
Joined: 05 Aug 2019, 03:39
Antispam: Yes

Re: Define output file name using variable

Post by dodo » 06 Aug 2019, 06:50

Hi Matthias,

Thanks for your reply.

After looking at the sprintf definition in the MATC manual, I tried some variations of the following approach, but it is not working:

Code: Select all

Solver 2
  Equation = Result Output
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Exec Solver = After Simulation
  Output File Name = sprintf("open_space_%iHz_pressdb",Frequency)
  Output Format = Vtu
  Scalar Field 1 = "Press_dB"
End
Could you please point me to the write syntax?

Cheers,
Rafa

mzenker
Posts: 1957
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Define output file name using variable

Post by mzenker » 06 Aug 2019, 09:54

Hi,

I think it could work with

Code: Select all

Output File Name = $ sprintf("open_space_%iHz_pressdb",Frequency)
or

Code: Select all

Output File Name = MATC "sprintf('open_space_%iHz_pressdb',Frequency)"
HTH,
Matthias

dodo
Posts: 3
Joined: 05 Aug 2019, 03:39
Antispam: Yes

Re: Define output file name using variable

Post by dodo » 07 Aug 2019, 03:10

It worked indeed!
Thank you very much, Matthias!

Regards,
Rafa

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

Re: Define output file name using variable

Post by raback » 11 Aug 2019, 01:49

Hi

Matthias already gave you an elegant answer. Still, if you want to use MATC directly you could note that if you should just close the field with another "$". For example,

Code: Select all

$freq=7
Filename = case$freq$.vtu
-Peter

mzenker
Posts: 1957
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Define output file name using variable

Post by mzenker » 28 Aug 2019, 11:56

...which is even more elegant! :)

Post Reply