I am currently working on a Stock and Flow model in AnyLogic, simulating a flow entering and leaving a reservoir with a monthly time step. I am facing challenges with unit measurements and would greatly appreciate your assistance in resolving this issue. Here's a brief overview of the model (Sorry it's a bit messy, but I'm doing some testing):Stock and Flow_proof
Inflow: AlarconMeanContribution is a Table Function with an Excel file containing two columns: one for months and the other for flow rates in m3/s (specified in "system dynamics units" advanced section as CubicMeters/Second).The variable UnitsConversion is used to convert seconds to months, with units of Second/Month.Inflow is calculated as AlarconMeanContribution(time()) * UnitsConversion, resulting in CubicMeters/Second * Second/Month.
Stock (Reservoir): The initial value of the stock is in CubicMeters, representing the volume.The stock equation is d(stock)/dt = inflow - outflow, with units of CubicMeters.
Outflow:
Outflow is determined using an if-then-else function: AlarconOutflow = (AlarconReservoir >= MaxAlarconCapacity) ? ConvertedMaxAlarconOutflow : (AlarconReservoir <= MinAlarconCapacity) ? ConvertedMinAlarconOutflow : AlarconInflow;
MaxAlarconCapacity and MinAlarconCapacity are volumes in CubicMeters.ConvertedOutflow represents flow rates in m3/s converted to CubicMeters/Month.
I am encountering an error on the stock and a warning on the outflow. The error states: "Actual unit CubicMeters/time differs from estimated: CubicMeters," located at ProvaJucar/Main/Riserva - Stock. The warning mentions: "Expression contains variable with undefined unit," located at Jucar River Basin _SD model/Jucar/AlarconReservoir - Stock.
Doing the same in Vensim I have no units errors. Could you please provide guidance on where I might be making a mistake? Thank you in advance for your assistance.
so when you create a stock, unless you are using custom equation in your stock, the flows require being stockUnit/time as the time unit When you create the unit Months, AnyLogic doesn't know what you are taking about, so instead of months you should use time
Summary: replace Month with time in your system dynamic units and you will be fine... do that everywhere