/
SMDS_Mesh.cpp
4853 lines (4402 loc) · 176 KB
/
SMDS_Mesh.cpp
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
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
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementation of Salome mesh data structure
//
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_FaceOfEdges.hxx"
#include "SMDS_FaceOfNodes.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_PolygonalFaceOfNodes.hxx"
#include "SMDS_PolyhedralVolumeOfNodes.hxx"
#include "SMDS_QuadraticEdge.hxx"
#include "SMDS_QuadraticFaceOfNodes.hxx"
#include "SMDS_QuadraticVolumeOfNodes.hxx"
#include "SMDS_SetIterator.hxx"
#include "SMDS_SpacePosition.hxx"
#include "SMDS_UnstructuredGrid.hxx"
#include "SMDS_VolumeOfFaces.hxx"
#include "SMDS_VolumeOfNodes.hxx"
#include "utilities.h"
#include <vtkUnstructuredGrid.h>
#include <vtkUnstructuredGridWriter.h>
#include <vtkUnsignedCharArray.h>
#include <vtkCell.h>
#include <vtkCellLinks.h>
#include <vtkIdList.h>
#include <algorithm>
#include <map>
#include <iostream>
#include <fstream>
#include <iterator>
using namespace std;
#ifndef WIN32
#if !(defined(__MACH__) && defined(__APPLE__))
#include <sys/sysinfo.h>
#endif
#include <sys/wait.h>
#endif
// number of added entities to check memory after
#define CHECKMEMORY_INTERVAL 100000
vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
int SMDS_Mesh::chunkSize = 1024;
//================================================================================
/*!
* \brief Raise an exception if free memory (ram+swap) too low
* \param doNotRaise - if true, suppres exception, just return free memory size
* \retval int - amount of available memory in MB or negative number in failure case
*/
//================================================================================
int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
{
#if 0
#if (defined(__MACH__) && defined(__APPLE__))
return 1000;
#else
#ifndef WIN32
struct sysinfo si;
int err = sysinfo( &si );
if ( err )
return -1;
const unsigned long Mbyte = 1024 * 1024;
static int limit = -1;
if ( limit < 0 ) {
int status = system("SMDS_MemoryLimit"); // it returns lower limit of free RAM
if (status >= 0 ) {
limit = WEXITSTATUS(status);
}
else {
double factor = ( si.totalswap == 0 ) ? 0.1 : 0.2;
limit = int(( factor * si.totalram * si.mem_unit ) / Mbyte );
}
if ( limit < 20 )
limit = 20;
else
limit = int ( limit * 1.5 );
MESSAGE ( "SMDS_Mesh::CheckMemory() memory limit = " << limit << " MB" );
}
// compute separately to avoid overflow
int freeMb =
( si.freeram * si.mem_unit ) / Mbyte +
( si.freeswap * si.mem_unit ) / Mbyte;
//cout << "freeMb = " << freeMb << " limit = " << limit << endl;
if ( freeMb > limit )
return freeMb - limit;
if ( doNotRaise )
return 0;
MESSAGE ("SMDS_Mesh::CheckMemory() throws as free memory too low: " << freeMb <<" MB" );
throw std::bad_alloc();
#else
return -1;
#endif
#endif
#else
return 1000;
#endif
}
///////////////////////////////////////////////////////////////////////////////
/// Create a new mesh object
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh::SMDS_Mesh()
:myParent(NULL),
myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
myElementIDFactory(new SMDS_MeshElementIDFactory()),
myHasConstructionEdges(false), myHasConstructionFaces(false),
myHasInverseElements(true),
myNodeMin(0), myNodeMax(0),
myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
myModified(false), myModifTime(0), myCompactTime(0),
xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
{
myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
myNodeIDFactory->SetMesh(this);
myElementIDFactory->SetMesh(this);
_meshList.push_back(this);
myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
myBallPool = new ObjectPool<SMDS_BallElement>(SMDS_Mesh::chunkSize);
myNodes.clear();
myCells.clear();
//myCellIdSmdsToVtk.clear();
myCellIdVtkToSmds.clear();
myGrid = SMDS_UnstructuredGrid::New();
myGrid->setSMDS_mesh(this);
myGrid->Initialize();
myGrid->Allocate();
vtkPoints* points = vtkPoints::New();
// bug "21125: EDF 1233 SMESH: Degrardation of precision in a test case for quadratic conversion"
// Use double type for storing coordinates of nodes instead of float.
points->SetDataType(VTK_DOUBLE);
points->SetNumberOfPoints(0 /*SMDS_Mesh::chunkSize*/);
myGrid->SetPoints( points );
points->Delete();
myGrid->BuildLinks();
this->Modified();
}
///////////////////////////////////////////////////////////////////////////////
/// Create a new child mesh
/// Note that the tree structure of SMDS_Mesh seems to be unused in this version
/// (2003-09-08) of SMESH
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
:myParent(parent), myNodeIDFactory(parent->myNodeIDFactory),
myElementIDFactory(parent->myElementIDFactory),
myHasConstructionEdges(false), myHasConstructionFaces(false),
myHasInverseElements(true),
myNodePool(parent->myNodePool),
myEdgePool(parent->myEdgePool),
myFacePool(parent->myFacePool),
myVolumePool(parent->myVolumePool),
myBallPool(parent->myBallPool)
{
}
///////////////////////////////////////////////////////////////////////////////
///Create a submesh and add it to the current mesh
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh *SMDS_Mesh::AddSubMesh()
{
SMDS_Mesh *submesh = new SMDS_Mesh(this);
myChildren.insert(myChildren.end(), submesh);
return submesh;
}
///////////////////////////////////////////////////////////////////////////////
///create a MeshNode and add it to the current Mesh
///An ID is automatically assigned to the node.
///@return : The created node
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshNode * SMDS_Mesh::AddNode(double x, double y, double z)
{
return SMDS_Mesh::AddNodeWithID(x,y,z,myNodeIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
///create a MeshNode and add it to the current Mesh
///@param ID : The ID of the MeshNode to create
///@return : The created node or NULL if a node with this ID already exists
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshNode * SMDS_Mesh::AddNodeWithID(double x, double y, double z, int ID)
{
// find the MeshNode corresponding to ID
const SMDS_MeshElement *node = myNodeIDFactory->MeshElement(ID);
if(!node){
if (ID < 1)
{
MESSAGE("=============> Bad Node Id: " << ID);
ID = myNodeIDFactory->GetFreeID();
}
myNodeIDFactory->adjustMaxId(ID);
SMDS_MeshNode * node = myNodePool->getNew();
node->init(ID, myMeshId, 0, x, y, z);
if (ID >= myNodes.size())
{
myNodes.resize(ID+SMDS_Mesh::chunkSize, 0);
// MESSAGE(" ------------------ myNodes resize " << ID << " --> " << ID+SMDS_Mesh::chunkSize);
}
myNodes[ID] = node;
myNodeIDFactory->BindID(ID,node);
myInfo.myNbNodes++;
myModified = true;
this->adjustBoundingBox(x, y, z);
return node;
}else
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
/// create a Mesh0DElement and add it to the current Mesh
/// @return : The created Mesh0DElement
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(int idnode, int ID)
{
SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
if (!node) return NULL;
return SMDS_Mesh::Add0DElementWithID(node, ID);
}
///////////////////////////////////////////////////////////////////////////////
/// create a Mesh0DElement and add it to the current Mesh
/// @return : The created Mesh0DElement
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh0DElement* SMDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
{
return SMDS_Mesh::Add0DElementWithID(node, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Create a new Mesh0DElement and at it to the mesh
/// @param idnode ID of the node
/// @param ID ID of the 0D element to create
/// @return The created 0D element or NULL if an element with this
/// ID already exists or if input node is not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_Mesh0DElement* SMDS_Mesh::Add0DElementWithID(const SMDS_MeshNode * n, int ID)
{
if (!n) return 0;
if (Nb0DElements() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
//MESSAGE("Add0DElementWithID" << ID)
SMDS_Mesh0DElement * el0d = new SMDS_Mesh0DElement(n);
if (myElementIDFactory->BindID(ID, el0d)) {
//SMDS_MeshNode *node = const_cast<SMDS_MeshNode*>(n);
//node->AddInverseElement(el0d);// --- fait avec BindID
adjustmyCellsCapacity(ID);
myCells[ID] = el0d;
myInfo.myNb0DElements++;
return el0d;
}
delete el0d;
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
/// create a Ball and add it to the current Mesh
/// @return : The created Ball
///////////////////////////////////////////////////////////////////////////////
SMDS_BallElement* SMDS_Mesh::AddBallWithID(int idnode, double diameter, int ID)
{
SMDS_MeshNode * node = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode);
if (!node) return NULL;
return SMDS_Mesh::AddBallWithID(node, diameter, ID);
}
///////////////////////////////////////////////////////////////////////////////
/// create a Ball and add it to the current Mesh
/// @return : The created Ball
///////////////////////////////////////////////////////////////////////////////
SMDS_BallElement* SMDS_Mesh::AddBall(const SMDS_MeshNode * node, double diameter)
{
return SMDS_Mesh::AddBallWithID(node, diameter, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Create a new Ball and at it to the mesh
/// @param idnode ID of the node
// @param diameter ball diameter
/// @param ID ID of the 0D element to create
/// @return The created 0D element or NULL if an element with this
/// ID already exists or if input node is not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_BallElement* SMDS_Mesh::AddBallWithID(const SMDS_MeshNode * n, double diameter, int ID)
{
if (!n) return 0;
if (NbBalls() % CHECKMEMORY_INTERVAL == 0) CheckMemory();
SMDS_BallElement *ball = myBallPool->getNew();
ball->init(n->getVtkId(), diameter, this);
if (!this->registerElement(ID,ball))
{
this->myGrid->GetCellTypesArray()->SetValue(ball->getVtkId(), VTK_EMPTY_CELL);
myBallPool->destroy(ball);
return 0;
}
adjustmyCellsCapacity(ID);
myCells[ID] = ball;
myInfo.myNbBalls++;
return ball;
}
///////////////////////////////////////////////////////////////////////////////
/// create a MeshEdge and add it to the current Mesh
/// @return : The created MeshEdge
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(int idnode1, int idnode2, int ID)
{
SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
if(!node1 || !node2) return NULL;
return SMDS_Mesh::AddEdgeWithID(node1, node2, ID);
}
///////////////////////////////////////////////////////////////////////////////
/// create a MeshEdge and add it to the current Mesh
/// @return : The created MeshEdge
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshEdge* SMDS_Mesh::AddEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
return SMDS_Mesh::AddEdgeWithID(node1, node2, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Create a new edge and at it to the mesh
/// @param idnode1 ID of the first node
/// @param idnode2 ID of the second node
/// @param ID ID of the edge to create
/// @return The created edge or NULL if an element with this ID already exists or
/// if input nodes are not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
int ID)
{
if ( !n1 || !n2 ) return 0;
SMDS_MeshEdge * edge = 0;
// --- retreive nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getVtkId());
nodeIds.push_back(n2->getVtkId());
SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
edgevtk->init(nodeIds, this);
if (!this->registerElement(ID,edgevtk))
{
this->myGrid->GetCellTypesArray()->SetValue(edgevtk->getVtkId(), VTK_EMPTY_CELL);
myEdgePool->destroy(edgevtk);
return 0;
}
edge = edgevtk;
adjustmyCellsCapacity(ID);
myCells[ID] = edge;
myInfo.myNbEdges++;
// if (edge && !registerElement(ID, edge))
// {
// RemoveElement(edge, false);
// edge = NULL;
// }
return edge;
}
///////////////////////////////////////////////////////////////////////////////
/// Add a triangle defined by its nodes. An ID is automatically affected to the
/// Created face
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3)
{
return SMDS_Mesh::AddFaceWithID(n1,n2,n3, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Add a triangle defined by its nodes IDs
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1, int idnode2, int idnode3, int ID)
{
SMDS_MeshNode * node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
SMDS_MeshNode * node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
SMDS_MeshNode * node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
if(!node1 || !node2 || !node3) return NULL;
return SMDS_Mesh::AddFaceWithID(node1, node2, node3, ID);
}
///////////////////////////////////////////////////////////////////////////////
/// Add a triangle defined by its nodes
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
int ID)
{
//MESSAGE("AddFaceWithID " << ID)
SMDS_MeshFace * face=createTriangle(n1, n2, n3, ID);
// if (face && !registerElement(ID, face)) {
// RemoveElement(face, false);
// face = NULL;
// }
return face;
}
///////////////////////////////////////////////////////////////////////////////
/// Add a quadrangle defined by its nodes. An ID is automatically affected to the
/// created face
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4)
{
return SMDS_Mesh::AddFaceWithID(n1,n2,n3, n4, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Add a quadrangle defined by its nodes IDs
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int idnode1,
int idnode2,
int idnode3,
int idnode4,
int ID)
{
SMDS_MeshNode *node1, *node2, *node3, *node4;
node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
if(!node1 || !node2 || !node3 || !node4) return NULL;
return SMDS_Mesh::AddFaceWithID(node1, node2, node3, node4, ID);
}
///////////////////////////////////////////////////////////////////////////////
/// Add a quadrangle defined by its nodes
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
int ID)
{
//MESSAGE("AddFaceWithID " << ID);
SMDS_MeshFace * face=createQuadrangle(n1, n2, n3, n4, ID);
// if (face && !registerElement(ID, face)) {
// RemoveElement(face, false);
// face = NULL;
// }
return face;
}
///////////////////////////////////////////////////////////////////////////////
/// Add a triangle defined by its edges. An ID is automatically assigned to the
/// Created face
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
const SMDS_MeshEdge * e2,
const SMDS_MeshEdge * e3)
{
if (!hasConstructionEdges())
return NULL;
//MESSAGE("AddFaceWithID");
return AddFaceWithID(e1,e2,e3, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Add a triangle defined by its edges
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
const SMDS_MeshEdge * e2,
const SMDS_MeshEdge * e3,
int ID)
{
if (!hasConstructionEdges())
return NULL;
if ( !e1 || !e2 || !e3 ) return 0;
if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
MESSAGE("AddFaceWithID" << ID);
SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3);
adjustmyCellsCapacity(ID);
myCells[ID] = face;
myInfo.myNbTriangles++;
if (!registerElement(ID, face)) {
registerElement(myElementIDFactory->GetFreeID(), face);
//RemoveElement(face, false);
//face = NULL;
}
return face;
}
///////////////////////////////////////////////////////////////////////////////
/// Add a quadrangle defined by its edges. An ID is automatically assigned to the
/// Created face
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshEdge * e1,
const SMDS_MeshEdge * e2,
const SMDS_MeshEdge * e3,
const SMDS_MeshEdge * e4)
{
if (!hasConstructionEdges())
return NULL;
//MESSAGE("AddFaceWithID" );
return AddFaceWithID(e1,e2,e3,e4, myElementIDFactory->GetFreeID());
}
///////////////////////////////////////////////////////////////////////////////
/// Add a quadrangle defined by its edges
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshEdge * e1,
const SMDS_MeshEdge * e2,
const SMDS_MeshEdge * e3,
const SMDS_MeshEdge * e4,
int ID)
{
if (!hasConstructionEdges())
return NULL;
MESSAGE("AddFaceWithID" << ID);
if ( !e1 || !e2 || !e3 || !e4 ) return 0;
if ( NbFaces() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
SMDS_MeshFace * face = new SMDS_FaceOfEdges(e1,e2,e3,e4);
adjustmyCellsCapacity(ID);
myCells[ID] = face;
myInfo.myNbQuadrangles++;
if (!registerElement(ID, face))
{
registerElement(myElementIDFactory->GetFreeID(), face);
//RemoveElement(face, false);
//face = NULL;
}
return face;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new tetrahedron and add it to the mesh.
///@return The created tetrahedron
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4)
{
int ID = myElementIDFactory->GetFreeID();
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
if(v==NULL) myElementIDFactory->ReleaseID(ID);
return v;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new tetrahedron and add it to the mesh.
///@param ID The ID of the new volume
///@return The created tetrahedron or NULL if an element with this ID already exists
///or if input nodes are not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
int idnode2,
int idnode3,
int idnode4,
int ID)
{
//MESSAGE("AddVolumeWithID" << ID);
SMDS_MeshNode *node1, *node2, *node3, *node4;
node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
if(!node1 || !node2 || !node3 || !node4) return NULL;
return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, ID);
}
///////////////////////////////////////////////////////////////////////////////
///Create a new tetrahedron and add it to the mesh.
///@param ID The ID of the new volume
///@return The created tetrahedron
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
int ID)
{
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4) return volume;
if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n4);
SMDS_MeshFace * f3=FindFaceOrCreate(n1,n3,n4);
SMDS_MeshFace * f4=FindFaceOrCreate(n2,n3,n4);
volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbTetras++;
}
else if(hasConstructionEdges()) {
MESSAGE("Error : Not implemented");
return NULL;
}
else {
// --- retrieve nodes ID
myNodeIds.resize(4);
myNodeIds[0] = n1->getVtkId();
myNodeIds[1] = n3->getVtkId(); // order SMDS-->VTK
myNodeIds[2] = n2->getVtkId();
myNodeIds[3] = n4->getVtkId();
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(myNodeIds, this);
if (!this->registerElement(ID,volvtk))
{
this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
myVolumePool->destroy(volvtk);
return 0;
}
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbTetras++;
}
// if (!registerElement(ID, volume)) {
// RemoveElement(volume, false);
// volume = NULL;
// }
return volume;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new pyramid and add it to the mesh.
///Nodes 1,2,3 and 4 define the base of the pyramid
///@return The created pyramid
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5)
{
int ID = myElementIDFactory->GetFreeID();
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
if(v==NULL) myElementIDFactory->ReleaseID(ID);
return v;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new pyramid and add it to the mesh.
///Nodes 1,2,3 and 4 define the base of the pyramid
///@param ID The ID of the new volume
///@return The created pyramid or NULL if an element with this ID already exists
///or if input nodes are not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
int idnode2,
int idnode3,
int idnode4,
int idnode5,
int ID)
{
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshNode *node1, *node2, *node3, *node4, *node5;
node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
if(!node1 || !node2 || !node3 || !node4 || !node5) return NULL;
return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, ID);
}
///////////////////////////////////////////////////////////////////////////////
///Create a new pyramid and add it to the mesh.
///Nodes 1,2,3 and 4 define the base of the pyramid
///@param ID The ID of the new volume
///@return The created pyramid
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5,
int ID)
{
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4 || !n5) return volume;
if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3,n4);
SMDS_MeshFace * f2=FindFaceOrCreate(n1,n2,n5);
SMDS_MeshFace * f3=FindFaceOrCreate(n2,n3,n5);
SMDS_MeshFace * f4=FindFaceOrCreate(n3,n4,n5);
volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPyramids++;
}
else if(hasConstructionEdges()) {
MESSAGE("Error : Not implemented");
return NULL;
}
else {
// --- retrieve nodes ID
myNodeIds.resize(5);
myNodeIds[0] = n1->getVtkId();
myNodeIds[1] = n4->getVtkId();
myNodeIds[2] = n3->getVtkId();
myNodeIds[3] = n2->getVtkId();
myNodeIds[4] = n5->getVtkId();
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(myNodeIds, this);
if (!this->registerElement(ID,volvtk))
{
this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
myVolumePool->destroy(volvtk);
return 0;
}
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPyramids++;
}
// if (!registerElement(ID, volume)) {
// RemoveElement(volume, false);
// volume = NULL;
// }
return volume;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new prism and add it to the mesh.
///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
///@return The created prism
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5,
const SMDS_MeshNode * n6)
{
int ID = myElementIDFactory->GetFreeID();
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
if(v==NULL) myElementIDFactory->ReleaseID(ID);
return v;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new prism and add it to the mesh.
///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
///@param ID The ID of the new volume
///@return The created prism or NULL if an element with this ID already exists
///or if input nodes are not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
int idnode2,
int idnode3,
int idnode4,
int idnode5,
int idnode6,
int ID)
{
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshNode *node1, *node2, *node3, *node4, *node5, *node6;
node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
if(!node1 || !node2 || !node3 || !node4 || !node5 || !node6) return NULL;
return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6, ID);
}
///////////////////////////////////////////////////////////////////////////////
///Create a new prism and add it to the mesh.
///Nodes 1,2,3 is a triangle and 1,2,5,4 a quadrangle.
///@param ID The ID of the new volume
///@return The created prism
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5,
const SMDS_MeshNode * n6,
int ID)
{
//MESSAGE("AddVolumeWithID " << ID);
SMDS_MeshVolume* volume = 0;
if ( !n1 || !n2 || !n3 || !n4 || !n5 || !n6) return volume;
if ( NbVolumes() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
if(hasConstructionFaces()) {
SMDS_MeshFace * f1=FindFaceOrCreate(n1,n2,n3);
SMDS_MeshFace * f2=FindFaceOrCreate(n4,n5,n6);
SMDS_MeshFace * f3=FindFaceOrCreate(n1,n4,n5,n2);
SMDS_MeshFace * f4=FindFaceOrCreate(n2,n5,n6,n3);
SMDS_MeshFace * f5=FindFaceOrCreate(n3,n6,n4,n1);
volume=new SMDS_VolumeOfFaces(f1,f2,f3,f4,f5);
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPrisms++;
}
else if(hasConstructionEdges()) {
MESSAGE("Error : Not implemented");
return NULL;
}
else {
// --- retrieve nodes ID
myNodeIds.resize(6);
myNodeIds[0] = n1->getVtkId();
myNodeIds[1] = n2->getVtkId();
myNodeIds[2] = n3->getVtkId();
myNodeIds[3] = n4->getVtkId();
myNodeIds[4] = n5->getVtkId();
myNodeIds[5] = n6->getVtkId();
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(myNodeIds, this);
if (!this->registerElement(ID,volvtk))
{
this->myGrid->GetCellTypesArray()->SetValue(volvtk->getVtkId(), VTK_EMPTY_CELL);
myVolumePool->destroy(volvtk);
return 0;
}
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPrisms++;
}
// if (!registerElement(ID, volume)) {
// RemoveElement(volume, false);
// volume = NULL;
// }
return volume;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new hexagonal prism and add it to the mesh.
///@return The created prism
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5,
const SMDS_MeshNode * n6,
const SMDS_MeshNode * n7,
const SMDS_MeshNode * n8,
const SMDS_MeshNode * n9,
const SMDS_MeshNode * n10,
const SMDS_MeshNode * n11,
const SMDS_MeshNode * n12)
{
int ID = myElementIDFactory->GetFreeID();
SMDS_MeshVolume * v = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6,
n7, n8, n9, n10, n11, n12,
ID);
if(v==NULL) myElementIDFactory->ReleaseID(ID);
return v;
}
///////////////////////////////////////////////////////////////////////////////
///Create a new hexagonal prism and add it to the mesh.
///@param ID The ID of the new volume
///@return The created prism or NULL if an element with this ID already exists
///or if input nodes are not found.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume * SMDS_Mesh::AddVolumeWithID(int idnode1,
int idnode2,
int idnode3,
int idnode4,
int idnode5,
int idnode6,
int idnode7,
int idnode8,
int idnode9,
int idnode10,
int idnode11,
int idnode12,
int ID)
{
SMDS_MeshNode *node1 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode1);
SMDS_MeshNode *node2 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode2);
SMDS_MeshNode *node3 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode3);
SMDS_MeshNode *node4 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode4);
SMDS_MeshNode *node5 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode5);
SMDS_MeshNode *node6 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode6);
SMDS_MeshNode *node7 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode7);
SMDS_MeshNode *node8 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode8);
SMDS_MeshNode *node9 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode9);
SMDS_MeshNode *node10 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode10);
SMDS_MeshNode *node11 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode11);
SMDS_MeshNode *node12 = (SMDS_MeshNode *)myNodeIDFactory->MeshElement(idnode12);
return SMDS_Mesh::AddVolumeWithID(node1, node2, node3, node4, node5, node6,
node7, node8, node9, node10, node11, node12,
ID);
}
///////////////////////////////////////////////////////////////////////////////
///Create a new hexagonal prism and add it to the mesh.
///@param ID The ID of the new volume
///@return The created prism
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
const SMDS_MeshNode * n2,
const SMDS_MeshNode * n3,
const SMDS_MeshNode * n4,
const SMDS_MeshNode * n5,
const SMDS_MeshNode * n6,
const SMDS_MeshNode * n7,
const SMDS_MeshNode * n8,
const SMDS_MeshNode * n9,
const SMDS_MeshNode * n10,
const SMDS_MeshNode * n11,
const SMDS_MeshNode * n12,
int ID)