From 09eafc78a9c496995614f4dbdea39c98de04a247 Mon Sep 17 00:00:00 2001 From: Michael Krayer Date: Thu, 24 Jun 2021 13:04:35 +0200 Subject: [PATCH] division operator --- field.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/field.py b/field.py index be8ac34..0b65980 100644 --- a/field.py +++ b/field.py @@ -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]."