/[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 1064 by gross, Tue Mar 27 06:21:02 2007 UTC revision 1346 by ksteube, Wed Nov 14 22:48:12 2007 UTC
# Line 1  Line 1 
 // $Id$  
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
1    
2  #ifdef PASO_MPI  /* $Id$ */
3  #include <mpi.h>  
4  #endif  /*******************************************************
5  #include "MeshAdapter.h"   *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16    #include "MeshAdapter.h"
17  #include "escript/Data.h"  #include "escript/Data.h"
18  #include "escript/DataFactory.h"  #include "escript/DataFactory.h"
19    #ifdef USE_NETCDF
20    #include <netcdfcpp.h>
21    #endif
22    extern "C" {
23    #include "escript/blocktimer.h"
24    }
25    #include <vector>
26    
27  using namespace std;  using namespace std;
28  using namespace escript;  using namespace escript;
# Line 47  MeshAdapter::MeshAdapter(Finley_Mesh* fi Line 50  MeshAdapter::MeshAdapter(Finley_Mesh* fi
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 66  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  }  }
# Line 85  void MeshAdapter::write(const std::strin Line 96  void MeshAdapter::write(const std::strin
96    TMPMEMFREE(fName);    TMPMEMFREE(fName);
97  }  }
98    
99    void MeshAdapter::Print_Mesh_Info(const bool full=false) const
100    {
101      Finley_PrintMesh_Info(m_finleyMesh.get(), full);
102    }
103    
104    void MeshAdapter::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  {  {
476    return "FinleyMesh";    return "FinleyMesh";
# Line 220  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;             break;
611        case(ReducedNodes):        case(ReducedNodes):
            /* TODO: add ReducedNodes */  
612             numDataPointsPerSample=1;             numDataPointsPerSample=1;
613             if (mesh->Nodes!=NULL) numSamples=mesh->Nodes->numNodes;             numSamples=Finley_NodeFile_getNumReducedNodes(mesh->Nodes);
            throw FinleyAdapterException("Error - ReducedNodes is not supported yet.");  
614             break;             break;
615        case(Elements):        case(Elements):
616             if (mesh->Elements!=NULL) {             if (mesh->Elements!=NULL) {
# Line 285  pair<int,int> MeshAdapter::getDataShape( Line 669  pair<int,int> MeshAdapter::getDataShape(
669        case(DegreesOfFreedom):        case(DegreesOfFreedom):
670             if (mesh->Nodes!=NULL) {             if (mesh->Nodes!=NULL) {
671               numDataPointsPerSample=1;               numDataPointsPerSample=1;
672  #ifndef PASO_MPI               numSamples=Finley_NodeFile_getNumDegreesOfFreedom(mesh->Nodes);
              numSamples=mesh->Nodes->numDegreesOfFreedom;  
 #else  
              numSamples=mesh->Nodes->degreeOfFreedomDistribution->numLocal;  
 #endif  
673             }             }
674             break;             break;
675        case(ReducedDegreesOfFreedom):        case(ReducedDegreesOfFreedom):
676             if (mesh->Nodes!=NULL) {             if (mesh->Nodes!=NULL) {
677               numDataPointsPerSample=1;               numDataPointsPerSample=1;
678  #ifndef PASO_MPI               numSamples=Finley_NodeFile_getNumReducedDegreesOfFreedom(mesh->Nodes);
              numSamples=mesh->Nodes->reducedNumDegreesOfFreedom;  
 #else  
              numSamples=mesh->Nodes->reducedDegreeOfFreedomDistribution->numLocal;  
 #endif  
679             }             }
680             break;             break;
681        default:        default:
# Line 344  void MeshAdapter::addPDEToSystem( Line 720  void MeshAdapter::addPDEToSystem(
720     checkFinleyError();     checkFinleyError();
721  }  }
722    
723    void  MeshAdapter::addPDEToLumpedSystem(
724                         escript::Data& mat,
725                         const escript::Data& D,
726                         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();
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  //  //
# Line 454  void MeshAdapter::interpolateOnDomain(es Line 848  void MeshAdapter::interpolateOnDomain(es
848       case(Elements):       case(Elements):
849          if (target.getFunctionSpace().getTypeCode()==Elements) {          if (target.getFunctionSpace().getTypeCode()==Elements) {
850             Finley_Assemble_CopyElementData(mesh->Elements,&_target,&_in);             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          }          }
# Line 468  void MeshAdapter::interpolateOnDomain(es Line 864  void MeshAdapter::interpolateOnDomain(es
864       case(FaceElements):       case(FaceElements):
865          if (target.getFunctionSpace().getTypeCode()==FaceElements) {          if (target.getFunctionSpace().getTypeCode()==FaceElements) {
866             Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);             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.");
871         }         }
# Line 490  void MeshAdapter::interpolateOnDomain(es Line 888  void MeshAdapter::interpolateOnDomain(es
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,&_in);             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;
# Line 508  void MeshAdapter::interpolateOnDomain(es Line 908  void MeshAdapter::interpolateOnDomain(es
908          switch(target.getFunctionSpace().getTypeCode()) {          switch(target.getFunctionSpace().getTypeCode()) {
909             case(ReducedDegreesOfFreedom):             case(ReducedDegreesOfFreedom):
910             case(DegreesOfFreedom):             case(DegreesOfFreedom):
            case(Nodes):  
            case(ReducedNodes):  
911                Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);                Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
912                break;                break;
913  #ifndef PASO_MPI  
914             case(Elements):             case(Nodes):
915             case(ReducedElements):             case(ReducedNodes):
916                Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);                if (getMPISize()>1) {
917                break;                    escript::Data temp=escript::Data(in);
918             case(FaceElements):                    temp.expand();
919             case(ReducedFaceElements):                    escriptDataC _in2 = temp.getDataC();
920                Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);                    Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in2);
921                break;                } else {
922             case(Points):                    Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
923                Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);                }
924                break;                break;
            case(ContactElementsZero):  
            case(ContactElementsOne):  
            case(ReducedContactElementsZero):  
            case(ReducedContactElementsOne):  
               Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);  
              break;  
 #else  
            /* need to copy Degrees of freedom data to nodal data so that the external values are available */  
925             case(Elements):             case(Elements):
926             case(ReducedElements):             case(ReducedElements):
927                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
928                Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&(nodeTemp.getDataC()),&_target);                   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             case(ReducedFaceElements):             case(ReducedFaceElements):
937                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
938                Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&(nodeTemp.getDataC()),&_target);                   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                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
948                Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&(nodeTemp.getDataC()),&_target);                   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             case(ReducedContactElementsZero):             case(ReducedContactElementsZero):
957             case(ReducedContactElementsOne):             case(ReducedContactElementsOne):
958                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
959                Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&(nodeTemp.getDataC()),&_target);                   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;
 #endif  
966             default:             default:
967               stringstream temp;               stringstream temp;
968               temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();               temp << "Error - Interpolation On Domain: Finley does not know anything about function space type " << target.getFunctionSpace().getTypeCode();
# Line 567  void MeshAdapter::interpolateOnDomain(es Line 976  void MeshAdapter::interpolateOnDomain(es
976               throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to mesh nodes.");               throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to mesh nodes.");
977               break;               break;
978            case(ReducedNodes):            case(ReducedNodes):
979               Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);                if (getMPISize()>1) {
980               break;                    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):            case(DegreesOfFreedom):
989               throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to degrees of freedom");               throw FinleyAdapterException("Error - Finley does not support interpolation from reduced degrees of freedom to degrees of freedom");
990               break;               break;
# Line 577  void MeshAdapter::interpolateOnDomain(es Line 993  void MeshAdapter::interpolateOnDomain(es
993               break;               break;
994            case(Elements):            case(Elements):
995            case(ReducedElements):            case(ReducedElements):
996               Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);                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            case(ReducedFaceElements):            case(ReducedFaceElements):
1006               Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);                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,&_target);                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            case(ReducedContactElementsZero):            case(ReducedContactElementsZero):
1026            case(ReducedContactElementsOne):            case(ReducedContactElementsOne):
1027               Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);                if (getMPISize()>1) {
1028                     escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1029                     escriptDataC _in2 = temp.getDataC();
1030                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in2,&_target);
1031                  } else {
1032                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
1033                 }
1034               break;               break;
1035            default:            default:
1036               stringstream temp;               stringstream temp;
# Line 707  void MeshAdapter::setToIntegrals(std::ve Line 1147  void MeshAdapter::setToIntegrals(std::ve
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();    escriptDataC _arg=arg.getDataC();
1155    switch(arg.getFunctionSpace().getTypeCode()) {    switch(arg.getFunctionSpace().getTypeCode()) {
1156       case(Nodes):       case(Nodes):
1157          /* TODO */          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1158          throw FinleyAdapterException("Error - Integral of data on nodes is not supported.");          _temp=temp.getDataC();
1159            Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1160          break;          break;
1161       case(ReducedNodes):       case(ReducedNodes):
1162          /* TODO */          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1163          throw FinleyAdapterException("Error - Integral of data on reduced nodes is not supported.");          _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,&integrals[0]);          Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);
# Line 746  void MeshAdapter::setToIntegrals(std::ve Line 1191  void MeshAdapter::setToIntegrals(std::ve
1191          Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);          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 758  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  //  //
# Line 775  void MeshAdapter::setToGradient(escript: Line 1225  void MeshAdapter::setToGradient(escript:
1225    Finley_Mesh* mesh=m_finleyMesh.get();    Finley_Mesh* mesh=m_finleyMesh.get();
1226    escriptDataC _grad=grad.getDataC();    escriptDataC _grad=grad.getDataC();
1227    escriptDataC nodeDataC;    escriptDataC nodeDataC;
1228  #ifdef PASO_MPI    escript::Data temp;
1229    escript::Data nodeTemp( arg, continuousFunction(asAbstractContinuousDomain()) );    if (getMPISize()>1) {
1230    if( arg.getFunctionSpace().getTypeCode() != Nodes )        if( arg.getFunctionSpace().getTypeCode() == DegreesOfFreedom ) {
1231    {          temp=escript::Data( arg,  continuousFunction(asAbstractContinuousDomain()) );
1232      Finley_Assemble_CopyNodalData(mesh->Nodes,&(nodeTemp.getDataC()),&(arg.getDataC()));          nodeDataC = temp.getDataC();
1233      nodeDataC = nodeTemp.getDataC();        } 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    }    }
   else  
     nodeDataC = arg.getDataC();  
 #else  
   nodeDataC = arg.getDataC();  
 #endif  
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.");
# Line 917  void MeshAdapter::saveDX(const std::stri Line 1369  void MeshAdapter::saveDX(const std::stri
1369    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1370    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
1371    
1372      boost::python::list keys=arg.keys();    boost::python::list keys=arg.keys();
1373      for (int i=0;i<num_data;++i) {    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]]);           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 saveDX: 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 967  void MeshAdapter::saveVTK(const std::str Line 1419  void MeshAdapter::saveVTK(const std::str
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             std::string n=boost::python::extract<std::string>(keys[i]);
1423           escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);           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 981  void MeshAdapter::saveVTK(const std::str Line 1433  void MeshAdapter::saveVTK(const std::str
1433              strcpy(c_names[i],n.c_str());              strcpy(c_names[i],n.c_str());
1434           }           }
1435      }      }
 #ifndef PASO_MPI      
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);
 #else  
     Finley_Mesh_saveVTK_MPIO(filename.c_str(),m_finleyMesh.get(),num_data,c_names,ptr_data);  
 #endif  
1437    
1438  checkFinleyError();    checkFinleyError();
1439    /* win32 refactor */    /* win32 refactor */
1440    TMPMEMFREE(c_names);    TMPMEMFREE(c_names);
1441    TMPMEMFREE(data);    TMPMEMFREE(data);
# Line 1038  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 1131  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 {          } else {
1594             return false;             return false;
1595          }          }
# Line 1143  bool MeshAdapter::probeInterpolationOnDo Line 1602  bool MeshAdapter::probeInterpolationOnDo
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 {          } else {
1608             return false;             return false;
1609          }          }
# Line 1162  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 {          } else {
1629             return false;             return false;
1630          }          }
# Line 1275  int* MeshAdapter::borrowSampleReferenceI Line 1738  int* MeshAdapter::borrowSampleReferenceI
1738    Finley_Mesh* mesh=m_finleyMesh.get();    Finley_Mesh* mesh=m_finleyMesh.get();
1739    switch (functionSpaceType) {    switch (functionSpaceType) {
1740      case(Nodes):      case(Nodes):
1741        if (mesh->Nodes!=NULL) {        out=mesh->Nodes->Id;
1742          out=mesh->Nodes->Id;        break;
         break;  
       }  
1743      case(ReducedNodes):      case(ReducedNodes):
1744        throw FinleyAdapterException("Error -  ReducedNodes not supported yet.");        out=mesh->Nodes->reducedNodesId;
1745        break;        break;
1746      case(Elements):      case(Elements):
1747        out=mesh->FaceElements->Id;        out=mesh->Elements->Id;
1748        break;        break;
1749      case(ReducedElements):      case(ReducedElements):
1750        out=mesh->Elements->Id;        out=mesh->Elements->Id;
# Line 1310  int* MeshAdapter::borrowSampleReferenceI Line 1771  int* MeshAdapter::borrowSampleReferenceI
1771        out=mesh->ContactElements->Id;        out=mesh->ContactElements->Id;
1772        break;        break;
1773      case(DegreesOfFreedom):      case(DegreesOfFreedom):
1774        out=mesh->Nodes->degreeOfFreedomId;        out=mesh->Nodes->degreesOfFreedomId;
1775        break;        break;
1776      case(ReducedDegreesOfFreedom):      case(ReducedDegreesOfFreedom):
1777        out=mesh->Nodes->reducedDegreeOfFreedomId;        out=mesh->Nodes->reducedDegreesOfFreedomId;
1778        break;        break;
1779      default:      default:
1780        stringstream temp;        stringstream temp;

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

  ViewVC Help
Powered by ViewVC 1.1.26