• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CSMMLab / KiT-RT / #120

12 Feb 2026 01:19AM UTC coverage: 57.164% (+0.05%) from 57.119%
#120

push

travis-ci

web-flow
Bugfixes in HPC SN Solver (#61)

* fix lattice perimeter definitions

* fix max outflow MPI

* fix output of varAbsorption

* fixed rms bug with mpi exec

* fix linspace vulnerability

* fixed MPI flag

* recomputation of scalar flux missing after heun averaging

* more guardrails around greenprobing

* made the probing blocks move with the center of the capsule

* update restart sim time

* fixed validation tests

26 of 27 new or added lines in 1 file covered. (96.3%)

5458 of 9548 relevant lines covered (57.16%)

31280.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.03
/src/solvers/snsolver_hpc.cpp
1
#ifdef IMPORT_MPI
2
#include <mpi.h>
3
#endif
4
#include "common/config.hpp"
5
#include "common/io.hpp"
6
#include "common/mesh.hpp"
7
#include "kernels/scatteringkernelbase.hpp"
8
#include "problems/problembase.hpp"
9
#include "quadratures/quadraturebase.hpp"
10
#include "solvers/snsolver_hpc.hpp"
11
#include "toolboxes/textprocessingtoolbox.hpp"
12
#include <cassert>
13

14
SNSolverHPC::SNSolverHPC( Config* settings ) {
2✔
15
#ifdef IMPORT_MPI
16
    // Initialize MPI
17
    MPI_Comm_size( MPI_COMM_WORLD, &_numProcs );
18
    MPI_Comm_rank( MPI_COMM_WORLD, &_rank );
19
#endif
20
#ifndef IMPORT_MPI
21
    _numProcs = 1;    // default values
2✔
22
    _rank     = 0;
2✔
23
#endif
24
    _settings       = settings;
2✔
25
    _currTime       = 0.0;
2✔
26
    _idx_start_iter = 0;
2✔
27
    _nOutputMoments = 2;    //  Currently only u_1 (x direction) and u_1 (y direction) are supported
2✔
28
    // Create Mesh
29
    _mesh = LoadSU2MeshFromFile( settings );
2✔
30
    _settings->SetNCells( _mesh->GetNumCells() );
2✔
31
    auto quad = QuadratureBase::Create( settings );
2✔
32
    _settings->SetNQuadPoints( quad->GetNq() );
2✔
33

34
    _nCells = static_cast<unsigned long>( _mesh->GetNumCells() );
2✔
35
    _nNbr   = static_cast<unsigned long>( _mesh->GetNumNodesPerCell() );
2✔
36
    _nDim   = static_cast<unsigned long>( _mesh->GetDim() );
2✔
37
    _nNodes = static_cast<unsigned long>( _mesh->GetNumNodes() );
2✔
38

39
    _nq   = static_cast<unsigned long>( quad->GetNq() );
2✔
40
    _nSys = _nq;
2✔
41

42
    if( static_cast<unsigned long>( _numProcs ) > _nq ) {
2✔
43
        ErrorMessages::Error( "The number of processors must be less than or equal to the number of quadrature points.", CURRENT_FUNCTION );
×
44
    }
45

46
    if( _numProcs == 1 ) {
2✔
47
        _localNSys   = _nSys;
2✔
48
        _startSysIdx = 0;
2✔
49
        _endSysIdx   = _nSys;
2✔
50
    }
51
    else {
52
        _localNSys   = _nSys / ( _numProcs - 1 );
×
53
        _startSysIdx = _rank * _localNSys;
×
54
        _endSysIdx   = _rank * _localNSys + _localNSys;
×
55

56
        if( _rank == _numProcs - 1 ) {
×
57
            _localNSys = _nSys - _startSysIdx;
×
58
            _endSysIdx = _nSys;
×
59
        }
60
    }
61

62
    // std::cout << "Rank: " << _rank << " startSysIdx: " << _startSysIdx << " endSysIdx: " << _endSysIdx <<  " localNSys: " << _localNSys <<
63
    // std::endl;
64

65
    _spatialOrder  = _settings->GetSpatialOrder();
2✔
66
    _temporalOrder = _settings->GetTemporalOrder();
2✔
67

68
    _areas                  = std::vector<double>( _nCells );
2✔
69
    _normals                = std::vector<double>( _nCells * _nNbr * _nDim );
2✔
70
    _neighbors              = std::vector<unsigned>( _nCells * _nNbr );
2✔
71
    _cellMidPoints          = std::vector<double>( _nCells * _nDim );
2✔
72
    _interfaceMidPoints     = std::vector<double>( _nCells * _nNbr * _nDim );
2✔
73
    _cellBoundaryTypes      = std::vector<BOUNDARY_TYPE>( _nCells );
2✔
74
    _relativeInterfaceMidPt = std::vector<double>( _nCells * _nNbr * _nDim );
2✔
75
    _relativeCellVertices   = std::vector<double>( _nCells * _nNbr * _nDim );
2✔
76

77
    // Slope
78
    _solDx   = std::vector<double>( _nCells * _localNSys * _nDim, 0.0 );
2✔
79
    _limiter = std::vector<double>( _nCells * _localNSys, 0.0 );
2✔
80

81
    // Physics
82
    _sigmaS = std::vector<double>( _nCells );
2✔
83
    _sigmaT = std::vector<double>( _nCells );
2✔
84
    _source = std::vector<double>( _nCells * _localNSys );
2✔
85

86
    // Quadrature
87
    _quadPts     = std::vector<double>( _localNSys * _nDim );
2✔
88
    _quadWeights = std::vector<double>( _localNSys );
2✔
89

90
    // Solution
91
    _sol  = std::vector<double>( _nCells * _localNSys );
2✔
92
    _flux = std::vector<double>( _nCells * _localNSys );
2✔
93

94
    _scalarFlux              = std::vector<double>( _nCells );
2✔
95
    _localMaxOrdinateOutflow = std::vector<double>( _nCells );
2✔
96

97
    auto areas           = _mesh->GetCellAreas();
4✔
98
    auto neighbors       = _mesh->GetNeighbours();
4✔
99
    auto normals         = _mesh->GetNormals();
4✔
100
    auto cellMidPts      = _mesh->GetCellMidPoints();
4✔
101
    auto interfaceMidPts = _mesh->GetInterfaceMidPoints();
4✔
102
    auto boundaryTypes   = _mesh->GetBoundaryTypes();
4✔
103
    auto nodes           = _mesh->GetNodes();
4✔
104
    auto cells           = _mesh->GetCells();
4✔
105

106
#pragma omp parallel for
2✔
107
    for( unsigned long idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
108
        _areas[idx_cell] = areas[idx_cell];
109
    }
110

111
    _dT    = ComputeTimeStep( _settings->GetCFL() );
2✔
112
    _nIter = unsigned( _settings->GetTEnd() / _dT ) + 1;
2✔
113

114
    auto quadPoints  = quad->GetPoints();
4✔
115
    auto quadWeights = quad->GetWeights();
4✔
116

117
    _problem    = ProblemBase::Create( _settings, _mesh, quad );
2✔
118
    auto sigmaT = _problem->GetTotalXS( Vector( _nIter, 0.0 ) );
4✔
119
    auto sigmaS = _problem->GetScatteringXS( Vector( _nIter, 0.0 ) );
4✔
120
    auto source = _problem->GetExternalSource( Vector( _nIter, 0.0 ) );
4✔
121

122
    // Copy to everything to solver
123
    _mass = 0;
2✔
124
#pragma omp parallel for
2✔
125
    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
126
        for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
127
            _quadPts[Idx2D( idx_sys, idx_dim, _nDim )] = quadPoints[idx_sys + _startSysIdx][idx_dim];
128
        }
129
        if( _settings->GetQuadName() == QUAD_GaussLegendreTensorized2D ) {
130
            _quadWeights[idx_sys] =
131
                2.0 * quadWeights[idx_sys + _startSysIdx];    // Rescaling of quadweights TODO: Check if this needs general refactoring
132
        }
133
        else {
134
            _quadWeights[idx_sys] = quadWeights[idx_sys + _startSysIdx];    // Rescaling of quadweights TODO: Check if this needs general refactoring}
135
        }
136
    }
137

138
#pragma omp parallel for
2✔
139
    for( unsigned long idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
140
        _cellBoundaryTypes[idx_cell] = boundaryTypes[idx_cell];
141

142
        for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
143
            _cellMidPoints[Idx2D( idx_cell, idx_dim, _nDim )] = cellMidPts[idx_cell][idx_dim];
144
        }
145

146
        for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; idx_nbr++ ) {
147

148
            _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] = neighbors[idx_cell][idx_nbr];
149

150
            for( unsigned long idx_dim = 0; idx_dim < _nDim; idx_dim++ ) {
151
                _normals[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )]            = normals[idx_cell][idx_nbr][idx_dim];
152
                _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] = interfaceMidPts[idx_cell][idx_nbr][idx_dim];
153
                _relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] =
154
                    _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] - _cellMidPoints[Idx2D( idx_cell, idx_dim, _nDim )];
155
                _relativeCellVertices[Idx3D( idx_cell, idx_nbr, idx_dim, _nNbr, _nDim )] =
156
                    nodes[cells[idx_cell][idx_nbr]][idx_dim] - cellMidPts[idx_cell][idx_dim];
157
            }
158
        }
159

160
        _sigmaS[idx_cell]     = sigmaS[0][idx_cell];
161
        _sigmaT[idx_cell]     = sigmaT[0][idx_cell];
162
        _scalarFlux[idx_cell] = 0;
163

164
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
165
            _source[Idx2D( idx_cell, idx_sys, _localNSys )] = source[0][idx_cell][0];    // CAREFUL HERE hardcoded to isotropic source
166
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )]    = 0.0;                       // initial condition is zero
167

168
            _scalarFlux[idx_cell] += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
169
        }
170
        // _mass += _scalarFlux[idx_cell] * _areas[idx_cell];
171
    }
172

173
    // Lattice
174
    {
175
        _curAbsorptionLattice    = 0;
2✔
176
        _totalAbsorptionLattice  = 0;
2✔
177
        _curMaxAbsorptionLattice = 0;
2✔
178
        _curScalarOutflow        = 0;
2✔
179
        _totalScalarOutflow      = 0;
2✔
180
        _curMaxOrdinateOutflow   = 0;
2✔
181
        _curScalarOutflowPeri1   = 0;
2✔
182
        _totalScalarOutflowPeri1 = 0;
2✔
183
        _curScalarOutflowPeri2   = 0;
2✔
184
        _totalScalarOutflowPeri2 = 0;
2✔
185
        ComputeCellsPerimeterLattice();
2✔
186
    }
187
    // Hohlraum
188
    {
189
        _totalAbsorptionHohlraumCenter     = 0;
2✔
190
        _totalAbsorptionHohlraumVertical   = 0;
2✔
191
        _totalAbsorptionHohlraumHorizontal = 0;
2✔
192
        _curAbsorptionHohlraumCenter       = 0;
2✔
193
        _curAbsorptionHohlraumVertical     = 0;
2✔
194
        _curAbsorptionHohlraumHorizontal   = 0;
2✔
195
        _varAbsorptionHohlraumGreen        = 0;
2✔
196
    }
197

198
    if( _settings->GetLoadRestartSolution() )
2✔
199
        _idx_start_iter = LoadRestartSolution( _settings->GetOutputFile(),
×
200
                                               _sol,
×
201
                                               _scalarFlux,
×
202
                                               _rank,
203
                                               _nCells,
204
                                               _totalAbsorptionHohlraumCenter,
×
205
                                               _totalAbsorptionHohlraumVertical,
×
206
                                               _totalAbsorptionHohlraumHorizontal,
×
207
                                               _totalAbsorptionLattice ) +
×
208
                          1;
209

210
#ifdef IMPORT_MPI
211
    MPI_Barrier( MPI_COMM_WORLD );
212
#endif
213
    SetGhostCells();
2✔
214
    if( _rank == 0 ) {
2✔
215
        PrepareScreenOutput();     // Screen Output
2✔
216
        PrepareHistoryOutput();    // History Output
2✔
217
    }
218
#ifdef IMPORT_MPI
219
    MPI_Barrier( MPI_COMM_WORLD );
220
#endif
221
    delete quad;
2✔
222

223
    // Initialiye QOIS
224
    _mass    = 0;
2✔
225
    _rmsFlux = 0;
2✔
226

227
    {    // Hohlraum
228

229
        unsigned n_probes = 4;
2✔
230
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
2✔
231
        // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
232

233
        _probingMoments = std::vector<double>( n_probes * 3, 0. );    // 10 time horizons
2✔
234

235
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
2✔
236
            _probingCellsHohlraum = {
5✔
237
                _mesh->GetCellsofBall( -0.4, 0., 0.01 ),
1✔
238
                _mesh->GetCellsofBall( 0.4, 0., 0.01 ),
1✔
239
                _mesh->GetCellsofBall( 0., -0.5, 0.01 ),
1✔
240
                _mesh->GetCellsofBall( 0., 0.5, 0.01 ),
1✔
241
            };
5✔
242
        }
243
        // else if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
244
        //     _probingCellsHohlraum = {
245
        //         _mesh->GetCellsofBall( 0.4, 0., 0.01 ),
246
        //         _mesh->GetCellsofBall( 0., 0.5, 0.01 ),
247
        //     };
248
        // }
249

250
        // Green
251
        _thicknessGreen = 0.05;
2✔
252

253
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
2✔
254
            _centerGreen           = { _settings->GetPosXCenterGreenHohlraum(), _settings->GetPosYCenterGreenHohlraum() };
1✔
255
            _cornerUpperLeftGreen  = { -0.2 + _centerGreen[0], 0.4 + _centerGreen[1] };
1✔
256
            _cornerLowerLeftGreen  = { -0.2 + _centerGreen[0], -0.4 + _centerGreen[1] };
1✔
257
            _cornerUpperRightGreen = { 0.2 + _centerGreen[0], 0.4 + _centerGreen[1] };
1✔
258
            _cornerLowerRightGreen = { 0.2 + _centerGreen[0], -0.4 + _centerGreen[1] };
1✔
259
        }
260
        // else {
261
        //     _centerGreen           = { 0.0, 0.0 };
262
        //     _cornerUpperLeftGreen  = { 0., 0.4 - _thicknessGreen / 2.0 };
263
        //     _cornerLowerLeftGreen  = { 0., +_thicknessGreen / 2.0 };
264
        //     _cornerUpperRightGreen = { 0.2 - _thicknessGreen / 2.0, 0.4 - _thicknessGreen / 2.0 };
265
        //     _cornerLowerRightGreen = { 0.2 - _thicknessGreen / 2.0, 0. + _thicknessGreen / 2.0 };
266
        // }
267

268
        _nProbingCellsLineGreen = _settings->GetNumProbingCellsLineHohlraum();
2✔
269

270
        _nProbingCellsBlocksGreen  = 44;
2✔
271
        _absorptionValsBlocksGreen = std::vector<double>( _nProbingCellsBlocksGreen, 0. );
2✔
272
        _absorptionValsLineSegment = std::vector<double>( _nProbingCellsLineGreen, 0.0 );
2✔
273

274
        SetProbingCellsLineGreen();    // ONLY FOR HOHLRAUM
2✔
275
    }
276
}
2✔
277

278
SNSolverHPC::~SNSolverHPC() {
2✔
279
    delete _mesh;
2✔
280
    delete _problem;
2✔
281
}
2✔
282

283
void SNSolverHPC::Solve() {
2✔
284

285
    // --- Preprocessing ---
286
    if( _rank == 0 ) {
2✔
287
        PrepareVolumeOutput();
2✔
288
        DrawPreSolverOutput();
2✔
289
    }
290
    // On restart, continue simulation time from the loaded iteration index.
291
    _curSimTime = static_cast<double>( _idx_start_iter ) * _dT;
2✔
292
    auto start  = std::chrono::high_resolution_clock::now();    // Start timing
2✔
293

294
    std::chrono::duration<double> duration;
295
    // Loop over energies (pseudo-time of continuous slowing down approach)
296
    for( unsigned iter = (unsigned)_idx_start_iter; iter < _nIter; iter++ ) {
10✔
297

298
        if( iter == _nIter - 1 ) {    // last iteration
8✔
299
            _dT = _settings->GetTEnd() - iter * _dT;
2✔
300
        }
301
        if( _temporalOrder == 2 ) {
8✔
302
            std::vector<double> solRK0( _sol );
16✔
303
            ( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
8✔
304
            FVMUpdate();
8✔
305
            ( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
8✔
306
            FVMUpdate();
8✔
307
#pragma omp parallel for
8✔
308
            for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
309
#pragma omp simd
310
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
311
                    _sol[Idx2D( idx_cell, idx_sys, _localNSys )] =
312
                        0.5 * ( solRK0[Idx2D( idx_cell, idx_sys, _localNSys )] +
313
                                _sol[Idx2D( idx_cell, idx_sys, _localNSys )] );    // Solution averaging with HEUN
314
                }
315
            }
316

317
            // Keep scalar flux consistent with the final RK2-averaged solution used in postprocessing.
318
            std::vector<double> temp_scalarFluxRK( _nCells, 0.0 );
16✔
319
#pragma omp parallel for
8✔
320
            for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
321
                double localScalarFlux = 0.0;
322
#pragma omp simd reduction( + : localScalarFlux )
323
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
324
                    localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
325
                }
326
                temp_scalarFluxRK[idx_cell] = localScalarFlux;
327
            }
328
#ifdef IMPORT_MPI
329
            MPI_Barrier( MPI_COMM_WORLD );
330
            MPI_Allreduce( temp_scalarFluxRK.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
331
            MPI_Barrier( MPI_COMM_WORLD );
332
#else
333
            _scalarFlux = temp_scalarFluxRK;
8✔
334
#endif
335
        }
336
        else {
337

338
            ( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
×
339
            FVMUpdate();
×
340
        }
341
        _curSimTime += _dT;
8✔
342
        IterPostprocessing();
8✔
343
        // --- Wall time measurement
344
        duration  = std::chrono::high_resolution_clock::now() - start;
8✔
345
        _currTime = std::chrono::duration_cast<std::chrono::duration<double>>( duration ).count();
8✔
346

347
        // --- Write Output ---
348
        if( _rank == 0 ) {
8✔
349

350
            WriteScalarOutput( iter );
8✔
351

352
            // --- Update Scalar Fluxes
353

354
            // --- Print Output ---
355
            PrintScreenOutput( iter );
8✔
356
            PrintHistoryOutput( iter );
8✔
357
        }
358
#ifdef IMPORT_MPI
359
        MPI_Barrier( MPI_COMM_WORLD );
360
#endif
361

362
        PrintVolumeOutput( iter );
8✔
363
#ifdef IMPORT_MPI
364
        MPI_Barrier( MPI_COMM_WORLD );
365
#endif
366
    }
367
    // --- Postprocessing ---
368
    if( _rank == 0 ) {
2✔
369
        DrawPostSolverOutput();
2✔
370
    }
371
}
2✔
372

373
void SNSolverHPC::FluxOrder2() {
16✔
374

375
    double const eps = 1e-10;
16✔
376

377
#pragma omp parallel for
16✔
378
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {            // Compute Slopes
379
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) {                // skip ghost cells
380
                                                                                   // #pragma omp simd
381
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {    //
382
                _limiter[Idx2D( idx_cell, idx_sys, _localNSys )]         = 1.;     // limiter should be zero at boundary//
383
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
384
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.;    //
385
                double solInterfaceAvg                                   = 0.0;
386
                for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {            // Compute slopes and mininum and maximum
387
                    unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    //
388
                    // Slopes
389
                    solInterfaceAvg = 0.5 * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] + _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] );
390
                    _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] +=
391
                        solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )];
392
                    _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] +=
393
                        solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
394
                }    //
395
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] /= _areas[idx_cell];
396
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] /= _areas[idx_cell];
397
            }
398
        }
399
    }
400
#pragma omp parallel for
16✔
401
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {    // Compute Limiter
402
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) {        // skip ghost cells
403

404
#pragma omp simd
405
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
406

407
                double gaussPoint = 0;
408
                double r          = 0;
409
                double minSol     = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
410
                double maxSol     = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
411

412
                for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {    // Compute slopes and mininum and maximum
413
                    unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];
414
                    // Compute ptswise max and minimum solultion values of current and neighbor cells
415
                    maxSol = std::max( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], maxSol );
416
                    minSol = std::min( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], minSol );
417
                }
418

419
                for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; idx_nbr++ ) {    // Compute limiter, see https://arxiv.org/pdf/1710.07187.pdf
420

421
                    // Compute test value at cell vertex, called gaussPt
422
                    gaussPoint =
423
                        _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
424
                            _relativeCellVertices[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
425
                        _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] * _relativeCellVertices[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
426

427
                    // BARTH-JESPERSEN LIMITER
428
                    // r = ( gaussPoint > 0 ) ? std::min( ( maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint + eps ), 1.0 )
429
                    //                       : std::min( ( minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint - eps ), 1.0 );
430
                    //
431
                    // r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
432
                    //_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
433

434
                    // VENKATAKRISHNAN LIMITER
435
                    double delta1Max = maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
436
                    double delta1Min = minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
437

438
                    r = ( gaussPoint > 0 ) ? ( ( delta1Max * delta1Max + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Max ) /
439
                                                 ( delta1Max * delta1Max + 2 * gaussPoint * gaussPoint + delta1Max * gaussPoint + _areas[idx_cell] ) /
440
                                                 ( gaussPoint + eps )
441
                                           : ( ( delta1Min * delta1Min + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Min ) /
442
                                                 ( delta1Min * delta1Min + 2 * gaussPoint * gaussPoint + delta1Min * gaussPoint + _areas[idx_cell] ) /
443
                                                 ( gaussPoint - eps );
444

445
                    r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
446

447
                    _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
448
                }
449
            }
450
        }
451
        else {
452
#pragma omp simd
453
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
454
                _limiter[Idx2D( idx_cell, idx_sys, _localNSys )]         = 0.;    // limiter should be zero at boundary
455
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
456
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.;
457
            }
458
        }
459
    }
460
#pragma omp parallel for
16✔
461
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {    // Compute Flux
462
#pragma omp simd
463
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
464
            _flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.;
465
        }
466

467
        // Fluxes
468
        for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
469
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
470
                // #pragma omp simd
471
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
472
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
473
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
474
                    if( localInner > 0 ) {
475
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
476
                    }
477
                    else {
478
                        double ghostCellValue = _ghostCells[idx_cell][idx_sys];    // fixed boundary
479
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
480
                    }
481
                }
482
            }
483
            else {
484

485
                unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    // global idx of neighbor cell
486
                                                                                           // Second order
487
#pragma omp simd
488
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
489
                    // store flux contribution on psiNew_sigmaS to save memory
490
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
491
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
492

493
                    _flux[Idx2D( idx_cell, idx_sys, _localNSys )] +=
494
                        ( localInner > 0 ) ? localInner * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] +
495
                                                            _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] *
496
                                                                ( _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
497
                                                                      _relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
498
                                                                  _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] *
499
                                                                      _relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) )
500
                                           : localInner * ( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] +
501
                                                            _limiter[Idx2D( nbr_glob, idx_sys, _localNSys )] *
502
                                                                ( _solDx[Idx3D( nbr_glob, idx_sys, 0, _localNSys, _nDim )] *
503
                                                                      ( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] -
504
                                                                        _cellMidPoints[Idx2D( nbr_glob, 0, _nDim )] ) +
505
                                                                  _solDx[Idx3D( nbr_glob, idx_sys, 1, _localNSys, _nDim )] *
506
                                                                      ( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] -
507
                                                                        _cellMidPoints[Idx2D( nbr_glob, 1, _nDim )] ) ) );
508
                }
509
            }
510
        }
511
    }
512
}
16✔
513

514
void SNSolverHPC::FluxOrder1() {
×
515

516
#pragma omp parallel for
×
517
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
518

519
#pragma omp simd
520
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
521
            _flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.0;    // Reset temporary variable
522
        }
523

524
        // Fluxes
525
        for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
526
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
527
#pragma omp simd
528
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
529
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
530
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
531
                    if( localInner > 0 ) {
532
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
533
                    }
534
                    else {
535
                        double ghostCellValue = _ghostCells[idx_cell][idx_sys];    // fixed boundary
536
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
537
                    }
538
                }
539
            }
540
            else {
541
                unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    // global idx of neighbor cell
542
#pragma omp simd
543
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
544

545
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
546
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
547

548
                    _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += ( localInner > 0 ) ? localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )]
549
                                                                                        : localInner * _sol[Idx2D( nbr_glob, idx_sys, _localNSys )];
550
                }
551
            }
552
        }
553
    }
554
}
555

556
void SNSolverHPC::FVMUpdate() {
16✔
557
    _mass    = 0.0;
16✔
558
    _rmsFlux = 0.0;
16✔
559
    std::vector<double> temp_scalarFlux( _nCells );    // for MPI allreduce
32✔
560
    std::vector<double> prev_scalarFlux( _scalarFlux );
16✔
561

562
#pragma omp parallel for reduction( + : _mass )
16✔
563
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
564

565
#pragma omp simd
566
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
567
            // Update
568
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )] =
569
                ( 1 - _dT * _sigmaT[idx_cell] ) * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] -
570
                _dT / _areas[idx_cell] * _flux[Idx2D( idx_cell, idx_sys, _localNSys )] +
571
                _dT * ( _sigmaS[idx_cell] * _scalarFlux[idx_cell] / ( 2 * M_PI ) + _source[Idx2D( idx_cell, idx_sys, _localNSys )] );
572
        }
573
        double localScalarFlux = 0;
574

575
#pragma omp simd reduction( + : localScalarFlux )
576
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
577
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )] = std::max( _sol[Idx2D( idx_cell, idx_sys, _localNSys )], 0.0 );
578
            localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
579
        }
580
        _mass += localScalarFlux * _areas[idx_cell];
581
        temp_scalarFlux[idx_cell] = localScalarFlux;    // set flux
582
    }
583
// MPI Allreduce: _scalarFlux
584
#ifdef IMPORT_MPI
585
    MPI_Barrier( MPI_COMM_WORLD );
586
    MPI_Allreduce( temp_scalarFlux.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
587
    MPI_Barrier( MPI_COMM_WORLD );
588
    if( _rank == 0 ) {
589
        for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
590
            double diff = _scalarFlux[idx_cell] - prev_scalarFlux[idx_cell];
591
            _rmsFlux += diff * diff;
592
        }
593
    }
594
#endif
595
#ifndef IMPORT_MPI
596
    _scalarFlux = temp_scalarFlux;
16✔
597
#pragma omp parallel for reduction( + : _rmsFlux )
16✔
598
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
599
        double diff = _scalarFlux[idx_cell] - prev_scalarFlux[idx_cell];
600
        _rmsFlux += diff * diff;
601
    }
602
#endif
603
}
16✔
604

605
void SNSolverHPC::IterPostprocessing() {
8✔
606
    // ALREDUCE NEEDED
607

608
    _curAbsorptionLattice            = 0.0;
8✔
609
    _curScalarOutflow                = 0.0;
8✔
610
    _curScalarOutflowPeri1           = 0.0;
8✔
611
    _curScalarOutflowPeri2           = 0.0;
8✔
612
    _curAbsorptionHohlraumCenter     = 0.0;    // Green and blue areas of symmetric hohlraum
8✔
613
    _curAbsorptionHohlraumVertical   = 0.0;    // Red areas of symmetric hohlraum
8✔
614
    _curAbsorptionHohlraumHorizontal = 0.0;    // Black areas of symmetric hohlraum
8✔
615
    _varAbsorptionHohlraumGreen      = 0.0;
8✔
616
    double a_g                       = 0.0;
8✔
617

618
#pragma omp parallel for reduction( + : _curAbsorptionLattice,                                                                                       \
8✔
619
                                        _curScalarOutflow,                                                                                           \
620
                                        _curScalarOutflowPeri1,                                                                                      \
621
                                        _curScalarOutflowPeri2,                                                                                      \
622
                                        _curAbsorptionHohlraumCenter,                                                                                \
623
                                        _curAbsorptionHohlraumVertical,                                                                              \
624
                                        _curAbsorptionHohlraumHorizontal,                                                                            \
625
                                        a_g ) reduction( max : _curMaxOrdinateOutflow, _curMaxAbsorptionLattice )
8✔
626
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
627

628
        if( _settings->GetProblemName() == PROBLEM_Lattice || _settings->GetProblemName() == PROBLEM_HalfLattice ) {
629
            if( IsAbsorptionLattice( _cellMidPoints[Idx2D( idx_cell, 0, _nDim )], _cellMidPoints[Idx2D( idx_cell, 1, _nDim )] ) ) {
630
                double sigmaAPsi = _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
631
                _curAbsorptionLattice += sigmaAPsi;
632
                _curMaxAbsorptionLattice = ( _curMaxAbsorptionLattice < sigmaAPsi ) ? sigmaAPsi : _curMaxAbsorptionLattice;
633
            }
634
        }
635

636
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {    //} || _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
637

638
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
639
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
640
            _curAbsorptionLattice += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
641
            if( x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
642
                y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum() ) {
643
                _curAbsorptionHohlraumCenter += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
644
            }
645
            if( ( x < _settings->GetPosRedLeftBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
646
                  y < _settings->GetPosRedLeftTopHohlraum() ) ||
647
                ( x > _settings->GetPosRedRightBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
648
                  y < _settings->GetPosRedRightTopHohlraum() ) ) {
649
                _curAbsorptionHohlraumVertical += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
650
            }
651
            if( y > 0.6 || y < -0.6 ) {
652
                _curAbsorptionHohlraumHorizontal += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
653
            }
654

655
            // Variation in absorption of center (part 1)
656
            // green area 1 (lower boundary)
657
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
658
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
659
            // green area 2 (upper boundary)
660
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
661
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
662
            // green area 3 (left boundary)
663
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
664
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
665
            // green area 4 (right boundary)
666
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
667
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
668
            if( green1 || green2 || green3 || green4 ) {
669
                a_g += ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _scalarFlux[idx_cell] * _areas[idx_cell] /
670
                       ( 44 * 0.05 * 0.05 );    // divisor is area of the green
671
            }
672
        }
673

674
        if( _settings->GetProblemName() == PROBLEM_Lattice ) {
675
            // Outflow out of inner and middle perimeter
676
            if( _isPerimeterLatticeCell1[idx_cell] ) {    // inner
677
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter1[idx_cell].size(); ++idx_nbr_helper ) {
678
#pragma omp simd reduction( + : _curScalarOutflowPeri1 )
679
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
680
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
681
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
682
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
683
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
684
                        // Find outward facing transport directions
685

686
                        if( localInner > 0.0 ) {
687
                            _curScalarOutflowPeri1 +=
688
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
689
                        }
690
                    }
691
                }
692
            }
693
            if( _isPerimeterLatticeCell2[idx_cell] ) {    // middle
694
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter2[idx_cell].size(); ++idx_nbr_helper ) {
695
#pragma omp simd reduction( + : _curScalarOutflowPeri2 )
696
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
697
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
698
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
699
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
700
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
701
                        // Find outward facing transport directions
702

703
                        if( localInner > 0.0 ) {
704
                            _curScalarOutflowPeri2 +=
705
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
706
                        }
707
                    }
708
                }
709
            }
710
        }
711
        // Outflow out of domain
712
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN ) {
713
            // Iterate over face cell faces
714
            double currOrdinatewiseOutflow = 0.0;
715

716
            for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
717
                // Find face that points outward
718
                if( _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
719
#pragma omp simd reduction( + : _curScalarOutflow ) reduction( max : _curMaxOrdinateOutflow )
720
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
721

722
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
723
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
724
                        // Find outward facing transport directions
725

726
                        if( localInner > 0.0 ) {
727
                            _curScalarOutflow +=
728
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
729

730
                            currOrdinatewiseOutflow =
731
                                _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * localInner /
732
                                sqrt( (
733
                                    _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
734
                                    _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) );
735

736
                            _curMaxOrdinateOutflow =
737
                                ( currOrdinatewiseOutflow > _curMaxOrdinateOutflow ) ? currOrdinatewiseOutflow : _curMaxOrdinateOutflow;
738
                        }
739
                    }
740
                }
741
            }
742
        }
743
    }
744
// MPI Allreduce
745
#ifdef IMPORT_MPI
746
    double tmp_curScalarOutflow      = 0.0;
747
    double tmp_curScalarOutflowPeri1 = 0.0;
748
    double tmp_curScalarOutflowPeri2 = 0.0;
749
    double tmp_curMaxOrdinateOutflow = 0.0;
750
    double tmp_mass                  = 0.0;
751
    double tmp_rmsFlux               = 0.0;
752
    MPI_Barrier( MPI_COMM_WORLD );
753
    MPI_Allreduce( &_curScalarOutflow, &tmp_curScalarOutflow, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
754
    _curScalarOutflow = tmp_curScalarOutflow;
755
    MPI_Barrier( MPI_COMM_WORLD );
756
    MPI_Allreduce( &_curScalarOutflowPeri1, &tmp_curScalarOutflowPeri1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
757
    _curScalarOutflowPeri1 = tmp_curScalarOutflowPeri1;
758
    MPI_Barrier( MPI_COMM_WORLD );
759
    MPI_Allreduce( &_curScalarOutflowPeri2, &tmp_curScalarOutflowPeri2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
760
    _curScalarOutflowPeri2 = tmp_curScalarOutflowPeri2;
761
    MPI_Barrier( MPI_COMM_WORLD );
762
    MPI_Allreduce( &_curMaxOrdinateOutflow, &tmp_curMaxOrdinateOutflow, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
763
    _curMaxOrdinateOutflow = tmp_curMaxOrdinateOutflow;
764
    MPI_Barrier( MPI_COMM_WORLD );
765
    MPI_Allreduce( &_mass, &tmp_mass, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
766
    _mass = tmp_mass;
767
    MPI_Barrier( MPI_COMM_WORLD );
768
    MPI_Allreduce( &_rmsFlux, &tmp_rmsFlux, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
769
    _rmsFlux = tmp_rmsFlux;
770
    MPI_Barrier( MPI_COMM_WORLD );
771
#endif
772
    // Variation absorption (part II)
773
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
8✔
774
        unsigned n_probes = 4;
5✔
775
        std::vector<double> temp_probingMoments( 3 * n_probes );    // for MPI allreduce
10✔
776

777
#pragma omp parallel for reduction( + : _varAbsorptionHohlraumGreen )
5✔
778
        for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
779
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
780
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
781

782
            // green area 1 (lower boundary)
783
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
784
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
785
            // green area 2 (upper boundary)
786
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
787
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
788
            // green area 3 (left boundary)
789
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
790
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
791
            // green area 4 (right boundary)
792
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
793
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
794
            if( green1 || green2 || green3 || green4 ) {
795
                _varAbsorptionHohlraumGreen += ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) *
796
                                               ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) * _areas[idx_cell];
797
            }
798
        }
799
        // Probes value moments
800
        // #pragma omp parallel for
801
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
25✔
802
            temp_probingMoments[Idx2D( idx_probe, 0, 3 )] = 0.0;
20✔
803
            temp_probingMoments[Idx2D( idx_probe, 1, 3 )] = 0.0;
20✔
804
            temp_probingMoments[Idx2D( idx_probe, 2, 3 )] = 0.0;
20✔
805
            // for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
806
            //   std::cout << idx_ball << _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI ) << std::endl;
807
            //}
808
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
740✔
809
                for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
1,440✔
810
                    temp_probingMoments[Idx2D( idx_probe, 0, 3 )] += _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
1,440✔
811
                                                                     _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] /
720✔
812
                                                                     ( 0.01 * 0.01 * M_PI );
813
                    temp_probingMoments[Idx2D( idx_probe, 1, 3 )] +=
720✔
814
                        _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
720✔
815
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
720✔
816
                    temp_probingMoments[Idx2D( idx_probe, 2, 3 )] +=
720✔
817
                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
720✔
818
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
720✔
819
                }
820
            }
821
        }
822

823
#ifdef IMPORT_MPI
824
        MPI_Barrier( MPI_COMM_WORLD );
825
        MPI_Allreduce( temp_probingMoments.data(), _probingMoments.data(), 3 * n_probes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
826
        MPI_Barrier( MPI_COMM_WORLD );
827
#endif
828
#ifndef IMPORT_MPI
829
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
25✔
830
            _probingMoments[Idx2D( idx_probe, 0, 3 )] = temp_probingMoments[Idx2D( idx_probe, 0, 3 )];
20✔
831
            _probingMoments[Idx2D( idx_probe, 1, 3 )] = temp_probingMoments[Idx2D( idx_probe, 1, 3 )];
20✔
832
            _probingMoments[Idx2D( idx_probe, 2, 3 )] = temp_probingMoments[Idx2D( idx_probe, 2, 3 )];
20✔
833
        }
834
#endif
835
    }
836
    // probe values green
837
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
8✔
838
        ComputeQOIsGreenProbingLine();
5✔
839
    }
840
    // Update time integral values on rank 0
841
    if( _rank == 0 ) {
8✔
842
        _totalScalarOutflow += _curScalarOutflow * _dT;
8✔
843
        _totalScalarOutflowPeri1 += _curScalarOutflowPeri1 * _dT;
8✔
844
        _totalScalarOutflowPeri2 += _curScalarOutflowPeri2 * _dT;
8✔
845
        _totalAbsorptionLattice += _curAbsorptionLattice * _dT;
8✔
846

847
        _totalAbsorptionHohlraumCenter += _curAbsorptionHohlraumCenter * _dT;
8✔
848
        _totalAbsorptionHohlraumVertical += _curAbsorptionHohlraumVertical * _dT;
8✔
849
        _totalAbsorptionHohlraumHorizontal += _curAbsorptionHohlraumHorizontal * _dT;
8✔
850

851
        _rmsFlux = sqrt( _rmsFlux );
8✔
852
    }
853
}
8✔
854

855
bool SNSolverHPC::IsAbsorptionLattice( double x, double y ) const {
600✔
856
    // Check whether pos is inside absorbing squares
857
    double xy_corrector = -3.5;
600✔
858
    std::vector<double> lbounds{ 1 + xy_corrector, 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector };
1,200✔
859
    std::vector<double> ubounds{ 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector, 6 + xy_corrector };
1,200✔
860
    for( unsigned k = 0; k < lbounds.size(); ++k ) {
3,204✔
861
        for( unsigned l = 0; l < lbounds.size(); ++l ) {
15,984✔
862
            if( ( l + k ) % 2 == 1 || ( k == 2 && l == 2 ) || ( k == 2 && l == 4 ) ) continue;
13,380✔
863
            if( x >= lbounds[k] && x <= ubounds[k] && y >= lbounds[l] && y <= ubounds[l] ) {
5,940✔
864
                return true;
132✔
865
            }
866
        }
867
    }
868
    return false;
468✔
869
}
870

871
// --- Helper ---
872
double SNSolverHPC::ComputeTimeStep( double cfl ) const {
2✔
873
    // for pseudo 1D, set timestep to dx
874
    double dx, dy;
875
    switch( _settings->GetProblemName() ) {
2✔
876
        case PROBLEM_Checkerboard1D:
×
877
            dx = 7.0 / (double)_nCells;
×
878
            dy = 0.3;
×
879
            return cfl * ( dx * dy ) / ( dx + dy );
×
880
            break;
881
        case PROBLEM_Linesource1D:     // Fallthrough
×
882
        case PROBLEM_Meltingcube1D:    // Fallthrough
883
        case PROBLEM_Aircavity1D:
884
            dx = 3.0 / (double)_nCells;
×
885
            dy = 0.3;
×
886
            return cfl * ( dx * dy ) / ( dx + dy );
×
887
            break;
888
        default: break;    // 2d as normal
2✔
889
    }
890
    // 2D case
891
    double charSize = __DBL_MAX__;    // minimum char size of all mesh cells in the mesh
2✔
892

893
#pragma omp parallel for reduction( min : charSize )
2✔
894
    for( unsigned long j = 0; j < _nCells; j++ ) {
895
        double currCharSize = sqrt( _areas[j] );
896
        if( currCharSize < charSize ) {
897
            charSize = currCharSize;
898
        }
899
    }
900
    if( _rank == 0 ) {
2✔
901
        auto log         = spdlog::get( "event" );
6✔
902
        std::string line = "| Smallest characteristic length of a grid cell in this mesh: " + std::to_string( charSize );
4✔
903
        log->info( line );
2✔
904
        line = "| Corresponding maximal time-step: " + std::to_string( cfl * charSize );
2✔
905
        log->info( line );
2✔
906
    }
907
    return cfl * charSize;
2✔
908
}
909

910
// --- IO ----
911
void SNSolverHPC::PrepareScreenOutput() {
2✔
912
    unsigned nFields = (unsigned)_settings->GetNScreenOutput();
2✔
913

914
    _screenOutputFieldNames.resize( nFields );
2✔
915
    _screenOutputFields.resize( nFields );
2✔
916

917
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
918
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
14✔
919
        // Prepare all Output Fields per group
920

921
        // Different procedure, depending on the Group...
922
        switch( _settings->GetScreenOutput()[idx_field] ) {
12✔
923
            case MASS: _screenOutputFieldNames[idx_field] = "Mass"; break;
2✔
924
            case ITER: _screenOutputFieldNames[idx_field] = "Iter"; break;
2✔
925
            case SIM_TIME: _screenOutputFieldNames[idx_field] = "Sim time"; break;
×
926
            case WALL_TIME: _screenOutputFieldNames[idx_field] = "Wall time [s]"; break;
2✔
927
            case RMS_FLUX: _screenOutputFieldNames[idx_field] = "RMS flux"; break;
2✔
928
            case VTK_OUTPUT: _screenOutputFieldNames[idx_field] = "VTK out"; break;
2✔
929
            case CSV_OUTPUT: _screenOutputFieldNames[idx_field] = "CSV out"; break;
2✔
930
            case CUR_OUTFLOW: _screenOutputFieldNames[idx_field] = "Cur. outflow"; break;
×
931
            case TOTAL_OUTFLOW: _screenOutputFieldNames[idx_field] = "Tot. outflow"; break;
×
932
            case CUR_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Cur. outflow P1"; break;
×
933
            case TOTAL_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Tot. outflow P1"; break;
×
934
            case CUR_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Cur. outflow P2"; break;
×
935
            case TOTAL_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Tot. outflow P2"; break;
×
936
            case MAX_OUTFLOW: _screenOutputFieldNames[idx_field] = "Max outflow"; break;
×
937
            case CUR_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Cur. absorption"; break;
×
938
            case TOTAL_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Tot. absorption"; break;
×
939
            case MAX_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Max absorption"; break;
×
940
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFieldNames[idx_field] = "Tot. abs. center"; break;
×
941
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFieldNames[idx_field] = "Tot. abs. vertical wall"; break;
×
942
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFieldNames[idx_field] = "Tot. abs. horizontal wall"; break;
×
943
            case PROBE_MOMENT_TIME_TRACE:
×
944
                _screenOutputFieldNames[idx_field] = "Probe 1 u_0";
×
945
                idx_field++;
×
946
                _screenOutputFieldNames[idx_field] = "Probe 2 u_0";
×
947
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
948
                    idx_field++;
×
949
                    _screenOutputFieldNames[idx_field] = "Probe 3 u_0";
×
950
                    idx_field++;
×
951
                    _screenOutputFieldNames[idx_field] = "Probe 4 u_0";
×
952
                }
953
                break;
×
954
            case VAR_ABSORPTION_GREEN: _screenOutputFieldNames[idx_field] = "Var. absorption green"; break;
×
955

956
            default: ErrorMessages::Error( "Screen output field not defined!", CURRENT_FUNCTION ); break;
×
957
        }
958
    }
959
}
2✔
960

961
void SNSolverHPC::WriteScalarOutput( unsigned idx_iter ) {
8✔
962
    unsigned n_probes = 4;
8✔
963

964
    unsigned nFields                  = (unsigned)_settings->GetNScreenOutput();
8✔
965
    const VectorVector probingMoments = _problem->GetCurrentProbeMoment();
16✔
966
    // -- Screen Output
967
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
56✔
968
        // Prepare all Output Fields per group
969
        // Different procedure, depending on the Group...
970
        switch( _settings->GetScreenOutput()[idx_field] ) {
48✔
971
            case MASS: _screenOutputFields[idx_field] = _mass; break;
8✔
972
            case ITER: _screenOutputFields[idx_field] = idx_iter; break;
8✔
973
            case SIM_TIME: _screenOutputFields[idx_field] = _curSimTime; break;
×
974
            case WALL_TIME: _screenOutputFields[idx_field] = _currTime; break;
8✔
975
            case RMS_FLUX: _screenOutputFields[idx_field] = _rmsFlux; break;
8✔
976
            case VTK_OUTPUT:
8✔
977
                _screenOutputFields[idx_field] = 0;
8✔
978
                if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
16✔
979
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
8✔
980
                    _screenOutputFields[idx_field] = 1;
2✔
981
                }
982
                break;
8✔
983
            case CSV_OUTPUT:
8✔
984
                _screenOutputFields[idx_field] = 0;
8✔
985
                if( ( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
8✔
986
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
987
                    _screenOutputFields[idx_field] = 1;
8✔
988
                }
989
                break;
8✔
990
            case CUR_OUTFLOW: _screenOutputFields[idx_field] = _curScalarOutflow; break;
×
991
            case TOTAL_OUTFLOW: _screenOutputFields[idx_field] = _totalScalarOutflow; break;
×
992
            case CUR_OUTFLOW_P1: _screenOutputFields[idx_field] = _curScalarOutflowPeri1; break;
×
993
            case TOTAL_OUTFLOW_P1: _screenOutputFields[idx_field] = _totalScalarOutflowPeri1; break;
×
994
            case CUR_OUTFLOW_P2: _screenOutputFields[idx_field] = _curScalarOutflowPeri2; break;
×
995
            case TOTAL_OUTFLOW_P2: _screenOutputFields[idx_field] = _totalScalarOutflowPeri2; break;
×
996
            case MAX_OUTFLOW: _screenOutputFields[idx_field] = _curMaxOrdinateOutflow; break;
×
997
            case CUR_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _curAbsorptionLattice; break;
×
998
            case TOTAL_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _totalAbsorptionLattice; break;
×
999
            case MAX_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _curMaxAbsorptionLattice; break;
×
1000
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumCenter; break;
×
1001
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumVertical; break;
×
1002
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumHorizontal; break;
×
1003
            case PROBE_MOMENT_TIME_TRACE:
×
1004
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
×
1005
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1006
                for( unsigned i = 0; i < n_probes; i++ ) {
×
1007
                    _screenOutputFields[idx_field] = _probingMoments[Idx2D( i, 0, 3 )];
×
1008
                    idx_field++;
×
1009
                }
1010
                idx_field--;
×
1011
                break;
×
NEW
1012
            case VAR_ABSORPTION_GREEN: _screenOutputFields[idx_field] = _varAbsorptionHohlraumGreen; break;
×
1013
            default: ErrorMessages::Error( "Screen output group not defined!", CURRENT_FUNCTION ); break;
×
1014
        }
1015
    }
1016

1017
    // --- History output ---
1018
    nFields = (unsigned)_settings->GetNHistoryOutput();
8✔
1019

1020
    std::vector<SCALAR_OUTPUT> screenOutputFields = _settings->GetScreenOutput();
16✔
1021
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
149✔
1022

1023
        // Prepare all Output Fields per group
1024
        // Different procedure, depending on the Group...
1025
        switch( _settings->GetHistoryOutput()[idx_field] ) {
141✔
1026
            case MASS: _historyOutputFields[idx_field] = _mass; break;
8✔
1027
            case ITER: _historyOutputFields[idx_field] = idx_iter; break;
8✔
1028
            case SIM_TIME: _historyOutputFields[idx_field] = _curSimTime; break;
8✔
1029
            case WALL_TIME: _historyOutputFields[idx_field] = _currTime; break;
8✔
1030
            case RMS_FLUX: _historyOutputFields[idx_field] = _rmsFlux; break;
8✔
1031
            case VTK_OUTPUT:
8✔
1032
                _historyOutputFields[idx_field] = 0;
8✔
1033
                if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
16✔
1034
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
8✔
1035
                    _historyOutputFields[idx_field] = 1;
2✔
1036
                }
1037
                break;
8✔
1038

1039
            case CSV_OUTPUT:
8✔
1040
                _historyOutputFields[idx_field] = 0;
8✔
1041
                if( ( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
8✔
1042
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
1043
                    _historyOutputFields[idx_field] = 1;
8✔
1044
                }
1045
                break;
8✔
1046
            case CUR_OUTFLOW: _historyOutputFields[idx_field] = _curScalarOutflow; break;
8✔
1047
            case TOTAL_OUTFLOW: _historyOutputFields[idx_field] = _totalScalarOutflow; break;
8✔
1048
            case CUR_OUTFLOW_P1: _historyOutputFields[idx_field] = _curScalarOutflowPeri1; break;
3✔
1049
            case TOTAL_OUTFLOW_P1: _historyOutputFields[idx_field] = _totalScalarOutflowPeri1; break;
3✔
1050
            case CUR_OUTFLOW_P2: _historyOutputFields[idx_field] = _curScalarOutflowPeri2; break;
3✔
1051
            case TOTAL_OUTFLOW_P2: _historyOutputFields[idx_field] = _totalScalarOutflowPeri2; break;
3✔
1052
            case MAX_OUTFLOW: _historyOutputFields[idx_field] = _curMaxOrdinateOutflow; break;
8✔
1053
            case CUR_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _curAbsorptionLattice; break;
3✔
1054
            case TOTAL_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _totalAbsorptionLattice; break;
8✔
1055
            case MAX_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _curMaxAbsorptionLattice; break;
3✔
1056
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumCenter; break;
5✔
1057
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumVertical; break;
5✔
1058
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumHorizontal; break;
5✔
1059
            case PROBE_MOMENT_TIME_TRACE:
5✔
1060
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
5✔
1061
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1062
                for( unsigned i = 0; i < n_probes; i++ ) {
25✔
1063
                    for( unsigned j = 0; j < 3; j++ ) {
80✔
1064
                        _historyOutputFields[idx_field] = _probingMoments[Idx2D( i, j, 3 )];
60✔
1065
                        idx_field++;
60✔
1066
                    }
1067
                }
1068
                idx_field--;
5✔
1069
                break;
5✔
1070
            case VAR_ABSORPTION_GREEN: _historyOutputFields[idx_field] = _varAbsorptionHohlraumGreen; break;
5✔
1071
            case ABSORPTION_GREEN_LINE:
5✔
1072
                for( unsigned i = 0; i < _settings->GetNumProbingCellsLineHohlraum(); i++ ) {
105✔
1073
                    _historyOutputFields[idx_field] = _absorptionValsLineSegment[i];
100✔
1074
                    idx_field++;
100✔
1075
                }
1076
                idx_field--;
5✔
1077
                break;
5✔
1078
            case ABSORPTION_GREEN_BLOCK:
5✔
1079
                for( unsigned i = 0; i < 44; i++ ) {
225✔
1080
                    _historyOutputFields[idx_field] = _absorptionValsBlocksGreen[i];
220✔
1081
                    // std::cout << _absorptionValsBlocksGreen[i] << "/" << _historyOutputFields[idx_field] << std::endl;
1082
                    idx_field++;
220✔
1083
                }
1084
                idx_field--;
5✔
1085
                break;
5✔
1086
            default: ErrorMessages::Error( "History output group not defined!", CURRENT_FUNCTION ); break;
×
1087
        }
1088
    }
1089
}
8✔
1090

1091
void SNSolverHPC::PrintScreenOutput( unsigned idx_iter ) {
8✔
1092
    auto log = spdlog::get( "event" );
24✔
1093

1094
    unsigned strLen  = 15;    // max width of one column
8✔
1095
    char paddingChar = ' ';
8✔
1096

1097
    // assemble the line to print
1098
    std::string lineToPrint = "| ";
16✔
1099
    std::string tmp;
16✔
1100
    for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput(); idx_field++ ) {
56✔
1101
        tmp = std::to_string( _screenOutputFields[idx_field] );
48✔
1102

1103
        // Format outputs correctly
1104
        std::vector<SCALAR_OUTPUT> integerFields    = { ITER };
96✔
1105
        std::vector<SCALAR_OUTPUT> scientificFields = { RMS_FLUX,
1106
                                                        MASS,
1107
                                                        WALL_TIME,
1108
                                                        CUR_OUTFLOW,
1109
                                                        TOTAL_OUTFLOW,
1110
                                                        CUR_OUTFLOW_P1,
1111
                                                        TOTAL_OUTFLOW_P1,
1112
                                                        CUR_OUTFLOW_P2,
1113
                                                        TOTAL_OUTFLOW_P2,
1114
                                                        MAX_OUTFLOW,
1115
                                                        CUR_PARTICLE_ABSORPTION,
1116
                                                        TOTAL_PARTICLE_ABSORPTION,
1117
                                                        MAX_PARTICLE_ABSORPTION,
1118
                                                        TOTAL_PARTICLE_ABSORPTION_CENTER,
1119
                                                        TOTAL_PARTICLE_ABSORPTION_VERTICAL,
1120
                                                        TOTAL_PARTICLE_ABSORPTION_HORIZONTAL,
1121
                                                        PROBE_MOMENT_TIME_TRACE,
1122
                                                        VAR_ABSORPTION_GREEN,
1123
                                                        ABSORPTION_GREEN_BLOCK,
1124
                                                        ABSORPTION_GREEN_LINE };
96✔
1125
        std::vector<SCALAR_OUTPUT> booleanFields    = { VTK_OUTPUT, CSV_OUTPUT };
48✔
1126

1127
        if( !( integerFields.end() == std::find( integerFields.begin(), integerFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
48✔
1128
            tmp = std::to_string( (int)_screenOutputFields[idx_field] );
8✔
1129
        }
1130
        else if( !( booleanFields.end() == std::find( booleanFields.begin(), booleanFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
40✔
1131
            tmp = "no";
16✔
1132
            if( (bool)_screenOutputFields[idx_field] ) tmp = "yes";
16✔
1133
        }
1134
        else if( !( scientificFields.end() ==
24✔
1135
                    std::find( scientificFields.begin(), scientificFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
48✔
1136

1137
            std::stringstream ss;
24✔
1138
            ss << TextProcessingToolbox::DoubleToScientificNotation( _screenOutputFields[idx_field] );
24✔
1139
            tmp = ss.str();
24✔
1140
            tmp.erase( std::remove( tmp.begin(), tmp.end(), '+' ), tmp.end() );    // removing the '+' sign
24✔
1141
        }
1142

1143
        if( strLen > tmp.size() )    // Padding
48✔
1144
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
48✔
1145
        else if( strLen < tmp.size() )    // Cutting
×
1146
            tmp.resize( strLen );
×
1147

1148
        lineToPrint += tmp + " |";
48✔
1149
    }
1150
    if( _settings->GetScreenOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetScreenOutputFrequency() == 0 ) {
8✔
1151
        log->info( lineToPrint );
8✔
1152
    }
1153
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1154
        log->info( lineToPrint );
×
1155
    }
1156
}
8✔
1157

1158
void SNSolverHPC::PrepareHistoryOutput() {
2✔
1159
    unsigned n_probes = 4;
2✔
1160

1161
    unsigned nFields = (unsigned)_settings->GetNHistoryOutput();
2✔
1162

1163
    _historyOutputFieldNames.resize( nFields );
2✔
1164
    _historyOutputFields.resize( nFields );
2✔
1165

1166
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
1167
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
37✔
1168
        // Prepare all Output Fields per group
1169

1170
        // Different procedure, depending on the Group...
1171
        switch( _settings->GetHistoryOutput()[idx_field] ) {
35✔
1172
            case MASS: _historyOutputFieldNames[idx_field] = "Mass"; break;
2✔
1173
            case ITER: _historyOutputFieldNames[idx_field] = "Iter"; break;
2✔
1174
            case SIM_TIME: _historyOutputFieldNames[idx_field] = "Sim_time"; break;
2✔
1175
            case WALL_TIME: _historyOutputFieldNames[idx_field] = "Wall_time_[s]"; break;
2✔
1176
            case RMS_FLUX: _historyOutputFieldNames[idx_field] = "RMS_flux"; break;
2✔
1177
            case VTK_OUTPUT: _historyOutputFieldNames[idx_field] = "VTK_out"; break;
2✔
1178
            case CSV_OUTPUT: _historyOutputFieldNames[idx_field] = "CSV_out"; break;
2✔
1179
            case CUR_OUTFLOW: _historyOutputFieldNames[idx_field] = "Cur_outflow"; break;
2✔
1180
            case TOTAL_OUTFLOW: _historyOutputFieldNames[idx_field] = "Total_outflow"; break;
2✔
1181
            case CUR_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Cur_outflow_P1"; break;
1✔
1182
            case TOTAL_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Total_outflow_P1"; break;
1✔
1183
            case CUR_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Cur_outflow_P2"; break;
1✔
1184
            case TOTAL_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Total_outflow_P2"; break;
1✔
1185
            case MAX_OUTFLOW: _historyOutputFieldNames[idx_field] = "Max_outflow"; break;
2✔
1186
            case CUR_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Cur_absorption"; break;
1✔
1187
            case TOTAL_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Total_absorption"; break;
2✔
1188
            case MAX_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Max_absorption"; break;
1✔
1189
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_center"; break;
1✔
1190
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_vertical_wall"; break;
1✔
1191
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_horizontal_wall"; break;
1✔
1192
            case PROBE_MOMENT_TIME_TRACE:
1✔
1193
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
1✔
1194
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1195
                for( unsigned i = 0; i < n_probes; i++ ) {
5✔
1196
                    for( unsigned j = 0; j < 3; j++ ) {
16✔
1197
                        _historyOutputFieldNames[idx_field] = "Probe " + std::to_string( i ) + " u_" + std::to_string( j );
12✔
1198
                        idx_field++;
12✔
1199
                    }
1200
                }
1201
                idx_field--;
1✔
1202
                break;
1✔
1203
            case VAR_ABSORPTION_GREEN: _historyOutputFieldNames[idx_field] = "Var. absorption green"; break;
1✔
1204
            case ABSORPTION_GREEN_BLOCK:
1✔
1205
                for( unsigned i = 0; i < 44; i++ ) {
45✔
1206
                    _historyOutputFieldNames[idx_field] = "Probe Green Block " + std::to_string( i );
44✔
1207
                    idx_field++;
44✔
1208
                }
1209
                idx_field--;
1✔
1210
                break;
1✔
1211

1212
            case ABSORPTION_GREEN_LINE:
1✔
1213
                for( unsigned i = 0; i < _settings->GetNumProbingCellsLineHohlraum(); i++ ) {
21✔
1214
                    _historyOutputFieldNames[idx_field] = "Probe Green Line " + std::to_string( i );
20✔
1215
                    idx_field++;
20✔
1216
                }
1217
                idx_field--;
1✔
1218
                break;
1✔
1219
            default: ErrorMessages::Error( "History output field not defined!", CURRENT_FUNCTION ); break;
×
1220
        }
1221
    }
1222
}
2✔
1223

1224
void SNSolverHPC::PrintHistoryOutput( unsigned idx_iter ) {
8✔
1225

1226
    auto log = spdlog::get( "tabular" );
24✔
1227

1228
    // assemble the line to print
1229
    std::string lineToPrint = "";
16✔
1230
    std::string tmp;
16✔
1231
    for( int idx_field = 0; idx_field < _settings->GetNHistoryOutput() - 1; idx_field++ ) {
506✔
1232
        if( idx_field == 0 ) {
498✔
1233
            tmp = std::to_string( _historyOutputFields[idx_field] );    // Iteration count
8✔
1234
        }
1235
        else {
1236
            tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[idx_field] );
490✔
1237
        }
1238
        lineToPrint += tmp + ",";
498✔
1239
    }
1240
    tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[_settings->GetNHistoryOutput() - 1] );
8✔
1241
    lineToPrint += tmp;    // Last element without comma
8✔
1242
    // std::cout << lineToPrint << std::endl;
1243
    if( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) {
8✔
1244
        log->info( lineToPrint );
8✔
1245
    }
1246
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1247
        log->info( lineToPrint );
×
1248
    }
1249
}
8✔
1250

1251
void SNSolverHPC::DrawPreSolverOutput() {
2✔
1252

1253
    // Logger
1254
    auto log    = spdlog::get( "event" );
6✔
1255
    auto logCSV = spdlog::get( "tabular" );
6✔
1256

1257
    std::string hLine = "--";
4✔
1258

1259
    unsigned strLen  = 15;    // max width of one column
2✔
1260
    char paddingChar = ' ';
2✔
1261

1262
    // Assemble Header for Screen Output
1263
    std::string lineToPrint = "| ";
4✔
1264
    std::string tmpLine     = "-----------------";
4✔
1265
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
14✔
1266
        std::string tmp = _screenOutputFieldNames[idxFields];
24✔
1267

1268
        if( strLen > tmp.size() )    // Padding
12✔
1269
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
12✔
1270
        else if( strLen < tmp.size() )    // Cutting
×
1271
            tmp.resize( strLen );
×
1272

1273
        lineToPrint += tmp + " |";
12✔
1274
        hLine += tmpLine;
12✔
1275
    }
1276
    log->info( "---------------------------- Solver Starts -----------------------------" );
2✔
1277
    log->info( "| The simulation will run for {} iterations.", _nIter );
2✔
1278
    log->info( "| The spatial grid contains {} cells.", _nCells );
2✔
1279
    if( _settings->GetSolverName() != PN_SOLVER && _settings->GetSolverName() != CSD_PN_SOLVER ) {
2✔
1280
        log->info( "| The velocity grid contains {} points.", _nq );
2✔
1281
    }
1282
    log->info( hLine );
2✔
1283
    log->info( lineToPrint );
2✔
1284
    log->info( hLine );
2✔
1285

1286
    std::string lineToPrintCSV = "";
4✔
1287
    for( int idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
108✔
1288
        std::string tmp = _historyOutputFieldNames[idxFields];
106✔
1289
        lineToPrintCSV += tmp + ",";
106✔
1290
    }
1291
    lineToPrintCSV += _historyOutputFieldNames[_settings->GetNHistoryOutput() - 1];
2✔
1292
    logCSV->info( lineToPrintCSV );
2✔
1293
}
2✔
1294

1295
void SNSolverHPC::DrawPostSolverOutput() {
2✔
1296

1297
    // Logger
1298
    auto log = spdlog::get( "event" );
6✔
1299

1300
    std::string hLine = "--";
4✔
1301

1302
    unsigned strLen  = 10;    // max width of one column
2✔
1303
    char paddingChar = ' ';
2✔
1304

1305
    // Assemble Header for Screen Output
1306
    std::string lineToPrint = "| ";
4✔
1307
    std::string tmpLine     = "------------";
4✔
1308
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
14✔
1309
        std::string tmp = _screenOutputFieldNames[idxFields];
24✔
1310

1311
        if( strLen > tmp.size() )    // Padding
12✔
1312
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
10✔
1313
        else if( strLen < tmp.size() )    // Cutting
2✔
1314
            tmp.resize( strLen );
2✔
1315

1316
        lineToPrint += tmp + " |";
12✔
1317
        hLine += tmpLine;
12✔
1318
    }
1319
    log->info( hLine );
2✔
1320
#ifndef BUILD_TESTING
1321
    log->info( "| The volume output files have been stored at " + _settings->GetOutputFile() );
1322
    log->info( "| The log files have been stored at " + _settings->GetLogDir() + _settings->GetLogFile() );
1323
#endif
1324
    log->info( "--------------------------- Solver Finished ----------------------------" );
2✔
1325
}
2✔
1326

1327
unsigned long SNSolverHPC::Idx2D( unsigned long idx1, unsigned long idx2, unsigned long len2 ) { return idx1 * len2 + idx2; }
6,394,040✔
1328

1329
unsigned long SNSolverHPC::Idx3D( unsigned long idx1, unsigned long idx2, unsigned long idx3, unsigned long len2, unsigned long len3 ) {
4,711,152✔
1330
    return ( idx1 * len2 + idx2 ) * len3 + idx3;
4,711,152✔
1331
}
1332

1333
void SNSolverHPC::WriteVolumeOutput( unsigned idx_iter ) {
2✔
1334
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
2✔
1335
    if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
4✔
1336
        ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
2✔
1337
        for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
4✔
1338
            switch( _settings->GetVolumeOutput()[idx_group] ) {
2✔
1339
                case MINIMAL:
2✔
1340
                    if( _rank == 0 ) {
2✔
1341
                        _outputFields[idx_group][0] = _scalarFlux;
2✔
1342
                    }
1343
                    break;
2✔
1344

1345
                case MOMENTS:
×
1346
#pragma omp parallel for
×
1347
                    for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
1348
                        _outputFields[idx_group][0][idx_cell] = 0.0;
1349
                        _outputFields[idx_group][1][idx_cell] = 0.0;
1350
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
1351
                            _outputFields[idx_group][0][idx_cell] +=
1352
                                _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1353
                            _outputFields[idx_group][1][idx_cell] +=
1354
                                _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1355
                        }
1356
                    }
1357
#ifdef IMPORT_MPI
1358
                    MPI_Barrier( MPI_COMM_WORLD );
1359
                    MPI_Allreduce(
1360
                        _outputFields[idx_group][0].data(), _outputFields[idx_group][0].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1361
                    MPI_Allreduce(
1362
                        _outputFields[idx_group][1].data(), _outputFields[idx_group][1].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1363
                    MPI_Barrier( MPI_COMM_WORLD );
1364
#endif
1365
                    break;
×
1366
                default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1367
            }
1368
        }
1369
    }
1370
}
2✔
1371

1372
void SNSolverHPC::PrintVolumeOutput( int idx_iter ) {
8✔
1373
    if( _settings->GetSaveRestartSolutionFrequency() != 0 && idx_iter % (int)_settings->GetSaveRestartSolutionFrequency() == 0 ) {
8✔
1374
        // std::cout << "Saving restart solution at iteration " << idx_iter << std::endl;
1375
        WriteRestartSolution( _settings->GetOutputFile(),
×
1376
                              _sol,
×
1377
                              _scalarFlux,
×
1378
                              _rank,
1379
                              idx_iter,
1380
                              _totalAbsorptionHohlraumCenter,
1381
                              _totalAbsorptionHohlraumVertical,
1382
                              _totalAbsorptionHohlraumHorizontal,
1383
                              _totalAbsorptionLattice );
1384
    }
1385

1386
    if( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (int)_settings->GetVolumeOutputFrequency() == 0 ) {
8✔
1387
        WriteVolumeOutput( idx_iter );
×
1388
        if( _rank == 0 ) {
×
1389
            ExportVTK( _settings->GetOutputFile() + "_" + std::to_string( idx_iter ), _outputFields, _outputFieldNames, _mesh );    // slow
×
1390
        }
1391
    }
1392
    if( idx_iter == (int)_nIter - 1 ) {    // Last iteration write without suffix.
8✔
1393
        WriteVolumeOutput( idx_iter );
2✔
1394
        if( _rank == 0 ) {
2✔
1395
            ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh );
2✔
1396
        }
1397
    }
1398
}
8✔
1399

1400
void SNSolverHPC::PrepareVolumeOutput() {
2✔
1401
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
2✔
1402

1403
    _outputFieldNames.resize( nGroups );
2✔
1404
    _outputFields.resize( nGroups );
2✔
1405

1406
    // Prepare all OutputGroups ==> Specified in option VOLUME_OUTPUT
1407
    for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
4✔
1408
        // Prepare all Output Fields per group
1409

1410
        // Different procedure, depending on the Group...
1411
        switch( _settings->GetVolumeOutput()[idx_group] ) {
2✔
1412
            case MINIMAL:
2✔
1413
                // Currently only one entry ==> rad flux
1414
                _outputFields[idx_group].resize( 1 );
2✔
1415
                _outputFieldNames[idx_group].resize( 1 );
2✔
1416

1417
                _outputFields[idx_group][0].resize( _nCells );
2✔
1418
                _outputFieldNames[idx_group][0] = "scalar flux";
2✔
1419
                break;
2✔
1420
            case MOMENTS:
×
1421
                // As many entries as there are moments in the system
1422
                _outputFields[idx_group].resize( _nOutputMoments );
×
1423
                _outputFieldNames[idx_group].resize( _nOutputMoments );
×
1424

1425
                for( unsigned idx_moment = 0; idx_moment < _nOutputMoments; idx_moment++ ) {
×
1426
                    _outputFieldNames[idx_group][idx_moment] = std::string( "u_" + std::to_string( idx_moment ) );
×
1427
                    _outputFields[idx_group][idx_moment].resize( _nCells );
×
1428
                }
1429
                break;
×
1430

1431
            default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1432
        }
1433
    }
1434
}
2✔
1435

1436
void SNSolverHPC::SetGhostCells() {
2✔
1437
    if( _settings->GetProblemName() == PROBLEM_Lattice ) {
2✔
1438
        // #pragma omp parallel for
1439
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
201✔
1440
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN || _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
200✔
1441
                _ghostCells[idx_cell] = std::vector<double>( _localNSys, 0.0 );
38✔
1442
            }
1443
        }
1444
    }
1445
    else if( _settings->GetProblemName() == PROBLEM_HalfLattice ) {    // HALF LATTICE NOT WORKING
1✔
1446
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1447
    }
1448
    else if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
1✔
1449

1450
        auto nodes = _mesh->GetNodes();
2✔
1451
        double tol = 1e-12;    // For distance to boundary
1✔
1452

1453
        // #pragma omp parallel for
1454
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
201✔
1455

1456
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN || _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
200✔
1457
                _ghostCells[idx_cell] = std::vector<double>( _localNSys, 0.0 );
38✔
1458

1459
                auto localCellNodes = _mesh->GetCells()[idx_cell];
76✔
1460

1461
                for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) {    // Check if corner node is in this cell
56✔
1462
                    if( nodes[localCellNodes[idx_node]][0] < -0.65 + tol ) {                          // close to 0 => left boundary
56✔
1463
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
407✔
1464
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] > 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
396✔
1465
                        }
1466
                        break;
11✔
1467
                    }
1468
                    else if( nodes[localCellNodes[idx_node]][0] > 0.65 - tol ) {    // right boundary
45✔
1469
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
370✔
1470
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] < 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
360✔
1471
                        }
1472
                        break;
10✔
1473
                    }
1474
                    else if( nodes[localCellNodes[idx_node]][1] < -0.65 + tol ) {    // lower boundary
35✔
1475
                        break;
9✔
1476
                    }
1477
                    else if( nodes[localCellNodes[idx_node]][1] > 0.65 - tol ) {    // upper boundary
26✔
1478
                        break;
8✔
1479
                    }
1480
                    else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
18✔
1481
                        ErrorMessages::Error( " Problem with ghost cell setup and  boundary of this mesh ", CURRENT_FUNCTION );
×
1482
                    }
1483
                }
1484
            }
1485
        }
1486
    }
1487
    else if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
×
1488
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1489
    }
1490
}
2✔
1491

1492
void SNSolverHPC::SetProbingCellsLineGreen() {
2✔
1493

1494
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
2✔
1495
        assert( _nProbingCellsLineGreen % 2 == 0 );
1✔
1496

1497
        std::vector<double> p1 = { _cornerUpperLeftGreen[0] + _thicknessGreen / 2.0, _cornerUpperLeftGreen[1] - _thicknessGreen / 2.0 };
2✔
1498
        std::vector<double> p2 = { _cornerUpperRightGreen[0] - _thicknessGreen / 2.0, _cornerUpperRightGreen[1] - _thicknessGreen / 2.0 };
2✔
1499
        std::vector<double> p3 = { _cornerLowerRightGreen[0] - _thicknessGreen / 2.0, _cornerLowerRightGreen[1] + _thicknessGreen / 2.0 };
2✔
1500
        std::vector<double> p4 = { _cornerLowerLeftGreen[0] + _thicknessGreen / 2.0, _cornerLowerLeftGreen[1] + _thicknessGreen / 2.0 };
2✔
1501

1502
        double verticalLineWidth   = std::abs( p1[1] - p4[1] );
1✔
1503
        double horizontalLineWidth = std::abs( p1[0] - p2[0] );
1✔
1504

1505
        double pt_ratio_h = horizontalLineWidth / ( horizontalLineWidth + verticalLineWidth );
1✔
1506

1507
        unsigned nHorizontalProbingCells = (unsigned)std::ceil( _nProbingCellsLineGreen / 2 * pt_ratio_h );
1✔
1508
        unsigned nVerticalProbingCells   = _nProbingCellsLineGreen / 2 - nHorizontalProbingCells;
1✔
1509
        assert( nHorizontalProbingCells > 1 );
1✔
1510
        assert( nVerticalProbingCells > 1 );
1✔
1511

1512
        _probingCellsLineGreen = std::vector<unsigned>( 2 * ( nVerticalProbingCells + nHorizontalProbingCells ) );
1✔
1513

1514
        // Sample points on each side of the rectangle
1515
        std::vector<unsigned> side1 = linspace2D( p1, p2, nHorizontalProbingCells );    // upper horizontal
2✔
1516
        std::vector<unsigned> side2 = linspace2D( p2, p3, nVerticalProbingCells );      // right vertical
2✔
1517
        std::vector<unsigned> side3 = linspace2D( p3, p4, nHorizontalProbingCells );    // lower horizontal
2✔
1518
        std::vector<unsigned> side4 = linspace2D( p4, p1, nVerticalProbingCells );      // left vertical
2✔
1519

1520
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
5✔
1521
            _probingCellsLineGreen[i] = side1[i];
4✔
1522
        }
1523
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
7✔
1524
            _probingCellsLineGreen[i + nHorizontalProbingCells] = side2[i];
6✔
1525
        }
1526
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
5✔
1527
            _probingCellsLineGreen[i + nVerticalProbingCells + nHorizontalProbingCells] = side3[i];
4✔
1528
        }
1529
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
7✔
1530
            _probingCellsLineGreen[i + nVerticalProbingCells + 2 * nHorizontalProbingCells] = side4[i];
6✔
1531
        }
1532

1533
        // Block-wise approach
1534
        // Initialize the vector to store the corner points of each block
1535
        std::vector<std::vector<std::vector<double>>> block_corners;
2✔
1536

1537
        double block_size = 0.05;
1✔
1538
        const double cx   = _centerGreen[0];
1✔
1539
        const double cy   = _centerGreen[1];
1✔
1540

1541
        // Loop to fill the blocks
1542
        for( int i = 0; i < 8; ++i ) {    // 8 blocks in the x-direction (horizontal) (upper) (left to right)
9✔
1543

1544
            // Top row
1545
            double x1 = -0.2 + cx + i * block_size;
8✔
1546
            double y1 = 0.4 + cy;
8✔
1547
            double x2 = x1 + block_size;
8✔
1548
            double y2 = y1 - block_size;
8✔
1549

1550
            std::vector<std::vector<double>> corners = {
1551
                { x1, y1 },    // top-left
1552
                { x2, y1 },    // top-right
1553
                { x2, y2 },    // bottom-right
1554
                { x1, y2 }     // bottom-left
1555
            };
64✔
1556
            block_corners.push_back( corners );
8✔
1557
        }
1558

1559
        for( int j = 0; j < 14; ++j ) {    // 14 blocks in the y-direction (vertical)
15✔
1560
            // right column double x1 = 0.15;
1561
            double x1 = 0.15 + cx;
14✔
1562
            double y1 = 0.35 + cy - j * block_size;
14✔
1563
            double x2 = x1 + block_size;
14✔
1564
            double y2 = y1 - block_size;
14✔
1565

1566
            // Store the four corner points for this block
1567
            std::vector<std::vector<double>> corners = {
1568
                { x1, y1 },    // top-left
1569
                { x2, y1 },    // top-right
1570
                { x2, y2 },    // bottom-right
1571
                { x1, y2 }     // bottom-left
1572
            };
112✔
1573

1574
            block_corners.push_back( corners );
14✔
1575
        }
1576

1577
        for( int i = 0; i < 8; ++i ) {    // 8 blocks in the x-direction (horizontal) (lower) (right to left)
9✔
1578
            // bottom row
1579
            double x1 = 0.15 + cx - i * block_size;
8✔
1580
            double y1 = -0.35 + cy;
8✔
1581
            double x2 = x1 + block_size;
8✔
1582
            double y2 = y1 - block_size;
8✔
1583

1584
            std::vector<std::vector<double>> corners = {
1585
                { x1, y1 },    // top-left
1586
                { x2, y1 },    // top-right
1587
                { x2, y2 },    // bottom-right
1588
                { x1, y2 }     // bottom-left
1589
            };
64✔
1590
            block_corners.push_back( corners );
8✔
1591
        }
1592

1593
        for( int j = 0; j < 14; ++j ) {    // 14 blocks in the y-direction (vertical) (down to up)
15✔
1594

1595
            // left column
1596
            double x1 = -0.2 + cx;
14✔
1597
            double y1 = -0.3 + cy + j * block_size;
14✔
1598
            double x2 = x1 + block_size;
14✔
1599
            double y2 = y1 - block_size;
14✔
1600

1601
            // Store the four corner points for this block
1602
            std::vector<std::vector<double>> corners = {
1603
                { x1, y1 },    // top-left
1604
                { x2, y1 },    // top-right
1605
                { x2, y2 },    // bottom-right
1606
                { x1, y2 }     // bottom-left
1607
            };
112✔
1608

1609
            block_corners.push_back( corners );
14✔
1610
        }
1611

1612
        // Compute the probing cells for each block
1613
        for( unsigned i = 0; i < _nProbingCellsBlocksGreen; i++ ) {
45✔
1614
            _probingCellsBlocksGreen.push_back( _mesh->GetCellsofRectangle( block_corners[i] ) );
44✔
1615
        }
1616
    }
1617
}
2✔
1618

1619
void SNSolverHPC::ComputeQOIsGreenProbingLine() {
5✔
1620
#pragma omp parallel for
5✔
1621
    for( unsigned i = 0; i < _nProbingCellsLineGreen; i++ ) {    // Loop over probing cells
1622
        _absorptionValsLineSegment[i] =
1623
            ( _sigmaT[_probingCellsLineGreen[i]] - _sigmaS[_probingCellsLineGreen[i]] ) * _scalarFlux[_probingCellsLineGreen[i]];
1624
    }
1625

1626
    // Block-wise approach
1627
    // #pragma omp parallel for
1628
    for( unsigned i = 0; i < _nProbingCellsBlocksGreen; i++ ) {
225✔
1629
        _absorptionValsBlocksGreen[i] = 0.0;
220✔
1630
        for( unsigned j = 0; j < _probingCellsBlocksGreen[i].size(); j++ ) {
440✔
1631
            _absorptionValsBlocksGreen[i] += ( _sigmaT[_probingCellsBlocksGreen[i][j]] - _sigmaS[_probingCellsBlocksGreen[i][j]] ) *
440✔
1632
                                             _scalarFlux[_probingCellsBlocksGreen[i][j]] * _areas[_probingCellsBlocksGreen[i][j]];
220✔
1633
        }
1634
    }
1635
    // std::cout << _absorptionValsBlocksGreen[1] << std::endl;
1636
    // std::cout << _absorptionValsLineSegment[1] << std::endl;
1637
}
5✔
1638

1639
std::vector<unsigned> SNSolverHPC::linspace2D( const std::vector<double>& start, const std::vector<double>& end, unsigned num_points ) {
4✔
1640
    /**
1641
     * Generate a 2D linspace based on the start and end points with a specified number of points.
1642
     *
1643
     * @param start vector of starting x and y coordinates
1644
     * @param end vector of ending x and y coordinates
1645
     * @param num_points number of points to generate
1646
     *
1647
     * @return vector of unsigned integers representing the result
1648
     */
1649

1650
    std::vector<unsigned> result;
4✔
1651
    assert( num_points > 1 );
4✔
1652
    result.resize( num_points );
4✔
1653
    double stepX = ( end[0] - start[0] ) / ( num_points - 1 );
4✔
1654
    double stepY = ( end[1] - start[1] ) / ( num_points - 1 );
4✔
1655
#pragma omp parallel for
4✔
1656
    for( unsigned i = 0; i < num_points; ++i ) {
1657
        double x = start[0] + i * stepX;
1658
        double y = start[1] + i * stepY;
1659

1660
        result[i] = _mesh->GetCellOfKoordinate( x, y );
1661
    }
1662

1663
    return result;
4✔
1664
}
1665

1666
void SNSolverHPC::ComputeCellsPerimeterLattice() {
2✔
1667
    double l_1    = 1.5;    // perimeter 1
2✔
1668
    double l_2    = 2.5;    // perimeter 2
2✔
1669
    auto nodes    = _mesh->GetNodes();
4✔
1670
    auto cells    = _mesh->GetCells();
4✔
1671
    auto cellMids = _mesh->GetCellMidPoints();
4✔
1672
    auto normals  = _mesh->GetNormals();
4✔
1673
    auto neigbors = _mesh->GetNeighbours();
4✔
1674

1675
    _isPerimeterLatticeCell1.resize( _mesh->GetNumCells(), false );
2✔
1676
    _isPerimeterLatticeCell2.resize( _mesh->GetNumCells(), false );
2✔
1677

1678
    for( unsigned idx_cell = 0; idx_cell < _mesh->GetNumCells(); ++idx_cell ) {
402✔
1679
        if( abs( cellMids[idx_cell][0] ) < l_1 && abs( cellMids[idx_cell][1] ) < l_1 ) {
400✔
1680
            // Cell is within perimeter
1681
            for( unsigned idx_nbr = 0; idx_nbr < _mesh->GetNumNodesPerCell(); ++idx_nbr ) {
928✔
1682
                if( neigbors[idx_cell][idx_nbr] == _mesh->GetNumCells() ) {
696✔
1683
                    continue;    // Skip boundary - ghost cells
40✔
1684
                }
1685

1686
                if( ( abs( cellMids[neigbors[idx_cell][idx_nbr]][0] ) > l_1 && abs( cellMids[idx_cell][0] ) < l_1 ) ||
1,312✔
1687
                    ( abs( cellMids[neigbors[idx_cell][idx_nbr]][1] ) > l_1 && abs( cellMids[idx_cell][1] ) < l_1 ) ) {
656✔
1688
                    // neighbor is outside perimeter
1689
                    _cellsLatticePerimeter1[idx_cell].push_back( idx_nbr );
16✔
1690
                    _isPerimeterLatticeCell1[idx_cell] = true;
16✔
1691
                }
1692
            }
1693
        }
1694
        else if( abs( cellMids[idx_cell][0] ) < l_2 && abs( cellMids[idx_cell][1] ) < l_2 ) {
168✔
1695
            // Cell is within perimeter
1696
            for( unsigned idx_nbr = 0; idx_nbr < _mesh->GetNumNodesPerCell(); ++idx_nbr ) {
264✔
1697
                if( neigbors[idx_cell][idx_nbr] == _mesh->GetNumCells() ) {
198✔
1698
                    continue;    // Skip boundary - ghost cells
×
1699
                }
1700
                if( ( abs( cellMids[neigbors[idx_cell][idx_nbr]][0] ) > l_2 && abs( cellMids[idx_cell][0] ) < l_2 ) ||
394✔
1701
                    ( abs( cellMids[neigbors[idx_cell][idx_nbr]][1] ) > l_2 && abs( cellMids[idx_cell][1] ) < l_2 ) ) {
196✔
1702
                    // neighbor is outside perimeter
1703
                    _cellsLatticePerimeter2[idx_cell].push_back( idx_nbr );
54✔
1704
                    _isPerimeterLatticeCell2[idx_cell] = true;
54✔
1705
                }
1706
            }
1707
        }
1708
    }
1709
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc