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.

Materiel sweep and parametric sweep. Quick help appreciated?

Please login with a confirmed email address before reporting spam

I have simulation which runs materiel sweeps in the outside for loops and parametric sweep inside for loops. I have around ~500 possible cases for materiel sweeps and for each case, I want to run a parametric sweep with different 100 values. As the simulation move from the next material sweep case, I want to assign a new 100 list of parametric values. I am not sure how to proceed to next 100 new parametric values once the previous 100 values computed.


5 Replies Last Post 02.07.2020, 11:56 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 24.06.2020, 06:37 GMT-4

Hi Wabi,

So, do you have 500 lists of size (100,), all different, or is there a logic that connects them all ?

If there is a logic, in the parametric sweep, you can combine the range function with other functions and there is no problem with using material parameters into these expressions.

If you really have 500 lists that are totally independent, one solution would be to use the java API : simply export your model to java, then open the source code of a single parametric sweep and wrap it with a for loop written in java with 500 iterations. At the beginning of each iteration you can load the 100 values from a text file and proceed.

Hi Wabi, So, do you have 500 lists of size (100,), all different, or is there a logic that connects them all ? If there is a logic, in the parametric sweep, you can combine the `range` function with other functions and there is no problem with using material parameters into these expressions. If you really have 500 lists that are totally independent, one solution would be to use the java API : simply export your model to java, then open the source code of a single parametric sweep and wrap it with a `for` loop written in java with 500 iterations. At the beginning of each iteration you can load the 100 values from a text file and proceed.

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 24.06.2020, 13:41 GMT-4
Updated: 4 years ago 24.06.2020, 13:42 GMT-4

Hi Wabi,

So, do you have 500 lists of size (100,), all different, or is there a logic that connects them all ?

If there is a logic, in the parametric sweep, you can combine the range function with other functions and there is no problem with using material parameters into these expressions.

If you really have 500 lists that are totally independent, one solution would be to use the java API : simply export your model to java, then open the source code of a single parametric sweep and wrap it with a for loop written in java with 500 iterations. At the beginning of each iteration you can load the 100 values from a text file and proceed.

Hi Alexis, thank you for your reply!

They are totally independent.FYI, I am using GUI not familiar with Java(but will try study if it's mandatory). Let me explain it in a simple way(when we have only 2 material types). Let's forget about 500 cases for now! Let's say we have 2 different materials (mat#1, mat#2) and I defined 2 switch functions during material declaration and each switch function contains (Mat#1 and Mat#2). In "study node" I called material Sweep( Switch-1, range(1,1,2)), (Switch-2, range(1,1,2)). As the simulation runs for material sweeps, I can have a combination of (Mat#1,Mat#1), (Mat#1,Mat#2), (Mat#2, Mat#1) and (Mat#2, Mat#2). The first run of material sweeps, we have (Mat#1, Mat#1) Here, I have parametric sweeps that assign 100 geometry values for each material(Mat#1,Mat#1) The second run of material sweeps, we have (Mat#1, Mat#2) Here, I want to do parametric sweeps that assign new 100 geometry values(different from the previous) for each material(Mat#,Mat#2) And so on until the (Mat#2, Mat#2).

I want to implment the same thing when we have material comibination of 500.

>Hi Wabi, > >So, do you have 500 lists of size (100,), all different, or is there a logic that connects them all ? > >If there is a logic, in the parametric sweep, you can combine the `range` function with other functions and there is no problem with using material parameters into these expressions. > >If you really have 500 lists that are totally independent, one solution would be to use the java API : simply export your model to java, then open the source code of a single parametric sweep and wrap it with a `for` loop written in java with 500 iterations. At the beginning of each iteration you can load the 100 values from a text file and proceed. Hi Alexis, thank you for your reply! They are totally independent.FYI, I am using GUI not familiar with Java(but will try study if it's mandatory). Let me explain it in a simple way(when we have only 2 material types). Let's forget about 500 cases for now! Let's say we have 2 different materials (mat#1, mat#2) and I defined 2 switch functions during material declaration and each switch function contains (Mat#1 and Mat#2). In "study node" I called material Sweep( Switch-1, range(1,1,2)), (Switch-2, range(1,1,2)). As the simulation runs for material sweeps, I can have a combination of (Mat#1,Mat#1), (Mat#1,Mat#2), (Mat#2, Mat#1) and (Mat#2, Mat#2). The first run of material sweeps, we have (Mat#1, Mat#1) Here, I have parametric sweeps that assign 100 geometry values for each material(Mat#1,Mat#1) The second run of material sweeps, we have (Mat#1, Mat#2) Here, I want to do parametric sweeps that assign new 100 geometry values(different from the previous) for each material(Mat#,Mat#2) And so on until the (Mat#2, Mat#2). I want to implment the same thing when we have material comibination of 500.

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 25.06.2020, 08:13 GMT-4
Updated: 4 years ago 25.06.2020, 08:15 GMT-4

From your second message, I think using java would be much simpler than trying a complicated solution in comsol.

If you are familiar with a scripting language like MATLAB or python, use this to generate as many text files as you need, containing your parameter values. You can name these files 1.txt, 2.txt, 3.txt, ...

Then in COMSOL perform the following steps

  • File > Save as ... > Name : version_for_java_export.mph
  • Edit > Clear All Meshes
  • Edit > Clear All Solutions
  • File > Compact History
  • File > Save as ... > Name : modified_version.java , filetype : Model file for java

This creates a file modified_version.java in your working directory. If you open it in a text editor you can see all your settings graphical interface.

Then it is quite simple to write the java patch that will do what you want, but you will need a little bit of java knowledge for this. My advice would be to simply look-up for-loops, then how to read a file in java and finally go to the documentation for specific java-comsol interaction.

When you make a change to the java, once you have saved the .java you can compile using

comsol compile modified_version.java

this will create the file modified_version.class, which you can directly run from command line with

comsol batch -inputfile modified_version.class -batchlog logfile & then follow the log with tail -f logfile (assuming linux)

or you can open the .class from COMSOL as if it was a .mph file

From your second message, I think using java would be much simpler than trying a complicated solution in comsol. If you are familiar with a scripting language like MATLAB or python, use this to generate as many text files as you need, containing your parameter values. You can name these files `1.txt`, `2.txt`, `3.txt`, ... Then in COMSOL perform the following steps * `File` > `Save as ...` > Name : `version_for_java_export.mph` * `Edit` > `Clear All Meshes` * `Edit` > `Clear All Solutions` * `File` > `Compact History` * `File` > `Save as ...` > Name : `modified_version.java` , filetype : `Model file for java` This creates a file `modified_version.java` in your working directory. If you open it in a text editor you can see all your settings graphical interface. Then it is quite simple to write the java patch that will do what you want, but you will need a little bit of java knowledge for this. My advice would be to simply look-up for-loops, then how to read a file in java and finally go to the documentation for specific java-comsol interaction. When you make a change to the java, once you have saved the .java you can compile using `comsol compile modified_version.java` this will create the file `modified_version.class`, which you can directly run from command line with `comsol batch -inputfile modified_version.class -batchlog logfile &` then follow the log with `tail -f logfile` (assuming linux) or you can open the .class from COMSOL as if it was a .mph file

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 01.07.2020, 00:27 GMT-4

Hi Alexis Prel,

Thank you very much for your replay!

1).I understood why you suggested me to create multiple text files instead of reading a single text files that contains 1.txt, 2.txt, 3.txt...combined (java read text file line by line).I have no problem with creating these text files in Matlab. But it's also possible to provide temporary text file just to read 100 lines from my text files contains all input parameters.

2). I followed the steps you suggested me to create a java file for my model. Also not a hard task.

3). However, my model contains around 2000 lines of code (even after clearing all sol, mesh and compacting history). I went through the code line by line it's actually make sense.

4)For now, I tried to work with application builder because it is simple. I wrote some java on methods for paramteric sweep. I followed this steps explained in this link [https://www.comsol.kr/support/knowledgebase/1250#:~:text=The%20Parametric%20Sweep%20node%20is,for%20the%20COMSOL%20batch%20call.]
When I test my application it doesn't do paramteirc sweep instead it use the intial values I used when I created my parameters as Global Definitions. Any insight about this? I found application builder more user friendly as it compares to exporting all the model as java files.

Hi Alexis Prel, Thank you very much for your replay! 1).I understood why you suggested me to create multiple text files instead of reading a single text files that contains 1.txt, 2.txt, 3.txt...combined (java read text file line by line).I have no problem with creating these text files in Matlab. But it's also possible to provide temporary text file just to read 100 lines from my text files contains all input parameters. 2). I followed the steps you suggested me to create a java file for my model. Also not a hard task. 3). However, my model contains around 2000 lines of code (even after clearing all sol, mesh and compacting history). I went through the code line by line it's actually make sense. 4)For now, I tried to work with application builder because it is simple. I wrote some java on methods for paramteric sweep. I followed this steps explained in this link [https://www.comsol.kr/support/knowledgebase/1250#:~:text=The%20Parametric%20Sweep%20node%20is,for%20the%20COMSOL%20batch%20call.] When I test my application it doesn't do paramteirc sweep instead it use the intial values I used when I created my parameters as Global Definitions. Any insight about this? I found application builder more user friendly as it compares to exporting all the model as java files.

Please login with a confirmed email address before reporting spam

Posted: 4 years ago 02.07.2020, 11:56 GMT-4

Hi Alexis Prel I figured something out. Thank you for your help.

Hi Alexis Prel I figured something out. Thank you for your help.

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.