/[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 3947 - (show annotations)
Wed Aug 22 23:19:10 2012 UTC (7 years, 2 months ago) by caltinay
File MIME type: text/x-python
File size: 2495 byte(s)
Compiling and installing downunder module now. Adjusted import statements
accordingly. Added a gravity test run.

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

  ViewVC Help
Powered by ViewVC 1.1.26