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

Legend:
Removed from v.1080  
changed lines
  Added in v.2100

  ViewVC Help
Powered by ViewVC 1.1.26