Commit ce972d95 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

tidy up core solver headers


Former-commit-id: 21109255
parent af310bbc
...@@ -29,7 +29,7 @@ class CSDSNSolver : public SNSolver ...@@ -29,7 +29,7 @@ class CSDSNSolver : public SNSolver
private: private:
void PrepareOutputFields() override; void PrepareOutputFields() override;
double WriteOutputFields( unsigned idx_pseudoTime ) override; void WriteOutputFields( unsigned idx_pseudoTime ) override;
}; };
#endif // CSDSNSOLVER_H #endif // CSDSNSOLVER_H
...@@ -20,6 +20,7 @@ class MNSolver : public Solver ...@@ -20,6 +20,7 @@ class MNSolver : public Solver
~MNSolver(); ~MNSolver();
private: private:
// --- Private member variables ---
unsigned _nTotalEntries; /*! @brief: Total number of equations in the system */ unsigned _nTotalEntries; /*! @brief: Total number of equations in the system */
unsigned short _LMaxDegree; /*! @brief: Max Order of Moments */ unsigned short _LMaxDegree; /*! @brief: Max Order of Moments */
...@@ -27,11 +28,10 @@ class MNSolver : public Solver ...@@ -27,11 +28,10 @@ class MNSolver : public Solver
SphericalHarmonics* _basis; /*! @brief: Class to compute and store current spherical harmonics basis */ SphericalHarmonics* _basis; /*! @brief: Class to compute and store current spherical harmonics basis */
VectorVector _moments; /*! @brief: Moment Vector pre-computed at each quadrature point: dim= _nq x _nTotalEntries */ VectorVector _moments; /*! @brief: Moment Vector pre-computed at each quadrature point: dim= _nq x _nTotalEntries */
// Right hand side members // Scattering
Vector _scatterMatDiag; /*! @brief: Diagonal of the scattering matrix (its a diagonal matrix by construction) */ Vector _scatterMatDiag; /*! @brief: Diagonal of the scattering matrix (its a diagonal matrix by construction) */
// TODO: Source
// quadrature related members // Quadrature related members
VectorVector _quadPoints; /*! @brief quadrature points, dim(_quadPoints) = (_nq,spatialDim) */ VectorVector _quadPoints; /*! @brief quadrature points, dim(_quadPoints) = (_nq,spatialDim) */
Vector _weights; /*! @brief quadrature weights, dim(_weights) = (_nq) */ Vector _weights; /*! @brief quadrature weights, dim(_weights) = (_nq) */
VectorVector _quadPointsSphere; /*! @brief (my,phi), dim(_quadPoints) = (_nq,2) */ VectorVector _quadPointsSphere; /*! @brief (my,phi), dim(_quadPoints) = (_nq,2) */
...@@ -42,49 +42,41 @@ class MNSolver : public Solver ...@@ -42,49 +42,41 @@ class MNSolver : public Solver
Layout: _nCells x _nTotalEntries*/ Layout: _nCells x _nTotalEntries*/
OptimizerBase* _optimizer; /*! @brief: Class to solve minimal entropy problem */ OptimizerBase* _optimizer; /*! @brief: Class to solve minimal entropy problem */
// ---- Member functions --- // ---- Private Member functions ---
// IO // IO
/*! @brief Initializes the output groups and fields of this solver and names the fields */
void PrepareOutputFields() override;
/*! @brief Function that writes NN Training Data in a .csv file */ /*! @brief Function that writes NN Training Data in a .csv file */
void WriteNNTrainingData( unsigned idx_pseudoTime ); void WriteNNTrainingData( unsigned idx_pseudoTime );
/*! @brief Function that prepares VTK export and csv export of the current solver iteration void PrepareOutputFields() override;
@returns: Mass of current iteration void WriteOutputFields( unsigned idx_pseudoTime ) override;
*/
double WriteOutputFields( unsigned idx_pseudoTime ) override;
/*! @brief : computes the global index of the moment corresponding to basis function (l,k)
* @param : degree l, it must hold: 0 <= l <=_nq
* @param : order k, it must hold: -l <=k <= l
* @returns : global index
*/
int GlobalIndex( int l, int k ) const;
// Solver
void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override;
void FluxUpdate( VectorVector& psiNew ) override;
void IterPreprocessing() override;
void IterPostprocessing();
/*! @brief : Construct flux by computing the Moment of the sum of FVM discretization at the interface of cell /*! @brief : Construct flux by computing the Moment of the sum of FVM discretization at the interface of cell
* @param : idx_cell = current cell id * @param : idx_cell = current cell id
* @returns : sum over all neighbors of flux for all moments at interface of idx_cell, idx_neighbor */ * @returns : sum over all neighbors of flux for all moments at interface of idx_cell, idx_neighbor */
Vector ConstructFlux( unsigned idx_cell ); Vector ConstructFlux( unsigned idx_cell );
/*! @brief Corrects the solution _sol[idx_cell] to be realizable w.r.t. the reconstructed entropy (eta'(alpha*m))
@param idx_cell = cell where the correction happens*/
void ComputeRealizableSolution( unsigned idx_cell );
// Initialization of the solver
/*! @brief : Pre-Compute Moments at all quadrature points. */ /*! @brief : Pre-Compute Moments at all quadrature points. */
void ComputeMoments(); void ComputeMoments();
/*! @brief: fucntion for computing and setting up EV matrix for scattering kernel */ /*! @brief: fucntion for computing and setting up EV matrix for scattering kernel */
void ComputeScatterMatrix(); void ComputeScatterMatrix();
/*! @brief Corrects the solution _sol[idx_cell] to be realizable w.r.t. the reconstructed entropy (eta'(alpha*m))
@param idx_cell = cell where the correction happens*/
void ComputeRealizableSolution( unsigned idx_cell );
// Solver
void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override;
void FluxUpdate( VectorVector& psiNew ) override;
void IterPreprocessing() override;
void IterPostprocessing();
// Helper // Helper
void ComputeRadFlux(); void ComputeRadFlux();
/*! @brief : computes the global index of the moment corresponding to basis function (l,k)
* @param : degree l, it must hold: 0 <= l <=_nq
* @param : order k, it must hold: -l <=k <= l
* @returns : global index
*/
int GlobalIndex( int l, int k ) const;
}; };
#endif // MNSOLVER_H #endif // MNSOLVER_H
...@@ -11,11 +11,13 @@ class PNSolver : public Solver ...@@ -11,11 +11,13 @@ class PNSolver : public Solver
*/ */
PNSolver( Config* settings ); PNSolver( Config* settings );
protected: /*! @brief PNSolver destructor */
~PNSolver();
private:
unsigned _nTotalEntries; /*! @brief: total number of equations in the system */ unsigned _nTotalEntries; /*! @brief: total number of equations in the system */
unsigned _LMaxDegree; /*! @brief: maximal degree of the spherical harmonics basis*/ unsigned _LMaxDegree; /*! @brief: maximal degree of the spherical harmonics basis*/
// VectorVector _sigmaA; /*! @brief: Absorption coefficient for all energies*/
// System Matrix for x, y and z flux // System Matrix for x, y and z flux
// ==> not needed after computation of A+ and A- ==> maybe safe only temporarly and remove as member? // ==> not needed after computation of A+ and A- ==> maybe safe only temporarly and remove as member?
SymMatrix _Ax; /*! @brief: Flux Jacbioan in x direction */ SymMatrix _Ax; /*! @brief: Flux Jacbioan in x direction */
...@@ -33,8 +35,6 @@ class PNSolver : public Solver ...@@ -33,8 +35,6 @@ class PNSolver : public Solver
Matrix _AzMinus; /*! @brief: Flux Jacbioan in z direction, negative part */ Matrix _AzMinus; /*! @brief: Flux Jacbioan in z direction, negative part */
Matrix _AzAbs; /*! @brief: Flux Jacbioan in z direction, absolute part */ Matrix _AzAbs; /*! @brief: Flux Jacbioan in z direction, absolute part */
// double _combinedSpectralRadius; /*! @brief: Combined spectral radius of sum of flux jacobians*/
Vector _scatterMatDiag; /*! @brief: diagonal of the scattering matrix (its a diagonal matrix by construction). Contains eigenvalues of the Vector _scatterMatDiag; /*! @brief: diagonal of the scattering matrix (its a diagonal matrix by construction). Contains eigenvalues of the
scattering kernel. */ scattering kernel. */
...@@ -43,10 +43,9 @@ class PNSolver : public Solver ...@@ -43,10 +43,9 @@ class PNSolver : public Solver
// IO // IO
/*! @brief Initializes the output groups and fields of this solver and names the fields */ /*! @brief Initializes the output groups and fields of this solver and names the fields */
void PrepareOutputFields() override; void PrepareOutputFields() override;
/*! @brief Function that prepares VTK export and csv export of the current solver iteration /*! @brief Function that prepares VTK export and csv export of the current solver iteration
@returns: Mass of current iteration */ @returns: Mass of current iteration */
double WriteOutputFields( unsigned idx_pseudoTime ) override; void WriteOutputFields( unsigned idx_pseudoTime ) override;
// Solver // Solver
void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override; void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override;
...@@ -57,7 +56,7 @@ class PNSolver : public Solver ...@@ -57,7 +56,7 @@ class PNSolver : public Solver
// Helper // Helper
void ComputeRadFlux(); void ComputeRadFlux();
// Initialization // Initialization of the Solver
/*! @brief: parameter functions for setting up system matrix /*! @brief: parameter functions for setting up system matrix
* @param: degree l, it must hold: 0 <= l <=_nq * @param: degree l, it must hold: 0 <= l <=_nq
* @param : order k, it must hold: -l <=k <= l * @param : order k, it must hold: -l <=k <= l
......
...@@ -20,8 +20,9 @@ class SNSolver : public Solver ...@@ -20,8 +20,9 @@ class SNSolver : public Solver
SNSolver( Config* settings ); SNSolver( Config* settings );
private: private:
// IO
void PrepareOutputFields() override; void PrepareOutputFields() override;
double WriteOutputFields( unsigned idx_pseudoTime ) override; void WriteOutputFields( unsigned idx_pseudoTime ) override;
// Solver // Solver
void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override; void FVMUpdate( VectorVector& psiNew, unsigned idx_energy ) override;
......
...@@ -74,17 +74,12 @@ class Solver ...@@ -74,17 +74,12 @@ class Solver
// IO // IO
/*! @brief Initializes the output groups and fields of this solver and names the fields */ /*! @brief Initializes the output groups and fields of this solver and names the fields */
virtual void PrepareOutputFields() = 0; virtual void PrepareOutputFields() = 0;
/*! @brief Function that prepares VTK export and csv export of the current solver iteration */
/*! @brief Function that prepares VTK export and csv export of the current solver iteration virtual void WriteOutputFields( unsigned idx_pseudoTime ) = 0;
@returns: Mass of current iteration */
virtual double WriteOutputFields( unsigned idx_pseudoTime ) = 0;
/*! @brief: Initialized the output fields and their Names for the Screenoutput */ /*! @brief: Initialized the output fields and their Names for the Screenoutput */
void PrepareScreenOutputFields(); void PrepareScreenOutputFields();
/*! @brief Function that Screen Output and prints to Screen/Logger */ /*! @brief Function that Screen Output and prints to Screen/Logger */
void WriteScreenOutputFields( unsigned idx_pseudoTime ); void WriteScreenOutputFields( unsigned idx_pseudoTime );
/*! @brief Prints ScreenOutputFields to Screen and to logger */ /*! @brief Prints ScreenOutputFields to Screen and to logger */
void PrintScreen( std::shared_ptr<spdlog::logger> log ); void PrintScreen( std::shared_ptr<spdlog::logger> log );
......
...@@ -187,7 +187,7 @@ void CSDSNSolver::PrepareOutputFields() { ...@@ -187,7 +187,7 @@ void CSDSNSolver::PrepareOutputFields() {
} }
} }
double CSDSNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { void CSDSNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
double mass = 0.0; double mass = 0.0;
unsigned nGroups = (unsigned)_settings->GetNVolumeOutput(); unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
...@@ -219,5 +219,4 @@ double CSDSNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { ...@@ -219,5 +219,4 @@ double CSDSNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
} }
} }
} }
return mass;
} }
...@@ -244,16 +244,8 @@ void MNSolver::PrepareOutputFields() { ...@@ -244,16 +244,8 @@ void MNSolver::PrepareOutputFields() {
} }
} }
double MNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { void MNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
double mass = 0.0; unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
double firstMomentScaleFactor = sqrt( 4 * M_PI );
// Compute total "mass" of the system ==> to check conservation properties
for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
mass += _sol[idx_cell][0] * _areas[idx_cell]; // Should probably go to postprocessing
}
mass *= firstMomentScaleFactor;
if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) || if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) { ( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) {
...@@ -294,7 +286,6 @@ double MNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { ...@@ -294,7 +286,6 @@ double MNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
} }
} }
} }
return mass;
} }
void MNSolver::WriteNNTrainingData( unsigned idx_pseudoTime ) { void MNSolver::WriteNNTrainingData( unsigned idx_pseudoTime ) {
......
...@@ -359,16 +359,8 @@ void PNSolver::PrepareOutputFields() { ...@@ -359,16 +359,8 @@ void PNSolver::PrepareOutputFields() {
} }
} }
double PNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { void PNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
double mass = 0.0; unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
double firstMomentScaleFactor = sqrt( 4 * M_PI );
// Compute total "mass" of the system ==> to check conservation properties
for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
mass += _sol[idx_cell][0] * _areas[idx_cell]; // Should probably go to postprocessing
}
mass *= firstMomentScaleFactor;
if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) || if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) { ( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) {
...@@ -390,7 +382,6 @@ double PNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { ...@@ -390,7 +382,6 @@ double PNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
} }
} }
} }
return mass;
} }
void PNSolver::CleanFluxMatrices() { void PNSolver::CleanFluxMatrices() {
......
...@@ -220,17 +220,9 @@ void SNSolver::PrepareOutputFields() { ...@@ -220,17 +220,9 @@ void SNSolver::PrepareOutputFields() {
} }
} }
double SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { void SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
double mass = 0.0;
unsigned nGroups = (unsigned)_settings->GetNVolumeOutput(); unsigned nGroups = (unsigned)_settings->GetNVolumeOutput();
// Compute total "mass" of the system ==> to check conservation properties
std::vector<double> flux( _nCells, 0.0 );
for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
flux[idx_cell] = dot( _sol[idx_cell], _weights );
mass += flux[idx_cell] * _areas[idx_cell];
}
if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) || if( ( _settings->GetVolumeOutputFrequency() != 0 && idx_pseudoTime % (unsigned)_settings->GetVolumeOutputFrequency() == 0 ) ||
( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) { ( idx_pseudoTime == _nEnergies - 1 ) /* need sol at last iteration */ ) {
...@@ -243,11 +235,8 @@ double SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { ...@@ -243,11 +235,8 @@ double SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
break; break;
case ANALYTIC: case ANALYTIC:
// Compute total "mass" of the system ==> to check conservation properties
for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) { for( unsigned idx_cell = 0; idx_cell < _nCells; ++idx_cell ) {
double time = idx_pseudoTime * _dE;
double time = idx_pseudoTime * _dE;
_outputFields[idx_group][0][idx_cell] = _problem->GetAnalyticalSolution( _outputFields[idx_group][0][idx_cell] = _problem->GetAnalyticalSolution(
_mesh->GetCellMidPoints()[idx_cell][0], _mesh->GetCellMidPoints()[idx_cell][1], time, _sigmaS[idx_pseudoTime][idx_cell] ); _mesh->GetCellMidPoints()[idx_cell][0], _mesh->GetCellMidPoints()[idx_cell][1], time, _sigmaS[idx_pseudoTime][idx_cell] );
} }
...@@ -257,5 +246,4 @@ double SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) { ...@@ -257,5 +246,4 @@ double SNSolver::WriteOutputFields( unsigned idx_pseudoTime ) {
} }
} }
} }
return mass;
} }
...@@ -155,8 +155,6 @@ void Solver::Solve() { ...@@ -155,8 +155,6 @@ void Solver::Solve() {
auto log = spdlog::get( "event" ); auto log = spdlog::get( "event" );
double mass = 0;
if( rank == 0 ) log->info( "{:10} {:10}", "t", "mass" ); if( rank == 0 ) log->info( "{:10} {:10}", "t", "mass" );
// Loop over energies (pseudo-time of continuous slowing down approach) // Loop over energies (pseudo-time of continuous slowing down approach)
...@@ -175,7 +173,7 @@ void Solver::Solve() { ...@@ -175,7 +173,7 @@ void Solver::Solve() {
IterPostprocessing(); IterPostprocessing();
// --- VTK and CSV Output --- // --- VTK and CSV Output ---
mass = WriteOutputFields( idx_energy ); WriteOutputFields( idx_energy );
Save( idx_energy ); Save( idx_energy );
// --- Screen Output --- // --- Screen Output ---
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment