<s> from SimPEG import * <EOL> import SimPEG . DCIP as DC <EOL> def run ( plotIt = False ) : <EOL> cs = <NUM_LIT> <EOL> hx = [ ( cs , <NUM_LIT:7> , - <NUM_LIT> ) , ( cs , <NUM_LIT> ) , ( cs , <NUM_LIT:7> , <NUM_LIT> ) ] <EOL> hy = [ ( cs , <NUM_LIT:7> , - <NUM_LIT> ) , ( cs , <NUM_LIT> ) , ( cs , <NUM_LIT:7> , <NUM_LIT> ) ] <EOL> hz = [ ( cs , <NUM_LIT:7> , - <NUM_LIT> ) , ( cs , <NUM_LIT:20> ) ] <EOL> mesh = Mesh . TensorMesh ( [ hx , hy , hz ] , '<STR_LIT>' ) <EOL> sighalf = <NUM_LIT> <EOL> sigma = np . ones ( mesh . nC ) * sighalf <EOL> xtemp = np . linspace ( - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> ytemp = np . linspace ( - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> xyz_rxP = Utils . ndgrid ( xtemp - <NUM_LIT> , ytemp , np . r_ [ <NUM_LIT:0.> ] ) <EOL> xyz_rxN = Utils . ndgrid ( xtemp + <NUM_LIT> , ytemp , np . r_ [ <NUM_LIT:0.> ] ) <EOL> xyz_rxM = Utils . ndgrid ( xtemp , ytemp , np . r_ [ <NUM_LIT:0.> ] ) <EOL> rx = DC . RxDipole ( xyz_rxP , xyz_rxN ) <EOL> src = DC . SrcDipole ( [ rx ] , [ - <NUM_LIT:200> , <NUM_LIT:0> , - <NUM_LIT> ] , [ + <NUM_LIT:200> , <NUM_LIT:0> , - <NUM_LIT> ] ) <EOL> survey = DC . SurveyDC ( [ src ] ) <EOL> problem = DC . ProblemDC_CC ( mesh ) <EOL> problem . pair ( survey ) <EOL> try : <EOL> from pymatsolver import MumpsSolver <EOL> problem . Solver = MumpsSolver <EOL> except Exception , e : <EOL> pass <EOL> data = survey . dpred ( sigma ) <EOL> def DChalf ( srclocP , srclocN , rxloc , sigma , I = <NUM_LIT:1.> ) : <EOL> rp = ( srclocP . reshape ( [ <NUM_LIT:1> , - <NUM_LIT:1> ] ) ) . repeat ( rxloc . shape [ <NUM_LIT:0> ] , axis = <NUM_LIT:0> ) <EOL> rn = ( srclocN . reshape ( [ <NUM_LIT:1> , - <NUM_LIT:1> ] ) ) . repeat ( rxloc . shape [ <NUM_LIT:0> ] , axis = <NUM_LIT:0> ) <EOL> rP = np . sqrt ( ( ( rxloc - rp ) ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:1> ) ) <EOL> rN = np . sqrt ( ( ( rxloc - rn ) ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:1> ) ) <EOL> return I / ( sigma * <NUM_LIT> * np . pi ) * ( <NUM_LIT:1> / rP - <NUM_LIT:1> / rN ) <EOL> data_anaP = DChalf ( np . r_ [ - <NUM_LIT:200> , <NUM_LIT:0> , <NUM_LIT:0.> ] , np . r_ [ + <NUM_LIT:200> , <NUM_LIT:0> , <NUM_LIT:0.> ] , xyz_rxP , sighalf ) <EOL> data_anaN = DChalf ( np . r_ [ - <NUM_LIT:200> , <NUM_LIT:0> , <NUM_LIT:0.> ] , np . r_ [ + <NUM_LIT:200> , <NUM_LIT:0> , <NUM_LIT:0.> ] , xyz_rxN , sighalf ) <EOL> data_ana = data_anaP - data_anaN <EOL> Data_ana = data_ana . reshape ( ( <NUM_LIT> , <NUM_LIT> ) , order = '<STR_LIT:F>' ) <EOL> Data = data . reshape ( ( <NUM_LIT> , <NUM_LIT> ) , order = '<STR_LIT:F>' ) <EOL> X = xyz_rxM [ : , <NUM_LIT:0> ] . reshape ( ( <NUM_LIT> , <NUM_LIT> ) , order = '<STR_LIT:F>' ) <EOL> Y = xyz_rxM [ : , <NUM_LIT:1> ] . reshape ( ( <NUM_LIT> , <NUM_LIT> ) , order = '<STR_LIT:F>' ) <EOL> if plotIt : <EOL> import matplotlib . pyplot as plt <EOL> fig , ax = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:2> , figsize = ( <NUM_LIT:12> , <NUM_LIT:5> ) ) <EOL> vmin = np . r_ [ data , data_ana ] . min ( ) <EOL> vmax = np . r_ [ data , data_ana ] . max ( ) <EOL> dat1 = ax [ <NUM_LIT:1> ] . contourf ( X , Y , Data , <NUM_LIT> , vmin = vmin , vmax = vmax ) <EOL> dat0 = ax [ <NUM_LIT:0> ] . contourf ( X , Y , Data_ana , <NUM_LIT> , vmin = vmin , vmax = vmax ) <EOL> cb0 = plt . colorbar ( dat1 , orientation = '<STR_LIT>' , ax = ax [ <NUM_LIT:0> ] ) <EOL> cb1 = plt . colorbar ( dat1 , orientation = '<STR_LIT>' , ax = ax [ <NUM_LIT:1> ] ) <EOL> ax [ <NUM_LIT:1> ] . set_title ( '<STR_LIT>' ) <EOL> ax [ <NUM_LIT:0> ] . set_title ( '<STR_LIT>' ) <EOL> plt . show ( ) <EOL> return np . linalg . norm ( data - data_ana ) / np . linalg . norm ( data_ana ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print run ( plotIt = True ) </s>
