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

Legend:
Removed from v.2548  
changed lines
  Added in v.5122

  ViewVC Help
Powered by ViewVC 1.1.26