marker.cc 20 KB
Newer Older
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1
2
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
30
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**********************************************************************************
 * Copyright 2010 Christoph Pflaum 
 * 		Department Informatik Lehrstuhl 10 - Systemsimulation
 *		Friedrich-Alexander Universität Erlangen-Nürnberg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **********************************************************************************/

// #include <assert.h>
#include "../mympi.h"
#include "../abbrevi.h"
#include "../parameter.h"
#include "../math_lib/math_lib.h"
#include "../basics/basic.h"
#include "elements.h"
#include "parti.h"
#include "ug.h"
#include "blockgrid.h"
#include "marker.h"
#include <stdexcept>
#include <vector>

Marker::Marker ( Unstructured_grid* ug_ ) {
	ug = ug_;
	marker_hexahedra = new marker_typ[ug->Give_number_hexahedra() ];    // num_hexahedra
	marker_quadrangles = new marker_typ[ug->Give_number_quadrangles() ]; // num_quadrangles
	marker_edges = new marker_typ[ug->Give_number_edges() ];            // num_edges
	marker_points = new marker_typ[ug->Give_number_points() ];          // num_points

	on();
}

void Marker::on() {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, yes_mark );
}

void Marker::off() {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, no_mark );
}

void Marker::Mark_hexahedra_only( void ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, no_mark );
}

void Marker::Mark_quadrangles_only( void ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, yes_mark );
}

void Marker::Mark_edges_only( void ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, no_mark );
}

void Marker::Mark_points_only( void ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, no_mark );

	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, yes_mark );

	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, no_mark );
}

void Marker::Unmark_hexahedra( void ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
		Set_marker<hexahedronEl> ( id, no_mark );
}

void Marker::Unmark_quadrangles( void ) {
	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
		Set_marker<quadrangleEl> ( id, no_mark );

}
void Marker::Unmark_edges( void ) {
	for ( int id=0; id<ug->Give_number_edges(); ++id )
		Set_marker<edgeEl> ( id, no_mark );
}
void Marker::Unmark_points( void ) {
	for ( int id=0; id<ug->Give_number_points(); ++id )
		Set_marker<pointEl> ( id, no_mark );
}


// Marks hexaeder and adjacent elements.
void Marker::selectHexBlock ( unsigned int chosenHexBlock ) {
	if ( ( int ) chosenHexBlock >= ug->Give_number_hexahedra() )
		throw ( std::runtime_error ( std::string ( "Marker::selectHexBlock(): Selected block does not exist" ) ) );
//   cout << "select Block " << chosenHexBlock << endl;
	Set_marker<hexahedronEl> ( chosenHexBlock, yes_mark );

	Hexahedron_el* pHex = ug->Give_hexahedron ( chosenHexBlock );

	for ( int i=0; i<12; ++i ) {
		Set_marker<edgeEl> ( pHex->Give_id_edge ( ( Edges_cell ) i ), yes_mark );
	}

	for ( int i=0; i<6; ++i ) {
		Set_marker<quadrangleEl> ( pHex->Give_id_quadrangle ( ( dir3D ) i ), yes_mark );
	}
	for ( int i=0; i<3; ++i ) {
		Set_marker<pointEl> ( pHex->Give_id_corner ( ( dir3D_sons ) i ), yes_mark );
	}
}

// Marks hexaeder and adjacent elements.
void Marker::selectSingleHexBlock ( unsigned int chosenHexBlock ) {
	this->off();
	selectHexBlock(chosenHexBlock);
}


void Marker::selectHexBlocks ( unsigned int firstBlock, unsigned int numBlocks) {
	this->off();
	for ( unsigned int i = 0; i < numBlocks; ++i ) {
		selectHexBlock(firstBlock+i);
179
    }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
180
181
}

182

Phillip Lino Rall's avatar
Phillip Lino Rall committed
183
184
185
186
187
188
189
190
191
192
void Marker::selectHexBlocks ( std::vector<unsigned int> & chosenHexBlocks ) {
	this->off();
	for ( unsigned int count = 0;
	        count <chosenHexBlocks.size();
	        ++count ) {
		unsigned chosenBlock = chosenHexBlocks.at ( count );
		selectHexBlock(chosenBlock);
	}
}

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
void Marker::selectQuad(unsigned int chosenQuad)
{
    if ( ( int ) chosenQuad >= ug->Give_number_quadrangles() )
        throw ( std::runtime_error ( std::string ( "Marker::selectQuad(): Selected quad does not exist" ) ) );
    Set_marker<quadrangleEl> ( chosenQuad, yes_mark );


}

void Marker::selectSingleQuad(unsigned int chosenQuad)
{
    this->off();
    selectQuad(chosenQuad);
}

void Marker::selectQuads(unsigned int firstQuad, unsigned int numQuads)
{
    this->off();
    for ( unsigned int i = 0; i < numQuads; ++i ) {
        selectQuad(firstQuad+i);
    }
}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
278
279
280
281
282
283
284
285
286
287
288
289
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
void Marker::operatorAnd(Marker *mark)
{
    for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
    {
        if (Give_marker<hexahedronEl> ( id ) == mark->Give_marker<hexahedronEl> ( id ))
        {
            //Set_marker<hexahedronEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<hexahedronEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_edges(); ++id )
    {
        if (Give_marker<edgeEl> ( id ) == mark->Give_marker<edgeEl> ( id ))
        {
            //Set_marker<edgeEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<edgeEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_points(); ++id )
    {
        if (Give_marker<pointEl> ( id ) == mark->Give_marker<pointEl> ( id ))
        {
            //Set_marker<pointEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<pointEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
    {
        if (Give_marker<quadrangleEl> ( id ) == mark->Give_marker<quadrangleEl> ( id ))
        {
            //Set_marker<quadrangleEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<quadrangleEl> ( id, no_mark );
        }
    }
}

void Marker::operatorOr(Marker *mark)
{

    for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
    {
        if (Give_marker<hexahedronEl> ( id ) != mark->Give_marker<hexahedronEl> ( id ) || Give_marker<hexahedronEl> ( id ) == yes_mark)
        {
            Set_marker<hexahedronEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<hexahedronEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_edges(); ++id )
    {
        if (Give_marker<edgeEl> ( id ) != mark->Give_marker<edgeEl> ( id ) || Give_marker<edgeEl> ( id ) == yes_mark)
        {
            Set_marker<edgeEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<edgeEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_points(); ++id )
    {
        if (Give_marker<pointEl> ( id ) != mark->Give_marker<pointEl> ( id ) || Give_marker<pointEl> ( id ) == yes_mark)
        {
            Set_marker<pointEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<pointEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
    {
        if (Give_marker<quadrangleEl> ( id ) != mark->Give_marker<quadrangleEl> ( id ) || Give_marker<quadrangleEl> ( id ) == yes_mark)
        {
            Set_marker<quadrangleEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<quadrangleEl> ( id, no_mark );
        }
    }
}


void Marker::operatorXOr(Marker *mark)
{

    for ( int id=0; id<ug->Give_number_hexahedra(); ++id )
    {
        if (Give_marker<hexahedronEl> ( id ) != mark->Give_marker<hexahedronEl> ( id ))
        {
            Set_marker<hexahedronEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<hexahedronEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_edges(); ++id )
    {
        if (Give_marker<edgeEl> ( id ) != mark->Give_marker<edgeEl> ( id ))
        {
            Set_marker<edgeEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<edgeEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_points(); ++id )
    {
        if (Give_marker<pointEl> ( id ) != mark->Give_marker<pointEl> ( id ))
        {
            Set_marker<pointEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<pointEl> ( id, no_mark );
        }
    }

    for ( int id=0; id<ug->Give_number_quadrangles(); ++id )
    {
        if (Give_marker<quadrangleEl> ( id ) != mark->Give_marker<quadrangleEl> ( id ))
        {
            Set_marker<quadrangleEl> ( id, yes_mark );
        }
        else
        {
            Set_marker<quadrangleEl> ( id, no_mark );
        }
    }
}


void Marker::complement ( Marker* marker ) {
    for ( int id=0; id<ug->Give_number_hexahedra(); ++id ) {
        if ( marker->Give_marker<hexahedronEl> ( id ) == no_mark )
            Set_marker<hexahedronEl> ( id, yes_mark );
        else Set_marker<hexahedronEl> ( id, no_mark );
    }
    for ( int id=0; id<ug->Give_number_quadrangles(); ++id ) {
        if ( marker->Give_marker<quadrangleEl> ( id ) == no_mark )
            Set_marker<quadrangleEl> ( id, yes_mark );
        else Set_marker<quadrangleEl> ( id, no_mark );
    }
    for ( int id=0; id<ug->Give_number_edges(); ++id ) {
        if ( marker->Give_marker<edgeEl> ( id ) == no_mark )
            Set_marker<edgeEl> ( id, yes_mark );
        else Set_marker<edgeEl> ( id, no_mark );
    }
    for ( int id=0; id<ug->Give_number_points(); ++id ) {
        if ( marker->Give_marker<pointEl> ( id ) == no_mark )
            Set_marker<pointEl> ( id, yes_mark );
        else Set_marker<pointEl> ( id, no_mark );
    }
}


void Marker::interior_boundary ( Marker* marker ) {
  // kopieren
  for ( int id=0; id<ug->Give_number_hexahedra(); ++id ) {
     if ( marker->Give_marker<hexahedronEl> ( id ) == no_mark )
    Set_marker<hexahedronEl> ( id, no_mark );
     else Set_marker<hexahedronEl> ( id, yes_mark );
  }
    for ( int id=0; id<ug->Give_number_quadrangles(); ++id ) {
        if ( marker->Give_marker<quadrangleEl> ( id ) == no_mark )
            Set_marker<quadrangleEl> ( id, no_mark );
        else Set_marker<quadrangleEl> ( id, yes_mark );
    }
    for ( int id=0; id<ug->Give_number_edges(); ++id ) {
        if ( marker->Give_marker<edgeEl> ( id ) == no_mark )
            Set_marker<edgeEl> ( id, no_mark );
        else Set_marker<edgeEl> ( id, yes_mark );
    }
    for ( int id=0; id<ug->Give_number_points(); ++id ) {
        if ( marker->Give_marker<pointEl> ( id ) == no_mark )
            Set_marker<pointEl> ( id, no_mark );
        else Set_marker<pointEl> ( id, yes_mark );
    }


  //aendern
  for ( int id_quad=0; id_quad<ug->Give_number_quadrangles(); ++id_quad ) {
     if ( marker->Give_marker<quadrangleEl> ( id_quad ) == no_mark ) {

       for(int e=0;e < 4;++e) {
          Set_marker<edgeEl> (ug->Give_quadrangle ( id_quad )->Give_id_edge ( (dir2D)e ),
                   no_mark );
       }
       for(int c=0;c < 4;++c) {
          Set_marker<pointEl> (ug->Give_quadrangle ( id_quad )->Give_id_corner ( (dir2D_sons)c ),
                no_mark );
       }
     }
  }
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
Marker::~Marker() {
	if ( marker_hexahedra != NULL )
		delete [] marker_hexahedra;
	marker_hexahedra = NULL;
	if ( marker_quadrangles != NULL )
		delete [] marker_quadrangles;
	marker_quadrangles = NULL;
	if ( marker_edges != NULL )
		delete [] marker_edges;
	marker_edges = NULL;
	if ( marker_points != NULL )
		delete [] marker_points;
	marker_points = NULL;
}

Boundary_Marker::Boundary_Marker ( Unstructured_grid* ug_ ) : Marker ( ug_ )    {
	Quadrangle_el* quad;
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id )     {
		Set_marker<hexahedronEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_edges(); ++id ) {
		Set_marker<edgeEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_points(); ++id )    {
		Set_marker<pointEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_quadrangles(); ++id )    {
		quad = ug->Give_quadrangle ( id );
		if ( quad->Give_exists_exterior() == true )
			Set_marker<quadrangleEl> ( id, no_mark );
		else  {
			Set_marker<quadrangleEl> ( id, yes_mark );
			for ( int i=0; i<4; ++i )
470
                Set_marker<edgeEl> ( quad->Give_id_edge ( ( dir2D ) i ), yes_mark );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
471
472
473
474
475
476
477
478
			for ( int i=0; i<4; ++i )
				Set_marker<pointEl> ( quad->Give_id_corner ( ( dir2D_sons ) i ), yes_mark );
		}
	}
}

Boundary_Marker::~Boundary_Marker() {}

479
480
481
482
483
484
485
486
487
488
489
490
491
void Boundary_Marker::markBoundaryDir3D(dir3D dir, int blockRangeStart, int blockRangeEnd)
    {
    if (blockRangeStart == -1)
    {return;}
    if (blockRangeEnd < 0 || blockRangeEnd > ug->Give_number_hexahedra())
    {
      blockRangeEnd =   ug->Give_number_hexahedra();
    }
    if (blockRangeStart < 0 || blockRangeStart > ug->Give_number_hexahedra())
    {
      blockRangeStart =   0;
    }

492
493
    Quadrangle_el* quad;
    Hexahedron_el* hex ;
494
    for ( int id = blockRangeStart;id < blockRangeEnd;++id ) {
495
496
497
498
499
500
501
502
503
504
505
            hex = ug->Give_hexahedron ( id );

            if ( ug->Give_quadrangle ( hex->Give_id_quadrangle ( dir ) )->Give_exists_exterior() == false ) {

            quad = ug->Give_quadrangle ( hex->Give_id_quadrangle ( dir ) );
            Set_marker<quadrangleEl> ( hex->Give_id_quadrangle ( dir ), yes_mark );
            for ( int i=0; i<4; ++i )
                Set_marker<edgeEl> ( quad->Give_id_edge ( ( dir2D ) i ), yes_mark );
            for ( int i=0; i<4; ++i )
                Set_marker<pointEl> ( quad->Give_id_corner ( ( dir2D_sons ) i ), yes_mark );
        }
506
        }
507
508
    }

509
void Boundary_Marker::unmarkBoundaryDir3D(dir3D dir, int blockRangeStart, int blockRangeEnd)
510
{
511
512
513
514
515
516
517
518
519
520
521
    if (blockRangeStart == -1)
    {return;}
    if (blockRangeEnd < 0 || blockRangeEnd > ug->Give_number_hexahedra())
    {
      blockRangeEnd =   ug->Give_number_hexahedra();
    }
    if (blockRangeStart < 0 || blockRangeStart > ug->Give_number_hexahedra())
    {
      blockRangeStart =   0;
    }

522
523
    Quadrangle_el* quad;
    Hexahedron_el* hex ;
524
    for ( int id = blockRangeStart;id < blockRangeStart;++id ) {
525
526
527
528
529
530
531
532
533
534
535
536
537
538
            hex = ug->Give_hexahedron ( id );

            if ( ug->Give_quadrangle ( hex->Give_id_quadrangle ( dir ) )->Give_exists_exterior() == false ) {

            quad = ug->Give_quadrangle ( hex->Give_id_quadrangle ( dir ) );
            Set_marker<quadrangleEl> ( hex->Give_id_quadrangle ( dir ), no_mark );
            for ( int i=0; i<4; ++i )
                Set_marker<edgeEl> ( quad->Give_id_edge ( ( dir2D ) i ), no_mark );
            for ( int i=0; i<4; ++i )
                Set_marker<pointEl> ( quad->Give_id_corner ( ( dir2D_sons ) i ), no_mark );
        }
    }
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663

Unstructured_grid_Marker::Unstructured_grid_Marker ( Unstructured_grid* ug_ ) : Marker ( ug_ ) {
	for ( int id=0; id<ug->Give_number_hexahedra(); ++id ) {
		Set_marker<hexahedronEl> ( id, yes_mark );
	}
	for ( int id=0; id<ug->Give_number_edges(); ++id ) {
		Set_marker<edgeEl> ( id, yes_mark );
	}
	for ( int id=0; id<ug->Give_number_points(); ++id ) {
		Set_marker<pointEl> ( id, yes_mark );
	}
	for ( int id=0; id<ug->Give_number_quadrangles(); ++id ) {
		Set_marker<quadrangleEl> ( id, yes_mark );
	}
}

Unstructured_grid_Marker::~Unstructured_grid_Marker() {}

Blockgrid_Marker::Blockgrid_Marker ( Unstructured_grid* ug_ ) : Marker ( ug_ ) {
}

Blockgrid_Marker::~Blockgrid_Marker() {}



void Unstructured_grid_Marker::operator= ( bool ( *Marker_formula ) ( double x, double y, double z ) ) {
	D3vector middle;

	Hexahedron_el* hex;
	Quadrangle_el* quad;
	Edge_el*       edge;

	for ( int id=0; id<ug->Give_number_hexahedra(); ++id ) {
		hex = ug->Give_hexahedron ( id );

		/* old
		   middle = D3vector(0.0,0.0,0.0);
		   for(int i=0;i<8;++i) middle = middle + hex->Give_coord((dir3D_sons)i);
		   middle = middle / 8.0;
		*/
		middle = hex->Give_middle_coord();

		if ( Marker_formula ( middle.x,middle.y,middle.z ) )
			Set_marker<hexahedronEl> ( id, yes_mark );
		else Set_marker<hexahedronEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_quadrangles(); ++id ) {
		quad = ug->Give_quadrangle ( id );

		/* old
		middle = D3vector(0.0,0.0,0.0);
		for(int i=0;i<4;++i)
		  middle = middle + ug->Give_point(quad->Give_id_corner((dir2D_sons)i))->Give_coordinate();
		middle = middle / 4.0;
		*/
		middle = quad->Give_middle_coord();

		if ( Marker_formula ( middle.x,middle.y,middle.z ) )
			Set_marker<quadrangleEl> ( id, yes_mark );
		else Set_marker<quadrangleEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_edges(); ++id ) {
		edge = ug->Give_edge ( id );

		middle = ( ug->Give_point ( edge->Give_id_corner_W() )->Give_coordinate() +
		           ug->Give_point ( edge->Give_id_corner_E() )->Give_coordinate() ) / 2.0;

		if ( Marker_formula ( middle.x,middle.y,middle.z ) )
			Set_marker<edgeEl> ( id, yes_mark );
		else Set_marker<edgeEl> ( id, no_mark );
	}
	for ( int id=0; id<ug->Give_number_points(); ++id ) {
		middle = ug->Give_point ( id )->Give_coordinate();

		if ( Marker_formula ( middle.x,middle.y,middle.z ) )
			Set_marker<pointEl> ( id, yes_mark );
		else Set_marker<pointEl> ( id, no_mark );
	}
}




void Unstructured_grid_Marker::setBoundary( bool ( *Marker_formula ) ( double x, double y, double z ) )  {
	D3vector middle;


	Quadrangle_el* quad;
	Edge_el*       edge;
	
	for ( int id=0; id<ug->Give_number_quadrangles(); ++id ) {
		quad = ug->Give_quadrangle ( id );
		if ( quad->Give_exists_exterior() == false) {

			// mark quadrangles
			middle = quad->Give_middle_coord();
			if ( Marker_formula ( middle.x,middle.y,middle.z ) )
				Set_marker<quadrangleEl> ( id, yes_mark );
			else Set_marker<quadrangleEl> ( id, no_mark );

			// mark edges
			for ( int i=0; i<4; ++i ) {
				int idquad = quad->Give_id_edge ( ( dir2D ) i );
				edge = ug->Give_edge ( idquad );

				middle = ( ug->Give_point ( edge->Give_id_corner_W() )->Give_coordinate() +
				           ug->Give_point ( edge->Give_id_corner_E() )->Give_coordinate() ) / 2.0;

				if ( Marker_formula ( middle.x,middle.y,middle.z ) )
					Set_marker<edgeEl> ( idquad, yes_mark );
				else Set_marker<edgeEl> ( idquad, no_mark );
			}

			// mark points
			for ( int i=0; i<4; ++i ) {
				int idcorner =  quad->Give_id_corner ( ( dir2D_sons ) i );
				middle = ug->Give_point ( idcorner )->Give_coordinate();

				if ( Marker_formula ( middle.x,middle.y,middle.z ) )
					Set_marker<pointEl> ( idcorner, yes_mark );
				else Set_marker<pointEl> ( idcorner, no_mark );
			}
		}
	}
}