Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

How to use previous solution as a initial condition in time dependent PDE with parametric sweep

Please login with a confirmed email address before reporting spam

I want to run parametric sweep on a time dependent PDE problem. During each parameter I want to set previous solution as a initial condition. I did it as attached. But in that case I have to manually change the parameter and run the simulation again and again for different parameter. I want to automate the process and do it in a parametric sweep.How can I do that?



1 Reply Last Post May 25, 2019, 6:46 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 6 years ago May 25, 2019, 6:46 a.m. EDT
Updated: 6 years ago May 25, 2019, 7:07 a.m. EDT

Hi Manula,

Have a look at the withsol and setval operators. By using them in the Initial conditions entry of your physics, you might be able to get what you want.

Another option which will give you far more control is to save your model as a java program and modify it to include a loop over your settings. Here are the steps for doing that:

  1. Compact the model's history (File > Compact History)
  2. Save your model as a java file (File > Save As > Model File for Java)
  3. Open the newly created java file with a text editor, or ideally with Eclipse, if you have that installed. This contains all the instructions to create your model
  4. Use the tags to navigate the file. You can look at the tags of the nodes of your model builder, by clicking the arrow at the top of the model builder window and ticking the "Tag" checkbox. see_tag
  5. Figure out which lines correspond to the settings you performed manually. To get help with that go in the graphical interface to the node you modified. Do a right click and select Copy as code to clipboard > Create and Copy as code to clipboard > Set All. Paste this into a text editor to see the corresponding java code. You can then search for these lines in your main java file. copy_code
  6. Add a loop to apply these settings repeatedly. You may or may not want to comment out all the .run() calls, which actually run computations.
  7. Once you are happy with your changes, save the java and compile it by running comsol compile name_of_your_file.java If all goes well this will create name_of_your_file.class
  8. Run the model by calling comsol batch -inputfile name_of_your_file.class. It will trigger calculations if a .run() method is present in your java. At the end, the model will be saved to name_of_your_file.mph
  9. Open the resulting mph in the graphical interface and check that the settings are what you intended.
  10. For more information see the programming reference manual

I know it looks like a lot, but once you get the hang of it, this is very easy and will allow you to automate anything you used to do manually with COMSOL.

Hi Manula, Have a look at the `withsol` and `setval` operators. By using them in the **Initial conditions** entry of your physics, you might be able to get what you want. Another option which will give you far more control is to save your model as a java program and modify it to include a loop over your settings. Here are the steps for doing that: 1. Compact the model's history (`File > Compact History`) 2. Save your model as a java file (`File > Save As > Model File for Java`) 3. Open the newly created java file with a text editor, or ideally with Eclipse, if you have that installed. This contains all the instructions to create your model 4. Use the tags to navigate the file. You can look at the tags of the nodes of your model builder, by clicking the arrow at the top of the model builder window and ticking the "Tag" checkbox. ![see_tag](https://i.ibb.co/MkRJ780/see-tag.png) 6. Figure out which lines correspond to the settings you performed manually. To get help with that go in the graphical interface to the node you modified. Do a right click and select `Copy as code to clipboard > Create` and `Copy as code to clipboard > Set All`. Paste this into a text editor to see the corresponding java code. You can then search for these lines in your main java file. ![copy_code](https://i.ibb.co/thm4p4r/copy-code-to-clipboard.png) 7. Add a loop to apply these settings repeatedly. You may or may not want to comment out all the `.run()` calls, which actually run computations. 8. Once you are happy with your changes, save the java and compile it by running `comsol compile name_of_your_file.java` If all goes well this will create `name_of_your_file.class` 9. Run the model by calling `comsol batch -inputfile name_of_your_file.class`. It will trigger calculations if a `.run()` method is present in your java. At the end, the model will be saved to `name_of_your_file.mph` 10. Open the resulting mph in the graphical interface and check that the settings are what you intended. 11. For more information see the programming reference manual I know it looks like a lot, but once you get the hang of it, this is very easy and will allow you to automate anything you used to do manually with COMSOL.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.