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.
Variable exchange between Matlab and Comsol
Posted 18 janv. 2013, 11:35 UTC−5 Interfacing Version 4.2a 4 Replies
Please login with a confirmed email address before reporting spam
Hello everyone,
I am running Comsol using the LiveLink with Matlab and am trying to do the following:
I have a value, dt, which is 0 everywhere in the beginning.
(I can either use dt=0, make an interpolation file x,y,dt(x,y), maybe make a Matlab fct.,...)
I run Comsol the first time.
Now, I use results ct calculated from the Matlab run to compute new dt values:
ct = mpheval(model, ct) // this also gives me access to the coordinates of the mesh points...
dt_new = f(ct.d1) // any function really
But how do I get Comsol to take dt_new at each meash point for the next run?!?
I've tried:
a) Using a simple variable dt.
Reassigning dt values by setIndex and using same indices as mpheval gives me.
--> Doesn't work.
b) Using an interpolation function reading dt.txt which contains: x y dt, initially: 0:1:x_max, 0:1:y_max, 0
Rewrite dt.txt to read: ct.p(1,:), ct.p(2,:), f(ct.d1)=dt_new (obtained by mpheval & Matlab calculation)
Now I have tried to: importData for the interpolation again, remove the interpolation & create a new one etc.
None of this works. It either gives weird errors (remove & create, importData) or doesn't do anything
(use solely setIndex)
What am I doing wrong in b)?
Or do I want to use a Matlab function under global definitions in Comsol?
(But how do I make that access values from a previous Matlab run?!?)
The problem to me seems to be simple:
Assign value dt=0 to mesh points. Run Comsol.
Get value ct at each mesh point. Calculate dt based on ct. Assign value dt to each mesh point. Run Comsol again.
It is straightforward to access the results at each mesh point.
Why is it so hard to assign values to mesh points for the next run?
Thanks in advance for any help.
Greets,
Thorsten
I am running Comsol using the LiveLink with Matlab and am trying to do the following:
I have a value, dt, which is 0 everywhere in the beginning.
(I can either use dt=0, make an interpolation file x,y,dt(x,y), maybe make a Matlab fct.,...)
I run Comsol the first time.
Now, I use results ct calculated from the Matlab run to compute new dt values:
ct = mpheval(model, ct) // this also gives me access to the coordinates of the mesh points...
dt_new = f(ct.d1) // any function really
But how do I get Comsol to take dt_new at each meash point for the next run?!?
I've tried:
a) Using a simple variable dt.
Reassigning dt values by setIndex and using same indices as mpheval gives me.
--> Doesn't work.
b) Using an interpolation function reading dt.txt which contains: x y dt, initially: 0:1:x_max, 0:1:y_max, 0
Rewrite dt.txt to read: ct.p(1,:), ct.p(2,:), f(ct.d1)=dt_new (obtained by mpheval & Matlab calculation)
Now I have tried to: importData for the interpolation again, remove the interpolation & create a new one etc.
None of this works. It either gives weird errors (remove & create, importData) or doesn't do anything
(use solely setIndex)
What am I doing wrong in b)?
Or do I want to use a Matlab function under global definitions in Comsol?
(But how do I make that access values from a previous Matlab run?!?)
The problem to me seems to be simple:
Assign value dt=0 to mesh points. Run Comsol.
Get value ct at each mesh point. Calculate dt based on ct. Assign value dt to each mesh point. Run Comsol again.
It is straightforward to access the results at each mesh point.
Why is it so hard to assign values to mesh points for the next run?
Thanks in advance for any help.
Greets,
Thorsten
4 Replies Last Post 15 juil. 2013, 05:00 UTC−4