/[escript]/trunk/dataexporter/src/NodeData.cpp
ViewVC logotype

Annotation of /trunk/dataexporter/src/NodeData.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2183 - (hide annotations)
Fri Dec 19 03:52:50 2008 UTC (10 years, 9 months ago) by caltinay
Original Path: trunk/tools/libescriptreader/src/escriptreader/Mesh.cpp
File size: 2711 byte(s)
Added escriptreader library with tools. For more information refer to README
file or wait for user documentation.

1 caltinay 2183
2     /*******************************************************
3     *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14     //
15     // Mesh.cpp
16     //
17     #include <escriptreader/Mesh.h>
18     #include <escriptreader/ElementData.h>
19     #include <netcdf.hh>
20     #if HAVE_SILO
21     #include <silo.h>
22     #endif
23    
24     using namespace std;
25    
26     //
27     //
28     //
29     Mesh::Mesh(CoordArray c, int nDims, int nNodes) :
30     coords(c), numDims(nDims), numNodes(nNodes), name("Mesh")
31     {
32     }
33    
34     //
35     //
36     //
37     Mesh::Mesh(const Mesh& m)
38     {
39     numDims = m.numDims;
40     numNodes = m.numNodes;
41     nodeID = m.nodeID;
42     nodeID2idx = m.nodeID2idx;
43     name = m.name;
44     siloPath = m.siloPath;
45     for (int i=0; i<numDims; i++) {
46     float* c = new float[numNodes];
47     copy(m.coords[i], m.coords[i]+numNodes, c);
48     coords.push_back(c);
49     }
50     }
51    
52     //
53     //
54     //
55     Mesh::~Mesh()
56     {
57     CoordArray::iterator it;
58     for (it = coords.begin(); it != coords.end(); it++)
59     delete[] *it;
60     }
61    
62     //
63     //
64     //
65     bool Mesh::readFromNc(const string& ncFile)
66     {
67     NcError ncerr(NcError::silent_nonfatal);
68     NcFile* input;
69     NcAtt* att;
70     NcVar* var;
71    
72     input = new NcFile(ncFile.c_str());
73     if (!input->is_valid()) {
74     cerr << "Could not open input file " << ncFile.c_str() << ".\n";
75     delete input;
76     return false;
77     }
78    
79     att = input->get_att("numDim");
80     numDims = att->as_int(0);
81    
82     att = input->get_att("numNodes");
83     numNodes = att->as_int(0);
84    
85     coords.clear();
86     var = input->get_var("Nodes_Coordinates");
87     for (int i=0; i<numDims; i++) {
88     float* c = new float[numNodes];
89     var->set_cur(0, i);
90     var->get(c, numNodes, 1);
91     coords.push_back(c);
92     }
93    
94     nodeID.clear();
95     nodeID.insert(nodeID.end(), numNodes, 0);
96     var = input->get_var("Nodes_Id");
97     var->get(&nodeID[0], numNodes);
98    
99     buildIndexMap();
100    
101     delete input;
102     return true;
103     }
104    
105     //
106     //
107     //
108     bool Mesh::writeToSilo(DBfile* dbfile, const string& pathInSilo)
109     {
110     #if HAVE_SILO
111     int ret;
112    
113     if (pathInSilo != "") {
114     siloPath = pathInSilo;
115     ret = DBSetDir(dbfile, siloPath.c_str());
116     if (ret != 0)
117     return false;
118     } else {
119     siloPath = "/";
120     }
121    
122     // Write node-centered variable
123     ret = DBPutUcdvar1(dbfile, "Nodes_Id", getFullSiloName().c_str(),
124     (float*)&nodeID[0], numNodes, NULL, 0, DB_INT, DB_NODECENT, NULL);
125    
126     DBSetDir(dbfile, "/");
127     return (ret == 0);
128    
129     #else // !HAVE_SILO
130     return false;
131     #endif
132     }
133    

  ViewVC Help
Powered by ViewVC 1.1.26