Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
CellMLToNektar.CellMLToNektar Namespace Reference

Functions

def euler
 
def writefile
 
def show_usage
 
def fix_divide_by_zero
 

Variables

tuple pycml_path = os.path.dirname(os.path.realpath(__file__))
 
string profile_name = '/tmp/pycml-profile-%f-%d'
 

Function Documentation

def CellMLToNektar.CellMLToNektar.euler (   doc,
  t,
  nsteps = 1000,
  dt = 0.01 
)

Definition at line 66 of file CellMLToNektar.py.

66 
67  def euler(doc, t, nsteps=1000, dt=0.01):
68  global tvar, state_vars, exprs #assigns tvar, state_vars and exprs to be global variables, meaning they can be used by any function
69  tvar = t.free_vars[0] #takes the t-input and does "free_vars[0]" to it?
70  state_vars = t.state_vars #defines state_vars as the state_vars of the t-input?
71  for var in state_vars: #cycles through all the entries in "state_vars"
72  var.set_value(float(var.initial_value)) #for all the entries in "state_vars" it sets the value to a float of the initial value
73  tvar.set_value(0.0) #this sets the value of tvars to (0.0)?
74  exprs = [e for e in doc.model.get_assignments() #I don't understand this part
75  if isinstance(e, modified_translators.mathml_apply)] #what is the mathml_apply function? Can't find it in modified_translators
76  for _ in range(nsteps): #this is a for-loop through all the values up to the input of nsteps
77  for expr in exprs: #this cycles through all the entries in exprs
78  expr.evaluate()
79  tvar.set_value(tvar.get_value() + dt)
80  for var in state_vars:
81  var.set_value(var.get_value() +
82  dt * var.get_value(ode=tvar))
83  return
def CellMLToNektar.CellMLToNektar.fix_divide_by_zero (   doc)
Several models have equations of a form that may give rise to
a divide by zero error on simulation, especially when lookup
tables are used.  The general form is:

(a * (V - v0)) / (exp(b * (V - v0)) - 1)

When V = v0 this is undefined, however the limit of the
function as V approaches v0 from either side is well-defined,
and each limit is the same.  We approximate the limit by
linear interpolation between values of the expression for
(V-v0) = +/- 1e-10.

Definition at line 97 of file CellMLToNektar.py.

97 
98  def fix_divide_by_zero(doc):
99  """
100  Several models have equations of a form that may give rise to
101  a divide by zero error on simulation, especially when lookup
102  tables are used. The general form is:
103 
104  (a * (V - v0)) / (exp(b * (V - v0)) - 1)
105 
106  When V = v0 this is undefined, however the limit of the
107  function as V approaches v0 from either side is well-defined,
108  and each limit is the same. We approximate the limit by
109  linear interpolation between values of the expression for
110  (V-v0) = +/- 1e-10.
111  """
112  divides = [d.xml_parent
113  for d in doc.xml_xpath(u'//m:apply/m:divide')]
114  for divide in divides:
115  pass
116  return
def CellMLToNektar.CellMLToNektar.show_usage (   doc)

Definition at line 91 of file CellMLToNektar.py.

91 
92  def show_usage(doc):
93  for comp in doc.model.component:
94  for var in comp.variable:
95  print var.fullname(), var._cml_usage_count
96 
def CellMLToNektar.CellMLToNektar.writefile (   doc,
  outfn = 'test.cml' 
)

Definition at line 84 of file CellMLToNektar.py.

Referenced by Nektar::FieldUtils::OutputFld.Process(), and Nektar::FieldUtils::OutputPts.Process().

84 
85  def writefile(doc, outfn='test.cml'):
86  # Write out CellML file
87  st = modified_translators.open_output_stream(outfn)
88  doc.xml(indent=1, stream=st)
89  st.close()
90  return

Variable Documentation

string CellMLToNektar.CellMLToNektar.profile_name = '/tmp/pycml-profile-%f-%d'

Definition at line 58 of file CellMLToNektar.py.

tuple CellMLToNektar.CellMLToNektar.pycml_path = os.path.dirname(os.path.realpath(__file__))

Definition at line 44 of file CellMLToNektar.py.