Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

scripting import and interpolation of solution

Please login with a confirmed email address before reporting spam

Hi all,

I'm attempting to automate a series of time-dependent 3D simulations, in which the geometry changes from one simulation to the next, but the final distribution of the dependent variable from one simulation should be the initial condition for the next one.

The geometry is set by a matlab script, but due to some memory issues in COMSOL (v 4.1, I haven't rewritten the code sonce 4.2 to try whether they've been solved) the only way to convert the matlab-made geometry to COMSOL is piece by piece, exiting and entering COMSOL after each bit, so as not to encounter the memory problem. Once the geometry is assembled, it is saved as a mphbin file.

Now here's my problem: I'd like to take this saved geometry, mesh it, and interpolate the previous solution onto its mesh. I cannot find a way, however, to import the solution exported by a previous COMSOL simulation. I could perhaps simply read a solution report to a set of matlab variables (coordinates and data) and try write a function using matlab's interp3 to set the initial values from that as f(x,y,z). I'm unclear, however, as to the proper way to set the outputs up so that the they are in the right shape to be used as initial values.

Alternatively, I could try to open up the model with the solution, import the geometry and try mesh it, then interpolate the previous solution to create the initial values with mphinterp (by the way, I have the same issue as with interp3 here: I'm not sure how to reshape the mphinterp outputs so they can be used as initial values), and solve on the new mesh. I'm not sure which of these approaches, if either, works with the way COMSOL is conceived.

Does anyone know of a successful approach to this or a similar problem?

Thanks,
Martin


6 Replies Last Post 12 mai 2012, 15:49 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 août 2011, 11:44 UTC−4
Actually a solution that works well for me seems to be defining an interpolation function, defined over a spreadsheet file, created by exporting data from the results of a previous simulation. Much simpler than I had anticipated - it was just a question of finding the right tool in the API guide.

Martin
Actually a solution that works well for me seems to be defining an interpolation function, defined over a spreadsheet file, created by exporting data from the results of a previous simulation. Much simpler than I had anticipated - it was just a question of finding the right tool in the API guide. Martin

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 24 août 2011, 12:04 UTC−4
Martin, I'm interested in this. I am doing a transient analysis in which the topology of one domain changes with each time step due to another domain traversing through it, the latter's position being a function of time. Do you have any recommendations or have you hit any roadblocks for using the previous time step solution as the initial condition for subsequent steps?

Thanks.
Martin, I'm interested in this. I am doing a transient analysis in which the topology of one domain changes with each time step due to another domain traversing through it, the latter's position being a function of time. Do you have any recommendations or have you hit any roadblocks for using the previous time step solution as the initial condition for subsequent steps? Thanks.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 déc. 2011, 11:39 UTC−5
Best way is to use the COMSOL_-MATLAB interface. Export data at each run. Create new data file after moving coordinates( x, y, z, T) to new (x', y' z', T). Use interpolation function to read this file in subsequent run for initialization.
With best wishes,
Sohan
Best way is to use the COMSOL_-MATLAB interface. Export data at each run. Create new data file after moving coordinates( x, y, z, T) to new (x', y' z', T). Use interpolation function to read this file in subsequent run for initialization. With best wishes, Sohan

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22 déc. 2011, 04:50 UTC−5
Hi, I'm wondering if I'm missing something about using an updated file within an interpolation function. I'm hoping this relates to what everyone here is discussing; otherwise I apologize for the thread-jacking.

Currently, I have an interpolation function created from a 3D spreadsheet text file. This works how I think it should. Now, what I want to be able to do is update the text file and have the interpolation function access the updated version whenever I run the Comsol model. However, when I try this with an updated text file, it appears that the original spreadsheet is saved within the Comsol model, and Comsol does not access the external file when run again.

I have tried this using the GUI and running batch from the command prompt. I've also attempted to use the Java API (re-compiling and running every time I update the text file but keep the name/location the same), but, again, it seems that the original text file is saved within the model.

Unfortunately, using Matlab is not logistically possible. I'm intending for the Comsol model to be a module within a larger Fortran model. Updating a Java file is fine, but Matlab is not.
Hi, I'm wondering if I'm missing something about using an updated file within an interpolation function. I'm hoping this relates to what everyone here is discussing; otherwise I apologize for the thread-jacking. Currently, I have an interpolation function created from a 3D spreadsheet text file. This works how I think it should. Now, what I want to be able to do is update the text file and have the interpolation function access the updated version whenever I run the Comsol model. However, when I try this with an updated text file, it appears that the original spreadsheet is saved within the Comsol model, and Comsol does not access the external file when run again. I have tried this using the GUI and running batch from the command prompt. I've also attempted to use the Java API (re-compiling and running every time I update the text file but keep the name/location the same), but, again, it seems that the original text file is saved within the model. Unfortunately, using Matlab is not logistically possible. I'm intending for the Comsol model to be a module within a larger Fortran model. Updating a Java file is fine, but Matlab is not.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22 déc. 2011, 11:10 UTC−5
I found a work around for what I'm doing.

My original spreadsheet file is named "spreadsheet1.txt."
I run Comsol using the Java file ("file.java") with the line (compiling first)

model.func("int1")
.set("filename", "spreadsheet1.txt");

Then I make changes to the spreadsheet and save it with the name "spreadsheet2.txt."

Then, I can change the line in "file.java" to read

model.func("int1")
.set("filename", "spreadsheet2.txt");

Re-compile and run again and repeat.

I found a work around for what I'm doing. My original spreadsheet file is named "spreadsheet1.txt." I run Comsol using the Java file ("file.java") with the line (compiling first) model.func("int1") .set("filename", "spreadsheet1.txt"); Then I make changes to the spreadsheet and save it with the name "spreadsheet2.txt." Then, I can change the line in "file.java" to read model.func("int1") .set("filename", "spreadsheet2.txt"); Re-compile and run again and repeat.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 12 mai 2012, 15:49 UTC−4
Hi Sohan,
Is "T" , the arc length between each two points? I am working with comsol4.2a and in that version there is only two columns defined in the "interpolation function". Would you please let me know how can I define the arc length?
Thanks,
Atefeh
Hi Sohan, Is "T" , the arc length between each two points? I am working with comsol4.2a and in that version there is only two columns defined in the "interpolation function". Would you please let me know how can I define the arc length? Thanks, Atefeh

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.