Skip to content

Commit acc1f4f

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 fe11c3f commit acc1f4f

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
@@ -170,6 +170,10 @@ class ALPStrategy final : public ProcessStrategy<NumericType, D> {
170170
return ProcessResult::USER_INTERRUPTED;
171171
#endif
172172

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

180184
outputIntermediateResults(context, fluxes, pulseIteration);
181185

182-
time += coverageTimeStep;
186+
time += dt;
183187
pulseIteration++;
184188

185189
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)