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.

expression

Please login with a confirmed email address before reporting spam

Hello

I am doing an electrostatic simulation and I would like to plot the intensity of the electric field ||E|| (surface), as well as the Gradient of this intensity squared (arrows or streamlines).

Is there a way to defined such a quantity globally (like in "derived values" / "global evaluation") such that it is then available for selection in the "add expression" / "replace expression" button-menus in the Expression secion of the Surface-, Arrow- etc. nodes in a plot group?

6 Replies Last Post 22 juil. 2010, 12:11 UTC−4
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 21 juil. 2010, 04:11 UTC−4
Hi

what about defining a variable (global variable in 3.5a) and use this ?

--
Good luck
Ivar
Hi what about defining a variable (global variable in 3.5a) and use this ? -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 21 juil. 2010, 05:11 UTC−4
Thank you. I only have version 4.0 but I tried it nevertheless. It does not seem to work. I cannot select the variable for plotting and if I write it in the expression field, it is not recognized.

What is puzzling me is I have seen on some forum discussions, that other people who are plotting field intensity are discussing about a predefined expression "normE". I have displacement intensity "normD" in my expression list but NOT normE! Is that not strange?
Thank you. I only have version 4.0 but I tried it nevertheless. It does not seem to work. I cannot select the variable for plotting and if I write it in the expression field, it is not recognized. What is puzzling me is I have seen on some forum discussions, that other people who are plotting field intensity are discussing about a predefined expression "normE". I have displacement intensity "normD" in my expression list but NOT normE! Is that not strange?

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 21 juil. 2010, 07:05 UTC−4
Hi,

Regarding es.normE: It was missing as a predefined variable in 4.0 but is available in 4.0a. You should have received an upgrade to 4.0a or should get one anyday now.

In 4.0, you can define it yourself as a variable using the same expression as in 4.0a:

sqrt(realdot(es.Ex,es.Ex)+realdot(es.Ey,es.Ey)+realdot(es.Ez,es.Ez))

The variable becomes available for plotting and evaluation after re-computing or updating the solution.
You find the variable in the list of predefined expressions but under Definitions (not Electrostatics). If you provide a description, COMSOL uses that and it appears among the other expressions in alphabetical order; otherwise the variable name appears within parentheses.

For plots that take vector inputs you must use the defined variables directly in the edit fields for the vector components. There is no support for grouping user-defined variables and declare them as components of a vector quantity.

Best regards,

Magnus Ringh
COMSOL
Hi, Regarding es.normE: It was missing as a predefined variable in 4.0 but is available in 4.0a. You should have received an upgrade to 4.0a or should get one anyday now. In 4.0, you can define it yourself as a variable using the same expression as in 4.0a: sqrt(realdot(es.Ex,es.Ex)+realdot(es.Ey,es.Ey)+realdot(es.Ez,es.Ez)) The variable becomes available for plotting and evaluation after re-computing or updating the solution. You find the variable in the list of predefined expressions but under Definitions (not Electrostatics). If you provide a description, COMSOL uses that and it appears among the other expressions in alphabetical order; otherwise the variable name appears within parentheses. For plots that take vector inputs you must use the defined variables directly in the edit fields for the vector components. There is no support for grouping user-defined variables and declare them as components of a vector quantity. Best regards, Magnus Ringh COMSOL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22 juil. 2010, 05:40 UTC−4


Excellent, this is exactly what I was looking for. But there is still a problem. If I use the variable (dubbed normE) as a plot expression I get an error "failed to evaluate variable" a screenshot of the error message dialog is attached. If I replace "normE" by "sqrt(realdot(es.Ex,es.Ex)+realdot(es.Ey,es.Ey)+realdot(es.Ez,es.Ez))" in the expression field the plot works without error.

Another thing is maybe unimportant but still... if I define an expression in a plot then comsol automatically computes the corresponding unity (V/m etc.). But when I define a Variable under "global definitions" it doesn't. Is this a hint that it doesn't recognize the names (es.Ez etc.) used in defining the variable?

Too bad that comsol does not allow the grouping of user-defined vector component variables. This would be a fine feature to add.
Excellent, this is exactly what I was looking for. But there is still a problem. If I use the variable (dubbed normE) as a plot expression I get an error "failed to evaluate variable" a screenshot of the error message dialog is attached. If I replace "normE" by "sqrt(realdot(es.Ex,es.Ex)+realdot(es.Ey,es.Ey)+realdot(es.Ez,es.Ez))" in the expression field the plot works without error. Another thing is maybe unimportant but still... if I define an expression in a plot then comsol automatically computes the corresponding unity (V/m etc.). But when I define a Variable under "global definitions" it doesn't. Is this a hint that it doesn't recognize the names (es.Ez etc.) used in defining the variable? Too bad that comsol does not allow the grouping of user-defined vector component variables. This would be a fine feature to add.


Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22 juil. 2010, 09:36 UTC−4
Hi,

Regarding the error, my guess is that you have defined the variable as a global variable under Global Definitions instead of a local (to the active model) variable under, for example, Model 1>Definitions. It is possible, but then you need the syntax mod1.es.Ex etc. to access these quantities.

Regarding grouping of vector components: That is something that we will look into. In the current version, you can press Ctrl+Space in the edit fields for each vector component to access user-defined variables. At least it saves some typing.

Best regards,

Magnus Ringh
COMSOL
Hi, Regarding the error, my guess is that you have defined the variable as a global variable under Global Definitions instead of a local (to the active model) variable under, for example, Model 1>Definitions. It is possible, but then you need the syntax mod1.es.Ex etc. to access these quantities. Regarding grouping of vector components: That is something that we will look into. In the current version, you can press Ctrl+Space in the edit fields for each vector component to access user-defined variables. At least it saves some typing. Best regards, Magnus Ringh COMSOL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 22 juil. 2010, 12:11 UTC−4

Thank you Magnus!! If I had only known this before, it would have saved me countless hors.

Thank you Magnus!! If I had only known this before, it would have saved me countless hors.

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.