-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsnsolver_hpc.cpp
More file actions
1732 lines (1533 loc) · 88.8 KB
/
snsolver_hpc.cpp
File metadata and controls
1732 lines (1533 loc) · 88.8 KB
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
#ifdef IMPORT_MPI
#include <mpi.h>
#endif
#include "common/config.hpp"
#include "common/io.hpp"
#include "common/mesh.hpp"
#include "kernels/scatteringkernelbase.hpp"
#include "problems/problembase.hpp"
#include "quadratures/quadraturebase.hpp"
#include "solvers/snsolver_hpc.hpp"
#include "toolboxes/textprocessingtoolbox.hpp"
#include <cassert>
SNSolverHPC::SNSolverHPC( Config* settings ) {
#ifdef IMPORT_MPI
// Initialize MPI
MPI_Comm_size( MPI_COMM_WORLD, &_numProcs );
MPI_Comm_rank( MPI_COMM_WORLD, &_rank );
#endif
#ifndef IMPORT_MPI
_numProcs = 1; // default values
_rank = 0;
#endif
_settings = settings;
_currTime = 0.0;
_idx_start_iter = 0;
_nOutputMoments = 2; // Currently only u_1 (x direction) and u_1 (y direction) are supported
// Create Mesh
_mesh = LoadSU2MeshFromFile( settings );
_settings->SetNCells( _mesh->GetNumCells() );
auto quad = QuadratureBase::Create( settings );
_settings->SetNQuadPoints( quad->GetNq() );
_nCells = static_cast<unsigned long>( _mesh->GetNumCells() );
_nNbr = static_cast<unsigned long>( _mesh->GetNumNodesPerCell() );
_nDim = static_cast<unsigned long>( _mesh->GetDim() );
_nNodes = static_cast<unsigned long>( _mesh->GetNumNodes() );
_nq = static_cast<unsigned long>( quad->GetNq() );
_nSys = _nq;
if( static_cast<unsigned long>( _numProcs ) > _nq ) {
ErrorMessages::Error( "The number of processors must be less than or equal to the number of quadrature points.", CURRENT_FUNCTION );
}
if( _numProcs == 1 ) {
_localNSys = _nSys;
_startSysIdx = 0;
_endSysIdx = _nSys;
}
else {
_localNSys = _nSys / ( _numProcs - 1 );
_startSysIdx = _rank * _localNSys;
_endSysIdx = _rank * _localNSys + _localNSys;
if( _rank == _numProcs - 1 ) {
_localNSys = _nSys - _startSysIdx;
_endSysIdx = _nSys;
}
}
// std::cout << "Rank: " << _rank << " startSysIdx: " << _startSysIdx << " endSysIdx: " << _endSysIdx << " localNSys: " << _localNSys <<
// std::endl;
_spatialOrder = _settings->GetSpatialOrder();
_temporalOrder = _settings->GetTemporalOrder();
_areas = std::vector<double>( _nCells );
_normals = std::vector<double>( _nCells * _nNbr * _nDim );
_neighbors = std::vector<unsigned>( _nCells * _nNbr );
_cellMidPoints = std::vector<double>( _nCells * _nDim );
_interfaceMidPoints = std::vector<double>( _nCells * _nNbr * _nDim );
_cellBoundaryTypes = std::vector<BOUNDARY_TYPE>( _nCells );
_relativeInterfaceMidPt = std::vector<double>( _nCells * _nNbr * _nDim );
_relativeCellVertices = std::vector<double>( _nCells * _nNbr * _nDim );
// Slope
_solDx = std::vector<double>( _nCells * _localNSys * _nDim, 0.0 );
_limiter = std::vector<double>( _nCells * _localNSys, 0.0 );
// Physics
_sigmaS = std::vector<double>( _nCells );
_sigmaT = std::vector<double>( _nCells );
_source = std::vector<double>( _nCells * _localNSys );
// Quadrature
_quadPts = std::vector<double>( _localNSys * _nDim );
_quadWeights = std::vector<double>( _localNSys );
// Solution
_sol = std::vector<double>( _nCells * _localNSys );
_flux = std::vector<double>( _nCells * _localNSys );
_scalarFlux = std::vector<double>( _nCells );
_scalarFluxPrevIter = std::vector<double>( _nCells );
_localMaxOrdinateOutflow = std::vector<double>( _nCells );
auto areas = _mesh->GetCellAreas();
auto neighbors = _mesh->GetNeighbours();
auto normals = _mesh->GetNormals();
auto cellMidPts = _mesh->GetCellMidPoints();
auto interfaceMidPts = _mesh->GetInterfaceMidPoints();
auto boundaryTypes = _mesh->GetBoundaryTypes();
auto nodes = _mesh->GetNodes();
auto cells = _mesh->GetCells();
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
_areas[idx_cell] = areas[idx_cell];
}
_dT = ComputeTimeStep( _settings->GetCFL() );
_nIter = unsigned( _settings->GetTEnd() / _dT ) + 1;
auto quadPoints = quad->GetPoints();
auto quadWeights = quad->GetWeights();
_problem = ProblemBase::Create( _settings, _mesh, quad );
auto sigmaT = _problem->GetTotalXS( Vector( _nIter, 0.0 ) );
auto sigmaS = _problem->GetScatteringXS( Vector( _nIter, 0.0 ) );
auto source = _problem->GetExternalSource( Vector( _nIter, 0.0 ) );
// Copy to everything to solver
_mass = 0;
#pragma omp parallel for
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
_quadPts[Idx2D( idx_sys, idx_dim, _nDim )] = quadPoints[idx_sys + _startSysIdx][idx_dim];
}
if( _settings->GetQuadName() == QUAD_GaussLegendreTensorized2D ) {
_quadWeights[idx_sys] =
2.0 * quadWeights[idx_sys + _startSysIdx]; // Rescaling of quadweights TODO: Check if this needs general refactoring
}
else {
_quadWeights[idx_sys] = quadWeights[idx_sys + _startSysIdx]; // Rescaling of quadweights TODO: Check if this needs general refactoring}
}
}
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
_cellBoundaryTypes[idx_cell] = boundaryTypes[idx_cell];
for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
_cellMidPoints[Idx2D( idx_cell, idx_dim, _nDim )] = cellMidPts[idx_cell][idx_dim];
}
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; idx_nbr++ ) {
_neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] = neighbors[idx_cell][idx_nbr];
for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
_normals[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] = normals[idx_cell][idx_nbr][idx_dim];
_interfaceMidPoints[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] = interfaceMidPts[idx_cell][idx_nbr][idx_dim];
_relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] =
_interfaceMidPoints[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] - _cellMidPoints[Idx2D( idx_cell, idx_dim, _nDim )];
_relativeCellVertices[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] =
nodes[cells[idx_cell][idx_nbr]][idx_dim] - cellMidPts[idx_cell][idx_dim];
}
}
_sigmaS[idx_cell] = sigmaS[0][idx_cell];
_sigmaT[idx_cell] = sigmaT[0][idx_cell];
_scalarFlux[idx_cell] = 0;
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_source[Idx2D( idx_cell, idx_sys, _localNSys )] = source[0][idx_cell][0]; // CAREFUL HERE hardcoded to isotropic source
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.0; // initial condition is zero
_scalarFlux[idx_cell] += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
}
}
// Lattice
{
_curAbsorptionLattice = 0;
_totalAbsorptionLattice = 0;
_curMaxAbsorptionLattice = 0;
_curScalarOutflow = 0;
_totalScalarOutflow = 0;
_curMaxOrdinateOutflow = 0;
_curScalarOutflowPeri1 = 0;
_totalScalarOutflowPeri1 = 0;
_curScalarOutflowPeri2 = 0;
_totalScalarOutflowPeri2 = 0;
ComputeCellsPerimeterLattice();
}
// Hohlraum
{
_totalAbsorptionHohlraumCenter = 0;
_totalAbsorptionHohlraumVertical = 0;
_totalAbsorptionHohlraumHorizontal = 0;
_curAbsorptionHohlraumCenter = 0;
_curAbsorptionHohlraumVertical = 0;
_curAbsorptionHohlraumHorizontal = 0;
_varAbsorptionHohlraumGreen = 0;
_avgAbsorptionHohlraumGreenBlockIntegrated = 0;
_varAbsorptionHohlraumGreenBlockIntegrated = 0;
}
if( _settings->GetLoadRestartSolution() )
_idx_start_iter = LoadRestartSolution( _settings->GetOutputFile(),
_sol,
_scalarFlux,
_rank,
_nCells,
_totalAbsorptionHohlraumCenter,
_totalAbsorptionHohlraumVertical,
_totalAbsorptionHohlraumHorizontal,
_totalAbsorptionLattice ) +
1;
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
SetGhostCells();
if( _rank == 0 ) {
PrepareScreenOutput(); // Screen Output
PrepareHistoryOutput(); // History Output
}
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
delete quad;
// Initialiye QOIS
_mass = 0;
_rmsFlux = 0;
{ // Hohlraum
unsigned n_probes = 4;
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
// if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
_probingMoments = std::vector<double>( n_probes * 3, 0. ); // 10 time horizons
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
_probingCellsHohlraum = {
_mesh->GetCellsofBall( -0.4, 0., 0.01 ),
_mesh->GetCellsofBall( 0.4, 0., 0.01 ),
_mesh->GetCellsofBall( 0., -0.5, 0.01 ),
_mesh->GetCellsofBall( 0., 0.5, 0.01 ),
};
}
// else if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
// _probingCellsHohlraum = {
// _mesh->GetCellsofBall( 0.4, 0., 0.01 ),
// _mesh->GetCellsofBall( 0., 0.5, 0.01 ),
// };
// }
// Green
_thicknessGreen = 0.05;
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
_centerGreen = { _settings->GetPosXCenterGreenHohlraum(), _settings->GetPosYCenterGreenHohlraum() };
_cornerUpperLeftGreen = { -0.2 + _centerGreen[0], 0.4 + _centerGreen[1] };
_cornerLowerLeftGreen = { -0.2 + _centerGreen[0], -0.4 + _centerGreen[1] };
_cornerUpperRightGreen = { 0.2 + _centerGreen[0], 0.4 + _centerGreen[1] };
_cornerLowerRightGreen = { 0.2 + _centerGreen[0], -0.4 + _centerGreen[1] };
}
// else {
// _centerGreen = { 0.0, 0.0 };
// _cornerUpperLeftGreen = { 0., 0.4 - _thicknessGreen / 2.0 };
// _cornerLowerLeftGreen = { 0., +_thicknessGreen / 2.0 };
// _cornerUpperRightGreen = { 0.2 - _thicknessGreen / 2.0, 0.4 - _thicknessGreen / 2.0 };
// _cornerLowerRightGreen = { 0.2 - _thicknessGreen / 2.0, 0. + _thicknessGreen / 2.0 };
// }
_nProbingCellsLineGreen = _settings->GetNumProbingCellsLineHohlraum();
_nProbingCellsBlocksGreen = 44;
_absorptionValsBlocksGreen = std::vector<double>( _nProbingCellsBlocksGreen, 0. );
_absorptionValsBlocksGreenIntegrated = std::vector<double>( _nProbingCellsBlocksGreen, 0. );
_absorptionValsLineSegment = std::vector<double>( _nProbingCellsLineGreen, 0.0 );
SetProbingCellsLineGreen(); // ONLY FOR HOHLRAUM
}
}
SNSolverHPC::~SNSolverHPC() {
delete _mesh;
delete _problem;
}
void SNSolverHPC::Solve() {
// --- Preprocessing ---
if( _rank == 0 ) {
PrepareVolumeOutput();
DrawPreSolverOutput();
}
// On restart, continue simulation time from the loaded iteration index.
_curSimTime = static_cast<double>( _idx_start_iter ) * _dT;
auto start = std::chrono::high_resolution_clock::now(); // Start timing
std::chrono::duration<double> duration;
// Loop over energies (pseudo-time of continuous slowing down approach)
for( unsigned iter = (unsigned)_idx_start_iter; iter < _nIter; iter++ ) {
if( iter == _nIter - 1 ) { // last iteration
_dT = _settings->GetTEnd() - iter * _dT;
}
_scalarFluxPrevIter = _scalarFlux;
if( _temporalOrder == 2 ) {
std::vector<double> solRK0( _sol );
( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
FVMUpdate();
( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
FVMUpdate();
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] =
0.5 * ( solRK0[Idx2D( idx_cell, idx_sys, _localNSys )] +
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] ); // Solution averaging with HEUN
}
}
// Keep scalar flux consistent with the final RK2-averaged solution used in postprocessing.
std::vector<double> temp_scalarFluxRK( _nCells, 0.0 );
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
double localScalarFlux = 0.0;
#pragma omp simd reduction( + : localScalarFlux )
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
}
temp_scalarFluxRK[idx_cell] = localScalarFlux;
}
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( temp_scalarFluxRK.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
#else
_scalarFlux = temp_scalarFluxRK;
#endif
}
else {
( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
FVMUpdate();
}
_curSimTime += _dT;
IterPostprocessing();
// --- Wall time measurement
duration = std::chrono::high_resolution_clock::now() - start;
_currTime = std::chrono::duration_cast<std::chrono::duration<double>>( duration ).count();
// --- Write Output ---
if( _rank == 0 ) {
WriteScalarOutput( iter );
// --- Update Scalar Fluxes
// --- Print Output ---
PrintScreenOutput( iter );
PrintHistoryOutput( iter );
}
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
PrintVolumeOutput( iter );
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
#endif
}
// --- Postprocessing ---
if( _rank == 0 ) {
DrawPostSolverOutput();
}
}
void SNSolverHPC::FluxOrder2() {
double const eps = 1e-10;
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) { // Compute Slopes
if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) { // skip ghost cells
// #pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) { //
_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = 1.; // limiter should be zero at boundary//
_solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.; //
double solInterfaceAvg = 0.0;
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) { // Compute slopes and mininum and maximum
unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )]; //
// Slopes
solInterfaceAvg = 0.5 * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] + _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] );
_solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] +=
solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )];
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] +=
solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
} //
_solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] /= _areas[idx_cell];
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] /= _areas[idx_cell];
}
}
}
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) { // Compute Limiter
if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) { // skip ghost cells
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double gaussPoint = 0;
double r = 0;
double minSol = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
double maxSol = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) { // Compute slopes and mininum and maximum
unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];
// Compute ptswise max and minimum solultion values of current and neighbor cells
maxSol = std::max( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], maxSol );
minSol = std::min( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], minSol );
}
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; idx_nbr++ ) { // Compute limiter, see https://arxiv.org/pdf/1710.07187.pdf
// Compute test value at cell vertex, called gaussPt
gaussPoint =
_solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
_relativeCellVertices[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] * _relativeCellVertices[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
// BARTH-JESPERSEN LIMITER
// r = ( gaussPoint > 0 ) ? std::min( ( maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint + eps ), 1.0 )
// : std::min( ( minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint - eps ), 1.0 );
//
// r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
//_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
// VENKATAKRISHNAN LIMITER
double delta1Max = maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
double delta1Min = minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
r = ( gaussPoint > 0 ) ? ( ( delta1Max * delta1Max + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Max ) /
( delta1Max * delta1Max + 2 * gaussPoint * gaussPoint + delta1Max * gaussPoint + _areas[idx_cell] ) /
( gaussPoint + eps )
: ( ( delta1Min * delta1Min + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Min ) /
( delta1Min * delta1Min + 2 * gaussPoint * gaussPoint + delta1Min * gaussPoint + _areas[idx_cell] ) /
( gaussPoint - eps );
r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
}
}
}
else {
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.; // limiter should be zero at boundary
_solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.;
}
}
}
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) { // Compute Flux
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.;
}
// Fluxes
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
// #pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
if( localInner > 0 ) {
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
}
else {
double ghostCellValue = _ghostCells[idx_cell][idx_sys]; // fixed boundary
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
}
}
}
else {
unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )]; // global idx of neighbor cell
// Second order
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
// store flux contribution on psiNew_sigmaS to save memory
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] +=
( localInner > 0 ) ? localInner * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] +
_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] *
( _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
_relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] *
_relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) )
: localInner * ( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] +
_limiter[Idx2D( nbr_glob, idx_sys, _localNSys )] *
( _solDx[Idx3D( nbr_glob, idx_sys, 0, _localNSys, _nDim )] *
( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] -
_cellMidPoints[Idx2D( nbr_glob, 0, _nDim )] ) +
_solDx[Idx3D( nbr_glob, idx_sys, 1, _localNSys, _nDim )] *
( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] -
_cellMidPoints[Idx2D( nbr_glob, 1, _nDim )] ) ) );
}
}
}
}
}
void SNSolverHPC::FluxOrder1() {
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.0; // Reset temporary variable
}
// Fluxes
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
if( localInner > 0 ) {
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
}
else {
double ghostCellValue = _ghostCells[idx_cell][idx_sys]; // fixed boundary
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
}
}
}
else {
unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )]; // global idx of neighbor cell
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
_flux[Idx2D( idx_cell, idx_sys, _localNSys )] += ( localInner > 0 ) ? localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )]
: localInner * _sol[Idx2D( nbr_glob, idx_sys, _localNSys )];
}
}
}
}
}
void SNSolverHPC::FVMUpdate() {
std::vector<double> temp_scalarFlux( _nCells ); // for MPI allreduce
#pragma omp parallel for
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
#pragma omp simd
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
// Update
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] =
( 1 - _dT * _sigmaT[idx_cell] ) * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] -
_dT / _areas[idx_cell] * _flux[Idx2D( idx_cell, idx_sys, _localNSys )] +
_dT * ( _sigmaS[idx_cell] * _scalarFlux[idx_cell] / ( 2 * M_PI ) + _source[Idx2D( idx_cell, idx_sys, _localNSys )] );
}
double localScalarFlux = 0;
#pragma omp simd reduction( + : localScalarFlux )
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] = std::max( _sol[Idx2D( idx_cell, idx_sys, _localNSys )], 0.0 );
localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
}
temp_scalarFlux[idx_cell] = localScalarFlux; // set flux
}
// MPI Allreduce: _scalarFlux
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( temp_scalarFlux.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
#endif
#ifndef IMPORT_MPI
_scalarFlux = temp_scalarFlux;
#endif
}
void SNSolverHPC::IterPostprocessing() {
// ALREDUCE NEEDED
_mass = 0.0;
_rmsFlux = 0.0;
#pragma omp parallel for reduction( + : _mass, _rmsFlux )
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
_mass += _scalarFlux[idx_cell] * _areas[idx_cell];
double diff = _scalarFlux[idx_cell] - _scalarFluxPrevIter[idx_cell];
_rmsFlux += diff * diff;
}
_curAbsorptionLattice = 0.0;
_curScalarOutflow = 0.0;
_curScalarOutflowPeri1 = 0.0;
_curScalarOutflowPeri2 = 0.0;
_curAbsorptionHohlraumCenter = 0.0; // Green and blue areas of symmetric hohlraum
_curAbsorptionHohlraumVertical = 0.0; // Red areas of symmetric hohlraum
_curAbsorptionHohlraumHorizontal = 0.0; // Black areas of symmetric hohlraum
_varAbsorptionHohlraumGreen = 0.0;
double a_g = 0.0;
#pragma omp parallel for reduction( + : _curAbsorptionLattice, \
_curScalarOutflow, \
_curScalarOutflowPeri1, \
_curScalarOutflowPeri2, \
_curAbsorptionHohlraumCenter, \
_curAbsorptionHohlraumVertical, \
_curAbsorptionHohlraumHorizontal, \
a_g ) reduction( max : _curMaxOrdinateOutflow, _curMaxAbsorptionLattice )
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
if( _settings->GetProblemName() == PROBLEM_Lattice || _settings->GetProblemName() == PROBLEM_HalfLattice ) {
if( IsAbsorptionLattice( _cellMidPoints[Idx2D( idx_cell, 0, _nDim )], _cellMidPoints[Idx2D( idx_cell, 1, _nDim )] ) ) {
double sigmaAPsi = _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
_curAbsorptionLattice += sigmaAPsi;
_curMaxAbsorptionLattice = ( _curMaxAbsorptionLattice < sigmaAPsi ) ? sigmaAPsi : _curMaxAbsorptionLattice;
}
}
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) { //} || _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
_curAbsorptionLattice += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
if( x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum() ) {
_curAbsorptionHohlraumCenter += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
}
if( ( x < _settings->GetPosRedLeftBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
y < _settings->GetPosRedLeftTopHohlraum() ) ||
( x > _settings->GetPosRedRightBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
y < _settings->GetPosRedRightTopHohlraum() ) ) {
_curAbsorptionHohlraumVertical += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
}
if( y > 0.6 || y < -0.6 ) {
_curAbsorptionHohlraumHorizontal += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
}
// Variation in absorption of center (part 1)
// green area 1 (lower boundary)
bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
// green area 2 (upper boundary)
bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
// green area 3 (left boundary)
bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
// green area 4 (right boundary)
bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
if( green1 || green2 || green3 || green4 ) {
a_g += ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _scalarFlux[idx_cell] * _areas[idx_cell] /
( 44 * 0.05 * 0.05 ); // divisor is area of the green
}
}
if( _settings->GetProblemName() == PROBLEM_Lattice ) {
// Outflow out of inner and middle perimeter
if( _isPerimeterLatticeCell1[idx_cell] ) { // inner
for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter1[idx_cell].size(); ++idx_nbr_helper ) {
#pragma omp simd reduction( + : _curScalarOutflowPeri1 )
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
_normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] *
_normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
// Find outward facing transport directions
if( localInner > 0.0 ) {
_curScalarOutflowPeri1 +=
localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys]; // Integrate flux
}
}
}
}
if( _isPerimeterLatticeCell2[idx_cell] ) { // middle
for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter2[idx_cell].size(); ++idx_nbr_helper ) {
#pragma omp simd reduction( + : _curScalarOutflowPeri2 )
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
_normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] *
_normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
// Find outward facing transport directions
if( localInner > 0.0 ) {
_curScalarOutflowPeri2 +=
localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys]; // Integrate flux
}
}
}
}
}
// Outflow out of domain
if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN ) {
// Iterate over face cell faces
double currOrdinatewiseOutflow = 0.0;
for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
// Find face that points outward
if( _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
#pragma omp simd reduction( + : _curScalarOutflow ) reduction( max : _curMaxOrdinateOutflow )
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
// Find outward facing transport directions
if( localInner > 0.0 ) {
_curScalarOutflow +=
localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys]; // Integrate flux
currOrdinatewiseOutflow =
_sol[Idx2D( idx_cell, idx_sys, _localNSys )] * localInner /
sqrt( (
_normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
_normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) );
_curMaxOrdinateOutflow =
( currOrdinatewiseOutflow > _curMaxOrdinateOutflow ) ? currOrdinatewiseOutflow : _curMaxOrdinateOutflow;
}
}
}
}
}
}
// MPI Allreduce
#ifdef IMPORT_MPI
double tmp_curScalarOutflow = 0.0;
double tmp_curScalarOutflowPeri1 = 0.0;
double tmp_curScalarOutflowPeri2 = 0.0;
double tmp_curMaxOrdinateOutflow = 0.0;
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( &_curScalarOutflow, &tmp_curScalarOutflow, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
_curScalarOutflow = tmp_curScalarOutflow;
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( &_curScalarOutflowPeri1, &tmp_curScalarOutflowPeri1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
_curScalarOutflowPeri1 = tmp_curScalarOutflowPeri1;
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( &_curScalarOutflowPeri2, &tmp_curScalarOutflowPeri2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
_curScalarOutflowPeri2 = tmp_curScalarOutflowPeri2;
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( &_curMaxOrdinateOutflow, &tmp_curMaxOrdinateOutflow, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
_curMaxOrdinateOutflow = tmp_curMaxOrdinateOutflow;
MPI_Barrier( MPI_COMM_WORLD );
#endif
// Variation absorption (part II)
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
unsigned n_probes = 4;
std::vector<double> temp_probingMoments( 3 * n_probes ); // for MPI allreduce
#pragma omp parallel for reduction( + : _varAbsorptionHohlraumGreen )
for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
// green area 1 (lower boundary)
bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
// green area 2 (upper boundary)
bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
// green area 3 (left boundary)
bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
// green area 4 (right boundary)
bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
if( green1 || green2 || green3 || green4 ) {
_varAbsorptionHohlraumGreen += ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) *
( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) * _areas[idx_cell];
}
}
// Probes value moments
// #pragma omp parallel for
for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) { // Loop over probing cells
temp_probingMoments[Idx2D( idx_probe, 0, 3 )] = 0.0;
temp_probingMoments[Idx2D( idx_probe, 1, 3 )] = 0.0;
temp_probingMoments[Idx2D( idx_probe, 2, 3 )] = 0.0;
// for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
// std::cout << idx_ball << _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI ) << std::endl;
//}
for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
temp_probingMoments[Idx2D( idx_probe, 0, 3 )] += _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
_quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] /
( 0.01 * 0.01 * M_PI );
temp_probingMoments[Idx2D( idx_probe, 1, 3 )] +=
_quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
_quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
temp_probingMoments[Idx2D( idx_probe, 2, 3 )] +=
_quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
_quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
}
}
}
#ifdef IMPORT_MPI
MPI_Barrier( MPI_COMM_WORLD );
MPI_Allreduce( temp_probingMoments.data(), _probingMoments.data(), 3 * n_probes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
MPI_Barrier( MPI_COMM_WORLD );
#endif
#ifndef IMPORT_MPI
for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) { // Loop over probing cells
_probingMoments[Idx2D( idx_probe, 0, 3 )] = temp_probingMoments[Idx2D( idx_probe, 0, 3 )];
_probingMoments[Idx2D( idx_probe, 1, 3 )] = temp_probingMoments[Idx2D( idx_probe, 1, 3 )];
_probingMoments[Idx2D( idx_probe, 2, 3 )] = temp_probingMoments[Idx2D( idx_probe, 2, 3 )];
}
#endif
}
// probe values green
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
ComputeQOIsGreenProbingLine();
}
// Update time integral values on rank 0
if( _rank == 0 ) {
constexpr double greenBlockArea = 0.05 * 0.05;
_totalScalarOutflow += _curScalarOutflow * _dT;
_totalScalarOutflowPeri1 += _curScalarOutflowPeri1 * _dT;
_totalScalarOutflowPeri2 += _curScalarOutflowPeri2 * _dT;
_totalAbsorptionLattice += _curAbsorptionLattice * _dT;
_totalAbsorptionHohlraumCenter += _curAbsorptionHohlraumCenter * _dT;
_totalAbsorptionHohlraumVertical += _curAbsorptionHohlraumVertical * _dT;
_totalAbsorptionHohlraumHorizontal += _curAbsorptionHohlraumHorizontal * _dT;
for( unsigned i = 0; i < _nProbingCellsBlocksGreen; ++i ) {
_absorptionValsBlocksGreenIntegrated[i] += _dT * _absorptionValsBlocksGreen[i] / greenBlockArea;
}
_avgAbsorptionHohlraumGreenBlockIntegrated = 0.0;
_varAbsorptionHohlraumGreenBlockIntegrated = 0.0;
for( unsigned i = 0; i < _nProbingCellsBlocksGreen; ++i ) {
_avgAbsorptionHohlraumGreenBlockIntegrated += _absorptionValsBlocksGreenIntegrated[i];
}
_avgAbsorptionHohlraumGreenBlockIntegrated /= static_cast<double>( _nProbingCellsBlocksGreen );
for( unsigned i = 0; i < _nProbingCellsBlocksGreen; ++i ) {
const double diff = _absorptionValsBlocksGreenIntegrated[i] - _avgAbsorptionHohlraumGreenBlockIntegrated;
_varAbsorptionHohlraumGreenBlockIntegrated += diff * diff;
}
_varAbsorptionHohlraumGreenBlockIntegrated /= static_cast<double>( _nProbingCellsBlocksGreen );
_rmsFlux = sqrt( _rmsFlux );
}
}
bool SNSolverHPC::IsAbsorptionLattice( double x, double y ) const {
// Check whether pos is inside absorbing squares
double xy_corrector = -3.5;
std::vector<double> lbounds{ 1 + xy_corrector, 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector };
std::vector<double> ubounds{ 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector, 6 + xy_corrector };
for( unsigned k = 0; k < lbounds.size(); ++k ) {
for( unsigned l = 0; l < lbounds.size(); ++l ) {
if( ( l + k ) % 2 == 1 || ( k == 2 && l == 2 ) || ( k == 2 && l == 4 ) ) continue;
if( x >= lbounds[k] && x <= ubounds[k] && y >= lbounds[l] && y <= ubounds[l] ) {
return true;
}
}
}
return false;
}
// --- Helper ---
double SNSolverHPC::ComputeTimeStep( double cfl ) const {
// for pseudo 1D, set timestep to dx
double dx, dy;
switch( _settings->GetProblemName() ) {
case PROBLEM_Checkerboard1D:
dx = 7.0 / (double)_nCells;
dy = 0.3;
return cfl * ( dx * dy ) / ( dx + dy );
break;
case PROBLEM_Linesource1D: // Fallthrough
case PROBLEM_Meltingcube1D: // Fallthrough
case PROBLEM_Aircavity1D:
dx = 3.0 / (double)_nCells;
dy = 0.3;
return cfl * ( dx * dy ) / ( dx + dy );
break;
default: break; // 2d as normal
}
// 2D case
double charSize = __DBL_MAX__; // minimum char size of all mesh cells in the mesh
#pragma omp parallel for reduction( min : charSize )
for( unsigned long j = 0; j < _nCells; j++ ) {
double currCharSize = sqrt( _areas[j] );
if( currCharSize < charSize ) {
charSize = currCharSize;
}
}
if( _rank == 0 ) {
auto log = spdlog::get( "event" );
std::string line = "| Smallest characteristic length of a grid cell in this mesh: " + std::to_string( charSize );
log->info( line );
line = "| Corresponding maximal time-step: " + std::to_string( cfl * charSize );
log->info( line );
}
return cfl * charSize;
}
// --- IO ----
void SNSolverHPC::PrepareScreenOutput() {
unsigned nFields = (unsigned)_settings->GetNScreenOutput();
_screenOutputFieldNames.resize( nFields );
_screenOutputFields.resize( nFields );
// Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
// Prepare all Output Fields per group
// Different procedure, depending on the Group...
switch( _settings->GetScreenOutput()[idx_field] ) {
case MASS: _screenOutputFieldNames[idx_field] = "Mass"; break;
case ITER: _screenOutputFieldNames[idx_field] = "Iter"; break;
case SIM_TIME: _screenOutputFieldNames[idx_field] = "Sim time"; break;
case WALL_TIME: _screenOutputFieldNames[idx_field] = "Wall time [s]"; break;
case RMS_FLUX: _screenOutputFieldNames[idx_field] = "RMS flux"; break;
case VTK_OUTPUT: _screenOutputFieldNames[idx_field] = "VTK out"; break;
case CSV_OUTPUT: _screenOutputFieldNames[idx_field] = "CSV out"; break;
case CUR_OUTFLOW: _screenOutputFieldNames[idx_field] = "Cur. outflow"; break;
case TOTAL_OUTFLOW: _screenOutputFieldNames[idx_field] = "Tot. outflow"; break;
case CUR_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Cur. outflow P1"; break;
case TOTAL_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Tot. outflow P1"; break;
case CUR_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Cur. outflow P2"; break;
case TOTAL_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Tot. outflow P2"; break;
case MAX_OUTFLOW: _screenOutputFieldNames[idx_field] = "Max outflow"; break;
case CUR_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Cur. absorption"; break;
case TOTAL_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Tot. absorption"; break;
case MAX_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Max absorption"; break;
case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFieldNames[idx_field] = "Tot. abs. center"; break;
case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFieldNames[idx_field] = "Tot. abs. vertical wall"; break;
case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFieldNames[idx_field] = "Tot. abs. horizontal wall"; break;
case PROBE_MOMENT_TIME_TRACE:
_screenOutputFieldNames[idx_field] = "Probe 1 u_0";
idx_field++;
_screenOutputFieldNames[idx_field] = "Probe 2 u_0";
if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
idx_field++;
_screenOutputFieldNames[idx_field] = "Probe 3 u_0";
idx_field++;
_screenOutputFieldNames[idx_field] = "Probe 4 u_0";
}
break;
case VAR_ABSORPTION_GREEN: _screenOutputFieldNames[idx_field] = "Var. absorption green"; break;
case AVG_ABSORPTION_GREEN_BLOCK_INTEGRATED: _screenOutputFieldNames[idx_field] = "A_G"; break;
case VAR_ABSORPTION_GREEN_BLOCK_INTEGRATED: _screenOutputFieldNames[idx_field] = "V_G"; break;
default: ErrorMessages::Error( "Screen output field not defined!", CURRENT_FUNCTION ); break;
}
}
}
void SNSolverHPC::WriteScalarOutput( unsigned idx_iter ) {
unsigned n_probes = 4;
unsigned nFields = (unsigned)_settings->GetNScreenOutput();
const VectorVector probingMoments = _problem->GetCurrentProbeMoment();
// -- Screen Output
for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
// Prepare all Output Fields per group
// Different procedure, depending on the Group...
switch( _settings->GetScreenOutput()[idx_field] ) {
case MASS: _screenOutputFields[idx_field] = _mass; break;
case ITER: _screenOutputFields[idx_field] = idx_iter; break;
case SIM_TIME: _screenOutputFields[idx_field] = _curSimTime; break;
case WALL_TIME: _screenOutputFields[idx_field] = _currTime; break;
case RMS_FLUX: _screenOutputFields[idx_field] = _rmsFlux; break;
case VTK_OUTPUT:
_screenOutputFields[idx_field] = 0;
if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
_screenOutputFields[idx_field] = 1;
}
break;
case CSV_OUTPUT:
_screenOutputFields[idx_field] = 0;
if( ( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
_screenOutputFields[idx_field] = 1;
}
break;
case CUR_OUTFLOW: _screenOutputFields[idx_field] = _curScalarOutflow; break;
case TOTAL_OUTFLOW: _screenOutputFields[idx_field] = _totalScalarOutflow; break;
case CUR_OUTFLOW_P1: _screenOutputFields[idx_field] = _curScalarOutflowPeri1; break;
case TOTAL_OUTFLOW_P1: _screenOutputFields[idx_field] = _totalScalarOutflowPeri1; break;