Lars Gregersen
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Oct 11, 2023, 3:00 a.m. EDT
Hi Jehyeok
If you need to perform postprocessing on the entire solution of a Comsol model the only way to do that is to have access to the solved Comsol model. The only way to save such a model is to save it as an MPH-file.
If you have an idea of what data you need for postprocessing I suggest that you extract that data using mphinterp or one of the many other functions for extracting numerical data. Once such data have been extracted you can save the data in MAT-files.
If you to extract plots as plotdata you can do:
pd = mphplot(model, ...)
which will return the data in the pd-variable. Thd pd-variable can be saved in a MAT-file. You can inspect the data in pd or you can perform a plot later using this command:
mphplot(pd)
-------------------
Lars Gregersen
Comsol Denmark
Hi Jehyeok
If you need to perform postprocessing on the entire solution of a Comsol model the only way to do that is to have access to the solved Comsol model. The only way to save such a model is to save it as an MPH-file.
If you have an idea of what data you need for postprocessing I suggest that you extract that data using mphinterp or one of the many other functions for extracting numerical data. Once such data have been extracted you can save the data in MAT-files.
If you to extract plots as plotdata you can do:
pd = mphplot(model, ...)
which will return the data in the pd-variable. Thd pd-variable can be saved in a MAT-file. You can inspect the data in pd or you can perform a plot later using this command:
mphplot(pd)
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Oct 23, 2023, 11:15 a.m. EDT
Updated:
1 year ago
Oct 23, 2023, 11:20 a.m. EDT
Hi Jehyeok
If you need to perform postprocessing on the entire solution of a Comsol model the only way to do that is to have access to the solved Comsol model. The only way to save such a model is to save it as an MPH-file.
If you have an idea of what data you need for postprocessing I suggest that you extract that data using mphinterp or one of the many other functions for extracting numerical data. Once such data have been extracted you can save the data in MAT-files.
If you to extract plots as plotdata you can do:
pd = mphplot(model, ...)
which will return the data in the pd-variable. Thd pd-variable can be saved in a MAT-file. You can inspect the data in pd or you can perform a plot later using this command:
mphplot(pd)
Thank you for your answer, Lars!
Do you have any plan to add the function to save the whole simulated model as mat file?
If I simulate with for loops, it will save mph files as many as the for loops. Therefore, it would be very helpful if I can save each model as an element of a cell.
For example,
clear
format long
import com.comsol.model.*
import com.comsol.model.util.*
ModelUtil.showProgress(true);
model=mphload('file.mph');
modelArray = cell(N);
for i 1:N
model.param.set('X parameter',i);
model.study('std1').run;
modelArray{i}=model;
end
Then, postprocessing at anytime later with i-th element of modelArray.
>Hi Jehyeok
>
>If you need to perform postprocessing on the entire solution of a Comsol model the only way to do that is to have access to the solved Comsol model. **The only way to save such a model is to save it as an MPH-file.**
>
>If you have an idea of what data you need for postprocessing I suggest that you extract that data using mphinterp or one of the many other functions for extracting numerical data. Once such data have been extracted you can save the data in MAT-files.
>
>If you to extract plots as plotdata you can do:
>pd = mphplot(model, ...)
>which will return the data in the pd-variable. Thd pd-variable can be saved in a MAT-file. You can inspect the data in pd or you can perform a plot later using this command:
>mphplot(pd)
Thank you for your answer, Lars!
Do you have any plan to add the function to save the whole simulated model as mat file?
If I simulate with for loops, it will save mph files as many as the for loops. Therefore, it would be very helpful if I can save each model as an element of a cell.
For example,
clear
format long
import com.comsol.model.*
import com.comsol.model.util.*
ModelUtil.showProgress(true);
model=mphload('file.mph');
modelArray = cell(N);
for i 1:N
model.param.set('X parameter',i);
model.study('std1').run;
modelArray{i}=model;
end
Then, postprocessing at anytime later with i-th element of modelArray.
Lars Gregersen
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Oct 24, 2023, 2:32 a.m. EDT
Updated:
1 year ago
Nov 7, 2023, 4:17 a.m. EST
Hi Jehyeok
Your code will not work. Not today or in the future.
The reason is that the model variable doesn't contain the model at all. It is simply a variable that points to a model which lives in the COMSOL Multiphysics server.
Extracting results from a Comsol model requires that the model settings, its geometry and mesh as well as the physics and shape functions are processed when you ask Comsol to return some data. There is no way that all this information can be saved into a MAT-file and expect that the MAT-file would be smaller than the corresponding MPH-file.
You can perhaps reduce the size of your MPH-files by using some of the suggestions mentioned on one of these pages:
https://www.comsol.com/support/learning-center/article/How-to-Reduce-the-Size-of-Your-Model-File-59711
https://www.comsol.com/support/learning-center/article/Reducing-the-Amount-of-Solution-Data-Stored-in-a-Model-67151.
For mphsave you can use the optimize argument.
The best option remains to extract any numerical results just after having solved the model.
-------------------
Lars Gregersen
Comsol Denmark
Hi Jehyeok
Your code will not work. Not today or in the future.
The reason is that the model variable doesn't contain the model at all. It is simply a variable that points to a model which lives in the COMSOL Multiphysics server.
Extracting results from a Comsol model requires that the model settings, its geometry and mesh as well as the physics and shape functions are processed when you ask Comsol to return some data. There is no way that all this information can be saved into a MAT-file and expect that the MAT-file would be smaller than the corresponding MPH-file.
You can perhaps reduce the size of your MPH-files by using some of the suggestions mentioned on one of these pages:
https://www.comsol.com/support/learning-center/article/How-to-Reduce-the-Size-of-Your-Model-File-59711
https://www.comsol.com/support/learning-center/article/Reducing-the-Amount-of-Solution-Data-Stored-in-a-Model-67151.
For mphsave you can use the optimize argument.
The best option remains to extract any numerical results just after having solved the model.