Tutorial Title
Contents
Description
- This file will describe the basic steps/pathway that happens after hitting the compile button on a Constitutive model which includes a dynamic variable tied to an Active Tension model.
The Compile Button
- You want to compile the Constitutive model, after submitting the corresponding Active Tension (AT) model.
The compile button is at: pcty/client/forms/MatModelForm.py, when hit, it runs the generateCode method within the same file.
generateCode
- This is the controlling method that handles source code generation, the steps it takes are:
- Parses equation meta data file, after moving it to a temp directory, for the Constitutive model and assigns the variables and equations to individual lists. (parse_table_file from sympy_to_c.py handles the parsing). We then have the following lists: scalar, vector, tensor, dynamic_vars, rpars, and equations.
- The variable name mapping is as follows:
Eqn Editor Name(s)
List Name
Independent
scalar
Dependent and tensor
tensor
Dynamic or time_dependent
dynamic
Parameters
rpars
n/a
vector - currently hard coded as: ['rpar_mat', 'rpar_at', 'y']
If we find any dynamic variables within the Constitutive model, we then get the other model's variables and equations, which is handled in the GenDynamics class, found in pcty/client/biomechanicsCommands.py, and add them to the appropriate list
updateVariables or stateVariables or rparDynamicVariables
Once we have all the variables and equations, generate the C code, done via generate_c method, found in src/csrc/strain_energy/sympy_to_c.py
- The end result of all of this is that we now have a file: src/csrc/strain_energy/strain_energy.cpp, that has 3 main functions:
- cpu_advance_be_mech1 - which is the partial update model code based on the AT model (i.e., does not contain the update vars)
- p_strain_energy -
- p_strain_energy_output -
GenDynamics
- This class (found in pcty/client/biomechanicsCommands.py), handles getting the variables and equations from the currently submitted Active Tension (AT) model and getting the AT model code ready to be included with the Constitutive model.
- Get the currently submitted AT model, and it's variables (as defined from it's meta file)
Pass the variables to EPSympyGenerator class in pcty/client/forms/EPSympyGenerator.py, which creates the header, constants and equations from the variable meta data file, basically turns the meta file into python code.
Calls rawCompileDynamics method from pcty/server/utils/IonicBuildSympy.c, which removes and then re-creates the dynamicData.pickle file and the helper and update code (i.e., ode_model_model_pert_delta_tweak_cpu_mech.c and odecusingle.so, respectively)
rawCompileDynamics_c
- This method will assure that the dynamic model build will start from scratch and be re-initialized to be ready for use, the steps it takes are:
- It writes out the dynamic model code (which is passed into it) to a local file named: src/ode_cuda/justmodel.py
- Removes the old version of /src/ode_cuda/ode_model_model_pert_delta_tweak_cpu_mech.c
- Then does the following:
Runs gen_sympy_model.py to generate a new dynamicData.pickle file containing dynamic variables (e.g., T_Active), and dynamic state variables (e.g., Lsi and Con). Reads in the sympy mode code (justmodel.py) and write out the model in C code (model_from_sympy.c).
Runs buildAndShow.py --norun --nobuild --dynamics to generate a new ode_model_model_pert_delta_tweak_cpu_mech.c file
Runs builsAndShow.py --norun again, and this time creates odecusingle.so, which will be used for the full update
buildAndShow
- Used for CUDA code generation and building of ODE models, there are various command line flags for this program
- Creates a build_settings.py file which sets the build settings, not surprisingly
- If the --dynamics flag is supplied when run (and it is for the first time from rawCompileDynamics) it generates code that is a partial update model, without the flag it generates code that is a full update model (e.g., the variable dSL_dt is only found in the full update model)
generate_c
- This is the main method used for converting sympy to C code, the steps it takes are:
- Ensures there is some dynamic code available: src/ode_cuda/ode_model_model_pert_delta_tweak_cpu_mech.c (which is the partial update model generated by buildAndShow).
- Calls gen_c_helper with list of variables and equations, which will handle changing the sympy code into C code, it calls it once when genOutputs = True and once when genOutputs = False.