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

Legend:
Removed from v.1859  
changed lines
  Added in v.5084

  ViewVC Help
Powered by ViewVC 1.1.26