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

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

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

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

Legend:
Removed from v.102  
changed lines
  Added in v.1366

  ViewVC Help
Powered by ViewVC 1.1.26