11 |
* |
* |
12 |
*******************************************************/ |
*******************************************************/ |
13 |
|
|
14 |
// |
#ifndef __NODEDATA_H__ |
15 |
// Mesh.h |
#define __NODEDATA_H__ |
|
// |
|
|
#ifndef __MESH_H__ |
|
|
#define __MESH_H__ |
|
16 |
|
|
17 |
#include <escriptreader/common.h> |
#include <escriptexport/escriptexport.h> |
18 |
|
|
19 |
class DBfile; |
class DBfile; |
20 |
|
class NcFile; |
21 |
|
struct Finley_NodeFile; |
22 |
|
|
23 |
namespace EscriptReader { |
namespace escriptexport { |
|
|
|
|
class ElementData; |
|
24 |
|
|
25 |
/// \brief |
/// \brief |
26 |
class Mesh |
class NodeData |
27 |
{ |
{ |
28 |
public: |
public: |
29 |
/// \brief Constructor with mesh coordinates, dimensionality and size. |
/// \brief Constructor with mesh name. |
30 |
Mesh(CoordArray c, int nDims, int nNodes); |
ESCRIPTEXPORT_DLL_API |
31 |
|
NodeData(const std::string& meshName); |
32 |
|
|
33 |
|
ESCRIPTEXPORT_DLL_API |
34 |
|
NodeData(NodeData_ptr fullNodes, IntVec& requiredNodes, |
35 |
|
const std::string& meshName); |
36 |
|
|
37 |
/// \brief Copy constructor. |
/// \brief Copy constructor. |
38 |
Mesh(const Mesh& m); |
ESCRIPTEXPORT_DLL_API |
39 |
|
NodeData(const NodeData& m); |
40 |
|
|
41 |
/// \brief Virtual destructor |
/// \brief Virtual destructor |
42 |
virtual ~Mesh(); |
ESCRIPTEXPORT_DLL_API |
43 |
|
virtual ~NodeData(); |
44 |
|
|
45 |
virtual bool readFromNc(const std::string& ncFile); |
/// \brief Initialises with finley node file. |
46 |
virtual bool writeToSilo(DBfile* dbfile, const std::string& pathInSilo); |
ESCRIPTEXPORT_DLL_API |
47 |
|
bool initFromFinley(const Finley_NodeFile* finleyFile); |
48 |
|
|
49 |
|
/// \brief Reads node data from a NetCDF file. |
50 |
|
ESCRIPTEXPORT_DLL_API |
51 |
|
bool readFromNc(NcFile* ncFile); |
52 |
|
|
53 |
|
/// \brief Writes node data to a Silo file. |
54 |
|
ESCRIPTEXPORT_DLL_API |
55 |
|
bool writeToSilo(DBfile* dbfile); |
56 |
|
|
57 |
|
/// \brief Sets the silo path to be used when saving. |
58 |
|
ESCRIPTEXPORT_DLL_API |
59 |
|
void setSiloPath(const std::string& path) { siloPath = path; } |
60 |
|
|
61 |
|
/// \brief Returns an array of nodal data by the given name. |
62 |
|
/// |
63 |
|
/// The name must be one of the names returned by getVarNames(). |
64 |
|
ESCRIPTEXPORT_DLL_API |
65 |
|
const IntVec& getVarDataByName(const std::string& name) const; |
66 |
|
|
67 |
|
/// \brief Returns a vector with the mesh variable names. |
68 |
|
ESCRIPTEXPORT_DLL_API |
69 |
|
StringVec getVarNames() const; |
70 |
|
|
71 |
void setName(const std::string& n) { name = n; } |
/// \brief Returns the name of this node mesh. |
72 |
|
ESCRIPTEXPORT_DLL_API |
73 |
std::string getName() const { return name; } |
std::string getName() const { return name; } |
74 |
|
|
75 |
void setSiloPath(const std::string& p) { siloPath = p; } |
/// \brief Returns full Silo mesh name, e.g. "/block0000/Nodes". |
76 |
std::string getSiloPath() const { return siloPath; } |
ESCRIPTEXPORT_DLL_API |
|
|
|
|
/// \brief Returns full Silo mesh name, e.g. "/block0000/Elements". |
|
77 |
std::string getFullSiloName() const; |
std::string getFullSiloName() const; |
78 |
|
|
79 |
|
/// \brief Returns the node ID array. |
80 |
|
ESCRIPTEXPORT_DLL_API |
81 |
const IntVec& getNodeIDs() const { return nodeID; } |
const IntVec& getNodeIDs() const { return nodeID; } |
|
void setNodeIDs(const IntVec& ids) { nodeID = ids; } |
|
82 |
|
|
83 |
const IndexMap& getIndexMap() const { return nodeID2idx; } |
/// \brief Returns a node ID to index mapping for this mesh. |
84 |
void setIndexMap(const IndexMap& map) { nodeID2idx = map; } |
ESCRIPTEXPORT_DLL_API |
85 |
|
IndexMap getIndexMap() const; |
86 |
|
|
87 |
/// \brief Returns an array with the coordinates of the mesh nodes. |
/// \brief Returns the coordinates of the mesh nodes. |
88 |
|
ESCRIPTEXPORT_DLL_API |
89 |
const CoordArray& getCoords() const { return coords; } |
const CoordArray& getCoords() const { return coords; } |
90 |
|
|
91 |
/// \brief Returns the dimensionality of this mesh (2 or 3). |
/// \brief Returns the dimensionality of this mesh (2 or 3). |
92 |
|
ESCRIPTEXPORT_DLL_API |
93 |
int getNumDims() const { return numDims; } |
int getNumDims() const { return numDims; } |
94 |
|
|
95 |
/// \brief Returns the number of mesh nodes. |
/// \brief Returns the number of mesh nodes. |
96 |
|
ESCRIPTEXPORT_DLL_API |
97 |
int getNumNodes() const { return numNodes; } |
int getNumNodes() const { return numNodes; } |
98 |
|
|
99 |
protected: |
/// \brief Removes "ghost" nodes. |
100 |
/// \brief Protected default constructor. |
ESCRIPTEXPORT_DLL_API |
101 |
Mesh() {} |
void removeGhostNodes(int ownIndex); |
|
|
|
|
void buildIndexMap(); |
|
102 |
|
|
103 |
CoordArray coords; /// x, y[, z] coordinates of mesh nodes |
protected: |
104 |
int numDims; /// dimensionality of mesh (2 or 3) |
CoordArray coords; /// x, y[, z] coordinates of nodes |
105 |
int numNodes; /// number of mesh nodes |
int numDims; /// dimensionality (2 or 3) |
106 |
IntVec nodeID; /// node IDs |
int numNodes; /// number of nodes |
107 |
IndexMap nodeID2idx; /// mapping of node ID -> array index |
IntVec nodeID; /// node IDs |
108 |
std::string name; /// the name of this mesh |
IntVec nodeTag, nodeGDOF, nodeGNI, nodeGRDFI, nodeGRNI; |
109 |
std::string siloPath; /// absolute path in Silo file |
IntVec nodeDist; /// node distribution |
110 |
|
std::string name; /// the name of this node mesh |
111 |
|
std::string siloPath; /// the path to this mesh within the SILO file |
112 |
}; |
}; |
113 |
|
|
114 |
|
|
115 |
inline void Mesh::buildIndexMap() |
inline IndexMap NodeData::getIndexMap() const |
116 |
{ |
{ |
117 |
nodeID2idx.clear(); |
IndexMap nodeID2idx; |
118 |
int idx = 0; |
int idx = 0; |
119 |
IntVec::const_iterator idIt; |
IntVec::const_iterator idIt; |
120 |
for (idIt = nodeID.begin(); idIt != nodeID.end(); idIt++, idx++) |
for (idIt = nodeID.begin(); idIt != nodeID.end(); idIt++, idx++) |
121 |
nodeID2idx[*idIt] = idx; |
nodeID2idx[*idIt] = idx; |
122 |
|
return nodeID2idx; |
123 |
} |
} |
124 |
|
|
125 |
inline std::string Mesh::getFullSiloName() const |
inline std::string NodeData::getFullSiloName() const |
126 |
{ |
{ |
127 |
if (siloPath == "/") |
std::string result(siloPath); |
128 |
return siloPath + name; |
if (result.length() == 0 || *result.rbegin() != '/') |
129 |
else |
result += '/'; |
130 |
return siloPath + std::string("/") + name; |
result += name; |
131 |
|
return result; |
132 |
} |
} |
133 |
|
|
134 |
} // namespace EscriptReader |
} // namespace escriptexport |
135 |
|
|
136 |
#endif // __MESH_H__ |
#endif // __NODEDATA_H__ |
137 |
|
|