Allow aliased field to be a property of the fields object.

This commit is contained in:
rowanc1
2014-05-15 12:37:35 -07:00
parent dd0a2e3878
commit 399678e496
2 changed files with 12 additions and 6 deletions
+9 -3
View File
@@ -353,7 +353,10 @@ class Fields(object):
else:
# Aliased fields
alias, loc, func = self.aliasFields[name]
out = func(self, self._fields[alias][:,ind], ind)
if type(func) is str:
assert hasattr(self, func), 'The alias field function is a string, but it does not exist in the Fields class.'
func = getattr(self, func)
out = func(self._fields[alias][:,ind], ind)
if out.shape[1] == 1:
out = Utils.mkvc(out)
@@ -431,16 +434,19 @@ class TimeFields(Fields):
else:
# Aliased fields
alias, loc, func = self.aliasFields[name]
if type(func) is str:
assert hasattr(self, func), 'The alias field function is a string, but it does not exist in the Fields class.'
func = getattr(self, func)
pointerFields = self._fields[alias][:,txInd,timeInd]
pointerShape = self._correctShape(alias, ind, deflate=True)
pointerFields = pointerFields.reshape(pointerShape, order='F')
if len(pointerShape) < 3:
out = func(self, pointerFields, txInd)
out = func(pointerFields, txInd)
else: #loop over the time steps
nT = pointerShape[2]
out = range(nT)
for i in range(nT):
out[i] = func(self, pointerFields[:,:,i], txInd)
out[i] = func(pointerFields[:,:,i], txInd)
out[i] = out[i][:,:,np.newaxis]
out = np.concatenate(out, axis=2)
+3 -3
View File
@@ -133,7 +133,7 @@ class FieldsTest_Alias(unittest.TestCase):
txList = [Tx0,Tx1,Tx2,Tx3,Tx4]
survey = Survey.BaseSurvey(txList=txList)
self.D = Survey.Data(survey)
self.F = Survey.Fields(mesh, survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',(lambda F, e, ind: F.mesh.edgeCurl * e)]})
self.F = Survey.Fields(mesh, survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',(lambda e, ind: self.F.mesh.edgeCurl * e)]})
self.Tx0 = Tx0
self.Tx1 = Tx1
self.mesh = mesh
@@ -287,8 +287,8 @@ class FieldsTest_Time_Aliased(unittest.TestCase):
survey = Survey.BaseSurvey(txList=txList)
prob = Problem.BaseTimeProblem(mesh, timeSteps=[(10.,3), (20.,2)])
survey.pair(prob)
def alias(F, b, ind):
return F.mesh.edgeCurl.T * b
def alias(b, ind):
return self.F.mesh.edgeCurl.T * b
self.F = Survey.TimeFields(mesh, survey, knownFields={'b':'F'}, aliasFields={'e':['b','E',alias]})
self.Tx0 = Tx0
self.Tx1 = Tx1