XdmfTopologyType.cpp 8.54 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
XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement, const std::string & name, const CellType cellType) :
176
	mCellType(cellType),
177
	mName(name),
178
	mNodesPerElement(nodesPerElement)
179 180
{
}
181

182 183 184 185
XdmfTopologyType::~XdmfTopologyType()
{
}

186
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
187
{
188 189 190 191 192 193
	std::map<std::string, std::string>::const_iterator type = itemProperties.find("Type");
	if(type == itemProperties.end())
	{
		type = itemProperties.find("TopologyType");
	}

194 195 196
	std::map<std::string, std::string>::const_iterator nodesPerElement = itemProperties.find("NodesPerElement");
	if(type != itemProperties.end())
	{
197 198 199
		std::string typeVal = type->second;
		std::transform(typeVal.begin(), typeVal.end(), typeVal.begin(), (int(*)(int))std::toupper);
		if(typeVal.compare("NOTOPOLOGY") == 0)
200 201 202
		{
			return NoTopologyType();
		}
203
		else if(typeVal.compare("POLYVERTEX") == 0)
204 205 206
		{
			return Polyvertex();
		}
207
		else if(typeVal.compare("POLYLINE") == 0)
208 209 210
		{
			return Polyline();
		}
211
		else if(typeVal.compare("POLYGON") == 0)
212 213 214 215 216 217 218
		{
			if(nodesPerElement != itemProperties.end())
			{
				return Polygon(atoi(nodesPerElement->second.c_str()));
			}
			assert(false);
		}
219
		else if(typeVal.compare("TRIANGLE") == 0)
220 221 222
		{
			return Triangle();
		}
223
		else if(typeVal.compare("QUADRILATERAL") == 0)
224 225 226
		{
			return Quadrilateral();
		}
227
		else if(typeVal.compare("TETRAHEDRON") == 0)
228 229 230
		{
			return Tetrahedron();
		}
231
		else if(typeVal.compare("PYRAMID") == 0)
232 233 234
		{
			return Pyramid();
		}
235
		else if(typeVal.compare("WEDGE") == 0)
236 237 238
		{
			return Wedge();
		}
239
		else if(typeVal.compare("HEXAHEDRON") == 0)
240 241 242
		{
			return Hexahedron();
		}
243
		else if(typeVal.compare("EDGE_3") == 0)
244 245 246
		{
			return Edge_3();
		}
247
		else if(typeVal.compare("TRIANGLE_6") == 0)
248 249 250
		{
			return Triangle_6();
		}
251
		else if(typeVal.compare("QUADRILATERAL_8") == 0)
252 253 254
		{
			return Quadrilateral_8();
		}
255
		else if(typeVal.compare("TETRAHEDRON_10") == 0)
256 257 258
		{
			return Tetrahedron_10();
		}
259
		else if(typeVal.compare("PYRAMID_13") == 0)
260 261 262
		{
			return Pyramid_13();
		}
263
		else if(typeVal.compare("WEDGE_15") == 0)
264 265 266
		{
			return Wedge_15();
		}
267
		else if(typeVal.compare("HEXAHEDRON_20") == 0)
268 269 270
		{
			return Hexahedron_20();
		}
271
		else if(typeVal.compare("HEXAHEDRON_24") == 0)
272 273 274
		{
			return Hexahedron_24();
		}
275
		else if(typeVal.compare("HEXAHEDRON_27") == 0)
276 277 278
		{
			return Hexahedron_27();
		}
279
		else if(typeVal.compare("HEXAHEDRON_64") == 0)
280 281 282
		{
			return Hexahedron_64();
		}
283
		else if(typeVal.compare("MIXED") == 0)
284 285 286 287 288 289 290 291 292 293 294
		{
			return Mixed();
		}
		else
		{
			assert(false);
		}
	}
	assert(false);
}

295
XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
296
{
297
	return mCellType;
298 299
}

300 301 302 303 304
std::string XdmfTopologyType::getName() const
{
	return mName;
}

305
unsigned int XdmfTopologyType::getNodesPerElement() const
306
{
307
	return mNodesPerElement;
308
}
309 310 311

void XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
312
	collectedProperties["Type"] = this->getName();
313
	if(mName.compare("Polygon") == 0)
314
	{
315 316 317
		std::stringstream nodesPerElement;
		nodesPerElement << mNodesPerElement;
		collectedProperties["NodesPerElement"] = nodesPerElement.str();
318 319
	}
}