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.

using a time dependent function

Please login with a confirmed email address before reporting spam

Hi

I'm trying to use a time dependent boundary condition with matlab. I need to simulate a boundary condition that change in a fixed sampling time, for example, every 15 seconds the value in the boundary condition changes. These values of boundary conditions are in a data file of matlab. I made the following code:

I initialize the variables c = 0 and n =1 in the workspace of matlab

function out = myfunction(t)
global Vector n c; % global variables
load('Data.mat') % load my Vector

if t == c
c = c + 15;
n = n+1;
end

out = Vector(n,1);


the argument of the function is the time (t) of the comsol simulation, but the comsol simulation does not work.
Anyone can say me if the time (t) in comsol is a 1x1 parameter? because in my matlab function I'm trying to compare the time with a 1x1 value, maybe this is causing the error.


kind regards

Geovani

4 Replies Last Post 5 nov 2012, 05:43 GMT-5
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 31 ott 2012, 15:59 GMT-4
Hi

there can be several issues, one that strikes me is that depending on your mdel, by applying dirac functions like that (boundary values changes abruptly, your are exciting many "modes" and your solver might go unstable. It's far better to use smoothed steps, as for the rect() function in the COMSOL GUI, these are based on the Heaviside step functions, that provide derivable functions over a steep transition.

Then you must ensure your model is not responding by oscillating for rapid boundary changes, in "solid" this can be improved, by ignoring the inertial terms (2nd time derivative values of the driving equations)

--
Good luck
Ivar
Hi there can be several issues, one that strikes me is that depending on your mdel, by applying dirac functions like that (boundary values changes abruptly, your are exciting many "modes" and your solver might go unstable. It's far better to use smoothed steps, as for the rect() function in the COMSOL GUI, these are based on the Heaviside step functions, that provide derivable functions over a steep transition. Then you must ensure your model is not responding by oscillating for rapid boundary changes, in "solid" this can be improved, by ignoring the inertial terms (2nd time derivative values of the driving equations) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 1 nov 2012, 19:20 GMT-4
Hi Ivar,


I made some tests trying to use constant boundary values from matlab, and I conclude that the interface is not working. I declared a vector with the same value in all lines and I made the algorithm to change the line every sampling time. I think that the global variables c, n are not working. I have no idea how I can simulate this conditions.

With a rect() function I can't reproduce the same values that are stored in the data file.

best regards
Hi Ivar, I made some tests trying to use constant boundary values from matlab, and I conclude that the interface is not working. I declared a vector with the same value in all lines and I made the algorithm to change the line every sampling time. I think that the global variables c, n are not working. I have no idea how I can simulate this conditions. With a rect() function I can't reproduce the same values that are stored in the data file. best regards

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 5 nov 2012, 04:52 GMT-5
Hi Geovani,

I'm using a time dependent boundary condition and it perfectly works.

I suggest you to start programming an easier case, for instance a ramp function. Of course you can define everything in Matlab, and I believe is far better to define a continuous function instead than a discrete number of values. So, try to define an analytical function.

Coming back to your question, I'm not sure if I understood what you're asking.... Mind that the variable time t is a scalar which varies into its domain, then is discretized to be a scalar function which varies into its discretized domain. In Matlab the discretization is really easy since you just have to define a range of values of t. This is done in the model.sol sequence when defining a range for the feature 'tlist'. I didn't get what you mean with "compare the time with a 1x1 value", but all you can do is to play with the syntax range(t1,t2,dt)

Hope it helps!
Mattia
Hi Geovani, I'm using a time dependent boundary condition and it perfectly works. I suggest you to start programming an easier case, for instance a ramp function. Of course you can define everything in Matlab, and I believe is far better to define a continuous function instead than a discrete number of values. So, try to define an analytical function. Coming back to your question, I'm not sure if I understood what you're asking.... Mind that the variable time t is a scalar which varies into its domain, then is discretized to be a scalar function which varies into its discretized domain. In Matlab the discretization is really easy since you just have to define a range of values of t. This is done in the model.sol sequence when defining a range for the feature 'tlist'. I didn't get what you mean with "compare the time with a 1x1 value", but all you can do is to play with the syntax range(t1,t2,dt) Hope it helps! Mattia

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 5 nov 2012, 05:43 GMT-5
Hi Mattia,

thanks for the help. I tryed to make the simulation in matlab, but I have a problem with the initial values, if you can see, I post this in the next link:

www.comsol.com/community/forums/general/thread/32751/#p89649

Did you have this problem ?

best regards
Hi Mattia, thanks for the help. I tryed to make the simulation in matlab, but I have a problem with the initial values, if you can see, I post this in the next link: http://www.comsol.com/community/forums/general/thread/32751/#p89649 Did you have this problem ? best regards

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.