Skip to content

Commit b716c91

Browse files
committed
enable smoothness indicator for pure DG simulations
1 parent c7b2ece commit b716c91

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/libcadet/model/parts/ConvectionDispersionOperatorDG.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,19 @@ bool AxialConvectionDispersionOperatorBaseDG::configureModelDiscretization(IPara
144144
if (numModes != 1 && numModes != 2)
145145
throw InvalidParameterException("Number of modes to compare modal energy must be 1 or 2, but was specified as " + std::to_string(numModes));
146146

147-
bool timeRelaxation = paramProvider.exists("TIME_RELAXATION") ? paramProvider.getBool("TIME_RELAXATION") : false;
147+
double timeRelaxation = paramProvider.exists("TIME_RELAXATION") ? paramProvider.getDouble("TIME_RELAXATION") : 0.0; // todo default value (0.7 was chosen in https://doi.org/10.1016/j.jcp.2021.110580)
148148

149149
_smoothnessIndicator = std::make_unique<ModalEnergyIndicator>(_polyDeg, getVandermonde_LEGENDRE().inverse(), numModes, nodalCoefThreshold, nodalCoefShift, timeRelaxation);
150150
}
151-
//else if (smoothness_indicator == "MODAL_ENERGY_PRIMITIVE") // todo? add other modal polynomial bases
152-
//{
153-
// double modalCoefThreshold = paramProvider.exists("MODAL_COEFFICIENT_THRESHOLD") ? paramProvider.getDouble("MODAL_COEFFICIENT_THRESHOLD") : 0.0; // 1e-12; // todo default value
154-
// double nodalCoefThreshold = paramProvider.exists("NODAL_COEFFICIENT_THRESHOLD") ? paramProvider.getDouble("NODAL_COEFFICIENT_THRESHOLD") : 0.0; // 1e-12; // todo default value
155-
// double nodalCoefShift = paramProvider.exists("NODAL_COEFFICIENT_SHIFT") ? paramProvider.getDouble("NODAL_COEFFICIENT_SHIFT") : 0.0; // 0.1; // todo default value
156-
// _smoothnessIndicator = std::make_unique<ModalEnergyIndicator>(_polyDeg, getVandermonde_PRIMITIVE().inverse(), nodalCoefThreshold, nodalCoefShift);
157-
//}
151+
else if (smoothness_indicator == "SLOPE_LIMITER")
152+
{
153+
const std::string limiter = paramProvider.exists("INDICATOR_LIMITER") ? paramProvider.getString("INDICATOR_LIMITER") : "MINMOD"; // todo choose default
154+
// todo time relaxation not required for this indicator (either 1 or zero) ?
155+
//double timeRelaxation = paramProvider.exists("TIME_RELAXATION") ? paramProvider.getDouble("TIME_RELAXATION") : 0.0; // todo default value (0.7 was chosen in https://doi.org/10.1016/j.jcp.2021.110580)
156+
double timeRelaxation = 0.0;
157+
// note that deltaZ is set in configure()
158+
_smoothnessIndicator = std::make_unique<SlopeIndicator>(_polyDeg, _nCells, 0.0, _invWeights.cwiseInverse(), _polyDerM, limiter, timeRelaxation);
159+
}
158160
else if (smoothness_indicator == "ALL_ELEMENTS")
159161
_smoothnessIndicator = std::make_unique<AllElementsIndicator>();
160162
else
@@ -207,6 +209,9 @@ bool AxialConvectionDispersionOperatorBaseDG::configureModelDiscretization(IPara
207209

208210
paramProvider.popScope();
209211
}
212+
else
213+
_smoothnessIndicator = nullptr;
214+
210215
paramProvider.popScope();
211216

212217
return true;
@@ -227,6 +232,8 @@ bool AxialConvectionDispersionOperatorBaseDG::configure(UnitOpIdx unitOpIdx, IPa
227232
_deltaZ = _colLength / _nCells;
228233
if (_OSmode == 1)
229234
_weno.setDeltaZ(_deltaZ);
235+
if (_OSmode)
236+
_smoothnessIndicator->configure(paramProvider);
230237

231238
/* compute dispersion jacobian blocks(without parameters except element spacing, i.e. static entries) */
232239
// we only need unique dispersion blocks, which are given by cells 1, 2, nCol for inexact integration DG and by cells 1, 2, 3, nCol-1, nCol for eaxct integration DG
@@ -483,7 +490,7 @@ int AxialConvectionDispersionOperatorBaseDG::residualImpl(const IModel& model, d
483490
Eigen::Map<Vector<StateType, Dynamic>, 0, InnerStride<>> _g(reinterpret_cast<StateType*>(&_g[0]), _nPoints, InnerStride<>(1));
484491

485492
// Calculate smoothness indicator if oscillation suppression is active
486-
if (_OSmode != 0 && _OSmode != 4)
493+
if (_calc_smoothness_indicator)
487494
{
488495
double oldIndicator = 0.0;
489496

@@ -494,12 +501,12 @@ int AxialConvectionDispersionOperatorBaseDG::residualImpl(const IModel& model, d
494501
_troubledCells[comp + cell * _nComp] = std::min(_maxBlending, _smoothnessIndicator->calcSmoothness(y + offsetC() + comp + cell * _strideCell, _strideNode, _nComp, cell));
495502
if (_troubledCells[comp + cell * _nComp] < _blendingThreshold)
496503
_troubledCells[comp + cell * _nComp] = 0.0;
497-
else if (_smoothnessIndicator->timeRelaxation())
498-
_troubledCells[comp + cell * _nComp] = std::max(0.7 * oldIndicator, _troubledCells[comp + cell * _nComp]);
504+
else if (_smoothnessIndicator->timeRelaxation()) // note: 0.0 <-> no relaxation
505+
_troubledCells[comp + cell * _nComp] = std::max(_smoothnessIndicator->timeRelaxation() * oldIndicator, _troubledCells[comp + cell * _nComp]);
499506
}
500507
//if (_OSmode == 1) // WENO
501508
//{
502-
// // todo: store reconstructed polynomial in h, calculate g from h and then set h = 2.0 / deltaZ * (-u * h + d_ax * (-2.0 / deltaZ) * g);
509+
// // todo: calculate and store reconstructed polynomial in h, calculate g from h and then set h = 2.0 / deltaZ * (-u * h + d_ax * (-2.0 / deltaZ) * g);
503510
//}
504511
}
505512

src/libcadet/model/parts/ConvectionDispersionOperatorDG.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace cadet
126126
inline unsigned int nNodes() const CADET_NOEXCEPT { return _nNodes; }
127127
inline unsigned int nPoints() const CADET_NOEXCEPT { return _nPoints; }
128128
inline bool exactInt() const CADET_NOEXCEPT { return _exactInt; }
129-
inline bool hasSmoothnessIndicator() const CADET_NOEXCEPT { return static_cast<bool>(_OSmode); } // only zero if no oscillation suppression
129+
inline bool hasSmoothnessIndicator() const CADET_NOEXCEPT { return _calc_smoothness_indicator; }
130130
inline double* smoothnessIndicator() const CADET_NOEXCEPT
131131
{
132132
if (hasSmoothnessIndicator())
@@ -194,9 +194,9 @@ namespace cadet
194194
double _maxBlending; //!< maximal blending coefficient of oscillation suppression mechanism
195195
double _blendingThreshold; //!< Threshold to clip-off blending coefficient
196196
WenoDG _weno; //!< WENO operator
197-
DGSubcellLimiterFV _subcellLimiter;
198-
std::unique_ptr<SmoothnessIndicator> _smoothnessIndicator;
199-
double* _troubledCells; //!< Troubled/oscillatory DG cell indicator
197+
DGSubcellLimiterFV _subcellLimiter; //!< FV subcell limiting operator
198+
std::unique_ptr<SmoothnessIndicator> _smoothnessIndicator; //!< smoothness/troubled-element indicator
199+
double* _troubledCells; //!< troubled-element indicator values
200200
bool _calc_smoothness_indicator; //!< Determines whether or not the smoothness indicator is evaluated
201201

202202
// Simulation parameters

0 commit comments

Comments
 (0)