public final class ModelPolynomial
extends java.lang.Object
Represent a polynomial model:
xModel{t} = c0 + c1*dt + c2*dt^2 + ...
where
Each ModelPolynomial
object needs to have an associated simulation
time, in order to define the model.
Add this simulation time by setting field this.tModel
to the
desired Time
object.
Failing to do so will cause a NullPointerException
for most of
the useful methods on this class.
Alternative designs that would enforce this condition include:
Time
object to the constructor.
This design was rejected because it implies that the model time is fixed,
and should not be changed during the lifetime of the model.Time
object, with a default
time, when constructing a ModelPoly
object.
This design was rejected because class Time
is meant
to be able to be swapped with other implementations, which may have
different constructor needs.This class is meant to provide a lightweight capability for working with and exchanging models. The majority of data are kept public, in order to facilitate changing model coefficients without the overhead of accessor (setter, getter) calls.
The design intention is that multiple objects in a system can share a
single ModelPolynomial
, in order to share a model of a common variable.
In principle, at any given simulation time, only one of those objects should
have "write access", and it alone should set the model parameters.
The other objects in the system can use the model, but should refrain from
changing it.
Note that the ModelPolynomial
object does nothing to enforce
cooperation among readers and writers.
It does, however, provide a simple counter for how many objects claim
write access.
This allows objects that intend to cooperate to double-check that they
are doing so correctly.
Modifier and Type | Field and Description |
---|---|
double[] |
coeffs
Polynomial coefficients, in order: [c0, c1, c2, ...].
|
Time |
tModel
Simulation time at which model was formed, such that xModel{tModel} = c0.
|
Constructor and Description |
---|
ModelPolynomial(int maxOrder)
Construct a
ModelPolynomial . |
Modifier and Type | Method and Description |
---|---|
int |
claimWriteAccess()
Claim write access.
|
double |
evaluate(double dt)
Evaluate the model at a delta-time.
|
double |
evaluate(Time simTime)
Evaluate the model at a simulation time.
|
double |
evaluateDerivative(double dt)
Evaluate d{model}/d{t} at a delta-time.
|
double |
evaluateDerivative(Time simTime)
Evaluate d{model}/d{t} at a simulation time.
|
double |
evaluateDerivative2(double dt)
Evaluate d^2{model}/d{t}^2 at a delta-time.
|
double |
evaluateDerivative2(Time simTime)
Evaluate d^2{model}/d{t}^2 at a simulation time.
|
int |
getMaximumOrder()
Get the maximum order of the polynomial.
|
int |
getWriterCount()
Find out how many objects claim write access.
|
int |
releaseWriteAccess()
Release claim of write access.
|
java.lang.String |
toString()
Return a string representation of the model.
|
public Time tModel
public final double[] coeffs
public ModelPolynomial(int maxOrder)
ModelPolynomial
.maxOrder
- Maximum order of the polynomial (0=constant, 1=line, etc).public final int claimWriteAccess()
public final double evaluate(Time simTime)
simTime
- Simulation time at which to evaluate the model.public final double evaluate(double dt)
dt
- Difference (simTime - tModel) at which to evaluate the model.public final double evaluateDerivative(Time simTime)
simTime
- Simulation time at which to evaluate the derivative.public final double evaluateDerivative(double dt)
dt
- Difference (simTime - tModel) at which to evaluate the derivative.public final double evaluateDerivative2(Time simTime)
simTime
- Simulation time at which to evaluate the derivative.public final double evaluateDerivative2(double dt)
dt
- Difference (simTime - tModel) at which to evaluate the derivative.public final int getMaximumOrder()
public final int getWriterCount()
public final int releaseWriteAccess()
public final java.lang.String toString()
toString
in class java.lang.Object