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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2187 - (hide annotations)
Tue Dec 23 04:13:15 2008 UTC (10 years, 9 months ago) by caltinay
Original Path: trunk/tools/libescriptreader/src/escriptreader/Mesh.cpp
File size: 2768 byte(s)
Moved escriptreader related classes into own namespace.

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 caltinay 2187 namespace EscriptReader {
27    
28 caltinay 2183 //
29     //
30     //
31     Mesh::Mesh(CoordArray c, int nDims, int nNodes) :
32     coords(c), numDims(nDims), numNodes(nNodes), name("Mesh")
33     {
34     }
35    
36     //
37     //
38     //
39     Mesh::Mesh(const Mesh& m)
40     {
41     numDims = m.numDims;
42     numNodes = m.numNodes;
43     nodeID = m.nodeID;
44     nodeID2idx = m.nodeID2idx;
45     name = m.name;
46     siloPath = m.siloPath;
47     for (int i=0; i<numDims; i++) {
48     float* c = new float[numNodes];
49     copy(m.coords[i], m.coords[i]+numNodes, c);
50     coords.push_back(c);
51     }
52     }
53    
54     //
55     //
56     //
57     Mesh::~Mesh()
58     {
59     CoordArray::iterator it;
60     for (it = coords.begin(); it != coords.end(); it++)
61     delete[] *it;
62     }
63    
64     //
65     //
66     //
67     bool Mesh::readFromNc(const string& ncFile)
68     {
69     NcError ncerr(NcError::silent_nonfatal);
70     NcFile* input;
71     NcAtt* att;
72     NcVar* var;
73    
74     input = new NcFile(ncFile.c_str());
75     if (!input->is_valid()) {
76     cerr << "Could not open input file " << ncFile.c_str() << ".\n";
77     delete input;
78     return false;
79     }
80    
81     att = input->get_att("numDim");
82     numDims = att->as_int(0);
83    
84     att = input->get_att("numNodes");
85     numNodes = att->as_int(0);
86    
87     coords.clear();
88     var = input->get_var("Nodes_Coordinates");
89     for (int i=0; i<numDims; i++) {
90     float* c = new float[numNodes];
91     var->set_cur(0, i);
92     var->get(c, numNodes, 1);
93     coords.push_back(c);
94     }
95    
96     nodeID.clear();
97     nodeID.insert(nodeID.end(), numNodes, 0);
98     var = input->get_var("Nodes_Id");
99     var->get(&nodeID[0], numNodes);
100    
101     buildIndexMap();
102    
103     delete input;
104     return true;
105     }
106    
107     //
108     //
109     //
110     bool Mesh::writeToSilo(DBfile* dbfile, const string& pathInSilo)
111     {
112     #if HAVE_SILO
113     int ret;
114    
115     if (pathInSilo != "") {
116     siloPath = pathInSilo;
117     ret = DBSetDir(dbfile, siloPath.c_str());
118     if (ret != 0)
119     return false;
120     } else {
121     siloPath = "/";
122     }
123    
124     // Write node-centered variable
125     ret = DBPutUcdvar1(dbfile, "Nodes_Id", getFullSiloName().c_str(),
126     (float*)&nodeID[0], numNodes, NULL, 0, DB_INT, DB_NODECENT, NULL);
127    
128     DBSetDir(dbfile, "/");
129     return (ret == 0);
130    
131     #else // !HAVE_SILO
132     return false;
133     #endif
134     }
135    
136 caltinay 2187 } // namespace EscriptReader
137    

  ViewVC Help
Powered by ViewVC 1.1.26