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.

Polynomial Issue with User-defined Variables

Please login with a confirmed email address before reporting spam

I have a 2D rectangular geometry that has porosity and permeability values dependent on x-coordinate. Polynomial expressions are used to define the local porosity and permeability. However, COMSOL does not accept a variable expression such as (x^2+x) because it tries to determine units and cannot add m^2 to m. Is there a way to use polynomial expressions and get around this units issue?

File is attached. Variables are defined under model definitions.

Thanks

Burns


6 Replies Last Post 14.01.2014, 19:35 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 21.03.2013, 15:21 GMT-4
Hi

normally COMSOL does only warn you for units errors (orange) but it calculates on, expecting you to take the responability of the final results w.r.t. unit coherence.
Only typo or variable name errors are flagged "red" and will abort a study.

now if you write an equation:

MyVal[myUnits] = a*x+b*x^2

with x in [m] then you should expect to have units on a and b of the type [myUnits/m] and [myUnits/m^2] respectively, so in your case why not multiply the x^2 term by 1[1/m]*x^2 ?

--
Good luck
Ivar
Hi normally COMSOL does only warn you for units errors (orange) but it calculates on, expecting you to take the responability of the final results w.r.t. unit coherence. Only typo or variable name errors are flagged "red" and will abort a study. now if you write an equation: MyVal[myUnits] = a*x+b*x^2 with x in [m] then you should expect to have units on a and b of the type [myUnits/m] and [myUnits/m^2] respectively, so in your case why not multiply the x^2 term by 1[1/m]*x^2 ? -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.04.2013, 13:02 GMT-4
Thanks Ivar, I was out of town last week so I apologize for the late response.

I multiplied each term of the porosity polynomial by its inverse unit, but this did not work either.
If, for example, my polynomial was 3x^3 + 2x^2 + x +1 ,
I tried to input 3[1/m^3]*x^3 + 2[1/m^2]*x^2 + 1[1/m]*x + 1 , but this did not work.


It seems as though COMSOL is not reading the porosity polynomial correctly, because the model would solve, but the local value for porosity is incorrect. What's interesting is that I have no idea where the values that COMSOL uses for porosity came from. I plotted porosity across the x axis and it did not match the polynomial function at all (which it should). I will look into this some more and report back with my findings. Any other ideas on your end?

Thanks

Burns
Thanks Ivar, I was out of town last week so I apologize for the late response. I multiplied each term of the porosity polynomial by its inverse unit, but this did not work either. If, for example, my polynomial was 3x^3 + 2x^2 + x +1 , I tried to input 3[1/m^3]*x^3 + 2[1/m^2]*x^2 + 1[1/m]*x + 1 , but this did not work. It seems as though COMSOL is not reading the porosity polynomial correctly, because the model would solve, but the local value for porosity is incorrect. What's interesting is that I have no idea where the values that COMSOL uses for porosity came from. I plotted porosity across the x axis and it did not match the polynomial function at all (which it should). I will look into this some more and report back with my findings. Any other ideas on your end? Thanks Burns

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 01.04.2013, 14:47 GMT-4
Hi

3[1/m^3]*x^3 + 2[1/m^2]*x^2 + 1[1/m]*x + 1 should give you a unitless number (no orange highlight), but how are the posority limit defined ?

between 0 an 1 ?

in which case you are always above 1 for x>0

Could that be linked to your issue ?

--
Good luck
Ivar
Hi 3[1/m^3]*x^3 + 2[1/m^2]*x^2 + 1[1/m]*x + 1 should give you a unitless number (no orange highlight), but how are the posority limit defined ? between 0 an 1 ? in which case you are always above 1 for x>0 Could that be linked to your issue ? -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 01.04.2013, 15:10 GMT-4
Yes, porosity is defined between 0 and 1. The polynomial I mentioned previously was just an example, not the actual polynomial I used.

Anyway, I figured out that if I define each term of the polynomial as an individual variable, using the inverse unit syntax mentioned earlier, and then add the terms together where the porosity value is defined, the porosity is correct.

My polynomial was -7e-6*x^5+26811*x^4-8043.4*x^3+793.79*x^2-28.58*x+0.6817
Under model variables I defined the following variables:
T5: -7e-6[1/m^5]*x^5
T4: 25811[1/m^4]*x^4
T3: -8043.4[1/m^3]*x^3
T2: 793.79[1/m^2]*x^2
T1: -28.58[1/m]*x
T: 0.6817

Under the porous media settings, I defined the porosity value as T5+T4+T3+T2+T1+T

This gave the correct porosity value as defined by the polynomial porosity expression.
Yes, porosity is defined between 0 and 1. The polynomial I mentioned previously was just an example, not the actual polynomial I used. Anyway, I figured out that if I define each term of the polynomial as an individual variable, using the inverse unit syntax mentioned earlier, and then add the terms together where the porosity value is defined, the porosity is correct. My polynomial was -7e-6*x^5+26811*x^4-8043.4*x^3+793.79*x^2-28.58*x+0.6817 Under model variables I defined the following variables: T5: -7e-6[1/m^5]*x^5 T4: 25811[1/m^4]*x^4 T3: -8043.4[1/m^3]*x^3 T2: 793.79[1/m^2]*x^2 T1: -28.58[1/m]*x T: 0.6817 Under the porous media settings, I defined the porosity value as T5+T4+T3+T2+T1+T This gave the correct porosity value as defined by the polynomial porosity expression.

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 01.04.2013, 16:05 GMT-4
Hi

I would say but why any difference ?
I would have asked "support" as I cannot understand what is different: full equation or partial variables references

--
Good luck
Ivar
Hi I would say but why any difference ? I would have asked "support" as I cannot understand what is different: full equation or partial variables references -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 14.01.2014, 19:35 GMT-5
Thank you guys for the discussion, it helped me on a similar problem.

I want to add one point here. The correlations we encounter in simulations often use non-integer exponentials, such as MyVal=a*x^0.5, but it seems that Comsol cannot deal with x^0.5 or any non-integer exponential for the unit calculation, so you cannot define MyVal as:

Myval=a[MyUnit*m^(-0.5)]*x^0.5

to make the unit of MyVal to be MyUnit. So what I did was to define MyVal as:

Myval=1[MyUnit]*(a*a[m^-1]*x)^0.5

In this way Comsol only deals with a dimensionless number to do the sqrt operation and gives correct unit. Hope this can help others that have similar problems.
Thank you guys for the discussion, it helped me on a similar problem. I want to add one point here. The correlations we encounter in simulations often use non-integer exponentials, such as MyVal=a*x^0.5, but it seems that Comsol cannot deal with x^0.5 or any non-integer exponential for the unit calculation, so you cannot define MyVal as: Myval=a[MyUnit*m^(-0.5)]*x^0.5 to make the unit of MyVal to be MyUnit. So what I did was to define MyVal as: Myval=1[MyUnit]*(a*a[m^-1]*x)^0.5 In this way Comsol only deals with a dimensionless number to do the sqrt operation and gives correct unit. Hope this can help others that have similar problems.

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.