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.

problem in initial value in matlab

Please login with a confirmed email address before reporting spam

Hi

I'm simulating a model in matlab for a sampling time 3 s. After this i use the last simulation as initial condition for the next iteration. I use the following code (as the tutorial):

for k = 1:nit
model.study('std1').run;
temp = mpheval(model,'T','edim','edge','selection',3);


% update initial time for next iteration
t0 = mphglobal(model,'t','solnum','end');
model.param.set('t0',t0);

% initial condition for the next iteration
model.physics('nipfl').feature('init1').set('p', 1, 'p');
model.physics('nipfl').feature('init1').set('u', 1, 'u');
model.physics('nipfl').feature('init1').set('T', 1, 'T');
model.physics('ge').feature('init1').set('Tm',1, 'Tm');
v1 = model.sol('sol1').feature('v1');
v1.set('initsol', 'sol1');

data = [data;temp.d1(end,3)]; % store in a vector the output

end


My dependent variables are p, u, T and Tm, as can be seen. But when I plot the temperature i have a wrong result (blue line).

I compare this result with other simulation, without use a loop 'for' (in red line). For this case I run the model from time = 0 to time final, don't using the interpolation.

The image is in attach.

Anyone have the same problem?

best regards

Geovani


1 Reply Last Post 6 nov. 2012, 03:53 UTC−5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 6 nov. 2012, 03:53 UTC−5
Hi Geovani,
very unlikely you'll find someone who has got the same problem of you, so (for the next time) I suggest you to formulate the question in a more general fashion :-)

I believe you are having problems when applying the initial conditions. To me the weird blue line sounds like numerical instability due, in your case, to the application of a not suitable initial conditions. What I image is that you have a solution for time t, and for t+1 you impose as a solution the field at time t. That's in principle obvious, but I guess you're doing it wrongly. To ensure this hypothesis of mine you can try to vary the time step's length.

My only suggestion, not that useful though, is to try with another simpler problem (maybe of lower dimension) and practise yourself with the technique of "using the last simulation as initial condition for the next iteration".

Hope it helps,
Mattia
Hi Geovani, very unlikely you'll find someone who has got the same problem of you, so (for the next time) I suggest you to formulate the question in a more general fashion :-) I believe you are having problems when applying the initial conditions. To me the weird blue line sounds like numerical instability due, in your case, to the application of a not suitable initial conditions. What I image is that you have a solution for time t, and for t+1 you impose as a solution the field at time t. That's in principle obvious, but I guess you're doing it wrongly. To ensure this hypothesis of mine you can try to vary the time step's length. My only suggestion, not that useful though, is to try with another simpler problem (maybe of lower dimension) and practise yourself with the technique of "using the last simulation as initial condition for the next iteration". Hope it helps, Mattia

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.