<s> from SimPEG import Survey , Problem , Utils , np , sp <EOL> from scipy . constants import mu_0 <EOL> from SimPEG . EM . Utils import * <EOL> from SimPEG . Utils import Zero <EOL> class BaseSrc ( Survey . BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> freq = None <EOL> integrate = True <EOL> def eval ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> S_m = self . S_m ( prob ) <EOL> S_e = self . S_e ( prob ) <EOL> return S_m , S_e <EOL> def evalDeriv ( self , prob , v = None , adjoint = False ) : <EOL> """<STR_LIT>""" <EOL> if v is not None : <EOL> return self . S_mDeriv ( prob , v , adjoint ) , self . S_eDeriv ( prob , v , adjoint ) <EOL> else : <EOL> return lambda v : self . S_mDeriv ( prob , v , adjoint ) , lambda v : self . S_eDeriv ( prob , v , adjoint ) <EOL> def bPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def hPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def ePrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def jPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def S_mDeriv ( self , prob , v , adjoint = False ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> def S_eDeriv ( self , prob , v , adjoint = False ) : <EOL> """<STR_LIT>""" <EOL> return Zero ( ) <EOL> class RawVec_e ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , S_e , integrate = True ) : <EOL> self . _S_e = np . array ( S_e , dtype = complex ) <EOL> self . freq = float ( freq ) <EOL> self . integrate = integrate <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if prob . _formulation is '<STR_LIT>' and self . integrate is True : <EOL> return prob . Me * self . _S_e <EOL> return self . _S_e <EOL> class RawVec_m ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , S_m , integrate = True ) : <EOL> self . _S_m = np . array ( S_m , dtype = complex ) <EOL> self . freq = float ( freq ) <EOL> self . integrate = integrate <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if prob . _formulation is '<STR_LIT>' and self . integrate is True : <EOL> return prob . Me * self . _S_m <EOL> return self . _S_m <EOL> class RawVec ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , S_m , S_e , integrate = True ) : <EOL> self . _S_m = np . array ( S_m , dtype = complex ) <EOL> self . _S_e = np . array ( S_e , dtype = complex ) <EOL> self . freq = float ( freq ) <EOL> self . integrate = integrate <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if prob . _formulation is '<STR_LIT>' and self . integrate is True : <EOL> return prob . Me * self . _S_m <EOL> return self . _S_m <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if prob . _formulation is '<STR_LIT>' and self . integrate is True : <EOL> return prob . Me * self . _S_e <EOL> return self . _S_e <EOL> class MagDipole ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , loc , orientation = '<STR_LIT>' , moment = <NUM_LIT:1.> , mu = mu_0 ) : <EOL> self . freq = float ( freq ) <EOL> self . loc = loc <EOL> self . orientation = orientation <EOL> assert orientation in [ '<STR_LIT:X>' , '<STR_LIT:Y>' , '<STR_LIT>' ] , "<STR_LIT>" <EOL> self . moment = moment <EOL> self . mu = mu <EOL> self . integrate = False <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def bPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridEx <EOL> gridY = prob . mesh . gridEy <EOL> gridZ = prob . mesh . gridEz <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridFx <EOL> gridY = prob . mesh . gridFy <EOL> gridZ = prob . mesh . gridFz <EOL> C = prob . mesh . edgeCurl . T <EOL> if prob . mesh . _meshType is '<STR_LIT>' : <EOL> if not prob . mesh . isSymmetric : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> a = MagneticDipoleVectorPotential ( self . loc , gridY , '<STR_LIT:y>' , mu = self . mu , moment = self . moment ) <EOL> else : <EOL> srcfct = MagneticDipoleVectorPotential <EOL> ax = srcfct ( self . loc , gridX , '<STR_LIT:x>' , mu = self . mu , moment = self . moment ) <EOL> ay = srcfct ( self . loc , gridY , '<STR_LIT:y>' , mu = self . mu , moment = self . moment ) <EOL> az = srcfct ( self . loc , gridZ , '<STR_LIT:z>' , mu = self . mu , moment = self . moment ) <EOL> a = np . concatenate ( ( ax , ay , az ) ) <EOL> return C * a <EOL> def hPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b = self . bPrimary ( prob ) <EOL> return <NUM_LIT:1.> / self . mu * b <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b_p = self . bPrimary ( prob ) <EOL> if prob . _formulation is '<STR_LIT>' : <EOL> b_p = prob . Me * b_p <EOL> return - <NUM_LIT> * omega ( self . freq ) * b_p <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if all ( np . r_ [ self . mu ] == np . r_ [ prob . curModel . mu ] ) : <EOL> return Zero ( ) <EOL> else : <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> mui_s = prob . curModel . mui - <NUM_LIT:1.> / self . mu <EOL> MMui_s = prob . mesh . getFaceInnerProduct ( mui_s ) <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> mu_s = prob . curModel . mu - self . mu <EOL> MMui_s = prob . mesh . getEdgeInnerProduct ( mu_s , invMat = True ) <EOL> C = prob . mesh . edgeCurl . T <EOL> return - C . T * ( MMui_s * self . bPrimary ( prob ) ) <EOL> class MagDipole_Bfield ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , loc , orientation = '<STR_LIT>' , moment = <NUM_LIT:1.> , mu = mu_0 ) : <EOL> self . freq = float ( freq ) <EOL> self . loc = loc <EOL> assert orientation in [ '<STR_LIT:X>' , '<STR_LIT:Y>' , '<STR_LIT>' ] , "<STR_LIT>" <EOL> self . orientation = orientation <EOL> self . moment = moment <EOL> self . mu = mu <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def bPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridFx <EOL> gridY = prob . mesh . gridFy <EOL> gridZ = prob . mesh . gridFz <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridEx <EOL> gridY = prob . mesh . gridEy <EOL> gridZ = prob . mesh . gridEz <EOL> C = prob . mesh . edgeCurl . T <EOL> srcfct = MagneticDipoleFields <EOL> if prob . mesh . _meshType is '<STR_LIT>' : <EOL> if not prob . mesh . isSymmetric : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> bx = srcfct ( self . loc , gridX , '<STR_LIT:x>' , mu = self . mu , moment = self . moment ) <EOL> bz = srcfct ( self . loc , gridZ , '<STR_LIT:z>' , mu = self . mu , moment = self . moment ) <EOL> b = np . concatenate ( ( bx , bz ) ) <EOL> else : <EOL> bx = srcfct ( self . loc , gridX , '<STR_LIT:x>' , mu = self . mu , moment = self . moment ) <EOL> by = srcfct ( self . loc , gridY , '<STR_LIT:y>' , mu = self . mu , moment = self . moment ) <EOL> bz = srcfct ( self . loc , gridZ , '<STR_LIT:z>' , mu = self . mu , moment = self . moment ) <EOL> b = np . concatenate ( ( bx , by , bz ) ) <EOL> return b <EOL> def hPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b = self . bPrimary ( prob ) <EOL> return <NUM_LIT:1> / self . mu * b <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b = self . bPrimary ( prob ) <EOL> if prob . _formulation is '<STR_LIT>' : <EOL> b = prob . Me * b <EOL> return - <NUM_LIT> * omega ( self . freq ) * b <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if all ( np . r_ [ self . mu ] == np . r_ [ prob . curModel . mu ] ) : <EOL> return Zero ( ) <EOL> else : <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> mui_s = prob . curModel . mui - <NUM_LIT:1.> / self . mu <EOL> MMui_s = prob . mesh . getFaceInnerProduct ( mui_s ) <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> mu_s = prob . curModel . mu - self . mu <EOL> MMui_s = prob . mesh . getEdgeInnerProduct ( mu_s , invMat = True ) <EOL> C = prob . mesh . edgeCurl . T <EOL> return - C . T * ( MMui_s * self . bPrimary ( prob ) ) <EOL> class CircularLoop ( BaseSrc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rxList , freq , loc , orientation = '<STR_LIT>' , radius = <NUM_LIT:1.> , mu = mu_0 ) : <EOL> self . freq = float ( freq ) <EOL> self . orientation = orientation <EOL> assert orientation in [ '<STR_LIT:X>' , '<STR_LIT:Y>' , '<STR_LIT>' ] , "<STR_LIT>" <EOL> self . radius = radius <EOL> self . mu = mu <EOL> self . loc = loc <EOL> self . integrate = False <EOL> BaseSrc . __init__ ( self , rxList ) <EOL> def bPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridEx <EOL> gridY = prob . mesh . gridEy <EOL> gridZ = prob . mesh . gridEz <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> gridX = prob . mesh . gridFx <EOL> gridY = prob . mesh . gridFy <EOL> gridZ = prob . mesh . gridFz <EOL> C = prob . mesh . edgeCurl . T <EOL> if prob . mesh . _meshType is '<STR_LIT>' : <EOL> if not prob . mesh . isSymmetric : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> a = MagneticDipoleVectorPotential ( self . loc , gridY , '<STR_LIT:y>' , moment = self . radius , mu = self . mu ) <EOL> else : <EOL> srcfct = MagneticDipoleVectorPotential <EOL> ax = srcfct ( self . loc , gridX , '<STR_LIT:x>' , self . radius , mu = self . mu ) <EOL> ay = srcfct ( self . loc , gridY , '<STR_LIT:y>' , self . radius , mu = self . mu ) <EOL> az = srcfct ( self . loc , gridZ , '<STR_LIT:z>' , self . radius , mu = self . mu ) <EOL> a = np . concatenate ( ( ax , ay , az ) ) <EOL> return C * a <EOL> def hPrimary ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b = self . bPrimary ( prob ) <EOL> return <NUM_LIT:1.> / self . mu * b <EOL> def S_m ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> b = self . bPrimary ( prob ) <EOL> if prob . _formulation is '<STR_LIT>' : <EOL> b = prob . Me * b <EOL> return - <NUM_LIT> * omega ( self . freq ) * b <EOL> def S_e ( self , prob ) : <EOL> """<STR_LIT>""" <EOL> if all ( np . r_ [ self . mu ] == np . r_ [ prob . curModel . mu ] ) : <EOL> return Zero ( ) <EOL> else : <EOL> formulation = prob . _formulation <EOL> if formulation is '<STR_LIT>' : <EOL> mui_s = prob . curModel . mui - <NUM_LIT:1.> / self . mu <EOL> MMui_s = prob . mesh . getFaceInnerProduct ( mui_s ) <EOL> C = prob . mesh . edgeCurl <EOL> elif formulation is '<STR_LIT>' : <EOL> mu_s = prob . curModel . mu - self . mu <EOL> MMui_s = prob . mesh . getEdgeInnerProduct ( mu_s , invMat = True ) <EOL> C = prob . mesh . edgeCurl . T <EOL> return - C . T * ( MMui_s * self . bPrimary ( prob ) ) </s>
