/[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 1062 by gross, Mon Mar 26 06:17:53 2007 UTC revision 1388 by trankine, Fri Jan 11 07:45:58 2008 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[12];
108       NcVar *ids, *data;
109       int *int_ptr;
110       Finley_Mesh *mesh = m_finleyMesh.get();
111       Finley_TagMap* tag_map;
112       int num_Tags = 0;
113       int mpi_size             = mesh->MPIInfo->size;
114       int mpi_rank             = mesh->MPIInfo->rank;
115       int numDim               = mesh->Nodes->numDim;
116       int numNodes             = mesh->Nodes->numNodes;
117       int num_Elements         = mesh->Elements->numElements;
118       int num_FaceElements         = mesh->FaceElements->numElements;
119       int num_ContactElements      = mesh->ContactElements->numElements;
120       int num_Points           = mesh->Points->numElements;
121       int num_Elements_numNodes        = mesh->Elements->numNodes;
122       int num_FaceElements_numNodes    = mesh->FaceElements->numNodes;
123       int num_ContactElements_numNodes = mesh->ContactElements->numNodes;
124       char *newFileName = Paso_MPI_appendRankToFileName(strdup(fileName.c_str()), mpi_size, mpi_rank);
125    
126       /* Figure out how much storage is required for tags */
127       tag_map = mesh->TagMap;
128       if (tag_map) {
129         while (tag_map) {
130        num_Tags++;
131            tag_map=tag_map->next;
132         }
133       }
134    
135       // NetCDF error handler
136       NcError err(NcError::verbose_nonfatal);
137       // Create the file.
138       NcFile dataFile(newFileName, NcFile::Replace);
139       // check if writing was successful
140       if (!dataFile.is_valid())
141            throw DataException("Error - MeshAdapter::dump: opening of NetCDF file for output failed: " + *newFileName);
142    
143       // Define dimensions (num_Elements and dim_Elements are identical, dim_Elements only appears if > 0)
144       if (! (ncdims[0] = dataFile.add_dim("numNodes", numNodes)) )
145            throw DataException("Error - MeshAdapter::dump: appending dimension numNodes to netCDF file failed: " + *newFileName);
146       if (! (ncdims[1] = dataFile.add_dim("numDim", numDim)) )
147            throw DataException("Error - MeshAdapter::dump: appending dimension numDim to netCDF file failed: " + *newFileName);
148       if (! (ncdims[2] = dataFile.add_dim("mpi_size_plus_1", mpi_size+1)) )
149            throw DataException("Error - MeshAdapter::dump: appending dimension mpi_size to netCDF file failed: " + *newFileName);
150       if (num_Elements>0)
151          if (! (ncdims[3] = dataFile.add_dim("dim_Elements", num_Elements)) )
152            throw DataException("Error - MeshAdapter::dump: appending dimension dim_Elements to netCDF file failed: " + *newFileName);
153       if (num_FaceElements>0)
154          if (! (ncdims[4] = dataFile.add_dim("dim_FaceElements", num_FaceElements)) )
155            throw DataException("Error - MeshAdapter::dump: appending dimension dim_FaceElements to netCDF file failed: " + *newFileName);
156       if (num_ContactElements>0)
157          if (! (ncdims[5] = dataFile.add_dim("dim_ContactElements", num_ContactElements)) )
158            throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements to netCDF file failed: " + *newFileName);
159       if (num_Points>0)
160          if (! (ncdims[6] = dataFile.add_dim("dim_Points", num_Points)) )
161            throw DataException("Error - MeshAdapter::dump: appending dimension dim_Points to netCDF file failed: " + *newFileName);
162       if (num_Elements>0)
163          if (! (ncdims[7] = dataFile.add_dim("dim_Elements_Nodes", num_Elements_numNodes)) )
164            throw DataException("Error - MeshAdapter::dump: appending dimension dim_Elements_Nodes to netCDF file failed: " + *newFileName);
165       if (num_FaceElements>0)
166          if (! (ncdims[8] = dataFile.add_dim("dim_FaceElements_numNodes", num_FaceElements_numNodes)) )
167            throw DataException("Error - MeshAdapter::dump: appending dimension dim_FaceElements_numNodes to netCDF file failed: " + *newFileName);
168       if (num_ContactElements>0)
169          if (! (ncdims[9] = dataFile.add_dim("dim_ContactElements_numNodes", num_ContactElements_numNodes)) )
170            throw DataException("Error - MeshAdapter::dump: appending dimension dim_ContactElements_numNodes to netCDF file failed: " + *newFileName);
171       if (num_Tags>0)
172          if (! (ncdims[10] = dataFile.add_dim("dim_Tags", num_Tags)) )
173            throw DataException("Error - MeshAdapter::dump: appending dimension dim_Tags to netCDF file failed: " + *newFileName);
174    
175       // Attributes: MPI size, MPI rank, Name, order, reduced_order
176       if (!dataFile.add_att("mpi_size", mpi_size) )
177            throw DataException("Error - MeshAdapter::dump: appending mpi_size to NetCDF file failed: " + *newFileName);
178       if (!dataFile.add_att("mpi_rank", mpi_rank) )
179            throw DataException("Error - MeshAdapter::dump: appending mpi_rank to NetCDF file failed: " + *newFileName);
180       if (!dataFile.add_att("Name",mesh->Name) )
181            throw DataException("Error - MeshAdapter::dump: appending Name to NetCDF file failed: " + *newFileName);
182       if (!dataFile.add_att("numDim",numDim) )
183            throw DataException("Error - MeshAdapter::dump: appending order to NetCDF file failed: " + *newFileName);
184       if (!dataFile.add_att("order",mesh->order) )
185            throw DataException("Error - MeshAdapter::dump: appending order to NetCDF file failed: " + *newFileName);
186       if (!dataFile.add_att("reduced_order",mesh->reduced_order) )
187            throw DataException("Error - MeshAdapter::dump: appending reduced_order to NetCDF file failed: " + *newFileName);
188       if (!dataFile.add_att("numNodes",numNodes) )
189            throw DataException("Error - MeshAdapter::dump: appending numNodes to NetCDF file failed: " + *newFileName);
190       if (!dataFile.add_att("num_Elements",num_Elements) )
191            throw DataException("Error - MeshAdapter::dump: appending num_Elements to NetCDF file failed: " + *newFileName);
192       if (!dataFile.add_att("num_FaceElements",num_FaceElements) )
193            throw DataException("Error - MeshAdapter::dump: appending num_FaceElements to NetCDF file failed: " + *newFileName);
194       if (!dataFile.add_att("num_ContactElements",num_ContactElements) )
195            throw DataException("Error - MeshAdapter::dump: appending num_ContactElements to NetCDF file failed: " + *newFileName);
196       if (!dataFile.add_att("num_Points",num_Points) )
197            throw DataException("Error - MeshAdapter::dump: appending num_Points to NetCDF file failed: " + *newFileName);
198       if (!dataFile.add_att("num_Elements_numNodes",num_Elements_numNodes) )
199            throw DataException("Error - MeshAdapter::dump: appending num_Elements_numNodes to NetCDF file failed: " + *newFileName);
200       if (!dataFile.add_att("num_FaceElements_numNodes",num_FaceElements_numNodes) )
201            throw DataException("Error - MeshAdapter::dump: appending num_FaceElements_numNodes to NetCDF file failed: " + *newFileName);
202       if (!dataFile.add_att("num_ContactElements_numNodes",num_ContactElements_numNodes) )
203            throw DataException("Error - MeshAdapter::dump: appending num_ContactElements_numNodes to NetCDF file failed: " + *newFileName);
204       if (!dataFile.add_att("Elements_TypeId", mesh->Elements->ReferenceElement->Type->TypeId) )
205          throw DataException("Error - MeshAdapter::dump: appending Elements_TypeId to NetCDF file failed: " + *newFileName);
206       if (!dataFile.add_att("FaceElements_TypeId", mesh->FaceElements->ReferenceElement->Type->TypeId) )
207          throw DataException("Error - MeshAdapter::dump: appending FaceElements_TypeId to NetCDF file failed: " + *newFileName);
208       if (!dataFile.add_att("ContactElements_TypeId", mesh->ContactElements->ReferenceElement->Type->TypeId) )
209          throw DataException("Error - MeshAdapter::dump: appending ContactElements_TypeId to NetCDF file failed: " + *newFileName);
210       if (!dataFile.add_att("Points_TypeId", mesh->Points->ReferenceElement->Type->TypeId) )
211          throw DataException("Error - MeshAdapter::dump: appending Points_TypeId to NetCDF file failed: " + *newFileName);
212       if (!dataFile.add_att("num_Tags", num_Tags) )
213          throw DataException("Error - MeshAdapter::dump: appending num_Tags to NetCDF file failed: " + *newFileName);
214    
215       // // // // // Nodes // // // // //
216    
217       // Only write nodes if non-empty because NetCDF doesn't like empty arrays (it treats them as NC_UNLIMITED)
218       if (numNodes>0) {
219    
220       // Nodes Id
221       if (! ( ids = dataFile.add_var("Nodes_Id", ncInt, ncdims[0])) )
222            throw DataException("Error - MeshAdapter::dump: appending Nodes_Id to netCDF file failed: " + *newFileName);
223       int_ptr = &mesh->Nodes->Id[0];
224       if (! (ids->put(int_ptr, numNodes)) )
225            throw DataException("Error - MeshAdapter::dump: copy Nodes_Id to netCDF buffer failed: " + *newFileName);
226    
227       // Nodes Tag
228       if (! ( ids = dataFile.add_var("Nodes_Tag", ncInt, ncdims[0])) )
229            throw DataException("Error - MeshAdapter::dump: appending Nodes_Tag to netCDF file failed: " + *newFileName);
230       int_ptr = &mesh->Nodes->Tag[0];
231       if (! (ids->put(int_ptr, numNodes)) )
232            throw DataException("Error - MeshAdapter::dump: copy Nodes_Tag to netCDF buffer failed: " + *newFileName);
233    
234       // Nodes gDOF
235       if (! ( ids = dataFile.add_var("Nodes_gDOF", ncInt, ncdims[0])) )
236            throw DataException("Error - MeshAdapter::dump: appending Nodes_gDOF to netCDF file failed: " + *newFileName);
237       int_ptr = &mesh->Nodes->globalDegreesOfFreedom[0];
238       if (! (ids->put(int_ptr, numNodes)) )
239            throw DataException("Error - MeshAdapter::dump: copy Nodes_gDOF to netCDF buffer failed: " + *newFileName);
240    
241       // Nodes global node index
242       if (! ( ids = dataFile.add_var("Nodes_gNI", ncInt, ncdims[0])) )
243            throw DataException("Error - MeshAdapter::dump: appending Nodes_gNI to netCDF file failed: " + *newFileName);
244       int_ptr = &mesh->Nodes->globalNodesIndex[0];
245       if (! (ids->put(int_ptr, numNodes)) )
246            throw DataException("Error - MeshAdapter::dump: copy Nodes_gNI to netCDF buffer failed: " + *newFileName);
247    
248       // Nodes grDof
249       if (! ( ids = dataFile.add_var("Nodes_grDfI", ncInt, ncdims[0])) )
250            throw DataException("Error - MeshAdapter::dump: appending Nodes_grDfI to netCDF file failed: " + *newFileName);
251       int_ptr = &mesh->Nodes->globalReducedDOFIndex[0];
252       if (! (ids->put(int_ptr, numNodes)) )
253            throw DataException("Error - MeshAdapter::dump: copy Nodes_grDfI to netCDF buffer failed: " + *newFileName);
254    
255       // Nodes grNI
256       if (! ( ids = dataFile.add_var("Nodes_grNI", ncInt, ncdims[0])) )
257            throw DataException("Error - MeshAdapter::dump: appending Nodes_grNI to netCDF file failed: " + *newFileName);
258       int_ptr = &mesh->Nodes->globalReducedNodesIndex[0];
259       if (! (ids->put(int_ptr, numNodes)) )
260            throw DataException("Error - MeshAdapter::dump: copy Nodes_grNI to netCDF buffer failed: " + *newFileName);
261    
262       // Nodes Coordinates
263       if (! ( ids = dataFile.add_var("Nodes_Coordinates", ncDouble, ncdims[0], ncdims[1]) ) )
264            throw DataException("Error - MeshAdapter::dump: appending Nodes_Coordinates to netCDF file failed: " + *newFileName);
265       if (! (ids->put(&(mesh->Nodes->Coordinates[INDEX2(0,0,numDim)]), numNodes, numDim)) )
266            throw DataException("Error - MeshAdapter::dump: copy Nodes_Coordinates to netCDF buffer failed: " + *newFileName);
267    
268       // Nodes degreesOfFreedomDistribution
269       if (! ( ids = dataFile.add_var("Nodes_DofDistribution", ncInt, ncdims[2])) )
270            throw DataException("Error - MeshAdapter::dump: appending Nodes_DofDistribution to netCDF file failed: " + *newFileName);
271       int_ptr = &mesh->Nodes->degreesOfFreedomDistribution->first_component[0];
272       if (! (ids->put(int_ptr, mpi_size+1)) )
273            throw DataException("Error - MeshAdapter::dump: copy Nodes_DofDistribution to netCDF buffer failed: " + *newFileName);
274    
275       }
276    
277       // // // // // Elements // // // // //
278    
279       if (num_Elements>0) {
280    
281         // Temp storage to gather node IDs
282         int *Elements_Nodes = TMPMEMALLOC(num_Elements*num_Elements_numNodes,int);
283    
284         // Elements_Id
285         if (! ( ids = dataFile.add_var("Elements_Id", ncInt, ncdims[3])) )
286            throw DataException("Error - MeshAdapter::dump: appending Elements_Id to netCDF file failed: " + *newFileName);
287         int_ptr = &mesh->Elements->Id[0];
288         if (! (ids->put(int_ptr, num_Elements)) )
289            throw DataException("Error - MeshAdapter::dump: copy Elements_Id to netCDF buffer failed: " + *newFileName);
290    
291         // Elements_Tag
292         if (! ( ids = dataFile.add_var("Elements_Tag", ncInt, ncdims[3])) )
293            throw DataException("Error - MeshAdapter::dump: appending Elements_Tag to netCDF file failed: " + *newFileName);
294         int_ptr = &mesh->Elements->Tag[0];
295         if (! (ids->put(int_ptr, num_Elements)) )
296            throw DataException("Error - MeshAdapter::dump: copy Elements_Tag to netCDF buffer failed: " + *newFileName);
297    
298         // Elements_Owner
299         if (! ( ids = dataFile.add_var("Elements_Owner", ncInt, ncdims[3])) )
300            throw DataException("Error - MeshAdapter::dump: appending Elements_Owner to netCDF file failed: " + *newFileName);
301         int_ptr = &mesh->Elements->Owner[0];
302         if (! (ids->put(int_ptr, num_Elements)) )
303            throw DataException("Error - MeshAdapter::dump: copy Elements_Owner to netCDF buffer failed: " + *newFileName);
304    
305         // Elements_Color
306         if (! ( ids = dataFile.add_var("Elements_Color", ncInt, ncdims[3])) )
307            throw DataException("Error - MeshAdapter::dump: appending Elements_Color to netCDF file failed: " + *newFileName);
308         int_ptr = &mesh->Elements->Color[0];
309         if (! (ids->put(int_ptr, num_Elements)) )
310            throw DataException("Error - MeshAdapter::dump: copy Elements_Color to netCDF buffer failed: " + *newFileName);
311    
312         // Elements_Nodes
313         for (int i=0; i<num_Elements; i++)
314           for (int j=0; j<num_Elements_numNodes; j++)
315             Elements_Nodes[INDEX2(j,i,num_Elements_numNodes)] = mesh->Nodes->Id[mesh->Elements->Nodes[INDEX2(j,i,num_Elements_numNodes)]];
316         if (! ( ids = dataFile.add_var("Elements_Nodes", ncInt, ncdims[3], ncdims[7]) ) )
317            throw DataException("Error - MeshAdapter::dump: appending Elements_Nodes to netCDF file failed: " + *newFileName);
318         if (! (ids->put(&(Elements_Nodes[0]), num_Elements, num_Elements_numNodes)) )
319            throw DataException("Error - MeshAdapter::dump: copy Elements_Nodes to netCDF buffer failed: " + *newFileName);
320    
321         TMPMEMFREE(Elements_Nodes);
322    
323       }
324    
325       // // // // // Face_Elements // // // // //
326    
327       if (num_FaceElements>0) {
328    
329         // Temp storage to gather node IDs
330         int *FaceElements_Nodes = TMPMEMALLOC(num_FaceElements*num_FaceElements_numNodes,int);
331    
332         // FaceElements_Id
333         if (! ( ids = dataFile.add_var("FaceElements_Id", ncInt, ncdims[4])) )
334            throw DataException("Error - MeshAdapter::dump: appending FaceElements_Id to netCDF file failed: " + *newFileName);
335         int_ptr = &mesh->FaceElements->Id[0];
336         if (! (ids->put(int_ptr, num_FaceElements)) )
337            throw DataException("Error - MeshAdapter::dump: copy FaceElements_Id to netCDF buffer failed: " + *newFileName);
338    
339         // FaceElements_Tag
340         if (! ( ids = dataFile.add_var("FaceElements_Tag", ncInt, ncdims[4])) )
341            throw DataException("Error - MeshAdapter::dump: appending FaceElements_Tag to netCDF file failed: " + *newFileName);
342         int_ptr = &mesh->FaceElements->Tag[0];
343         if (! (ids->put(int_ptr, num_FaceElements)) )
344            throw DataException("Error - MeshAdapter::dump: copy FaceElements_Tag to netCDF buffer failed: " + *newFileName);
345    
346         // FaceElements_Owner
347         if (! ( ids = dataFile.add_var("FaceElements_Owner", ncInt, ncdims[4])) )
348            throw DataException("Error - MeshAdapter::dump: appending FaceElements_Owner to netCDF file failed: " + *newFileName);
349         int_ptr = &mesh->FaceElements->Owner[0];
350         if (! (ids->put(int_ptr, num_FaceElements)) )
351            throw DataException("Error - MeshAdapter::dump: copy FaceElements_Owner to netCDF buffer failed: " + *newFileName);
352    
353         // FaceElements_Color
354         if (! ( ids = dataFile.add_var("FaceElements_Color", ncInt, ncdims[4])) )
355            throw DataException("Error - MeshAdapter::dump: appending FaceElements_Color to netCDF file failed: " + *newFileName);
356         int_ptr = &mesh->FaceElements->Color[0];
357         if (! (ids->put(int_ptr, num_FaceElements)) )
358            throw DataException("Error - MeshAdapter::dump: copy FaceElements_Color to netCDF buffer failed: " + *newFileName);
359    
360         // FaceElements_Nodes
361         for (int i=0; i<num_FaceElements; i++)
362           for (int j=0; j<num_FaceElements_numNodes; j++)
363             FaceElements_Nodes[INDEX2(j,i,num_FaceElements_numNodes)] = mesh->Nodes->Id[mesh->FaceElements->Nodes[INDEX2(j,i,num_FaceElements_numNodes)]];
364         if (! ( ids = dataFile.add_var("FaceElements_Nodes", ncInt, ncdims[4], ncdims[8]) ) )
365            throw DataException("Error - MeshAdapter::dump: appending FaceElements_Nodes to netCDF file failed: " + *newFileName);
366         if (! (ids->put(&(FaceElements_Nodes[0]), num_FaceElements, num_FaceElements_numNodes)) )
367            throw DataException("Error - MeshAdapter::dump: copy FaceElements_Nodes to netCDF buffer failed: " + *newFileName);
368    
369         TMPMEMFREE(FaceElements_Nodes);
370    
371       }
372    
373       // // // // // Contact_Elements // // // // //
374    
375       if (num_ContactElements>0) {
376    
377         // Temp storage to gather node IDs
378         int *ContactElements_Nodes = TMPMEMALLOC(num_ContactElements*num_ContactElements_numNodes,int);
379    
380         // ContactElements_Id
381         if (! ( ids = dataFile.add_var("ContactElements_Id", ncInt, ncdims[5])) )
382            throw DataException("Error - MeshAdapter::dump: appending ContactElements_Id to netCDF file failed: " + *newFileName);
383         int_ptr = &mesh->ContactElements->Id[0];
384         if (! (ids->put(int_ptr, num_ContactElements)) )
385            throw DataException("Error - MeshAdapter::dump: copy ContactElements_Id to netCDF buffer failed: " + *newFileName);
386    
387         // ContactElements_Tag
388         if (! ( ids = dataFile.add_var("ContactElements_Tag", ncInt, ncdims[5])) )
389            throw DataException("Error - MeshAdapter::dump: appending ContactElements_Tag to netCDF file failed: " + *newFileName);
390         int_ptr = &mesh->ContactElements->Tag[0];
391         if (! (ids->put(int_ptr, num_ContactElements)) )
392            throw DataException("Error - MeshAdapter::dump: copy ContactElements_Tag to netCDF buffer failed: " + *newFileName);
393    
394         // ContactElements_Owner
395         if (! ( ids = dataFile.add_var("ContactElements_Owner", ncInt, ncdims[5])) )
396            throw DataException("Error - MeshAdapter::dump: appending ContactElements_Owner to netCDF file failed: " + *newFileName);
397         int_ptr = &mesh->ContactElements->Owner[0];
398         if (! (ids->put(int_ptr, num_ContactElements)) )
399            throw DataException("Error - MeshAdapter::dump: copy ContactElements_Owner to netCDF buffer failed: " + *newFileName);
400    
401         // ContactElements_Color
402         if (! ( ids = dataFile.add_var("ContactElements_Color", ncInt, ncdims[5])) )
403            throw DataException("Error - MeshAdapter::dump: appending ContactElements_Color to netCDF file failed: " + *newFileName);
404         int_ptr = &mesh->ContactElements->Color[0];
405         if (! (ids->put(int_ptr, num_ContactElements)) )
406            throw DataException("Error - MeshAdapter::dump: copy ContactElements_Color to netCDF buffer failed: " + *newFileName);
407    
408         // ContactElements_Nodes
409         for (int i=0; i<num_ContactElements; i++)
410           for (int j=0; j<num_ContactElements_numNodes; j++)
411             ContactElements_Nodes[INDEX2(j,i,num_ContactElements_numNodes)] = mesh->Nodes->Id[mesh->ContactElements->Nodes[INDEX2(j,i,num_ContactElements_numNodes)]];
412         if (! ( ids = dataFile.add_var("ContactElements_Nodes", ncInt, ncdims[5], ncdims[9]) ) )
413            throw DataException("Error - MeshAdapter::dump: appending ContactElements_Nodes to netCDF file failed: " + *newFileName);
414         if (! (ids->put(&(ContactElements_Nodes[0]), num_ContactElements, num_ContactElements_numNodes)) )
415            throw DataException("Error - MeshAdapter::dump: copy ContactElements_Nodes to netCDF buffer failed: " + *newFileName);
416    
417         TMPMEMFREE(ContactElements_Nodes);
418    
419       }
420    
421       // // // // // Points // // // // //
422    
423       if (num_Points>0) {
424    
425         fprintf(stderr, "\n\n\nWARNING: MeshAdapter::dump has not been tested with Point elements\n\n\n");
426    
427         // Temp storage to gather node IDs
428         int *Points_Nodes = TMPMEMALLOC(num_Points,int);
429    
430         // Points_Id
431         if (! ( ids = dataFile.add_var("Points_Id", ncInt, ncdims[6])) )
432            throw DataException("Error - MeshAdapter::dump: appending Points_Id to netCDF file failed: " + *newFileName);
433         int_ptr = &mesh->Points->Id[0];
434         if (! (ids->put(int_ptr, num_Points)) )
435            throw DataException("Error - MeshAdapter::dump: copy Points_Id to netCDF buffer failed: " + *newFileName);
436    
437         // Points_Tag
438         if (! ( ids = dataFile.add_var("Points_Tag", ncInt, ncdims[6])) )
439            throw DataException("Error - MeshAdapter::dump: appending Points_Tag to netCDF file failed: " + *newFileName);
440         int_ptr = &mesh->Points->Tag[0];
441         if (! (ids->put(int_ptr, num_Points)) )
442            throw DataException("Error - MeshAdapter::dump: copy Points_Tag to netCDF buffer failed: " + *newFileName);
443    
444         // Points_Owner
445         if (! ( ids = dataFile.add_var("Points_Owner", ncInt, ncdims[6])) )
446            throw DataException("Error - MeshAdapter::dump: appending Points_Owner to netCDF file failed: " + *newFileName);
447         int_ptr = &mesh->Points->Owner[0];
448         if (! (ids->put(int_ptr, num_Points)) )
449            throw DataException("Error - MeshAdapter::dump: copy Points_Owner to netCDF buffer failed: " + *newFileName);
450    
451         // Points_Color
452         if (! ( ids = dataFile.add_var("Points_Color", ncInt, ncdims[6])) )
453            throw DataException("Error - MeshAdapter::dump: appending Points_Color to netCDF file failed: " + *newFileName);
454         int_ptr = &mesh->Points->Color[0];
455         if (! (ids->put(int_ptr, num_Points)) )
456            throw DataException("Error - MeshAdapter::dump: copy Points_Color to netCDF buffer failed: " + *newFileName);
457    
458         // Points_Nodes
459         // mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]]
460         for (int i=0; i<num_Points; i++)
461           Points_Nodes[i] = mesh->Nodes->Id[mesh->Points->Nodes[INDEX2(0,i,1)]];
462         if (! ( ids = dataFile.add_var("Points_Nodes", ncInt, ncdims[6]) ) )
463            throw DataException("Error - MeshAdapter::dump: appending Points_Nodes to netCDF file failed: " + *newFileName);
464         if (! (ids->put(&(Points_Nodes[0]), num_Points)) )
465            throw DataException("Error - MeshAdapter::dump: copy Points_Nodes to netCDF buffer failed: " + *newFileName);
466    
467         TMPMEMFREE(Points_Nodes);
468    
469       }
470    
471       // // // // // TagMap // // // // //
472    
473       if (num_Tags>0) {
474    
475         // Temp storage to gather node IDs
476         int *Tags_keys = TMPMEMALLOC(num_Tags, int);
477         char name_temp[4096];
478    
479         /* Copy tag data into temp arrays */
480         tag_map = mesh->TagMap;
481         if (tag_map) {
482           int i = 0;
483           while (tag_map) {
484        Tags_keys[i++] = tag_map->tag_key;
485            tag_map=tag_map->next;
486           }
487         }
488    
489         // Tags_keys
490         if (! ( ids = dataFile.add_var("Tags_keys", ncInt, ncdims[10])) )
491            throw DataException("Error - MeshAdapter::dump: appending Tags_keys to netCDF file failed: " + *newFileName);
492         int_ptr = &Tags_keys[0];
493         if (! (ids->put(int_ptr, num_Tags)) )
494            throw DataException("Error - MeshAdapter::dump: copy Tags_keys to netCDF buffer failed: " + *newFileName);
495    
496         // Tags_names_*
497         // This is an array of strings, it should be stored as an array but instead I have hacked in one attribute per string
498         // because the NetCDF manual doesn't tell how to do an array of strings
499         tag_map = mesh->TagMap;
500         if (tag_map) {
501           int i = 0;
502           while (tag_map) {
503             sprintf(name_temp, "Tags_name_%d", i);
504             if (!dataFile.add_att(name_temp, tag_map->name) )
505               throw DataException("Error - MeshAdapter::dump: appending Tags_names_ to NetCDF file failed: " + *newFileName);
506             tag_map=tag_map->next;
507         i++;
508           }
509         }
510    
511         TMPMEMFREE(Tags_keys);
512    
513       }
514    
515    
516       // NetCDF file is closed by destructor of NcFile object
517    #else
518       Finley_setError(IO_ERROR, "MeshAdapter::dump: not configured with NetCDF. Please contact your installation manager.");
519    #endif  /* USE_NETCDF */
520       checkFinleyError();
521    }
522    
523  string MeshAdapter::getDescription() const  string MeshAdapter::getDescription() const
524  {  {
525    return "FinleyMesh";    return "FinleyMesh";
# Line 220  pair<int,int> MeshAdapter::getDataShape( Line 655  pair<int,int> MeshAdapter::getDataShape(
655     switch (functionSpaceCode) {     switch (functionSpaceCode) {
656        case(Nodes):        case(Nodes):
657             numDataPointsPerSample=1;             numDataPointsPerSample=1;
658             if (mesh->Nodes!=NULL) numSamples=mesh->Nodes->numNodes;             numSamples=Finley_NodeFile_getNumNodes(mesh->Nodes);
659             break;             break;
660        case(ReducedNodes):        case(ReducedNodes):
            /* TODO: add ReducedNodes */  
661             numDataPointsPerSample=1;             numDataPointsPerSample=1;
662             if (mesh->Nodes!=NULL) numSamples=mesh->Nodes->numNodes;             numSamples=Finley_NodeFile_getNumReducedNodes(mesh->Nodes);
            throw FinleyAdapterException("Error - ReducedNodes is not supported yet.");  
663             break;             break;
664        case(Elements):        case(Elements):
665             if (mesh->Elements!=NULL) {             if (mesh->Elements!=NULL) {
# Line 285  pair<int,int> MeshAdapter::getDataShape( Line 718  pair<int,int> MeshAdapter::getDataShape(
718        case(DegreesOfFreedom):        case(DegreesOfFreedom):
719             if (mesh->Nodes!=NULL) {             if (mesh->Nodes!=NULL) {
720               numDataPointsPerSample=1;               numDataPointsPerSample=1;
721  #ifndef PASO_MPI               numSamples=Finley_NodeFile_getNumDegreesOfFreedom(mesh->Nodes);
              numSamples=mesh->Nodes->numDegreesOfFreedom;  
 #else  
              numSamples=mesh->Nodes->degreeOfFreedomDistribution->numLocal;  
 #endif  
722             }             }
723             break;             break;
724        case(ReducedDegreesOfFreedom):        case(ReducedDegreesOfFreedom):
725             if (mesh->Nodes!=NULL) {             if (mesh->Nodes!=NULL) {
726               numDataPointsPerSample=1;               numDataPointsPerSample=1;
727  #ifndef PASO_MPI               numSamples=Finley_NodeFile_getNumReducedDegreesOfFreedom(mesh->Nodes);
              numSamples=mesh->Nodes->reducedNumDegreesOfFreedom;  
 #else  
              numSamples=mesh->Nodes->reducedDegreeOfFreedomDistribution->numLocal;  
 #endif  
728             }             }
729             break;             break;
730        default:        default:
# Line 344  void MeshAdapter::addPDEToSystem( Line 769  void MeshAdapter::addPDEToSystem(
769     checkFinleyError();     checkFinleyError();
770  }  }
771    
772    void  MeshAdapter::addPDEToLumpedSystem(
773                         escript::Data& mat,
774                         const escript::Data& D,
775                         const escript::Data& d) const
776    {
777       escriptDataC _mat=mat.getDataC();
778       escriptDataC _D=D.getDataC();
779       escriptDataC _d=d.getDataC();
780    
781       Finley_Mesh* mesh=m_finleyMesh.get();
782    
783       Finley_Assemble_LumpedSystem(mesh->Nodes,mesh->Elements,&_mat, &_D);
784       Finley_Assemble_LumpedSystem(mesh->Nodes,mesh->FaceElements,&_mat, &_d);
785    
786       checkFinleyError();
787    }
788    
789    
790  //  //
791  // adds linear PDE of second order into the right hand side only  // adds linear PDE of second order into the right hand side only
792  //  //
# Line 366  void MeshAdapter::addPDEToRHS( escript:: Line 809  void MeshAdapter::addPDEToRHS( escript::
809     Finley_Assemble_PDE(mesh->Nodes,mesh->ContactElements, 0, &_rhs , 0, 0, 0, 0, 0, &_y_contact );     Finley_Assemble_PDE(mesh->Nodes,mesh->ContactElements, 0, &_rhs , 0, 0, 0, 0, 0, &_y_contact );
810     checkFinleyError();     checkFinleyError();
811  }  }
812    //
813    // adds PDE of second order into a transport problem
814    //
815    void MeshAdapter::addPDEToTransportProblem(
816                         TransportProblemAdapter& tp, escript::Data& source, const escript::Data& M,
817                         const escript::Data& A, const escript::Data& B, const escript::Data& C,const  escript::Data& D,const  escript::Data& X,const  escript::Data& Y,
818                         const escript::Data& d, const escript::Data& y,
819                         const escript::Data& d_contact,const escript::Data& y_contact) const
820    {
821       DataArrayView::ShapeType shape;
822       source.expand();
823       escript:: Data tmp(0.0,M.getDataPointShape(),tp.getFunctionSpace(),true);
824       escriptDataC _source=source.getDataC();
825       escriptDataC _tmp=tmp.getDataC();
826       escriptDataC _M=M.getDataC();
827       escriptDataC _A=A.getDataC();
828       escriptDataC _B=B.getDataC();
829       escriptDataC _C=C.getDataC();
830       escriptDataC _D=D.getDataC();
831       escriptDataC _X=X.getDataC();
832       escriptDataC _Y=Y.getDataC();
833       escriptDataC _d=d.getDataC();
834       escriptDataC _y=y.getDataC();
835       escriptDataC _d_contact=d_contact.getDataC();
836       escriptDataC _y_contact=y_contact.getDataC();
837    
838       Finley_Mesh* mesh=m_finleyMesh.get();
839       Paso_FCTransportProblem* _tp = tp.getPaso_FCTransportProblem();
840      
841    
842       Finley_Assemble_LumpedSystem(mesh->Nodes,mesh->Elements,&_tmp, &_M);
843       checkFinleyError();
844       /* add mass matix to lumped mass matrix of transport problem */
845       double* tmp_prt=getSampleData(&_tmp,0);
846       int i;
847       int n=Paso_FCTransportProblem_getTotalNumRows(_tp);
848       #pragma omp parallel for private(i) schedule(static)
849       for (i=0;i<n ;++i) _tp->lumped_mass_matrix[i]+=tmp_prt[i];
850    
851       Finley_Assemble_PDE(mesh->Nodes,mesh->Elements,_tp->transport_matrix, &_source, &_A, 0, 0, &_D, &_X, &_Y );
852       checkFinleyError();
853    
854       Finley_Assemble_PDE(mesh->Nodes,mesh->Elements,_tp->flux_matrix, &_source, 0, &_B, &_C, 0, 0, 0 );
855       checkFinleyError();
856    
857       Finley_Assemble_PDE(mesh->Nodes,mesh->FaceElements, _tp->transport_matrix, &_source, 0, 0, 0, &_d, 0, &_y );
858       checkFinleyError();
859    
860       Finley_Assemble_PDE(mesh->Nodes,mesh->ContactElements, _tp->transport_matrix, &_source , 0, 0, 0, &_d_contact, 0, &_y_contact );
861       checkFinleyError();
862    }
863    
864  //  //
865  // interpolates data between different function spaces:  // interpolates data between different function spaces:
# Line 454  void MeshAdapter::interpolateOnDomain(es Line 948  void MeshAdapter::interpolateOnDomain(es
948       case(Elements):       case(Elements):
949          if (target.getFunctionSpace().getTypeCode()==Elements) {          if (target.getFunctionSpace().getTypeCode()==Elements) {
950             Finley_Assemble_CopyElementData(mesh->Elements,&_target,&_in);             Finley_Assemble_CopyElementData(mesh->Elements,&_target,&_in);
951            } else if (target.getFunctionSpace().getTypeCode()==ReducedElements) {
952               Finley_Assemble_AverageElementData(mesh->Elements,&_target,&_in);
953          } else {          } else {
954             throw FinleyAdapterException("Error - No interpolation with data on elements possible.");             throw FinleyAdapterException("Error - No interpolation with data on elements possible.");
955          }          }
# Line 468  void MeshAdapter::interpolateOnDomain(es Line 964  void MeshAdapter::interpolateOnDomain(es
964       case(FaceElements):       case(FaceElements):
965          if (target.getFunctionSpace().getTypeCode()==FaceElements) {          if (target.getFunctionSpace().getTypeCode()==FaceElements) {
966             Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);             Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);
967            } else if (target.getFunctionSpace().getTypeCode()==ReducedFaceElements) {
968               Finley_Assemble_AverageElementData(mesh->FaceElements,&_target,&_in);
969          } else {          } else {
970             throw FinleyAdapterException("Error - No interpolation with data on face elements possible.");             throw FinleyAdapterException("Error - No interpolation with data on face elements possible.");
971         }          }
972         break;          break;
973       case(ReducedFaceElements):       case(ReducedFaceElements):
974          if (target.getFunctionSpace().getTypeCode()==FaceElements) {          if (target.getFunctionSpace().getTypeCode()==ReducedFaceElements) {
975             Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);             Finley_Assemble_CopyElementData(mesh->FaceElements,&_target,&_in);
976          } else {          } else {
977             throw FinleyAdapterException("Error - No interpolation with data on face elements with reduced integration order possible.");             throw FinleyAdapterException("Error - No interpolation with data on face elements with reduced integration order possible.");
# Line 490  void MeshAdapter::interpolateOnDomain(es Line 988  void MeshAdapter::interpolateOnDomain(es
988       case(ContactElementsOne):       case(ContactElementsOne):
989          if (target.getFunctionSpace().getTypeCode()==ContactElementsZero || target.getFunctionSpace().getTypeCode()==ContactElementsOne) {          if (target.getFunctionSpace().getTypeCode()==ContactElementsZero || target.getFunctionSpace().getTypeCode()==ContactElementsOne) {
990             Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);             Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);
991            } else if (target.getFunctionSpace().getTypeCode()==ReducedContactElementsZero || target.getFunctionSpace().getTypeCode()==ReducedContactElementsOne) {
992               Finley_Assemble_AverageElementData(mesh->ContactElements,&_target,&_in);
993          } else {          } else {
994             throw FinleyAdapterException("Error - No interpolation with data on contact elements possible.");             throw FinleyAdapterException("Error - No interpolation with data on contact elements possible.");
            break;  
995          }          }
996          break;          break;
997       case(ReducedContactElementsZero):       case(ReducedContactElementsZero):
# Line 501  void MeshAdapter::interpolateOnDomain(es Line 1000  void MeshAdapter::interpolateOnDomain(es
1000             Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);             Finley_Assemble_CopyElementData(mesh->ContactElements,&_target,&_in);
1001          } else {          } else {
1002             throw FinleyAdapterException("Error - No interpolation with data on contact elements with reduced integration order possible.");             throw FinleyAdapterException("Error - No interpolation with data on contact elements with reduced integration order possible.");
            break;  
1003          }          }
1004          break;          break;
1005       case(DegreesOfFreedom):             case(DegreesOfFreedom):      
1006          switch(target.getFunctionSpace().getTypeCode()) {          switch(target.getFunctionSpace().getTypeCode()) {
1007             case(ReducedDegreesOfFreedom):             case(ReducedDegreesOfFreedom):
1008             case(DegreesOfFreedom):             case(DegreesOfFreedom):
            case(Nodes):  
            case(ReducedNodes):  
1009                Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);                Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
1010                break;                break;
1011  #ifndef PASO_MPI  
1012             case(Elements):             case(Nodes):
1013             case(ReducedElements):             case(ReducedNodes):
1014                Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);                if (getMPISize()>1) {
1015                break;                    escript::Data temp=escript::Data(in);
1016             case(FaceElements):                    temp.expand();
1017             case(ReducedFaceElements):                    escriptDataC _in2 = temp.getDataC();
1018                Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);                    Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in2);
1019                break;                } else {
1020             case(Points):                    Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
1021                Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);                }
1022                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 */  
1023             case(Elements):             case(Elements):
1024             case(ReducedElements):             case(ReducedElements):
1025                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
1026                Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&(nodeTemp.getDataC()),&_target);                   escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1027                     escriptDataC _in2 = temp.getDataC();
1028                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in2,&_target);
1029                  } else {
1030                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
1031                  }
1032                break;                break;
1033             case(FaceElements):             case(FaceElements):
1034             case(ReducedFaceElements):             case(ReducedFaceElements):
1035                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
1036                Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&(nodeTemp.getDataC()),&_target);                   escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1037                     escriptDataC _in2 = temp.getDataC();
1038                     Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in2,&_target);
1039    
1040                  } else {
1041                     Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
1042                  }
1043                break;                break;
1044             case(Points):             case(Points):
1045                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
1046                Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&(nodeTemp.getDataC()),&_target);                   escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1047                     escriptDataC _in2 = temp.getDataC();
1048                  } else {
1049                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
1050                  }
1051                break;                break;
1052             case(ContactElementsZero):             case(ContactElementsZero):
1053             case(ContactElementsOne):             case(ContactElementsOne):
1054             case(ReducedContactElementsZero):             case(ReducedContactElementsZero):
1055             case(ReducedContactElementsOne):             case(ReducedContactElementsOne):
1056                escript::Data nodeTemp( in, continuousFunction(asAbstractContinuousDomain()) );                if (getMPISize()>1) {
1057                Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&(nodeTemp.getDataC()),&_target);                   escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1058                     escriptDataC _in2 = temp.getDataC();
1059                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in2,&_target);
1060                  } else {
1061                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
1062                  }
1063               break;               break;
 #endif  
1064             default:             default:
1065               stringstream temp;               stringstream temp;
1066               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 1074  void MeshAdapter::interpolateOnDomain(es
1074               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.");
1075               break;               break;
1076            case(ReducedNodes):            case(ReducedNodes):
1077               Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);                if (getMPISize()>1) {
1078               break;                    escript::Data temp=escript::Data(in);
1079                      temp.expand();
1080                      escriptDataC _in2 = temp.getDataC();
1081                      Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in2);
1082                  } else {
1083                      Finley_Assemble_CopyNodalData(mesh->Nodes,&_target,&_in);
1084                  }
1085                  break;
1086            case(DegreesOfFreedom):            case(DegreesOfFreedom):
1087               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");
1088               break;               break;
# Line 577  void MeshAdapter::interpolateOnDomain(es Line 1091  void MeshAdapter::interpolateOnDomain(es
1091               break;               break;
1092            case(Elements):            case(Elements):
1093            case(ReducedElements):            case(ReducedElements):
1094               Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);                if (getMPISize()>1) {
1095                     escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1096                     escriptDataC _in2 = temp.getDataC();
1097                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in2,&_target);
1098                  } else {
1099                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Elements,&_in,&_target);
1100                 }
1101               break;               break;
1102            case(FaceElements):            case(FaceElements):
1103            case(ReducedFaceElements):            case(ReducedFaceElements):
1104               Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);                if (getMPISize()>1) {
1105                     escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1106                     escriptDataC _in2 = temp.getDataC();
1107                     Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in2,&_target);
1108                  } else {
1109                     Finley_Assemble_interpolate(mesh->Nodes,mesh->FaceElements,&_in,&_target);
1110                  }
1111               break;               break;
1112            case(Points):            case(Points):
1113               Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);                if (getMPISize()>1) {
1114                     escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1115                     escriptDataC _in2 = temp.getDataC();
1116                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in2,&_target);
1117                  } else {
1118                     Finley_Assemble_interpolate(mesh->Nodes,mesh->Points,&_in,&_target);
1119                 }
1120               break;               break;
1121            case(ContactElementsZero):            case(ContactElementsZero):
1122            case(ContactElementsOne):            case(ContactElementsOne):
1123            case(ReducedContactElementsZero):            case(ReducedContactElementsZero):
1124            case(ReducedContactElementsOne):            case(ReducedContactElementsOne):
1125               Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);                if (getMPISize()>1) {
1126                     escript::Data temp=escript::Data( in,  continuousFunction(asAbstractContinuousDomain()) );
1127                     escriptDataC _in2 = temp.getDataC();
1128                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in2,&_target);
1129                  } else {
1130                     Finley_Assemble_interpolate(mesh->Nodes,mesh->ContactElements,&_in,&_target);
1131                 }
1132               break;               break;
1133            default:            default:
1134               stringstream temp;               stringstream temp;
# Line 707  void MeshAdapter::setToIntegrals(std::ve Line 1245  void MeshAdapter::setToIntegrals(std::ve
1245    if (argDomain!=*this)    if (argDomain!=*this)
1246       throw FinleyAdapterException("Error - Illegal domain of integration kernel");       throw FinleyAdapterException("Error - Illegal domain of integration kernel");
1247    
1248      double blocktimer_start = blocktimer_time();
1249    Finley_Mesh* mesh=m_finleyMesh.get();    Finley_Mesh* mesh=m_finleyMesh.get();
1250      escriptDataC _temp;
1251      escript::Data temp;
1252    escriptDataC _arg=arg.getDataC();    escriptDataC _arg=arg.getDataC();
1253    switch(arg.getFunctionSpace().getTypeCode()) {    switch(arg.getFunctionSpace().getTypeCode()) {
1254       case(Nodes):       case(Nodes):
1255          /* TODO */          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1256          throw FinleyAdapterException("Error - Integral of data on nodes is not supported.");          _temp=temp.getDataC();
1257            Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1258          break;          break;
1259       case(ReducedNodes):       case(ReducedNodes):
1260          /* TODO */          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1261          throw FinleyAdapterException("Error - Integral of data on reduced nodes is not supported.");          _temp=temp.getDataC();
1262            Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1263          break;          break;
1264       case(Elements):       case(Elements):
1265          Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);          Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);
1266          break;          break;
1267       case(ReducedElements):       case(ReducedElements):
1268          Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);          Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_arg,&integrals[0]);
1269            break;
1270       case(FaceElements):       case(FaceElements):
1271          Finley_Assemble_integrate(mesh->Nodes,mesh->FaceElements,&_arg,&integrals[0]);          Finley_Assemble_integrate(mesh->Nodes,mesh->FaceElements,&_arg,&integrals[0]);
1272          break;          break;
# Line 745  void MeshAdapter::setToIntegrals(std::ve Line 1289  void MeshAdapter::setToIntegrals(std::ve
1289          Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);          Finley_Assemble_integrate(mesh->Nodes,mesh->ContactElements,&_arg,&integrals[0]);
1290          break;          break;
1291       case(DegreesOfFreedom):       case(DegreesOfFreedom):
1292          throw FinleyAdapterException("Error - Integral of data on degrees of freedom is not supported.");          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1293            _temp=temp.getDataC();
1294            Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1295          break;          break;
1296       case(ReducedDegreesOfFreedom):       case(ReducedDegreesOfFreedom):
1297          throw FinleyAdapterException("Error - Integral of data on reduced degrees of freedom is not supported.");          temp=escript::Data( arg, function(asAbstractContinuousDomain()) );
1298            _temp=temp.getDataC();
1299            Finley_Assemble_integrate(mesh->Nodes,mesh->Elements,&_temp,&integrals[0]);
1300          break;          break;
1301       default:       default:
1302          stringstream temp;          stringstream temp;
# Line 757  void MeshAdapter::setToIntegrals(std::ve Line 1305  void MeshAdapter::setToIntegrals(std::ve
1305          break;          break;
1306    }    }
1307    checkFinleyError();    checkFinleyError();
1308      blocktimer_increment("integrate()", blocktimer_start);
1309  }  }
1310    
1311  //  //
# Line 774  void MeshAdapter::setToGradient(escript: Line 1323  void MeshAdapter::setToGradient(escript:
1323    Finley_Mesh* mesh=m_finleyMesh.get();    Finley_Mesh* mesh=m_finleyMesh.get();
1324    escriptDataC _grad=grad.getDataC();    escriptDataC _grad=grad.getDataC();
1325    escriptDataC nodeDataC;    escriptDataC nodeDataC;
1326  #ifdef PASO_MPI    escript::Data temp;
1327    escript::Data nodeTemp( arg, continuousFunction(asAbstractContinuousDomain()) );    if (getMPISize()>1) {
1328    if( arg.getFunctionSpace().getTypeCode() != Nodes )        if( arg.getFunctionSpace().getTypeCode() == DegreesOfFreedom ) {
1329    {          temp=escript::Data( arg,  continuousFunction(asAbstractContinuousDomain()) );
1330      Finley_Assemble_CopyNodalData(mesh->Nodes,&(nodeTemp.getDataC()),&(arg.getDataC()));          nodeDataC = temp.getDataC();
1331      nodeDataC = nodeTemp.getDataC();        } else if( arg.getFunctionSpace().getTypeCode() == ReducedDegreesOfFreedom ) {
1332            temp=escript::Data( arg,  reducedContinuousFunction(asAbstractContinuousDomain()) );
1333            nodeDataC = temp.getDataC();
1334          } else {
1335            nodeDataC = arg.getDataC();
1336          }
1337      } else {
1338         nodeDataC = arg.getDataC();
1339    }    }
   else  
     nodeDataC = arg.getDataC();  
 #else  
   nodeDataC = arg.getDataC();  
 #endif  
1340    switch(grad.getFunctionSpace().getTypeCode()) {    switch(grad.getFunctionSpace().getTypeCode()) {
1341         case(Nodes):         case(Nodes):
1342            throw FinleyAdapterException("Error - Gradient at nodes is not supported.");            throw FinleyAdapterException("Error - Gradient at nodes is not supported.");
# Line 916  void MeshAdapter::saveDX(const std::stri Line 1467  void MeshAdapter::saveDX(const std::stri
1467    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;    escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
1468    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;    escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
1469    
1470      boost::python::list keys=arg.keys();    boost::python::list keys=arg.keys();
1471      for (int i=0;i<num_data;++i) {    for (int i=0;i<num_data;++i) {
1472             std::string n=boost::python::extract<std::string>(keys[i]);
1473           escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);           escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1474           if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)           if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)
1475               throw FinleyAdapterException("Error  in saveDX: Data must be defined on same Domain");               throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");
1476           data[i]=d.getDataC();           data[i]=d.getDataC();
1477           ptr_data[i]=&(data[i]);           ptr_data[i]=&(data[i]);
          std::string n=boost::python::extract<std::string>(keys[i]);  
1478           c_names[i]=&(names[i][0]);           c_names[i]=&(names[i][0]);
1479           if (n.length()>MAX_namelength-1) {           if (n.length()>MAX_namelength-1) {
1480              strncpy(c_names[i],n.c_str(),MAX_namelength-1);              strncpy(c_names[i],n.c_str(),MAX_namelength-1);
# Line 966  void MeshAdapter::saveVTK(const std::str Line 1517  void MeshAdapter::saveVTK(const std::str
1517    
1518      boost::python::list keys=arg.keys();      boost::python::list keys=arg.keys();
1519      for (int i=0;i<num_data;++i) {      for (int i=0;i<num_data;++i) {
1520             std::string n=boost::python::extract<std::string>(keys[i]);
1521           escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);           escript::Data& d=boost::python::extract<escript::Data&>(arg[keys[i]]);
1522           if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)           if (dynamic_cast<const MeshAdapter&>(d.getFunctionSpace().getDomain()) !=*this)
1523               throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");               throw FinleyAdapterException("Error  in saveVTK: Data must be defined on same Domain");
1524           data[i]=d.getDataC();           data[i]=d.getDataC();
1525           ptr_data[i]=&(data[i]);           ptr_data[i]=&(data[i]);
          std::string n=boost::python::extract<std::string>(keys[i]);  
1526           c_names[i]=&(names[i][0]);           c_names[i]=&(names[i][0]);
1527           if (n.length()>MAX_namelength-1) {           if (n.length()>MAX_namelength-1) {
1528              strncpy(c_names[i],n.c_str(),MAX_namelength-1);              strncpy(c_names[i],n.c_str(),MAX_namelength-1);
# Line 980  void MeshAdapter::saveVTK(const std::str Line 1531  void MeshAdapter::saveVTK(const std::str
1531              strcpy(c_names[i],n.c_str());              strcpy(c_names[i],n.c_str());
1532           }           }
1533      }      }
 #ifndef PASO_MPI      
1534      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  
1535    
1536  checkFinleyError();    checkFinleyError();
1537    /* win32 refactor */    /* win32 refactor */
1538    TMPMEMFREE(c_names);    TMPMEMFREE(c_names);
1539    TMPMEMFREE(data);    TMPMEMFREE(data);
# Line 1037  SystemMatrixAdapter MeshAdapter::newSyst Line 1584  SystemMatrixAdapter MeshAdapter::newSyst
1584            
1585      Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceRowOrder,reduceColOrder);      Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceRowOrder,reduceColOrder);
1586      checkFinleyError();      checkFinleyError();
1587      Paso_SystemMatrix* fsystemMatrix=Paso_SystemMatrix_alloc(type,fsystemMatrixPattern,row_blocksize,column_blocksize);      Paso_SystemMatrix* fsystemMatrix;
1588        int trilinos = 0;
1589        if (trilinos) {
1590    #ifdef TRILINOS
1591          /* Allocation Epetra_VrbMatrix here */
1592    #endif
1593        }
1594        else {
1595          fsystemMatrix=Paso_SystemMatrix_alloc(type,fsystemMatrixPattern,row_blocksize,column_blocksize);
1596        }
1597      checkPasoError();      checkPasoError();
1598      Paso_SystemMatrixPattern_dealloc(fsystemMatrixPattern);      Paso_SystemMatrixPattern_free(fsystemMatrixPattern);
1599      return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);      return SystemMatrixAdapter(fsystemMatrix,row_blocksize,row_functionspace,column_blocksize,column_functionspace);
1600  }  }
1601    // creates a TransportProblemAdapter
1602    TransportProblemAdapter MeshAdapter::newTransportProblem(
1603                          const double theta,
1604                          const double dt_max,
1605                          const int blocksize,
1606                          const escript::FunctionSpace& functionspace,
1607                          const int type) const
1608    {
1609        int reduceOrder=0;
1610        // is the domain right?
1611        const MeshAdapter& domain=dynamic_cast<const MeshAdapter&>(functionspace.getDomain());
1612        if (domain!=*this)
1613              throw FinleyAdapterException("Error - domain of function space does not match the domain of transport problem generator.");
1614        // is the function space type right
1615        if (functionspace.getTypeCode()==DegreesOfFreedom) {
1616            reduceOrder=0;
1617        } else if (functionspace.getTypeCode()==ReducedDegreesOfFreedom) {
1618            reduceOrder=1;
1619        } else {
1620            throw FinleyAdapterException("Error - illegal function space type for system matrix rows.");
1621        }
1622        // generate matrix:
1623        
1624        Paso_SystemMatrixPattern* fsystemMatrixPattern=Finley_getPattern(getFinley_Mesh(),reduceOrder,reduceOrder);
1625        checkFinleyError();
1626        Paso_FCTransportProblem* transportProblem;
1627        transportProblem=Paso_FCTransportProblem_alloc(theta,dt_max,fsystemMatrixPattern,blocksize);
1628        checkPasoError();
1629        Paso_SystemMatrixPattern_free(fsystemMatrixPattern);
1630        return TransportProblemAdapter(transportProblem,theta,dt_max,blocksize,functionspace);
1631    }
1632    
1633  //  //
1634  // vtkObject MeshAdapter::createVtkObject() const  // vtkObject MeshAdapter::createVtkObject() const
# Line 1130  bool MeshAdapter::probeInterpolationOnDo Line 1717  bool MeshAdapter::probeInterpolationOnDo
1717       case(Elements):       case(Elements):
1718          if (functionSpaceType_target==Elements) {          if (functionSpaceType_target==Elements) {
1719             return true;             return true;
1720            } else if (functionSpaceType_target==ReducedElements) {
1721               return true;
1722          } else {          } else {
1723             return false;             return false;
1724          }          }
# Line 1142  bool MeshAdapter::probeInterpolationOnDo Line 1731  bool MeshAdapter::probeInterpolationOnDo
1731       case(FaceElements):       case(FaceElements):
1732          if (functionSpaceType_target==FaceElements) {          if (functionSpaceType_target==FaceElements) {
1733             return true;             return true;
1734            } else if (functionSpaceType_target==ReducedFaceElements) {
1735               return true;
1736          } else {          } else {
1737             return false;             return false;
1738          }          }
# Line 1161  bool MeshAdapter::probeInterpolationOnDo Line 1752  bool MeshAdapter::probeInterpolationOnDo
1752       case(ContactElementsOne):       case(ContactElementsOne):
1753          if (functionSpaceType_target==ContactElementsZero || functionSpaceType_target==ContactElementsOne) {          if (functionSpaceType_target==ContactElementsZero || functionSpaceType_target==ContactElementsOne) {
1754             return true;             return true;
1755            } else if (functionSpaceType_target==ReducedContactElementsZero || functionSpaceType_target==ReducedContactElementsOne) {
1756               return true;
1757          } else {          } else {
1758             return false;             return false;
1759          }          }
# Line 1274  int* MeshAdapter::borrowSampleReferenceI Line 1867  int* MeshAdapter::borrowSampleReferenceI
1867    Finley_Mesh* mesh=m_finleyMesh.get();    Finley_Mesh* mesh=m_finleyMesh.get();
1868    switch (functionSpaceType) {    switch (functionSpaceType) {
1869      case(Nodes):      case(Nodes):
1870        if (mesh->Nodes!=NULL) {        out=mesh->Nodes->Id;
1871          out=mesh->Nodes->Id;        break;
         break;  
       }  
1872      case(ReducedNodes):      case(ReducedNodes):
1873        throw FinleyAdapterException("Error -  ReducedNodes not supported yet.");        out=mesh->Nodes->reducedNodesId;
1874        break;        break;
1875      case(Elements):      case(Elements):
1876        out=mesh->FaceElements->Id;        out=mesh->Elements->Id;
1877        break;        break;
1878      case(ReducedElements):      case(ReducedElements):
1879        out=mesh->Elements->Id;        out=mesh->Elements->Id;
# Line 1309  int* MeshAdapter::borrowSampleReferenceI Line 1900  int* MeshAdapter::borrowSampleReferenceI
1900        out=mesh->ContactElements->Id;        out=mesh->ContactElements->Id;
1901        break;        break;
1902      case(DegreesOfFreedom):      case(DegreesOfFreedom):
1903        out=mesh->Nodes->degreeOfFreedomId;        out=mesh->Nodes->degreesOfFreedomId;
1904        break;        break;
1905      case(ReducedDegreesOfFreedom):      case(ReducedDegreesOfFreedom):
1906        out=mesh->Nodes->reducedDegreeOfFreedomId;        out=mesh->Nodes->reducedDegreesOfFreedomId;
1907        break;        break;
1908      default:      default:
1909        stringstream temp;        stringstream temp;

Legend:
Removed from v.1062  
changed lines
  Added in v.1388

  ViewVC Help
Powered by ViewVC 1.1.26