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

CSMMLab / KiT-RT / #114

10 Feb 2026 07:30PM UTC coverage: 46.616% (-0.01%) from 46.626%
#114

push

travis-ci

web-flow
Merge 88c19a5f2 into e3695236a

0 of 11 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

4422 of 9486 relevant lines covered (46.62%)

57114.84 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
#include <cassert>
13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

227
    {    // Hohlraum
228

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

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

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

250
        // Green
251
        _thicknessGreen = 0.05;
×
252

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

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

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

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

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

283
void SNSolverHPC::Solve() {
×
284

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

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

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

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

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

330
            WriteScalarOutput( iter );
×
331

332
            // --- Update Scalar Fluxes
333

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

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

353
void SNSolverHPC::FluxOrder2() {
×
354

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

494
void SNSolverHPC::FluxOrder1() {
×
495

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

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

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

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

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

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

NEW
542
#pragma omp parallel for reduction( + : _mass )
×
543
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
544

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

555
#pragma omp simd reduction( + : localScalarFlux )
556
        for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
557
            _sol[Idx2D( idx_cell, idx_sys, _localNSys )] = std::max( _sol[Idx2D( idx_cell, idx_sys, _localNSys )], 0.0 );
558
            localScalarFlux += _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
559
        }
560
        _mass += localScalarFlux * _areas[idx_cell];
561
        temp_scalarFlux[idx_cell] = localScalarFlux;    // set flux
562
    }
563
// MPI Allreduce: _scalarFlux
564
#ifdef IMPORT_MPI
565
    MPI_Barrier( MPI_COMM_WORLD );
566
    MPI_Allreduce( temp_scalarFlux.data(), _scalarFlux.data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
567
    MPI_Barrier( MPI_COMM_WORLD );
568
    if( _rank == 0 ) {
569
        for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
570
            double diff = _scalarFlux[idx_cell] - prev_scalarFlux[idx_cell];
571
            _rmsFlux += diff * diff;
572
        }
573
    }
574
#endif
575
#ifndef IMPORT_MPI
576
    _scalarFlux = temp_scalarFlux;
×
NEW
577
#pragma omp parallel for reduction( + : _rmsFlux )
×
578
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
579
        double diff = _scalarFlux[idx_cell] - prev_scalarFlux[idx_cell];
580
        _rmsFlux += diff * diff;
581
    }
582
#endif
583
}
584

585
void SNSolverHPC::IterPostprocessing() {
×
586
    // ALREDUCE NEEDED
587

588
    _curAbsorptionLattice            = 0.0;
×
589
    _curScalarOutflow                = 0.0;
×
590
    _curScalarOutflowPeri1           = 0.0;
×
591
    _curScalarOutflowPeri2           = 0.0;
×
592
    _curAbsorptionHohlraumCenter     = 0.0;    // Green and blue areas of symmetric hohlraum
×
593
    _curAbsorptionHohlraumVertical   = 0.0;    // Red areas of symmetric hohlraum
×
594
    _curAbsorptionHohlraumHorizontal = 0.0;    // Black areas of symmetric hohlraum
×
595
    _varAbsorptionHohlraumGreen      = 0.0;
×
596
    double a_g                       = 0.0;
×
597

598
#pragma omp parallel for reduction( + : _curAbsorptionLattice,                                                                                       \
×
599
                                        _curScalarOutflow,                                                                                           \
600
                                        _curScalarOutflowPeri1,                                                                                      \
601
                                        _curScalarOutflowPeri2,                                                                                      \
602
                                        _curAbsorptionHohlraumCenter,                                                                                \
603
                                        _curAbsorptionHohlraumVertical,                                                                              \
604
                                        _curAbsorptionHohlraumHorizontal,                                                                            \
605
                                        a_g ) reduction( max : _curMaxOrdinateOutflow, _curMaxAbsorptionLattice )
×
606
    for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
607

608
        if( _settings->GetProblemName() == PROBLEM_Lattice || _settings->GetProblemName() == PROBLEM_HalfLattice ) {
609
            if( IsAbsorptionLattice( _cellMidPoints[Idx2D( idx_cell, 0, _nDim )], _cellMidPoints[Idx2D( idx_cell, 1, _nDim )] ) ) {
610
                double sigmaAPsi = _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
611
                _curAbsorptionLattice += sigmaAPsi;
612
                _curMaxAbsorptionLattice = ( _curMaxAbsorptionLattice < sigmaAPsi ) ? sigmaAPsi : _curMaxAbsorptionLattice;
613
            }
614
        }
615

616
        if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {    //} || _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
617

618
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
619
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
620
            _curAbsorptionLattice += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
621
            if( x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
622
                y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum() ) {
623
                _curAbsorptionHohlraumCenter += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
624
            }
625
            if( ( x < _settings->GetPosRedLeftBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
626
                  y < _settings->GetPosRedLeftTopHohlraum() ) ||
627
                ( x > _settings->GetPosRedRightBorderHohlraum() && y > _settings->GetPosRedLeftBottomHohlraum() &&
628
                  y < _settings->GetPosRedRightTopHohlraum() ) ) {
629
                _curAbsorptionHohlraumVertical += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
630
            }
631
            if( y > 0.6 || y < -0.6 ) {
632
                _curAbsorptionHohlraumHorizontal += _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _areas[idx_cell];
633
            }
634

635
            // Variation in absorption of center (part 1)
636
            // green area 1 (lower boundary)
637
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
638
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
639
            // green area 2 (upper boundary)
640
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
641
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
642
            // green area 3 (left boundary)
643
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
644
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
645
            // green area 4 (right boundary)
646
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
647
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
648
            if( green1 || green2 || green3 || green4 ) {
649
                a_g += ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) * _scalarFlux[idx_cell] * _areas[idx_cell] /
650
                       ( 44 * 0.05 * 0.05 );    // divisor is area of the green
651
            }
652
        }
653

654
        if( _settings->GetProblemName() == PROBLEM_Lattice ) {
655
            // Outflow out of inner and middle perimeter
656
            if( _isPerimeterLatticeCell1[idx_cell] ) {    // inner
657
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter1[idx_cell].size(); ++idx_nbr_helper ) {
658
#pragma omp simd reduction( + : _curScalarOutflowPeri1 )
659
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
660
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
661
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
662
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
663
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter1[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
664
                        // Find outward facing transport directions
665

666
                        if( localInner > 0.0 ) {
667
                            _curScalarOutflowPeri1 +=
668
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
669
                        }
670
                    }
671
                }
672
            }
673
            if( _isPerimeterLatticeCell2[idx_cell] ) {    // middle
674
                for( unsigned long idx_nbr_helper = 0; idx_nbr_helper < _cellsLatticePerimeter2[idx_cell].size(); ++idx_nbr_helper ) {
675
#pragma omp simd reduction( + : _curScalarOutflowPeri2 )
676
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
677
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] *
678
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 0, _nNbr, _nDim )] +
679
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] *
680
                                                _normals[Idx3D( idx_cell, _cellsLatticePerimeter2[idx_cell][idx_nbr_helper], 1, _nNbr, _nDim )];
681
                        // Find outward facing transport directions
682

683
                        if( localInner > 0.0 ) {
684
                            _curScalarOutflowPeri2 +=
685
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
686
                        }
687
                    }
688
                }
689
            }
690
        }
691
        // Outflow out of domain
692
        if( _cellBoundaryTypes[idx_cell] == BOUNDARY_TYPE::NEUMANN ) {
693
            // Iterate over face cell faces
694
            double currOrdinatewiseOutflow = 0.0;
695

696
            for( unsigned long idx_nbr = 0; idx_nbr < _nNbr; ++idx_nbr ) {
697
                // Find face that points outward
698
                if( _neighbors[Idx2D( idx_cell, idx_nbr, _nNbr )] == _nCells ) {
699
#pragma omp simd reduction( + : _curScalarOutflow ) reduction( max : _curMaxOrdinateOutflow )
700
                    for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
701

702
                        double localInner = _quadPts[Idx2D( idx_sys, 0, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
703
                                            _quadPts[Idx2D( idx_sys, 1, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )];
704
                        // Find outward facing transport directions
705

706
                        if( localInner > 0.0 ) {
707
                            _curScalarOutflow +=
708
                                localInner * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];    // Integrate flux
709

710
                            currOrdinatewiseOutflow =
711
                                _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * localInner /
712
                                sqrt( (
713
                                    _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 0, _nNbr, _nDim )] +
714
                                    _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] * _normals[Idx3D( idx_cell, idx_nbr, 1, _nNbr, _nDim )] ) );
715

716
                            _curMaxOrdinateOutflow =
717
                                ( currOrdinatewiseOutflow > _curMaxOrdinateOutflow ) ? currOrdinatewiseOutflow : _curMaxOrdinateOutflow;
718
                        }
719
                    }
720
                }
721
            }
722
        }
723
    }
724
// MPI Allreduce
725
#ifdef IMPORT_MPI
726
    double tmp_curScalarOutflow      = 0.0;
727
    double tmp_curScalarOutflowPeri1 = 0.0;
728
    double tmp_curScalarOutflowPeri2 = 0.0;
729
    double tmp_curMaxOrdinateOutflow = 0.0;
730
    double tmp_mass                  = 0.0;
731
    double tmp_rmsFlux               = 0.0;
732
    MPI_Barrier( MPI_COMM_WORLD );
733
    MPI_Allreduce( &_curScalarOutflow, &tmp_curScalarOutflow, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
734
    _curScalarOutflow = tmp_curScalarOutflow;
735
    MPI_Barrier( MPI_COMM_WORLD );
736
    MPI_Allreduce( &_curScalarOutflowPeri1, &tmp_curScalarOutflowPeri1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
737
    _curScalarOutflowPeri1 = tmp_curScalarOutflowPeri1;
738
    MPI_Barrier( MPI_COMM_WORLD );
739
    MPI_Allreduce( &_curScalarOutflowPeri2, &tmp_curScalarOutflowPeri2, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
740
    _curScalarOutflowPeri2 = tmp_curScalarOutflowPeri2;
741
    MPI_Barrier( MPI_COMM_WORLD );
742
    MPI_Allreduce( &_curMaxOrdinateOutflow, &tmp_curMaxOrdinateOutflow, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
743
    _curMaxOrdinateOutflow = tmp_curMaxOrdinateOutflow;
744
    MPI_Barrier( MPI_COMM_WORLD );
745
    MPI_Allreduce( &_mass, &tmp_mass, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
746
    _mass = tmp_mass;
747
    MPI_Barrier( MPI_COMM_WORLD );
748
    MPI_Allreduce( &_rmsFlux, &tmp_rmsFlux, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
749
    _rmsFlux = tmp_rmsFlux;
750
    MPI_Barrier( MPI_COMM_WORLD );
751
#endif
752
    // Variation absorption (part II)
753
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
754
        unsigned n_probes = 4;
×
755
        std::vector<double> temp_probingMoments( 3 * n_probes );    // for MPI allreduce
×
756

757
#pragma omp parallel for reduction( + : _varAbsorptionHohlraumGreen )
×
758
        for( unsigned long idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
759
            double x = _cellMidPoints[Idx2D( idx_cell, 0, _nDim )];
760
            double y = _cellMidPoints[Idx2D( idx_cell, 1, _nDim )];
761

762
            // green area 1 (lower boundary)
763
            bool green1 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
764
                          y > -0.4 + _settings->GetPosYCenterGreenHohlraum() && y < -0.35 + _settings->GetPosYCenterGreenHohlraum();
765
            // green area 2 (upper boundary)
766
            bool green2 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
767
                          y > 0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.4 + _settings->GetPosYCenterGreenHohlraum();
768
            // green area 3 (left boundary)
769
            bool green3 = x > -0.2 + _settings->GetPosXCenterGreenHohlraum() && x < -0.15 + _settings->GetPosXCenterGreenHohlraum() &&
770
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
771
            // green area 4 (right boundary)
772
            bool green4 = x > 0.15 + _settings->GetPosXCenterGreenHohlraum() && x < 0.2 + _settings->GetPosXCenterGreenHohlraum() &&
773
                          y > -0.35 + _settings->GetPosYCenterGreenHohlraum() && y < 0.35 + _settings->GetPosYCenterGreenHohlraum();
774
            if( green1 || green2 || green3 || green4 ) {
775
                _varAbsorptionHohlraumGreen += ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) *
776
                                               ( a_g - _scalarFlux[idx_cell] * ( _sigmaT[idx_cell] - _sigmaS[idx_cell] ) ) * _areas[idx_cell];
777
            }
778
        }
779
        // Probes value moments
780
        // #pragma omp parallel for
781
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
×
782
            temp_probingMoments[Idx2D( idx_probe, 0, 3 )] = 0.0;
×
783
            temp_probingMoments[Idx2D( idx_probe, 1, 3 )] = 0.0;
×
784
            temp_probingMoments[Idx2D( idx_probe, 2, 3 )] = 0.0;
×
785
            // for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
786
            //   std::cout << idx_ball << _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI ) << std::endl;
787
            //}
788
            for( unsigned long idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
789
                for( unsigned long idx_ball = 0; idx_ball < _probingCellsHohlraum[idx_probe].size(); idx_ball++ ) {
×
790
                    temp_probingMoments[Idx2D( idx_probe, 0, 3 )] += _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
791
                                                                     _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] /
×
792
                                                                     ( 0.01 * 0.01 * M_PI );
793
                    temp_probingMoments[Idx2D( idx_probe, 1, 3 )] +=
×
794
                        _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
795
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
×
796
                    temp_probingMoments[Idx2D( idx_probe, 2, 3 )] +=
×
797
                        _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( _probingCellsHohlraum[idx_probe][idx_ball], idx_sys, _localNSys )] *
×
798
                        _quadWeights[idx_sys] * _areas[_probingCellsHohlraum[idx_probe][idx_ball]] / ( 0.01 * 0.01 * M_PI );
×
799
                }
800
            }
801
        }
802

803
#ifdef IMPORT_MPI
804
        MPI_Barrier( MPI_COMM_WORLD );
805
        MPI_Allreduce( temp_probingMoments.data(), _probingMoments.data(), 3 * n_probes, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
806
        MPI_Barrier( MPI_COMM_WORLD );
807
#endif
808
#ifndef IMPORT_MPI
809
        for( unsigned long idx_probe = 0; idx_probe < n_probes; idx_probe++ ) {    // Loop over probing cells
×
810
            _probingMoments[Idx2D( idx_probe, 0, 3 )] = temp_probingMoments[Idx2D( idx_probe, 0, 3 )];
×
811
            _probingMoments[Idx2D( idx_probe, 1, 3 )] = temp_probingMoments[Idx2D( idx_probe, 1, 3 )];
×
812
            _probingMoments[Idx2D( idx_probe, 2, 3 )] = temp_probingMoments[Idx2D( idx_probe, 2, 3 )];
×
813
        }
814
#endif
815
    }
816
    // probe values green
817
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
818
        ComputeQOIsGreenProbingLine();
×
819
    }
820
    // Update time integral values on rank 0
821
    if( _rank == 0 ) {
×
822
        _totalScalarOutflow += _curScalarOutflow * _dT;
×
823
        _totalScalarOutflowPeri1 += _curScalarOutflowPeri1 * _dT;
×
824
        _totalScalarOutflowPeri2 += _curScalarOutflowPeri2 * _dT;
×
825
        _totalAbsorptionLattice += _curAbsorptionLattice * _dT;
×
826

827
        _totalAbsorptionHohlraumCenter += _curAbsorptionHohlraumCenter * _dT;
×
828
        _totalAbsorptionHohlraumVertical += _curAbsorptionHohlraumVertical * _dT;
×
829
        _totalAbsorptionHohlraumHorizontal += _curAbsorptionHohlraumHorizontal * _dT;
×
830

831
        _rmsFlux = sqrt( _rmsFlux );
×
832
    }
833
}
834

835
bool SNSolverHPC::IsAbsorptionLattice( double x, double y ) const {
×
836
    // Check whether pos is inside absorbing squares
837
    double xy_corrector = -3.5;
×
838
    std::vector<double> lbounds{ 1 + xy_corrector, 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector };
×
839
    std::vector<double> ubounds{ 2 + xy_corrector, 3 + xy_corrector, 4 + xy_corrector, 5 + xy_corrector, 6 + xy_corrector };
×
840
    for( unsigned k = 0; k < lbounds.size(); ++k ) {
×
841
        for( unsigned l = 0; l < lbounds.size(); ++l ) {
×
842
            if( ( l + k ) % 2 == 1 || ( k == 2 && l == 2 ) || ( k == 2 && l == 4 ) ) continue;
×
843
            if( x >= lbounds[k] && x <= ubounds[k] && y >= lbounds[l] && y <= ubounds[l] ) {
×
844
                return true;
×
845
            }
846
        }
847
    }
848
    return false;
×
849
}
850

851
// --- Helper ---
852
double SNSolverHPC::ComputeTimeStep( double cfl ) const {
×
853
    // for pseudo 1D, set timestep to dx
854
    double dx, dy;
855
    switch( _settings->GetProblemName() ) {
×
856
        case PROBLEM_Checkerboard1D:
×
857
            dx = 7.0 / (double)_nCells;
×
858
            dy = 0.3;
×
859
            return cfl * ( dx * dy ) / ( dx + dy );
×
860
            break;
861
        case PROBLEM_Linesource1D:     // Fallthrough
×
862
        case PROBLEM_Meltingcube1D:    // Fallthrough
863
        case PROBLEM_Aircavity1D:
864
            dx = 3.0 / (double)_nCells;
×
865
            dy = 0.3;
×
866
            return cfl * ( dx * dy ) / ( dx + dy );
×
867
            break;
868
        default: break;    // 2d as normal
×
869
    }
870
    // 2D case
871
    double charSize = __DBL_MAX__;    // minimum char size of all mesh cells in the mesh
×
872

873
#pragma omp parallel for reduction( min : charSize )
×
874
    for( unsigned long j = 0; j < _nCells; j++ ) {
875
        double currCharSize = sqrt( _areas[j] );
876
        if( currCharSize < charSize ) {
877
            charSize = currCharSize;
878
        }
879
    }
880
    if( _rank == 0 ) {
×
881
        auto log         = spdlog::get( "event" );
×
882
        std::string line = "| Smallest characteristic length of a grid cell in this mesh: " + std::to_string( charSize );
×
883
        log->info( line );
×
884
        line = "| Corresponding maximal time-step: " + std::to_string( cfl * charSize );
×
885
        log->info( line );
×
886
    }
887
    return cfl * charSize;
×
888
}
889

890
// --- IO ----
891
void SNSolverHPC::PrepareScreenOutput() {
×
892
    unsigned nFields = (unsigned)_settings->GetNScreenOutput();
×
893

894
    _screenOutputFieldNames.resize( nFields );
×
895
    _screenOutputFields.resize( nFields );
×
896

897
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
898
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
899
        // Prepare all Output Fields per group
900

901
        // Different procedure, depending on the Group...
902
        switch( _settings->GetScreenOutput()[idx_field] ) {
×
903
            case MASS: _screenOutputFieldNames[idx_field] = "Mass"; break;
×
904
            case ITER: _screenOutputFieldNames[idx_field] = "Iter"; break;
×
905
            case SIM_TIME: _screenOutputFieldNames[idx_field] = "Sim time"; break;
×
906
            case WALL_TIME: _screenOutputFieldNames[idx_field] = "Wall time [s]"; break;
×
907
            case RMS_FLUX: _screenOutputFieldNames[idx_field] = "RMS flux"; break;
×
908
            case VTK_OUTPUT: _screenOutputFieldNames[idx_field] = "VTK out"; break;
×
909
            case CSV_OUTPUT: _screenOutputFieldNames[idx_field] = "CSV out"; break;
×
910
            case CUR_OUTFLOW: _screenOutputFieldNames[idx_field] = "Cur. outflow"; break;
×
911
            case TOTAL_OUTFLOW: _screenOutputFieldNames[idx_field] = "Tot. outflow"; break;
×
912
            case CUR_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Cur. outflow P1"; break;
×
913
            case TOTAL_OUTFLOW_P1: _screenOutputFieldNames[idx_field] = "Tot. outflow P1"; break;
×
914
            case CUR_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Cur. outflow P2"; break;
×
915
            case TOTAL_OUTFLOW_P2: _screenOutputFieldNames[idx_field] = "Tot. outflow P2"; break;
×
916
            case MAX_OUTFLOW: _screenOutputFieldNames[idx_field] = "Max outflow"; break;
×
917
            case CUR_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Cur. absorption"; break;
×
918
            case TOTAL_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Tot. absorption"; break;
×
919
            case MAX_PARTICLE_ABSORPTION: _screenOutputFieldNames[idx_field] = "Max absorption"; break;
×
920
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _screenOutputFieldNames[idx_field] = "Tot. abs. center"; break;
×
921
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _screenOutputFieldNames[idx_field] = "Tot. abs. vertical wall"; break;
×
922
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _screenOutputFieldNames[idx_field] = "Tot. abs. horizontal wall"; break;
×
923
            case PROBE_MOMENT_TIME_TRACE:
×
924
                _screenOutputFieldNames[idx_field] = "Probe 1 u_0";
×
925
                idx_field++;
×
926
                _screenOutputFieldNames[idx_field] = "Probe 2 u_0";
×
927
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
928
                    idx_field++;
×
929
                    _screenOutputFieldNames[idx_field] = "Probe 3 u_0";
×
930
                    idx_field++;
×
931
                    _screenOutputFieldNames[idx_field] = "Probe 4 u_0";
×
932
                }
933
                break;
×
934
            case VAR_ABSORPTION_GREEN: _screenOutputFieldNames[idx_field] = "Var. absorption green"; break;
×
935

936
            default: ErrorMessages::Error( "Screen output field not defined!", CURRENT_FUNCTION ); break;
×
937
        }
938
    }
939
}
940

941
void SNSolverHPC::WriteScalarOutput( unsigned idx_iter ) {
×
942
    unsigned n_probes = 4;
×
943

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

997
    // --- History output ---
998
    nFields = (unsigned)_settings->GetNHistoryOutput();
×
999

1000
    std::vector<SCALAR_OUTPUT> screenOutputFields = _settings->GetScreenOutput();
×
1001
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
1002

1003
        // Prepare all Output Fields per group
1004
        // Different procedure, depending on the Group...
1005
        switch( _settings->GetHistoryOutput()[idx_field] ) {
×
1006
            case MASS: _historyOutputFields[idx_field] = _mass; break;
×
1007
            case ITER: _historyOutputFields[idx_field] = idx_iter; break;
×
1008
            case SIM_TIME: _historyOutputFields[idx_field] = _curSimTime; break;
×
1009
            case WALL_TIME: _historyOutputFields[idx_field] = _currTime; break;
×
1010
            case RMS_FLUX: _historyOutputFields[idx_field] = _rmsFlux; break;
×
1011
            case VTK_OUTPUT:
×
1012
                _historyOutputFields[idx_field] = 0;
×
1013
                if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
×
1014
                    ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
1015
                    _historyOutputFields[idx_field] = 1;
×
1016
                }
1017
                break;
×
1018

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

1071
void SNSolverHPC::PrintScreenOutput( unsigned idx_iter ) {
×
1072
    auto log = spdlog::get( "event" );
×
1073

1074
    unsigned strLen  = 15;    // max width of one column
×
1075
    char paddingChar = ' ';
×
1076

1077
    // assemble the line to print
1078
    std::string lineToPrint = "| ";
×
1079
    std::string tmp;
×
1080
    for( unsigned idx_field = 0; idx_field < _settings->GetNScreenOutput(); idx_field++ ) {
×
1081
        tmp = std::to_string( _screenOutputFields[idx_field] );
×
1082

1083
        // Format outputs correctly
1084
        std::vector<SCALAR_OUTPUT> integerFields    = { ITER };
×
1085
        std::vector<SCALAR_OUTPUT> scientificFields = { RMS_FLUX,
1086
                                                        MASS,
1087
                                                        WALL_TIME,
1088
                                                        CUR_OUTFLOW,
1089
                                                        TOTAL_OUTFLOW,
1090
                                                        CUR_OUTFLOW_P1,
1091
                                                        TOTAL_OUTFLOW_P1,
1092
                                                        CUR_OUTFLOW_P2,
1093
                                                        TOTAL_OUTFLOW_P2,
1094
                                                        MAX_OUTFLOW,
1095
                                                        CUR_PARTICLE_ABSORPTION,
1096
                                                        TOTAL_PARTICLE_ABSORPTION,
1097
                                                        MAX_PARTICLE_ABSORPTION,
1098
                                                        TOTAL_PARTICLE_ABSORPTION_CENTER,
1099
                                                        TOTAL_PARTICLE_ABSORPTION_VERTICAL,
1100
                                                        TOTAL_PARTICLE_ABSORPTION_HORIZONTAL,
1101
                                                        PROBE_MOMENT_TIME_TRACE,
1102
                                                        VAR_ABSORPTION_GREEN,
1103
                                                        ABSORPTION_GREEN_BLOCK,
1104
                                                        ABSORPTION_GREEN_LINE };
×
1105
        std::vector<SCALAR_OUTPUT> booleanFields    = { VTK_OUTPUT, CSV_OUTPUT };
×
1106

1107
        if( !( integerFields.end() == std::find( integerFields.begin(), integerFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1108
            tmp = std::to_string( (int)_screenOutputFields[idx_field] );
×
1109
        }
1110
        else if( !( booleanFields.end() == std::find( booleanFields.begin(), booleanFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1111
            tmp = "no";
×
1112
            if( (bool)_screenOutputFields[idx_field] ) tmp = "yes";
×
1113
        }
1114
        else if( !( scientificFields.end() ==
×
1115
                    std::find( scientificFields.begin(), scientificFields.end(), _settings->GetScreenOutput()[idx_field] ) ) ) {
×
1116

1117
            std::stringstream ss;
×
1118
            ss << TextProcessingToolbox::DoubleToScientificNotation( _screenOutputFields[idx_field] );
×
1119
            tmp = ss.str();
×
1120
            tmp.erase( std::remove( tmp.begin(), tmp.end(), '+' ), tmp.end() );    // removing the '+' sign
×
1121
        }
1122

1123
        if( strLen > tmp.size() )    // Padding
×
1124
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1125
        else if( strLen < tmp.size() )    // Cutting
×
1126
            tmp.resize( strLen );
×
1127

1128
        lineToPrint += tmp + " |";
×
1129
    }
1130
    if( _settings->GetScreenOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetScreenOutputFrequency() == 0 ) {
×
1131
        log->info( lineToPrint );
×
1132
    }
1133
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1134
        log->info( lineToPrint );
×
1135
    }
1136
}
1137

1138
void SNSolverHPC::PrepareHistoryOutput() {
×
1139
    unsigned n_probes = 4;
×
1140

1141
    unsigned nFields = (unsigned)_settings->GetNHistoryOutput();
×
1142

1143
    _historyOutputFieldNames.resize( nFields );
×
1144
    _historyOutputFields.resize( nFields );
×
1145

1146
    // Prepare all output Fields ==> Specified in option SCREEN_OUTPUT
1147
    for( unsigned idx_field = 0; idx_field < nFields; idx_field++ ) {
×
1148
        // Prepare all Output Fields per group
1149

1150
        // Different procedure, depending on the Group...
1151
        switch( _settings->GetHistoryOutput()[idx_field] ) {
×
1152
            case MASS: _historyOutputFieldNames[idx_field] = "Mass"; break;
×
1153
            case ITER: _historyOutputFieldNames[idx_field] = "Iter"; break;
×
1154
            case SIM_TIME: _historyOutputFieldNames[idx_field] = "Sim_time"; break;
×
1155
            case WALL_TIME: _historyOutputFieldNames[idx_field] = "Wall_time_[s]"; break;
×
1156
            case RMS_FLUX: _historyOutputFieldNames[idx_field] = "RMS_flux"; break;
×
1157
            case VTK_OUTPUT: _historyOutputFieldNames[idx_field] = "VTK_out"; break;
×
1158
            case CSV_OUTPUT: _historyOutputFieldNames[idx_field] = "CSV_out"; break;
×
1159
            case CUR_OUTFLOW: _historyOutputFieldNames[idx_field] = "Cur_outflow"; break;
×
1160
            case TOTAL_OUTFLOW: _historyOutputFieldNames[idx_field] = "Total_outflow"; break;
×
1161
            case CUR_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Cur_outflow_P1"; break;
×
1162
            case TOTAL_OUTFLOW_P1: _historyOutputFieldNames[idx_field] = "Total_outflow_P1"; break;
×
1163
            case CUR_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Cur_outflow_P2"; break;
×
1164
            case TOTAL_OUTFLOW_P2: _historyOutputFieldNames[idx_field] = "Total_outflow_P2"; break;
×
1165
            case MAX_OUTFLOW: _historyOutputFieldNames[idx_field] = "Max_outflow"; break;
×
1166
            case CUR_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Cur_absorption"; break;
×
1167
            case TOTAL_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Total_absorption"; break;
×
1168
            case MAX_PARTICLE_ABSORPTION: _historyOutputFieldNames[idx_field] = "Max_absorption"; break;
×
1169
            case TOTAL_PARTICLE_ABSORPTION_CENTER: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_center"; break;
×
1170
            case TOTAL_PARTICLE_ABSORPTION_VERTICAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_vertical_wall"; break;
×
1171
            case TOTAL_PARTICLE_ABSORPTION_HORIZONTAL: _historyOutputFieldNames[idx_field] = "Cumulated_absorption_horizontal_wall"; break;
×
1172
            case PROBE_MOMENT_TIME_TRACE:
×
1173
                if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) n_probes = 4;
×
1174
                // if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) n_probes = 2;
1175
                for( unsigned i = 0; i < n_probes; i++ ) {
×
1176
                    for( unsigned j = 0; j < 3; j++ ) {
×
1177
                        _historyOutputFieldNames[idx_field] = "Probe " + std::to_string( i ) + " u_" + std::to_string( j );
×
1178
                        idx_field++;
×
1179
                    }
1180
                }
1181
                idx_field--;
×
1182
                break;
×
1183
            case VAR_ABSORPTION_GREEN: _historyOutputFieldNames[idx_field] = "Var. absorption green"; break;
×
1184
            case ABSORPTION_GREEN_BLOCK:
×
1185
                for( unsigned i = 0; i < 44; i++ ) {
×
1186
                    _historyOutputFieldNames[idx_field] = "Probe Green Block " + std::to_string( i );
×
1187
                    idx_field++;
×
1188
                }
1189
                idx_field--;
×
1190
                break;
×
1191

1192
            case ABSORPTION_GREEN_LINE:
×
1193
                for( unsigned i = 0; i < _settings->GetNumProbingCellsLineHohlraum(); i++ ) {
×
1194
                    _historyOutputFieldNames[idx_field] = "Probe Green Line " + std::to_string( i );
×
1195
                    idx_field++;
×
1196
                }
1197
                idx_field--;
×
1198
                break;
×
1199
            default: ErrorMessages::Error( "History output field not defined!", CURRENT_FUNCTION ); break;
×
1200
        }
1201
    }
1202
}
1203

1204
void SNSolverHPC::PrintHistoryOutput( unsigned idx_iter ) {
×
1205

1206
    auto log = spdlog::get( "tabular" );
×
1207

1208
    // assemble the line to print
1209
    std::string lineToPrint = "";
×
1210
    std::string tmp;
×
1211
    for( int idx_field = 0; idx_field < _settings->GetNHistoryOutput() - 1; idx_field++ ) {
×
1212
        if( idx_field == 0 ) {
×
1213
            tmp = std::to_string( _historyOutputFields[idx_field] );    // Iteration count
×
1214
        }
1215
        else {
1216
            tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[idx_field] );
×
1217
        }
1218
        lineToPrint += tmp + ",";
×
1219
    }
1220
    tmp = TextProcessingToolbox::DoubleToScientificNotation( _historyOutputFields[_settings->GetNHistoryOutput() - 1] );
×
1221
    lineToPrint += tmp;    // Last element without comma
×
1222
    // std::cout << lineToPrint << std::endl;
1223
    if( _settings->GetHistoryOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetHistoryOutputFrequency() == 0 ) {
×
1224
        log->info( lineToPrint );
×
1225
    }
1226
    else if( idx_iter == _nIter - 1 ) {    // Always print last iteration
×
1227
        log->info( lineToPrint );
×
1228
    }
1229
}
1230

1231
void SNSolverHPC::DrawPreSolverOutput() {
×
1232

1233
    // Logger
1234
    auto log    = spdlog::get( "event" );
×
1235
    auto logCSV = spdlog::get( "tabular" );
×
1236

1237
    std::string hLine = "--";
×
1238

1239
    unsigned strLen  = 15;    // max width of one column
×
1240
    char paddingChar = ' ';
×
1241

1242
    // Assemble Header for Screen Output
1243
    std::string lineToPrint = "| ";
×
1244
    std::string tmpLine     = "-----------------";
×
1245
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
×
1246
        std::string tmp = _screenOutputFieldNames[idxFields];
×
1247

1248
        if( strLen > tmp.size() )    // Padding
×
1249
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1250
        else if( strLen < tmp.size() )    // Cutting
×
1251
            tmp.resize( strLen );
×
1252

1253
        lineToPrint += tmp + " |";
×
1254
        hLine += tmpLine;
×
1255
    }
1256
    log->info( "---------------------------- Solver Starts -----------------------------" );
×
1257
    log->info( "| The simulation will run for {} iterations.", _nIter );
×
1258
    log->info( "| The spatial grid contains {} cells.", _nCells );
×
1259
    if( _settings->GetSolverName() != PN_SOLVER && _settings->GetSolverName() != CSD_PN_SOLVER ) {
×
1260
        log->info( "| The velocity grid contains {} points.", _nq );
×
1261
    }
1262
    log->info( hLine );
×
1263
    log->info( lineToPrint );
×
1264
    log->info( hLine );
×
1265

1266
    std::string lineToPrintCSV = "";
×
1267
    for( int idxFields = 0; idxFields < _settings->GetNHistoryOutput() - 1; idxFields++ ) {
×
1268
        std::string tmp = _historyOutputFieldNames[idxFields];
×
1269
        lineToPrintCSV += tmp + ",";
×
1270
    }
1271
    lineToPrintCSV += _historyOutputFieldNames[_settings->GetNHistoryOutput() - 1];
×
1272
    logCSV->info( lineToPrintCSV );
×
1273
}
1274

1275
void SNSolverHPC::DrawPostSolverOutput() {
×
1276

1277
    // Logger
1278
    auto log = spdlog::get( "event" );
×
1279

1280
    std::string hLine = "--";
×
1281

1282
    unsigned strLen  = 10;    // max width of one column
×
1283
    char paddingChar = ' ';
×
1284

1285
    // Assemble Header for Screen Output
1286
    std::string lineToPrint = "| ";
×
1287
    std::string tmpLine     = "------------";
×
1288
    for( unsigned idxFields = 0; idxFields < _settings->GetNScreenOutput(); idxFields++ ) {
×
1289
        std::string tmp = _screenOutputFieldNames[idxFields];
×
1290

1291
        if( strLen > tmp.size() )    // Padding
×
1292
            tmp.insert( 0, strLen - tmp.size(), paddingChar );
×
1293
        else if( strLen < tmp.size() )    // Cutting
×
1294
            tmp.resize( strLen );
×
1295

1296
        lineToPrint += tmp + " |";
×
1297
        hLine += tmpLine;
×
1298
    }
1299
    log->info( hLine );
×
1300
#ifndef BUILD_TESTING
1301
    log->info( "| The volume output files have been stored at " + _settings->GetOutputFile() );
1302
    log->info( "| The log files have been stored at " + _settings->GetLogDir() + _settings->GetLogFile() );
1303
#endif
1304
    log->info( "--------------------------- Solver Finished ----------------------------" );
×
1305
}
1306

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

1309
unsigned long SNSolverHPC::Idx3D( unsigned long idx1, unsigned long idx2, unsigned long idx3, unsigned long len2, unsigned long len3 ) {
×
1310
    return ( idx1 * len2 + idx2 ) * len3 + idx3;
×
1311
}
1312

1313
void SNSolverHPC::WriteVolumeOutput( unsigned idx_iter ) {
×
1314
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
×
1315
    if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
×
1316
        ( idx_iter == _nIter - 1 ) /* need sol at last iteration */ ) {
×
1317
        for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
×
1318
            switch( _settings->GetVolumeOutput()[idx_group] ) {
×
1319
                case MINIMAL:
×
1320
                    if( _rank == 0 ) {
×
1321
                        _outputFields[idx_group][0] = _scalarFlux;
×
1322
                    }
1323
                    break;
×
1324

1325
                case MOMENTS:
×
1326
#pragma omp parallel for
×
1327
                    for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
1328
                        _outputFields[idx_group][0][idx_cell] = 0.0;
1329
                        _outputFields[idx_group][1][idx_cell] = 0.0;
1330
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
1331
                            _outputFields[idx_group][0][idx_cell] +=
1332
                                _quadPts[Idx2D( idx_sys, 0, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1333
                            _outputFields[idx_group][1][idx_cell] +=
1334
                                _quadPts[Idx2D( idx_sys, 1, _nDim )] * _sol[Idx2D( idx_cell, idx_sys, _localNSys )] * _quadWeights[idx_sys];
1335
                        }
1336
                    }
1337
#ifdef BUILD_MPI
1338
                    MPI_Barrier( MPI_COMM_WORLD );
1339
                    MPI_Allreduce(
1340
                        _outputFields[idx_group][0].data(), _outputFields[idx_group][0].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1341
                    MPI_Allreduce(
1342
                        _outputFields[idx_group][1].data(), _outputFields[idx_group][1].data(), _nCells, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
1343
                    MPI_Barrier( MPI_COMM_WORLD );
1344
#endif
1345
                    break;
×
1346
                default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1347
            }
1348
        }
1349
    }
1350
}
1351

1352
void SNSolverHPC::PrintVolumeOutput( int idx_iter ) {
×
1353
    if( _settings->GetSaveRestartSolutionFrequency() != 0 && idx_iter % (int)_settings->GetSaveRestartSolutionFrequency() == 0 ) {
×
1354
        // std::cout << "Saving restart solution at iteration " << idx_iter << std::endl;
1355
        WriteRestartSolution( _settings->GetOutputFile(),
×
1356
                              _sol,
×
1357
                              _scalarFlux,
×
1358
                              _rank,
1359
                              idx_iter,
1360
                              _totalAbsorptionHohlraumCenter,
1361
                              _totalAbsorptionHohlraumVertical,
1362
                              _totalAbsorptionHohlraumHorizontal,
1363
                              _totalAbsorptionLattice );
1364
    }
1365

1366
    if( _settings->GetVolumeOutputFrequency() != 0 && idx_iter % (int)_settings->GetVolumeOutputFrequency() == 0 ) {
×
1367
        WriteVolumeOutput( idx_iter );
×
1368
        if( _rank == 0 ) {
×
1369
            ExportVTK( _settings->GetOutputFile() + "_" + std::to_string( idx_iter ), _outputFields, _outputFieldNames, _mesh );    // slow
×
1370
        }
1371
    }
1372
    if( idx_iter == (int)_nIter - 1 ) {    // Last iteration write without suffix.
×
1373
        WriteVolumeOutput( idx_iter );
×
1374
        if( _rank == 0 ) {
×
1375
            ExportVTK( _settings->GetOutputFile(), _outputFields, _outputFieldNames, _mesh );
×
1376
        }
1377
    }
1378
}
1379

1380
void SNSolverHPC::PrepareVolumeOutput() {
×
1381
    unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
×
1382

1383
    _outputFieldNames.resize( nGroups );
×
1384
    _outputFields.resize( nGroups );
×
1385

1386
    // Prepare all OutputGroups ==> Specified in option VOLUME_OUTPUT
1387
    for( unsigned idx_group = 0; idx_group < nGroups; idx_group++ ) {
×
1388
        // Prepare all Output Fields per group
1389

1390
        // Different procedure, depending on the Group...
1391
        switch( _settings->GetVolumeOutput()[idx_group] ) {
×
1392
            case MINIMAL:
×
1393
                // Currently only one entry ==> rad flux
1394
                _outputFields[idx_group].resize( 1 );
×
1395
                _outputFieldNames[idx_group].resize( 1 );
×
1396

1397
                _outputFields[idx_group][0].resize( _nCells );
×
1398
                _outputFieldNames[idx_group][0] = "scalar flux";
×
1399
                break;
×
1400
            case MOMENTS:
×
1401
                // As many entries as there are moments in the system
1402
                _outputFields[idx_group].resize( _nOutputMoments );
×
1403
                _outputFieldNames[idx_group].resize( _nOutputMoments );
×
1404

1405
                for( unsigned idx_moment = 0; idx_moment < _nOutputMoments; idx_moment++ ) {
×
1406
                    _outputFieldNames[idx_group][idx_moment] = std::string( "u_" + std::to_string( idx_moment ) );
×
1407
                    _outputFields[idx_group][idx_moment].resize( _nCells );
×
1408
                }
1409
                break;
×
1410

1411
            default: ErrorMessages::Error( "Volume Output Group not defined for HPC SN Solver!", CURRENT_FUNCTION ); break;
×
1412
        }
1413
    }
1414
}
1415

1416
void SNSolverHPC::SetGhostCells() {
×
1417
    if( _settings->GetProblemName() == PROBLEM_Lattice ) {
×
1418
        // #pragma omp parallel for
1419
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
×
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
        }
1424
    }
1425
    else if( _settings->GetProblemName() == PROBLEM_HalfLattice ) {    // HALF LATTICE NOT WORKING
×
1426
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1427
    }
1428
    else if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
1429

1430
        auto nodes = _mesh->GetNodes();
×
1431
        double tol = 1e-12;    // For distance to boundary
×
1432

1433
        // #pragma omp parallel for
1434
        for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
×
1435

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

1439
                auto localCellNodes = _mesh->GetCells()[idx_cell];
×
1440

1441
                for( unsigned idx_node = 0; idx_node < _mesh->GetNumNodesPerCell(); idx_node++ ) {    // Check if corner node is in this cell
×
1442
                    if( nodes[localCellNodes[idx_node]][0] < -0.65 + tol ) {                          // close to 0 => left boundary
×
1443
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
1444
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] > 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
×
1445
                        }
1446
                        break;
×
1447
                    }
1448
                    else if( nodes[localCellNodes[idx_node]][0] > 0.65 - tol ) {    // right boundary
×
1449
                        for( unsigned idx_sys = 0; idx_sys < _localNSys; idx_sys++ ) {
×
1450
                            if( _quadPts[Idx2D( idx_sys, 0, _nDim )] < 0.0 ) _ghostCells[idx_cell][idx_sys] = 1.0;
×
1451
                        }
1452
                        break;
×
1453
                    }
1454
                    else if( nodes[localCellNodes[idx_node]][1] < -0.65 + tol ) {    // lower boundary
×
1455
                        break;
×
1456
                    }
1457
                    else if( nodes[localCellNodes[idx_node]][1] > 0.65 - tol ) {    // upper boundary
×
1458
                        break;
×
1459
                    }
1460
                    else if( idx_node == _mesh->GetNumNodesPerCell() - 1 ) {
×
1461
                        ErrorMessages::Error( " Problem with ghost cell setup and  boundary of this mesh ", CURRENT_FUNCTION );
×
1462
                    }
1463
                }
1464
            }
1465
        }
1466
    }
1467
    else if( _settings->GetProblemName() == PROBLEM_QuarterHohlraum ) {
×
1468
        ErrorMessages::Error( "Test case does not work with MPI", CURRENT_FUNCTION );
×
1469
    }
1470
}
1471

1472
void SNSolverHPC::SetProbingCellsLineGreen() {
×
1473

UNCOV
1474
    if( _settings->GetProblemName() == PROBLEM_SymmetricHohlraum ) {
×
1475

1476
        std::vector<double> p1 = { _cornerUpperLeftGreen[0] + _thicknessGreen / 2.0, _cornerUpperLeftGreen[1] - _thicknessGreen / 2.0 };
×
1477
        std::vector<double> p2 = { _cornerUpperRightGreen[0] - _thicknessGreen / 2.0, _cornerUpperRightGreen[1] - _thicknessGreen / 2.0 };
×
1478
        std::vector<double> p3 = { _cornerLowerRightGreen[0] - _thicknessGreen / 2.0, _cornerLowerRightGreen[1] + _thicknessGreen / 2.0 };
×
1479
        std::vector<double> p4 = { _cornerLowerLeftGreen[0] + _thicknessGreen / 2.0, _cornerLowerLeftGreen[1] + _thicknessGreen / 2.0 };
×
1480

1481
        double verticalLineWidth   = std::abs( p1[1] - p4[1] );
×
1482
        double horizontalLineWidth = std::abs( p1[0] - p2[0] );
×
1483

1484
        double pt_ratio_h = horizontalLineWidth / ( horizontalLineWidth + verticalLineWidth );
×
1485
        double pt_ratio_v = verticalLineWidth / ( horizontalLineWidth + verticalLineWidth );
×
1486

1487
        unsigned nHorizontalProbingCells = (unsigned)std::ceil( _nProbingCellsLineGreen / 2 * pt_ratio_h );
×
1488
        unsigned nVerticalProbingCells   = _nProbingCellsLineGreen / 2 - nHorizontalProbingCells;
×
1489

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

1492
        // Sample points on each side of the rectangle
1493
        std::vector<unsigned> side1 = linspace2D( p1, p2, nHorizontalProbingCells );    // upper horizontal
×
1494
        std::vector<unsigned> side2 = linspace2D( p2, p3, nVerticalProbingCells );      // right vertical
×
1495
        std::vector<unsigned> side3 = linspace2D( p3, p4, nHorizontalProbingCells );    // lower horizontal
×
1496
        std::vector<unsigned> side4 = linspace2D( p4, p1, nVerticalProbingCells );      // left vertical
×
1497

1498
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
×
1499
            _probingCellsLineGreen[i] = side1[i];
×
1500
        }
1501
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
×
1502
            _probingCellsLineGreen[i + nHorizontalProbingCells] = side2[i];
×
1503
        }
1504
        for( unsigned i = 0; i < nHorizontalProbingCells; ++i ) {
×
1505
            _probingCellsLineGreen[i + nVerticalProbingCells + nHorizontalProbingCells] = side3[i];
×
1506
        }
1507
        for( unsigned i = 0; i < nVerticalProbingCells; ++i ) {
×
1508
            _probingCellsLineGreen[i + nVerticalProbingCells + 2 * nHorizontalProbingCells] = side4[i];
×
1509
        }
1510

1511
        // Block-wise approach
1512
        // Initialize the vector to store the corner points of each block
1513
        std::vector<std::vector<std::vector<double>>> block_corners;
×
1514

1515
        double block_size = 0.05;
×
1516

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

1520
            // Top row
1521
            double x1 = -0.2 + i * block_size;
×
1522
            double y1 = 0.4;
×
1523
            double x2 = x1 + block_size;
×
1524
            double y2 = y1 - block_size;
×
1525

1526
            std::vector<std::vector<double>> corners = {
1527
                { x1, y1 },    // top-left
1528
                { x2, y1 },    // top-right
1529
                { x2, y2 },    // bottom-right
1530
                { x1, y2 }     // bottom-left
1531
            };
1532
            block_corners.push_back( corners );
×
1533
        }
1534

1535
        for( int j = 0; j < 14; ++j ) {    // 14 blocks in the y-direction (vertical)
×
1536
            // right column double x1 = 0.15;
1537
            double x1 = 0.15;
×
1538
            double y1 = 0.35 - j * block_size;
×
1539
            double x2 = x1 + block_size;
×
1540
            double y2 = y1 - block_size;
×
1541

1542
            // Store the four corner points for this block
1543
            std::vector<std::vector<double>> corners = {
1544
                { x1, y1 },    // top-left
1545
                { x2, y1 },    // top-right
1546
                { x2, y2 },    // bottom-right
1547
                { x1, y2 }     // bottom-left
1548
            };
1549

1550
            block_corners.push_back( corners );
×
1551
        }
1552

1553
        for( int i = 0; i < 8; ++i ) {    // 8 blocks in the x-direction (horizontal) (lower) (right to left)
×
1554
            // bottom row
1555
            double x1 = 0.15 - i * block_size;
×
1556
            double y1 = -0.35;
×
1557
            double x2 = x1 + block_size;
×
1558
            double y2 = y1 - block_size;
×
1559

1560
            std::vector<std::vector<double>> corners = {
1561
                { x1, y1 },    // top-left
1562
                { x2, y1 },    // top-right
1563
                { x2, y2 },    // bottom-right
1564
                { x1, y2 }     // bottom-left
1565
            };
1566
            block_corners.push_back( corners );
×
1567
        }
1568

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

1571
            // left column
1572
            double x1 = -0.2;
×
1573
            double y1 = -0.3 + j * block_size;
×
1574
            double x2 = x1 + block_size;
×
1575
            double y2 = y1 - block_size;
×
1576

1577
            // Store the four corner points for this block
1578
            std::vector<std::vector<double>> corners = {
1579
                { x1, y1 },    // top-left
1580
                { x2, y1 },    // top-right
1581
                { x2, y2 },    // bottom-right
1582
                { x1, y2 }     // bottom-left
1583
            };
1584

1585
            block_corners.push_back( corners );
×
1586
        }
1587

1588
        // Compute the probing cells for each block
1589
        for( int i = 0; i < _nProbingCellsBlocksGreen; i++ ) {
×
1590
            _probingCellsBlocksGreen.push_back( _mesh->GetCellsofRectangle( block_corners[i] ) );
×
1591
        }
1592
    }
1593
}
1594

1595
void SNSolverHPC::ComputeQOIsGreenProbingLine() {
×
1596
    double verticalLineWidth   = std::abs( _cornerUpperLeftGreen[1] - _cornerLowerLeftGreen[1] - _thicknessGreen );
×
1597
    double horizontalLineWidth = std::abs( _cornerUpperLeftGreen[0] - _cornerUpperRightGreen[0] - _thicknessGreen );
×
1598

1599
    double dl    = 2 * ( horizontalLineWidth + verticalLineWidth ) / ( (double)_nProbingCellsLineGreen );
×
1600
    double area  = dl * _thicknessGreen;
×
1601
    double l_max = _nProbingCellsLineGreen * dl;
×
1602

1603
#pragma omp parallel for
×
1604
    for( unsigned i = 0; i < _nProbingCellsLineGreen; i++ ) {    // Loop over probing cells
1605
        _absorptionValsLineSegment[i] =
1606
            ( _sigmaT[_probingCellsLineGreen[i]] - _sigmaS[_probingCellsLineGreen[i]] ) * _scalarFlux[_probingCellsLineGreen[i]];
1607
    }
1608

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

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

1633
    std::vector<unsigned> result;
×
NEW
1634
    assert( num_points > 1 );
×
1635
    result.resize( num_points );
×
1636
    double stepX = ( end[0] - start[0] ) / ( num_points - 1 );
×
1637
    double stepY = ( end[1] - start[1] ) / ( num_points - 1 );
×
1638
#pragma omp parallel for
×
1639
    for( unsigned i = 0; i < num_points; ++i ) {
1640
        double x = start[0] + i * stepX;
1641
        double y = start[1] + i * stepY;
1642

1643
        result[i] = _mesh->GetCellOfKoordinate( x, y );
1644
    }
1645

1646
    return result;
×
1647
}
1648

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

1658
    _isPerimeterLatticeCell1.resize( _mesh->GetNumCells(), false );
×
1659
    _isPerimeterLatticeCell2.resize( _mesh->GetNumCells(), false );
×
1660

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

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