1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
""" |
""" |
4 |
provides a some tools related to PDEs currently includes: |
Provides some tools related to PDEs. |
|
|
|
|
Projector - to project a discontinuous |
|
|
|
|
5 |
|
|
6 |
|
Currently includes: |
7 |
|
- Projector - to project a discontinuous |
8 |
""" |
""" |
9 |
|
|
10 |
from escript import * |
import escript |
11 |
from linearPDEs import LinearPDE |
import linearPDEs |
12 |
import numarray |
import numarray |
13 |
|
import util |
14 |
|
|
15 |
class Projector: |
class Projector: |
16 |
"""The Projector is a factory which projects a discontiuous function onto a continuous function on the a given domain""" |
""" |
17 |
|
The Projector is a factory which projects a discontiuous function onto a |
18 |
|
continuous function on the a given domain. |
19 |
|
""" |
20 |
def __init__(self, domain, reduce = True, fast=True): |
def __init__(self, domain, reduce = True, fast=True): |
21 |
""" |
""" |
22 |
@brief Create a continuous function space projector for a domain. |
Create a continuous function space projector for a domain. |
23 |
|
|
24 |
@param domain Domain of the projection. |
@param domain: Domain of the projection. |
25 |
@param reduce Flag to reduce projection order (default is True) |
@param reduce: Flag to reduce projection order (default is True) |
26 |
@param fast Flag to use a fast method based on matrix lumping (default is true) |
@param fast: Flag to use a fast method based on matrix lumping (default is true) |
27 |
""" |
""" |
28 |
self.__pde = LinearPDE(domain) |
self.__pde = linearPDEs.LinearPDE(domain) |
29 |
if fast: |
if fast: |
30 |
self.__pde.setSolverMethod(LinearPDE.LUMPING) |
self.__pde.setSolverMethod(linearPDEs.LinearPDE.LUMPING) |
31 |
self.__pde.setSymmetryOn() |
self.__pde.setSymmetryOn() |
32 |
self.__pde.setReducedOrderTo(reduce) |
self.__pde.setReducedOrderTo(reduce) |
33 |
self.__pde.setValue(D = 1.) |
self.__pde.setValue(D = 1.) |
38 |
|
|
39 |
def __call__(self, input_data): |
def __call__(self, input_data): |
40 |
""" |
""" |
41 |
@brief projects input_data onto a continuous function |
Projects input_data onto a continuous function |
42 |
|
|
43 |
@param input_data The input_data to be projected. |
@param input_data: The input_data to be projected. |
44 |
""" |
""" |
45 |
out=Data(0.,input_data.getShape(),what=ContinuousFunction(self.__pde.getDomain())) |
out=escript.Data(0.,input_data.getShape(),what=escript.ContinuousFunction(self.__pde.getDomain())) |
46 |
if input_data.getRank()==0: |
if input_data.getRank()==0: |
47 |
self.__pde.setValue(Y = input_data) |
self.__pde.setValue(Y = input_data) |
48 |
out=self.__pde.getSolution() |
out=self.__pde.getSolution() |
73 |
|
|
74 |
class Locator: |
class Locator: |
75 |
""" |
""" |
76 |
|
Locator provides access to the values of data objects at a given |
77 |
Locator provides a access the values of data objects at a given spatial coordinate x. |
spatial coordinate x. |
78 |
In fact, a Locator object finds the sample in the set of samples of a given function space or domain where which is closest |
|
79 |
to the given point x. |
In fact, a Locator object finds the sample in the set of samples of a |
80 |
|
given function space or domain where which is closest to the given |
81 |
|
point x. |
82 |
""" |
""" |
83 |
|
|
84 |
def __init__(self,where,x=numarray.zeros((3,))): |
def __init__(self,where,x=numarray.zeros((3,))): |
85 |
"""initializes a Locator to access values in Data objects on the Doamin or FunctionSpace where for the sample point which |
""" |
86 |
closest to the given point x""" |
Initializes a Locator to access values in Data objects on the Doamin |
87 |
if isinstance(where,FunctionSpace): |
or FunctionSpace where for the sample point which |
88 |
|
closest to the given point x. |
89 |
|
""" |
90 |
|
if isinstance(where,escript.FunctionSpace): |
91 |
self.__function_space=where |
self.__function_space=where |
92 |
else: |
else: |
93 |
self.__function_space=ContinuousFunction(where) |
self.__function_space=escript.ContinuousFunction(where) |
94 |
self.__id=length(x[:self.__function_space.getDim()]-self.__function_space.getX()).mindp() |
self.__id=util.length(x[:self.__function_space.getDim()]-self.__function_space.getX()).mindp() |
95 |
|
|
96 |
def __str__(self): |
def __str__(self): |
97 |
"""returns the coordinates of the Locator as a string""" |
""" |
98 |
|
Returns the coordinates of the Locator as a string. |
99 |
|
""" |
100 |
return "<Locator %s>"%str(self.getX()) |
return "<Locator %s>"%str(self.getX()) |
101 |
|
|
102 |
def getFunctionSpace(self): |
def getFunctionSpace(self): |
103 |
"""returns the function space of the Locator""" |
""" |
104 |
|
Returns the function space of the Locator. |
105 |
|
""" |
106 |
return self.__function_space |
return self.__function_space |
107 |
|
|
108 |
def getId(self): |
def getId(self): |
109 |
"""returns the identifier of the location""" |
""" |
110 |
|
Returns the identifier of the location. |
111 |
|
""" |
112 |
return self.__id |
return self.__id |
113 |
|
|
114 |
def getX(self): |
def getX(self): |
115 |
"""returns the exact coordinates of the Locator""" |
""" |
116 |
|
Returns the exact coordinates of the Locator. |
117 |
|
""" |
118 |
return self(self.getFunctionSpace().getX()) |
return self(self.getFunctionSpace().getX()) |
119 |
|
|
120 |
def __call__(self,data): |
def __call__(self,data): |
121 |
"""returns the value of data at the Locator of a Data object otherwise the object is returned.""" |
""" |
122 |
|
Returns the value of data at the Locator of a Data object otherwise |
123 |
|
the object is returned. |
124 |
|
""" |
125 |
return self.getValue(data) |
return self.getValue(data) |
126 |
|
|
127 |
def getValue(self,data): |
def getValue(self,data): |
128 |
"""returns the value of data at the Locator if data is a Data object otherwise the object is returned.""" |
""" |
129 |
if isinstance(data,Data): |
Returns the value of data at the Locator if data is a Data object |
130 |
|
otherwise the object is returned. |
131 |
|
""" |
132 |
|
if isinstance(data,escript.Data): |
133 |
if data.getFunctionSpace()==self.getFunctionSpace(): |
if data.getFunctionSpace()==self.getFunctionSpace(): |
134 |
out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1]) |
out=data.convertToNumArrayFromDPNo(self.getId()[0],self.getId()[1]) |
135 |
else: |
else: |
140 |
return out |
return out |
141 |
else: |
else: |
142 |
return data |
return data |
143 |
|
|
144 |
|
# vim: expandtab shiftwidth=4: |