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.
Time dependant coefficients in Livelink for Matlab
Posted Jun 5, 2012, 9:19 a.m. EDT 5 Replies
Please login with a confirmed email address before reporting spam
I am a new user of COMSOL and currently trying to use COMSOL Livelink for Matlab in order to run simulations.
I am planning on using the coefficient form PDE functions in my simulations. As a curiosity, my question is quite simple, but I haven't been able to find any answers in this discussion forum.
I would like Comsol to solve a 2D-coefficient form PDE, whose coefficients might depend on time t.
I'm just wondering if COMSOL is able to handle such a feature and how it could be done... For this reason, I could really use some documentation on this, or inspiring models where such a feature was implemented.
Thank you for your time,
Best regards,
Matt
Please login with a confirmed email address before reporting spam
Yes it is possible.
All models generated in COMSOL can be transferred to MATLAB, be it coefficient form or others. Of course you go to matlab provided you want to do things that cannot be easily or efficiently implemented within COMSOL GUI.
I think (but I cannot guarantee as I don't know your work) it is not difficult for you to solve equations with time dependent coefficients. This can be done explicitly in MATLAB by storing previous time step values in an array and calling them in subsequent time steps. This is one approach.
It can also be done in COMSOL GUI itself if you choose to work with "time discrete solver" wherein you have prev(u,i) operator from which you can use previous time step values in the current time step (u is any expression that is a function of time). This is available in the manual. There is also '"at" and "with" operators, which you can read yourself from the manual. There are also many threads that tell you how to do this exactly.
May be there are other ways too.
Hope this helps.
Suresh
Please login with a confirmed email address before reporting spam
Thank you for your answer !
Hi,
Yes it is possible.
All models generated in COMSOL can be transferred to MATLAB, be it coefficient form or others. Of course you go to matlab provided you want to do things that cannot be easily or efficiently implemented within COMSOL GUI.
I think (but I cannot guarantee as I don't know your work) it is not difficult for you to solve equations with time dependent coefficients. This can be done explicitly in MATLAB by storing previous time step values in an array and calling them in subsequent time steps. This is one approach.
It sound quite messy. I'm still wondering if instead of setting constant values to the coefficient, we could instead set a time-dependant function. Something similar to pdepe, somehow.
www.mathworks.fr/help/techdoc/ref/pdepe.html
It can also be done in COMSOL GUI itself if you choose to work with "time discrete solver" wherein you have prev(u,i) operator from which you can use previous time step values in the current time step (u is any expression that is a function of time). This is available in the manual. There is also '"at" and "with" operators, which you can read yourself from the manual. There are also many threads that tell you how to do this exactly.
Sounds great. Which manual are you talking about ? Been searching for it yesterday and haven't found precisely, which one, you were talking about... The API Guide ?
May be there are other ways too.
Hope this helps.
Suresh
Matt
Please login with a confirmed email address before reporting spam
In COMSOL GUI, under help, just type prev() and you will get to know. Because everything in the manual can also be accessed through the GUI help, at least that is what I realise.
Also please download a file that Niklas Rom (from COMSOL) had uploaded into this discussion forum in response to a query concerning time discrete solver.
Suresh
Please login with a confirmed email address before reporting spam
Have a nice day,
Matt
Please login with a confirmed email address before reporting spam
I am stuck again, when it comes down to defining time/space-dependant coefficients in livelink...
Basically, I would like to define a coefficient which will depend on time and space variables in the coefficient form PDE case.
Space and time have been "meshed" into a grid like this. I haven't encountered any issue with the grid.
t_set = [0:0.02:1];
x_set = [0:0.02:1];
y_set = [0:0.02:1];
At this point I need to define a function fun1, which basically returns a coefficient in a 3D-Matrix m_(x,y,t) whose size is length(t_set) * length(x_set) * length(y_set).
This m_ matrix does not depend on the differential equation to be solved. We assume, it is known at the beginning.
out = fun1(t,x,y)
t_num = find(t_set>t,1);
if isempty(t_num)
t_num = length(t_set);
end
x_num = find(x_set>x,1);
if isempty(t_num)
x_num = length(x_set);
end
y_num = find(y_set>y,1);
if isempty(y_num)
y_num = length(y_set);
end
out = m_(x_num, y_num, t_num)
end
Basically, I would like to do this kind of thing.
model.physics('c').feature('cfeq1').set('a', 1, 'fun1(t,x,y)');
But it does not work... I've been reading the manual about the at(), with() and prev() operators as advised by Suresh, but I don't see how it could help me on this. I simply don't get it.
Any simple illustrative example ? Any lead that could help me on this ?
Thank you for your time.
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.
Suggested Content
- FORUM Time dependant signal at inlet
- KNOWLEDGE BASE Problems Launching COMSOL Server™ 5.3 with MATLAB®
- KNOWLEDGE BASE Error: Failure Loading MATLAB Libraries. This model requires that MATLAB is available.
- KNOWLEDGE BASE COMSOL Does Not Start with the Latest MATLAB Version
- BLOG Studying the Migration of Mineral Oil Hydrocarbons in Food Packaging