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

CSMMLab / KiT-RT / #110

09 Oct 2025 07:43PM UTC coverage: 46.626% (-0.03%) from 46.655%
#110

push

travis-ci

web-flow
Merge 740a903b1 into 5a519d0c8

2 of 12 new or added lines in 2 files covered. (16.67%)

24 existing lines in 2 files now uncovered.

4422 of 9484 relevant lines covered (46.63%)

57126.88 hits per line

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

0.0
/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

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

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

38
    _nq   = static_cast<unsigned long>( quad->GetNq() );
×
39
    _nSys = _nq;
×
40

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

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

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

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

64
    _spatialOrder  = _settings->GetSpatialOrder();
×
65
    _temporalOrder = _settings->GetTemporalOrder();
×
66

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

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

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

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

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

93
    _scalarFlux              = std::vector<double>( _nCells );
×
94
    _localMaxOrdinateOutflow = std::vector<double>( _nCells );
×
95

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

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

110
    _dT    = ComputeTimeStep( _settings->GetCFL() );
×
111
    _nIter = unsigned( _settings->GetTEnd() / _dT ) + 1;
×
112

113
    auto quadPoints  = quad->GetPoints();
×
114
    auto quadWeights = quad->GetWeights();
×
115

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

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

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

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

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

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

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

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

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

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

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

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

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

222
    // Initialiye QOIS
223
    _mass    = 0;
×
224
    _rmsFlux = 0;
×
225

226
    {    // Hohlraum
227

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

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

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

249
        // Green
250
        _thicknessGreen = 0.05;
×
251

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

267
        _nProbingCellsLineGreen = _settings->GetNumProbingCellsLineHohlraum();
×
268

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

273
        SetProbingCellsLineGreen();    // ONLY FOR HOHLRAUM
×
274
    }
275
}
276

277
SNSolverHPC::~SNSolverHPC() {
×
278
    delete _mesh;
×
279
    delete _problem;
×
280
}
281

282
void SNSolverHPC::Solve() {
×
283

284
    // --- Preprocessing ---
285
    if( _rank == 0 ) {
×
286
        PrepareVolumeOutput();
×
287
        DrawPreSolverOutput();
×
288
    }
NEW
289
    _curSimTime = 0.0;
×
290
    auto start = std::chrono::high_resolution_clock::now();    // Start timing
×
291

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

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

317
            ( _spatialOrder == 2 ) ? FluxOrder2() : FluxOrder1();
×
318
            FVMUpdate();
×
319
        }
NEW
320
        _curSimTime += _dT;
×
UNCOV
321
        IterPostprocessing();
×
322
        // --- Wall time measurement
323
        duration  = std::chrono::high_resolution_clock::now() - start;
×
324
        _currTime = std::chrono::duration_cast<std::chrono::duration<double>>( duration ).count();
×
325

326
        // --- Write Output ---
327
        if( _rank == 0 ) {
×
328

329
            WriteScalarOutput( iter );
×
330

331
            // --- Update Scalar Fluxes
332

333
            // --- Print Output ---
334
            PrintScreenOutput( iter );
×
335
            PrintHistoryOutput( iter );
×
336
        }
337
#ifdef BUILD_MPI
338
        MPI_Barrier( MPI_COMM_WORLD );
339
#endif
340

341
        PrintVolumeOutput( iter );
×
342
#ifdef BUILD_MPI
343
        MPI_Barrier( MPI_COMM_WORLD );
344
#endif
345
    }
346
    // --- Postprocessing ---
347
    if( _rank == 0 ) {
×
348
        DrawPostSolverOutput();
×
349
    }
350
}
351

352
void SNSolverHPC::FluxOrder2() {
×
353

354
    double const eps = 1e-10;
×
355

356
#pragma omp parallel for
×
357
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {            // Compute Slopes
358
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) {                // skip ghost cells
359
                                                                                   // #pragma omp simd
360
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {    //
361
                _limiter[Idx2D( idx_cell, idx_sys, _localNSys )]         = 1.;     // limiter should be zero at boundary//
362
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
363
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.;    //
364
                double solInterfaceAvg                                   = 0.0;
365
                for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {            // Compute slopes and mininum and maximum
366
                    unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    //
367
                    // Slopes
368
                    solInterfaceAvg = 0.5 * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] + _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] );
369
                    _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] +=
370
                        solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )];
371
                    _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] +=
372
                        solInterfaceAvg * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
373
                }    //
374
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] /= _areas[idx_cell];
375
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] /= _areas[idx_cell];
376
            }
377
        }
378
    }
379
#pragma omp parallel for
×
380
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {    // Compute Limiter
381
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NONE ) {        // skip ghost cells
382

383
#pragma omp simd
384
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
385

386
                double gaussPoint = 0;
387
                double r          = 0;
388
                double minSol     = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
389
                double maxSol     = _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
390

391
                for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {    // Compute slopes and mininum and maximum
392
                    unsigned nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];
393
                    // Compute ptswise max and minimum solultion values of current and neighbor cells
394
                    maxSol = std::max( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], maxSol );
395
                    minSol = std::min( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )], minSol );
396
                }
397

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

400
                    // Compute test value at cell vertex, called gaussPt
401
                    gaussPoint =
402
                        _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
403
                            _relativeCellVertices[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
404
                        _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] * _relativeCellVertices[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
405

406
                    // BARTH-JESPERSEN LIMITER
407
                    // r = ( gaussPoint > 0 ) ? std::min( ( maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint + eps ), 1.0 )
408
                    //                       : std::min( ( minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )] ) / ( gaussPoint - eps ), 1.0 );
409
                    //
410
                    // r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
411
                    //_limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
412

413
                    // VENKATAKRISHNAN LIMITER
414
                    double delta1Max = maxSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
415
                    double delta1Min = minSol - _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
416

417
                    r = ( gaussPoint > 0 ) ? ( ( delta1Max * delta1Max + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Max ) /
418
                                                 ( delta1Max * delta1Max + 2 * gaussPoint * gaussPoint + delta1Max * gaussPoint + _areas[idx_cell] ) /
419
                                                 ( gaussPoint + eps )
420
                                           : ( ( delta1Min * delta1Min + _areas[idx_cell] ) * gaussPoint + 2 * gaussPoint * gaussPoint * delta1Min ) /
421
                                                 ( delta1Min * delta1Min + 2 * gaussPoint * gaussPoint + delta1Min * gaussPoint + _areas[idx_cell] ) /
422
                                                 ( gaussPoint - eps );
423

424
                    r = ( std::abs( gaussPoint ) < eps ) ? 1 : r;
425

426
                    _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] = std::min( r, _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] );
427
                }
428
            }
429
        }
430
        else {
431
#pragma omp simd
432
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
433
                _limiter[Idx2D( idx_cell, idx_sys, _localNSys )]         = 0.;    // limiter should be zero at boundary
434
                _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] = 0.;
435
                _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] = 0.;
436
            }
437
        }
438
    }
439
#pragma omp parallel for
×
440
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {    // Compute Flux
441
#pragma omp simd
442
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
443
            _flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.;
444
        }
445

446
        // Fluxes
447
        for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
448
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
449
                // #pragma omp simd
450
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
451
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
452
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
453
                    if( localInner > 0 ) {
454
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
455
                    }
456
                    else {
457
                        double ghostCellValue = _ghostCells[idx_cell][idx_sys];    // fixed boundary
458
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
459
                    }
460
                }
461
            }
462
            else {
463

464
                unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    // global idx of neighbor cell
465
                                                                                           // Second order
466
#pragma omp simd
467
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
468
                    // store flux contribution on psiNew_sigmaS to save memory
469
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
470
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
471

472
                    _flux[Idx2D( idx_cell, idx_sys, _localNSys )] +=
473
                        ( localInner > 0 ) ? localInner * ( _sol[Idx2D( idx_cell, idx_sys, _localNSys )] +
474
                                                            _limiter[Idx2D( idx_cell, idx_sys, _localNSys )] *
475
                                                                ( _solDx[Idx3D( idx_cell, idx_sys, 0, _localNSys, _nDim )] *
476
                                                                      _relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
477
                                                                  _solDx[Idx3D( idx_cell, idx_sys, 1, _localNSys, _nDim )] *
478
                                                                      _relativeInterfaceMidPt[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) )
479
                                           : localInner * ( _sol[Idx2D( nbr_glob, idx_sys, _localNSys )] +
480
                                                            _limiter[Idx2D( nbr_glob, idx_sys, _localNSys )] *
481
                                                                ( _solDx[Idx3D( nbr_glob, idx_sys, 0, _localNSys, _nDim )] *
482
                                                                      ( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] -
483
                                                                        _cellMidPoints[Idx2D( nbr_glob, 0, _nDim )] ) +
484
                                                                  _solDx[Idx3D( nbr_glob, idx_sys, 1, _localNSys, _nDim )] *
485
                                                                      ( _interfaceMidPoints[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] -
486
                                                                        _cellMidPoints[Idx2D( nbr_glob, 1, _nDim )] ) ) );
487
                }
488
            }
489
        }
490
    }
491
}
492

493
void SNSolverHPC::FluxOrder1() {
×
494

495
#pragma omp parallel for
×
496
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
497

498
#pragma omp simd
499
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
500
            _flux[Idx2D( idx_cell, idx_sys, _localNSys )] = 0.0;    // Reset temporary variable
501
        }
502

503
        // Fluxes
504
        for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
505
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
506
#pragma omp simd
507
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
508
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
509
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
510
                    if( localInner > 0 ) {
511
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )];
512
                    }
513
                    else {
514
                        double ghostCellValue = _ghostCells[idx_cell][idx_sys];    // fixed boundary
515
                        _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += localInner * ghostCellValue;
516
                    }
517
                }
518
            }
519
            else {
520
                unsigned long nbr_glob = _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )];    // global idx of neighbor cell
521
#pragma omp simd
522
                for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
523

524
                    double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
525
                                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
526

527
                    _flux[Idx2D( idx_cell, idx_sys, _localNSys )] += ( localInner > 0 ) ? localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )]
528
                                                                                        : localInner * _sol[Idx2D( nbr_glob, idx_sys, _localNSys )];
529
                }
530
            }
531
        }
532
    }
533
}
534

535
void SNSolverHPC::FVMUpdate() {
×
536
    _mass    = 0.0;
×
537
    _rmsFlux = 0.0;
×
538
    std::vector<double> temp_scalarFlux( _nCells );    // for MPI allreduce
×
539

540
#pragma omp parallel for reduction( + : _mass, _rmsFlux )
×
541
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
542

543
#pragma omp simd
544
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
545
            // Update
546
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )] =
547
                ( 1 - _dT * _sigmaT[idx_cell] ) * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] -
548
                _dT / _areas[idx_cell] * _flux[Idx2D( idx_cell, idx_sys, _localNSys )] +
549
                _dT * ( _sigmaS[idx_cell] * _scalarFlux[idx_cell] / ( 2 * M_PI ) + _source[Idx2D( idx_cell, idx_sys, _localNSys )] );
550
        }
551
        double localScalarFlux = 0;
552

553
#pragma omp simd reduction( + : localScalarFlux )
554
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
555
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )] = std::max( _sol[Idx2D( idx_cell, idx_sys, _localNSys )], 0.0 );
556
            localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
557
        }
558
        _mass += localScalarFlux * _areas[idx_cell];
559
        _rmsFlux += ( localScalarFlux - _scalarFlux[idx_cell] ) * ( localScalarFlux - _scalarFlux[idx_cell] );
560
        temp_scalarFlux[idx_cell] = localScalarFlux;    // set flux
561
    }
562
// MPI Allreduce: _scalarFlux
563
#ifdef IMPORT_MPI
564
    MPI_Barrier( MPI_COMM_WORLD );
565
    MPI_Allreduce( temp_scalarFlux.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
566
    MPI_Barrier( MPI_COMM_WORLD );
567
#endif
568
#ifndef IMPORT_MPI
569
    _scalarFlux = temp_scalarFlux;
×
570
#endif
571
}
572

573
void SNSolverHPC::IterPostprocessing() {
×
574
    // ALREDUCE NEEDED
575

576
    _curAbsorptionLattice            = 0.0;
×
577
    _curScalarOutflow                = 0.0;
×
578
    _curScalarOutflowPeri1           = 0.0;
×
579
    _curScalarOutflowPeri2           = 0.0;
×
580
    _curAbsorptionHohlraumCenter     = 0.0;    // Green and blue areas of symmetric hohlraum
×
581
    _curAbsorptionHohlraumVertical   = 0.0;    // Red areas of symmetric hohlraum
×
582
    _curAbsorptionHohlraumHorizontal = 0.0;    // Black areas of symmetric hohlraum
×
583
    _varAbsorptionHohlraumGreen      = 0.0;
×
584
    double a_g                       = 0.0;
×
585

586
#pragma omp parallel for reduction( + : _curAbsorptionLattice,                                                                                       \
×
587
                                        _curScalarOutflow,                                                                                           \
588
                                        _curScalarOutflowPeri1,                                                                                      \
589
                                        _curScalarOutflowPeri2,                                                                                      \
590
                                        _curAbsorptionHohlraumCenter,                                                                                \
591
                                        _curAbsorptionHohlraumVertical,                                                                              \
592
                                        _curAbsorptionHohlraumHorizontal,                                                                            \
593
                                        a_g ) reduction( max : _curMaxOrdinateOutflow, _curMaxAbsorptionLattice )
×
594
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
595

596
        if( _settings->GetProblemName() == PROBLEM_Lattice || _settings->GetProblemName() == PROBLEM_HalfLattice ) {
597
            if( IsAbsorptionLattice( _cellMidPoints[Idx2D( idx_cell, 0, _nDim )], _cellMidPoints[Idx2D( idx_cell, 1, _nDim )] ) ) {
598
                double sigmaAPsi = _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
599
                _curAbsorptionLattice += sigmaAPsi;
600
                _curMaxAbsorptionLattice = ( _curMaxAbsorptionLattice < sigmaAPsi ) ? sigmaAPsi : _curMaxAbsorptionLattice;
601
            }
602
        }
603

604
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {    //} || _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
605

606
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
607
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
608
            _curAbsorptionLattice += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
609
            if( x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
610
                y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum() ) {
611
                _curAbsorptionHohlraumCenter += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
612
            }
613
            if( ( x < _settings->GetPosRedLeftBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
614
                  y < _settings->GetPosRedLeftTopHohlraum() ) ||
615
                ( x > _settings->GetPosRedRightBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
616
                  y < _settings->GetPosRedRightTopHohlraum() ) ) {
617
                _curAbsorptionHohlraumVertical += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
618
            }
619
            if( y > 0.6 || y < -0.6 ) {
620
                _curAbsorptionHohlraumHorizontal += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
621
            }
622

623
            // Variation in absorption of center (part 1)
624
            // green area 1 (lower boundary)
625
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
626
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
627
            // green area 2 (upper boundary)
628
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
629
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
630
            // green area 3 (left boundary)
631
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
632
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
633
            // green area 4 (right boundary)
634
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
635
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
636
            if( green1 || green2 || green3 || green4 ) {
637
                a_g += ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _scalarFlux[idx_cell] * _areas[idx_cell] /
638
                       ( 44 * 0.05 * 0.05 );    // divisor is area of the green
639
            }
640
        }
641

642
        if( _settings->GetProblemName() == PROBLEM_Lattice ) {
643
            // Outflow out of inner and middle perimeter
644
            if( _isPerimeterLatticeCell1[idx_cell] ) {    // inner
645
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter1[idx_cell].size(); ++idx_nbr_helper ) {
646
#pragma omp simd reduction( + : _curScalarOutflowPeri1 )
647
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
648
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
649
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
650
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
651
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
652
                        // Find outward facing transport directions
653

654
                        if( localInner > 0.0 ) {
655
                            _curScalarOutflowPeri1 +=
656
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
657
                        }
658
                    }
659
                }
660
            }
661
            if( _isPerimeterLatticeCell2[idx_cell] ) {    // middle
662
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter2[idx_cell].size(); ++idx_nbr_helper ) {
663
#pragma omp simd reduction( + : _curScalarOutflowPeri2 )
664
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
665
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
666
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
667
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
668
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
669
                        // Find outward facing transport directions
670

671
                        if( localInner > 0.0 ) {
672
                            _curScalarOutflowPeri2 +=
673
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
674
                        }
675
                    }
676
                }
677
            }
678
        }
679
        // Outflow out of domain
680
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN ) {
681
            // Iterate over face cell faces
682
            double currOrdinatewiseOutflow = 0.0;
683

684
            for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
685
                // Find face that points outward
686
                if( _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
687
#pragma omp simd reduction( + : _curScalarOutflow ) reduction( max : _curMaxOrdinateOutflow )
688
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
689

690
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
691
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
692
                        // Find outward facing transport directions
693

694
                        if( localInner > 0.0 ) {
695
                            _curScalarOutflow +=
696
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
697

698
                            currOrdinatewiseOutflow =
699
                                _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * localInner /
700
                                sqrt( (
701
                                    _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
702
                                    _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) );
703

704
                            _curMaxOrdinateOutflow =
705
                                ( currOrdinatewiseOutflow > _curMaxOrdinateOutflow ) ? currOrdinatewiseOutflow : _curMaxOrdinateOutflow;
706
                        }
707
                    }
708
                }
709
            }
710
        }
711
    }
712
// MPI Allreduce
713
#ifdef IMPORT_MPI
714
    double tmp_curScalarOutflow      = 0.0;
715
    double tmp_curScalarOutflowPeri1 = 0.0;
716
    double tmp_curScalarOutflowPeri2 = 0.0;
717
    double tmp_mass                  = 0.0;
718
    double tmp_rmsFlux               = 0.0;
719
    MPI_Barrier( MPI_COMM_WORLD );
720
    MPI_Allreduce( &_curScalarOutflow, &tmp_curScalarOutflow, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
721
    _curScalarOutflow = tmp_curScalarOutflow;
722
    MPI_Barrier( MPI_COMM_WORLD );
723
    MPI_Allreduce( &_curScalarOutflowPeri1, &tmp_curScalarOutflowPeri1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
724
    _curScalarOutflowPeri1 = tmp_curScalarOutflowPeri1;
725
    MPI_Barrier( MPI_COMM_WORLD );
726
    MPI_Allreduce( &_curScalarOutflowPeri2, &tmp_curScalarOutflowPeri2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
727
    _curScalarOutflowPeri2 = tmp_curScalarOutflowPeri2;
728
    MPI_Barrier( MPI_COMM_WORLD );
729
    MPI_Allreduce( &_mass, &tmp_mass, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
730
    _mass = tmp_mass;
731
    MPI_Barrier( MPI_COMM_WORLD );
732
    MPI_Allreduce( &_rmsFlux, &tmp_rmsFlux, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
733
    _rmsFlux = tmp_rmsFlux;
734
    MPI_Barrier( MPI_COMM_WORLD );
735
#endif
736
    // Variation absorption (part II)
737
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
738
        unsigned n_probes = 4;
×
739
        std::vector<double> temp_probingMoments( 3 * n_probes );    // for MPI allreduce
×
740

741
#pragma omp parallel for reduction( + : _varAbsorptionHohlraumGreen )
×
742
        for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
743
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
744
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
745

746
            // green area 1 (lower boundary)
747
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
748
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
749
            // green area 2 (upper boundary)
750
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
751
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
752
            // green area 3 (left boundary)
753
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
754
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
755
            // green area 4 (right boundary)
756
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
757
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
758
            if( green1 || green2 || green3 || green4 ) {
759
                _varAbsorptionHohlraumGreen += ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) *
760
                                               ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) * _areas[idx_cell];
761
            }
762
        }
763
        // Probes value moments
764
        // #pragma omp parallel for
765
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
×
766
            temp_probingMoments[Idx2D( idx_probe, 0, 3 )] = 0.0;
×
767
            temp_probingMoments[Idx2D( idx_probe, 1, 3 )] = 0.0;
×
768
            temp_probingMoments[Idx2D( idx_probe, 2, 3 )] = 0.0;
×
769
            // for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
770
            //   std::cout << idx_ball << _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI ) << std::endl;
771
            //}
772
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
773
                for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
×
774
                    temp_probingMoments[Idx2D( idx_probe, 0, 3 )] += _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
775
                                                                     _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] /
×
776
                                                                     ( 0.01 * 0.01 * M_PI );
777
                    temp_probingMoments[Idx2D( idx_probe, 1, 3 )] +=
×
778
                        _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
779
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
×
780
                    temp_probingMoments[Idx2D( idx_probe, 2, 3 )] +=
×
781
                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
782
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
×
783
                }
784
            }
785
        }
786

787
#ifdef IMPORT_MPI
788
        MPI_Barrier( MPI_COMM_WORLD );
789
        MPI_Allreduce( temp_probingMoments.data(), _probingMoments.data(), 3 * n_probes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
790
        MPI_Barrier( MPI_COMM_WORLD );
791
#endif
792
#ifndef IMPORT_MPI
793
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
×
794
            _probingMoments[Idx2D( idx_probe, 0, 3 )] = temp_probingMoments[Idx2D( idx_probe, 0, 3 )];
×
795
            _probingMoments[Idx2D( idx_probe, 1, 3 )] = temp_probingMoments[Idx2D( idx_probe, 1, 3 )];
×
796
            _probingMoments[Idx2D( idx_probe, 2, 3 )] = temp_probingMoments[Idx2D( idx_probe, 2, 3 )];
×
797
        }
798
#endif
799
    }
800
    // probe values green
801
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
802
        ComputeQOIsGreenProbingLine();
×
803
    }
804
    // Update time integral values on rank 0
805
    if( _rank == 0 ) {
×
806
        _totalScalarOutflow += _curScalarOutflow * _dT;
×
807
        _totalScalarOutflowPeri1 += _curScalarOutflowPeri1 * _dT;
×
808
        _totalScalarOutflowPeri2 += _curScalarOutflowPeri2 * _dT;
×
809
        _totalAbsorptionLattice += _curAbsorptionLattice * _dT;
×
810

811
        _totalAbsorptionHohlraumCenter += _curAbsorptionHohlraumCenter * _dT;
×
812
        _totalAbsorptionHohlraumVertical += _curAbsorptionHohlraumVertical * _dT;
×
813
        _totalAbsorptionHohlraumHorizontal += _curAbsorptionHohlraumHorizontal * _dT;
×
814

815
        _rmsFlux = sqrt( _rmsFlux );
×
816
    }
817
}
818

819
bool SNSolverHPC::IsAbsorptionLattice( double x, double y ) const {
×
820
    // Check whether pos is inside absorbing squares
821
    double xy_corrector = -3.5;
×
822
    std::vector<double> lbounds{ 1 + xy_corrector, 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector };
×
823
    std::vector<double> ubounds{ 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector, 6 + xy_corrector };
×
824
    for( unsigned k = 0; k < lbounds.size(); ++k ) {
×
825
        for( unsigned l = 0; l < lbounds.size(); ++l ) {
×
826
            if( ( l + k ) % 2 == 1 || ( k == 2 && l == 2 ) || ( k == 2 && l == 4 ) ) continue;
×
827
            if( x >= lbounds[k] && x <= ubounds[k] && y >= lbounds[l] && y <= ubounds[l] ) {
×
828
                return true;
×
829
            }
830
        }
831
    }
832
    return false;
×
833
}
834

835
// --- Helper ---
836
double SNSolverHPC::ComputeTimeStep( double cfl ) const {
×
837
    // for pseudo 1D, set timestep to dx
838
    double dx, dy;
839
    switch( _settings->GetProblemName() ) {
×
840
        case PROBLEM_Checkerboard1D:
×
841
            dx = 7.0 / (double)_nCells;
×
842
            dy = 0.3;
×
843
            return cfl * ( dx * dy ) / ( dx + dy );
×
844
            break;
845
        case PROBLEM_Linesource1D:     // Fallthrough
×
846
        case PROBLEM_Meltingcube1D:    // Fallthrough
847
        case PROBLEM_Aircavity1D:
848
            dx = 3.0 / (double)_nCells;
×
849
            dy = 0.3;
×
850
            return cfl * ( dx * dy ) / ( dx + dy );
×
851
            break;
852
        default: break;    // 2d as normal
×
853
    }
854
    // 2D case
855
    double charSize = __DBL_MAX__;    // minimum char size of all mesh cells in the mesh
×
856

857
#pragma omp parallel for reduction( min : charSize )
×
858
    for( unsigned long j = 0; j < _nCells; j++ ) {
859
        double currCharSize = sqrt( _areas[j] );
860
        if( currCharSize < charSize ) {
861
            charSize = currCharSize;
862
        }
863
    }
864
    if( _rank == 0 ) {
×
865
        auto log         = spdlog::get( "event" );
×
866
        std::string line = "| Smallest characteristic length of a grid cell in this mesh: " + std::to_string( charSize );
×
867
        log->info( line );
×
868
        line = "| Corresponding maximal time-step: " + std::to_string( cfl * charSize );
×
869
        log->info( line );
×
870
    }
871
    return cfl * charSize;
×
872
}
873

874
// --- IO ----
875
void SNSolverHPC::PrepareScreenOutput() {
×
876
    unsigned nFields = (unsigned)_settings->GetNScreenOutput();
×
877

878
    _screenOutputFieldNames.resize( nFields );
×
879
    _screenOutputFields.resize( nFields );
×
880

881
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
882
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
883
        // Prepare all Output Fields per group
884

885
        // Different procedure, depending on the Group...
886
        switch( _settings->GetScreenOutput()[idx_field] ) {
×
887
            case MASS: _screenOutputFieldNames[idx_field] = "Mass"; break;
×
888
            case ITER: _screenOutputFieldNames[idx_field] = "Iter"; break;
×
NEW
889
            case SIM_TIME: _screenOutputFieldNames[idx_field] = "Sim time"; break;
×
890
            case WALL_TIME: _screenOutputFieldNames[idx_field] = "Wall time [s]"; break;
×
891
            case RMS_FLUX: _screenOutputFieldNames[idx_field] = "RMS flux"; break;
×
892
            case VTK_OUTPUT: _screenOutputFieldNames[idx_field] = "VTK out"; break;
×
893
            case CSV_OUTPUT: _screenOutputFieldNames[idx_field] = "CSV out"; break;
×
894
            case CUR_OUTFLOW: _screenOutputFieldNames[idx_field] = "Cur. outflow"; break;
×
895
            case TOTAL_OUTFLOW: _screenOutputFieldNames[idx_field] = "Tot. outflow"; break;
×
896
            case CUR_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Cur. outflow P1"; break;
×
897
            case TOTAL_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Tot. outflow P1"; break;
×
898
            case CUR_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Cur. outflow P2"; break;
×
899
            case TOTAL_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Tot. outflow P2"; break;
×
900
            case MAX_OUTFLOW: _screenOutputFieldNames[idx_field] = "Max outflow"; break;
×
901
            case CUR_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Cur. absorption"; break;
×
902
            case TOTAL_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Tot. absorption"; break;
×
903
            case MAX_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Max absorption"; break;
×
904
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFieldNames[idx_field] = "Tot. abs. center"; break;
×
905
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFieldNames[idx_field] = "Tot. abs. vertical wall"; break;
×
906
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFieldNames[idx_field] = "Tot. abs. horizontal wall"; break;
×
907
            case PROBE_MOMENT_TIME_TRACE:
×
908
                _screenOutputFieldNames[idx_field] = "Probe 1 u_0";
×
909
                idx_field++;
×
910
                _screenOutputFieldNames[idx_field] = "Probe 2 u_0";
×
911
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
912
                    idx_field++;
×
913
                    _screenOutputFieldNames[idx_field] = "Probe 3 u_0";
×
914
                    idx_field++;
×
915
                    _screenOutputFieldNames[idx_field] = "Probe 4 u_0";
×
916
                }
917
                break;
×
918
            case VAR_ABSORPTION_GREEN: _screenOutputFieldNames[idx_field] = "Var. absorption green"; break;
×
919

920
            default: ErrorMessages::Error( "Screen output field not defined!", CURRENT_FUNCTION ); break;
×
921
        }
922
    }
923
}
924

925
void SNSolverHPC::WriteScalarOutput( unsigned idx_iter ) {
×
926
    unsigned n_probes = 4;
×
927

928
    unsigned nFields                  = (unsigned)_settings->GetNScreenOutput();
×
929
    const VectorVector probingMoments = _problem->GetCurrentProbeMoment();
×
930
    // -- Screen Output
931
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
932
        // Prepare all Output Fields per group
933
        // Different procedure, depending on the Group...
934
        switch( _settings->GetScreenOutput()[idx_field] ) {
×
935
            case MASS: _screenOutputFields[idx_field] = _mass; break;
×
936
            case ITER: _screenOutputFields[idx_field] = idx_iter; break;
×
NEW
937
            case SIM_TIME: _screenOutputFields[idx_field] = _curSimTime; break;
×
938
            case WALL_TIME: _screenOutputFields[idx_field] = _currTime; break;
×
939
            case RMS_FLUX: _screenOutputFields[idx_field] = _rmsFlux; break;
×
940
            case VTK_OUTPUT:
×
941
                _screenOutputFields[idx_field] = 0;
×
942
                if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
×
943
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
944
                    _screenOutputFields[idx_field] = 1;
×
945
                }
946
                break;
×
947
            case CSV_OUTPUT:
×
948
                _screenOutputFields[idx_field] = 0;
×
949
                if( ( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
×
950
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
951
                    _screenOutputFields[idx_field] = 1;
×
952
                }
953
                break;
×
954
            case CUR_OUTFLOW: _screenOutputFields[idx_field] = _curScalarOutflow; break;
×
955
            case TOTAL_OUTFLOW: _screenOutputFields[idx_field] = _totalScalarOutflow; break;
×
956
            case CUR_OUTFLOW_P1: _screenOutputFields[idx_field] = _curScalarOutflowPeri1; break;
×
957
            case TOTAL_OUTFLOW_P1: _screenOutputFields[idx_field] = _totalScalarOutflowPeri1; break;
×
958
            case CUR_OUTFLOW_P2: _screenOutputFields[idx_field] = _curScalarOutflowPeri2; break;
×
959
            case TOTAL_OUTFLOW_P2: _screenOutputFields[idx_field] = _totalScalarOutflowPeri2; break;
×
960
            case MAX_OUTFLOW: _screenOutputFields[idx_field] = _curMaxOrdinateOutflow; break;
×
961
            case CUR_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _curAbsorptionLattice; break;
×
962
            case TOTAL_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _totalAbsorptionLattice; break;
×
963
            case MAX_PARTICLE_ABSORPTION: _screenOutputFields[idx_field] = _curMaxAbsorptionLattice; break;
×
964
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumCenter; break;
×
965
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumVertical; break;
×
966
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFields[idx_field] = _totalAbsorptionHohlraumHorizontal; break;
×
967
            case PROBE_MOMENT_TIME_TRACE:
×
968
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
×
969
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
970
                for( unsigned i = 0; i < n_probes; i++ ) {
×
971
                    _screenOutputFields[idx_field] = _probingMoments[Idx2D( i, 0, 3 )];
×
972
                    idx_field++;
×
973
                }
974
                idx_field--;
×
975
                break;
×
976
            case VAR_ABSORPTION_GREEN: _screenOutputFields[idx_field] = _absorptionValsBlocksGreen[0]; break;
×
977
            default: ErrorMessages::Error( "Screen output group not defined!", CURRENT_FUNCTION ); break;
×
978
        }
979
    }
980

981
    // --- History output ---
982
    nFields = (unsigned)_settings->GetNHistoryOutput();
×
983

984
    std::vector<SCALAR_OUTPUT> screenOutputFields = _settings->GetScreenOutput();
×
985
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
986

987
        // Prepare all Output Fields per group
988
        // Different procedure, depending on the Group...
989
        switch( _settings->GetHistoryOutput()[idx_field] ) {
×
990
            case MASS: _historyOutputFields[idx_field] = _mass; break;
×
991
            case ITER: _historyOutputFields[idx_field] = idx_iter; break;
×
NEW
992
            case SIM_TIME: _screenOutputFields[idx_field] = _curSimTime; break;
×
993
            case WALL_TIME: _historyOutputFields[idx_field] = _currTime; break;
×
994
            case RMS_FLUX: _historyOutputFields[idx_field] = _rmsFlux; break;
×
995
            case VTK_OUTPUT:
×
996
                _historyOutputFields[idx_field] = 0;
×
997
                if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
×
998
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
999
                    _historyOutputFields[idx_field] = 1;
×
1000
                }
1001
                break;
×
1002

1003
            case CSV_OUTPUT:
×
1004
                _historyOutputFields[idx_field] = 0;
×
1005
                if( ( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) ||
×
1006
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
1007
                    _historyOutputFields[idx_field] = 1;
×
1008
                }
1009
                break;
×
1010
            case CUR_OUTFLOW: _historyOutputFields[idx_field] = _curScalarOutflow; break;
×
1011
            case TOTAL_OUTFLOW: _historyOutputFields[idx_field] = _totalScalarOutflow; break;
×
1012
            case CUR_OUTFLOW_P1: _historyOutputFields[idx_field] = _curScalarOutflowPeri1; break;
×
1013
            case TOTAL_OUTFLOW_P1: _historyOutputFields[idx_field] = _totalScalarOutflowPeri1; break;
×
1014
            case CUR_OUTFLOW_P2: _historyOutputFields[idx_field] = _curScalarOutflowPeri2; break;
×
1015
            case TOTAL_OUTFLOW_P2: _historyOutputFields[idx_field] = _totalScalarOutflowPeri2; break;
×
1016
            case MAX_OUTFLOW: _historyOutputFields[idx_field] = _curMaxOrdinateOutflow; break;
×
1017
            case CUR_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _curAbsorptionLattice; break;
×
1018
            case TOTAL_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _totalAbsorptionLattice; break;
×
1019
            case MAX_PARTICLE_ABSORPTION: _historyOutputFields[idx_field] = _curMaxAbsorptionLattice; break;
×
1020
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumCenter; break;
×
1021
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumVertical; break;
×
1022
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _historyOutputFields[idx_field] = _totalAbsorptionHohlraumHorizontal; break;
×
1023
            case PROBE_MOMENT_TIME_TRACE:
×
1024
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
×
1025
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1026
                for( unsigned i = 0; i < n_probes; i++ ) {
×
1027
                    for( unsigned j = 0; j < 3; j++ ) {
×
1028
                        _historyOutputFields[idx_field] = _probingMoments[Idx2D( i, j, 3 )];
×
1029
                        idx_field++;
×
1030
                    }
1031
                }
1032
                idx_field--;
×
1033
                break;
×
1034
            case VAR_ABSORPTION_GREEN: _historyOutputFields[idx_field] = _varAbsorptionHohlraumGreen; break;
×
1035
            case ABSORPTION_GREEN_LINE:
×
1036
                for( unsigned i = 0; i < _settings->GetNumProbingCellsLineHohlraum(); i++ ) {
×
1037
                    _historyOutputFields[idx_field] = _absorptionValsLineSegment[i];
×
1038
                    idx_field++;
×
1039
                }
1040
                idx_field--;
×
1041
                break;
×
1042
            case ABSORPTION_GREEN_BLOCK:
×
1043
                for( unsigned i = 0; i < 44; i++ ) {
×
1044
                    _historyOutputFields[idx_field] = _absorptionValsBlocksGreen[i];
×
1045
                    // std::cout << _absorptionValsBlocksGreen[i] << "/" << _historyOutputFields[idx_field] << std::endl;
1046
                    idx_field++;
×
1047
                }
1048
                idx_field--;
×
1049
                break;
×
1050
            default: ErrorMessages::Error( "History output group not defined!", CURRENT_FUNCTION ); break;
×
1051
        }
1052
    }
1053
}
1054

1055
void SNSolverHPC::PrintScreenOutput( unsigned idx_iter ) {
×
1056
    auto log = spdlog::get( "event" );
×
1057

1058
    unsigned strLen  = 15;    // max width of one column
×
1059
    char paddingChar = ' ';
×
1060

1061
    // assemble the line to print
1062
    std::string lineToPrint = "| ";
×
1063
    std::string tmp;
×
1064
    for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput(); idx_field++ ) {
×
1065
        tmp = std::to_string( _screenOutputFields[idx_field] );
×
1066

1067
        // Format outputs correctly
1068
        std::vector<SCALAR_OUTPUT> integerFields    = { ITER };
×
1069
        std::vector<SCALAR_OUTPUT> scientificFields = { RMS_FLUX,
1070
                                                        MASS,
1071
                                                        WALL_TIME,
1072
                                                        CUR_OUTFLOW,
1073
                                                        TOTAL_OUTFLOW,
1074
                                                        CUR_OUTFLOW_P1,
1075
                                                        TOTAL_OUTFLOW_P1,
1076
                                                        CUR_OUTFLOW_P2,
1077
                                                        TOTAL_OUTFLOW_P2,
1078
                                                        MAX_OUTFLOW,
1079
                                                        CUR_PARTICLE_ABSORPTION,
1080
                                                        TOTAL_PARTICLE_ABSORPTION,
1081
                                                        MAX_PARTICLE_ABSORPTION,
1082
                                                        TOTAL_PARTICLE_ABSORPTION_CENTER,
1083
                                                        TOTAL_PARTICLE_ABSORPTION_VERTICAL,
1084
                                                        TOTAL_PARTICLE_ABSORPTION_HORIZONTAL,
1085
                                                        PROBE_MOMENT_TIME_TRACE,
1086
                                                        VAR_ABSORPTION_GREEN,
1087
                                                        ABSORPTION_GREEN_BLOCK,
1088
                                                        ABSORPTION_GREEN_LINE };
×
1089
        std::vector<SCALAR_OUTPUT> booleanFields    = { VTK_OUTPUT, CSV_OUTPUT };
×
1090

1091
        if( !( integerFields.end() == std::find( integerFields.begin(), integerFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1092
            tmp = std::to_string( (int)_screenOutputFields[idx_field] );
×
1093
        }
1094
        else if( !( booleanFields.end() == std::find( booleanFields.begin(), booleanFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1095
            tmp = "no";
×
1096
            if( (bool)_screenOutputFields[idx_field] ) tmp = "yes";
×
1097
        }
1098
        else if( !( scientificFields.end() ==
×
1099
                    std::find( scientificFields.begin(), scientificFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1100

1101
            std::stringstream ss;
×
1102
            ss << TextProcessingToolbox::DoubleToScientificNotation( _screenOutputFields[idx_field] );
×
1103
            tmp = ss.str();
×
1104
            tmp.erase( std::remove( tmp.begin(), tmp.end(), '+' ), tmp.end() );    // removing the '+' sign
×
1105
        }
1106

1107
        if( strLen > tmp.size() )    // Padding
×
1108
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1109
        else if( strLen < tmp.size() )    // Cutting
×
1110
            tmp.resize( strLen );
×
1111

1112
        lineToPrint += tmp + " |";
×
1113
    }
1114
    if( _settings->GetScreenOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetScreenOutputFrequency() == 0 ) {
×
1115
        log->info( lineToPrint );
×
1116
    }
1117
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1118
        log->info( lineToPrint );
×
1119
    }
1120
}
1121

1122
void SNSolverHPC::PrepareHistoryOutput() {
×
1123
    unsigned n_probes = 4;
×
1124

1125
    unsigned nFields = (unsigned)_settings->GetNHistoryOutput();
×
1126

1127
    _historyOutputFieldNames.resize( nFields );
×
1128
    _historyOutputFields.resize( nFields );
×
1129

1130
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
1131
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
1132
        // Prepare all Output Fields per group
1133

1134
        // Different procedure, depending on the Group...
1135
        switch( _settings->GetHistoryOutput()[idx_field] ) {
×
1136
            case MASS: _historyOutputFieldNames[idx_field] = "Mass"; break;
×
1137
            case ITER: _historyOutputFieldNames[idx_field] = "Iter"; break;
×
NEW
1138
            case SIM_TIME: _historyOutputFieldNames[idx_field] = "Sim_time"; break;
×
1139
            case WALL_TIME: _historyOutputFieldNames[idx_field] = "Wall_time_[s]"; break;
×
1140
            case RMS_FLUX: _historyOutputFieldNames[idx_field] = "RMS_flux"; break;
×
1141
            case VTK_OUTPUT: _historyOutputFieldNames[idx_field] = "VTK_out"; break;
×
1142
            case CSV_OUTPUT: _historyOutputFieldNames[idx_field] = "CSV_out"; break;
×
1143
            case CUR_OUTFLOW: _historyOutputFieldNames[idx_field] = "Cur_outflow"; break;
×
1144
            case TOTAL_OUTFLOW: _historyOutputFieldNames[idx_field] = "Total_outflow"; break;
×
1145
            case CUR_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Cur_outflow_P1"; break;
×
1146
            case TOTAL_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Total_outflow_P1"; break;
×
1147
            case CUR_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Cur_outflow_P2"; break;
×
1148
            case TOTAL_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Total_outflow_P2"; break;
×
1149
            case MAX_OUTFLOW: _historyOutputFieldNames[idx_field] = "Max_outflow"; break;
×
1150
            case CUR_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Cur_absorption"; break;
×
1151
            case TOTAL_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Total_absorption"; break;
×
1152
            case MAX_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Max_absorption"; break;
×
1153
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_center"; break;
×
1154
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_vertical_wall"; break;
×
1155
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_horizontal_wall"; break;
×
1156
            case PROBE_MOMENT_TIME_TRACE:
×
1157
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
×
1158
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1159
                for( unsigned i = 0; i < n_probes; i++ ) {
×
1160
                    for( unsigned j = 0; j < 3; j++ ) {
×
1161
                        _historyOutputFieldNames[idx_field] = "Probe " + std::to_string( i ) + " u_" + std::to_string( j );
×
1162
                        idx_field++;
×
1163
                    }
1164
                }
1165
                idx_field--;
×
1166
                break;
×
1167
            case VAR_ABSORPTION_GREEN: _historyOutputFieldNames[idx_field] = "Var. absorption green"; break;
×
1168
            case ABSORPTION_GREEN_BLOCK:
×
1169
                for( unsigned i = 0; i < 44; i++ ) {
×
1170
                    _historyOutputFieldNames[idx_field] = "Probe Green Block " + std::to_string( i );
×
1171
                    idx_field++;
×
1172
                }
1173
                idx_field--;
×
1174
                break;
×
1175

1176
            case ABSORPTION_GREEN_LINE:
×
1177
                for( unsigned i = 0; i < _settings->GetNumProbingCellsLineHohlraum(); i++ ) {
×
1178
                    _historyOutputFieldNames[idx_field] = "Probe Green Line " + std::to_string( i );
×
1179
                    idx_field++;
×
1180
                }
1181
                idx_field--;
×
1182
                break;
×
1183
            default: ErrorMessages::Error( "History output field not defined!", CURRENT_FUNCTION ); break;
×
1184
        }
1185
    }
1186
}
1187

1188
void SNSolverHPC::PrintHistoryOutput( unsigned idx_iter ) {
×
1189

1190
    auto log = spdlog::get( "tabular" );
×
1191

1192
    // assemble the line to print
1193
    std::string lineToPrint = "";
×
1194
    std::string tmp;
×
1195
    for( int idx_field = 0; idx_field < _settings->GetNHistoryOutput() - 1; idx_field++ ) {
×
1196
        if( idx_field == 0 ) {
×
1197
            tmp = std::to_string( _historyOutputFields[idx_field] );    // Iteration count
×
1198
        }
1199
        else {
1200
            tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[idx_field] );
×
1201
        }
1202
        lineToPrint += tmp + ",";
×
1203
    }
1204
    tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[_settings->GetNHistoryOutput() - 1] );
×
1205
    lineToPrint += tmp;    // Last element without comma
×
1206
    // std::cout << lineToPrint << std::endl;
1207
    if( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) {
×
1208
        log->info( lineToPrint );
×
1209
    }
1210
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1211
        log->info( lineToPrint );
×
1212
    }
1213
}
1214

1215
void SNSolverHPC::DrawPreSolverOutput() {
×
1216

1217
    // Logger
1218
    auto log    = spdlog::get( "event" );
×
1219
    auto logCSV = spdlog::get( "tabular" );
×
1220

1221
    std::string hLine = "--";
×
1222

1223
    unsigned strLen  = 15;    // max width of one column
×
1224
    char paddingChar = ' ';
×
1225

1226
    // Assemble Header for Screen Output
1227
    std::string lineToPrint = "| ";
×
1228
    std::string tmpLine     = "-----------------";
×
1229
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
×
1230
        std::string tmp = _screenOutputFieldNames[idxFields];
×
1231

1232
        if( strLen > tmp.size() )    // Padding
×
1233
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1234
        else if( strLen < tmp.size() )    // Cutting
×
1235
            tmp.resize( strLen );
×
1236

1237
        lineToPrint += tmp + " |";
×
1238
        hLine += tmpLine;
×
1239
    }
1240
    log->info( "---------------------------- Solver Starts -----------------------------" );
×
1241
    log->info( "| The simulation will run for {} iterations.", _nIter );
×
1242
    log->info( "| The spatial grid contains {} cells.", _nCells );
×
1243
    if( _settings->GetSolverName() != PN_SOLVER && _settings->GetSolverName() != CSD_PN_SOLVER ) {
×
1244
        log->info( "| The velocity grid contains {} points.", _nq );
×
1245
    }
1246
    log->info( hLine );
×
1247
    log->info( lineToPrint );
×
1248
    log->info( hLine );
×
1249

1250
    std::string lineToPrintCSV = "";
×
1251
    for( int idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
×
1252
        std::string tmp = _historyOutputFieldNames[idxFields];
×
1253
        lineToPrintCSV += tmp + ",";
×
1254
    }
1255
    lineToPrintCSV += _historyOutputFieldNames[_settings->GetNHistoryOutput() - 1];
×
1256
    logCSV->info( lineToPrintCSV );
×
1257
}
1258

1259
void SNSolverHPC::DrawPostSolverOutput() {
×
1260

1261
    // Logger
1262
    auto log = spdlog::get( "event" );
×
1263

1264
    std::string hLine = "--";
×
1265

1266
    unsigned strLen  = 10;    // max width of one column
×
1267
    char paddingChar = ' ';
×
1268

1269
    // Assemble Header for Screen Output
1270
    std::string lineToPrint = "| ";
×
1271
    std::string tmpLine     = "------------";
×
1272
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
×
1273
        std::string tmp = _screenOutputFieldNames[idxFields];
×
1274

1275
        if( strLen > tmp.size() )    // Padding
×
1276
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1277
        else if( strLen < tmp.size() )    // Cutting
×
1278
            tmp.resize( strLen );
×
1279

1280
        lineToPrint += tmp + " |";
×
1281
        hLine += tmpLine;
×
1282
    }
1283
    log->info( hLine );
×
1284
#ifndef BUILD_TESTING
1285
    log->info( "| The volume output files have been stored at " + _settings->GetOutputFile() );
1286
    log->info( "| The log files have been stored at " + _settings->GetLogDir() + _settings->GetLogFile() );
1287
#endif
1288
    log->info( "--------------------------- Solver Finished ----------------------------" );
×
1289
}
1290

1291
unsigned long SNSolverHPC::Idx2D( unsigned long idx1, unsigned long idx2, unsigned long len2 ) { return idx1 * len2 + idx2; }
×
1292

1293
unsigned long SNSolverHPC::Idx3D( unsigned long idx1, unsigned long idx2, unsigned long idx3, unsigned long len2, unsigned long len3 ) {
×
1294
    return ( idx1 * len2 + idx2 ) * len3 + idx3;
×
1295
}
1296

1297
void SNSolverHPC::WriteVolumeOutput( unsigned idx_iter ) {
×
1298
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
×
1299
    if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
×
1300
        ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
1301
        for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
×
1302
            switch( _settings->GetVolumeOutput()[idx_group] ) {
×
1303
                case MINIMAL:
×
1304
                    if( _rank == 0 ) {
×
1305
                        _outputFields[idx_group][0] = _scalarFlux;
×
1306
                    }
1307
                    break;
×
1308

1309
                case MOMENTS:
×
1310
#pragma omp parallel for
×
1311
                    for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
1312
                        _outputFields[idx_group][0][idx_cell] = 0.0;
1313
                        _outputFields[idx_group][1][idx_cell] = 0.0;
1314
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
1315
                            _outputFields[idx_group][0][idx_cell] +=
1316
                                _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1317
                            _outputFields[idx_group][1][idx_cell] +=
1318
                                _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1319
                        }
1320
                    }
1321
#ifdef BUILD_MPI
1322
                    MPI_Barrier( MPI_COMM_WORLD );
1323
                    MPI_Allreduce(
1324
                        _outputFields[idx_group][0].data(), _outputFields[idx_group][0].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1325
                    MPI_Allreduce(
1326
                        _outputFields[idx_group][1].data(), _outputFields[idx_group][1].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1327
                    MPI_Barrier( MPI_COMM_WORLD );
1328
#endif
1329
                    break;
×
1330
                default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1331
            }
1332
        }
1333
    }
1334
}
1335

1336
void SNSolverHPC::PrintVolumeOutput( int idx_iter ) {
×
1337
    if( _settings->GetSaveRestartSolutionFrequency() != 0 && idx_iter % (int)_settings->GetSaveRestartSolutionFrequency() == 0 ) {
×
1338
        // std::cout << "Saving restart solution at iteration " << idx_iter << std::endl;
1339
        WriteRestartSolution( _settings->GetOutputFile(),
×
1340
                              _sol,
×
1341
                              _scalarFlux,
×
1342
                              _rank,
1343
                              idx_iter,
1344
                              _totalAbsorptionHohlraumCenter,
1345
                              _totalAbsorptionHohlraumVertical,
1346
                              _totalAbsorptionHohlraumHorizontal,
1347
                              _totalAbsorptionLattice );
1348
    }
1349

1350
    if( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (int)_settings->GetVolumeOutputFrequency() == 0 ) {
×
1351
        WriteVolumeOutput( idx_iter );
×
1352
        if( _rank == 0 ) {
×
1353
            ExportVTK( _settings->GetOutputFile() + "_" + std::to_string( idx_iter ), _outputFields, _outputFieldNames, _mesh );    // slow
×
1354
        }
1355
    }
1356
    if( idx_iter == (int)_nIter - 1 ) {    // Last iteration write without suffix.
×
1357
        WriteVolumeOutput( idx_iter );
×
1358
        if( _rank == 0 ) {
×
1359
            ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh );
×
1360
        }
1361
    }
1362
}
1363

1364
void SNSolverHPC::PrepareVolumeOutput() {
×
1365
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
×
1366

1367
    _outputFieldNames.resize( nGroups );
×
1368
    _outputFields.resize( nGroups );
×
1369

1370
    // Prepare all OutputGroups ==> Specified in option VOLUME_OUTPUT
1371
    for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
×
1372
        // Prepare all Output Fields per group
1373

1374
        // Different procedure, depending on the Group...
1375
        switch( _settings->GetVolumeOutput()[idx_group] ) {
×
1376
            case MINIMAL:
×
1377
                // Currently only one entry ==> rad flux
1378
                _outputFields[idx_group].resize( 1 );
×
1379
                _outputFieldNames[idx_group].resize( 1 );
×
1380

1381
                _outputFields[idx_group][0].resize( _nCells );
×
1382
                _outputFieldNames[idx_group][0] = "scalar flux";
×
1383
                break;
×
1384
            case MOMENTS:
×
1385
                // As many entries as there are moments in the system
1386
                _outputFields[idx_group].resize( _nOutputMoments );
×
1387
                _outputFieldNames[idx_group].resize( _nOutputMoments );
×
1388

1389
                for( unsigned idx_moment = 0; idx_moment < _nOutputMoments; idx_moment++ ) {
×
1390
                    _outputFieldNames[idx_group][idx_moment] = std::string( "u_" + std::to_string( idx_moment ) );
×
1391
                    _outputFields[idx_group][idx_moment].resize( _nCells );
×
1392
                }
1393
                break;
×
1394

1395
            default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1396
        }
1397
    }
1398
}
1399

1400
void SNSolverHPC::SetGhostCells() {
×
1401
    if( _settings->GetProblemName() == PROBLEM_Lattice ) {
×
1402
        // #pragma omp parallel for
1403
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
×
1404
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN || _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
×
1405
                _ghostCells[idx_cell] = std::vector<double>( _localNSys, 0.0 );
×
1406
            }
1407
        }
1408
    }
1409
    else if( _settings->GetProblemName() == PROBLEM_HalfLattice ) {    // HALF LATTICE NOT WORKING
×
1410
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1411
    }
1412
    else if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
1413

1414
        auto nodes = _mesh->GetNodes();
×
1415
        double tol = 1e-12;    // For distance to boundary
×
1416

1417
        // #pragma omp parallel for
1418
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
×
1419

1420
            if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN || _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::DIRICHLET ) {
×
1421
                _ghostCells[idx_cell] = std::vector<double>( _localNSys, 0.0 );
×
1422

1423
                auto localCellNodes = _mesh->GetCells()[idx_cell];
×
1424

1425
                for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) {    // Check if corner node is in this cell
×
1426
                    if( nodes[localCellNodes[idx_node]][0] < -0.65 + tol ) {                          // close to 0 => left boundary
×
1427
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
1428
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] > 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
×
1429
                        }
1430
                        break;
×
1431
                    }
1432
                    else if( nodes[localCellNodes[idx_node]][0] > 0.65 - tol ) {    // right boundary
×
1433
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
1434
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] < 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
×
1435
                        }
1436
                        break;
×
1437
                    }
1438
                    else if( nodes[localCellNodes[idx_node]][1] < -0.65 + tol ) {    // lower boundary
×
1439
                        break;
×
1440
                    }
1441
                    else if( nodes[localCellNodes[idx_node]][1] > 0.65 - tol ) {    // upper boundary
×
1442
                        break;
×
1443
                    }
1444
                    else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
×
1445
                        ErrorMessages::Error( " Problem with ghost cell setup and  boundary of this mesh ", CURRENT_FUNCTION );
×
1446
                    }
1447
                }
1448
            }
1449
        }
1450
    }
1451
    else if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
×
1452
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1453
    }
1454
}
1455

1456
void SNSolverHPC::SetProbingCellsLineGreen() {
×
1457

1458
    // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
1459
    //     double verticalLineWidth   = std::abs( _cornerUpperLeftGreen[1] - _cornerLowerLeftGreen[1] );
1460
    //     double horizontalLineWidth = std::abs( _cornerUpperLeftGreen[0] - _cornerUpperRightGreen[0] );
1461
    //
1462
    //     // double dx = 2 * ( horizontalLineWidth + verticalLineWidth ) / ( (double)_nProbingCellsLineGreen );
1463
    //
1464
    //     unsigned nHorizontalProbingCells =
1465
    //         (unsigned)std::ceil( _nProbingCellsLineGreen * ( horizontalLineWidth / ( horizontalLineWidth + verticalLineWidth ) ) );
1466
    //     unsigned nVerticalProbingCells = _nProbingCellsLineGreen - nHorizontalProbingCells;
1467
    //
1468
    //     _probingCellsLineGreen = std::vector<unsigned>( _nProbingCellsLineGreen );
1469
    //
1470
    //     // Sample points on each side of the rectangle
1471
    //     std::vector<unsigned> side3 = linspace2D( _cornerLowerRightGreen, _cornerUpperRightGreen, nVerticalProbingCells );
1472
    //     std::vector<unsigned> side4 = linspace2D( _cornerUpperRightGreen, _cornerUpperLeftGreen, nHorizontalProbingCells );
1473
    //
1474
    //     //  Combine the points from each side
1475
    //     _probingCellsLineGreen.insert( _probingCellsLineGreen.end(), side3.begin(), side3.end() );
1476
    //     _probingCellsLineGreen.insert( _probingCellsLineGreen.end(), side4.begin(), side4.end() );
1477
    // }
1478
    // else
1479
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
1480

1481
        std::vector<double> p1 = { _cornerUpperLeftGreen[0] + _thicknessGreen / 2.0, _cornerUpperLeftGreen[1] - _thicknessGreen / 2.0 };
×
1482
        std::vector<double> p2 = { _cornerUpperRightGreen[0] - _thicknessGreen / 2.0, _cornerUpperRightGreen[1] - _thicknessGreen / 2.0 };
×
1483
        std::vector<double> p3 = { _cornerLowerRightGreen[0] - _thicknessGreen / 2.0, _cornerLowerRightGreen[1] + _thicknessGreen / 2.0 };
×
1484
        std::vector<double> p4 = { _cornerLowerLeftGreen[0] + _thicknessGreen / 2.0, _cornerLowerLeftGreen[1] + _thicknessGreen / 2.0 };
×
1485

1486
        double verticalLineWidth   = std::abs( p1[1] - p4[1] );
×
1487
        double horizontalLineWidth = std::abs( p1[0] - p2[0] );
×
1488

1489
        double pt_ratio_h = horizontalLineWidth / ( horizontalLineWidth + verticalLineWidth );
×
1490
        double pt_ratio_v = verticalLineWidth / ( horizontalLineWidth + verticalLineWidth );
×
1491

1492
        unsigned nHorizontalProbingCells = (unsigned)std::ceil( _nProbingCellsLineGreen / 2 * pt_ratio_h );
×
1493
        unsigned nVerticalProbingCells   = _nProbingCellsLineGreen / 2 - nHorizontalProbingCells;
×
1494

1495
        _probingCellsLineGreen = std::vector<unsigned>( 2 * ( nVerticalProbingCells + nHorizontalProbingCells ) );
×
1496

1497
        // Sample points on each side of the rectangle
1498
        std::vector<unsigned> side1 = linspace2D( p1, p2, nHorizontalProbingCells );    // upper horizontal
×
1499
        std::vector<unsigned> side2 = linspace2D( p2, p3, nVerticalProbingCells );      // right vertical
×
1500
        std::vector<unsigned> side3 = linspace2D( p3, p4, nHorizontalProbingCells );    // lower horizontal
×
1501
        std::vector<unsigned> side4 = linspace2D( p4, p1, nVerticalProbingCells );      // left vertical
×
1502

1503
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
×
1504
            _probingCellsLineGreen[i] = side1[i];
×
1505
        }
1506
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
×
1507
            _probingCellsLineGreen[i + nHorizontalProbingCells] = side2[i];
×
1508
        }
1509
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
×
1510
            _probingCellsLineGreen[i + nVerticalProbingCells + nHorizontalProbingCells] = side3[i];
×
1511
        }
1512
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
×
1513
            _probingCellsLineGreen[i + nVerticalProbingCells + 2 * nHorizontalProbingCells] = side4[i];
×
1514
        }
1515

1516
        // Block-wise approach
1517
        // Initialize the vector to store the corner points of each block
1518
        std::vector<std::vector<std::vector<double>>> block_corners;
×
1519

1520
        double block_size = 0.05;
×
1521

1522
        // Loop to fill the blocks
1523
        for( int i = 0; i < 8; ++i ) {    // 8 blocks in the x-direction (horizontal) (upper) (left to right)
×
1524

1525
            // Top row
1526
            double x1 = -0.2 + i * block_size;
×
1527
            double y1 = 0.4;
×
1528
            double x2 = x1 + block_size;
×
1529
            double y2 = y1 - block_size;
×
1530

1531
            std::vector<std::vector<double>> corners = {
1532
                { x1, y1 },    // top-left
1533
                { x2, y1 },    // top-right
1534
                { x2, y2 },    // bottom-right
1535
                { x1, y2 }     // bottom-left
1536
            };
1537
            block_corners.push_back( corners );
×
1538
        }
1539

1540
        for( int j = 0; j < 14; ++j ) {    // 14 blocks in the y-direction (vertical)
×
1541
            // right column double x1 = 0.15;
1542
            double x1 = 0.15;
×
1543
            double y1 = 0.35 - j * block_size;
×
1544
            double x2 = x1 + block_size;
×
1545
            double y2 = y1 - block_size;
×
1546

1547
            // Store the four corner points for this block
1548
            std::vector<std::vector<double>> corners = {
1549
                { x1, y1 },    // top-left
1550
                { x2, y1 },    // top-right
1551
                { x2, y2 },    // bottom-right
1552
                { x1, y2 }     // bottom-left
1553
            };
1554

1555
            block_corners.push_back( corners );
×
1556
        }
1557

1558
        for( int i = 0; i < 8; ++i ) {    // 8 blocks in the x-direction (horizontal) (lower) (right to left)
×
1559
            // bottom row
1560
            double x1 = 0.15 - i * block_size;
×
1561
            double y1 = -0.35;
×
1562
            double x2 = x1 + block_size;
×
1563
            double y2 = y1 - block_size;
×
1564

1565
            std::vector<std::vector<double>> corners = {
1566
                { x1, y1 },    // top-left
1567
                { x2, y1 },    // top-right
1568
                { x2, y2 },    // bottom-right
1569
                { x1, y2 }     // bottom-left
1570
            };
1571
            block_corners.push_back( corners );
×
1572
        }
1573

1574
        for( int j = 0; j < 14; ++j ) {    // 14 blocks in the y-direction (vertical) (down to up)
×
1575

1576
            // left column
1577
            double x1 = -0.2;
×
1578
            double y1 = -0.3 + j * block_size;
×
1579
            double x2 = x1 + block_size;
×
1580
            double y2 = y1 - block_size;
×
1581

1582
            // Store the four corner points for this block
1583
            std::vector<std::vector<double>> corners = {
1584
                { x1, y1 },    // top-left
1585
                { x2, y1 },    // top-right
1586
                { x2, y2 },    // bottom-right
1587
                { x1, y2 }     // bottom-left
1588
            };
1589

1590
            block_corners.push_back( corners );
×
1591
        }
1592

1593
        // Compute the probing cells for each block
1594
        for( int i = 0; i < _nProbingCellsBlocksGreen; i++ ) {
×
1595
            _probingCellsBlocksGreen.push_back( _mesh->GetCellsofRectangle( block_corners[i] ) );
×
1596
        }
1597
    }
1598
}
1599

1600
void SNSolverHPC::ComputeQOIsGreenProbingLine() {
×
1601
    double verticalLineWidth   = std::abs( _cornerUpperLeftGreen[1] - _cornerLowerLeftGreen[1] - _thicknessGreen );
×
1602
    double horizontalLineWidth = std::abs( _cornerUpperLeftGreen[0] - _cornerUpperRightGreen[0] - _thicknessGreen );
×
1603

1604
    double dl    = 2 * ( horizontalLineWidth + verticalLineWidth ) / ( (double)_nProbingCellsLineGreen );
×
1605
    double area  = dl * _thicknessGreen;
×
1606
    double l_max = _nProbingCellsLineGreen * dl;
×
1607

1608
#pragma omp parallel for
×
1609
    for( unsigned i = 0; i < _nProbingCellsLineGreen; i++ ) {    // Loop over probing cells
1610
        _absorptionValsLineSegment[i] =
1611
            ( _sigmaT[_probingCellsLineGreen[i]] - _sigmaS[_probingCellsLineGreen[i]] ) * _scalarFlux[_probingCellsLineGreen[i]];
1612
    }
1613

1614
    // Block-wise approach
1615
    // #pragma omp parallel for
1616
    for( unsigned i = 0; i < _nProbingCellsBlocksGreen; i++ ) {
×
1617
        _absorptionValsBlocksGreen[i] = 0.0;
×
1618
        for( unsigned j = 0; j < _probingCellsBlocksGreen[i].size(); j++ ) {
×
1619
            _absorptionValsBlocksGreen[i] += ( _sigmaT[_probingCellsBlocksGreen[i][j]] - _sigmaS[_probingCellsBlocksGreen[i][j]] ) *
×
1620
                                             _scalarFlux[_probingCellsBlocksGreen[i][j]] * _areas[_probingCellsBlocksGreen[i][j]];
×
1621
        }
1622
    }
1623
    // std::cout << _absorptionValsBlocksGreen[1] << std::endl;
1624
    // std::cout << _absorptionValsLineSegment[1] << std::endl;
1625
}
1626

1627
std::vector<unsigned> SNSolverHPC::linspace2D( const std::vector<double>& start, const std::vector<double>& end, unsigned num_points ) {
×
1628
    /**
1629
     * Generate a 2D linspace based on the start and end points with a specified number of points.
1630
     *
1631
     * @param start vector of starting x and y coordinates
1632
     * @param end vector of ending x and y coordinates
1633
     * @param num_points number of points to generate
1634
     *
1635
     * @return vector of unsigned integers representing the result
1636
     */
1637

1638
    std::vector<unsigned> result;
×
1639
    result.resize( num_points );
×
1640
    double stepX = ( end[0] - start[0] ) / ( num_points - 1 );
×
1641
    double stepY = ( end[1] - start[1] ) / ( num_points - 1 );
×
1642
#pragma omp parallel for
×
1643
    for( unsigned i = 0; i < num_points; ++i ) {
1644
        double x = start[0] + i * stepX;
1645
        double y = start[1] + i * stepY;
1646

1647
        result[i] = _mesh->GetCellOfKoordinate( x, y );
1648
    }
1649

1650
    return result;
×
1651
}
1652

1653
void SNSolverHPC::ComputeCellsPerimeterLattice() {
×
1654
    double l_1    = 1.5;    // perimeter 1
×
1655
    double l_2    = 2.5;    // perimeter 2
×
1656
    auto nodes    = _mesh->GetNodes();
×
1657
    auto cells    = _mesh->GetCells();
×
1658
    auto cellMids = _mesh->GetCellMidPoints();
×
1659
    auto normals  = _mesh->GetNormals();
×
1660
    auto neigbors = _mesh->GetNeighbours();
×
1661

1662
    _isPerimeterLatticeCell1.resize( _mesh->GetNumCells(), false );
×
1663
    _isPerimeterLatticeCell2.resize( _mesh->GetNumCells(), false );
×
1664

1665
    for( unsigned idx_cell = 0; idx_cell < _mesh->GetNumCells(); ++idx_cell ) {
×
1666
        if( abs( cellMids[idx_cell][0] ) < l_1 && abs( cellMids[idx_cell][1] ) < l_1 ) {
×
1667
            // Cell is within perimeter
1668
            for( unsigned idx_nbr = 0; idx_nbr < _mesh->GetNumNodesPerCell(); ++idx_nbr ) {
×
1669
                if( neigbors[idx_cell][idx_nbr] == _mesh->GetNumCells() ) {
×
1670
                    continue;    // Skip boundary - ghost cells
×
1671
                }
1672

1673
                if( abs( ( cellMids[neigbors[idx_cell][idx_nbr]][0] ) > l_1 && abs( cellMids[idx_cell][0] ) < l_1 ) ||
×
1674
                    abs( ( cellMids[neigbors[idx_cell][idx_nbr]][1] ) > l_1 && abs( cellMids[idx_cell][1] ) < l_1 ) ) {
×
1675
                    // neighbor is outside perimeter
1676
                    _cellsLatticePerimeter1[idx_cell].push_back( idx_nbr );
×
1677
                    _isPerimeterLatticeCell1[idx_cell] = true;
×
1678
                }
1679
            }
1680
        }
1681
        if( abs( cellMids[idx_cell][0] ) < l_2 && abs( cellMids[idx_cell][1] ) < l_2 && abs( cellMids[idx_cell][0] ) > l_1 &&
×
1682
            abs( cellMids[idx_cell][1] ) > l_1 ) {
×
1683
            // Cell is within perimeter
1684
            for( unsigned idx_nbr = 0; idx_nbr < _mesh->GetNumNodesPerCell(); ++idx_nbr ) {
×
1685
                if( neigbors[idx_cell][idx_nbr] == _mesh->GetNumCells() ) {
×
1686
                    continue;    // Skip boundary - ghost cells
×
1687
                }
1688
                if( abs( ( cellMids[neigbors[idx_cell][idx_nbr]][0] ) > l_2 && abs( cellMids[idx_cell][0] ) < l_2 ) ||
×
1689
                    abs( ( cellMids[neigbors[idx_cell][idx_nbr]][1] ) > l_2 && abs( cellMids[idx_cell][1] ) < l_2 ) ) {
×
1690
                    // neighbor is outside perimeter
1691
                    _cellsLatticePerimeter2[idx_cell].push_back( idx_nbr );
×
1692
                    _isPerimeterLatticeCell2[idx_cell] = true;
×
1693
                }
1694
            }
1695
        }
1696
    }
1697
}
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