element.cpp 31.4 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
#include "inmost.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
2
#include <iomanip>
Kirill Terekhov's avatar
Kirill Terekhov committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#if defined(USE_MESH)
namespace INMOST
{

	const char * Element::GeometricTypeName(GeometricType t)
	{
		switch(t)
		{
			case Unset:        return "Unset";
			case Vertex:       return "Vertex";
			case Line:         return "Line";
			case MultiLine:    return "MultiLine";
			case Tri:          return "Tri";
			case Quad:         return "Quad";
			case Polygon:      return "Polygon";
			case MultiPolygon: return "MultiPolygon";
			case Tet:          return "Tet";
			case Hex:          return "Hex";
			case Prism:        return "Prism";
			case Pyramid:      return "Pyramid";
			case Polyhedron:   return "Polyhedron";
			case Set:          return "Set";
		};
		return "Unset";
	}
	
	
Kirill Terekhov's avatar
Kirill Terekhov committed
30
	Storage::integer Element::GetGeometricDimension(GeometricType m_type)
Kirill Terekhov's avatar
Kirill Terekhov committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	{
		switch(m_type)
		{
			case Vertex:		return 0;
			case Line:			return 1;
			case MultiLine:
			case Tri:
			case Quad: 			
			case Polygon:		return 2;
			case MultiPolygon:
			case Tet:
			case Hex:
			case Prism:
			case Pyramid:
			case Polyhedron:	return 3;
			default: return UINT_MAX;
		}
		return UINT_MAX;
	}
	
	const char * Element::StatusName(Status s)
	{
		switch(s)
		{
			case Owned:  return "Owned";
			case Shared: return "Shared";
			case Ghost:  return "Ghost";
		}
		return "Unknown";
	}
	
	
	
	
	
Kirill Terekhov's avatar
Kirill Terekhov committed
66
	Storage::enumerator Element::nbAdjElements(ElementType _etype)const 
Kirill Terekhov's avatar
Kirill Terekhov committed
67
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
68
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->nbAdjElements(_etype);
Kirill Terekhov's avatar
Kirill Terekhov committed
69
70
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
71
72
73
74
75
		Mesh * mesh = GetMeshLink();
		dynarray<HandleType,128> result;
		integer conn[4] = {0,0,0,0};
		integer myconn, i;
		enumerator ret = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
76
77
78
79
80
81
		
		for(ElementType e = NODE, i = 0; e <= CELL; i++, e = e << 1)
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
82
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
83
84
85
86
87
88
89
90
91
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					ret += 1;
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
92
					ret += static_cast<enumerator>(mesh->HighConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
93
94
95
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
96
					ret += static_cast<enumerator>(mesh->LowConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
97
98
99
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
100
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
101
102
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
103
104
105
106
107
108
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
109
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
110
111
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
112
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
113
114
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
115
116
117
					}
					else if( GetElementType() & FACE )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
118
						ret += static_cast<enumerator>(mesh->LowConn(GetHandle()).size());
Kirill Terekhov's avatar
Kirill Terekhov committed
119
120
121
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
122
123
124
125
126
127
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
128
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
129
130
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
131
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
132
133
						}		
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
134
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
135
136
137
138
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result[it],mrk);
					result.clear();
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
139
140
141
142
143
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
144
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
145
146
147
148
149
150
151
152
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					if( !GetMarker(hm) ) ret ++;
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
153
154
155
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( !mesh->GetMarker(hc[it],hm) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
156
157
158
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
159
160
161
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( !mesh->GetMarker(lc[it],hm) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
162
163
164
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
165
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
166
167
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
168
169
170
171
172
173
174
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
							{
								if( !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
175
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
176
177
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
178
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
179
180
181
							}
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
182
183
184
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
185
186
187
188
189
190
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
191
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
192
193
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
194
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
195
196
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
197
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
198
199
200
201
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result[it],mrk);
					result.clear();
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
202
203
204
205
206
				}
			}
		}
		return ret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
207
208


Kirill Terekhov's avatar
Kirill Terekhov committed
209
	Storage::enumerator Element::nbAdjElements(ElementType _etype, MarkerType mask, bool invert)const 
Kirill Terekhov's avatar
Kirill Terekhov committed
210
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
211
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->nbAdjElements(_etype,mask,invert);
Kirill Terekhov's avatar
Kirill Terekhov committed
212
213
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
214
215
216
217
218
		Mesh * mesh = GetMeshLink();
		dynarray<HandleType,128> result;
		integer conn[4] = {0,0,0,0};
		integer myconn, i;
		enumerator ret = 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
219
220
221
222
223
224
		
		for(ElementType e = NODE, i = 0; e <= CELL; i++, e = e << 1)
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
225
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
226
227
228
229
230
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
231
					if( invert ^ GetMarker(mask) ) ret += 1;
Kirill Terekhov's avatar
Kirill Terekhov committed
232
233
234
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
235
236
237
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it) 
						if( invert ^ mesh->GetMarker(hc[it],mask) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
238
239
240
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
241
242
243
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it) 
						if( invert ^ mesh->GetMarker(lc[it],mask) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
244
245
246
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
247
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
248
249
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
250
251
252
253
254
255
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
256
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
257
258
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
259
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
260
261
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
262
263
264
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
265
266
267
268
269
270
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
271
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
272
273
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
274
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
275
276
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
277
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
278
279
280
281
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result[it],mrk);
					result.clear();
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
282
283
284
285
286
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
287
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
288
289
290
291
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
292
					if( !GetMarker(hm) && (invert ^ GetMarker(mask)) ) ret ++;
Kirill Terekhov's avatar
Kirill Terekhov committed
293
294
295
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
296
297
298
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( !mesh->GetMarker(hc[it],hm) && (invert ^ mesh->GetMarker(hc[it],mask)) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
299
300
301
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
302
303
304
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( !mesh->GetMarker(lc[it],hm) && (invert ^ mesh->GetMarker(lc[it],mask)) ) ret++;
Kirill Terekhov's avatar
Kirill Terekhov committed
305
306
307
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
308
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
309
310
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
311
312
313
314
315
316
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
317
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
318
319
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
320
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
321
322
						}
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
323
324
325
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
326
327
328
329
330
331
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
332
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
333
334
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
335
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
336
337
						}		
						ret += static_cast<enumerator>(result.size());
Kirill Terekhov's avatar
Kirill Terekhov committed
338
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
339
340
341
342
					for(dynarray<HandleType,128>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result[it],mrk);
					result.clear();
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
343
344
345
346
347
				}
			}
		}
		return ret;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
348
	
Kirill Terekhov's avatar
Kirill Terekhov committed
349
	ElementArray<Element> Element::getAdjElements(ElementType _etype) const 
Kirill Terekhov's avatar
Kirill Terekhov committed
350
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
351
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->getAdjElements(_etype);
Kirill Terekhov's avatar
Kirill Terekhov committed
352
353
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
354
355
		INMOST::Mesh * mesh = GetMeshLink();
		ElementArray<Element> result(mesh);
Kirill Terekhov's avatar
Kirill Terekhov committed
356
357
358
359
360
361
362
363
364
		unsigned int conn[4] = {0,0,0,0};
		unsigned int myconn, i = 0;
		
		for(ElementType e = NODE; e <= CELL; e = e << 1)
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
			i++;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
365
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
366
367
368
369
370
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
371
					result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
372
373
374
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
375
376
					adj_type const & hc = mesh->HighConn(GetHandle());
					result.insert(result.end(),hc.begin(),hc.end());
Kirill Terekhov's avatar
Kirill Terekhov committed
377
378
379
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
380
381
					adj_type const & lc = mesh->LowConn(GetHandle());
					result.insert(result.end(),lc.begin(),lc.end());
Kirill Terekhov's avatar
Kirill Terekhov committed
382
383
384
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
385
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
386
387
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
388
389
390
391
392
393
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
394
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
395
396
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
397
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
398
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
399
400
401
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
402
403
404
405
406
407
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
408
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
409
410
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
411
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
412
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
413
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
414
415
416
					for(ElementArray<Element>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result.at(it),mrk);
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
417
418
419
420
421
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
422
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
423
424
425
426
427
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
					if( !GetMarker(hm) )
Kirill Terekhov's avatar
Kirill Terekhov committed
428
						result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
429
430
431
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
432
433
434
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( !mesh->GetMarker(hc[it],hm) ) result.push_back(hc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
435
436
437
438
					
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
439
440
441
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( !mesh->GetMarker(lc[it],hm) ) result.push_back(lc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
442
443
444
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
445
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
446
447
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
448
449
450
451
452
453
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
								if( !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
454
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
455
456
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
457
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
458
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
459
460
461
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
462
463
464
465
466
467
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt != ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
468
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
469
470
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
471
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
472
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
473
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
474
475
476
					for(ElementArray<Element>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result.at(it),mrk);
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
477
478
479
480
481
482
				}
			}
		}
		return result;
	}
	
Kirill Terekhov's avatar
Kirill Terekhov committed
483
	ElementArray<Element> Element::getAdjElements(ElementType _etype, MarkerType mask, bool invert) const 
Kirill Terekhov's avatar
Kirill Terekhov committed
484
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
485
		if( GetHandleElementType(GetHandle()) == ESET ) return getAsSet()->getAdjElements(_etype,mask,invert);
Kirill Terekhov's avatar
Kirill Terekhov committed
486
487
		assert( !(_etype & MESH) );
		assert( !(_etype & ESET) );
Kirill Terekhov's avatar
Kirill Terekhov committed
488
489
		INMOST::Mesh * mesh = GetMeshLink();
		ElementArray<Element> result(mesh);
Kirill Terekhov's avatar
Kirill Terekhov committed
490
491
492
493
494
495
496
497
498
		unsigned int conn[4] = {0,0,0,0};
		unsigned int myconn, i = 0;
		
		for(ElementType e = NODE; e <= CELL; e = e << 1)
		{
			if( _etype & e ) conn[i] = 1;
			if( GetElementType() & e ) myconn = i;
			i++;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
499
		if( !mesh->HideMarker() )
Kirill Terekhov's avatar
Kirill Terekhov committed
500
501
502
503
504
		{
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
505
					if( invert ^ GetMarker(mask) ) result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
506
507
508
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
509
510
511
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( invert ^ mesh->GetMarker(hc[it],mask) ) result.push_back(hc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
512
513
514
515
					
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
516
517
518
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( invert ^ mesh->GetMarker(lc[it],mask) ) result.push_back(lc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
519
520
521
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
522
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
523
524
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
525
526
527
528
529
530
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++)
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
531
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
532
533
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
534
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
535
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
536
537
538
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
539
540
541
542
543
544
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++)
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++)
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
545
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
546
547
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
548
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
549
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
550
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
551
552
553
					for(ElementArray<Element>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result.at(it),mrk);
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
554
555
556
557
558
				}
			}
		}
		else
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
559
			MarkerType hm = mesh->HideMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
560
561
562
563
			for(i = 0; i < 4; i++) if( conn[i] )
			{
				if( i == myconn )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
564
					if( !GetMarker(hm) && (invert ^ GetMarker(mask)) )
Kirill Terekhov's avatar
Kirill Terekhov committed
565
						result.push_back(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
566
567
568
				}
				else if( i == (myconn + 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
569
570
571
					adj_type const & hc = mesh->HighConn(GetHandle());
					for(adj_type::size_type it = 0; it < hc.size(); ++it)
						if( (invert ^ mesh->GetMarker(hc[it],mask)) && !mesh->GetMarker(hc[it],hm) ) result.push_back(hc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
572
573
574
575
					
				}
				else if( i == (myconn - 1 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
576
577
578
					adj_type const & lc = mesh->LowConn(GetHandle());
					for(adj_type::size_type it = 0; it < lc.size(); ++it)
						if( (invert ^ mesh->GetMarker(lc[it],mask)) && !mesh->GetMarker(lc[it],hm) ) result.push_back(lc[it]);
Kirill Terekhov's avatar
Kirill Terekhov committed
579
580
581
				}
				else if( i == (myconn - 2 + 4)%4 )
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
582
					MarkerType mrk = mesh->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
583
584
					if( (GetElementType() & NODE) || (GetElementType() & EDGE) )
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
585
586
587
588
589
590
						adj_type const & hc = mesh->HighConn(GetHandle());
						for(adj_type::size_type it = 0; it < hc.size(); it++) if( !mesh->GetMarker(hc[it],hm) )
						{
							adj_type const & ihc = mesh->HighConn(hc[it]);
							for(adj_type::size_type jt = 0; jt < ihc.size(); jt++) if( !mesh->GetMarker(ihc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ihc[jt],mask)) && !mesh->GetMarker(ihc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
591
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
592
593
									result.push_back(ihc[jt]);
									mesh->SetMarker(ihc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
594
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
595
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
596
597
598
					}
					else
					{
Kirill Terekhov's avatar
Kirill Terekhov committed
599
600
601
602
603
604
						adj_type const & lc = mesh->LowConn(GetHandle());
						for(adj_type::size_type it = 0; it < lc.size(); it++) if( !mesh->GetMarker(lc[it],hm) )
						{
							adj_type const & ilc = mesh->LowConn(lc[it]);
							for(adj_type::size_type jt = 0; jt < ilc.size(); jt++) if( !mesh->GetMarker(ilc[jt],hm) )
								if( (invert ^ mesh->GetMarker(ilc[jt],mask)) && !mesh->GetMarker(ilc[jt],mrk) )
Kirill Terekhov's avatar
Kirill Terekhov committed
605
								{
Kirill Terekhov's avatar
Kirill Terekhov committed
606
607
									result.push_back(ilc[jt]);
									mesh->SetMarker(ilc[jt],mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
608
								}
Kirill Terekhov's avatar
Kirill Terekhov committed
609
						}
Kirill Terekhov's avatar
Kirill Terekhov committed
610
					}
Kirill Terekhov's avatar
Kirill Terekhov committed
611
612
613
					for(ElementArray<Element>::size_type it = 0; it < result.size(); it++)
						mesh->RemMarker(result.at(it),mrk);
					mesh->ReleaseMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
614
615
616
617
618
				}
			}
		}
		return result;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
619
	
Kirill Terekhov's avatar
Kirill Terekhov committed
620
	ElementArray<Node> Element::getNodes() const
Kirill Terekhov's avatar
Kirill Terekhov committed
621
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
622
623
624
625
626
627
628
629
630
		switch(GetElementType())
		{
		case NODE: return ElementArray<Node>(GetMeshLink(),1,GetHandle());
		case EDGE: return getAsEdge()->getNodes();
		case FACE: return getAsFace()->getNodes();
		case CELL: return getAsCell()->getNodes();
		case ESET: return getAsSet()->getNodes();
		}
		return ElementArray<Node>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
631
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
632
	ElementArray<Edge> Element::getEdges() const
Kirill Terekhov's avatar
Kirill Terekhov committed
633
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
634
635
636
637
638
639
640
641
642
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getEdges();
		case EDGE: return ElementArray<Edge>(GetMeshLink(),1,GetHandle());
		case FACE: return getAsFace()->getEdges();
		case CELL: return getAsCell()->getEdges();
		case ESET: return getAsSet()->getEdges();
		}
		return ElementArray<Edge>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
643
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
644
	ElementArray<Face> Element::getFaces() const
Kirill Terekhov's avatar
Kirill Terekhov committed
645
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
646
647
648
649
650
651
652
653
654
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getFaces();
		case EDGE: return getAsEdge()->getFaces();
		case FACE: return ElementArray<Face>(GetMeshLink(),1,GetHandle());
		case CELL: return getAsCell()->getFaces();
		case ESET: return getAsSet()->getFaces();
		}
		return ElementArray<Face>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
655
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
656
	ElementArray<Cell> Element::getCells() const
Kirill Terekhov's avatar
Kirill Terekhov committed
657
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
658
659
660
661
662
663
664
665
666
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getCells();
		case EDGE: return getAsEdge()->getCells();
		case FACE: return getAsFace()->getCells();
		case CELL: return ElementArray<Cell>(GetMeshLink(),1,GetHandle());
		case ESET: return getAsSet()->getCells();
		}
		return ElementArray<Cell>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
667
668
	}
	
Kirill Terekhov's avatar
Kirill Terekhov committed
669
	ElementArray<Node> Element::getNodes(MarkerType mask,bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
670
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
671
672
673
674
675
676
677
678
679
		switch(GetElementType())
		{
		case NODE: return ElementArray<Node>(GetMeshLink(),invert ^ GetMarker(mask) ? 1 : 0,GetHandle());
		case EDGE: return getAsEdge()->getNodes(mask,invert);
		case FACE: return getAsFace()->getNodes(mask,invert);
		case CELL: return getAsCell()->getNodes(mask,invert);
		case ESET: return getAsSet()->getNodes(mask,invert);
		}
		return ElementArray<Node>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
680
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
681
	ElementArray<Edge> Element::getEdges(MarkerType mask,bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
682
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
683
684
685
686
687
688
689
690
691
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getEdges(mask,invert);
		case EDGE: return ElementArray<Edge>(GetMeshLink(),invert ^ GetMarker(mask) ? 1 : 0,GetHandle());
		case FACE: return getAsFace()->getEdges(mask,invert);
		case CELL: return getAsCell()->getEdges(mask,invert);
		case ESET: return getAsSet()->getEdges(mask,invert);
		}
		return ElementArray<Edge>(NULL);	
Kirill Terekhov's avatar
Kirill Terekhov committed
692
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
693
	ElementArray<Face> Element::getFaces(MarkerType mask,bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
694
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
695
696
697
698
699
700
701
702
703
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getFaces(mask,invert);
		case EDGE: return getAsEdge()->getFaces(mask,invert);
		case FACE: return ElementArray<Face>(GetMeshLink(),invert ^ GetMarker(mask) ? 1 : 0,GetHandle());
		case CELL: return getAsCell()->getFaces(mask,invert);
		case ESET: return getAsSet()->getFaces(mask,invert);
		}
		return ElementArray<Face>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
704
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
705
	ElementArray<Cell> Element::getCells(MarkerType mask,bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
706
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
707
708
709
710
711
712
713
714
715
		switch(GetElementType())
		{
		case NODE: return getAsNode()->getCells(mask,invert);
		case EDGE: return getAsEdge()->getCells(mask,invert);
		case FACE: return getAsFace()->getCells(mask,invert);
		case CELL: return ElementArray<Cell>(GetMeshLink(),invert ^ GetMarker(mask) ? 1 : 0,GetHandle());
		case ESET: return getAsSet()->getCells(mask,invert);
		}
		return ElementArray<Cell>(NULL);
Kirill Terekhov's avatar
Kirill Terekhov committed
716
717
	}
	
Kirill Terekhov's avatar
Kirill Terekhov committed
718
	bool Element::CheckElementConnectivity() const
Kirill Terekhov's avatar
Kirill Terekhov committed
719
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
		Mesh * mesh = GetMeshLink();
		HandleType me = GetHandle();
		adj_type const & hc = mesh->HighConn(GetHandle());
		for(adj_type::size_type jt = 0; jt < hc.size(); jt++) //iterate over upper adjacent
		{
			bool found = false;
			adj_type const & ilc = mesh->LowConn(hc[jt]);
			for(adj_type::size_type kt = 0; kt < ilc.size(); kt++) //search for the link to me
				if( ilc[kt] == me )
				{
					found = true;
					break;
				}
			if( !found ) return false;
		}
		adj_type const & lc = mesh->LowConn(GetHandle());
		for(adj_type::size_type jt = 0; jt < lc.size(); jt++) //iterate over lower adjacent
		{
			bool found = false;
			adj_type const & ihc = mesh->HighConn(lc[jt]);
			for(adj_type::size_type kt = 0; kt < ihc.size(); kt++) //search for the link to me
				if( ihc[kt] == me )
				{
					found = true;
					break;
				}
			if( !found ) return false;
		}
		return true;
Kirill Terekhov's avatar
Kirill Terekhov committed
749
750
	}

Kirill Terekhov's avatar
Kirill Terekhov committed
751
	void Element::PrintElementConnectivity() const
Kirill Terekhov's avatar
Kirill Terekhov committed
752
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
753
754
755
756
757
758
759
		Mesh * mesh = GetMeshLink();
		HandleType me = GetHandle();
		std::cout << "Element " << ElementTypeName(GetElementType()) << " " << LocalID() << std::endl;

		adj_type const & hc = mesh->HighConn(GetHandle());
		std::cout << "Upper adjacencies (" << hc.size() << "):" << std::endl;
		for(adj_type::size_type jt = 0; jt < hc.size(); jt++) //iterate over upper adjacent
Kirill Terekhov's avatar
Kirill Terekhov committed
760
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
761
762
763
764
765
			std::cout << "[" << std::setw(3) << jt << "] " << ElementTypeName(GetHandleElementType(hc[jt])) << " " << GetHandleID(hc[jt]) << " lower ";
			bool found = false;
			adj_type const & ilc = mesh->LowConn(hc[jt]);
			std::cout << "(" << ilc.size() << "): ";
			for(adj_type::size_type kt = 0; kt < ilc.size(); kt++) //search for the link to me
Kirill Terekhov's avatar
Kirill Terekhov committed
766
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
767
768
				std::cout << ElementTypeName(GetHandleElementType(ilc[kt])) << " " << GetHandleID(ilc[kt]) << " ";
				if( ilc[kt] == me ) found = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
769
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
770
771
			if( !found ) std::cout << " no me here! ";
			std::cout << std::endl;
Kirill Terekhov's avatar
Kirill Terekhov committed
772
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
773
774
775
		adj_type const & lc = mesh->LowConn(GetHandle());
		std::cout << "Lower adjacencies (" << lc.size() << "):" << std::endl;
		for(adj_type::size_type jt = 0; jt < lc.size(); jt++) //iterate over lower adjacent
Kirill Terekhov's avatar
Kirill Terekhov committed
776
		{
Kirill Terekhov's avatar
Kirill Terekhov committed
777
778
779
780
781
			std::cout << "[" <<  std::setw(3) <<  jt << "] " << ElementTypeName(GetHandleElementType(lc[jt])) << " " << GetHandleID(lc[jt]) << " higher ";
			bool found = false;
			adj_type const & ihc = mesh->HighConn(lc[jt]);
			std::cout << "(" << ihc.size() << "): ";
			for(adj_type::size_type kt = 0; kt < ihc.size(); kt++) //search for the link to me
Kirill Terekhov's avatar
Kirill Terekhov committed
782
			{
Kirill Terekhov's avatar
Kirill Terekhov committed
783
784
				std::cout << ElementTypeName(GetHandleElementType(ihc[kt])) << " " << GetHandleID(ihc[kt]) << " ";
				if( ihc[kt] == me ) found = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
785
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
786
787
			if( !found ) std::cout << " no me here! ";
			std::cout << std::endl;
Kirill Terekhov's avatar
Kirill Terekhov committed
788
789
790
791
792
793
794
795
796
797
798
799
		}
	}
	
	bool Element::CheckConnectivity(Mesh * m)
	{
		for(Mesh::iteratorElement it = m->BeginElement(CELL | FACE | EDGE | NODE); it != m->EndElement(); it++)
			if( !it->CheckElementConnectivity() ) return false;
		return true;
	}
	
	
	
Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
800
	ElementArray<Element> Element::BridgeAdjacencies(ElementType Bridge, ElementType Dest, MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
801
802
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
803
		MarkerType mrk = m->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
804
805
806
807
808
809
810
811
		ElementArray<Element> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(Dest);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetMarker(mrk);
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++)
		{
			ElementArray<Element> sub = it->getAdjElements(Dest);
			for(ElementArray<Element>::iterator jt = sub.begin(); jt != sub.end(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
812
				if( !jt->GetMarker(mrk) && (mask == 0 || (invert ^ jt->GetMarker(mask))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
813
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
814
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
815
816
817
					jt->SetMarker(mrk);
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
818
819
		for(ElementArray<Element>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
820
821
822
823
824
		m->ReleaseMarker(mrk);
		return adjcells;
	}


Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
825
	ElementArray<Node> Element::BridgeAdjacencies2Node(ElementType Bridge, MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
826
827
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
828
		MarkerType mrk = m->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
829
830
831
832
833
834
835
836
		ElementArray<Node> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(NODE);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetMarker(mrk);
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++)
		{
			ElementArray<Node> sub = it->getNodes();
			for(ElementArray<Node>::iterator jt = sub.begin(); jt != sub.end(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
837
				if( !jt->GetMarker(mrk) && (mask == 0 || (invert ^ jt->GetMarker(mask))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
838
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
839
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
840
841
842
					jt->SetMarker(mrk);
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
843
844
		for(ElementArray<Node>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
845
846
847
848
		m->ReleaseMarker(mrk);
		return adjcells;
	}

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
849
	ElementArray<Edge> Element::BridgeAdjacencies2Edge(ElementType Bridge, MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
850
851
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
852
		MarkerType mrk = m->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
853
854
855
856
857
858
859
860
		ElementArray<Edge> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(EDGE);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetMarker(mrk);
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++)
		{
			ElementArray<Edge> sub = it->getEdges();
			for(ElementArray<Edge>::iterator jt = sub.begin(); jt != sub.end(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
861
				if( !jt->GetMarker(mrk) && (mask == 0 || (invert ^ jt->GetMarker(mask))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
862
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
863
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
864
865
866
					jt->SetMarker(mrk);
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
867
868
		for(ElementArray<Edge>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
869
870
871
872
		m->ReleaseMarker(mrk);
		return adjcells;
	}

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
873
	ElementArray<Face> Element::BridgeAdjacencies2Face(ElementType Bridge, MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
874
875
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
876
		MarkerType mrk = m->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
877
878
879
880
881
882
883
884
		ElementArray<Face> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(FACE);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetMarker(mrk);
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++)
		{
			ElementArray<Face> sub = it->getFaces();
			for(ElementArray<Face>::iterator jt = sub.begin(); jt != sub.end(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
885
				if( !jt->GetMarker(mrk) && (mask == 0 || (invert ^ jt->GetMarker(mask))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
886
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
887
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
888
889
890
					jt->SetMarker(mrk);
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
891
892
		for(ElementArray<Face>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
893
894
895
896
		m->ReleaseMarker(mrk);
		return adjcells;
	}

Kirill Terekhov's avatar
Fixes    
Kirill Terekhov committed
897
	ElementArray<Cell> Element::BridgeAdjacencies2Cell(ElementType Bridge, MarkerType mask, bool invert) const
Kirill Terekhov's avatar
Kirill Terekhov committed
898
899
	{
		Mesh * m = GetMeshLink();
Kirill Terekhov's avatar
Kirill Terekhov committed
900
		MarkerType mrk = m->CreateMarker();
Kirill Terekhov's avatar
Kirill Terekhov committed
901
902
903
904
905
906
907
908
		ElementArray<Cell> adjcells(m);
		ElementArray<Element> adjfaces = getAdjElements(Bridge);
		ElementArray<Element> my = Bridge & GetElementType() ? ElementArray<Element>(m) : getAdjElements(CELL);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->SetMarker(mrk);
		for(ElementArray<Element>::iterator it = adjfaces.begin(); it != adjfaces.end(); it++)
		{
			ElementArray<Cell> sub = it->getCells();
			for(ElementArray<Cell>::iterator jt = sub.begin(); jt != sub.end(); jt++)
Kirill Terekhov's avatar
Kirill Terekhov committed
909
				if( !jt->GetMarker(mrk) && (mask == 0 || (invert ^ jt->GetMarker(mask))) )
Kirill Terekhov's avatar
Kirill Terekhov committed
910
				{
Kirill Terekhov's avatar
Kirill Terekhov committed
911
					adjcells.push_back(*jt);
Kirill Terekhov's avatar
Kirill Terekhov committed
912
913
914
					jt->SetMarker(mrk);
				}
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
915
916
		for(ElementArray<Cell>::iterator it = adjcells.begin(); it != adjcells.end(); it++) it->RemMarker(mrk);
		for(ElementArray<Element>::iterator it = my.begin(); it != my.end(); it++) it->RemMarker(mrk);
Kirill Terekhov's avatar
Kirill Terekhov committed
917
918
919
920
921
		m->ReleaseMarker(mrk);
		return adjcells;
	}


Kirill Terekhov's avatar
Kirill Terekhov committed
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
	Element::Status Element::GetStatus() const
	{
		assert(isValid());
		return GetMeshLink()->GetStatus(GetHandle());
	}
	void Element::SetStatus(Status status) const
	{
		GetMeshLink()->SetStatus(GetHandle(),status);
	}
	Storage::integer & Element::GlobalID() const
	{
		return GetMeshLink()->GlobalID(GetHandle());
	}
	void Element::Centroid  (Storage::real * cnt) const
	{
		GetMeshLink()->GetGeometricData(GetHandle(),CENTROID,cnt);
	}
	void Element::Barycenter(Storage::real * cnt) const
	{
		GetMeshLink()->GetGeometricData(GetHandle(),BARYCENTER,cnt);
	}
	/*
Kirill Terekhov's avatar
Kirill Terekhov committed
944
945
	Element::adj_type &       Element::HighConn() 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
946
947
		assert(isValid()); 
		return GetMeshLink()->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
948
949
950
	}
	Element::adj_type &       Element::LowConn () 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
951
952
		assert(isValid()); 
		return GetMeshLink()->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
953
954
955
	}
	Element::adj_type const & Element::HighConn() const 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
956
957
		assert(isValid()); 
		return GetMeshLink()->HighConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
958
959
960
	}
	Element::adj_type const & Element::LowConn () const 
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
961
962
		assert(isValid()); 
		return GetMeshLink()->LowConn(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
963
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
964
965
	*/
	Element::GeometricType Element::GetGeometricType() const 
Kirill Terekhov's avatar
Kirill Terekhov committed
966
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
967
968
		assert(isValid()); 
		return GetMeshLink()->GetGeometricType(GetHandle());
Kirill Terekhov's avatar
Kirill Terekhov committed
969
970
971
	}
	void Element::SetGeometricType(GeometricType t)
	{
Kirill Terekhov's avatar
Kirill Terekhov committed
972
973
		assert(isValid()); 
		GetMeshLink()->SetGeometricType(GetHandle(),t); 
Kirill Terekhov's avatar
Kirill Terekhov committed
974
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
975

Kirill Terekhov's avatar
Kirill Terekhov committed
976
	
Kirill Terekhov's avatar
Kirill Terekhov committed
977

Kirill Terekhov's avatar
Kirill Terekhov committed
978
979
}
#endif