Andrea Ferrario
COMSOL Employee
Please login with a confirmed email address before reporting spam
Posted:
9 years ago
7 sept. 2015, 04:21 UTC−4
Hi Philipp,
You can define a function with an analytic expression (such as x^2+4) as an Analytic function under the Definitions node, and then use it anywhere in COMSOL as a function. For example, if you called your function f, you can use f(x) anywhere, where x is the argument to your function.
The integrate operator numerically integrates any function with respect to a variable:
integrate(E(x),x,x_a,x_b)
but this assumes that there is a function with name E defined e.g. as an analytic function. Note that x is a "dummy" integration variable, not the x-coordinate, so if you write
integrate(es.Ex,x,x_a,x_b)
you simply get es.Ex*(x_b-x_a) since es.Ex is a constant with respect to the dummy integration variable x. In this respect, it's better if you use another name for the dummy variable to avoid confusion.
If you want to integrate a space-dependent expression (such as es.Ex) on a line or a boundary, you need to use an Integration coupling operator (again under the Definitions node). For example, if you add an Integration operator called intop1 and select a line, the expression
intop1(es.Ex)
will integrate the x-component of the electric field on the line. You can also combine this with the Analytic function you defined earlier:
intop1(f(es.Ex))
--
Andrea Ferrario
COMSOL AB
Hi Philipp,
You can define a function with an analytic expression (such as x^2+4) as an Analytic function under the Definitions node, and then use it anywhere in COMSOL as a function. For example, if you called your function f, you can use f(x) anywhere, where x is the argument to your function.
The integrate operator numerically integrates any function with respect to a variable:
integrate(E(x),x,x_a,x_b)
but this assumes that there is a function with name E defined e.g. as an analytic function. Note that x is a "dummy" integration variable, not the x-coordinate, so if you write
integrate(es.Ex,x,x_a,x_b)
you simply get es.Ex*(x_b-x_a) since es.Ex is a constant with respect to the dummy integration variable x. In this respect, it's better if you use another name for the dummy variable to avoid confusion.
If you want to integrate a space-dependent expression (such as es.Ex) on a line or a boundary, you need to use an Integration coupling operator (again under the Definitions node). For example, if you add an Integration operator called intop1 and select a line, the expression
intop1(es.Ex)
will integrate the x-component of the electric field on the line. You can also combine this with the Analytic function you defined earlier:
intop1(f(es.Ex))
--
Andrea Ferrario
COMSOL AB
Please login with a confirmed email address before reporting spam
Posted:
9 years ago
7 sept. 2015, 05:54 UTC−4
Hi Andrea,
thanks for your helpful advice. I tried to do as you said, but it didn't work for some reason :(. Guess it's my bad.
I've attached a file with my problem. It's a simple capacitor and I wanted to (at first) plot the Integration of the electric potential). It just offers me one single point in the results. What did I do wrong? Maybe you could change it to a working solution and tell me about my mistakes.
Thanks a lot in advance,
Philipp.
Hi Andrea,
thanks for your helpful advice. I tried to do as you said, but it didn't work for some reason :(. Guess it's my bad.
I've attached a file with my problem. It's a simple capacitor and I wanted to (at first) plot the Integration of the electric potential). It just offers me one single point in the results. What did I do wrong? Maybe you could change it to a working solution and tell me about my mistakes.
Thanks a lot in advance,
Philipp.
Please login with a confirmed email address before reporting spam
Posted:
9 years ago
8 sept. 2015, 02:56 UTC−4
Try to define your functions in Global definition in analytical functions, above the component section.
Maybe it works, and then you can define your functions for different physics that you have.
Hope it helps.
Good luck
Try to define your functions in Global definition in analytical functions, above the component section.
Maybe it works, and then you can define your functions for different physics that you have.
Hope it helps.
Good luck