Skip to content

Commit ed84ffc

Browse files
fix: use clamped timestep in ALP last-pulse iteration
Clamp dt = min(coverageTimeStep, pulseTime - time) and push it to the surface model via a new setTimeStep hook to non-const dt_ so the final iteration integrates over the actual remaining pulse time instead of overshooting with the full coverageTimeStep.
1 parent 9094763 commit ed84ffc

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

include/viennaps/models/psSingleParticleALD.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ template <typename NumericType>
1212
class SingleParticleALDSurfaceModel : public SurfaceModel<NumericType> {
1313
using SurfaceModel<NumericType>::coverages;
1414

15-
const NumericType dt_;
15+
NumericType dt_;
1616
const NumericType gpc_;
1717
const NumericType s0_;
1818

@@ -37,6 +37,8 @@ class SingleParticleALDSurfaceModel : public SurfaceModel<NumericType> {
3737
coverages->insertNextScalarData(cov, "Coverage");
3838
}
3939

40+
void setTimeStep(NumericType dt) override { dt_ = dt; }
41+
4042
SmartPointer<std::vector<NumericType>>
4143
calculateVelocities(SmartPointer<viennals::PointData<NumericType>> rates,
4244
const std::vector<Vec3D<NumericType>> &coordinates,

include/viennaps/process/psALPStrategy.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ class ALPStrategy final : public ProcessStrategy<NumericType, D> {
171171
return ProcessResult::USER_INTERRUPTED;
172172
#endif
173173

174+
// Clamp last step to land exactly on pulseTime
175+
double dt = std::min(coverageTimeStep, pulseTime - time);
176+
context.model->getSurfaceModel()->setTimeStep(dt);
177+
174178
// Calculate fluxes
175179
auto fluxes = SmartPointer<viennals::PointData<NumericType>>::New();
176180
PROCESS_CHECK(fluxEngine_->calculateFluxes(context, fluxes));
@@ -180,7 +184,7 @@ class ALPStrategy final : public ProcessStrategy<NumericType, D> {
180184

181185
outputIntermediateResults(context, fluxes, pulseIteration);
182186

183-
time += coverageTimeStep;
187+
time += dt;
184188
pulseIteration++;
185189

186190
if (Logger::hasInfo()) {

include/viennaps/process/psSurfaceModel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ template <typename NumericType> class SurfaceModel {
3232
// if no surface data get initialized here, they won't be used at all
3333
}
3434

35+
virtual void setTimeStep(NumericType dt) {}
36+
3537
virtual SmartPointer<std::vector<NumericType>>
3638
calculateVelocities(SmartPointer<viennals::PointData<NumericType>> fluxes,
3739
const std::vector<Vec3D<NumericType>> &coordinates,

0 commit comments

Comments
 (0)