Scanning with parametrized keywords (parameter sweep)

The graphical user interface of Elmer

Scanning with parametrized keywords (parameter sweep)

Postby CrocoDuck » 20 May 2016, 15:56

Hi there!

I wanted to share on the forums a simple way to do scanning simulations (kinda like COMSOL parameter sweeps). I have two reasons for doing that:

  • People have been helping me, so I wanted to "balance the karma" sharing a solution for a problem which I hope will help someone else.
  • There are other threads on this, and also documentation covers the topic. However, solution in threads is not clearly stated and documentation on this topic is not very detailed. For a newbie like me it is not the best situation.

So, I think that just using what I did as an example will make it clear for other newbies.

Let's assume we have an acoustic simulation we solve with the Helmholtz solver. We define the frequency vector containing all the frequencies we want to test in the Header of the sif (Model > Setup > Header > Free Text):

Code: Select all
$ f = 500 1000 2200

We shift now to Simulation and we select Scanning. f is declared, with that syntax, as a MATC vector. It has clearly 3 components, so we set Timestep intervals to 3. Scanning produces a sort of time axis with integer values. So, time will look like this: time = 1, 2,3 ...

Then, when we edit the Helmholtz equation, we write this into Angular Frequency:

Code: Select all
Variable time; Real MATC "2 * pi * f(tx - 1)"

Which means that at each timestep a value of frequency is taken from the vector f and used to calculate the simulation Angular Frequency. You can do the same for boundary conditions. For example, this updates the flux of a constant velocity radiator:

Code: Select all
Boundary Condition 2
  Target Boundaries(1) = 10
  Name = "Radiator"
  Wave Flux 1 = 0
  Wave Flux 2 = Variable time;Real MATC "2 * pi * f(tx - 1) * 1.205 * v"

tx - 1 is used because MATC vectors are 0 indexed: f(0) = 500, f(1) = 1000, f(2) = 2200. tx has the current value of time, which can be 1 ,2 or 3. Hence, you see why we subtract 1.

If you have any solver saving data for you, just set Exec Solver to After Timestep (Equation > Your-Saver-Equation > Edit Solver Settings > General). Here how my Save-My-Stuff setup looks like:

Code: Select all
Equation 2
  Name = "Result Output EQ"
  Active Solvers(1) = 3

Solver 3
  Equation = Result Output
  Save Geometry Ids = True
  Output Format = Vtu
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Save Linear Elements = True
  Output File Name = case
  Exec Solver = After Timestep

This way, the solution after each simulation at a given frequency is saved.

Hope this helps somebody.

Related threads:

Related documentation: ... Manual.pdf ... ection.2.3


Ehm... look at this equation:
Code: Select all
Real MATC "2 * pi * f(tx - 1) * 1.205 * v"

1.205 is the density of air, which is a parameter of the material I am using. Is there a way to get it from the material parameters? Couldn't find a way to do it... :oops:
Last edited by CrocoDuck on 22 May 2016, 18:33, edited 3 times in total.
Posts: 44
Joined: 12 May 2016, 13:15

Re: Scaning with parametrized keywords (parameter sweep)

Postby annier » 20 May 2016, 18:46

Hi CrocoDuck
Thank you for your excellent contribution and illustration.

Yours Sincerely
Anil Kunwar
Posts: 1074
Joined: 27 Aug 2013, 13:51

Re: Scanning with parametrized keywords (parameter sweep)

Postby drone50 » 29 May 2016, 15:56

Dear CrocoDuck,

Thank you very much for your kind and detailed descriptions !!

Posts: 4
Joined: 09 Jul 2015, 15:58

Re: Scanning with parametrized keywords (parameter sweep)

Postby daria19 » 12 Mar 2018, 14:22


Thank you guys for sharing the above information..., it's really helpful for us...
Posts: 1
Joined: 12 Mar 2018, 14:04

Return to ElmerGUI

Who is online

Users browsing this forum: No registered users and 1 guest