XdmfTopologyType.cpp 9.48 KB
Newer Older
1
2
3
4
5
6
7
/*
 * XdmfTopologyType.cpp
 *
 *  Created on: Jan 29, 2010
 *      Author: kleiter
 */

8
#include <map>
9
#include <sstream>
10
11
12
#include "XdmfTopologyType.hpp"

// Supported XdmfTopologyTypes
13
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::NoTopologyType()
14
{
15
16
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "NoTopology", NoCellType));
	return p;
17
18
}

19
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Polyvertex()
20
{
21
22
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "Polyvertex", Linear));
	return p;
23
24
}

25
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Polyline()
26
{
27
28
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "Polyline", Linear));
	return p;
29
30
}

31
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Polygon(const unsigned int nodesPerElement)
32
{
33
34
35
36
37
38
39
40
41
	static std::map<unsigned int, boost::shared_ptr<const XdmfTopologyType> > previousTypes;
	std::map<unsigned int, boost::shared_ptr<const XdmfTopologyType> >::const_iterator type = previousTypes.find(nodesPerElement);
	if(type != previousTypes.end())
	{
		return type->second;
	}
	boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(nodesPerElement, "Polygon", Linear));
	previousTypes[nodesPerElement] = p;
	return p;
42
43
}

44
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Triangle()
45
{
46
47
	boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(3, "Triangle", Linear));
	return p;
48
49
}

50
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Quadrilateral()
51
{
52
53
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(4, "Quadrilateral", Linear));
	return p;
54
55
}

56
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Tetrahedron()
57
{
58
59
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(4, "Tetrahedron", Linear));
	return p;
60
61
}

62
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Pyramid()
63
{
64
65
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(5, "Pyramid", Linear));
	return p;
66
67
}

68
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Wedge()
69
{
70
71
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(6, "Wedge", Linear));
	return p;
72
73
}

74
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron()
75
{
76
77
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(8, "Hexahedron", Linear));
	return p;
78
79
}

80
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Edge_3()
81
{
82
83
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(3, "Edge_3", Quadratic));
	return p;
84
85
}

86
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Triangle_6()
87
{
88
89
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(6, "Triangle_6", Quadratic));
	return p;
90
91
}

92
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Quadrilateral_8()
93
{
94
95
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(8, "Quadrilateral_8", Quadratic));
	return p;
96
97
}

98
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Tetrahedron_10()
99
{
100
101
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(10, "Tetrahedron_10", Quadratic));
	return p;
102
103
}

104
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Pyramid_13()
105
{
106
107
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(13, "Pyramid_13", Quadratic));
	return p;
108
109
}

110
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Wedge_15()
111
{
112
113
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(15, "Wedge_15", Quadratic));
	return p;
114
115
}

116
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_20()
117
{
118
119
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(20, "Hexahedron_20", Quadratic));
	return p;
120
121
}

122
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_24()
123
{
124
125
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(24, "Hexahedron_24", Quadratic));
	return p;
126
127
}

128
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_27()
129
{
130
131
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(27, "Hexahedron_27", Quadratic));
	return p;
132
133
}

134
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_64()
135
{
136
137
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(64, "Hexahedron_64", Cubic));
	return p;
138
139
}

140
141
142
143
144
145
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_125()
{
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(125, "Hexahedron_125", Quartic));
	return p;
}

146
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Mixed()
147
{
148
149
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "Mixed", Arbitrary));
	return p;
150
151
}

152
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDSMesh()
153
{
154
155
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DSMesh", Structured));
	return p;
156
157
}

158
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDRectMesh()
159
{
160
161
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DRectMesh", Structured));
	return p;
162
163
}

164
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDCoRectMesh()
165
{
166
167
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DCoRectMesh", Structured));
	return p;
168
169
}

170
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDSMesh()
171
{
172
173
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DSMesh", Structured));
	return p;
174
175
}

176
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDRectMesh()
177
{
178
179
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DRectMesh", Structured));
	return p;
180
181
}

182
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh()
183
{
184
185
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DCoRectMesh", Structured));
	return p;
186
187
188
189
190
191
}

XdmfTopologyType::XdmfTopologyType(const int& nodesPerElement, const std::string& name, const CellType& cellType) :
	mNodesPerElement(nodesPerElement),
	mName(name),
	mCellType(cellType)
192
193
{
}
194

195
196
197
198
XdmfTopologyType::~XdmfTopologyType()
{
}

199
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{
	std::map<std::string, std::string>::const_iterator type = itemProperties.find("TopologyType");
	std::map<std::string, std::string>::const_iterator nodesPerElement = itemProperties.find("NodesPerElement");
	if(type != itemProperties.end())
	{
		const std::string typeVal = type->second;
		if(typeVal.compare("NoTopology") == 0)
		{
			return NoTopologyType();
		}
		else if(typeVal.compare("Polyvertex") == 0)
		{
			return Polyvertex();
		}
		else if(typeVal.compare("Polyline") == 0)
		{
			return Polyline();
		}
		else if(typeVal.compare("Polygon") == 0)
		{
			if(nodesPerElement != itemProperties.end())
			{
				return Polygon(atoi(nodesPerElement->second.c_str()));
			}
			assert(false);
		}
		else if(typeVal.compare("Triangle") == 0)
		{
			return Triangle();
		}
		else if(typeVal.compare("Quadrilateral") == 0)
		{
			return Quadrilateral();
		}
		else if(typeVal.compare("Tetrahedron") == 0)
		{
			return Tetrahedron();
		}
		else if(typeVal.compare("Pyramid") == 0)
		{
			return Pyramid();
		}
		else if(typeVal.compare("Wedge") == 0)
		{
			return Wedge();
		}
		else if(typeVal.compare("Hexahedron") == 0)
		{
			return Hexahedron();
		}
		else if(typeVal.compare("Edge_3") == 0)
		{
			return Edge_3();
		}
		else if(typeVal.compare("Triangle_6") == 0)
		{
			return Triangle_6();
		}
		else if(typeVal.compare("Quadrilateral_8") == 0)
		{
			return Quadrilateral_8();
		}
		else if(typeVal.compare("Tetrahedron_10") == 0)
		{
			return Tetrahedron_10();
		}
		else if(typeVal.compare("Pyramid_13") == 0)
		{
			return Pyramid_13();
		}
		else if(typeVal.compare("Wedge_15") == 0)
		{
			return Wedge_15();
		}
		else if(typeVal.compare("Hexahedron_20") == 0)
		{
			return Hexahedron_20();
		}
278
279
280
281
282
283
284
285
286
287
288
289
		else if(typeVal.compare("Hexahedron_24") == 0)
		{
			return Hexahedron_24();
		}
		else if(typeVal.compare("Hexahedron_27") == 0)
		{
			return Hexahedron_27();
		}
		else if(typeVal.compare("Hexahedron_64") == 0)
		{
			return Hexahedron_64();
		}
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
		else if(typeVal.compare("Mixed") == 0)
		{
			return Mixed();
		}
		else if(typeVal.compare("2DSMesh") == 0)
		{
			return TwoDSMesh();
		}
		else if(typeVal.compare("2DRectMesh") == 0)
		{
			return TwoDRectMesh();
		}
		else if(typeVal.compare("2DCoRectMesh") == 0)
		{
			return TwoDCoRectMesh();
		}
		else if(typeVal.compare("3DSMesh") == 0)
		{
			return ThreeDSMesh();
		}
		else if(typeVal.compare("3DRectMesh") == 0)
		{
			return ThreeDRectMesh();
		}
		else if(typeVal.compare("3DCoRectMesh") == 0)
		{
			return ThreeDCoRectMesh();
		}
		else
		{
			assert(false);
		}
	}
	assert(false);
}

326
327
328
329
330
331
332
333
334
335
bool XdmfTopologyType::operator==(const XdmfTopologyType& topologyType) const
{
	return mNodesPerElement == topologyType.mNodesPerElement && mName.compare(topologyType.mName) == 0 && mCellType == topologyType.mCellType;
}

bool XdmfTopologyType::operator!=(const XdmfTopologyType& topologyType) const
{
	return !this->operator==(topologyType);
}

336
XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
337
{
338
	return mCellType;
339
340
}

341
unsigned int XdmfTopologyType::getNodesPerElement() const
342
{
343
	return mNodesPerElement;
344
}
345
346
347

void XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
348
	collectedProperties["TopologyType"] = mName;
349
	if(mName.compare("Polygon") == 0)
350
	{
351
352
353
		std::stringstream nodesPerElement;
		nodesPerElement << mNodesPerElement;
		collectedProperties["NodesPerElement"] = nodesPerElement.str();
354
355
	}
}