<s> import unittest <EOL> from SimPEG import * <EOL> import SimPEG . DCIP as DC <EOL> class DCProblemTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> aSpacing = <NUM_LIT> <EOL> nElecs = <NUM_LIT:10> <EOL> surveySize = nElecs * aSpacing - aSpacing <EOL> cs = surveySize / nElecs / <NUM_LIT:4> <EOL> mesh = Mesh . TensorMesh ( [ <EOL> [ ( cs , <NUM_LIT:10> , - <NUM_LIT> ) , ( cs , surveySize / cs ) , ( cs , <NUM_LIT:10> , <NUM_LIT> ) ] , <EOL> [ ( cs , <NUM_LIT:3> , - <NUM_LIT> ) , ( cs , <NUM_LIT:3> , <NUM_LIT> ) ] , <EOL> ] , '<STR_LIT>' ) <EOL> srcList = DC . Utils . WennerSrcList ( nElecs , aSpacing , in2D = True ) <EOL> survey = DC . SurveyDC ( srcList ) <EOL> problem = DC . ProblemDC_CC ( mesh ) <EOL> problem . pair ( survey ) <EOL> mSynth = np . ones ( mesh . nC ) <EOL> survey . makeSyntheticData ( mSynth ) <EOL> dmis = DataMisfit . l2_DataMisfit ( survey ) <EOL> reg = Regularization . Tikhonov ( mesh ) <EOL> opt = Optimization . InexactGaussNewton ( maxIterLS = <NUM_LIT:20> , maxIter = <NUM_LIT:10> , tolF = <NUM_LIT> , tolX = <NUM_LIT> , tolG = <NUM_LIT> , maxIterCG = <NUM_LIT:6> ) <EOL> invProb = InvProblem . BaseInvProblem ( dmis , reg , opt , beta = <NUM_LIT> ) <EOL> inv = Inversion . BaseInversion ( invProb ) <EOL> self . inv = inv <EOL> self . reg = reg <EOL> self . p = problem <EOL> self . mesh = mesh <EOL> self . m0 = mSynth <EOL> self . survey = survey <EOL> self . dmis = dmis <EOL> def test_misfit ( self ) : <EOL> derChk = lambda m : [ self . survey . dpred ( m ) , lambda mx : self . p . Jvec ( self . m0 , mx ) ] <EOL> passed = Tests . checkDerivative ( derChk , self . m0 , plotIt = False ) <EOL> self . assertTrue ( passed ) <EOL> def test_adjoint ( self ) : <EOL> u = np . random . rand ( self . mesh . nC * self . survey . nSrc ) <EOL> v = np . random . rand ( self . mesh . nC ) <EOL> w = np . random . rand ( self . survey . dobs . shape [ <NUM_LIT:0> ] ) <EOL> wtJv = w . dot ( self . p . Jvec ( self . m0 , v ) ) <EOL> vtJtw = v . dot ( self . p . Jtvec ( self . m0 , w ) ) <EOL> passed = np . abs ( wtJv - vtJtw ) < <NUM_LIT> <EOL> print '<STR_LIT>' , np . abs ( wtJv - vtJtw ) , passed <EOL> self . assertTrue ( passed ) <EOL> def test_dataObj ( self ) : <EOL> derChk = lambda m : [ self . dmis . eval ( m ) , self . dmis . evalDeriv ( m ) ] <EOL> passed = Tests . checkDerivative ( derChk , self . m0 , plotIt = False ) <EOL> self . assertTrue ( passed ) <EOL> def test_massMatrices ( self ) : <EOL> Gu = np . random . rand ( self . mesh . nF ) <EOL> def derChk ( m ) : <EOL> self . p . curModel = m <EOL> return [ self . p . Msig * Gu , self . p . dMdsig ( Gu ) ] <EOL> passed = Tests . checkDerivative ( derChk , self . m0 , plotIt = False ) <EOL> self . assertTrue ( passed ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
