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

Contents of /trunk/downunder/py_src/regularizations.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4044 - (show annotations)
Tue Oct 30 03:35:17 2012 UTC (7 years ago) by caltinay
File MIME type: text/x-python
File size: 2664 byte(s)
Some doco fixes for downunder.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2012 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 __all__ = ['Regularization']
24
25 import numpy as np
26 from esys.escript.linearPDEs import LinearSinglePDE
27 from esys.escript import Data, grad, inner, integrate, kronecker, vol
28
29 class Regularization(object):
30 """
31 """
32 def __init__(self, domain, m_ref=0, w0=None, w=None, location_of_set_m=Data(), tol=1e-8):
33 """
34 """
35 self.__domain=domain
36 self.__m_ref=m_ref
37 self.location_of_set_m=location_of_set_m
38 if w0 is None:
39 self._w0 = None
40 else:
41 self._w0=np.asarray(w0) / vol(self.__domain)
42 if w is None:
43 self._w = None
44 else:
45 self._w=np.asarray(w)
46
47 self.__projector=LinearSinglePDE(domain)
48 self.__projector.getSolverOptions().setTolerance(tol)
49 self.__projector.setValue(A=kronecker(domain), q=location_of_set_m, D=0.)
50
51 def getInner(self, f0, f1):
52 """
53 returns the inner product of two gradients.
54 """
55 return integrate(inner(grad(f0),grad(f1)))
56
57 def project(self, Y=Data(), X=Data()):
58 """
59 """
60 self.__projector.setValue(Y=Y, X=X)
61 return self.__projector.getSolution()
62
63 def getValue(self, m):
64 """
65 """
66 A=0
67 if self._w0 is not None:
68 A=(m-self.__m_ref)**2 * self._w0
69 if self._w is not None:
70 A=inner(self._w, grad(m-self.__m_ref)**2) + A
71 return integrate(A)
72
73 def getGradient(self, m):
74 """
75 """
76 if not self._w0 == None:
77 Y=2. * (m-self.__m_ref) * self._w0
78 else:
79 Y=0.
80 if not self._w == None:
81 X=2. * grad(m-self.__m_ref) * self._w
82 else:
83 X=np.zeros((self.__domain.getDim(),))
84
85 return Y, X
86
87 def getArguments(self, m):
88 """
89 """
90 return ()
91

  ViewVC Help
Powered by ViewVC 1.1.26