Continues simulations

Hello developers,

I need to run my freefem code for multiple meshes, so that each time my code read a different mesh and do the simulation for this mesh, then stores the result for every mesh and again repeat it continuesly for several meshes.
May you help me how can I do it?

Thanks.

Hi !

It is possible to do this in several ways. Two simple ideas might be something like

  1. Assume the meshes are named as mesh0.msh, mesh1.msh, etc., and that they are in the same directory as your main.edp script. Then you could do something like

    load "iovtk"
    int[int] vtkOrder=[1];
    for(int k=0; k<2; ++k){
           mesh Th=readmesh("mesh"+k+".msh");
    
           fespace Vh(Th,P1);
           Vh      uh, vh;
    
           solve mweProblem([uh],[vh]) = int2d(Th)(uh*vh) - int2d(Th)((k+1)*(x+y)*vh);
           //plot(Th,uh,wait=0,value=1,cmm="k = "+k);
    
           savevtk("sols"+k+"/result.vtk",Th,uh,dataname="uh",order=vtkOrder,bin=false);
    }
    

Assumption here is also that solution(s) for each k are saved in pre-existing directories sols0, sols1, etc…

  1. Alternatively, if your code differs a lot from case-to-case, you might want to consider simply writing different scripts for different meshes (cases), i.e. main1.edp, main2.edp, etc., where each maink.edp works on meshk.edp, for k=0,1,…
    Then, at the end of the maink.edp script just add the command

    system("FreeFem++ main(k+1).edp");
    

This command will simply start running the next script after it finishes with the current. Assumption is that they are all in the same directory, but of course you can add path in above ‘system’ command to each script if you wish to keep them separate.

if

Hello,

Thanks alot for your response, your notes did solve my issue, I just have a few questions left here.
Why did you add (k+1) to your problem in - int2d(Th)((k+1)*(x+y)*vh); ? because I don’t want number of my mesh changes my equation.

I would like to explore more about the methods that you proposed to me, like changing names “mesh”+k+".msh" scripts , or defining folders system(“FreeFem++ main(k+1).edp”); May you introduce more examples or training on the freefem tutorials website so that I can read? I couldn’t find it myself.

My other question is that do you know how can I use shell scripting for this problem?

Best regards.

you can passe argument to freefem+= script
like

  include "getARGV.idp"
  int k=getARGV("-k",1);// default value 1. 
  real rho = getARGV("-rho",3.14);// default value 3.14 
  mesh Th= “mesh”+k+".msh";

usage :

FreeFem++ your-script.edp -k 10 -rho 10.5

  1. No particular reason for putting k+1 - just to emphasize that your problem definition can be made parameter k dependent. Of course, if you run the same problem just on series of meshes (like in convergence study), clearly you can use the same “problem” definition.

  2. Here is the link to “system” command documentation Functions - but, basically, you can think of it just as executing a specific command from your terminal when your code reaches a certain execution point - in case I wrote above, at the end of the code. So you don’t have to do it by hand, rather, it will be automatically executed by your program. You can play around with it - I most commonly use it to start another script when one is finished and I run long simulations.

  3. I never tried to use shell scripting for something like your problem - it doesn’t seem impossible though. Maybe rather explore your options with passing argument to your script as explained in Continues simulations - #4 by frederichecht .

if