public class MatrixStateElementConverter extends PropagationStateElementConverter
PropagationStateElement
corresponding
to a set of Matrix
values back and forth
between its raw indexed state, and a Motion<Matrix>
.Modifier | Constructor and Description |
---|---|
protected |
MatrixStateElementConverter(MatrixStateElementConverter existingInstance,
CopyContext context)
Initializes a new instance as a copy of an existing instance.
|
|
MatrixStateElementConverter(String identification,
Motion1<int[]> stateIndices,
Motion1<Matrix> initialState)
Initializes a new instance.
|
|
MatrixStateElementConverter(String identification,
Motion1<int[]> stateIndices,
Motion1<Matrix> initialState,
Motion1<Matrix> weights)
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
adjustStateFromElement(double[] overallRawState,
Motion1<double[]> stateElementValues)
Adjust the subset of the overall raw state corresponding to this element to new values.
|
<T> boolean |
adjustStateWithType(double[] overallRawState,
Motion1<T> newStateElement)
Adjust the subset of the raw state corresponding to this element to new values.
|
Object |
clone(CopyContext context)
Clones this object using the specified context.
|
Motion1<Matrix> |
convertState(double[] overallState)
Convert the raw state into a
Matrix
and its derivatives. |
int |
getDimension()
Gets the number of parameters (per
Order (get )) within this element. |
Motion1<double[]> |
getElementFromState(double[] overallState)
Produces this state element's values and their derivatives from the overall raw state.
|
Class<?> |
getTypeOfOutput()
Gets the type associated with the output of this instance.
|
getAdaptiveWeights, getIdentification, getInitialState, getIsThreadSafe, getOrder, getStateIndices, setAdaptiveWeights
public MatrixStateElementConverter(String identification, @Nonnull Motion1<int[]> stateIndices, @Nonnull Motion1<Matrix> initialState)
identification
- A string identifying this instance in the overall output.stateIndices
- The indices of the individual values and their derivatives in the overall state.initialState
- The values of the state at the epoch of the overall NumericalPropagatorDefinition
.public MatrixStateElementConverter(String identification, @Nonnull Motion1<int[]> stateIndices, @Nonnull Motion1<Matrix> initialState, @Nonnull Motion1<Matrix> weights)
identification
- A string identifying this instance in the overall output.stateIndices
- The indices of the individual values and their derivatives in the overall state.initialState
- The values of the state at the epoch of the overall NumericalPropagatorDefinition
.weights
- A set of weights associated with each value in the state to use when performing adaptive
step control with an AdaptiveNumericalIntegrator
.protected MatrixStateElementConverter(@Nonnull MatrixStateElementConverter existingInstance, @Nonnull CopyContext context)
See ICloneWithContext.clone(CopyContext)
for more information about how to implement this constructor
in a derived class.
existingInstance
- The existing instance to copy.context
- A CopyContext
that controls the depth of the copy.ArgumentNullException
- Thrown when existingInstance
or context
is null
.public Object clone(CopyContext context)
This method should be implemented to call a copy constructor on the class of the
object being cloned. The copy constructor should take the CopyContext
as a parameter
in addition to the existing instance to copy. The copy constructor should first call
CopyContext.addObjectMapping(T, T)
to identify the newly constructed instance
as a copy of the existing instance. It should then copy all fields, using
CopyContext.updateReference(T)
to copy any reference fields.
A typical implementation of ICloneWithContext
:
public static class MyClass implements ICloneWithContext {
public MyClass(MyClass existingInstance, CopyContext context) {
context.addObjectMapping(existingInstance, this);
someReference = context.updateReference(existingInstance.someReference);
}
@Override
public final Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
}
In general, all fields that are reference types should be copied with a call to
CopyContext.updateReference(T)
. There are a couple of exceptions:
If one of these exceptions applies, the CopyContext
should be given an opportunity
to update the reference before the reference is copied explicitly. Use
CopyContext.updateReference(T)
to update the reference. If CopyContext.updateReference(T)
returns
the original object, indicating that the context does not have a replacement registered,
then copy the object manually by invoking a Clone method, a copy constructor, or by manually
constructing a new instance and copying the values.
alwaysCopy = context.updateReference(existingInstance.alwaysCopy);
if (existingInstance.alwaysCopy != null && alwaysCopy == existingInstance.alwaysCopy) {
alwaysCopy = (AlwaysCopy) existingInstance.alwaysCopy.clone(context);
}
If you are implementing an evaluator (a class that implements IEvaluator
), the
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
method shares some responsibilities with the
copy context constructor. Code duplication can be avoided by doing the following:
CopyContext.updateReference(T)
. You should still call CopyContext.updateReference(T)
on any references to
non-evaluators.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as the last line in the constructor and pass it the
same CopyContext
passed to the constructor.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as normal. See the reference documentation for
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
for more information on implementing that method.
public MyClass(MyClass existingInstance, CopyContext context) {
super(existingInstance, context);
someReference = context.updateReference(existingInstance.someReference);
evaluatorReference = existingInstance.evaluatorReference;
updateEvaluatorReferences(context);
}
@Override
public void updateEvaluatorReferences(CopyContext context) {
evaluatorReference = context.updateReference(evaluatorReference);
}
@Override
public Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
private IEvaluator evaluatorReference;
clone
in interface ICloneWithContext
clone
in class PropagationStateElementConverter
context
- The context to use to perform the copy.public int getDimension()
Order
(get
)) within this element.getDimension
in class PropagationStateElementConverter
public Class<?> getTypeOfOutput()
getTypeOfOutput
in class PropagationStateElementConverter
@Nonnull public final Motion1<Matrix> convertState(double[] overallState)
Matrix
and its derivatives.convertState
in class PropagationStateElementConverter
overallState
- The raw state to convert.@Nonnull public Motion1<double[]> getElementFromState(double[] overallState)
getElementFromState
in class PropagationStateElementConverter
overallState
- The overall raw state from which to produce this element's array.Dimension
(get
) in
a motion of this element's Order
(get
) minus one.public <T> boolean adjustStateWithType(double[] overallRawState, @Nonnull Motion1<T> newStateElement)
adjustStateWithType
in class PropagationStateElementConverter
T
- The type corresponding to the TypeOfOutput
(get
) of
this element.overallRawState
- The overall raw state to adjust.newStateElement
- The new values and derivatives for the requested element.IllegalStateException
- Thrown if the newStateElement
are not an instance of Motion<Cartesian>
.public boolean adjustStateFromElement(double[] overallRawState, @Nonnull Motion1<double[]> stateElementValues)
adjustStateFromElement
in class PropagationStateElementConverter
overallRawState
- The overall raw state to adjust.stateElementValues
- The new values and derivatives for the requested element
represented as an array. To obtain an instance of this array, call MatrixStateElementConverter.getElementFromState(double[])
.