MML variable constants



  • A MML variable constant
  • A Simple MML Model
  • Comments or Questions?
    Give feedback

A MML variable constant

JSim MML variable constants are calculated at compile time but can be changed by the user at run time.

For example:

 real Rgas = 8.31441 J/(mol*K); 

After compilation the value '8.31441' is visible in the 'Model Inputs' section of the JSim GUI Run Time page. The variable has no dependency on any other variable, but since 'Rgas' is an input, the user can change the value of it before running a simulation. This is why it can be referred to as a variable constant. This behavior can be confusing if your constant is defined with operators in it:

real x = (8.31441*310.6)/96484.56;  

At run time, 'x' has a value of '.0267275655' and is a model input. As a model input, the user can still change the value of 'x' to whatever value they want and the source code calculation for 'x' is ignored. Importantly, if you want the original value back, as specified in the source MML, you must use the 'ParSet ->Revert to Model defaults' option available in the JSim GUI Run Time page. Changing the value in the source code and compiling it again will not update the value in the Run Time page as user specified model input values have precedence over the source code values. If you do not want the user to see or adjust a variable declare it as private.


A Simple MML Model

Below is a simple model using MML variable constants. Change the numeric values in the source code and at run time and observe the behavior of JSim:

// Variable Consts example
import  nsrunit; unit conversion on;
math VarConsts {        
real Rgas   = 8.31441 J/(mol*K),         
     Temp   = 310.16 K,                
     RT     = Rgas*Temp,           
     Farad  = 96484.56 coulomb/mol;  
real Temp2 = 310.16;
real x volt; 
real xx volt;
real xxx volt, // All three give same value in source code:   
  x    = (8.31441*310.16)/(96484.56);
  xx   = (8.31441*Temp2)/(96484.56);  
  xxx  = Rgas*Temp/Farad;  

 (Java required)

Items of note:

  • Variable 'x' can be directly changed at run time, while 'xx' and 'xxx' cannot be as they are considered model outputs. They can be changed indirectly by changing their dependencies ('Rgas', 'Temp', 'Farad', 'Temp2') in the Model Inputs section.
  • After compiling the model, go back and change the value for 'x' in the source code, then compile again. Note that the run time value for 'x' has not changed. To see the updated value for 'x' in the Run Time window, chose the 'ParSet -> Revert to model defaults' from the drop down menu.You will now see the updated value for 'x'.

Comments or Questions?

Give feedback

Model development and archiving support at provided by the following grants: NIH U01HL122199 Analyzing the Cardiac Power Grid, 09/15/2015 - 05/31/2020, NIH/NIBIB BE08407 Software Integration, JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ, 4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation, 8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973 JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.