Commit 7590242d authored by yy3406's avatar yy3406
Browse files

Merge branch 'recons' into 'master'

Merge recons into master

See merge request !36

Former-commit-id: 2e59500d
parents abc5e0a3 d1c74e69
...@@ -42,6 +42,9 @@ class MNSolver : public Solver ...@@ -42,6 +42,9 @@ 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 */
VectorVector _solDx; /*! @brief: temporary storage of x-derivatives of alpha */
VectorVector _solDy; /*! @brief: temporary storage of y-derivatives of alpha */
// ---- Private Member functions --- // ---- Private Member functions ---
// IO // IO
......
...@@ -38,8 +38,8 @@ class PNSolver : public Solver ...@@ -38,8 +38,8 @@ class PNSolver : public Solver
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. */
VectorVector _solDx; VectorVector _solDx; /*! @brief: temporary storage of x-derivatives of solution */
VectorVector _solDy; VectorVector _solDy; /*! @brief: temporary storage of y-derivatives of solution */
// ---- Member functions ---- // ---- Member functions ----
......
...@@ -53,12 +53,12 @@ class Solver ...@@ -53,12 +53,12 @@ class Solver
std::vector<std::vector<unsigned>> _neighbors; std::vector<std::vector<unsigned>> _neighbors;
// slope related params // slope related params
Reconstructor* _reconstructor; /*! @brief reconstructor class for high order scheme */ Reconstructor* _reconstructor; /*! @brief reconstructor object for high-order scheme */
unsigned _reconsOrder; unsigned _reconsOrder; /*! @brief reconstruction order (current: 1 & 2) */
VectorVector _psiDx; VectorVector _psiDx; /*! @brief slope of solutions in X direction */
VectorVector _psiDy; VectorVector _psiDy; /*! @brief slope of solutions in Y direction */
VectorVector _cellMidPoints; VectorVector _cellMidPoints; /*! @brief middle point locations of elements */
std::vector<std::vector<Vector>> _interfaceMidPoints; std::vector<std::vector<Vector>> _interfaceMidPoints; /*! @brief middle point locations of edges */
// Solution related members // Solution related members
VectorVector _sol; /*! @brief solution of the PDE, e.g. angular flux or moments */ VectorVector _sol; /*! @brief solution of the PDE, e.g. angular flux or moments */
......
...@@ -36,6 +36,8 @@ MAX_MOMENT_SOLVER = 0 ...@@ -36,6 +36,8 @@ MAX_MOMENT_SOLVER = 0
%% Entropy settings %% Entropy settings
ENTROPY_FUNCTIONAL = MAXWELL_BOLTZMANN ENTROPY_FUNCTIONAL = MAXWELL_BOLTZMANN
ENTROPY_OPTIMIZER = NEWTON ENTROPY_OPTIMIZER = NEWTON
% Reconstruction order
RECONS_ORDER = 2
% %
% ----- Newton Solver Specifications ---- % ----- Newton Solver Specifications ----
% %
......
...@@ -31,6 +31,10 @@ MNSolver::MNSolver( Config* settings ) : Solver( settings ) { ...@@ -31,6 +31,10 @@ MNSolver::MNSolver( Config* settings ) : Solver( settings ) {
_quadPointsSphere = _quadrature->GetPointsSphere(); _quadPointsSphere = _quadrature->GetPointsSphere();
_settings->SetNQuadPoints( _nq ); _settings->SetNQuadPoints( _nq );
// Initialize temporary storages of alpha derivatives
_solDx = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) );
_solDy = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) );
// Initialize Scatter Matrix -- // Initialize Scatter Matrix --
_scatterMatDiag = Vector( _nTotalEntries, 0.0 ); _scatterMatDiag = Vector( _nTotalEntries, 0.0 );
ComputeScatterMatrix(); ComputeScatterMatrix();
...@@ -88,29 +92,49 @@ void MNSolver::ComputeMoments() { ...@@ -88,29 +92,49 @@ void MNSolver::ComputeMoments() {
Vector MNSolver::ConstructFlux( unsigned idx_cell ) { Vector MNSolver::ConstructFlux( unsigned idx_cell ) {
// ---- Integration of Moment of flux ---- //--- Integration of moments of flux ---
double entropyL, entropyR, entropyFlux; double entropyL, entropyR, entropyFlux;
Vector flux( _nTotalEntries, 0.0 ); Vector flux( _nTotalEntries, 0.0 );
for( unsigned idx_quad = 0; idx_quad < _nq; idx_quad++ ) { //--- Temporary storages of reconstructed alpha ---
Vector alphaL( _nTotalEntries, 0.0 );
entropyFlux = 0.0; // Reset temorary flux Vector alphaR( _nTotalEntries, 0.0 );
entropyL = _entropy->EntropyPrimeDual( blaze::dot( _alpha[idx_cell], _moments[idx_quad] ) ); for( unsigned idx_quad = 0; idx_quad < _nq; idx_quad++ ) {
entropyFlux = 0.0; // reset temorary flux
for( unsigned idx_neigh = 0; idx_neigh < _neighbors[idx_cell].size(); idx_neigh++ ) { for( unsigned idx_neigh = 0; idx_neigh < _neighbors[idx_cell].size(); idx_neigh++ ) {
// Store fluxes in psiNew, to save memory // Left side reconstruction
if( _reconsOrder > 1 ) {
alphaL = _alpha[idx_cell] +
_solDx[idx_cell] * ( _interfaceMidPoints[idx_cell][idx_neigh][0] - _cellMidPoints[idx_cell][0] ) +
_solDy[idx_cell] * ( _interfaceMidPoints[idx_cell][idx_neigh][1] - _cellMidPoints[idx_cell][1] );
}
else {
alphaL = _alpha[idx_cell];
}
entropyL = _entropy->EntropyPrimeDual( blaze::dot( alphaL, _moments[idx_quad] ) );
// Right side reconstruction
if( _boundaryCells[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[idx_cell][idx_neigh] == _nCells ) if( _boundaryCells[idx_cell] == BOUNDARY_TYPE::NEUMANN && _neighbors[idx_cell][idx_neigh] == _nCells )
entropyR = entropyL; entropyR = entropyL;
else { else {
entropyR = _entropy->EntropyPrimeDual( blaze::dot( _alpha[_neighbors[idx_cell][idx_neigh]], _moments[idx_quad] ) ); if( _reconsOrder > 1 ) {
alphaR = _alpha[_neighbors[idx_cell][idx_neigh]] +
_solDx[_neighbors[idx_cell][idx_neigh]] * ( _interfaceMidPoints[idx_cell][idx_neigh][0] - _cellMidPoints[_neighbors[idx_cell][idx_neigh]][0] ) +
_solDy[_neighbors[idx_cell][idx_neigh]] * ( _interfaceMidPoints[idx_cell][idx_neigh][1] - _cellMidPoints[_neighbors[idx_cell][idx_neigh]][1] );
}
else {
alphaR = _alpha[_neighbors[idx_cell][idx_neigh]];
}
entropyR = _entropy->EntropyPrimeDual( blaze::dot( alphaR, _moments[idx_quad] ) );
} }
// Entropy flux
entropyFlux += _g->Flux( _quadPoints[idx_quad], entropyL, entropyR, _normals[idx_cell][idx_neigh] ); entropyFlux += _g->Flux( _quadPoints[idx_quad], entropyL, entropyR, _normals[idx_cell][idx_neigh] );
} }
// Solution flux
flux += _moments[idx_quad] * ( _weights[idx_quad] * entropyFlux ); flux += _moments[idx_quad] * ( _weights[idx_quad] * entropyFlux );
// ------- Relizablity Reconstruction Step ----
} }
return flux; return flux;
} }
...@@ -153,6 +177,10 @@ void MNSolver::ComputeRadFlux() { ...@@ -153,6 +177,10 @@ void MNSolver::ComputeRadFlux() {
} }
void MNSolver::FluxUpdate() { void MNSolver::FluxUpdate() {
if( _reconsOrder > 1 ) {
_mesh->ReconstructSlopesU( _nTotalEntries, _solDx, _solDy, _alpha ); // unstructured reconstruction
}
// Loop over the grid cells // Loop over the grid cells
for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) { for( unsigned idx_cell = 0; idx_cell < _nCells; idx_cell++ ) {
// Dirichlet Boundaries stay // Dirichlet Boundaries stay
......
...@@ -32,6 +32,7 @@ PNSolver::PNSolver( Config* settings ) : Solver( settings ) { ...@@ -32,6 +32,7 @@ PNSolver::PNSolver( Config* settings ) : Solver( settings ) {
// Initialize Scatter Matrix // Initialize Scatter Matrix
_scatterMatDiag = Vector( _nTotalEntries, 0 ); _scatterMatDiag = Vector( _nTotalEntries, 0 );
// Initialize temporary storages of solution derivatives
_solDx = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) ); _solDx = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) );
_solDy = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) ); _solDy = VectorVector( _nCells, Vector( _nTotalEntries, 0.0 ) );
...@@ -126,7 +127,8 @@ void PNSolver::FluxUpdate() { ...@@ -126,7 +127,8 @@ void PNSolver::FluxUpdate() {
solR = _sol[_neighbors[idx_cell][idx_neighbor]] + solR = _sol[_neighbors[idx_cell][idx_neighbor]] +
_solDx[_neighbors[idx_cell][idx_neighbor]] * ( _interfaceMidPoints[idx_cell][idx_neighbor][0] - _cellMidPoints[_neighbors[idx_cell][idx_neighbor]][0] ) + _solDx[_neighbors[idx_cell][idx_neighbor]] * ( _interfaceMidPoints[idx_cell][idx_neighbor][0] - _cellMidPoints[_neighbors[idx_cell][idx_neighbor]][0] ) +
_solDy[_neighbors[idx_cell][idx_neighbor]] * ( _interfaceMidPoints[idx_cell][idx_neighbor][1] - _cellMidPoints[_neighbors[idx_cell][idx_neighbor]][1] ); _solDy[_neighbors[idx_cell][idx_neighbor]] * ( _interfaceMidPoints[idx_cell][idx_neighbor][1] - _cellMidPoints[_neighbors[idx_cell][idx_neighbor]][1] );
// positivity check (if not satisfied, deduce to first order) // positivity checker (if not satisfied, deduce to first order)
// I manually turned it off here since Pn produces negative solutions essentially
//if( min(solL) < 0.0 || min(solR) < 0.0 ) { //if( min(solL) < 0.0 || min(solR) < 0.0 ) {
// solL = _sol[idx_cell]; // solL = _sol[idx_cell];
// solR = _sol[_neighbors[idx_cell][idx_neighbor]]; // solR = _sol[_neighbors[idx_cell][idx_neighbor]];
......
Markdown is supported
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