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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4007 - (hide annotations)
Tue Oct 2 02:12:01 2012 UTC (7 years, 2 months ago) by caltinay
File MIME type: text/x-python
File size: 2677 byte(s)
Doco updates.
Data source paddings now take x,y not xy,z as Z padding can be done by setting
vertical extents.

1 caltinay 3946
2 jfenwick 3981 ##############################################################################
3 caltinay 3946 #
4     # Copyright (c) 2003-2012 by University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 caltinay 3946 #
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 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     # Development since 2012 by School of Earth Sciences
13     #
14     ##############################################################################
15 caltinay 3946
16     __copyright__="""Copyright (c) 2003-2012 by University of Queensland
17 jfenwick 3981 http://www.uq.edu.au
18 caltinay 3946 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 caltinay 3947 __all__ = ['Regularization']
24    
25 caltinay 3946 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 caltinay 4007 """
34     """
35 caltinay 3946 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    
48     self.__projector=LinearSinglePDE(domain)
49     self.__projector.getSolverOptions().setTolerance(tol)
50     self.__projector.setValue(A=kronecker(domain), q=location_of_set_m, D=0.)
51    
52     def getInner(self, f0, f1):
53     """
54     returns the inner product of two gradients.
55     """
56     return integrate(inner(grad(f0),grad(f1)))
57    
58     def project(self, Y=Data(), X=Data()):
59 caltinay 4007 """
60     """
61 caltinay 3946 self.__projector.setValue(Y=Y, X=X)
62     return self.__projector.getSolution()
63    
64     def getValue(self, m):
65 caltinay 4007 """
66     """
67 caltinay 3946 A=0
68     if self._w0 is not None:
69     A=(m-self.__m_ref)**2 * self._w0
70     if self._w is not None:
71     A=inner(self._w, grad(m-self.__m_ref)**2) + A
72     return integrate(A)
73    
74     def getGradient(self, m):
75 caltinay 4007 """
76     """
77 caltinay 3946 if not self._w0 == None:
78     Y=2. * (m-self.__m_ref) * self._w0
79     else:
80     Y=0.
81     if not self._w == None:
82     X=2. * grad(m-self.__m_ref) * self._w
83     else:
84     X=np.zeros((self.__domain.getDim(),))
85    
86     return Y, X
87    
88     def getArguments(self, m):
89 caltinay 4007 """
90     """
91 caltinay 3946 return ()
92    

  ViewVC Help
Powered by ViewVC 1.1.26