Nektar++
Functions | Variables
CellMLToNektar.CellMLToNektar Namespace Reference

Functions

def euler (doc, t, nsteps=1000, dt=0.01)
 
def writefile (doc, outfn='test.cml')
 
def show_usage (doc)
 
def fix_divide_by_zero (doc)
 

Variables

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

Detailed Description

Copyright (c) 2005-2016, University of Oxford.
All rights reserved.

University of Oxford means the Chancellor, Masters and Scholars of the
University of Oxford, having an administrative office at Wellington
Square, Oxford OX1 2JD, UK.

This file is part of Chaste.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 * Neither the name of the University of Oxford nor the names of its
   contributors may be used to endorse or promote products derived from this
   software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ euler()

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

Definition at line 66 of file CellMLToNektar.py.

66 def euler(doc, t, nsteps=1000, dt=0.01):
67 global tvar, state_vars, exprs #assigns tvar, state_vars and exprs to be global variables, meaning they can be used by any function
68 tvar = t.free_vars[0] #takes the t-input and does "free_vars[0]" to it?
69 state_vars = t.state_vars #defines state_vars as the state_vars of the t-input?
70 for var in state_vars: #cycles through all the entries in "state_vars"
71 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
72 tvar.set_value(0.0) #this sets the value of tvars to (0.0)?
73 exprs = [e for e in doc.model.get_assignments() #I don't understand this part
74 if isinstance(e, modified_translators.mathml_apply)] #what is the mathml_apply function? Can't find it in modified_translators
75 for _ in range(nsteps): #this is a for-loop through all the values up to the input of nsteps
76 for expr in exprs: #this cycles through all the entries in exprs
77 expr.evaluate()
78 tvar.set_value(tvar.get_value() + dt)
79 for var in state_vars:
80 var.set_value(var.get_value() +
81 dt * var.get_value(ode=tvar))
82 return
83
def euler(doc, t, nsteps=1000, dt=0.01)

◆ fix_divide_by_zero()

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

◆ show_usage()

def CellMLToNektar.CellMLToNektar.show_usage (   doc)

Definition at line 91 of file CellMLToNektar.py.

91 def show_usage(doc):
92 for comp in doc.model.component:
93 for var in comp.variable:
94 print var.fullname(), var._cml_usage_count
95
96

◆ writefile()

def CellMLToNektar.CellMLToNektar.writefile (   doc,
  outfn = 'test.cml' 
)

Definition at line 84 of file CellMLToNektar.py.

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

Variable Documentation

◆ profile_name

string CellMLToNektar.CellMLToNektar.profile_name = '/tmp/pycml-profile-%f-%d' % (time.time(), os.getpid())

Definition at line 58 of file CellMLToNektar.py.

◆ pycml_path

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

Definition at line 44 of file CellMLToNektar.py.