1 |
// $Id$ |
2 |
/* |
3 |
****************************************************************************** |
4 |
* * |
5 |
* COPYRIGHT ACcESS 2004 - All Rights Reserved * |
6 |
* * |
7 |
* This software is the property of ACcESS. No part of this code * |
8 |
* may be copied in any form or by any means without the expressed written * |
9 |
* consent of ACcESS. Copying, use or modification of this software * |
10 |
* by any unauthorised person is illegal unless that person has a software * |
11 |
* license agreement with ACcESS. * |
12 |
* * |
13 |
****************************************************************************** |
14 |
*/ |
15 |
|
16 |
#if !defined finley_MeshAdapter_20040526_H |
17 |
#define finley_MeshAdapter_20040526_H |
18 |
|
19 |
#include "escript/Data/AbstractContinuousDomain.h" |
20 |
#include "escript/Data/Data.h" |
21 |
#include "escript/Data/FunctionSpace.h" |
22 |
extern "C" { |
23 |
#include "finley/finleyC/Mesh.h" |
24 |
} |
25 |
#include "finley/CPPAdapter/SystemMatrixAdapter.h" |
26 |
#include <boost/shared_ptr.hpp> |
27 |
#include <boost/python/object.hpp> |
28 |
#include <map> |
29 |
#include <vector> |
30 |
#include <string> |
31 |
|
32 |
namespace finley { |
33 |
|
34 |
struct null_deleter |
35 |
{ |
36 |
void operator()(void const *ptr) const |
37 |
{ |
38 |
} |
39 |
}; |
40 |
|
41 |
|
42 |
/** |
43 |
\brief |
44 |
MeshAdapter implements the AbstractContinuousDomain |
45 |
interface for the Finley library. |
46 |
|
47 |
Description: |
48 |
MeshAdapter implements the AbstractContinuousDomain |
49 |
interface for the Finley library. |
50 |
*/ |
51 |
|
52 |
class MeshAdapter:public escript::AbstractContinuousDomain { |
53 |
|
54 |
public: |
55 |
|
56 |
// |
57 |
// Codes for function space types supported |
58 |
static const int DegreesOfFreedom; |
59 |
static const int ReducedDegreesOfFreedom; |
60 |
static const int Nodes; |
61 |
static const int Elements; |
62 |
static const int FaceElements; |
63 |
static const int Points; |
64 |
static const int ContactElementsZero; |
65 |
static const int ContactElementsOne; |
66 |
|
67 |
/** |
68 |
\brief |
69 |
Constructor for MeshAdapter |
70 |
|
71 |
Description: |
72 |
Constructor for MeshAdapter. The pointer passed to MeshAdapter |
73 |
is deleted using a call to Finley_Mesh_deallocate in the |
74 |
MeshAdapter destructor. |
75 |
|
76 |
Throws: |
77 |
May throw an exception derived from EsysException |
78 |
|
79 |
\param finleyMesh Input - A pointer to the externally constructed |
80 |
finley mesh.The pointer passed to MeshAdapter |
81 |
is deleted using a call to |
82 |
Finley_Mesh_deallocate in the MeshAdapter |
83 |
destructor. |
84 |
*/ |
85 |
MeshAdapter(Finley_Mesh* finleyMesh=0); |
86 |
/** |
87 |
\brief |
88 |
Copy constructor. |
89 |
*/ |
90 |
MeshAdapter(const MeshAdapter& in); |
91 |
/** |
92 |
\brief |
93 |
Destructor for MeshAdapter. As specified in the constructor |
94 |
this calls Finley_Mesh_deallocate for the pointer given to the |
95 |
constructor. |
96 |
*/ |
97 |
~MeshAdapter(); |
98 |
/** |
99 |
\brief |
100 |
return this as an AbstractContinuousDomain. |
101 |
*/ |
102 |
inline const AbstractContinuousDomain& asAbstractContinuousDomain() const |
103 |
{ |
104 |
return *(static_cast<const AbstractContinuousDomain*>(this)); |
105 |
} |
106 |
|
107 |
/** |
108 |
\brief |
109 |
return this as an AbstractDomain. |
110 |
*/ |
111 |
inline const AbstractDomain& asAbstractDomain() const |
112 |
{ |
113 |
return *(static_cast<const AbstractDomain*>(this)); |
114 |
} |
115 |
/** |
116 |
\brief |
117 |
Write the current mesh to a file with the given name. |
118 |
\param fileName Input - The name of the file to write to. |
119 |
*/ |
120 |
void write(const std::string& fileName) const; |
121 |
/** |
122 |
\brief |
123 |
return the pointer of the underlying finley mesh structure |
124 |
*/ |
125 |
Finley_Mesh* getFinley_Mesh() const; |
126 |
/** |
127 |
\brief |
128 |
Return the tag list indexed by sampleNo. |
129 |
\param functionSpaceType Input |
130 |
\param tagList Output |
131 |
\param numTags Output |
132 |
*/ |
133 |
|
134 |
void getTagList(int functionSpaceType, int** tagList, |
135 |
int* numTags) const; |
136 |
/** |
137 |
\brief |
138 |
Return the reference number list indexed by sampleNo. |
139 |
\param functionSpaceType Input |
140 |
\param referenceNoList Output |
141 |
\param numReferenceNo Output |
142 |
*/ |
143 |
void getReferenceNoList(int functionSpaceType, int** referenceNoList, |
144 |
int* numReferenceNo) const; |
145 |
|
146 |
/** |
147 |
\brief |
148 |
Return the tag key for the given sample number. |
149 |
\param functionSpaceType Input - The function space type. |
150 |
\param sampleNo Input - The sample number. |
151 |
*/ |
152 |
int getTagFromSampleNo(int functionSpaceType, int sampleNo) const; |
153 |
/** |
154 |
\brief |
155 |
Return the reference number of the given sample number. |
156 |
\param functionSpaceType Input - The function space type. |
157 |
\param sampleNo Input - The sample number. |
158 |
*/ |
159 |
int getReferenceNoFromSampleNo(int functionSpaceType, int sampleNo) const; |
160 |
|
161 |
/** |
162 |
\brief |
163 |
Returns true if the given integer is a valid function space type |
164 |
for this domain. |
165 |
*/ |
166 |
virtual bool isValidFunctionSpaceType(int functionSpaceType) const; |
167 |
/** |
168 |
\brief |
169 |
Return a description for this domain |
170 |
*/ |
171 |
virtual std::string getDescription() const; |
172 |
/** |
173 |
\brief |
174 |
Return a description for the given function space type code |
175 |
*/ |
176 |
virtual std::string functionSpaceTypeAsString(int functionSpaceType) const; |
177 |
|
178 |
/** |
179 |
\brief |
180 |
Build the table of function space type names |
181 |
*/ |
182 |
void setFunctionSpaceTypeNames(); |
183 |
/** |
184 |
\brief |
185 |
Return a continuous FunctionSpace code |
186 |
*/ |
187 |
virtual int getContinuousFunctionCode() const; |
188 |
/** |
189 |
\brief |
190 |
Return a functon FunctionSpace code |
191 |
*/ |
192 |
virtual int getFunctionCode() const; |
193 |
/** |
194 |
\brief |
195 |
Return a function on boundary FunctionSpace code |
196 |
*/ |
197 |
virtual int getFunctionOnBoundaryCode() const; |
198 |
/** |
199 |
\brief |
200 |
Return a FunctionOnContactZero code |
201 |
*/ |
202 |
virtual int getFunctionOnContactZeroCode() const; |
203 |
/** |
204 |
\brief |
205 |
Return a FunctionOnContactOne code |
206 |
*/ |
207 |
virtual int getFunctionOnContactOneCode() const; |
208 |
/** |
209 |
\brief |
210 |
Return a Solution code |
211 |
*/ |
212 |
virtual int getSolutionCode() const; |
213 |
/** |
214 |
\brief |
215 |
Return a ReducedSolution code |
216 |
*/ |
217 |
virtual int getReducedSolutionCode() const; |
218 |
/** |
219 |
\brief |
220 |
Return a DiracDeltaFunction code |
221 |
*/ |
222 |
virtual int getDiracDeltaFunctionCode() const; |
223 |
// |
224 |
// |
225 |
typedef std::map<int, std::string> FunctionSpaceNamesMapType; |
226 |
/** |
227 |
\brief |
228 |
*/ |
229 |
virtual int getDim() const; |
230 |
/** |
231 |
\brief |
232 |
Return the number of data points per sample, and the number of samples as a pair. |
233 |
\param functionSpaceCode Input - |
234 |
*/ |
235 |
virtual std::pair<int,int> getDataShape(int functionSpaceCode) const; |
236 |
|
237 |
/** |
238 |
\brief |
239 |
copies the location of data points into arg. The domain of arg has to match this. |
240 |
has to be implemented by the actual Domain adapter. |
241 |
*/ |
242 |
virtual void setToX(escript::Data& arg) const; |
243 |
/** |
244 |
\brief |
245 |
assigns new location to the domain |
246 |
*/ |
247 |
virtual void setNewX(const escript::Data& arg); |
248 |
/** |
249 |
\brief |
250 |
interpolates data given on source onto target where source and target have to be given on the same domain. |
251 |
*/ |
252 |
virtual void interpolateOnDomain(escript::Data& target,const escript::Data& source) const; |
253 |
virtual bool probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const; |
254 |
/** |
255 |
\brief |
256 |
interpolates data given on source onto target where source and target are given on different domains. |
257 |
has to be implemented by the actual Domain adapter. |
258 |
*/ |
259 |
virtual void interpolateACross(escript::Data& target, const escript::Data& source) const; |
260 |
virtual bool probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const; |
261 |
/** |
262 |
\brief |
263 |
copies the surface normals at data points into out. The actual function space to be considered |
264 |
is defined by out. out has to be defined on this. |
265 |
*/ |
266 |
virtual void setToNormal(escript::Data& out) const; |
267 |
/** |
268 |
\brief |
269 |
copies the size of samples into out. The actual function space to be considered |
270 |
is defined by out. out has to be defined on this. |
271 |
*/ |
272 |
virtual void setToSize(escript::Data& out) const; |
273 |
|
274 |
/** |
275 |
\brief |
276 |
copies the gradient of arg into grad. The actual function space to be considered |
277 |
for the gradient is defined by grad. arg and grad have to be defined on this. |
278 |
*/ |
279 |
virtual void setToGradient(escript::Data& grad,const escript::Data& arg) const; |
280 |
|
281 |
/** |
282 |
\brief |
283 |
copies the integrals of the function defined by arg into integrals. |
284 |
arg has to be defined on this. |
285 |
*/ |
286 |
virtual void setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const; |
287 |
|
288 |
/** |
289 |
\brief |
290 |
return the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, preconditioner |
291 |
and symmetric matrix is used. |
292 |
\param solver |
293 |
\param symmetry |
294 |
*/ |
295 |
virtual int getSystemMatrixTypeId(const int solver, const bool symmetry) const; |
296 |
|
297 |
/** |
298 |
\brief |
299 |
returns true if data on this domain and a function space of type functionSpaceCode has to |
300 |
considered as cell centered data. |
301 |
*/ |
302 |
virtual bool isCellOriented(int functionSpaceCode) const; |
303 |
/** |
304 |
\brief |
305 |
saves data arg to an OpenDX input file. |
306 |
considered as cell centered data. |
307 |
*/ |
308 |
virtual void saveDX(const std::string& filename,const escript::Data& arg) const; |
309 |
/** |
310 |
\brief |
311 |
saves data arg to a VTK input file. |
312 |
considered as cell centered data. |
313 |
*/ |
314 |
virtual void saveVTK(const std::string& filename,const escript::Data& arg) const; |
315 |
/** |
316 |
\brief |
317 |
returns the function space representation of the type functionSpaceCode on this domain |
318 |
as a vtkObject. |
319 |
*/ |
320 |
// vtkObject createVtkObject(int functionSpaceCode) const; |
321 |
/** |
322 |
\brief |
323 |
adds a PDE onto the stiffness matrix mat and a rhs |
324 |
*/ |
325 |
virtual void addPDEToSystem( |
326 |
SystemMatrixAdapter& mat, escript::Data& rhs, |
327 |
const escript::Data& A, const escript::Data& B, const escript::Data& C, |
328 |
const escript::Data& D, const escript::Data& X, const escript::Data& Y, |
329 |
const escript::Data& d, const escript::Data& y, |
330 |
const escript::Data& d_contact, const escript::Data& y_contact) const; |
331 |
/** |
332 |
\brief |
333 |
adds a PDE onto the stiffness matrix mat and a rhs |
334 |
*/ |
335 |
virtual void addPDEToRHS(escript::Data& rhs, |
336 |
const escript::Data& X, const escript::Data& Y, |
337 |
const escript::Data& y, const escript::Data& y_contact) const; |
338 |
/** |
339 |
\brief |
340 |
creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros: |
341 |
*/ |
342 |
SystemMatrixAdapter newSystemMatrix( |
343 |
const int row_blocksize, |
344 |
const escript::FunctionSpace& row_functionspace, |
345 |
const int column_blocksize, |
346 |
const escript::FunctionSpace& column_functionspace, |
347 |
const int type) const; |
348 |
|
349 |
/** |
350 |
\brief returns locations in the FEM nodes |
351 |
*/ |
352 |
virtual escript::Data getX() const; |
353 |
/** |
354 |
\brief return boundary normals at the quadrature point on the face elements |
355 |
*/ |
356 |
virtual escript::Data getNormal() const; |
357 |
/** |
358 |
\brief returns the element size |
359 |
*/ |
360 |
virtual escript::Data getSize() const; |
361 |
|
362 |
virtual bool operator==(const AbstractDomain& other) const; |
363 |
virtual bool operator!=(const AbstractDomain& other) const; |
364 |
|
365 |
protected: |
366 |
|
367 |
private: |
368 |
// |
369 |
// pointer to the externally created finley mesh |
370 |
boost::shared_ptr<Finley_Mesh> m_finleyMesh; |
371 |
|
372 |
static FunctionSpaceNamesMapType m_functionSpaceTypeNames; |
373 |
|
374 |
}; |
375 |
|
376 |
} // end of namespace |
377 |
#endif |