Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ Building the example
Instructions on how to configure and build with CMake::

git clone https://github.com/OpenCMISS-Examples/left_ventricle_inflation.git
cd left_ventricle_inflation
mkdir build
cmake -DOpenCMISSLibs_DIR=/path/to/opencmisslib/install ../left_ventricle_inflation
cd build
cmake -DOpenCMISS_INSTALL_ROOT=/path/to/opencmiss/install ../.
make # cmake --build . will also work here and is much more platform agnostic.

Running the example
===================

Explain how the example is run::

cd build
./src/fortran/left_ventricle_inflation.F90

or maybe it is a Python only example::
Expand Down
11 changes: 6 additions & 5 deletions src/python/exfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _read_element(self, f):
try:
indices = map(int, element_line.split(':')[1].split())
except:
print element_line
print(element_line)
raise
if indices[1] == 0 and indices[2] == 0:
#raise ExfileError(f, "Face or line elements not supported")
Expand Down Expand Up @@ -292,12 +292,13 @@ def _read_node(self, f):
while read < self.num_node_values:
line = f.readline()
try:
new_values = map(float, line.split())
new_values = list(map(float, line.split()))
except ValueError:
raise ExfileError(f, "Expecting node values, got: %s" % line.strip())
if read + len(new_values) > self.num_node_values:
if read + len(list(new_values)) > self.num_node_values:
raise ExfileError(f, "Got more node values than expected.")
values[read:read + len(new_values)] = new_values
for nodeIndex in (0,len(new_values)-1):
values[read+nodeIndex] = new_values[nodeIndex]
read += len(new_values)

self.nodes.append(ExnodeNode(number, values))
Expand Down Expand Up @@ -462,7 +463,7 @@ def _read_element(self, f):
element_line = f.readline()
if element_line == "":
raise EOFError
indices = map(int, element_line.split(':')[1].split())
indices = list(map(int, element_line.split(':')[1].split()))
if indices[1] == 0 and indices[2] == 0:
# raise ExfileError(f, "Face or line elements not supported")
values = []
Expand Down
56 changes: 34 additions & 22 deletions src/python/left_ventricle_inflation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#> of Oxford are Copyright (C) 2007 by the University of Auckland and
#> the University of Oxford. All Rights Reserved.
#>
#> Contributor(s): Sander Land
#> Contributor(s): Zhinuo Jenny Wang, Sander Land
#>
#> Alternatively, the contents of this file may be used under the terms of
#> either the GNU General Public License Version 2 or later (the "GPL"), or
Expand Down Expand Up @@ -77,13 +77,15 @@
cellMLOption = [False]

### Set arbitrary user numbers which are unique to each object.
(coordinateSystemUserNumber,
(contextUserNumber,
coordinateSystemUserNumber,
regionUserNumber,
linearBasisUserNumber,
cubicBasisUserNumber,
generatedMeshUserNumber,
meshUserNumber,
decompositionUserNumber,
decomposerUserNumber,
geometricFieldUserNumber,
equationsSetUserNumber,
equationsSetFieldUserNumber,
Expand All @@ -96,7 +98,7 @@
cellMLUserNumber,
cellMLModelsFieldUserNumber,
cellMLParametersFieldUserNumber,
cellMLIntermediateFieldUserNumber) = range(1, 21)
cellMLIntermediateFieldUserNumber) = range(1, 23)

# Set up geometric model
# longitudinal elements, circumferential elements, transmural elements
Expand All @@ -116,31 +118,38 @@
apex_elems.append([start, end])

# Set up region and CS
[numOfCompNodes, compNodeNum, CS, region] = BasicSetUp(regionUserNumber, coordinateSystemUserNumber)
[context, worldWorkGroup, numOfCompNodes, compNodeNum, CS, region] = BasicSetUp(contextUserNumber, regionUserNumber, coordinateSystemUserNumber)

# Set the OpenCMISS random seed so that we can test this example by using the
# same parallel decomposition
numberOfRandomSeeds = context.RandomSeedsSizeGet()
randomSeeds = [0]*numberOfRandomSeeds
randomSeeds[0] = 100
context.RandomSeedsSet(randomSeeds)

# Set up tricubic Hermite basis functions
[linearBasis, colBasis] = BasisFunction(linearBasisUserNumber, numOfXi, option, collapsed=True)
[linearBasis, colBasis] = BasisFunction(context, linearBasisUserNumber, numOfXi, option, collapsed=True)

# Set up mesh
mesh = iron.Mesh()
mesh = oc.Mesh()
mesh.CreateStart(meshUserNumber, region, numOfXi)
mesh.NumberOfComponentsSet(1)
mesh.NumberOfElementsSet(inputElems.num_elements)

nodes = iron.Nodes()
nodes = oc.Nodes()
nodes.CreateStart(region, inputNodes.num_nodes)
nodes.CreateFinish()

# Linear lagrange component
linearElem = iron.MeshElements()
linearElem = oc.MeshElements()
linearElem.CreateStart(mesh, 1, linearBasis)
for elem in inputElems.elements:
for i in range(1, elems[2]+1):
if (elem.number >= (i-1)*elems[1]*elems[0]) & (elem.number <= i*elems[1]*elems[0]):
if (elem.number >= apex_elems[i-1][0]) & (elem.number <= apex_elems[i-1][1]):
linearElem.BasisSet(elem.number, colBasis)
nodes = list(OrderedDict.fromkeys(elem.nodes))
nodes = map(int, nodes)
nodes = list(map(int, nodes))
linearElem.NodesSet(elem.number, nodes)
else:
linearElem.NodesSet(elem.number, elem.nodes)
Expand All @@ -149,13 +158,16 @@
mesh.CreateFinish()

# Set up decomposition for the mesh.
decomposition = DecompositionSetUp(decompositionUserNumber, mesh, numOfCompNodes)
decomposition = DecompositionSetUp(decompositionUserNumber, mesh)

# Decompose
decomposer = DecomposerSetUp(decomposerUserNumber, region, worldWorkGroup, decomposition)

# Set up geometric field.
geometricField = GeometricFieldSetUp(geometricFieldUserNumber, region, decomposition, option)

# Update the geometric field parameters manually
geometricField.ParameterSetUpdateStart(iron.FieldVariableTypes.U,iron.FieldParameterSetTypes.VALUES)
geometricField.ParameterSetUpdateStart(oc.FieldVariableTypes.U,oc.FieldParameterSetTypes.VALUES)

def ExtractNodeCoords(nodes, field_name):
coords = []
Expand All @@ -178,7 +190,7 @@ def ExtractNodeCoords(nodes, field_name):
coord = []
for component in [1,2,3]:
value = all_nodes[node_num-1][component-1]
geometricField.ParameterSetUpdateNodeDP(iron.FieldVariableTypes.U, iron.FieldParameterSetTypes.VALUES, 1, 1,
geometricField.ParameterSetUpdateNodeDP(oc.FieldVariableTypes.U, oc.FieldParameterSetTypes.VALUES, 1, 1,
node_num, component, value)
coord = all_nodes[node_num-1]
if coord[2] >= 5:
Expand Down Expand Up @@ -222,7 +234,7 @@ def ExtractNodeCoords(nodes, field_name):
eval_node_num.append(i+1)
#print eval_node_num

geometricField.ParameterSetUpdateFinish(iron.FieldVariableTypes.U,iron.FieldParameterSetTypes.VALUES)
geometricField.ParameterSetUpdateFinish(oc.FieldVariableTypes.U,oc.FieldParameterSetTypes.VALUES)

# Export undeformed geometry.
GeometricFieldExport(region, "LVInflation_trilinear_undeformed_"+str(elems[2])+"-"+str(elems[1])+"-"+str(elems[0]))
Expand All @@ -237,15 +249,15 @@ def ExtractNodeCoords(nodes, field_name):
cellMLOption)

# Set up equations set
equationsSetField = iron.Field() # Equations are also in a field
equationsSet = iron.EquationsSet() # Initialise an equation set.
equationsSetSpecification = [iron.EquationsSetClasses.ELASTICITY,
iron.EquationsSetTypes.FINITE_ELASTICITY,
iron.EquationsSetSubtypes.TRANSVERSE_ISOTROPIC_GUCCIONE]
equationsSetField = oc.Field() # Equations are also in a field
equationsSet = oc.EquationsSet() # Initialise an equation set.
equationsSetSpecification = [oc.EquationsSetClasses.ELASTICITY,
oc.EquationsSetTypes.FINITE_ELASTICITY,
oc.EquationsSetSubtypes.TRANSVERSE_ISOTROPIC_GUCCIONE]
equationsSet.CreateStart(equationsSetUserNumber, region, fibreField, equationsSetSpecification,
equationsSetFieldUserNumber, equationsSetField)
equationsSet.CreateFinish()
print "----> Set up equations set <---\n"
print("----> Set up equations set <---\n")

# Set up material field in equations set.
equationsSet.MaterialsCreateStart(materialFieldUserNumber, materialField)
Expand All @@ -270,9 +282,9 @@ def ExtractNodeCoords(nodes, field_name):
increm = pressure_increments[i]
p = p + increm
tol = tolerances[i]
print 'Applying pressure increment of: ', increm, ' using ', iters, ' iterations'
print 'Current pressure is: ', p
[problem, solverEquations] = ProblemSolverSetup(equationsSet, problemUserNumber, iters, tol, cellMLOption)
print('Applying pressure increment of: ', increm, ' using ', iters, ' iterations')
print('Current pressure is: ', p)
[problem, solverEquations] = ProblemSolverSetup(context, equationsSet, problemUserNumber, iters, tol, cellMLOption)
BCEndoPressure(solverEquations, dependentField, endocardial_nodes, increm, basal_nodes, option)

# Solve Problem
Expand Down
Loading