Run Control: new outer loop do optimization, scanning etc.

Discussion about coding and new developments
Post Reply
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Run Control: new outer loop do optimization, scanning etc.

Post by raback »

Hi All,

There are some new developments related to optimization, parameter scanning and beyond, of multiple Elmer simulations in "devel" branch. This involves new section ”Run Control”. This is a special section in the way that it is analyzed before the rest of the simulation is carried out.

For example, test case "ParamFourHeaters" has the following section that will run the case four times altering the parameters as defined in ascii table par.dat

Code: Select all

Run Control
  Run Control Iterations = Integer 4
  ! give parameters as an ascii matrix:
  Parameter File = File "par.dat"
  Parameter Count = Integer 4 ! columns in matrix
  Parameter Row Offset = Integer 2 ! starts from line 3
End
The parameters are then available as "rpar" vector for following matc expressions (starting with $ or MATC). For example, the first parameter sets the heat source 1 in the test case:

Code: Select all

Body Force 1
  Name = "Heater1"
  Heat Source = $rpar(0)
End
By construction the "Run Control" section is read first, and then the MATC vector is created. The sif file is reanalyzed meaning that all dependent variables may also change. The good thing with this approach is that constants may be truly constants i.e. time is not spent in analyzing variables. A minor limitation is that "Run Control" section must preceed all other sections.

The parameters may also be generated by internal optimization procedures. The routines in the old FindOptimum solver has been copy-pasted & slightly modified to provide simple internal optimization routines. For example, in test case "OptimizeSimplexFourHeatersInt" we have:

Code: Select all

Run Control
  Run Control Iterations = Integer 100
  Parameter Count = Integer 4
  Parameter Optimal Finish = Logical True
  Parameter Best File = File "optimize-best.dat"
  Parameter History File = File "optimize-history.dat"
  Cost Function = Variable Time
    Real Procedure "CostFunction" "CostFunction"
  Optimization Method = String "simplex"
  Simplex Relative Length Scale = Real 1.0
End
Again the parameter $rpar() is used in the following sections and simplex method is used for 100 simulations. The history and best configuration are saved.

Traditionally Elmer has had time dependency mode "scanning" that has enabled simple sweeps over parameters. This can now be achieved also with the new "Run Control". Test case "HelmholtzPlaneWavesParam" demonstrates how to scan over frequency space. The key line is

Code: Select all

  Frequency = Variable "run"
    Real MATC "1000*tx"
i.e. the loop parameter is available as variable "run" for all dependency models.

So why did the old "scanning" mode not do the work? It perhaps could have done it for steady state cases. The problem is that it used the time as a pseudo variable which meant that it was impossible to study transient systems. This can deal with transient cases (the initialization may need to be checked).

So why now do everything externally? That might be the ideal modular way to work. However, there may be additional features that you can do when everything is internal also concerning the history. Also some redundant pre and post tasks are eliminated. There is no strong case for this but with this rather modest work, why not have an internal option?

An example of something more non-conventional use of "Run Control" is found in test case "RunControlStructured". There
a simple 3D heat equation is solved and the boundary conditions between different runs are inherited from
the other end of the cube.

We are open for comments & ideas. Do you have any idea how this additional outer control level could be used?

-Peter
thomasatelmer
Posts: 47
Joined: 18 Jan 2019, 18:18
Antispam: Yes

Re: Run Control: new outer loop do optimization, scanning etc.

Post by thomasatelmer »

Dear Peter,
thank you very much for this news note that I just came about to see (over one year later - my bad) because I also searched for optimization means within Elmer.

I currently work on a case to match a transient simulation model to real-world time series temperature data by changing some of the unknowns (material constants being a little different from textbook values, interface heat transfer coefficients being widely unknown and the like). So I tried the Run Control feature and it works like a charm for my purposes also on these transient runs, but I still assess the matching quality by graphical result interpretation (for which parameter set does the time series temperature curves match the real world data best?)

I realize, that this is a classical optimization task, and diving a little into the "OptimizeSimplexFourHeatersInt" example, I start to get my head around how it is specified and the Fortran code works. Not knowing the data structure in Elmers data layer nearly at all, and only knowing some small bits of fortran, I wonder how I could extend the heater example to a transient case - the heater temperatures should be like in the example, but after a given time...

It would be nice if you could give me a small hint for such a change or where to find further reading on the data structure in transient cases and how to access it for a fortran-written cost-function routine.

Thank you and keep up the good work!
Thomas.

p.s. a small quirk made it to my attention when testing the RunControl feature, as I use ElmerFEM under Ubuntu as well as under Win10. Under Ubuntu, the estimated remaining time is guessed for the current set of transient steps (which is ok, and it is calculated seemingly correct). However under Win10, the time estimation is getting longer and longer from loop to loop - looks like the time estimation routine "sees no progress", as it keeps coming around the same timesteps :-) I am just astonished that there is a difference between different OS builds of Elmer...
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Run Control: new outer loop do optimization, scanning etc.

Post by raback »

Hi

I only read this now. Maybe you have resolved the issues already... I know we are developing this further within a few months, and actually the target may be transient simulation. Hence some example like that will certainly be created. I'm afraid this work will commence only early next year.

The time estimation needs time function from the system. I guess in Windows this is not supported in the same way as in Linux. It may be beyond Elmer. We could perhaps try to use the standard "cpu_time" function of fortran. The original timing code is using some c-code that proceeded probably this native function.

-Peter
thomasatelmer
Posts: 47
Joined: 18 Jan 2019, 18:18
Antispam: Yes

Re: Run Control: new outer loop do optimization, scanning etc.

Post by thomasatelmer »

Good evening, Peter,
and thank you for your reply that I am also late on commenting (for some reason, the board software did choose not to notify me of your post). I just returned to read your initial writing once more in search for a way to go, when I realized there is an answer following my post.

Thus I have not managed to resolve my topic. I am definitely looking forward to the further developments... Just let us know any news.
I already thought about using the run variable somehow to assess the cost function with different target values depending on the run step, but as you said, re-initialization is not easy to solve. But by this, it might be doable to create a cost function that accumulates the match of target values to achieved values for several time intervals. On the other hand, me not knowing how Elmer really operates under the hood, this may be total nonsense :lol:
Thank you for now, keep me posted please.
Thomas.
Post Reply