/[escript]/trunk/downunder/py_src/forwardmodels.py
ViewVC logotype

Diff of /trunk/downunder/py_src/forwardmodels.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4096 by caltinay, Wed Dec 5 05:32:22 2012 UTC revision 4097 by caltinay, Fri Dec 7 01:18:35 2012 UTC
# Line 67  class ForwardModelWithPotential(ForwardM Line 67  class ForwardModelWithPotential(ForwardM
67          initializes a new forward model with potential.          initializes a new forward model with potential.
68    
69          :param domain: domain of the model          :param domain: domain of the model
70          :type domain: `esys.escript.Domain`          :type domain: `Domain`
71          :param w: data weighting factors          :param w: data weighting factors
72          :type w: `Vector` or list of `Vector`          :type w: ``Vector`` or list of ``Vector``
73          :param data: data          :param data: data
74          :type data: `Vector` or list of `Vector`          :type data: ``Vector`` or list of ``Vector``
75          :param useSphericalCoordinates: if set spherical coordinates are used.          :param useSphericalCoordinates: if set spherical coordinates are used
76          :type useSphericalCoordinates: ``bool``          :type useSphericalCoordinates: ``bool``
77          :param tol: tolerance of underlying PDE          :param tol: tolerance of underlying PDE
78          :type tol: positive ``float``          :type tol: positive ``float``
79          :param scale: constant scaling factor          :param scale: constant scaling factor
80          :type scale: positive ``float``          :type scale: positive ``float``
81    
82          :note: The weighting factors are rescaled such that          :note: The weighting factors are rescaled such that
83               *sum_s integrate(  ( weight_i[s] *data_i[s]) **2  )=1*                 *sum_s integrate( ( weight_i[s] *data_i[s]) **2 )=1*
84          """          """
85          super(ForwardModelWithPotential, self).__init__()          super(ForwardModelWithPotential, self).__init__()
86          self.__domain = domain          self.__domain = domain
# Line 89  class ForwardModelWithPotential(ForwardM Line 89  class ForwardModelWithPotential(ForwardM
89          else:          else:
90               raise ValueError("Scaling factor must be positive.")               raise ValueError("Scaling factor must be positive.")
91    
           
92          if useSphericalCoordinates:          if useSphericalCoordinates:
93               raise ValueError("Spherical coordinates are not supported yet.")               raise ValueError("Spherical coordinates are not supported yet.")
94          else:          else:
# Line 109  class ForwardModelWithPotential(ForwardM Line 108  class ForwardModelWithPotential(ForwardM
108          for s in xrange(len(self.__weight)):          for s in xrange(len(self.__weight)):
109              A += integrate( inner(self.__weight[s], self.__data[s]) **2 )              A += integrate( inner(self.__weight[s], self.__data[s]) **2 )
110          if A > 0:          if A > 0:
111              A=vol(domain)/A              A=vol(domain)/A
112              for s in xrange(len(self.__weight)):  self.__weight[s]*=A              for s in xrange(len(self.__weight)):  self.__weight[s]*=A
113          else:          else:
114              raise ValueError("No non-zero data contribution found.")              raise ValueError("No non-zero data contribution found.")
# Line 122  class ForwardModelWithPotential(ForwardM Line 121  class ForwardModelWithPotential(ForwardM
121          self.__pde.getSolverOptions().setTolerance(tol)          self.__pde.getSolverOptions().setTolerance(tol)
122          self.__pde.setSymmetryOn()          self.__pde.setSymmetryOn()
123          self.__pde.setValue(q=whereZero(x[DIM-1]-BX[DIM-1][1]))          self.__pde.setValue(q=whereZero(x[DIM-1]-BX[DIM-1][1]))
124            
125      def useSphericalCoordinates(self):      def useSphericalCoordinates(self):
126          """          """
127          Returns ``True`` if spherical coordinates are used.          Returns ``True`` if spherical coordinates are used.
128          """          """
129          return self.__useSphericalCoordinates          return self.__useSphericalCoordinates
130        
131      def getScalingFactor(self):      def getScalingFactor(self):
132          """          """
133          Returns the scaling factor.          Returns the scaling factor.
# Line 136  class ForwardModelWithPotential(ForwardM Line 135  class ForwardModelWithPotential(ForwardM
135          :rtype: ``float``          :rtype: ``float``
136          """          """
137          return self.__scale          return self.__scale
138        
139      def getDomain(self):      def getDomain(self):
140          """          """
141          Returns the domain of the forward model.          Returns the domain of the forward model.
142    
143          :rtype: `esys.escript.Domain`          :rtype: `Domain`
144          """          """
145          return self.__domain          return self.__domain
146    
# Line 172  class ForwardModelWithPotential(ForwardM Line 171  class ForwardModelWithPotential(ForwardM
171              Y = inner(self.__weight[s], self.__data[s]-result) * self.__weight[s] + Y              Y = inner(self.__weight[s], self.__data[s]-result) * self.__weight[s] + Y
172          print "self.__scale*Y =",self.__scale*Y          print "self.__scale*Y =",self.__scale*Y
173          return self.__scale*Y          return self.__scale*Y
174            
175      def getSurvey(self, index=None):      def getSurvey(self, index=None):
176          """          """
177          Returns the pair (data_index, weight_index), where data_i is the data          Returns the pair (data_index, weight_index), where data_i is the data
# Line 191  class GravityModel(ForwardModelWithPoten Line 190  class GravityModel(ForwardModelWithPoten
190      """      """
191      Forward Model for gravity inversion as described in the inversion      Forward Model for gravity inversion as described in the inversion
192      cookbook.      cookbook.
           
193      """      """
194      def __init__(self, domain, w, g,  gravity_constant=U.Gravitational_Constant,      def __init__(self, domain, w, g,  gravity_constant=U.Gravitational_Constant,
195                   useSphericalCoordinates=False, scale=1., tol=1e-8):                   useSphericalCoordinates=False, scale=1., tol=1e-8):
196          """          """
197          Creates a new gravity model on the given domain with one or more          Creates a new gravity model on the given domain with one or more
198          surveys (w, g).          surveys (w, g).
199    
200          :param domain: domain of the model          :param domain: domain of the model
201          :type domain: `esys.escript.Domain`          :type domain: `Domain`
202          :param w: data weighting factors          :param w: data weighting factors
203          :type w: `Vector` or list of `Vector`          :type w: ``Vector`` or list of ``Vector``
204          :param g: gravity anomaly data          :param g: gravity anomaly data
205          :type g: `Vector` or list of `Vector`          :type g: ``Vector`` or list of ``Vector``
206          :param useSphericalCoordinates: if set spherical coordinates are used.          :param useSphericalCoordinates: if set spherical coordinates are used.
207          :type useSphericalCoordinates: ``bool``          :type useSphericalCoordinates: ``bool``
208          :param tol: tolerance of underlying PDE          :param tol: tolerance of underlying PDE
209          :type tol: positive ``float``          :type tol: positive ``float``
210          :param scale: constant scaling factor          :param scale: constant scaling factor
211          :type scale: positive ``float``          :type scale: positive ``float``
212    
213          :note: The weighting factors are rescaled such that          :note: The weighting factors are rescaled such that
214               *sum_s integrate(  ( w_i[s] *g_i[s]) **2  )=1*                 *sum_s integrate(  ( w_i[s] *g_i[s]) **2  )=1*
215          """          """
216          super(GravityModel, self).__init__(domain, w, g, useSphericalCoordinates, scale, tol)          super(GravityModel, self).__init__(domain, w, g, useSphericalCoordinates, scale, tol)
217    
# Line 222  class GravityModel(ForwardModelWithPoten Line 220  class GravityModel(ForwardModelWithPoten
220    
221      def getArguments(self, rho):      def getArguments(self, rho):
222          """          """
223          Returns precomputed values shared by getValue() and getGradient().          Returns precomputed values shared by `getValue()` and `getGradient()`.
224    
225          :param rho: a suggestion for the density distribution          :param rho: a suggestion for the density distribution
226          :type rho: `Scalar`          :type rho: ``Scalar``
227          :return: gravity potential and corresponding gravity field.          :return: gravity potential and corresponding gravity field.
228          :rtype: ``Scalar``, ``Vector``          :rtype: ``Scalar``, ``Vector``
229          """          """
# Line 238  class GravityModel(ForwardModelWithPoten Line 236  class GravityModel(ForwardModelWithPoten
236          Calculates the gravity potential for a given density distribution.          Calculates the gravity potential for a given density distribution.
237    
238          :param rho: a suggestion for the density distribution          :param rho: a suggestion for the density distribution
239          :type rho: `Scalar`          :type rho: ``Scalar``
240          :return: gravity potential          :return: gravity potential
241          :rtype: ``Scalar``          :rtype: ``Scalar``
242          """          """
# Line 255  class GravityModel(ForwardModelWithPoten Line 253  class GravityModel(ForwardModelWithPoten
253          Returns the value of the defect          Returns the value of the defect
254    
255          :param rho: density distribution          :param rho: density distribution
256          :type rho: `Scalar`          :type rho: ``Scalar``
257          :param phi: corresponding potential          :param phi: corresponding potential
258          :type phi: `Scalar`          :type phi: ``Scalar``
259          :param gravity_force: gravity force          :param gravity_force: gravity force
260          :type gravity_force: `Vector`          :type gravity_force: ``Vector``
261          :rtype: ``float``          :rtype: ``float``
262          """          """
263          return self.getDefect(gravity_force)          return self.getDefect(gravity_force)
# Line 269  class GravityModel(ForwardModelWithPoten Line 267  class GravityModel(ForwardModelWithPoten
267          Returns the gradient of the defect with respect to density.          Returns the gradient of the defect with respect to density.
268    
269          :param rho: density distribution          :param rho: density distribution
270          :type rho: `Scalar`          :type rho: ``Scalar``
271          :param phi: corresponding potential          :param phi: corresponding potential
272          :type phi: `Scalar`          :type phi: ``Scalar``
273          :param gravity_force: gravity force          :param gravity_force: gravity force
274          :type gravity_force: `Vector`          :type gravity_force: ``Vector``
275          :rtype: `Scalar`          :rtype: ``Scalar``
276          """          """
277          pde=self.getPDE()          pde=self.getPDE()
278          pde.resetRightHandSideCoefficients()          pde.resetRightHandSideCoefficients()
# Line 296  class MagneticModel(ForwardModelWithPote Line 294  class MagneticModel(ForwardModelWithPote
294          :param domain: domain of the model          :param domain: domain of the model
295          :type domain: `Domain`          :type domain: `Domain`
296          :param w: data weighting factors          :param w: data weighting factors
297          :type w: `Vector` or list of `Vector`          :type w: ``Vector`` or list of ``Vector``
298          :param B: magnetic field data          :param B: magnetic field data
299          :type B: `Vector` or list of `Vector`          :type B: ``Vector`` or list of ``Vector``
300          :param tol: tolerance of underlying PDE          :param tol: tolerance of underlying PDE
301          :type tol: positive ``float``          :type tol: positive ``float``
302          :param useSphericalCoordinates: if set spherical coordinates are used.          :param useSphericalCoordinates: if set spherical coordinates are used
303          :type useSphericalCoordinates: ``bool``          :type useSphericalCoordinates: ``bool``
304          :param scale: constant scaling factor          :param scale: constant scaling factor
305          :type scale: positive ``float``          :type scale: positive ``float``
306            
307          :note: The weighting factors are rescaled such that          :note: The weighting factors are rescaled such that
308               *sum_s integrate(  ( w_i[s] *B_i[s]) **2  )=1*                 *sum_s integrate( ( w_i[s] * B_i[s])**2 )=1*
309          """          """
310          super(MagneticModel, self).__init__(domain, w, B, useSphericalCoordinates, scale, tol)                  super(MagneticModel, self).__init__(domain, w, B, useSphericalCoordinates, scale, tol)
311          self.__background_field=interpolate(background_field, B[0].getFunctionSpace())          self.__background_field=interpolate(background_field, B[0].getFunctionSpace())
312          self.getPDE().setValue(A=kronecker(self.getDomain()))          self.getPDE().setValue(A=kronecker(self.getDomain()))
313    
314      def getArguments(self, k):      def getArguments(self, k):
315          """          """
316          Returns precomputed values shared by getValue() and getGradient().          Returns precomputed values shared by `getValue()` and `getGradient()`.
317    
318          :param k: susceptibility          :param k: susceptibility
319          :type k: `Scalar`          :type k: ``Scalar``
320          :return: scalar magnetic potential and corresponding magnetic field          :return: scalar magnetic potential and corresponding magnetic field
321          :rtype: ``Scalar``, ``Vector``          :rtype: ``Scalar``, ``Vector``
322          """          """
# Line 331  class MagneticModel(ForwardModelWithPote Line 329  class MagneticModel(ForwardModelWithPote
329          Calculates the magnetic potential for a given susceptibility.          Calculates the magnetic potential for a given susceptibility.
330    
331          :param k: susceptibility          :param k: susceptibility
332          :type k: `Scalar`          :type k: ``Scalar``
333          :return: magnetic potential          :return: magnetic potential
334          :rtype: ``Scalar``          :rtype: ``Scalar``
335          """          """
# Line 348  class MagneticModel(ForwardModelWithPote Line 346  class MagneticModel(ForwardModelWithPote
346          Returns the value of the defect.          Returns the value of the defect.
347    
348          :param k: susceptibility          :param k: susceptibility
349          :type k: `Scalar`          :type k: ``Scalar``
350          :param phi: corresponding potential          :param phi: corresponding potential
351          :type phi: `Scalar`          :type phi: ``Scalar``
352          :param magnetic_field: magnetic field          :param magnetic_field: magnetic field
353          :type magnetic_field: `Vector`          :type magnetic_field: ``Vector``
354          :rtype: ``float``          :rtype: ``float``
355          """          """
356          return self.getDefect(magnetic_field)          return self.getDefect(magnetic_field)
# Line 362  class MagneticModel(ForwardModelWithPote Line 360  class MagneticModel(ForwardModelWithPote
360          Returns the gradient of the defect with respect to susceptibility.          Returns the gradient of the defect with respect to susceptibility.
361    
362          :param k: susceptibility          :param k: susceptibility
363          :type k: `Scalar`          :type k: ``Scalar``
364          :param phi: corresponding potential          :param phi: corresponding potential
365          :type phi: `Scalar`          :type phi: ``Scalar``
366          :param magnetic_field: magnetic field          :param magnetic_field: magnetic field
367          :type magnetic_field: `Vector`          :type magnetic_field: ``Vector``
368          :rtype: `Scalar`          :rtype: ``Scalar``
369          """          """
370          Y=self.getDefectGradient(magnetic_field)          Y=self.getDefectGradient(magnetic_field)
371          pde=self.getPDE()          pde=self.getPDE()

Legend:
Removed from v.4096  
changed lines
  Added in v.4097

  ViewVC Help
Powered by ViewVC 1.1.26