worlddynamics / Vensim2MTK.jl

A Julia package to import Vensim .xmile files as ModelingToolkit.jl models.
MIT License
2 stars 1 forks source link

domain error #8

Closed meyde closed 1 year ago

meyde commented 1 year ago

these equations leads to a domain error in the model: CO2_Rad_Forcing ~ (CO2_Rad_Force_Coeff)(log((2),((CO2_in_Atmos)/(Preindustrial_CO2)))) Cons_Growth_Rate ~ (log((Consumption_per_Cap)/(TEMPVARSMOOTHED_Cons_Growth_Rate)))/(TIME_STEP) Reference_Output ~ (Output_in_1965)((Factor_Productivity)((((Capital)/(Initial_Capital))^(Capital_Elast_Output))(((Population)/(Initial_Population))^((1)-(Capital_Elast_Output))))) Utility ~ (Utility_Coeff)*(IfElse.ifelse((Rate_of_Inequal_Aversion)==(1),(log((Consumption_per_Cap)/(Ref_Cons_per_Cap))),(((((Consumption_per_Cap)/(Ref_Cons_per_Cap))^((1)-(Rate_of_Inequal_Aversion)))-(1))/((1)-(Rate_of_Inequal_Aversion)))))

currently i'm making sure the equations are right by checking in Vensim

meyde commented 1 year ago

as a reference, the error messages of each equation are: -DomainError with -1.6949152542372881e-12 -DomainError with -Inf (both of thoses are log problems)

meyde commented 1 year ago

update:

i've been trying out some things to see where the model fail, and basically what i got : after a few steps, the value of "CO2_in_Atmos" plummet into -infinity. this is wrong ,as it should smoothly increase. to see why it does that, i've checked the initial values of variables used in the calculation of this variable; and i've found that the arbitrary "1" value i gave to the variable "Reference Output" as a placeholder to wait until i've solved it's issue is the cause, as it should be in the magnitude of 1e14.

however, when i fix it, i get this error: Warning: dt(4.547473508864641e-13) <= dtmin(4.547473508864641e-13) at t=1965. dtmin(4.547473508864641e-13) at t=1965.3054359281255, and step error estimate = 0.9752046186701183. Aborting. There is either an error in your model specification or the true solution is unstable.

meaning the solution is probably unstable. the limit before this occurs is 10.

so now i will try and solve the problem of the "Reference Output" Equation before the "CO2_in_Atmos", as it's apparently a part of what is breaking the model

aurorarossi commented 1 year ago

Hello, I'm trying to run Dice.jl and from here I understand that the variable TIME_STEP is not giving you an error right? It is strange because the variable is not defined. If I replace it with t then I get this error

ArgumentError: SymbolicUtils.BasicSymbolic{Real}[TEMPVARSMOOTHED_Cons_Growth_Rate(t)] are missing from the variable map 

because the variable TEMPVARSMOOTHED_Cons_Growth_Rate(t) is not initialized

meyde commented 1 year ago

about TIME_STEP i'm sorry, this is a mistake i've yet to fix and i've been fixing manually since the start. the code in the git is a bit behind what i have now i've just realised, i'll push the recent changes on Dice.jl

aurorarossi commented 1 year ago

ok thank you!

aurorarossi commented 1 year ago

I looked at the version you just pushed and I found some problems in the initialization of variables for example the variable Deep_Ocean_Temp is initialized as -1 but its true value is 0.1 which is stored in the parameter init_Deep_Ocean_Temp that you are not using. So maybe you missed to replace that -1 and some others?

meyde commented 1 year ago

this looks like a big mistake actually, thank you for finding that one! there is probably a mistake in the parser that leads to the parameters not being read correctly. I'll fix this as soon as possible, thanks a lot!

aurorarossi commented 1 year ago

Yes, I would say it is a problem in reading the initializations of some variables because more than one is set to -1. Let me know if you are stuck again!

meyde commented 1 year ago

this was due to a very early mistake in the parser where i was still confused about the Symbol type... anyway, issue corrected, and this looks good, it compile with no issue, and the values don't look incorrect; i'll compare all the graphs with those found in Vensim to be sure, but this looks good! thank you again!