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

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

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

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

Legend:
Removed from v.757  
changed lines
  Added in v.1776

  ViewVC Help
Powered by ViewVC 1.1.26