Skip to content

Commit

Permalink
now storing the dof-to-vertex mapping in the model object when serial…
Browse files Browse the repository at this point in the history
…ized
  • Loading branch information
Brian Drawert committed Aug 28, 2014
1 parent e3df528 commit d4d89df
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions pyurdme/pyurdme.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def __setstate__(self, state):
mesh.constrained_domain = compiled_object
if 'num_dof_voxels' in state['mesh']:
mesh.num_dof_voxels = state['mesh']['num_dof_voxels']
mesh.init(2, 0)
self.__dict__['mesh'] = mesh
except Exception as e:
print "Error unpickling model, could not recreate the mesh."
Expand Down Expand Up @@ -1239,6 +1240,10 @@ def __getstate__(self):

state = self.__dict__
state["filecontents"] = filecontents
state["v2d"] = self.get_v2d()
state["d2v"] = self.get_d2v()


for key, item in state.items():
try:
pickle.dumps(item)
Expand All @@ -1265,11 +1270,26 @@ def __setstate__(self, state):
for k,v in state.items():
self.__dict__[k] = v

def get_v2d(self):
""" Return the vertex-to-dof mapping. """
if not hasattr(self, 'v2d'):
fs = self.model.mesh.get_function_space()
self.v2d = dolfin.vertex_to_dof_map(fs)

return self.v2d

def get_d2v(self):
""" Return the dof-to-vertex mapping. """
if not hasattr(self, 'd2v'):
fs = self.model.mesh.get_function_space()
self.d2v = dolfin.dof_to_vertex_map(fs)

return self.d2v

def _reorder_dof_to_voxel(self, M, num_species=None):
""" Reorder the colums of M from dof ordering to vertex ordering. """

fs = self.model.mesh.get_function_space()
v2d = dolfin.vertex_to_dof_map(fs)
v2d = self.get_v2d()
if len(M.shape) == 1:
num_timepoints = 1
else:
Expand Down Expand Up @@ -1424,8 +1444,8 @@ def _initialize_sol(self):
raise URDMEError("URDMEResult.model must be set before the sol attribute can be accessed.")
numvox = self.model.mesh.num_vertices()
fs = self.model.mesh.get_function_space()
vertex_to_dof_map = dolfin.vertex_to_dof_map(fs)
dof_to_vertex_map = dolfin.dof_to_vertex_map(fs)
vertex_to_dof_map = self.get_v2d()
dof_to_vertex_map = self.get_d2v()

# The result is loaded in dolfin Functions, one for each species and time point
for i, spec in enumerate(self.model.listOfSpecies):
Expand Down Expand Up @@ -1607,8 +1627,7 @@ def _copynumber_to_concentration(self,copy_number_data):
where the volume unit is defined by the user input.
"""

fs = self.model.mesh.get_function_space()
v2d = dolfin.vertex_to_dof_map(fs)
v2d = self.get_v2d()
shape = numpy.shape(copy_number_data)
if len(shape) == 1:
shape = (1,shape[0])
Expand Down

0 comments on commit d4d89df

Please sign in to comment.