Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Propogate boundary conditions to old values #921

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 21 additions & 7 deletions fipy/variables/cellVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__docformat__ = 'restructuredtext'

from .meshVariable import _MeshVariable
from .variable import Variable
from ..solvers import _MeshMatrix
from ..tools import numerix
from ..tools.decorators import deprecate
Expand Down Expand Up @@ -478,7 +479,12 @@ def updateOld(self):
raise AssertionError('The updateOld method requires the CellVariable to have an old value. Set hasOld to True when instantiating the CellVariable.')
else:
self._old.value = self.value.copy()


# Also propogate constraints:
if hasattr(self._old, 'faceConstraints'):
for n in range(len(self.faceConstraints)):
self._old.faceConstraints[n].value.setValue(self.faceConstraints[n].value)

def _resetToOld(self):
if self._old is not None:
self.value = (self._old.value)
Expand Down Expand Up @@ -584,19 +590,27 @@ def constrain(self, value, where=None):
"""
from fipy.boundaryConditions.constraint import Constraint
if not isinstance(value, Constraint):
value = Constraint(value=value, where=where)
constraint = Constraint(value=value, where=where)
else:
constraint = value

if numerix.shape(value.where)[-1] == self.mesh.numberOfFaces:
if numerix.shape(constraint.where)[-1] == self.mesh.numberOfFaces:

if not hasattr(self, 'faceConstraints'):
self.faceConstraints = []
self.faceConstraints.append(value)
self._requires(value.value)
# self._requires(value.where) ???

self.faceConstraints.append(constraint)

if self._old is not None:
value_old = Variable(value = value)
self._old.constrain(value=value_old, where=where)

self._requires(constraint.value)
# self._requires(constraint.where) ???
self._markStale()
else:
## _MeshVariable.constrain(value, where)
super(CellVariable, self).constrain(value, where)
super(CellVariable, self).constrain(constraint, where)

def release(self, constraint):
"""Remove `constraint` from `self`
Expand Down