Commit 86955c82 authored by Mathieu Westphal's avatar Mathieu Westphal
Browse files

Adding a UserData parameter to vtkInitialValueProblemSolver::ComputeNextStep

This adds a new UserData parameter, that can be used to transfer any kind of pointer
parent 9b2d712c
......@@ -68,35 +68,67 @@ public:
virtual int ComputeNextStep(double* xprev, double* xnext, double t,
double& delT, double maxError,
double& error)
{
return this->ComputeNextStep(xprev, xnext, t, delT, maxError, error, nullptr);
}
virtual int ComputeNextStep(double* xprev, double* xnext, double t,
double& delT, double maxError,
double& error, void* userData)
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
virtual int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double maxError,
double& error)
{
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, maxError, error, nullptr);
}
virtual int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double maxError,
double& error, void* userData)
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
virtual int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error)
{
return this->ComputeNextStep(xprev, xnext, t, delT, delTActual, minStep, maxStep, maxError, error, nullptr);
}
virtual int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error, void* userData)
{
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
virtual int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) = 0;
double maxError, double& error)
{
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, delTActual, minStep, maxStep, maxError, error, nullptr);
}
virtual int ComputeNextStep(double* vtkNotUsed(xprev), double* vtkNotUsed(dxprev), double* vtkNotUsed(xnext),
double vtkNotUsed(t), double& vtkNotUsed(delT), double& vtkNotUsed(delTActual),
double vtkNotUsed(minStep), double vtkNotUsed(maxStep),
double vtkNotUsed(maxError), double& vtkNotUsed(error), void* vtkNotUsed(userData)) { return 0; }
//@}
//@{
......@@ -139,7 +171,3 @@ private:
};
#endif
......@@ -26,7 +26,7 @@ vtkRungeKutta2::~vtkRungeKutta2() = default;
// Calculate next time step
int vtkRungeKutta2::ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double, double, double, double& error)
double, double, double, double& error, void* userData)
{
int i, numDerivs, numVals;
......@@ -61,7 +61,7 @@ int vtkRungeKutta2::ComputeNextStep(double* xprev, double* dxprev, double* xnext
this->Derivs[i] = dxprev[i];
}
}
else if ( !this->FunctionSet->FunctionValues(this->Vals, this->Derivs) )
else if (!this->FunctionSet->FunctionValues(this->Vals, this->Derivs))
{
memcpy(xnext, this->Vals, (numVals-1)*sizeof(double));
return OUT_OF_DOMAIN;
......
......@@ -42,6 +42,7 @@ public:
*/
static vtkRungeKutta2 *New();
using Superclass::ComputeNextStep;
//@{
/**
* Given initial values, xprev , initial time, t and a requested time
......@@ -58,36 +59,36 @@ public:
*/
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override;
double maxError, double& error, void* userData) override;
//@}
protected:
......@@ -100,11 +101,4 @@ private:
#endif
// VTK-HeaderTest-Exclude: vtkRungeKutta2.h
......@@ -60,7 +60,7 @@ void vtkRungeKutta4::Initialize()
// (Addison Wesley)
int vtkRungeKutta4::ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double, double, double, double& error)
double, double, double, double& error, void* userData)
{
int i, numDerivs, numVals;
......@@ -97,7 +97,7 @@ int vtkRungeKutta4::ComputeNextStep(double* xprev, double* dxprev, double* xnext
this->Derivs[i] = dxprev[i];
}
}
else if ( !this->FunctionSet->FunctionValues(this->Vals, this->Derivs) )
else if (!this->FunctionSet->FunctionValues(this->Vals, this->Derivs))
{
memcpy(xnext, this->Vals, (numVals-1)*sizeof(double));
return OUT_OF_DOMAIN;
......
......@@ -43,7 +43,7 @@ public:
*/
static vtkRungeKutta4 *New();
using Superclass::ComputeNextStep;
//@{
/**
* Given initial values, xprev , initial time, t and a requested time
......@@ -60,36 +60,36 @@ public:
*/
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override;
double maxError, double& error, void* userData) override;
//@}
protected:
......@@ -105,11 +105,3 @@ private:
};
#endif
......@@ -91,7 +91,7 @@ int vtkRungeKutta45::ComputeNextStep(double* xprev, double* dxprev,
double* xnext, double t, double& delT,
double& delTActual,
double minStep, double maxStep,
double maxError, double& estErr )
double maxError, double& estErr, void* userData)
{
estErr = VTK_DOUBLE_MAX;
......@@ -112,7 +112,7 @@ int vtkRungeKutta45::ComputeNextStep(double* xprev, double* dxprev,
if ( ((minStep == absDT) && (maxStep == absDT)) ||
(maxError <= 0.0) )
{
int retVal = this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr);
int retVal = this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr, userData);
return retVal;
}
else if ( minStep > maxStep )
......@@ -127,7 +127,7 @@ int vtkRungeKutta45::ComputeNextStep(double* xprev, double* dxprev,
while ( estErr > maxError )
{
if ((retVal =
this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr)))
this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr, userData)))
{
return retVal;
}
......@@ -189,7 +189,7 @@ int vtkRungeKutta45::ComputeNextStep(double* xprev, double* dxprev,
if (shouldBreak)
{
if ( (retVal =
this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr)) )
this->ComputeAStep(xprev, dxprev, xnext, t, delT, delTActual, estErr, userData)) )
{
return retVal;
}
......@@ -204,7 +204,7 @@ int vtkRungeKutta45::ComputeNextStep(double* xprev, double* dxprev,
// Calculate next time step
int vtkRungeKutta45::ComputeAStep(
double* xprev, double* dxprev, double* xnext, double t, double& delT,
double& actualDelT, double& error)
double& actualDelT, double& error, void* userData)
{
int i, j, k, numDerivs, numVals;
......@@ -239,8 +239,7 @@ int vtkRungeKutta45::ComputeAStep(
this->NextDerivs[0][i] = dxprev[i];
}
}
else if ( !this->FunctionSet->FunctionValues(this->Vals,
this->NextDerivs[0]) )
else if (!this->FunctionSet->FunctionValues(this->Vals, this->NextDerivs[0]))
{
for(i=0; i<numVals-1; i++)
{
......@@ -265,8 +264,7 @@ int vtkRungeKutta45::ComputeAStep(
}
this->Vals[numVals-1] = t + delT*A[i-1];
if ( !this->FunctionSet->FunctionValues(this->Vals,
this->NextDerivs[i]) )
if (!this->FunctionSet->FunctionValues(this->Vals, this->NextDerivs[i]))
{
for(int l = 0; l < numVals - 1; l++)
{
......
......@@ -49,6 +49,7 @@ public:
*/
static vtkRungeKutta45 *New();
using Superclass::ComputeNextStep;
//@{
/**
* Given initial values, xprev , initial time, t and a requested time
......@@ -74,36 +75,36 @@ public:
*/
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
double minStep = delT;
double maxStep = delT;
double delTActual;
return this->ComputeNextStep(xprev, dxprev, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override
double maxError, double& error, void* userData) override
{
return this->ComputeNextStep(xprev, nullptr, xnext, t, delT, delTActual,
minStep, maxStep, maxError, error);
minStep, maxStep, maxError, error, userData);
}
int ComputeNextStep(double* xprev, double* dxprev, double* xnext,
double t, double& delT, double& delTActual,
double minStep, double maxStep,
double maxError, double& error) override;
double maxError, double& error, void* userData) override;
//@}
protected:
......@@ -121,7 +122,7 @@ protected:
double* NextDerivs[6];
int ComputeAStep(double* xprev, double* dxprev, double* xnext, double t,
double& delT, double& delTActual, double& error);
double& delT, double& delTActual, double& error, void* userData);
private:
vtkRungeKutta45(const vtkRungeKutta45&) = delete;
......
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