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

Diff of /branches/diaplayground/finley/src/CPPAdapter/MeshAdapter.cpp

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

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

Legend:
Removed from v.798  
changed lines
  Added in v.1755

  ViewVC Help
Powered by ViewVC 1.1.26