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.

Defining a variable....

Please login with a confirmed email address before reporting spam

Hello everyone, I would like to define a variable suppose 'a' that starts from 0 to 1 with stepsize=0. I did this in local variables with 'range' operator but if i do it for 0 to 3 its ok but if i do it range(2.1337,0,4.255) then its giving me error of Unknown range operator..... Thanks

6 Replies Last Post 22.05.2015, 21:22 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 19.05.2015, 22:53 GMT-4
Could anyone help please....
Could anyone help please....

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 20.05.2015, 08:36 GMT-4
Hi,

I'm not sure what you want to do, but I can see a couple of issues here:

- Using a step size of 0 is not allowed. You should use a nonzero step size for the range function.
- For a variable defined under Variables, you can define an expression in a flexible way, but it must represent a scalar-valued function (that is, when called with its inputs, it returns a scalar value). You can define a variable as

2*pi*r^2

in an axisymmetric model where r is a spatial coordinate, for example.

The range function returns a list (vector) of values, and it is therefore not applicable in the Variables definitions, so it should not work in any of the cases you describe. It is useful where you specify lists of values: In the Times field for the output times from a time-dependent study, for example.

Best regards,
Magnus Ringh, COMSOL

Hi, I'm not sure what you want to do, but I can see a couple of issues here: - Using a step size of 0 is not allowed. You should use a nonzero step size for the range function. - For a variable defined under Variables, you can define an expression in a flexible way, but it must represent a scalar-valued function (that is, when called with its inputs, it returns a scalar value). You can define a variable as 2*pi*r^2 in an axisymmetric model where r is a spatial coordinate, for example. The range function returns a list (vector) of values, and it is therefore not applicable in the Variables definitions, so it should not work in any of the cases you describe. It is useful where you specify lists of values: In the Times field for the output times from a time-dependent study, for example. Best regards, Magnus Ringh, COMSOL

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 20.05.2015, 21:59 GMT-4
Hello Magnus, thanks for the reply. What I want to do is that to define a variable that varies for continuous range of values like the range function does the same but with a step size(discontinuity).
Hello Magnus, thanks for the reply. What I want to do is that to define a variable that varies for continuous range of values like the range function does the same but with a step size(discontinuity).

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 21.05.2015, 10:14 GMT-4
A continuous range of values takes infinitely long to evaluate. So you probably don't want that....

One way I like evaluating my ranges is using normalized ranges, for example:

5 + 7 * range(0, 0.01, 1)

is a range from 5 to 12 with 101 points.

A nice thing about doing a 0 to 1 range is it's easy to modify the progression. For example, if I want to slowly increase the step size I can do:

5 + 7 * range(0, 0.01, 1)^2

Then I get small steps at the beginning but larger steps at the end but I don't need to do any math to figure out how to adjust the function.

A continuous range of values takes infinitely long to evaluate. So you probably don't want that.... One way I like evaluating my ranges is using normalized ranges, for example: 5 + 7 * range(0, 0.01, 1) is a range from 5 to 12 with 101 points. A nice thing about doing a 0 to 1 range is it's easy to modify the progression. For example, if I want to slowly increase the step size I can do: 5 + 7 * range(0, 0.01, 1)^2 Then I get small steps at the beginning but larger steps at the end but I don't need to do any math to figure out how to adjust the function.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 21.05.2015, 22:15 GMT-4
Thanks for the reply Daniel. Actually I want to define a variable in my variables(local) that will take the range of values but in my variables we can not use the range function so what other function we have in comsol to define a variable that takes a range of values and can be defined in my variables.

I am working on the fault diagnosis of the grounding grid. For the diagnosis I am using electromagnetic Induction Method. As I inject the current, the magnetic flux density that is produced is to be measured. Now I want to put the formula for magnetic flux density B that is through Biot Savat law.
The case I am working on is a conductor of length 1m lying at 45 degrees with the x-axis. When current I flows in the conductor the magnetic flux density produced at point (x0,y0,z0) will be...
B=uI/(4pi)*[cos(45)*integrate((y0-a)/r^3,a,0,cos(45))-sin(45)*integrate((x0-a)/r^3,a,0,sin(45))].
where r is the position vector from the differential element on the conductor to the point of measurement(x0,y0,z0). r=sqrt((xo-a)^2+(y0-a)^2+(z0-0)^). where (a,a,0) is the position of differential elements.
where a ranges from 0 to 0.707. Now I want to define this 'a' in my variables(local) because it takes range of values. How can we define? I defined the 'B' in my variables as well.
Thanks for the reply Daniel. Actually I want to define a variable in my variables(local) that will take the range of values but in my variables we can not use the range function so what other function we have in comsol to define a variable that takes a range of values and can be defined in my variables. I am working on the fault diagnosis of the grounding grid. For the diagnosis I am using electromagnetic Induction Method. As I inject the current, the magnetic flux density that is produced is to be measured. Now I want to put the formula for magnetic flux density B that is through Biot Savat law. The case I am working on is a conductor of length 1m lying at 45 degrees with the x-axis. When current I flows in the conductor the magnetic flux density produced at point (x0,y0,z0) will be... B=uI/(4pi)*[cos(45)*integrate((y0-a)/r^3,a,0,cos(45))-sin(45)*integrate((x0-a)/r^3,a,0,sin(45))]. where r is the position vector from the differential element on the conductor to the point of measurement(x0,y0,z0). r=sqrt((xo-a)^2+(y0-a)^2+(z0-0)^). where (a,a,0) is the position of differential elements. where a ranges from 0 to 0.707. Now I want to define this 'a' in my variables(local) because it takes range of values. How can we define? I defined the 'B' in my variables as well.

Please login with a confirmed email address before reporting spam

Posted: 9 years ago 22.05.2015, 21:22 GMT-4
???????????
???????????

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.