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

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

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

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

Legend:
Removed from v.471  
changed lines
  Added in v.1346

  ViewVC Help
Powered by ViewVC 1.1.26