Error in functions and measurement units

Use this forum to post Vensim related questions.
Post Reply
madina_bekchanova
Junior Member
Posts: 17
Joined: Fri Nov 19, 2021 2:51 pm
Vensim version: PLE

Error in functions and measurement units

Post by madina_bekchanova »

Hi,

I was trying to model the soil water dynamics. I gave the same measurement unit of cm/month for all the variables and stocks, but when I want to run it, the vensim doesn't run it and it keeps showing an error. When I opened the errors, it is most of the time about the measurement unit mismatch. How I can solve this issue? Could you please give guidance on this?

Thank you beforehand
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Error in functions and measurement units

Post by tomfid »

It would help a lot if we could see the model, or at least a screenshot of the errors.

Unit errors won't prevent the model from running, so there must be some kind of syntax error in one or more equations. Normally if you use "check model" the equation editor will take you to the first error instance.

Matching units everywhere may not be sufficient for balance. A basic rule, for example is that flows have the same units as stocks, divided by time. That is,

Stock = INTEG( flow, init value ) ~ stuff
Flow = ... ~ stuff/time

So, if your model time unit is in months, and you have a flow in cm/month, the associated stock will be in cm.
madina_bekchanova
Junior Member
Posts: 17
Joined: Fri Nov 19, 2021 2:51 pm
Vensim version: PLE

Re: Error in functions and measurement units

Post by madina_bekchanova »

Thank you very much for your help. I checked the units and they are in proper order. I would love to show my model but I am not sure how can I upload here my model. Below I am copying and pasting the errors that are appearing units check

1. Error in units for the following equation:
#Soil temperature 1>DELAY1>LV1# =
INTEG( Surface tempertature
- #Soil temperature 1>DELAY1# ,
Surface tempertature
* ( 0.5) )
#Soil temperature 1>DELAY1>LV1# --> Month
Surface tempertature --> Month
#Soil temperature 1>DELAY1# --> Month

Analysis of units error:
Units mismatch in INTEG
Surface tempertature
- #Soil temperature 1>DELAY1#
Has Units: Month*Month
Surface tempertature
* ( 0.5)
Has Units: Month

********************
2. Error in units for the following equation:
Evapotranspiration =
IF THEN ELSE ( Soil temperature 1
> 0
:AND: Surface tempertature
> 0,
Evapotranspiration Actual ,
0)
Evapotranspiration --> cm/Month
Soil temperature 1 --> Month
Surface tempertature --> Month
Evapotranspiration Actual --> Month

Analysis of units error:
Right hand and left hand units do not match
Evapotranspiration
Has Units: cm/Month
IF THEN ELSE ( Soil temperature 1
> 0
:AND: Surface tempertature
> 0,
Evapotranspiration Actual ,
0)
Has Units: Month

********************

3. Error in units for the following equation:
Evapotranspiration Actual =
IF THEN ELSE ( Soil water
> Evapotranspiration potential ,
Evapotranspiration potential ,
Soil water
* 0.9)
Evapotranspiration Actual --> Month
Soil water --> cm
Evapotranspiration potential --> Month

Analysis of units error:
Units mismatch
Soil water
Has Units: cm
Evapotranspiration potential
Has Units: Month

***********************************************
4. ***********************************************
Warning: units in equation for - F Infiltration1
Lookup -#F Infiltration1#- used with dimensioned argument
cm

***********************************************
5. Error in units for the following equation:
Infiltration =
IF THEN ELSE ( Surface tempertature
> 0
:AND: Soil temperature 1
> 0,
F Infiltration1 ,
0)
Infiltration --> cm/Month
Surface tempertature --> Month
Soil temperature 1 --> Month
F Infiltration1 --> Month

Analysis of units error:
Right hand and left hand units do not match
Infiltration
Has Units: cm/Month
IF THEN ELSE ( Surface tempertature
> 0
:AND: Soil temperature 1
> 0,
F Infiltration1 ,
0)
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Error in functions and measurement units

Post by Administrator »

Looking at the last one. You have "Infiltration" measured in "cm/Month". But the output of IF THEN ELSE is either "Soil temperature 1" or zero and "Soil temperature 1" is measured in "Month". "cm/Month" is definitely not equal to "Month".

Also, why is "Soil temperature 1" measured in "Month"? Same question for "Surface tempertature", is "Month" the correct unit?

The units should be fairly easy to get right. If you have a temperature in your model, it should be measured in "DEG" or similar. If you have a distance, the units should be something like KM, CM etc. If you have a flow of people (for example, visitors to a bank), that should be "people/day" (or people/hour, people/min etc). The number of people in the bank at any one time would be measured in "people". Always use units that are correct for the parameter you are calculating.

Hope this helps.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Error in functions and measurement units

Post by tomfid »

Similarly, "evapotranspiration actual" and "evapotranspiration potential" have units of month. These should also be cm/month I would guess.

There's an "Attachments" tab for uploading files - it's available when you use the full editor, not the quick response field.
madina_bekchanova
Junior Member
Posts: 17
Joined: Fri Nov 19, 2021 2:51 pm
Vensim version: PLE

Re: Error in functions and measurement units

Post by madina_bekchanova »

Here is my model. I have tried all the options but it still keeps showing me an error. Could you please suggest to me how to eliminate these errors? Thank you beforehand
Attachments
Soil_water.mdl
(5.33 KiB) Downloaded 106 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Error in functions and measurement units

Post by tomfid »

There are still some units issues here. Surface temperature and soil temperature presumably dont have units of month. K runoff should probably be fraction/month (or equivalently 1/month), not month. K percolation should probably also be 1/month.

However, the reason the model won't run is that surface temperature, evapotranspiration potential, and precipitation are all lookups that are being (mis)used as regular variables, as reported if you use Model>Check Model.

I assume these are meant to be functions of time, in which case there are two possible approaches:

- Change the lookups to be Auxiliaries, With Lookup, as you've done for K Percolation1. The input will then be Time.

- Use the existing lookups, and create additional variables to contain the actual values derived from the lookups. For example,

Precipitation = Precipitation Lookup( Time/one month ) ~ cm/month
Precipitation Lookup = [(0,0)-(11,10)],(1,5),(2,5),(3,5),(4,5),(5,5),(6,5),(7,5),(8,5),(9,5),(10,5),(11,5) ~ cm/month
one month == 1 ~ month

The constant "one month" is just there to suppress unit warnings from the use of a dimensioned input.
madina_bekchanova
Junior Member
Posts: 17
Joined: Fri Nov 19, 2021 2:51 pm
Vensim version: PLE

Re: Error in functions and measurement units

Post by madina_bekchanova »

Thank you very much for your explanation. I have tried both approaches.

For the first approach you have suggested, I had to create a Time variable because otherwise, vensim kept showing me that the Time variable wasn't expected but used. I guess Vensim has a Time variable but it did not allow me to use it till I created a variable Time. But still, the errors are not gone (please see attached).

I also tried the second approach using the existing lookups and creating additional variables to contain the actual values derived from the lookups. So I created an additional variable with precipitation lookup, however, I did not understand if I should create an additional variable called one month? Also when I put your example in Vensim it kept showing me the error of Time variable is not found. Could you please give me more explanation on this thank you
Attachments
Water systems .mdl
(5.61 KiB) Downloaded 107 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Error in functions and measurement units

Post by tomfid »

When you get the "wasn't expected but used" warning, you should say yes to add the needed variable to the diagram. This just indicates that there's no arrow connecting that variable to the target equation.

However, PLE doesn't generally permit this, so you have to first make the connection on the diagram. Assuming that's what you're using, delete the "time1" variable, and use the shadow variable tool to add time to the diagram. Then add arrows to the 3 lookups that use time, and edit their equations again, chainging time1 back to time.

The process is similar if you want to add "one month" - first create the variable, then connect it to the same uses as "time". This isn't essential - if you don't do it, you'll get a warning like

Code: Select all

***********************************************
Warning: units in equation for - Evapotranspiration potential 
Lookup -#Evapotranspiration potential#- used with dimensioned argument
 Month
which you can ignore. Personally, I find it cleaner to suppress all unit warnings when possible.

With these changes, the model runs in equilibrium.

However, there will be some unit errors remaining, like

Code: Select all

***********************************************
Error in units for the following equation:
#Soil temperature 1>DELAY1>LV1#  = 
        INTEG( Surface tempertature 
                  - #Soil temperature 1>DELAY1# , 
             Surface tempertature 
                  * ( 0.5) ) 
#Soil temperature 1>DELAY1>LV1#  --> cm/Month
Surface tempertature  --> cm/Month
#Soil temperature 1>DELAY1#  --> cm/Month

Analysis of units error:
Units mismatch in INTEG
Surface tempertature 
     - #Soil temperature 1>DELAY1# 
Has Units: cm
Surface tempertature 
     * ( 0.5) 
Has Units: cm/Month

***********************************************
Error in units for the following equation:
Evapotranspiration Actual  = 
        IF THEN ELSE ( Soil water 
                  > Evapotranspiration potential , 
             Evapotranspiration potential , 
             Soil water 
                  * 0.9) 
Evapotranspiration Actual  --> cm/Month
Soil water  --> cm
Evapotranspiration potential  --> cm/Month

Analysis of units error:
Units mismatch
Soil water 
Has Units: cm
Evapotranspiration potential 
Has Units: cm/Month
I think the first one is because the 0.5 embedded in the equation is not dimensionless. This needs to be made into an explicit variable with a unit. My guess is that it's a rate constant, with units 1/month or fraction/month (these are equivalent - I prefer the latter usually).

The second error occurs because the IF condition compares soil water, a stock (cm) to evapotranspiration potential, a flow (cm/mo). That's a conceptual problem - comparisons need to use the same unit. Possibly the unit change could come from the embedded parameter 0.9 - again, this is presumably some kind of rate constant with units of fraction/month.
Post Reply