MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
263 stars 67 forks source link

How to set initial conditions by MPh? #84

Closed LPW0351 closed 2 years ago

LPW0351 commented 2 years ago

Hi!

I recently wanted a way to automate the simulation of comsol files with different initial conditions under the same operating conditions. I tried to use the shell script under Linux, but it doesn't seem to work, so can MPh set different initial conditions?

Note: For example, for a plasma simulation program, under the same working condition, by setting different initial electron densities, initial electron average energy, and potential, assuming that 10,000 initial conditions are determined, how to realize automatic operation?

Thank you very much! Pw L

kkorhone commented 2 years ago

I did all that by setting up the initial conditions under the COMSOL GUI and then saving as M file. Then you can take out the MATLAB code that sets up the initial conditions and port it to Python very easily. Same can be done by saving as Java and porting the Java code to Python.

LPW0351 commented 2 years ago

OK! Thanks again for your reply, I will try it.

max3-2 commented 2 years ago

This should be a perfect use case. Just build your model using mph or the GUI (whatever suits you better). Probably include an export node. then load the Mph file in python and reference the node using the Node class. Start your loop and adapt the sub node and run and export (eg using another node reference). Do this as often as needed. You might want to use multi threading, an example exists in the docs