Page 1 of 1

Define output file name using variable

Posted: 05 Aug 2019, 03:53
by dodo
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

Re: Define output file name using variable

Posted: 05 Aug 2019, 11:05
by mzenker
Hi,

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

HTH,
Matthias

Re: Define output file name using variable

Posted: 06 Aug 2019, 06:50
by dodo
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

Re: Define output file name using variable

Posted: 06 Aug 2019, 09:54
by mzenker
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

Re: Define output file name using variable

Posted: 07 Aug 2019, 03:10
by dodo
It worked indeed!
Thank you very much, Matthias!

Regards,
Rafa

Re: Define output file name using variable

Posted: 11 Aug 2019, 01:49
by raback
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

Re: Define output file name using variable

Posted: 28 Aug 2019, 11:56
by mzenker
...which is even more elegant! :)