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

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

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

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

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

30
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Polygon(const unsigned int nodesPerElement)
31
{
32 33 34 35 36 37 38 39 40
	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;
41 42
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

133
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_24()
134
{
135 136
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(24, "Hexahedron_24", Quadratic));
	return p;
137 138
}

139
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_27()
140
{
141 142
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(27, "Hexahedron_27", Quadratic));
	return p;
143 144
}

145
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_64()
146
{
147 148
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(64, "Hexahedron_64", Cubic));
	return p;
149 150
}

151 152 153 154 155 156
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_64_GLL()
{
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(64, "Hexahedron_64_GLL", Cubic));
	return p;
}

157 158 159 160 161 162
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_125()
{
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(125, "Hexahedron_125", Quartic));
	return p;
}

163 164 165 166 167 168
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Hexahedron_125_GLL()
{
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(125, "Hexahedron_125_GLL", Quartic));
	return p;
}

169
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Mixed()
170
{
171 172
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "Mixed", Arbitrary));
	return p;
173 174
}

175
/*
176
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDSMesh()
177
{
178 179
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DSMesh", Structured));
	return p;
180 181
}

182
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDRectMesh()
183
{
184 185
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DRectMesh", Structured));
	return p;
186 187
}

188
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDCoRectMesh()
189
{
190 191
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DCoRectMesh", Structured));
	return p;
192 193
}

194
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDSMesh()
195
{
196 197
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DSMesh", Structured));
	return p;
198 199
}

200
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDRectMesh()
201
{
202 203
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DRectMesh", Structured));
	return p;
204 205
}

206
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh()
207
{
208 209
	static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DCoRectMesh", Structured));
	return p;
210
}*/
211

212
XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement, const std::string & name, const CellType cellType) :
213
	mCellType(cellType),
214
	mName(name),
215
	mNodesPerElement(nodesPerElement)
216 217
{
}
218

219 220 221 222
XdmfTopologyType::~XdmfTopologyType()
{
}

223
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
224
{
225 226 227 228 229 230
	std::map<std::string, std::string>::const_iterator type = itemProperties.find("Type");
	if(type == itemProperties.end())
	{
		type = itemProperties.find("TopologyType");
	}

231 232 233
	std::map<std::string, std::string>::const_iterator nodesPerElement = itemProperties.find("NodesPerElement");
	if(type != itemProperties.end())
	{
234 235 236
		std::string typeVal = type->second;
		std::transform(typeVal.begin(), typeVal.end(), typeVal.begin(), (int(*)(int))std::toupper);
		if(typeVal.compare("NOTOPOLOGY") == 0)
237 238 239
		{
			return NoTopologyType();
		}
240
		else if(typeVal.compare("POLYVERTEX") == 0)
241 242 243
		{
			return Polyvertex();
		}
244
		else if(typeVal.compare("POLYLINE") == 0)
245 246 247
		{
			return Polyline();
		}
248
		else if(typeVal.compare("POLYGON") == 0)
249 250 251 252 253 254 255
		{
			if(nodesPerElement != itemProperties.end())
			{
				return Polygon(atoi(nodesPerElement->second.c_str()));
			}
			assert(false);
		}
256
		else if(typeVal.compare("TRIANGLE") == 0)
257 258 259
		{
			return Triangle();
		}
260
		else if(typeVal.compare("QUADRILATERAL") == 0)
261 262 263
		{
			return Quadrilateral();
		}
264
		else if(typeVal.compare("TETRAHEDRON") == 0)
265 266 267
		{
			return Tetrahedron();
		}
268
		else if(typeVal.compare("PYRAMID") == 0)
269 270 271
		{
			return Pyramid();
		}
272
		else if(typeVal.compare("WEDGE") == 0)
273 274 275
		{
			return Wedge();
		}
276
		else if(typeVal.compare("HEXAHEDRON") == 0)
277 278 279
		{
			return Hexahedron();
		}
280
		else if(typeVal.compare("EDGE_3") == 0)
281 282 283
		{
			return Edge_3();
		}
284
		else if(typeVal.compare("TRIANGLE_6") == 0)
285 286 287
		{
			return Triangle_6();
		}
288
		else if(typeVal.compare("QUADRILATERAL_8") == 0)
289 290 291
		{
			return Quadrilateral_8();
		}
292
		else if(typeVal.compare("TETRAHEDRON_10") == 0)
293 294 295
		{
			return Tetrahedron_10();
		}
296
		else if(typeVal.compare("PYRAMID_13") == 0)
297 298 299
		{
			return Pyramid_13();
		}
300
		else if(typeVal.compare("WEDGE_15") == 0)
301 302 303
		{
			return Wedge_15();
		}
304
		else if(typeVal.compare("HEXAHEDRON_20") == 0)
305 306 307
		{
			return Hexahedron_20();
		}
308
		else if(typeVal.compare("HEXAHEDRON_24") == 0)
309 310 311
		{
			return Hexahedron_24();
		}
312
		else if(typeVal.compare("HEXAHEDRON_27") == 0)
313 314 315
		{
			return Hexahedron_27();
		}
316
		else if(typeVal.compare("HEXAHEDRON_64") == 0)
317 318 319
		{
			return Hexahedron_64();
		}
320
		else if(typeVal.compare("MIXED") == 0)
321 322 323
		{
			return Mixed();
		}
324
		/*else if(typeVal.compare("2DSMESH") == 0)
325 326 327
		{
			return TwoDSMesh();
		}
328
		else if(typeVal.compare("2DRECTMESH") == 0)
329 330
		{
			return TwoDRectMesh();
331
		}
332
		else if(typeVal.compare("2DCORECTMESH") == 0 || typeVal.compare("3DCORECTMESH") == 0)
333
		{
334 335 336
			// Special case --- Regular Grid
			boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "REGULAR", Structured));
			return p;
337
		}
338
		else if(typeVal.compare("3DSMESH") == 0)
339 340 341
		{
			return ThreeDSMesh();
		}
342
		else if(typeVal.compare("3DRECTMESH") == 0)
343 344
		{
			return ThreeDRectMesh();
345
		}*/
346 347 348 349 350 351 352 353
		else
		{
			assert(false);
		}
	}
	assert(false);
}

354 355 356 357 358 359 360 361 362 363
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);
}

364 365 366 367 368 369 370 371 372 373 374
bool XdmfTopologyType::IsEqual(boost::shared_ptr<XdmfTopologyType> topologyType)
{
        if(topologyType == NULL) return false;
        if(this == topologyType.get()
	   &&   mNodesPerElement == topologyType->mNodesPerElement
	   &&	mCellType == topologyType->mCellType
           &&   mName == topologyType->mName
        ) return true;
        return false;
}

375
XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
376
{
377
	return mCellType;
378 379
}

380 381 382 383 384
std::string XdmfTopologyType::getName() const
{
	return mName;
}

385
unsigned int XdmfTopologyType::getNodesPerElement() const
386
{
387
	return mNodesPerElement;
388
}
389 390 391

void XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
392
	collectedProperties["Type"] = this->getName();
393
	if(mName.compare("Polygon") == 0)
394
	{
395 396 397
		std::stringstream nodesPerElement;
		nodesPerElement << mNodesPerElement;
		collectedProperties["NodesPerElement"] = nodesPerElement.str();
398 399
	}
}