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.

when to use parameters, variables, and functions

Darin Bellisario
Hi All,

Considering global values for now.

It seems clear to me when to use parameters - any value that is independent of the independent or dependent variables. But when is it appropriate to use global variables, and global functions?

Thank you for any insight,

3 Replies Last Post Oct 18, 2012, 11:10 AM EDT
Posted: 5 years ago Oct 17, 2012, 2:27 PM EDT
Hi

this is an interesting issue, as it took me quite some time to get this (more or less) straight. In fact what I find confusing in COMSOL is that most if not all "variables" are in fact fields over (x,y,z,t ...). Even if often we write in a scalar it is "just" means to say that the field is a scalar and is invariant over the spatial and/or time domain.

Global variables was mainly variables that could be changed independetly of the model, or are integrated over the geometry (spatial dimension) of the model"n" .

Model variables are depenent on the specific model, hence are defined over part or all entities (domains, boundaries, edges, points ...

Parameters are constants that is evaluated once at solver run, but these might be overwritten by COMSOL later, this is handy to define some variables, such as "t" for time when you have specific equations dependeing on "t" but you mix time dependent and spatial solvers, and during stationary solvers "t" is not defined by default, only when you run a time dependent solver does COSMOl add in"t", except if you fix it once in the Parameters

So define in the Global section something that is indepedent of your model (geometry), but that you expect to change (as Variables); or what is to remain constant, as Parameter, and define all other variables locally.

Additionally Parameters can drive geometry dimensions and be referred to in the parametric sweep (Variables cannot)

Same principle for functions etc

As I'm not from COMSOL I might well have missed soemthing important, so whoever has other ideas, pls update, so I learn something new too :)

--
Good luck
Ivar
Hi this is an interesting issue, as it took me quite some time to get this (more or less) straight. In fact what I find confusing in COMSOL is that most if not all "variables" are in fact fields over (x,y,z,t ...). Even if often we write in a scalar it is "just" means to say that the field is a scalar and is invariant over the spatial and/or time domain. Global variables was mainly variables that could be changed independetly of the model, or are integrated over the geometry (spatial dimension) of the model"n" . Model variables are depenent on the specific model, hence are defined over part or all entities (domains, boundaries, edges, points ... Parameters are constants that is evaluated once at solver run, but these might be overwritten by COMSOL later, this is handy to define some variables, such as "t" for time when you have specific equations dependeing on "t" but you mix time dependent and spatial solvers, and during stationary solvers "t" is not defined by default, only when you run a time dependent solver does COSMOl add in"t", except if you fix it once in the Parameters So define in the Global section something that is indepedent of your model (geometry), but that you expect to change (as Variables); or what is to remain constant, as Parameter, and define all other variables locally. Additionally Parameters can drive geometry dimensions and be referred to in the parametric sweep (Variables cannot) Same principle for functions etc As I'm not from COMSOL I might well have missed soemthing important, so whoever has other ideas, pls update, so I learn something new too :) -- Good luck Ivar

Darin Bellisario
Posted: 5 years ago Oct 18, 2012, 10:54 AM EDT
Thanks Ivar, that is hugely helpful, and cleans up my model quite a bit. Now I'm using model variables for simple relations, and only need PDEs/ODEs for differential equations, its a much neater way of organizing things.
Thanks Ivar, that is hugely helpful, and cleans up my model quite a bit. Now I'm using model variables for simple relations, and only need PDEs/ODEs for differential equations, its a much neater way of organizing things.

Posted: 5 years ago Oct 18, 2012, 11:10 AM EDT
Hi

and I have just noticed that in V4.3a, the doc and help has been greatly updated, it given even more info, it's worth to reread the doc at each release ;)

OK I agree COMSOL could flag regions with updates somewhat, as everything is electronic now, but still the updates are extensive for each new version I see

--
Good luck
Ivar
Hi and I have just noticed that in V4.3a, the doc and help has been greatly updated, it given even more info, it's worth to reread the doc at each release ;) OK I agree COMSOL could flag regions with updates somewhat, as everything is electronic now, but still the updates are extensive for each new version I see -- Good luck Ivar

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.