parameters: (self, model)
return_statement: return self.lastResponse
docstring: Solve forward task and return apparent resistivity for self.mesh.
docstring_summary: Solve forward task and return apparent resistivity for self.mesh.
docstring_tokens: Solve forward task and return apparent resistivity for self . mesh .
function: def response(self, model):
          """Solve forward task and return apparent resistivity for self.mesh."""
          # NOTE TODO can't be MT until mixed boundary condition depends on
          # self.resistivity
          pg.tic()
          if not self.data.allNonZero('k'):
              pg.error('Need valid geometric factors: "k".')
              pg.warn('Fallback "k" values to -sign("rhoa")')
              self.data.set('k', -pg.math.sign(self.data('rhoa')))
  
          mesh = self.mesh()
  
          nDof = mesh.nodeCount()
          elecs = self.data.sensorPositions()
  
          nEle = len(elecs)
          nData = self.data.size()
  
          self.resistivity = res = self.createMappedModel(model, -1.0)
  
          if self.verbose:
              print("Calculate response for model:", min(res), max(res))
  
          rMin = elecs[0].dist(elecs[1]) / 2.0
          rMax = elecs[0].dist(elecs[-1]) * 2.0
  
          k, w = self.getIntegrationWeights(rMin, rMax)
  
          self.k = k
          self.w = w
  
          # pg.show(mesh, res, label='res')
          # pg.wait()
  
          rhs = self.createRHS(mesh, elecs)
  
          # store all potential fields
          u = np.zeros((nEle, nDof))
          self.subPotentials = [pg.Matrix(nEle, nDof) for i in range(len(k))]
  
          for i, ki in enumerate(k):
              uE = pg.solve(mesh, a=1./res, b=-(ki * ki)/res, f=rhs,
                            bc={'Robin': ['*', self.mixedBC]},
                            userData={'sourcePos': elecs, 'k': ki},
                            verbose=False, stats=0, debug=False)
              self.subPotentials[i] = uE
              u += w[i] * uE
  
          # collect potential matrix,
          # i.e., potential for all electrodes and all injections
          pM = np.zeros((nEle, nEle))
  
          for i in range(nEle):
              pM[i] = pg.interpolate(mesh, u[i, :], destPos=elecs)
  
          # collect resistivity values for all 4 pole measurements
          r = np.zeros(nData)
  
          for i in range(nData):
              iA = int(self.data('a')[i])
              iB = int(self.data('b')[i])
              iM = int(self.data('m')[i])
              iN = int(self.data('n')[i])
  
              uAB = pM[iA] - pM[iB]
              r[i] = uAB[iM] - uAB[iN]
  
          self.lastResponse = r * self.data('k')
  
          if self.verbose:
              print("Resp min/max: {0} {1} {2}s".format(min(self.lastResponse),
                                                        max(self.lastResponse),
                                                        pg.dur()))
  
          return self.lastResponse
function_tokens: def response ( self , model ) : # NOTE TODO can't be MT until mixed boundary condition depends on # self.resistivity pg . tic ( ) if not self . data . allNonZero ( 'k' ) : pg . error ( 'Need valid geometric factors: "k".' ) pg . warn ( 'Fallback "k" values to -sign("rhoa")' ) self . data . set ( 'k' , - pg . math . sign ( self . data ( 'rhoa' ) ) ) mesh = self . mesh ( ) nDof = mesh . nodeCount ( ) elecs = self . data . sensorPositions ( ) nEle = len ( elecs ) nData = self . data . size ( ) self . resistivity = res = self . createMappedModel ( model , - 1.0 ) if self . verbose : print ( "Calculate response for model:" , min ( res ) , max ( res ) ) rMin = elecs [ 0 ] . dist ( elecs [ 1 ] ) / 2.0 rMax = elecs [ 0 ] . dist ( elecs [ - 1 ] ) * 2.0 k , w = self . getIntegrationWeights ( rMin , rMax ) self . k = k self . w = w # pg.show(mesh, res, label='res') # pg.wait() rhs = self . createRHS ( mesh , elecs ) # store all potential fields u = np . zeros ( ( nEle , nDof ) ) self . subPotentials = [ pg . Matrix ( nEle , nDof ) for i in range ( len ( k ) ) ] for i , ki in enumerate ( k ) : uE = pg . solve ( mesh , a = 1. / res , b = - ( ki * ki ) / res , f = rhs , bc = { 'Robin' : [ '*' , self . mixedBC ] } , userData = { 'sourcePos' : elecs , 'k' : ki } , verbose = False , stats = 0 , debug = False ) self . subPotentials [ i ] = uE u += w [ i ] * uE # collect potential matrix, # i.e., potential for all electrodes and all injections pM = np . zeros ( ( nEle , nEle ) ) for i in range ( nEle ) : pM [ i ] = pg . interpolate ( mesh , u [ i , : ] , destPos = elecs ) # collect resistivity values for all 4 pole measurements r = np . zeros ( nData ) for i in range ( nData ) : iA = int ( self . data ( 'a' ) [ i ] ) iB = int ( self . data ( 'b' ) [ i ] ) iM = int ( self . data ( 'm' ) [ i ] ) iN = int ( self . data ( 'n' ) [ i ] ) uAB = pM [ iA ] - pM [ iB ] r [ i ] = uAB [ iM ] - uAB [ iN ] self . lastResponse = r * self . data ( 'k' ) if self . verbose : print ( "Resp min/max: {0} {1} {2}s" . format ( min ( self . lastResponse ) , max ( self . lastResponse ) , pg . dur ( ) ) ) return self . lastResponse