Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all articles
Browse latest Browse all 26527

Variable exchange between Matlab and Comsol

$
0
0
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

Viewing all articles
Browse latest Browse all 26527

Trending Articles