-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathvolcartesian.cpp
2301 lines (1891 loc) · 60.5 KB
/
volcartesian.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
/*---------------------------------------------------------------------------*\
*
* bitpit
*
* Copyright (C) 2015-2021 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of bitpit.
*
* bitpit is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* bitpit 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 bitpit. If not, see <http://www.gnu.org/licenses/>.
*
\*---------------------------------------------------------------------------*/
#include <cmath>
#include <bitset>
#if BITPIT_ENABLE_MPI==1
# include <mpi.h>
#endif
#include "bitpit_common.hpp"
#include "volcartesian.hpp"
namespace bitpit {
/*!
\class VolCartesian
\ingroup volumepatches
\brief The VolCartesian defines a Cartesian patch.
VolCartesian is a Cartesian patch that can operate in two modes. In normal
memory mode, the patch behaves like a standard patch: all data structures
needed by the patch are generated and stored within the ptch. This means
that, in normal mode, the patch will create cells, vertices and, if
requested, interfaces data structures. In light memory mode, the patch
will create only a minimal set of data structures. Altohugh this allows
to reduce its memory footprint, it will also limit the functionalites
available when operating in light memory mode. Features that are
available in light memory mode are:
- evaluation of vertex/cell/interface topological properties;
- evaluation of vertex/cell/interface geometrical properties;
- evaluation of cell neighbours.
Features that are NOT available in light memory mode are:
- access to vertex/cell/interface data structures;
- access to vertex/cell/interface iterators;
- writing of VTK files.
When in light memory mode, updating the patch will automatically switch
to normal memory mode.
*/
/*!
Creates an uninitialized patch.
*/
VolCartesian::VolCartesian()
#if BITPIT_ENABLE_MPI==1
: VolumeKernel(MPI_COMM_NULL, 0, ADAPTION_DISABLED, PARTITIONING_DISABLED)
#else
: VolumeKernel(ADAPTION_DISABLED)
#endif
{
initialize();
}
/*!
Creates a patch.
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param lengths are the lengths of the domain
\param nCells are the numbers of cells of the patch
*/
VolCartesian::VolCartesian(int dimension,
const std::array<double, 3> &origin,
const std::array<double, 3> &lengths,
const std::array<int, 3> &nCells)
: VolCartesian(PatchManager::AUTOMATIC_ID, dimension, origin, lengths, nCells)
{
}
/*!
Creates a patch.
\param id is the id of the patch
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param lengths are the lengths of the domain
\param nCells are the number of cells along each direction
*/
VolCartesian::VolCartesian(int id, int dimension,
const std::array<double, 3> &origin,
const std::array<double, 3> &lengths,
const std::array<int, 3> &nCells)
#if BITPIT_ENABLE_MPI==1
: VolumeKernel(id, dimension, MPI_COMM_NULL, 0, ADAPTION_DISABLED, PARTITIONING_DISABLED)
#else
: VolumeKernel(id, dimension, ADAPTION_DISABLED)
#endif
{
initialize();
setOrigin(origin);
setLengths(lengths);
setDiscretization(nCells);
}
/*!
Creates a patch.
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param length is the length of the domain
\param nCells is the number of cells along each direction
*/
VolCartesian::VolCartesian(int dimension,
const std::array<double, 3> &origin,
double length, int nCells)
: VolCartesian(PatchManager::AUTOMATIC_ID, dimension, origin, length, nCells)
{
}
/*!
Creates a patch.
\param id is the id of the patch
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param length is the length of the domain
\param nCells is the number of cells along each direction
*/
VolCartesian::VolCartesian(int id, int dimension,
const std::array<double, 3> &origin,
double length, int nCells)
#if BITPIT_ENABLE_MPI==1
: VolumeKernel(id, dimension, MPI_COMM_NULL, 0, ADAPTION_DISABLED, PARTITIONING_DISABLED)
#else
: VolumeKernel(id, dimension, ADAPTION_DISABLED)
#endif
{
initialize();
setOrigin(origin);
setLengths({{length, length, length}});
setDiscretization({{nCells, nCells, nCells}});
}
/*!
Creates a patch.
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param length is the length of the domain
\param dh is the maximum allowed mesh spacing
*/
VolCartesian::VolCartesian(int dimension,
const std::array<double, 3> &origin,
double length, double dh)
: VolCartesian(PatchManager::AUTOMATIC_ID, dimension, origin, length, dh)
{
}
/*!
Creates a patch.
\param id is the id of the patch
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param length is the length of the domain
\param dh is the maximum allowed mesh spacing
*/
VolCartesian::VolCartesian(int id, int dimension,
const std::array<double, 3> &origin,
double length, double dh)
#if BITPIT_ENABLE_MPI==1
: VolumeKernel(id, dimension, MPI_COMM_NULL, 0, ADAPTION_DISABLED, PARTITIONING_DISABLED)
#else
: VolumeKernel(id, dimension, ADAPTION_DISABLED)
#endif
{
initialize();
setOrigin(origin);
setLengths({{length, length, length}});
int nCells = (int) std::ceil(length / dh);
setDiscretization({{nCells, nCells, nCells}});
}
/*!
Creates a serial patch restoring the patch saved in the specified stream.
\param stream is the stream to read from
*/
VolCartesian::VolCartesian(std::istream &stream)
#if BITPIT_ENABLE_MPI==1
: VolumeKernel(MPI_COMM_NULL, 0, ADAPTION_DISABLED, PARTITIONING_DISABLED)
#else
: VolumeKernel(ADAPTION_DISABLED)
#endif
{
initialize();
restore(stream);
}
/*!
Creates a clone of the pach.
\result A clone of the pach.
*/
std::unique_ptr<PatchKernel> VolCartesian::clone() const
{
return std::unique_ptr<VolCartesian>(new VolCartesian(*this));
}
/*!
Function to reset the patch.
*/
void VolCartesian::reset()
{
// Switch to light memeory mode
switchMemoryMode(MEMORY_LIGHT);
// Reset geometry and discretization
m_minCoords = {{0., 0., 0.}};
m_maxCoords = {{1., 1., 1.}};
m_nCells1D = {{0, 0, 0}};
m_nVertices1D = {{0, 0, 0}};
m_cellSpacings = {{0., 0., 0.}};
for (int n = 0; n < 3; ++n) {
std::vector<double>().swap(m_vertexCoords[n]);
std::vector<double>().swap(m_cellCenters[n]);
}
m_nVertices = 0;
m_nCells = 0;
m_nInterfaces = 0;
}
/*!
Resest the interfaces of the patch.
*/
void VolCartesian::resetInterfaces()
{
PatchKernel::resetInterfaces();
}
/*!
Internal function to update the adjacencies of the patch.
The function will always update the adjacencies of all the cells.
*/
void VolCartesian::_updateAdjacencies()
{
// Partial updates are not supported
CellConstIterator beginItr = cellConstBegin();
CellConstIterator endItr = cellConstEnd();
bool partialUpdate = false;
for (CellConstIterator cellIterator = beginItr; cellIterator != endItr; ++cellIterator) {
long cellId = cellIterator.getId();
if (!testCellAlterationFlags(cellId, FLAG_ADJACENCIES_DIRTY)) {
partialUpdate = true;
break;
}
}
if (partialUpdate) {
log::cout() << " It is not possible to partially update the adjacencies.";
log::cout() << " All adjacencies will be updated.";
}
// Update adjacencies
int nCellFaces = 2 * getDimension();
for (Cell &cell : getCells()) {
// Reset cell adjacencies
if (cell.getAdjacencyCount() != 0) {
cell.resetAdjacencies();
}
// Evaluate adjacencies
long cellId = cell.getId();
for (int face = 0; face < nCellFaces; ++face) {
// Identify face neighbour
long neighId = getCellFaceNeighsLinearId(cellId, face);
if (neighId < 0) {
continue;
}
// Add adjacency
cell.pushAdjacency(face, neighId);
}
}
}
/*!
Internal function to update the interfaces of the patch.
It is not possible to partially update the interfaces of this patch.
The function will always update all the interfaces.
*/
void VolCartesian::_updateInterfaces()
{
// Partial updates are not supported
CellConstIterator beginItr = cellConstBegin();
CellConstIterator endItr = cellConstEnd();
bool partialUpdate = false;
for (CellConstIterator cellIterator = beginItr; cellIterator != endItr; ++cellIterator) {
long cellId = cellIterator.getId();
if (!testCellAlterationFlags(cellId, FLAG_INTERFACES_DIRTY)) {
partialUpdate = true;
break;
}
}
if (partialUpdate) {
log::cout() << " It is not possible to partially update the interfaces.";
log::cout() << " All interfaces will be updated.";
}
// Build interfaces
if (getMemoryMode() == MemoryMode::MEMORY_NORMAL) {
int nCellFaces = 2 * getDimension();
// Info on the interfaces
ElementType interfaceType = getInterfaceType();
const ReferenceElementInfo &interfaceTypeInfo = ReferenceElementInfo::getInfo(interfaceType);
const int nInterfaceVertices = interfaceTypeInfo.nVertices;
// Enable manual adaption
AdaptionMode previousAdaptionMode = getAdaptionMode();
setAdaptionMode(ADAPTION_MANUAL);
// Initialize interfaces
for (Cell &cell : getCells()) {
cell.setInterfaces(FlatVector2D<long>(nCellFaces, 1, Interface::NULL_ID));
}
// Build interfaces
for (Cell &cell : getCells()) {
long cellId = cell.getId();
for (int face = 0; face < nCellFaces; ++face) {
// Get neighbour information
//
// The interface between two cells needs to be processed only
// once. In order to ensure this, we build an interface if the
// faces is a border, or if the id of this cell is lower than
// the id of its neighbour.
long neighId;
if (cell.getAdjacencyCount(face) > 0) {
neighId = cell.getAdjacencies(face)[0];
if (neighId < cellId) {
continue;
}
} else {
neighId = Cell::NULL_ID;
}
// Create the interface
InterfaceIterator interfaceIterator = VolumeKernel::addInterface(interfaceType);
Interface &interface = *interfaceIterator;
long interfaceId = interface.getId();
// Set connectivity
ConstProxyVector<long> faceConnect = cell.getFaceConnect(face);
int connectSize = faceConnect.size();
std::unique_ptr<long[]> connect = std::unique_ptr<long[]>(new long[nInterfaceVertices]);
for (int k = 0; k < connectSize; ++k) {
connect[k] = faceConnect[k];
}
interface.setConnect(std::move(connect));
// Set owner data
interface.setOwner(cellId, face);
cell.setInterface(face, 0, interfaceId);
// Neighbour data
if (neighId >= 0) {
Cell &neigh = getCell(neighId);
int neighFace = 2 * static_cast<int>(std::floor(face / 2.)) + (1 - face % 2);
interface.setNeigh(neighId, neighFace);
neigh.setInterface(neighFace, 0, interfaceId);
} else {
interface.unsetNeigh();
}
}
}
// Restore previous adaption mode
setAdaptionMode(previousAdaptionMode);
}
}
/*!
Initialize the data structures of the patch.
*/
void VolCartesian::initialize()
{
// Normals
int i = 0;
for (int n = 0; n < 3; n++) {
for (int k = -1; k <= 1; k += 2) {
std::array<double, 3> normal = {{0.0, 0.0, 0.0}};
normal[n] = k;
m_normals[i++] = normal;
}
}
// Deltas for the evaluation of the vertex neighbours
m_vertexNeighDeltas = std::vector<std::array<int, 3>>(8);
m_vertexNeighDeltas[0] = {{ 0, 0, 0}};
m_vertexNeighDeltas[1] = {{-1, 0, 0}};
m_vertexNeighDeltas[2] = {{ 0, -1, 0}};
m_vertexNeighDeltas[3] = {{-1, -1, 0}};
m_vertexNeighDeltas[4] = {{ 0, 0, -1}};
m_vertexNeighDeltas[5] = {{-1, 0, -1}};
m_vertexNeighDeltas[6] = {{ 0, -1, -1}};
m_vertexNeighDeltas[7] = {{-1, -1, -1}};
// Deltas for the evaluation of the edge neighbours
m_edgeNeighDeltas = std::vector<std::array<int, 3>>(12);
m_edgeNeighDeltas[ 0] = {{-1, 0, -1}};
m_edgeNeighDeltas[ 1] = {{ 1, 0, -1}};
m_edgeNeighDeltas[ 2] = {{ 0, -1, -1}};
m_edgeNeighDeltas[ 3] = {{ 0, 1, -1}};
m_edgeNeighDeltas[ 4] = {{-1, -1, 0}};
m_edgeNeighDeltas[ 5] = {{ 1, -1, 0}};
m_edgeNeighDeltas[ 6] = {{-1, 1, 0}};
m_edgeNeighDeltas[ 7] = {{ 1, 1, 0}};
m_edgeNeighDeltas[ 8] = {{-1, 0, 1}};
m_edgeNeighDeltas[ 9] = {{ 1, 0, 1}};
m_edgeNeighDeltas[10] = {{ 0, -1, 1}};
m_edgeNeighDeltas[11] = {{ 0, 1, 1}};
// Faces associated to the edges
m_edgeFaces = std::vector<std::array<int, 2>>(12);
m_edgeFaces[ 0] = {{ 0, 4}};
m_edgeFaces[ 1] = {{ 1, 4}};
m_edgeFaces[ 2] = {{ 2, 4}};
m_edgeFaces[ 3] = {{ 3, 4}};
m_edgeFaces[ 4] = {{ 0, 2}};
m_edgeFaces[ 5] = {{ 1, 2}};
m_edgeFaces[ 6] = {{ 0, 3}};
m_edgeFaces[ 7] = {{ 1, 3}};
m_edgeFaces[ 8] = {{ 0, 5}};
m_edgeFaces[ 9] = {{ 1, 5}};
m_edgeFaces[10] = {{ 2, 5}};
m_edgeFaces[11] = {{ 3, 5}};
// Set the bounding box as frozen
setBoundingBoxFrozen(true);
// Set the light memory mode
setMemoryMode(MemoryMode::MEMORY_LIGHT);
// Reset the patch
reset();
}
/*!
Initializes cell volume
*/
void VolCartesian::initializeCellVolume()
{
m_cellVolume = 1;
for (int d = 0; d < getDimension(); ++d) {
if (m_directionOrdering[d] >= 0) {
m_cellVolume *= m_cellSpacings[d];
}
}
}
/*!
Initializes cell size
*/
void VolCartesian::initializeCellSize()
{
m_cellSize = std::pow(m_cellVolume, 1. / getDimension());
}
/*!
Initializes interface area
*/
void VolCartesian::initializeInterfaceArea()
{
for (int d = 0; d < getDimension(); ++d) {
if (m_directionOrdering[d] >= 0) {
m_interfaceArea[d] = m_cellVolume / m_cellSpacings[d];
} else {
m_interfaceArea[d] = 0.;
}
}
}
/*!
Discretizes the domain.
\param nCells is the numbers of cells along each direction
*/
void VolCartesian::setDiscretization(const std::array<int, 3> &nCells)
{
// Spacing
for (int d = 0; d < getDimension(); ++d) {
// Initialize cells
if (nCells[d] > 0) {
m_nCells1D[d] = nCells[d];
m_cellSpacings[d] = (m_maxCoords[d] - m_minCoords[d]) / m_nCells1D[d];
m_cellCenters[d].resize(m_nCells1D[d]);
for (int i = 0; i < m_nCells1D[d]; i++) {
m_cellCenters[d][i] = m_minCoords[d] + (0.5 + i) * m_cellSpacings[d];
}
} else {
m_nCells1D[d] = 0;
m_cellSpacings[d] = 0.;
}
log::cout() << " - Cell count along direction " << d << " : " << m_nCells1D[d] << "\n";
// Initialize vertices
m_nVertices1D[d] = m_nCells1D[d] + 1;
m_vertexCoords[d].resize(m_nVertices1D[d]);
for (int i = 0; i < m_nVertices1D[d]; i++) {
m_vertexCoords[d][i] = m_minCoords[d] + i * m_cellSpacings[d];
}
}
for (int d = getDimension(); d < 3; ++d) {
m_nCells1D[d] = 0;
m_cellSpacings[d] = 0.;
m_nVertices1D[d] = 1;
}
log::cout() << std::endl;
// Define direction ordering
//
// It is the ordering in which the different directions will be considered
// when numbering cell, vertices, ... For each direction, it will contain
// the order in which the direction should be considered or -1 if there
// are no cells along the direction.
for (int d = 0; d < 3; ++d) {
if (d == 0) {
m_directionOrdering[d] = 0;
} else {
int previousDirection = m_directionOrdering[d - 1];
if (previousDirection < 0 || previousDirection >= 2) {
m_directionOrdering[d] = -1;
continue;
}
m_directionOrdering[d] = previousDirection + 1;
}
while (m_nCells1D[m_directionOrdering[d]] == 0) {
if (m_directionOrdering[d] == 2) {
m_directionOrdering[d] = -1;
break;
}
++m_directionOrdering[d];
}
}
// Count the total number of vertices
m_nVertices = 1;
for (int n = 0; n < getDimension(); ++n) {
m_nVertices *= m_nVertices1D[n];
}
log::cout() << " - Total vertex count: " << m_nVertices << "\n";
// Count the total number of cells
m_nCells = 1;
for (int d = 0; d < getDimension(); ++d) {
if (m_directionOrdering[d] >= 0) {
m_nCells *= m_nCells1D[d];
}
}
log::cout() << " - Total cell count: " << m_nCells << "\n";
// Count the total number of interfaces
m_nInterfaces = 0;
for (int d = 0; d < getDimension(); ++d) {
int nDirectionInterfaces = 1;
for (int n = 0; n < getDimension(); n++) {
int nDirectionInterfaces1D = m_nCells1D[n];
if (n == d) {
++nDirectionInterfaces1D;
}
nDirectionInterfaces *= nDirectionInterfaces1D;
}
m_nInterfaces += nDirectionInterfaces;
}
log::cout() << " - Total interface count: " << m_nInterfaces << "\n";
// Cell volume
initializeCellVolume();
// Cell size
initializeCellSize();
// Interface area
initializeInterfaceArea();
// Update patch data structures
if (getMemoryMode() == MemoryMode::MEMORY_NORMAL) {
// Switch to light mode to reset patchdata structures
switchMemoryMode(MemoryMode::MEMORY_LIGHT);
// Swich back to normal mode to rebuild patchdata structures
switchMemoryMode(MemoryMode::MEMORY_NORMAL);
}
}
/*!
Gets the number of vertices in the patch.
\return The number of vertices in the patch
*/
long VolCartesian::getVertexCount() const
{
return m_nVertices;
}
/*!
Gets the number of vertices along the specified direction.
\param direction is the direction along which vertex count is requested
\return The number of vertices along the specified.
*/
int VolCartesian::getVertexCount(int direction) const
{
return m_nVertices1D[direction];
}
/*!
Gets the number of cells in the patch.
\return The number of cells in the patch
*/
long VolCartesian::getCellCount() const
{
return m_nCells;
}
/*!
Gets the number of cells along the specified direction.
\param direction is the direction along which cell count is requested
\return The number of cells along the specified.
*/
int VolCartesian::getCellCount(int direction) const
{
return m_nCells1D[direction];
}
/*!
Gets the element type for the cell with the specified id.
\param id is the id of the requested cell
\return The element type for the cell with the specified id.
*/
ElementType VolCartesian::getCellType(long id) const
{
BITPIT_UNUSED(id);
return getCellType();
}
/*!
Gets the element type for the cells in the patch.
\return The element type for the cells in the patch.
*/
ElementType VolCartesian::getCellType() const
{
if (isThreeDimensional()) {
return ElementType::VOXEL;
} else {
return ElementType::PIXEL;
}
}
/*!
Gets the number of interfaces in the patch.
\return The number of interfaces in the patch
*/
long VolCartesian::getInterfaceCount() const
{
return m_nInterfaces;
}
/*!
Gets the element type for the interface with the specified id.
\param id is the id of the requested interface
\return The element type for the interface with the specified id.
*/
ElementType VolCartesian::getInterfaceType(long id) const
{
BITPIT_UNUSED(id);
return getInterfaceType();
}
/*!
Gets the element type for the interfaces in the patch.
\return The element type for the interfaces in the patch.
*/
ElementType VolCartesian::getInterfaceType() const
{
if (isThreeDimensional()) {
return ElementType::PIXEL;
} else {
return ElementType::LINE;
}
}
/*!
Evaluates the coordinate of the specified vertex.
\param id is the id of the vertex
\result The coordinate of the specified vertex.
*/
std::array<double, 3> VolCartesian::evalVertexCoords(long id) const
{
std::array<int, 3> ijk = getVertexCartesianId(id);
return evalVertexCoords(ijk);
}
/*!
Evaluates the coordinate of the specified vertex.
\param ijk is the set of cartesian indices of the vertex
\result The coordinate of the specified vertex.
*/
std::array<double, 3> VolCartesian::evalVertexCoords(const std::array<int, 3> &ijk) const
{
std::array<double, 3> coords;
for (int d = 0; d < 3; ++d) {
if (ijk[d] >= 0) {
coords[d] = m_vertexCoords[d][ijk[d]];
} else {
coords[d] = m_minCoords[d];
}
}
return coords;
}
/*!
Get vertex coordinates along the specified direction.
\param direction is the direction along which vertex coordinates are
requested
\result Vertex coordinates along the specified direction.
*/
const std::vector<double> & VolCartesian::getVertexCoords(int direction) const
{
return m_vertexCoords[direction];
}
/*!
Evaluates the volume of the specified cell.
\param id is the id of the cell
\result The volume of the specified cell.
*/
double VolCartesian::evalCellVolume(long id) const
{
BITPIT_UNUSED(id);
return evalCellVolume();
}
/*!
Evaluates the volume of the specified cell.
\param ijk is the set of cartesian indices of the cell
\result The volume of the specified cell.
*/
double VolCartesian::evalCellVolume(const std::array<int, 3> &ijk) const
{
BITPIT_UNUSED(ijk);
return evalCellVolume();
}
/*!
Evaluates the volume of a cell.
The patch is uniformly spaced, so all the cells have the same volume.
\result The volume of a cell.
*/
double VolCartesian::evalCellVolume() const
{
return m_cellVolume;
}
/*!
Evaluates the characteristic size of the specified cell.
\param id is the id of the cell
\result The characteristic size of the specified cell.
*/
double VolCartesian::evalCellSize(long id) const
{
BITPIT_UNUSED(id);
return evalCellSize();
}
/*!
Evaluates the characteristic size of the specified cell.
\param ijk is the set of cartesian indices of the cell
\result The characteristic size of the specified cell.
*/
double VolCartesian::evalCellSize(const std::array<int, 3> &ijk) const
{
BITPIT_UNUSED(ijk);
return evalCellSize();
}
/*!
Evaluates the characteristic size of a cell.
The patch is uniformly spaced, so all the cells have the same size.
\result The characteristic size of a cell.
*/
double VolCartesian::evalCellSize() const
{
return m_cellSize;
}
/*!
Evaluates the bounding box of the specified cell.
\param id is the id of the cell
\param[out] minPoint is the minimum point of the bounding box
\param[out] maxPoint is the maximum point of the bounding box
*/
void VolCartesian::evalCellBoundingBox(long id, std::array<double,3> *minPoint, std::array<double,3> *maxPoint) const
{
std::array<double,3> cellCentroid = evalCellCentroid(id);
for (int d = 0; d < 3; ++d) {
(*minPoint)[d] = cellCentroid[d] - 0.5 * m_cellSpacings[d];
(*maxPoint)[d] = cellCentroid[d] + 0.5 * m_cellSpacings[d];
}
}
/*!
Evaluates the area of the specified interface.
\param id is the id of the interface
\result The area of the specified interface.
*/
double VolCartesian::evalInterfaceArea(long id) const
{
const Interface &interface = getInterface(id);
int ownerFace = interface.getOwnerFace();
int direction = static_cast<int>(std::floor(ownerFace / 2.));
return m_interfaceArea[direction];
}
/*!
Evaluates the normal of the specified interface.
\param id is the id of the interface
\result The normal of the specified interface.
*/
std::array<double, 3> VolCartesian::evalInterfaceNormal(long id) const
{
const Interface &interface = getInterface(id);
int ownerFace = interface.getOwnerFace();
return m_normals[ownerFace];
}
/*!
Get cell spacings of the patch.
\result Cell spacings of the patch.
*/
std::array<double, 3> VolCartesian::getSpacing() const
{
return m_cellSpacings;
}
/*!
Switch to the specified memory mode.
\param mode is the memory mode that will be set
*/
void VolCartesian::switchMemoryMode(MemoryMode mode)
{
// Early return if the current memory mode matches the requested one
if (mode == getMemoryMode()) {
return;
}
// Update patch data structures
switch (mode) {
case MemoryMode::MEMORY_NORMAL:
{
// Enable manual adaption
AdaptionMode previousAdaptionMode = getAdaptionMode();
setAdaptionMode(ADAPTION_MANUAL);
// Create the mesh
addVertices();
addCells();
// Restore previous adaption mode
setAdaptionMode(previousAdaptionMode);
break;
}
case MemoryMode::MEMORY_LIGHT:
{
// To put the patch in memory mode we need to reset the generic data
// of the patch, therefore we can call the 'reset' implementation of
// the kernel.
VolumeKernel::reset();
break;
}
}
// Set the requested memory mode
setMemoryMode(mode);
}
/*!
Function to set the memory mode flag.
This function just sets the flag to the specified value.
\param mode is the memory mode that will be set
*/
void VolCartesian::setMemoryMode(MemoryMode mode)
{
m_memoryMode = mode;
}
/*!
Get the current memory mode.
\result The current memory mode.
*/
VolCartesian::MemoryMode VolCartesian::getMemoryMode() const
{
return m_memoryMode;
}
/*!
Get cell spacing along the specificed direction.
\param[in] direction is the direction along which the spacing is
requested
\result The cell spacing along the specificed direction.
*/
double VolCartesian::getSpacing(int direction) const
{