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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.967  
changed lines
  Added in v.1811

  ViewVC Help
Powered by ViewVC 1.1.26