/[escript]/trunk/finley/src/CPPAdapter/MeshAdapter.cpp
ViewVC logotype

Contents of /trunk/finley/src/CPPAdapter/MeshAdapter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1346 - (show annotations)
Wed Nov 14 22:48:12 2007 UTC (11 years, 8 months ago) by ksteube
File size: 80790 byte(s)
dump/LoadMesh methods work except for TagMap, Point elements probably OK but are untested.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "MeshAdapter.h"
17 #include "escript/Data.h"
18 #include "escript/DataFactory.h"
19 #ifdef USE_NETCDF
20 #include <netcdfcpp.h>
21 #endif
22 extern "C" {
23 #include "escript/blocktimer.h"
24 }
25 #include <vector>
26
27 using namespace std;
28 using namespace escript;
29
30 namespace finley {
31
32 //
33 // define the static constants
34 MeshAdapter::FunctionSpaceNamesMapType MeshAdapter::m_functionSpaceTypeNames;
35 const int MeshAdapter::DegreesOfFreedom=FINLEY_DEGREES_OF_FREEDOM;
36 const int MeshAdapter::ReducedDegreesOfFreedom=FINLEY_REDUCED_DEGREES_OF_FREEDOM;
37 const int MeshAdapter::Nodes=FINLEY_NODES;
38 const int MeshAdapter::ReducedNodes=FINLEY_REDUCED_NODES;
39 const int MeshAdapter::Elements=FINLEY_ELEMENTS;
40 const int MeshAdapter::ReducedElements=FINLEY_REDUCED_ELEMENTS;
41 const int MeshAdapter::FaceElements=FINLEY_FACE_ELEMENTS;
42 const int MeshAdapter::ReducedFaceElements=FINLEY_REDUCED_FACE_ELEMENTS;
43 const int MeshAdapter::Points=FINLEY_POINTS;
44 const int MeshAdapter::ContactElementsZero=FINLEY_CONTACT_ELEMENTS_1;
45 const int MeshAdapter::ReducedContactElementsZero=FINLEY_REDUCED_CONTACT_ELEMENTS_1;
46 const int MeshAdapter::ContactElementsOne=FINLEY_CONTACT_ELEMENTS_2;
47 const int MeshAdapter::ReducedContactElementsOne=FINLEY_REDUCED_CONTACT_ELEMENTS_2;
48
49 MeshAdapter::MeshAdapter(Finley_Mesh* finleyMesh)
50 {
51 setFunctionSpaceTypeNames();
52 //
53 // need to use a null_deleter as Finley_Mesh_free deletes the pointer
54 // for us.
55 m_finleyMesh.reset(finleyMesh,null_deleter());
56 }
57
58 //
59 // The copy constructor should just increment the use count
60 MeshAdapter::MeshAdapter(const MeshAdapter& in):
61 m_finleyMesh(in.m_finleyMesh)
62 {
63 setFunctionSpaceTypeNames();
64 }
65
66 MeshAdapter::~MeshAdapter()
67 {
68 //
69 // I hope the case for the pointer being zero has been taken care of.
70 // cout << "In MeshAdapter destructor." << endl;
71 if (m_finleyMesh.unique()) {
72 Finley_Mesh_free(m_finleyMesh.get());
73 }
74 }
75
76 int MeshAdapter::getMPISize() const
77 {
78 return m_finleyMesh.get()->MPIInfo->size;
79 }
80 int MeshAdapter::getMPIRank() const
81 {
82 return m_finleyMesh.get()->MPIInfo->rank;
83 }
84
85
86 Finley_Mesh* MeshAdapter::getFinley_Mesh() const {
87 return m_finleyMesh.get();
88 }
89
90 void MeshAdapter::write(const std::string& fileName) const
91 {
92 char *fName = (fileName.size()+1>0) ? TMPMEMALLOC(fileName.size()+1,char) : (char*)NULL;
93 strcpy(fName,fileName.c_str());
94 Finley_Mesh_write(m_finleyMesh.get(),fName);
95 checkFinleyError();
96 TMPMEMFREE(fName);
97 }
98
99 void MeshAdapter::Print_Mesh_Info(const bool full=false) const
100 {
101 Finley_PrintMesh_Info(m_finleyMesh.get(), full);
102 }
103
104 void MeshAdapter::dump(const std::string& fileName) const
105 {
106 #ifdef USE_NETCDF
107 const NcDim* ncdims[25]; /* ksteube how big should ncdims be? */
108 NcVar *ids, *data;
109 int *int_ptr;
110 Finley_Mesh *mesh = m_finleyMesh.get();
111 int mpi_size = mesh->MPIInfo->size;
112 int mpi_rank = mesh->MPIInfo->rank;
113 int numDim = mesh->Nodes->numDim;
114 int numNodes = mesh->Nodes->numNodes;
115 int num_Elements = mesh->Elements->numElements;
116 int num_FaceElements = mesh->FaceElements->numElements;
117 int num_ContactElements = mesh->ContactElements->numElements;
118 int num_Points = mesh->Points->numElements;
119 int num_Elements_numNodes = mesh->Elements->numNodes;
120 int num_FaceElements_numNodes = mesh->FaceElements->numNodes;
121 int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
122 char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);
123
124 // NetCDF error handler
125 NcError err(NcError::verbose_nonfatal);
126 // Create the file.
127 NcFile dataFile(newFileName, NcFile::Replace);
128 // check if writing was successful
129 if (!dataFile.is_valid())
130 throw DataException("Error - MeshAdapter::dump: opening of NetCDF file for output failed: " + *newFileName);
131
132 // Define dimensions (num_Elements and dim_Elements are identical, dim_Elements only appears if > 0)
133 if (! (ncdims[0] = dataFile.add_dim("numNodes", numNodes)) )
134 throw DataException("Error - MeshAdapter::dump: appending dimension numNodes to netCDF file failed: " + *newFileName);
135 if (! (ncdims[1] = dataFile.add_dim("numDim", numDim)) )
136 throw DataException("Error - MeshAdapter::dump: appending dimension numDim to netCDF file failed: " + *newFileName);
137 if (! (ncdims[2] = dataFile.add_dim("mpi_size_plus_1", mpi_size+1)) )
138 throw DataException("Error - MeshAdapter::dump: appending dimension mpi_size to netCDF file failed: " + *newFileName);
139 if (num_Elements>0)
140 if (! (ncdims[3] = dataFile.add_dim("dim_Elements", num_Elements)) )
141 throw DataException("Error - MeshAdapter::dump: appending dimension dim_Elements to netCDF file failed: " + *newFileName);
142 if (num_FaceElements>0)
143 if (! (ncdims[4] = dataFile.add_dim("dim_FaceElements", num_FaceElements)) )
144 throw DataException("Error - MeshAdapter::dump: appending dimension dim_FaceElements to netCDF file failed: " + *newFileName);
145 if (num_ContactElements>0)
146 if (! (ncdims[5] = dataFile.add_dim("dim_ContactElements", num_ContactElements)) )
147 throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements to netCDF file failed: " + *newFileName);
148 if (num_Points>0)
149 if (! (ncdims[6] = dataFile.add_dim("dim_Points", num_Points)) )
150 throw DataException("Error - MeshAdapter::dump: appending dimension dim_Points to netCDF file failed: " + *newFileName);
151 if (num_Elements>0)
152 if (! (ncdims[7] = dataFile.add_dim("dim_Elements_Nodes", num_Elements_numNodes)) )
153 throw DataException("Error - MeshAdapter::dump: appending dimension dim_Elements_Nodes to netCDF file failed: " + *newFileName);
154 if (num_FaceElements>0)
155 if (! (ncdims[8] = dataFile.add_dim("dim_FaceElements_numNodes", num_FaceElements_numNodes)) )
156 throw DataException("Error - MeshAdapter::dump: appending dimension dim_FaceElements_numNodes to netCDF file failed: " + *newFileName);
157 if (num_ContactElements>0)
158 if (! (ncdims[9] = dataFile.add_dim("dim_ContactElements_numNodes", num_ContactElements_numNodes)) )
159 throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements_numNodes to netCDF file failed: " + *newFileName);
160
161 // Attributes: MPI size, MPI rank, Name, order, reduced_order
162 if (!dataFile.add_att("mpi_size", mpi_size) )
163 throw DataException("Error - MeshAdapter::dump: appending mpi_size to NetCDF file failed: " + *newFileName);
164 if (!dataFile.add_att("mpi_rank", mpi_rank) )
165 throw DataException("Error - MeshAdapter::dump: appending mpi_rank to NetCDF file failed: " + *newFileName);
166 if (!dataFile.add_att("Name",mesh->Name) )
167 throw DataException("Error - MeshAdapter::dump: appending Name to NetCDF file failed: " + *newFileName);
168 if (!dataFile.add_att("numDim",numDim) )
169 throw DataException("Error - MeshAdapter::dump: appending order to NetCDF file failed: " + *newFileName);
170 if (!dataFile.add_att("order",mesh->order) )
171 throw DataException("Error - MeshAdapter::dump: appending order to NetCDF file failed: " + *newFileName);
172 if (!dataFile.add_att("reduced_order",mesh->reduced_order) )
173 throw DataException("Error - MeshAdapter::dump: appending reduced_order to NetCDF file failed: " + *newFileName);
174 if (!dataFile.add_att("numNodes",numNodes) )
175 throw DataException("Error - MeshAdapter::dump: appending numNodes to NetCDF file failed: " + *newFileName);
176 if (!dataFile.add_att("num_Elements",num_Elements) )
177 throw DataException("Error - MeshAdapter::dump: appending num_Elements to NetCDF file failed: " + *newFileName);
178 if (!dataFile.add_att("num_FaceElements",num_FaceElements) )
179 throw DataException("Error - MeshAdapter::dump: appending num_FaceElements to NetCDF file failed: " + *newFileName);
180 if (!dataFile.add_att("num_ContactElements",num_ContactElements) )
181 throw DataException("Error - MeshAdapter::dump: appending num_ContactElements to NetCDF file failed: " + *newFileName);
182 if (!dataFile.add_att("num_Points",num_Points) )
183 throw DataException("Error - MeshAdapter::dump: appending num_Points to NetCDF file failed: " + *newFileName);
184 if (!dataFile.add_att("num_Elements_numNodes",num_Elements_numNodes) )
185 throw DataException("Error - MeshAdapter::dump: appending num_Elements_numNodes to NetCDF file failed: " + *newFileName);
186 if (!dataFile.add_att("num_FaceElements_numNodes",num_FaceElements_numNodes) )
187 throw DataException("Error - MeshAdapter::dump: appending num_FaceElements_numNodes to NetCDF file failed: " + *newFileName);
188 if (!dataFile.add_att("num_ContactElements_numNodes",num_ContactElements_numNodes) )
189 throw DataException("Error - MeshAdapter::dump: appending num_ContactElements_numNodes to NetCDF file failed: " + *newFileName);
190
191 // // // // // Nodes // // // // //
192
193 // Only write nodes if non-empty because NetCDF doesn't like empty arrays (it treats them as NC_UNLIMITED)
194 if (numNodes>0) {
195
196 // Nodes Id
197 if (! ( ids = dataFile.add_var("Nodes_Id", ncInt, ncdims[0])) )
198 throw DataException("Error - MeshAdapter::dump: appending Nodes_Id to netCDF file failed: " + *newFileName);
199 int_ptr = &mesh->Nodes->Id[0];
200 if (! (ids->put(int_ptr, numNodes)) )
201 throw DataException("Error - MeshAdapter::dump: copy Nodes_Id to netCDF buffer failed: " + *newFileName);
202
203 // Nodes Tag
204 if (! ( ids = dataFile.add_var("Nodes_Tag", ncInt, ncdims[0])) )
205 throw DataException("Error - MeshAdapter::dump: appending Nodes_Tag to netCDF file failed: " + *newFileName);
206 int_ptr = &mesh->Nodes->Tag[0];
207 if (! (ids->put(int_ptr, numNodes)) )
208 throw DataException("Error - MeshAdapter::dump: copy Nodes_Tag to netCDF buffer failed: " + *newFileName);
209
210 // Nodes gDOF
211 if (! ( ids = dataFile.add_var("Nodes_gDOF", ncInt, ncdims[0])) )
212 throw DataException("Error - MeshAdapter::dump: appending Nodes_gDOF to netCDF file failed: " + *newFileName);
213 int_ptr = &mesh->Nodes->globalDegreesOfFreedom[0];
214 if (! (ids->put(int_ptr, numNodes)) )
215 throw DataException("Error - MeshAdapter::dump: copy Nodes_gDOF to netCDF buffer failed: " + *newFileName);
216
217 // Nodes global node index
218 if (! ( ids = dataFile.add_var("Nodes_gNI", ncInt, ncdims[0])) )
219 throw DataException("Error - MeshAdapter::dump: appending Nodes_gNI to netCDF file failed: " + *newFileName);
220 int_ptr = &mesh->Nodes->globalNodesIndex[0];
221 if (! (ids->put(int_ptr, numNodes)) )
222 throw DataException("Error - MeshAdapter::dump: copy Nodes_gNI to netCDF buffer failed: " + *newFileName);
223
224 // Nodes grDof
225 if (! ( ids = dataFile.add_var("Nodes_grDfI", ncInt, ncdims[0])) )
226 throw DataException("Error - MeshAdapter::dump: appending Nodes_grDfI to netCDF file failed: " + *newFileName);
227 int_ptr = &mesh->Nodes->globalReducedDOFIndex[0];
228 if (! (ids->put(int_ptr, numNodes)) )
229 throw DataException("Error - MeshAdapter::dump: copy Nodes_grDfI to netCDF buffer failed: " + *newFileName);
230
231 // Nodes grNI
232 if (! ( ids = dataFile.add_var("Nodes_grNI", ncInt, ncdims[0])) )
233 throw DataException("Error - MeshAdapter::dump: appending Nodes_grNI to netCDF file failed: " + *newFileName);
234 int_ptr = &mesh->Nodes->globalReducedNodesIndex[0];
235 if (! (ids->put(int_ptr, numNodes)) )
236 throw DataException("Error - MeshAdapter::dump: copy Nodes_grNI to netCDF buffer failed: " + *newFileName);
237
238 // Nodes Coordinates
239 if (! ( ids = dataFile.add_var("Nodes_Coordinates", ncDouble, ncdims[0], ncdims[1]) ) )
240 throw DataException("Error - MeshAdapter::dump: appending Nodes_Coordinates to netCDF file failed: " + *newFileName);
241 if (! (ids->put(&(mesh->Nodes->Coordinates[INDEX2(0,0,numDim)]), numNodes, numDim)) )
242 throw DataException("Error - MeshAdapter::dump: copy Nodes_Coordinates to netCDF buffer failed: " + *newFileName);
243
244 // Nodes degreesOfFreedomDistribution
245 if (! ( ids = dataFile.add_var("Nodes_DofDistribution", ncInt, ncdims[2])) )
246 throw DataException("Error - MeshAdapter::dump: appending Nodes_DofDistribution to netCDF file failed: " + *newFileName);
247 int_ptr = &mesh->Nodes->degreesOfFreedomDistribution->first_component[0];
248 if (! (ids->put(int_ptr, mpi_size+1)) )
249 throw DataException("Error - MeshAdapter::dump: copy Nodes_DofDistribution to netCDF buffer failed: " + *newFileName);
250
251 }
252
253 // // // // // Elements // // // // //
254
255 if (num_Elements>0) {
256
257 // Temp storage to gather node IDs
258 int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);
259
260 // Elements ReferenceElement->ElementTypeId
261 if (!dataFile.add_att("Elements_TypeId", mesh->Elements->ReferenceElement->Type->TypeId) )
262 throw DataException("Error - MeshAdapter::dump: appending Elements_TypeId to NetCDF file failed: " + *newFileName);
263
264 // Elements_Id
265 if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
266 throw DataException("Error - MeshAdapter::dump: appending Elements_Id to netCDF file failed: " + *newFileName);
267 int_ptr = &mesh->Elements->Id[0];
268 if (! (ids->put(int_ptr, num_Elements)) )
269 throw DataException("Error - MeshAdapter::dump: copy Elements_Id to netCDF buffer failed: " + *newFileName);
270
271 // Elements_Tag
272 if (! ( ids = dataFile.add_var("Elements_Tag", ncInt, ncdims[3])) )
273 throw DataException("Error - MeshAdapter::dump: appending Elements_Tag to netCDF file failed: " + *newFileName);
274 int_ptr = &mesh->Elements->Tag[0];
275 if (! (ids->put(int_ptr, num_Elements)) )
276 throw DataException("Error - MeshAdapter::dump: copy Elements_Tag to netCDF buffer failed: " + *newFileName);
277
278 // Elements_Owner
279 if (! ( ids = dataFile.add_var("Elements_Owner", ncInt, ncdims[3])) )
280 throw DataException("Error - MeshAdapter::dump: appending Elements_Owner to netCDF file failed: " + *newFileName);
281 int_ptr = &mesh->Elements->Owner[0];
282 if (! (ids->put(int_ptr, num_Elements)) )
283 throw DataException("Error - MeshAdapter::dump: copy Elements_Owner to netCDF buffer failed: " + *newFileName);
284
285 // Elements_Color
286 if (! ( ids = dataFile.add_var("Elements_Color", ncInt, ncdims[3])) )
287 throw DataException("Error - MeshAdapter::dump: appending Elements_Color to netCDF file failed: " + *newFileName);
288 int_ptr = &mesh->Elements->Color[0];
289 if (! (ids->put(int_ptr, num_Elements)) )
290 throw DataException("Error - MeshAdapter::dump: copy Elements_Color to netCDF buffer failed: " + *newFileName);
291
292 // Elements_Nodes
293 for (int i=0; i<num_Elements; i++)
294 for (int j=0; j<num_Elements_numNodes; j++)
295 Elements_Nodes[INDEX2(j,i,num_Elements_numNodes)] = mesh->Nodes->Id[mesh->Elements->Nodes[INDEX2(j,i,num_Elements_numNodes)]];
296 if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
297 throw DataException("Error - MeshAdapter::dump: appending Elements_Nodes to netCDF file failed: " + *newFileName);
298 if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )
299 throw DataException("Error - MeshAdapter::dump: copy Elements_Nodes to netCDF buffer failed: " + *newFileName);
300
301 TMPMEMFREE(Elements_Nodes);
302
303 }
304
305 // // // // // Face_Elements // // // // //
306
307 if (num_FaceElements>0) {
308
309 // Temp storage to gather node IDs
310 int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);
311
312 // FaceElements ReferenceElement->ElementTypeId
313 if (!dataFile.add_att("FaceElements_TypeId", mesh->FaceElements->ReferenceElement->Type->TypeId) )
314 throw DataException("Error - MeshAdapter::dump: appending FaceElements_TypeId to NetCDF file failed: " + *newFileName);
315
316 // FaceElements_Id
317 if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
318 throw DataException("Error - MeshAdapter::dump: appending FaceElements_Id to netCDF file failed: " + *newFileName);
319 int_ptr = &mesh->FaceElements->Id[0];
320 if (! (ids->put(int_ptr, num_FaceElements)) )
321 throw DataException("Error - MeshAdapter::dump: copy FaceElements_Id to netCDF buffer failed: " + *newFileName);
322
323 // FaceElements_Tag
324 if (! ( ids = dataFile.add_var("FaceElements_Tag", ncInt, ncdims[4])) )
325 throw DataException("Error - MeshAdapter::dump: appending FaceElements_Tag to netCDF file failed: " + *newFileName);
326 int_ptr = &mesh->FaceElements->Tag[0];
327 if (! (ids->put(int_ptr, num_FaceElements)) )
328 throw DataException("Error - MeshAdapter::dump: copy FaceElements_Tag to netCDF buffer failed: " + *newFileName);
329
330 // FaceElements_Owner
331 if (! ( ids = dataFile.add_var("FaceElements_Owner", ncInt, ncdims[4])) )
332 throw DataException("Error - MeshAdapter::dump: appending FaceElements_Owner to netCDF file failed: " + *newFileName);
333 int_ptr = &mesh->FaceElements->Owner[0];
334 if (! (ids->put(int_ptr, num_FaceElements)) )
335 throw DataException("Error - MeshAdapter::dump: copy FaceElements_Owner to netCDF buffer failed: " + *newFileName);
336
337 // FaceElements_Color
338 if (! ( ids = dataFile.add_var("FaceElements_Color", ncInt, ncdims[4])) )
339 throw DataException("Error - MeshAdapter::dump: appending FaceElements_Color to netCDF file failed: " + *newFileName);
340 int_ptr = &mesh->FaceElements->Color[0];
341 if (! (ids->put(int_ptr, num_FaceElements)) )
342 throw DataException("Error - MeshAdapter::dump: copy FaceElements_Color to netCDF buffer failed: " + *newFileName);
343
344 // FaceElements_Nodes
345 for (int i=0; i<num_FaceElements; i++)
346 for (int j=0; j<num_FaceElements_numNodes; j++)
347 FaceElements_Nodes[INDEX2(j,i,num_FaceElements_numNodes)] = mesh->Nodes->Id[mesh->FaceElements->Nodes[INDEX2(j,i,num_FaceElements_numNodes)]];
348 if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
349 throw DataException("Error - MeshAdapter::dump: appending FaceElements_Nodes to netCDF file failed: " + *newFileName);
350 if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
351 throw DataException("Error - MeshAdapter::dump: copy FaceElements_Nodes to netCDF buffer failed: " + *newFileName);
352
353 TMPMEMFREE(FaceElements_Nodes);
354
355 }
356
357 // // // // // Contact_Elements // // // // //
358
359 if (num_ContactElements>0) {
360
361 // Temp storage to gather node IDs
362 int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);
363
364 // ContactElements ReferenceElement->ElementTypeId
365 if (!dataFile.add_att("ContactElements_TypeId", mesh->ContactElements->ReferenceElement->Type->TypeId) )
366 throw DataException("Error - MeshAdapter::dump: appending ContactElements_TypeId to NetCDF file failed: " + *newFileName);
367
368 // ContactElements_Id
369 if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
370 throw DataException("Error - MeshAdapter::dump: appending ContactElements_Id to netCDF file failed: " + *newFileName);
371 int_ptr = &mesh->ContactElements->Id[0];
372 if (! (ids->put(int_ptr, num_ContactElements)) )
373 throw DataException("Error - MeshAdapter::dump: copy ContactElements_Id to netCDF buffer failed: " + *newFileName);
374
375 // ContactElements_Tag
376 if (! ( ids = dataFile.add_var("ContactElements_Tag", ncInt, ncdims[5])) )
377 throw DataException("Error - MeshAdapter::dump: appending ContactElements_Tag to netCDF file failed: " + *newFileName);
378 int_ptr = &mesh->ContactElements->Tag[0];
379 if (! (ids->put(int_ptr, num_ContactElements)) )
380 throw DataException("Error - MeshAdapter::dump: copy ContactElements_Tag to netCDF buffer failed: " + *newFileName);
381
382 // ContactElements_Owner
383 if (! ( ids = dataFile.add_var("ContactElements_Owner", ncInt, ncdims[5])) )
384 throw DataException("Error - MeshAdapter::dump: appending ContactElements_Owner to netCDF file failed: " + *newFileName);
385 int_ptr = &mesh->ContactElements->Owner[0];
386 if (! (ids->put(int_ptr, num_ContactElements)) )
387 throw DataException("Error - MeshAdapter::dump: copy ContactElements_Owner to netCDF buffer failed: " + *newFileName);
388
389 // ContactElements_Color
390 if (! ( ids = dataFile.add_var("ContactElements_Color", ncInt, ncdims[5])) )
391 throw DataException("Error - MeshAdapter::dump: appending ContactElements_Color to netCDF file failed: " + *newFileName);
392 int_ptr = &mesh->ContactElements->Color[0];
393 if (! (ids->put(int_ptr, num_ContactElements)) )
394 throw DataException("Error - MeshAdapter::dump: copy ContactElements_Color to netCDF buffer failed: " + *newFileName);
395
396 // ContactElements_Nodes
397 for (int i=0; i<num_ContactElements; i++)
398 for (int j=0; j<num_ContactElements_numNodes; j++)
399 ContactElements_Nodes[INDEX2(j,i,num_ContactElements_numNodes)] = mesh->Nodes->Id[mesh->ContactElements->Nodes[INDEX2(j,i,num_ContactElements_numNodes)]];
400 if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
401 throw DataException("Error - MeshAdapter::dump: appending ContactElements_Nodes to netCDF file failed: " + *newFileName);
402 if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
403 throw DataException("Error - MeshAdapter::dump: copy ContactElements_Nodes to netCDF buffer failed: " + *newFileName);
404
405 TMPMEMFREE(ContactElements_Nodes);
406
407 }
408
409 // // // // // Points // // // // //
410
411 if (num_Points>0) {
412
413 fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump has not been tested with Point elements\n\n\n");
414
415 // Temp storage to gather node IDs
416 int *Points_Nodes = TMPMEMALLOC(num_Points,int);
417
418 // Points ReferenceElement->ElementTypeId
419 if (!dataFile.add_att("Points_TypeId", mesh->Points->ReferenceElement->Type->TypeId) )
420 throw DataException("Error - MeshAdapter::dump: appending Points_TypeId to NetCDF file failed: " + *newFileName);
421
422 // Points_Id
423 if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
424 throw DataException("Error - MeshAdapter::dump: appending Points_Id to netCDF file failed: " + *newFileName);
425 int_ptr = &mesh->Points->Id[0];
426 if (! (ids->put(int_ptr, num_Points)) )
427 throw DataException("Error - MeshAdapter::dump: copy Points_Id to netCDF buffer failed: " + *newFileName);
428
429 // Points_Tag
430 if (! ( ids = dataFile.add_var("Points_Tag", ncInt, ncdims[6])) )
431 throw DataException("Error - MeshAdapter::dump: appending Points_Tag to netCDF file failed: " + *newFileName);
432 int_ptr = &mesh->Points->Tag[0];
433 if (! (ids->put(int_ptr, num_Points)) )
434 throw DataException("Error - MeshAdapter::dump: copy Points_Tag to netCDF buffer failed: " + *newFileName);
435
436 // Points_Owner
437 if (! ( ids = dataFile.add_var("Points_Owner", ncInt, ncdims[6])) )
438 throw DataException("Error - MeshAdapter::dump: appending Points_Owner to netCDF file failed: " + *newFileName);
439 int_ptr = &mesh->Points->Owner[0];
440 if (! (ids->put(int_ptr, num_Points)) )
441 throw DataException("Error - MeshAdapter::dump: copy Points_Owner to netCDF buffer failed: " + *newFileName);
442
443 // Points_Color
444 if (! ( ids = dataFile.add_var("Points_Color", ncInt, ncdims[6])) )
445 throw DataException("Error - MeshAdapter::dump: appending Points_Color to netCDF file failed: " + *newFileName);
446 int_ptr = &mesh->Points->Color[0];
447 if (! (ids->put(int_ptr, num_Points)) )
448 throw DataException("Error - MeshAdapter::dump: copy Points_Color to netCDF buffer failed: " + *newFileName);
449
450 // Points_Nodes
451 // mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]]
452 for (int i=0; i<num_Points; i++)
453 Points_Nodes[i] = mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]];
454 if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
455 throw DataException("Error - MeshAdapter::dump: appending Points_Nodes to netCDF file failed: " + *newFileName);
456 if (! (ids->put(&(Points_Nodes[0]), num_Points)) )
457 throw DataException("Error - MeshAdapter::dump: copy Points_Nodes to netCDF buffer failed: " + *newFileName);
458
459 TMPMEMFREE(Points_Nodes);
460
461 }
462
463 // // // // // TagMap // // // // //
464
465 fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump does not save the TagMap yet\n\n\n");
466
467 // NetCDF file is closed by destructor of NcFile object
468 #else
469 Finley_setError(IO_ERROR, "MeshAdapter::dump: not configured with NetCDF. Please contact your installation manager.");
470 #endif /* USE_NETCDF */
471 checkFinleyError();
472 }
473
474 string MeshAdapter::getDescription() const
475 {
476 return "FinleyMesh";
477 }
478
479 string MeshAdapter::functionSpaceTypeAsString(int functionSpaceType) const
480 {
481 FunctionSpaceNamesMapType::iterator loc;
482 loc=m_functionSpaceTypeNames.find(functionSpaceType);
483 if (loc==m_functionSpaceTypeNames.end()) {
484 return "Invalid function space type code.";
485 } else {
486 return loc->second;
487 }
488 }
489
490 bool MeshAdapter::isValidFunctionSpaceType(int functionSpaceType) const
491 {
492 FunctionSpaceNamesMapType::iterator loc;
493 loc=m_functionSpaceTypeNames.find(functionSpaceType);
494 return (loc!=m_functionSpaceTypeNames.end());
495 }
496
497 void MeshAdapter::setFunctionSpaceTypeNames()
498 {
499 m_functionSpaceTypeNames.insert
500 (FunctionSpaceNamesMapType::value_type(DegreesOfFreedom,"Finley_DegreesOfFreedom"));
501 m_functionSpaceTypeNames.insert
502 (FunctionSpaceNamesMapType::value_type(ReducedDegreesOfFreedom,"Finley_ReducedDegreesOfFreedom"));
503 m_functionSpaceTypeNames.insert
504 (FunctionSpaceNamesMapType::value_type(Nodes,"Finley_Nodes"));
505 m_functionSpaceTypeNames.insert
506 (FunctionSpaceNamesMapType::value_type(ReducedNodes,"Finley_Reduced_Nodes"));
507 m_functionSpaceTypeNames.insert
508 (FunctionSpaceNamesMapType::value_type(Elements,"Finley_Elements"));
509 m_functionSpaceTypeNames.insert
510 (FunctionSpaceNamesMapType::value_type(ReducedElements,"Finley_Reduced_Elements"));
511 m_functionSpaceTypeNames.insert
512 (FunctionSpaceNamesMapType::value_type(FaceElements,"Finley_Face_Elements"));
513 m_functionSpaceTypeNames.insert
514 (FunctionSpaceNamesMapType::value_type(ReducedFaceElements,"Finley_Reduced_Face_Elements"));
515 m_functionSpaceTypeNames.insert
516 (FunctionSpaceNamesMapType::value_type(Points,"Finley_Points"));
517 m_functionSpaceTypeNames.insert
518 (FunctionSpaceNamesMapType::value_type(ContactElementsZero,"Finley_Contact_Elements_0"));
519 m_functionSpaceTypeNames.insert
520 (FunctionSpaceNamesMapType::value_type(ReducedContactElementsZero,"Finley_Reduced_Contact_Elements_0"));
521 m_functionSpaceTypeNames.insert
522 (FunctionSpaceNamesMapType::value_type(ContactElementsOne,"Finley_Contact_Elements_1"));
523 m_functionSpaceTypeNames.insert
524 (FunctionSpaceNamesMapType::value_type(ReducedContactElementsOne,"Finley_Reduced_Contact_Elements_1"));
525 }
526
527 int MeshAdapter::getContinuousFunctionCode() const
528 {
529 return Nodes;
530 }
531 int MeshAdapter::getReducedContinuousFunctionCode() const
532 {
533 return ReducedNodes;
534 }
535
536 int MeshAdapter::getFunctionCode() const
537 {
538 return Elements;
539 }
540 int MeshAdapter::getReducedFunctionCode() const
541 {
542 return ReducedElements;
543 }
544
545 int MeshAdapter::getFunctionOnBoundaryCode() const
546 {
547 return FaceElements;
548 }
549 int MeshAdapter::getReducedFunctionOnBoundaryCode() const
550 {
551 return ReducedFaceElements;
552 }
553
554 int MeshAdapter::getFunctionOnContactZeroCode() const
555 {
556 return ContactElementsZero;
557 }
558 int MeshAdapter::getReducedFunctionOnContactZeroCode() const
559 {
560 return ReducedContactElementsZero;
561 }
562
563 int MeshAdapter::getFunctionOnContactOneCode() const
564 {
565 return ContactElementsOne;
566 }
567 int MeshAdapter::getReducedFunctionOnContactOneCode() const
568 {
569 return ReducedContactElementsOne;
570 }
571
572 int MeshAdapter::getSolutionCode() const
573 {
574 return DegreesOfFreedom;
575 }
576
577 int MeshAdapter::getReducedSolutionCode() const
578 {
579 return ReducedDegreesOfFreedom;
580 }
581
582 int MeshAdapter::getDiracDeltaFunctionCode() const
583 {
584 return Points;
585 }
586
587 //
588 // return the spatial dimension of the Mesh:
589 //
590 int MeshAdapter::getDim() const
591 {
592 int numDim=Finley_Mesh_getDim(m_finleyMesh.get());
593 checkFinleyError();
594 return numDim;
595 }
596
597 //
598 // return the number of data points per sample and the number of samples
599 // needed to represent data on a parts of the mesh.
600 //
601 pair<int,int> MeshAdapter::getDataShape(int functionSpaceCode) const
602 {
603 int numDataPointsPerSample=0;
604 int numSamples=0;
605 Finley_Mesh* mesh=m_finleyMesh.get();
606 switch (functionSpaceCode) {
607 case(Nodes):
608 numDataPointsPerSample=1;
609 numSamples=Finley_NodeFile_getNumNodes(mesh->Nodes);
610 break;
611 case(ReducedNodes):
612 numDataPointsPerSample=1;
613 numSamples=Finley_NodeFile_getNumReducedNodes(mesh->Nodes);
614 break;
615 case(Elements):
616 if (mesh->Elements!=NULL) {
617 numSamples=mesh->Elements->numElements;
618 numDataPointsPerSample=mesh->Elements->ReferenceElement->numQuadNodes;
619 }
620 break;
621 case(ReducedElements):
622 if (mesh->Elements!=NULL) {
623 numSamples=mesh->Elements->numElements;
624 numDataPointsPerSample=mesh->Elements->ReferenceElementReducedOrder->numQuadNodes;
625 }
626 break;
627 case(FaceElements):
628 if (mesh->FaceElements!=NULL) {
629 numDataPointsPerSample=mesh->FaceElements->ReferenceElement->numQuadNodes;
630 numSamples=mesh->FaceElements->numElements;
631 }
632 break;
633 case(ReducedFaceElements):
634 if (mesh->FaceElements!=NULL) {
635 numDataPointsPerSample=mesh->FaceElements->ReferenceElementReducedOrder->numQuadNodes;
636 numSamples=mesh->FaceElements->numElements;
637 }
638 break;
639 case(Points):
640 if (mesh->Points!=NULL) {
641 numDataPointsPerSample=1;
642 numSamples=mesh->Points->numElements;
643 }
644 break;
645 case(ContactElementsZero):
646 if (mesh->ContactElements!=NULL) {
647 numDataPointsPerSample=mesh->ContactElements->ReferenceElement->numQuadNodes;
648 numSamples=mesh->ContactElements->numElements;
649 }
650 break;
651 case(ReducedContactElementsZero):
652 if (mesh->ContactElements!=NULL) {
653 numDataPointsPerSample=mesh->ContactElements->ReferenceElementReducedOrder->numQuadNodes;
654 numSamples=mesh->ContactElements->numElements;
655 }
656 break;
657 case(ContactElementsOne):
658 if (mesh->ContactElements!=NULL) {
659 numDataPointsPerSample=mesh->ContactElements->ReferenceElement->numQuadNodes;
660 numSamples=mesh->ContactElements->numElements;
661 }
662 break;
663 case(ReducedContactElementsOne):
664 if (mesh->ContactElements!=NULL) {
665 numDataPointsPerSample=mesh->ContactElements->ReferenceElementReducedOrder->numQuadNodes;
666 numSamples=mesh->ContactElements->numElements;
667 }
668 break;
669 case(DegreesOfFreedom):
670 if (mesh->Nodes!=NULL) {
671 numDataPointsPerSample=1;
672 numSamples=Finley_NodeFile_getNumDegreesOfFreedom(mesh->Nodes);
673 }
674 break;
675 case(ReducedDegreesOfFreedom):
676 if (mesh->Nodes!=NULL) {
677 numDataPointsPerSample=1;
678 numSamples=Finley_NodeFile_getNumReducedDegreesOfFreedom(mesh->Nodes);
679 }
680 break;
681 default:
682 stringstream temp;
683 temp << "Error - Invalid function space type: " << functionSpaceCode << " for domain: " << getDescription();
684 throw FinleyAdapterException(temp.str());
685 break;
686 }
687 return pair<int,int>(numDataPointsPerSample,numSamples);
688 }
689
690 //
691 // adds linear PDE of second order into a given stiffness matrix and right hand side:
692 //
693 void MeshAdapter::addPDEToSystem(
694 SystemMatrixAdapter& mat, escript::Data& rhs,
695 const escript::Data& A, const escript::Data& B, const escript::Data& C,const escript::Data& D,const escript::Data& X,const escript::Data& Y,
696 const escript::Data& d, const escript::Data& y,
697 const escript::Data& d_contact,const escript::Data& y_contact) const
698 {
699 escriptDataC _rhs=rhs.getDataC();
700 escriptDataC _A =A.getDataC();
701 escriptDataC _B=B.getDataC();
702 escriptDataC _C=C.getDataC();
703 escriptDataC _D=D.getDataC();
704 escriptDataC _X=X.getDataC();
705 escriptDataC _Y=Y.getDataC();
706 escriptDataC _d=d.getDataC();
707 escriptDataC _y=y.getDataC();
708 escriptDataC _d_contact=d_contact.getDataC();
709 escriptDataC _y_contact=y_contact.getDataC();
710
711 Finley_Mesh* mesh=m_finleyMesh.get();
712
713 Finley_Assemble_PDE(mesh->Nodes,mesh->Elements,mat.getPaso_SystemMatrix(), &_rhs, &_A, &_B, &_C, &_D, &_X, &_Y );
714 checkFinleyError();
715
716 Finley_Assemble_PDE(mesh->Nodes,mesh->FaceElements, mat.getPaso_SystemMatrix(), &_rhs, 0, 0, 0, &_d, 0, &_y );
717 checkFinleyError();
718
719 Finley_Assemble_PDE(mesh->Nodes,mesh->ContactElements, mat.getPaso_SystemMatrix(), &_rhs , 0, 0, 0, &_d_contact, 0, &_y_contact );
720 checkFinleyError();
721 }
722
723 void MeshAdapter::addPDEToLumpedSystem(
724 escript::Data& mat,
725 const escript::Data& D,
726 const escript::Data& d) const
727 {
728 escriptDataC _mat=mat.getDataC();
729 escriptDataC _D=D.getDataC();
730 escriptDataC _d=d.getDataC();
731
732 Finley_Mesh* mesh=m_finleyMesh.get();
733
734 Finley_Assemble_LumpedSystem(mesh->Nodes,mesh->Elements,&_mat, &_D);
735 Finley_Assemble_LumpedSystem(mesh->Nodes,mesh->FaceElements,&_mat, &_d);
736
737 checkFinleyError();
738 }
739
740
741 //
742 // adds linear PDE of second order into the right hand side only
743 //
744 void MeshAdapter::addPDEToRHS( escript::Data& rhs, const escript::Data& X,const escript::Data& Y, const escript::Data& y, const escript::Data& y_contact) const
745 {
746 Finley_Mesh* mesh=m_finleyMesh.get();
747
748 escriptDataC _rhs=rhs.getDataC();
749 escriptDataC _X=X.getDataC();
750 escriptDataC _Y=Y.getDataC();
751 escriptDataC _y=y.getDataC();
752 escriptDataC _y_contact=y_contact.getDataC();
753
754 Finley_Assemble_PDE(mesh->Nodes,mesh->Elements, 0, &_rhs, 0, 0, 0, 0, &_X, &_Y );
755 checkFinleyError();
756
757 Finley_Assemble_PDE(mesh->Nodes,mesh->FaceElements, 0, &_rhs, 0, 0, 0, 0, 0, &_y );
758 checkFinleyError();
759
760 Finley_Assemble_PDE(mesh->Nodes,mesh->ContactElements, 0, &_rhs , 0, 0, 0, 0, 0, &_y_contact );
761 checkFinleyError();
762 }
763
764 //
765 // interpolates data between different function spaces:
766 //
767 void MeshAdapter::interpolateOnDomain(escript::Data& target,const escript::Data& in) const
768 {
769 const MeshAdapter& inDomain=dynamic_cast<const MeshAdapter&>(in.getFunctionSpace().getDomain());
770 const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());
771 if (inDomain!=*this)
772 throw FinleyAdapterException("Error - Illegal domain of interpolant.");
773 if (targetDomain!=*this)
774 throw FinleyAdapterException("Error - Illegal domain of interpolation target.");
775
776 Finley_Mesh* mesh=m_finleyMesh.get();
777 escriptDataC _target=target.getDataC();
778 escriptDataC _in=in.getDataC();
779 switch(in.getFunctionSpace().getTypeCode()) {
780 case(Nodes):
781 switch(target.getFunctionSpace().getTypeCode()) {
782 case(Nodes):
783 case(ReducedNodes):
784 case(DegreesOfFreedom):
785 case(ReducedDegreesOfFreedom):
786 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
787 break;
788 case(Elements):
789 case(ReducedElements):
790 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
791 break;
792 case(FaceElements):
793 case(ReducedFaceElements):
794 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
795 break;
796 case(Points):
797 Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
798 break;
799 case(ContactElementsZero):
800 case(ReducedContactElementsZero):
801 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
802 break;
803 case(ContactElementsOne):
804 case(ReducedContactElementsOne):
805 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
806 break;
807 default:
808 stringstream temp;
809 temp << "Error - Interpolation on Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();
810 throw FinleyAdapterException(temp.str());
811 break;
812 }
813 break;
814 case(ReducedNodes):
815 switch(target.getFunctionSpace().getTypeCode()) {
816 case(Nodes):
817 case(ReducedNodes):
818 case(DegreesOfFreedom):
819 case(ReducedDegreesOfFreedom):
820 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
821 break;
822 case(Elements):
823 case(ReducedElements):
824 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
825 break;
826 case(FaceElements):
827 case(ReducedFaceElements):
828 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
829 break;
830 case(Points):
831 Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
832 break;
833 case(ContactElementsZero):
834 case(ReducedContactElementsZero):
835 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
836 break;
837 case(ContactElementsOne):
838 case(ReducedContactElementsOne):
839 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
840 break;
841 default:
842 stringstream temp;
843 temp << "Error - Interpolation on Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();
844 throw FinleyAdapterException(temp.str());
845 break;
846 }
847 break;
848 case(Elements):
849 if (target.getFunctionSpace().getTypeCode()==Elements) {
850 Finley_Assemble_CopyElementData(mesh->Elements,&_target,&_in);
851 } else if (target.getFunctionSpace().getTypeCode()==ReducedElements) {
852 Finley_Assemble_AverageElementData(mesh->Elements,&_target,&_in);
853 } else {
854 throw FinleyAdapterException("Error - No interpolation with data on elements possible.");
855 }
856 break;
857 case(ReducedElements):
858 if (target.getFunctionSpace().getTypeCode()==ReducedElements) {
859 Finley_Assemble_CopyElementData(mesh->Elements,&_target,&_in);
860 } else {
861 throw FinleyAdapterException("Error - No interpolation with data on elements with reduced integration order possible.");
862 }
863 break;
864 case(FaceElements):
865 if (target.getFunctionSpace().getTypeCode()==FaceElements) {
866 Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);
867 } else if (target.getFunctionSpace().getTypeCode()==ReducedFaceElements) {
868 Finley_Assemble_AverageElementData(mesh->FaceElements,&_target,&_in);
869 } else {
870 throw FinleyAdapterException("Error - No interpolation with data on face elements possible.");
871 }
872 break;
873 case(ReducedFaceElements):
874 if (target.getFunctionSpace().getTypeCode()==FaceElements) {
875 Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);
876 } else {
877 throw FinleyAdapterException("Error - No interpolation with data on face elements with reduced integration order possible.");
878 }
879 break;
880 case(Points):
881 if (target.getFunctionSpace().getTypeCode()==Points) {
882 Finley_Assemble_CopyElementData(mesh->Points,&_target,&_in);
883 } else {
884 throw FinleyAdapterException("Error - No interpolation with data on points possible.");
885 }
886 break;
887 case(ContactElementsZero):
888 case(ContactElementsOne):
889 if (target.getFunctionSpace().getTypeCode()==ContactElementsZero || target.getFunctionSpace().getTypeCode()==ContactElementsOne) {
890 Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);
891 } else if (target.getFunctionSpace().getTypeCode()==ReducedContactElementsZero || target.getFunctionSpace().getTypeCode()==ReducedContactElementsOne) {
892 Finley_Assemble_AverageElementData(mesh->ContactElements,&_target,&_in);
893 } else {
894 throw FinleyAdapterException("Error - No interpolation with data on contact elements possible.");
895 break;
896 }
897 break;
898 case(ReducedContactElementsZero):
899 case(ReducedContactElementsOne):
900 if (target.getFunctionSpace().getTypeCode()==ReducedContactElementsZero || target.getFunctionSpace().getTypeCode()==ReducedContactElementsOne) {
901 Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);
902 } else {
903 throw FinleyAdapterException("Error - No interpolation with data on contact elements with reduced integration order possible.");
904 break;
905 }
906 break;
907 case(DegreesOfFreedom):
908 switch(target.getFunctionSpace().getTypeCode()) {
909 case(ReducedDegreesOfFreedom):
910 case(DegreesOfFreedom):
911 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
912 break;
913
914 case(Nodes):
915 case(ReducedNodes):
916 if (getMPISize()>1) {
917 escript::Data temp=escript::Data(in);
918 temp.expand();
919 escriptDataC _in2 = temp.getDataC();
920 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in2);
921 } else {
922 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
923 }
924 break;
925 case(Elements):
926 case(ReducedElements):
927 if (getMPISize()>1) {
928 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
929 escriptDataC _in2 = temp.getDataC();
930 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in2,&_target);
931 } else {
932 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
933 }
934 break;
935 case(FaceElements):
936 case(ReducedFaceElements):
937 if (getMPISize()>1) {
938 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
939 escriptDataC _in2 = temp.getDataC();
940 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in2,&_target);
941
942 } else {
943 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
944 }
945 break;
946 case(Points):
947 if (getMPISize()>1) {
948 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
949 escriptDataC _in2 = temp.getDataC();
950 } else {
951 Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
952 }
953 break;
954 case(ContactElementsZero):
955 case(ContactElementsOne):
956 case(ReducedContactElementsZero):
957 case(ReducedContactElementsOne):
958 if (getMPISize()>1) {
959 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
960 escriptDataC _in2 = temp.getDataC();
961 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in2,&_target);
962 } else {
963 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
964 }
965 break;
966 default:
967 stringstream temp;
968 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();
969 throw FinleyAdapterException(temp.str());
970 break;
971 }
972 break;
973 case(ReducedDegreesOfFreedom):
974 switch(target.getFunctionSpace().getTypeCode()) {
975 case(Nodes):
976 throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to mesh nodes.");
977 break;
978 case(ReducedNodes):
979 if (getMPISize()>1) {
980 escript::Data temp=escript::Data(in);
981 temp.expand();
982 escriptDataC _in2 = temp.getDataC();
983 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in2);
984 } else {
985 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
986 }
987 break;
988 case(DegreesOfFreedom):
989 throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to degrees of freedom");
990 break;
991 case(ReducedDegreesOfFreedom):
992 Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
993 break;
994 case(Elements):
995 case(ReducedElements):
996 if (getMPISize()>1) {
997 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
998 escriptDataC _in2 = temp.getDataC();
999 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in2,&_target);
1000 } else {
1001 Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
1002 }
1003 break;
1004 case(FaceElements):
1005 case(ReducedFaceElements):
1006 if (getMPISize()>1) {
1007 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
1008 escriptDataC _in2 = temp.getDataC();
1009 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in2,&_target);
1010 } else {
1011 Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
1012 }
1013 break;
1014 case(Points):
1015 if (getMPISize()>1) {
1016 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
1017 escriptDataC _in2 = temp.getDataC();
1018 Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in2,&_target);
1019 } else {
1020 Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
1021 }
1022 break;
1023 case(ContactElementsZero):
1024 case(ContactElementsOne):
1025 case(ReducedContactElementsZero):
1026 case(ReducedContactElementsOne):
1027 if (getMPISize()>1) {
1028 escript::Data temp=escript::Data( in, continuousFunction(asAbstractContinuousDomain()) );
1029 escriptDataC _in2 = temp.getDataC();
1030 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in2,&_target);
1031 } else {
1032 Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
1033 }
1034 break;
1035 default:
1036 stringstream temp;
1037 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();
1038 throw FinleyAdapterException(temp.str());
1039 break;
1040 }
1041 break;
1042 default:
1043 stringstream temp;
1044 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type %d" << in.getFunctionSpace().getTypeCode();
1045 throw FinleyAdapterException(temp.str());
1046 break;
1047 }
1048 checkFinleyError();
1049 }
1050
1051 //
1052 // copies the locations of sample points into x:
1053 //
1054 void MeshAdapter::setToX(escript::Data& arg) const
1055 {
1056 const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());
1057 if (argDomain!=*this)
1058 throw FinleyAdapterException("Error - Illegal domain of data point locations");
1059 Finley_Mesh* mesh=m_finleyMesh.get();
1060 // in case of values node coordinates we can do the job directly:
1061 if (arg.getFunctionSpace().getTypeCode()==Nodes) {
1062 escriptDataC _arg=arg.getDataC();
1063 Finley_Assemble_NodeCoordinates(mesh->Nodes,&_arg);
1064 } else {
1065 escript::Data tmp_data=Vector(0.0,continuousFunction(asAbstractContinuousDomain()),true);
1066 escriptDataC _tmp_data=tmp_data.getDataC();
1067 Finley_Assemble_NodeCoordinates(mesh->Nodes,&_tmp_data);
1068 // this is then interpolated onto arg:
1069 interpolateOnDomain(arg,tmp_data);
1070 }
1071 checkFinleyError();
1072 }
1073
1074 //
1075 // return the normal vectors at the location of data points as a Data object:
1076 //
1077 void MeshAdapter::setToNormal(escript::Data& normal) const
1078 {
1079 const MeshAdapter& normalDomain=dynamic_cast<const MeshAdapter&>(normal.getFunctionSpace().getDomain());
1080 if (normalDomain!=*this)
1081 throw FinleyAdapterException("Error - Illegal domain of normal locations");
1082 Finley_Mesh* mesh=m_finleyMesh.get();
1083 escriptDataC _normal=normal.getDataC();
1084 switch(normal.getFunctionSpace().getTypeCode()) {
1085 case(Nodes):
1086 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for nodes");
1087 break;
1088 case(ReducedNodes):
1089 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for reduced nodes");
1090 break;
1091 case(Elements):
1092 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for elements");
1093 break;
1094 case(ReducedElements):
1095 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for elements with reduced integration order");
1096 break;
1097 case (FaceElements):
1098 Finley_Assemble_setNormal(mesh->Nodes,mesh->FaceElements,&_normal);
1099 break;
1100 case (ReducedFaceElements):
1101 Finley_Assemble_setNormal(mesh->Nodes,mesh->FaceElements,&_normal);
1102 break;
1103 case(Points):
1104 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for point elements");
1105 break;
1106 case (ContactElementsOne):
1107 case (ContactElementsZero):
1108 Finley_Assemble_setNormal(mesh->Nodes,mesh->ContactElements,&_normal);
1109 break;
1110 case (ReducedContactElementsOne):
1111 case (ReducedContactElementsZero):
1112 Finley_Assemble_setNormal(mesh->Nodes,mesh->ContactElements,&_normal);
1113 break;
1114 case(DegreesOfFreedom):
1115 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for degrees of freedom.");
1116 break;
1117 case(ReducedDegreesOfFreedom):
1118 throw FinleyAdapterException("Error - Finley does not support surface normal vectors for reduced degrees of freedom.");
1119 break;
1120 default:
1121 stringstream temp;
1122 temp << "Error - Normal Vectors: Finley does not know anything about function space type " << normal.getFunctionSpace().getTypeCode();
1123 throw FinleyAdapterException(temp.str());
1124 break;
1125 }
1126 checkFinleyError();
1127 }
1128
1129 //
1130 // interpolates data to other domain:
1131 //
1132 void MeshAdapter::interpolateACross(escript::Data& target,const escript::Data& source) const
1133 {
1134 const MeshAdapter& targetDomain=dynamic_cast<const MeshAdapter&>(target.getFunctionSpace().getDomain());
1135 if (targetDomain!=*this)
1136 throw FinleyAdapterException("Error - Illegal domain of interpolation target");
1137
1138 throw FinleyAdapterException("Error - Finley does not allow interpolation across domains yet.");
1139 }
1140
1141 //
1142 // calculates the integral of a function defined of arg:
1143 //
1144 void MeshAdapter::setToIntegrals(std::vector<double>& integrals,const escript::Data& arg) const
1145 {
1146 const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());
1147 if (argDomain!=*this)
1148 throw FinleyAdapterException("Error - Illegal domain of integration kernel");
1149
1150 double blocktimer_start = blocktimer_time();
1151 Finley_Mesh* mesh=m_finleyMesh.get();
1152 escriptDataC _temp;
1153 escript::Data temp;
1154 escriptDataC _arg=arg.getDataC();
1155 switch(arg.getFunctionSpace().getTypeCode()) {
1156 case(Nodes):
1157 temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1158 _temp=temp.getDataC();
1159 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1160 break;
1161 case(ReducedNodes):
1162 temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1163 _temp=temp.getDataC();
1164 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1165 break;
1166 case(Elements):
1167 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);
1168 break;
1169 case(ReducedElements):
1170 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);
1171 break;
1172 case(FaceElements):
1173 Finley_Assemble_integrate(mesh->Nodes,mesh->FaceElements,&_arg,&integrals[0]);
1174 break;
1175 case(ReducedFaceElements):
1176 Finley_Assemble_integrate(mesh->Nodes,mesh->FaceElements,&_arg,&integrals[0]);
1177 break;
1178 case(Points):
1179 throw FinleyAdapterException("Error - Integral of data on points is not supported.");
1180 break;
1181 case(ContactElementsZero):
1182 Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1183 break;
1184 case(ReducedContactElementsZero):
1185 Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1186 break;
1187 case(ContactElementsOne):
1188 Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1189 break;
1190 case(ReducedContactElementsOne):
1191 Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1192 break;
1193 case(DegreesOfFreedom):
1194 temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1195 _temp=temp.getDataC();
1196 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1197 break;
1198 case(ReducedDegreesOfFreedom):
1199 temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1200 _temp=temp.getDataC();
1201 Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1202 break;
1203 default:
1204 stringstream temp;
1205 temp << "Error - Integrals: Finley does not know anything about function space type " << arg.getFunctionSpace().getTypeCode();
1206 throw FinleyAdapterException(temp.str());
1207 break;
1208 }
1209 checkFinleyError();
1210 blocktimer_increment("integrate()", blocktimer_start);
1211 }
1212
1213 //
1214 // calculates the gradient of arg:
1215 //
1216 void MeshAdapter::setToGradient(escript::Data& grad,const escript::Data& arg) const
1217 {
1218 const MeshAdapter& argDomain=dynamic_cast<const MeshAdapter&>(arg.getFunctionSpace().getDomain());
1219 if (argDomain!=*this)
1220 throw FinleyAdapterException("Error - Illegal domain of gradient argument");
1221 const MeshAdapter& gradDomain=dynamic_cast<const MeshAdapter&>(grad.getFunctionSpace().getDomain());
1222 if (gradDomain!=*this)
1223 throw FinleyAdapterException("Error - Illegal domain of gradient");
1224
1225 Finley_Mesh* mesh=m_finleyMesh.get();
1226 escriptDataC _grad=grad.getDataC();
1227 escriptDataC nodeDataC;
1228 escript::Data temp;
1229 if (getMPISize()>1) {
1230 if( arg.getFunctionSpace().getTypeCode() == DegreesOfFreedom ) {
1231 temp=escript::Data( arg, continuousFunction(asAbstractContinuousDomain()) );
1232 nodeDataC = temp.getDataC();
1233 } else if( arg.getFunctionSpace().getTypeCode() == ReducedDegreesOfFreedom ) {
1234 temp=escript::Data( arg, reducedContinuousFunction(asAbstractContinuousDomain()) );
1235 nodeDataC = temp.getDataC();
1236 } else {
1237 nodeDataC = arg.getDataC();
1238 }
1239 } else {
1240 nodeDataC = arg.getDataC();
1241 }
1242 switch(grad.getFunctionSpace().getTypeCode()) {
1243 case(Nodes):
1244 throw FinleyAdapterException("Error - Gradient at nodes is not supported.");
1245 break;
1246 case(ReducedNodes):
1247 throw FinleyAdapterException("Error - Gradient at reduced nodes is not supported.");
1248 break;
1249 case(Elements):
1250 Finley_Assemble_gradient(mesh->Nodes,mesh->Elements,&_grad,&nodeDataC);
1251 break;
1252 case(ReducedElements):
1253 Finley_Assemble_gradient(mesh->Nodes,mesh->Elements,&_grad,&nodeDataC);
1254 break;
1255 case(FaceElements):
1256 Finley_Assemble_gradient(mesh->Nodes,mesh->FaceElements,&_grad,&nodeDataC);
1257 break;
1258 case(ReducedFaceElements):
1259 Finley_Assemble_gradient(mesh->Nodes,mesh->FaceElements,&_grad,&nodeDataC);
1260 break;
1261 case(Points):
1262 throw FinleyAdapterException("Error - Gradient at points is not supported.");
1263 break;
1264 case(ContactElementsZero):
1265 Finley_Assemble_gradient(mesh->Nodes,mesh->ContactElements,&_grad,&nodeDataC);
1266 break;
1267 case(ReducedContactElementsZero):
1268 Finley_Assemble_gradient(mesh->Nodes,mesh->ContactElements,&_grad,&nodeDataC);
1269 break;
1270 case(ContactElementsOne):
1271 Finley_Assemble_gradient(mesh->Nodes,mesh->ContactElements,&_grad,&nodeDataC);
1272 break;
1273 case(ReducedContactElementsOne):
1274 Finley_Assemble_gradient(mesh->Nodes,mesh->ContactElements,&_grad,&nodeDataC);
1275 break;
1276 case(DegreesOfFreedom):
1277 throw FinleyAdapterException("Error - Gradient at degrees of freedom is not supported.");
1278 break;
1279 case(ReducedDegreesOfFreedom):
1280 throw FinleyAdapterException("Error - Gradient at reduced degrees of freedom is not supported.");
1281 break;
1282 default:
1283 stringstream temp;
1284 temp << "Error - Gradient: Finley does not know anything about function space type " << arg.getFunctionSpace().getTypeCode();
1285 throw FinleyAdapterException(temp.str());
1286 break;
1287 }
1288 checkFinleyError();
1289 }
1290
1291 //
1292 // returns the size of elements:
1293 //
1294 void MeshAdapter::setToSize(escript::Data& size) const
1295 {
1296 Finley_Mesh* mesh=m_finleyMesh.get();
1297 escriptDataC tmp=size.getDataC();
1298 switch(size.getFunctionSpace().getTypeCode()) {
1299 case(Nodes):
1300 throw FinleyAdapterException("Error - Size of nodes is not supported.");
1301 break;
1302 case(ReducedNodes):
1303 throw FinleyAdapterException("Error - Size of reduced nodes is not supported.");
1304 break;
1305 case(Elements):
1306 Finley_Assemble_getSize(mesh->Nodes,mesh->Elements,&tmp);
1307 break;
1308 case(ReducedElements):
1309 Finley_Assemble_getSize(mesh->Nodes,mesh->Elements,&tmp);
1310 break;
1311 case(FaceElements):
1312 Finley_Assemble_getSize(mesh->Nodes,mesh->FaceElements,&tmp);
1313 break;
1314 case(ReducedFaceElements):
1315 Finley_Assemble_getSize(mesh->Nodes,mesh->FaceElements,&tmp);
1316 break;
1317 case(Points):
1318 throw FinleyAdapterException("Error - Size of point elements is not supported.");
1319 break;
1320 case(ContactElementsZero):
1321 case(ContactElementsOne):
1322 Finley_Assemble_getSize(mesh->Nodes,mesh->ContactElements,&tmp);
1323 break;
1324 case(ReducedContactElementsZero):
1325 case(ReducedContactElementsOne):
1326 Finley_Assemble_getSize(mesh->Nodes,mesh->ContactElements,&tmp);
1327 break;
1328 case(DegreesOfFreedom):
1329 throw FinleyAdapterException("Error - Size of degrees of freedom is not supported.");
1330 break;
1331 case(ReducedDegreesOfFreedom):
1332 throw FinleyAdapterException("Error - Size of reduced degrees of freedom is not supported.");
1333 break;
1334 default:
1335 stringstream temp;
1336 temp << "Error - Element size: Finley does not know anything about function space type " << size.getFunctionSpace().getTypeCode();
1337 throw FinleyAdapterException(temp.str());
1338 break;
1339 }
1340 checkFinleyError();
1341 }
1342
1343 // sets the location of nodes:
1344 void MeshAdapter::setNewX(const escript::Data& new_x)
1345 {
1346 Finley_Mesh* mesh=m_finleyMesh.get();
1347 escriptDataC tmp;
1348 const MeshAdapter& newDomain=dynamic_cast<const MeshAdapter&>(new_x.getFunctionSpace().getDomain());
1349 if (newDomain!=*this)
1350 throw FinleyAdapterException("Error - Illegal domain of new point locations");
1351 tmp = new_x.getDataC();
1352 Finley_Mesh_setCoordinates(mesh,&tmp);
1353 checkFinleyError();
1354 }
1355
1356 // saves a data array in openDX format:
1357 void MeshAdapter::saveDX(const std::string& filename,const boost::python::dict& arg) const
1358 {
1359 int MAX_namelength=256;
1360 const int num_data=boost::python::extract<int>(arg.attr("__len__")());
1361 /* win32 refactor */
1362 char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
1363 for(int i=0;i<num_data;i++)
1364 {
1365 names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;
1366 }
1367
1368 char* *c_names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
1369 escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1370 escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
1371
1372 boost::python::list keys=arg.keys();
1373 for (int i=0;i<num_data;++i) {
1374 std::string n=boost::python::extract<std::string>(keys[i]);
1375 escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1376 if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)
1377 throw FinleyAdapterException("Error in saveVTK: Data must be defined on same Domain");
1378 data[i]=d.getDataC();
1379 ptr_data[i]=&(data[i]);
1380 c_names[i]=&(names[i][0]);
1381 if (n.length()>MAX_namelength-1) {
1382 strncpy(c_names[i],n.c_str(),MAX_namelength-1);
1383 c_names[i][MAX_namelength-1]='\0';
1384 } else {
1385 strcpy(c_names[i],n.c_str());
1386 }
1387 }
1388 Finley_Mesh_saveDX(filename.c_str(),m_finleyMesh.get(),num_data,c_names,ptr_data);
1389 checkFinleyError();
1390
1391 /* win32 refactor */
1392 TMPMEMFREE(c_names);
1393 TMPMEMFREE(data);
1394 TMPMEMFREE(ptr_data);
1395 for(int i=0;i<num_data;i++)
1396 {
1397 TMPMEMFREE(names[i]);
1398 }
1399 TMPMEMFREE(names);
1400
1401 return;
1402 }
1403
1404 // saves a data array in openVTK format:
1405 void MeshAdapter::saveVTK(const std::string& filename,const boost::python::dict& arg) const
1406 {
1407 int MAX_namelength=256;
1408 const int num_data=boost::python::extract<int>(arg.attr("__len__")());
1409 /* win32 refactor */
1410 char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
1411 for(int i=0;i<num_data;i++)
1412 {
1413 names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;
1414 }
1415
1416 char* *c_names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
1417 escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1418 escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
1419
1420 boost::python::list keys=arg.keys();
1421 for (int i=0;i<num_data;++i) {
1422 std::string n=boost::python::extract<std::string>(keys[i]);
1423 escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1424 if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)
1425 throw FinleyAdapterException("Error in saveVTK: Data must be defined on same Domain");
1426 data[i]=d.getDataC();
1427 ptr_data[i]=&(data[i]);
1428 c_names[i]=&(names[i][0]);
1429 if (n.length()>MAX_namelength-1) {
1430 strncpy(c_names[i],n.c_str(),MAX_namelength-1);
1431 c_names[i][MAX_namelength-1]='\0';
1432 } else {
1433 strcpy(c_names[i],n.c_str());
1434 }
1435 }
1436 Finley_Mesh_saveVTK(filename.c_str(),m_finleyMesh.get(),num_data,c_names,ptr_data);
1437
1438 checkFinleyError();
1439 /* win32 refactor */
1440 TMPMEMFREE(c_names);
1441 TMPMEMFREE(data);
1442 TMPMEMFREE(ptr_data);
1443 for(int i=0;i<num_data;i++)
1444 {
1445 TMPMEMFREE(names[i]);
1446 }
1447 TMPMEMFREE(names);
1448
1449 return;
1450 }
1451
1452
1453 // creates a SystemMatrixAdapter stiffness matrix an initializes it with zeros:
1454 SystemMatrixAdapter MeshAdapter::newSystemMatrix(
1455 const int row_blocksize,
1456 const escript::FunctionSpace& row_functionspace,
1457 const int column_blocksize,
1458 const escript::FunctionSpace& column_functionspace,
1459 const int type) const
1460 {
1461 int reduceRowOrder=0;
1462 int reduceColOrder=0;
1463 // is the domain right?
1464 const MeshAdapter& row_domain=dynamic_cast<const MeshAdapter&>(row_functionspace.getDomain());
1465 if (row_domain!=*this)
1466 throw FinleyAdapterException("Error - domain of row function space does not match the domain of matrix generator.");
1467 const MeshAdapter& col_domain=dynamic_cast<const MeshAdapter&>(column_functionspace.getDomain());
1468 if (col_domain!=*this)
1469 throw FinleyAdapterException("Error - domain of columnn function space does not match the domain of matrix generator.");
1470 // is the function space type right
1471 if (row_functionspace.getTypeCode()==DegreesOfFreedom) {
1472 reduceRowOrder=0;
1473 } else if (row_functionspace.getTypeCode()==ReducedDegreesOfFreedom) {
1474 reduceRowOrder=1;
1475 } else {
1476 throw FinleyAdapterException("Error - illegal function space type for system matrix rows.");
1477 }
1478 if (column_functionspace.getTypeCode()==DegreesOfFreedom) {
1479 reduceColOrder=0;
1480 } else if (column_functionspace.getTypeCode()==ReducedDegreesOfFreedom) {
1481 reduceColOrder=1;
1482 } else {
1483 throw FinleyAdapterException("Error - illegal function space type for system matrix columns.");
1484 }
1485 // generate matrix:
1486
1487 Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceRowOrder,reduceColOrder);
1488 checkFinleyError();
1489 Paso_SystemMatrix* fsystemMatrix;
1490 int trilinos = 0;
1491 if (trilinos) {
1492 #ifdef TRILINOS
1493 /* Allocation Epetra_VrbMatrix here */
1494 #endif
1495 }
1496 else {
1497 fsystemMatrix=Paso_SystemMatrix_alloc(type,fsystemMatrixPattern,row_blocksize,column_blocksize);
1498 }
1499 checkPasoError();
1500 Paso_SystemMatrixPattern_free(fsystemMatrixPattern);
1501 return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);
1502 }
1503
1504 //
1505 // vtkObject MeshAdapter::createVtkObject() const
1506 // TODO:
1507 //
1508
1509 //
1510 // returns true if data at the atom_type is considered as being cell centered:
1511 bool MeshAdapter::isCellOriented(int functionSpaceCode) const
1512 {
1513 switch(functionSpaceCode) {
1514 case(Nodes):
1515 case(DegreesOfFreedom):
1516 case(ReducedDegreesOfFreedom):
1517 return false;
1518 break;
1519 case(Elements):
1520 case(FaceElements):
1521 case(Points):
1522 case(ContactElementsZero):
1523 case(ContactElementsOne):
1524 case(ReducedElements):
1525 case(ReducedFaceElements):
1526 case(ReducedContactElementsZero):
1527 case(ReducedContactElementsOne):
1528 return true;
1529 break;
1530 default:
1531 stringstream temp;
1532 temp << "Error - Cell: Finley does not know anything about function space type " << functionSpaceCode;
1533 throw FinleyAdapterException(temp.str());
1534 break;
1535 }
1536 checkFinleyError();
1537 return false;
1538 }
1539
1540 bool MeshAdapter::probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const
1541 {
1542 switch(functionSpaceType_source) {
1543 case(Nodes):
1544 switch(functionSpaceType_target) {
1545 case(Nodes):
1546 case(ReducedNodes):
1547 case(ReducedDegreesOfFreedom):
1548 case(DegreesOfFreedom):
1549 case(Elements):
1550 case(ReducedElements):
1551 case(FaceElements):
1552 case(ReducedFaceElements):
1553 case(Points):
1554 case(ContactElementsZero):
1555 case(ReducedContactElementsZero):
1556 case(ContactElementsOne):
1557 case(ReducedContactElementsOne):
1558 return true;
1559 default:
1560 stringstream temp;
1561 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << functionSpaceType_target;
1562 throw FinleyAdapterException(temp.str());
1563 }
1564 break;
1565 case(ReducedNodes):
1566 switch(functionSpaceType_target) {
1567 case(ReducedNodes):
1568 case(ReducedDegreesOfFreedom):
1569 case(Elements):
1570 case(ReducedElements):
1571 case(FaceElements):
1572 case(ReducedFaceElements):
1573 case(Points):
1574 case(ContactElementsZero):
1575 case(ReducedContactElementsZero):
1576 case(ContactElementsOne):
1577 case(ReducedContactElementsOne):
1578 return true;
1579 case(Nodes):
1580 case(DegreesOfFreedom):
1581 return false;
1582 default:
1583 stringstream temp;
1584 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << functionSpaceType_target;
1585 throw FinleyAdapterException(temp.str());
1586 }
1587 break;
1588 case(Elements):
1589 if (functionSpaceType_target==Elements) {
1590 return true;
1591 } else if (functionSpaceType_target==ReducedElements) {
1592 return true;
1593 } else {
1594 return false;
1595 }
1596 case(ReducedElements):
1597 if (functionSpaceType_target==ReducedElements) {
1598 return true;
1599 } else {
1600 return false;
1601 }
1602 case(FaceElements):
1603 if (functionSpaceType_target==FaceElements) {
1604 return true;
1605 } else if (functionSpaceType_target==ReducedFaceElements) {
1606 return true;
1607 } else {
1608 return false;
1609 }
1610 case(ReducedFaceElements):
1611 if (functionSpaceType_target==ReducedFaceElements) {
1612 return true;
1613 } else {
1614 return false;
1615 }
1616 case(Points):
1617 if (functionSpaceType_target==Points) {
1618 return true;
1619 } else {
1620 return false;
1621 }
1622 case(ContactElementsZero):
1623 case(ContactElementsOne):
1624 if (functionSpaceType_target==ContactElementsZero || functionSpaceType_target==ContactElementsOne) {
1625 return true;
1626 } else if (functionSpaceType_target==ReducedContactElementsZero || functionSpaceType_target==ReducedContactElementsOne) {
1627 return true;
1628 } else {
1629 return false;
1630 }
1631 case(ReducedContactElementsZero):
1632 case(ReducedContactElementsOne):
1633 if (functionSpaceType_target==ReducedContactElementsZero || functionSpaceType_target==ReducedContactElementsOne) {
1634 return true;
1635 } else {
1636 return false;
1637 }
1638 case(DegreesOfFreedom):
1639 switch(functionSpaceType_target) {
1640 case(ReducedDegreesOfFreedom):
1641 case(DegreesOfFreedom):
1642 case(Nodes):
1643 case(ReducedNodes):
1644 case(Elements):
1645 case(ReducedElements):
1646 case(Points):
1647 case(FaceElements):
1648 case(ReducedFaceElements):
1649 case(ContactElementsZero):
1650 case(ReducedContactElementsZero):
1651 case(ContactElementsOne):
1652 case(ReducedContactElementsOne):
1653 return true;
1654 default:
1655 stringstream temp;
1656 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << functionSpaceType_target;
1657 throw FinleyAdapterException(temp.str());
1658 }
1659 break;
1660 case(ReducedDegreesOfFreedom):
1661 switch(functionSpaceType_target) {
1662 case(ReducedDegreesOfFreedom):
1663 case(ReducedNodes):
1664 case(Elements):
1665 case(ReducedElements):
1666 case(FaceElements):
1667 case(ReducedFaceElements):
1668 case(Points):
1669 case(ContactElementsZero):
1670 case(ReducedContactElementsZero):
1671 case(ContactElementsOne):
1672 case(ReducedContactElementsOne):
1673 return true;
1674 case(Nodes):
1675 case(DegreesOfFreedom):
1676 return false;
1677 default:
1678 stringstream temp;
1679 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << functionSpaceType_target;
1680 throw FinleyAdapterException(temp.str());
1681 }
1682 break;
1683 default:
1684 stringstream temp;
1685 temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << functionSpaceType_source;
1686 throw FinleyAdapterException(temp.str());
1687 break;
1688 }
1689 checkFinleyError();
1690 return false;
1691 }
1692
1693 bool MeshAdapter::probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const
1694 {
1695 return false;
1696 }
1697
1698 bool MeshAdapter::operator==(const AbstractDomain& other) const
1699 {
1700 const MeshAdapter* temp=dynamic_cast<const MeshAdapter*>(&other);
1701 if (temp!=0) {
1702 return (m_finleyMesh==temp->m_finleyMesh);
1703 } else {
1704 return false;
1705 }
1706 }
1707
1708 bool MeshAdapter::operator!=(const AbstractDomain& other) const
1709 {
1710 return !(operator==(other));
1711 }
1712
1713 int MeshAdapter::getSystemMatrixTypeId(const int solver, const int package, const bool symmetry) const
1714 {
1715 int out=Paso_SystemMatrix_getSystemMatrixTypeId(SystemMatrixAdapter::mapOptionToPaso(solver),SystemMatrixAdapter::mapOptionToPaso(package),symmetry?1:0);
1716 checkPasoError();
1717 return out;
1718 }
1719
1720 escript::Data MeshAdapter::getX() const
1721 {
1722 return continuousFunction(asAbstractContinuousDomain()).getX();
1723 }
1724
1725 escript::Data MeshAdapter::getNormal() const
1726 {
1727 return functionOnBoundary(asAbstractContinuousDomain()).getNormal();
1728 }
1729
1730 escript::Data MeshAdapter::getSize() const
1731 {
1732 return function(asAbstractContinuousDomain()).getSize();
1733 }
1734
1735 int* MeshAdapter::borrowSampleReferenceIDs(int functionSpaceType) const
1736 {
1737 int *out=0,i;
1738 Finley_Mesh* mesh=m_finleyMesh.get();
1739 switch (functionSpaceType) {
1740 case(Nodes):
1741 out=mesh->Nodes->Id;
1742 break;
1743 case(ReducedNodes):
1744 out=mesh->Nodes->reducedNodesId;
1745 break;
1746 case(Elements):
1747 out=mesh->Elements->Id;
1748 break;
1749 case(ReducedElements):
1750 out=mesh->Elements->Id;
1751 break;
1752 case(FaceElements):
1753 out=mesh->FaceElements->Id;
1754 break;
1755 case(ReducedFaceElements):
1756 out=mesh->FaceElements->Id;
1757 break;
1758 case(Points):
1759 out=mesh->Points->Id;
1760 break;
1761 case(ContactElementsZero):
1762 out=mesh->ContactElements->Id;
1763 break;
1764 case(ReducedContactElementsZero):
1765 out=mesh->ContactElements->Id;
1766 break;
1767 case(ContactElementsOne):
1768 out=mesh->ContactElements->Id;
1769 break;
1770 case(ReducedContactElementsOne):
1771 out=mesh->ContactElements->Id;
1772 break;
1773 case(DegreesOfFreedom):
1774 out=mesh->Nodes->degreesOfFreedomId;
1775 break;
1776 case(ReducedDegreesOfFreedom):
1777 out=mesh->Nodes->reducedDegreesOfFreedomId;
1778 break;
1779 default:
1780 stringstream temp;
1781 temp << "Error - Invalid function space type: " << functionSpaceType << " for domain: " << getDescription();
1782 throw FinleyAdapterException(temp.str());
1783 break;
1784 }
1785 return out;
1786 }
1787 int MeshAdapter::getTagFromSampleNo(int functionSpaceType, int sampleNo) const
1788 {
1789 int out=0;
1790 Finley_Mesh* mesh=m_finleyMesh.get();
1791 switch (functionSpaceType) {
1792 case(Nodes):
1793 out=mesh->Nodes->Tag[sampleNo];
1794 break;
1795 case(ReducedNodes):
1796 throw FinleyAdapterException(" Error - ReducedNodes does not support tags.");
1797 break;
1798 case(Elements):
1799 out=mesh->Elements->Tag[sampleNo];
1800 break;
1801 case(ReducedElements):
1802 out=mesh->Elements->Tag[sampleNo];
1803 break;
1804 case(FaceElements):
1805 out=mesh->FaceElements->Tag[sampleNo];
1806 break;
1807 case(ReducedFaceElements):
1808 out=mesh->FaceElements->Tag[sampleNo];
1809 break;
1810 case(Points):
1811 out=mesh->Points->Tag[sampleNo];
1812 break;
1813 case(ContactElementsZero):
1814 out=mesh->ContactElements->Tag[sampleNo];
1815 break;
1816 case(ReducedContactElementsZero):
1817 out=mesh->ContactElements->Tag[sampleNo];
1818 break;
1819 case(ContactElementsOne):
1820 out=mesh->ContactElements->Tag[sampleNo];
1821 break;
1822 case(ReducedContactElementsOne):
1823 out=mesh->ContactElements->Tag[sampleNo];
1824 break;
1825 case(DegreesOfFreedom):
1826 throw FinleyAdapterException(" Error - DegreesOfFreedom does not support tags.");
1827 break;
1828 case(ReducedDegreesOfFreedom):
1829 throw FinleyAdapterException(" Error - ReducedDegreesOfFreedom does not support tags.");
1830 break;
1831 default:
1832 stringstream temp;
1833 temp << "Error - Invalid function space type: " << functionSpaceType << " for domain: " << getDescription();
1834 throw FinleyAdapterException(temp.str());
1835 break;
1836 }
1837 return out;
1838 }
1839
1840
1841 void MeshAdapter::setTags(const int functionSpaceType, const int newTag, const escript::Data& mask) const
1842 {
1843 Finley_Mesh* mesh=m_finleyMesh.get();
1844 escriptDataC tmp=mask.getDataC();
1845 switch(functionSpaceType) {
1846 case(Nodes):
1847 Finley_NodeFile_setTags(mesh->Nodes,newTag,&tmp);
1848 break;
1849 case(ReducedNodes):
1850 throw FinleyAdapterException("Error - ReducedNodes does not support tags");
1851 break;
1852 case(DegreesOfFreedom):
1853 throw FinleyAdapterException("Error - DegreesOfFreedom does not support tags");
1854 break;
1855 case(ReducedDegreesOfFreedom):
1856 throw FinleyAdapterException("Error - ReducedDegreesOfFreedom does not support tags");
1857 break;
1858 case(Elements):
1859 Finley_ElementFile_setTags(mesh->Elements,newTag,&tmp);
1860 break;
1861 case(ReducedElements):
1862 Finley_ElementFile_setTags(mesh->Elements,newTag,&tmp);
1863 break;
1864 case(FaceElements):
1865 Finley_ElementFile_setTags(mesh->FaceElements,newTag,&tmp);
1866 break;
1867 case(ReducedFaceElements):
1868 Finley_ElementFile_setTags(mesh->FaceElements,newTag,&tmp);
1869 break;
1870 case(Points):
1871 Finley_ElementFile_setTags(mesh->Points,newTag,&tmp);
1872 break;
1873 case(ContactElementsZero):
1874 Finley_ElementFile_setTags(mesh->ContactElements,newTag,&tmp);
1875 break;
1876 case(ReducedContactElementsZero):
1877 Finley_ElementFile_setTags(mesh->ContactElements,newTag,&tmp);
1878 break;
1879 case(ContactElementsOne):
1880 Finley_ElementFile_setTags(mesh->ContactElements,newTag,&tmp);
1881 break;
1882 case(ReducedContactElementsOne):
1883 Finley_ElementFile_setTags(mesh->ContactElements,newTag,&tmp);
1884 break;
1885 default:
1886 stringstream temp;
1887 temp << "Error - Finley does not know anything about function space type " << functionSpaceType;
1888 throw FinleyAdapterException(temp.str());
1889 }
1890 checkFinleyError();
1891 return;
1892 }
1893
1894 void MeshAdapter::setTagMap(const std::string& name, int tag)
1895 {
1896 Finley_Mesh* mesh=m_finleyMesh.get();
1897 Finley_Mesh_addTagMap(mesh, name.c_str(),tag);
1898 checkPasoError();
1899 // throwStandardException("MeshAdapter::set TagMap is not implemented.");
1900 }
1901
1902 int MeshAdapter::getTag(const std::string& name) const
1903 {
1904 Finley_Mesh* mesh=m_finleyMesh.get();
1905 int tag=0;
1906 tag=Finley_Mesh_getTag(mesh, name.c_str());
1907 checkPasoError();
1908 // throwStandardException("MeshAdapter::getTag is not implemented.");
1909 return tag;
1910 }
1911
1912 bool MeshAdapter::isValidTagName(const std::string& name) const
1913 {
1914 Finley_Mesh* mesh=m_finleyMesh.get();
1915 return Finley_Mesh_isValidTagName(mesh,name.c_str());
1916 }
1917
1918 std::string MeshAdapter::showTagNames() const
1919 {
1920 stringstream temp;
1921 Finley_Mesh* mesh=m_finleyMesh.get();
1922 Finley_TagMap* tag_map=mesh->TagMap;
1923 while (tag_map) {
1924 temp << tag_map->name;
1925 tag_map=tag_map->next;
1926 if (tag_map) temp << ", ";
1927 }
1928 return temp.str();
1929 }
1930
1931 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26