division operator

This commit is contained in:
Michael Krayer 2021-06-24 13:04:35 +02:00
parent 1ca85cd7c2
commit 09eafc78a9
1 changed files with 15 additions and 0 deletions

View File

@ -39,6 +39,13 @@ class Field3d:
else:
return Field3d(self.data*other,self.origin,self.spacing)
def __truediv__(self,other):
if isinstance(other,Field3d):
assert self.has_same_grid(other), "Grid mismatch."
return Field3d(self.data/other.data,self.origin,self.spacing)
else:
return Field3d(self.data/other,self.origin,self.spacing)
def __radd__(self,other):
return Field3d(other+self.data,self.origin,self.spacing)
@ -72,6 +79,14 @@ class Field3d:
self.data *= other
return self
def __itruediv__(self,other):
if isinstance(other,Field3d):
assert self.has_same_grid(other), "Grid mismatch."
self.data /= other.data
else:
self.data /= other
return self
# TBD: this should return another Field3d object
# def __getitem__(self,val):
# assert isinstance(val,tuple) and len(val)==3, "Field3d must be indexed by [ii,jj,kk]."