|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.algart.model3d.common.movement.model.AbstractMovementIntegrator
public abstract class AbstractMovementIntegrator extends java.lang.Object implements MovementIntegrator
A skeletal implementation of the MovementIntegrator interface to minimize
the effort required to implement this interface.
All non-abstract methods of this class, excepting performIteration(),
are completely implemented and usually should not be overridden.
Also this class offers protected methods
calculateLeftSide(double[], double[], double[], double[], double[], double[], double),calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
preprocess(),simplifying implementation of performIteration() method.
This class, by default, does not support estimation of the maximal and mean errors:
isErrorInformationAvailable() method returns false,
maxLastCoordinateError(), meanLastCoordinateError(),
maxLastVelocityError(), meanLastVelocityError() methods return Double.NaN.
But inheritors of this class can add this feature but overriding these methods.
AlgART Laboratory 2010
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.atomic.AtomicLong |
countOfCheckedNeighbours
The counter, returned by getCounterOfCheckedNeighbours() method. |
protected java.util.concurrent.atomic.AtomicLong |
countOfProcessedInteractions
The counter, returned by getCounterOfProcessedInteractions() method. |
protected java.util.concurrent.atomic.AtomicLong |
countOfProcessedItems
The counter, returned by getCounterOfProcessedItems() method. |
protected java.util.concurrent.atomic.AtomicLong |
countOfProcessedSymmetricInteractions
The counter, returned by getCounterOfProcessedSymmetricInteractions() method. |
protected int |
n
The current size of itemSet, calculated while the last
call of preprocess() method. |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMovementIntegrator(ItemSet itemSet,
java.util.Collection<InteractionRule> interactionRules,
double deltaT)
Creates new instance of this class. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
calculateLeftSide(double[] resultDX,
double[] resultDY,
double[] resultDZ,
double[] resultDVX,
double[] resultDVY,
double[] resultDVZ,
double deltaT)
Calculates the left sides of the motion equations, integrated by this object, multiplied by the passed deltaT=Δt argument. |
protected void |
calculateLeftSide(double[] resultDX,
double[] resultDY,
double[] resultDZ,
double[] resultDVX,
double[] resultDVY,
double[] resultDVZ,
double deltaT,
int threadIndex,
int fromIndex,
int toIndex)
An analog of the full calculateLeftSide(double[], double[], double[], double[], double[], double[], double) method,
which processes only the specified range of items. |
void |
copyBasicSettings(MovementIntegrator source)
Copies all basic settings, that can be accessed via getXxx/setXxx methods of this interface, from the specified object. |
double |
getAccelerationLimit()
Returns the acceleration limit Amax. |
long |
getCounterOfCheckedNeighbours()
Returns the internal thread-safe counter of "neighbour" item pairs,
which were checked by MovementIntegrator.performIteration() method
while calculation of the right side of the motion equations. |
long |
getCounterOfProcessedInteractions()
Returns the internal thread-safe counter of really interacted item pairs, which were really processed by MovementIntegrator.performIteration() method
while calculation of the right side of the motion equations,
that is for which calculateForce method was really called
and returned true. |
long |
getCounterOfProcessedItems()
Returns the internal thread-safe counter of items, which were processed by MovementIntegrator.performIteration() method
while calculation of the right side of the motion equations. |
long |
getCounterOfProcessedSymmetricInteractions()
An analog of the counter MovementIntegrator.getCounterOfProcessedInteractions(), counting only pairs,
which were processed in more efficient way thanks to
symmetric interaction rules. |
double |
getDeltaT()
Returns the time step Δt for one iteration of integration. |
java.util.List<InteractionRule> |
getInteractionRules()
Returns the list of interaction rules, used by this object. |
ItemSet |
getItemSet()
Returns the item set, processed by this object. |
int |
getNumberOfParallelTasks()
Returns the current number of parallel threads, which is recommended this object to use for optimizing calculations on multiprocessor systems. |
double |
getT()
Returns the current time t in the physical model. |
double |
getVelocityLimit()
Returns the velocity limit Vmax. |
boolean |
getViscousForces()
Returns true if this object works in the mode of viscous forces. |
boolean |
isErrorInformationAvailable()
Returns true if this implementation allows to estimate the maximal and mean error of calculating coordinates and velocities. |
double |
maxLastCoordinateError()
Returns the estimation of the maximal error of calculating coordinates while the previous MovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case. |
double |
maxLastVelocityError()
Returns the estimation of the maximal error of calculating velocities while the previous MovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case. |
double |
meanLastCoordinateError()
Returns the estimation of the average error of calculating coordinates while the previous MovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case. |
double |
meanLastVelocityError()
Returns the estimation of the average error of calculating velocities while the previous MovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case. |
abstract void |
performIteration()
Performs one iteration of integration. |
protected void |
preprocess()
Performs necessary preprocessing before an iteration, in particular, reallocate all necessary work memory. |
void |
resetCounters()
Resets to 0 all internal counters, returned by MovementIntegrator.getCounterOfProcessedItems(),
MovementIntegrator.getCounterOfCheckedNeighbours(), MovementIntegrator.getCounterOfProcessedInteractions()
and MovementIntegrator.getCounterOfProcessedSymmetricInteractions() methods. |
void |
setAccelerationLimit(double accelerationLimit)
Sets the acceleration limit Amax to the given value. |
void |
setDeltaT(double deltaT)
Sets the current time Δt for one iteration of integration. |
void |
setNumberOfParallelTasks(int numberOfParallelTasks)
Sets the number of parallel threads, which should be used, if possible, for optimizing calculations on multiprocessor systems. |
void |
setT(double t)
Sets the current time t in the physical model. |
void |
setVelocityLimit(double velocityLimit)
Sets the velocity limit Vmax to the given value. |
void |
setViscousForces(boolean viscousForces)
Sets the mode of viscous forces ("pseudo-Newton's" motion equations), if the argument is true, or the usual mode (standard Newton's laws), if the argument is false See comments to this interface for more details. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final java.util.concurrent.atomic.AtomicLong countOfProcessedItems
getCounterOfProcessedItems() method.
This counter is increased by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method.
protected final java.util.concurrent.atomic.AtomicLong countOfCheckedNeighbours
getCounterOfCheckedNeighbours() method.
This counter is increased by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method.
protected final java.util.concurrent.atomic.AtomicLong countOfProcessedInteractions
getCounterOfProcessedInteractions() method.
This counter is increased by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method.
protected final java.util.concurrent.atomic.AtomicLong countOfProcessedSymmetricInteractions
getCounterOfProcessedSymmetricInteractions() method.
This counter is increased by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method.
protected int n
size of itemSet, calculated while the last
call of preprocess() method.
After creating the object, this field contains 0.
| Constructor Detail |
|---|
protected AbstractMovementIntegrator(ItemSet itemSet,
java.util.Collection<InteractionRule> interactionRules,
double deltaT)
The itemSet argument is just stored in an internal field, and this reference
will be returned by getItemSet() method.
Unlike this, the interactionRules collection is copied into a newly created list:
no references to it are maintained by the created object.
itemSet - the item set, which will be processed by this class.interactionRules - the list of interaction rules, used by this class.deltaT - the time step Δt.java.lang.NullPointerException - if one of the arguments is null or
if one of interaction rules in the passed collection is null.java.lang.IllegalArgumentException - if deltaT<0.| Method Detail |
|---|
public ItemSet getItemSet()
MovementIntegratorItemSet interface.
getItemSet in interface MovementIntegratorItemSet object, processed by this object.public java.util.List<InteractionRule> getInteractionRules()
MovementIntegratorThe result is an immutable view (Collections.unmodifiableList) or a clone of the internal collection, stored by this object: you cannot modify the set of used interaction rules via the result of this method.
The elements of the returned list are never null.
getInteractionRules in interface MovementIntegratorpublic int getNumberOfParallelTasks()
MovementIntegratorThe returned value is always positive (>0).
getNumberOfParallelTasks in interface MovementIntegratorpublic void setNumberOfParallelTasks(int numberOfParallelTasks)
MovementIntegratorIf this argument is 0, it is automatically replaced with
MovementIntegrator.getNumberOfParallelTasks() method will return not 0,
but the actual number of available processors.
setNumberOfParallelTasks in interface MovementIntegratornumberOfParallelTasks - the desired number of parallel threads for multiprocessor optimization.public boolean getViscousForces()
MovementIntegratorcomments to this interface for more details.
getViscousForces in interface MovementIntegratorpublic void setViscousForces(boolean viscousForces)
MovementIntegratorcomments to this interface for more details.
setViscousForces in interface MovementIntegratorviscousForces - whether you this object should be switched in the mode of viscous forces.public double getAccelerationLimit()
MovementIntegratorcomments to this interface for more details.
getAccelerationLimit in interface MovementIntegratorpublic void setAccelerationLimit(double accelerationLimit)
MovementIntegratorcomments to this interface for more details.
setAccelerationLimit in interface MovementIntegratoraccelerationLimit - new acceleration limit Amax.public double getVelocityLimit()
MovementIntegratorcomments to this interface for more details.
getVelocityLimit in interface MovementIntegratorpublic void setVelocityLimit(double velocityLimit)
MovementIntegratorcomments to this interface for more details.
setVelocityLimit in interface MovementIntegratorvelocityLimit - new velocity limit Vmax.public double getT()
MovementIntegratorMovementIntegrator.performIteration() method.
getT in interface MovementIntegratorMovementIntegrator.getDeltaT()public void setT(double t)
MovementIntegrator
setT in interface MovementIntegratort - new value of the current time t.public double getDeltaT()
MovementIntegrator
getDeltaT in interface MovementIntegratorpublic void setDeltaT(double deltaT)
MovementIntegrator
setDeltaT in interface MovementIntegratordeltaT - new value of the time step Δt.public void copyBasicSettings(MovementIntegrator source)
MovementIntegratorsetNumberOfParallelTasks(source.getNumberOfParallelTasks());setViscousForces(source.getViscousForces());setAccelerationLimit(source.getAccelerationLimit());setVelocityLimit(source.getVelocityLimit());setT(source.getT());setDeltaT(source.getDeltaT());
copyBasicSettings in interface MovementIntegratorsource - another movement integrator, the basic settings of which should be copied into this one.public long getCounterOfProcessedItems()
MovementIntegratorMovementIntegrator.performIteration() method
while calculation of the right side of the motion equations.
Note that MovementIntegrator.performIteration() can calculate the right side of the equations several times
(as in Runge-Kutta algorithms), and then every item will be also counted several times.
Usually the items, which do not have coordinates of centers and velocities
or do not have masses, are not counted.
This counter is 0 after creating new instance of this class
and can be set to 0 by MovementIntegrator.resetCounters() method.
This method is provided for profiling and debugging needs only. It works as described above in the implementations, offered by this package, but there is no guarantee that it will return correct values in all implementations. If the implementation does not provide this counter, this method should return 0 always.
getCounterOfProcessedItems in interface MovementIntegratorpublic long getCounterOfCheckedNeighbours()
MovementIntegrator"neighbour" item pairs,
which were checked by MovementIntegrator.performIteration() method
while calculation of the right side of the motion equations.
This number depends on the implementation of ItemSet interface:
good implementations, like GridItemSet, allow to check only restricted number of items
while finding all "neighbours" of the given item, which can interact with it.
Note that the "neighbour" pair is counted independently for both its elements. In other words, it two items act to each other, their pair is counter twice.
Note that MovementIntegrator.performIteration() can calculate the right side of the equations several times
(as in Runge-Kutta algorithms), and then every neighbour item pair will be also counted several times.
This counter is 0 after creating new instance of this class
and can be set to 0 by MovementIntegrator.resetCounters() method.
This method is provided for profiling and debugging needs only. It works as described above in the implementations, offered by this package, but there is no guarantee that it will return correct values in all implementations. If the implementation does not provide this counter, this method should return 0 always.
getCounterOfCheckedNeighbours in interface MovementIntegratorpublic long getCounterOfProcessedInteractions()
MovementIntegratorMovementIntegrator.performIteration() method
while calculation of the right side of the motion equations,
that is for which calculateForce method was really called
and returned true.
Note that an interacted pair is counted independently for both items. In other words, it two items act to each other, their pair is counter twice.
Note that an interacted pair is counted again for every interaction rule, applicable for this pair.
So, if there are K>1 rules, in which calculateForce method
returned true for the given pair, then this pair will be counted K times.
Note that MovementIntegrator.performIteration() can calculate the right side of the equations several times
(as in Runge-Kutta algorithms), and then every neighbour item pair will be also counted several times.
This counter is 0 after creating new instance of this class
and can be set to 0 by MovementIntegrator.resetCounters() method.
This method is provided for profiling and debugging needs only. It works as described above in the implementations, offered by this package, but there is no guarantee that it will return correct values in all implementations. If the implementation does not provide this counter, this method should return 0 always.
getCounterOfProcessedInteractions in interface MovementIntegratorpublic long getCounterOfProcessedSymmetricInteractions()
MovementIntegratorMovementIntegrator.getCounterOfProcessedInteractions(), counting only pairs,
which were processed in more efficient way thanks to
symmetric interaction rules.
Namely, some implementations of this interface can use the fact, that some interaction is symmetric
(implements SymmetricInteractionRule), and calculate the interaction force only once.
The force F' of acting of the 2nd item to the 1st one is produced from
the force F of acting of the 1st item to the 2nd one by changing the sign:
MovementIntegrator.getCounterOfProcessedInteractions() method.
But some "neighbour" item pairs cannot be processed in such a manner, for example,
when the first item is processed (moved) by one processor in multiprocessor system
and the second one is processed by another processor.
In such situation, this counter is not increased, though the counter,
returned by MovementIntegrator.getCounterOfProcessedInteractions() method, is increased by 2
(by 1 for each from two items). So, this method can help to measure optimization,
achieved thanks to usage of symmetric interaction rules.
This counter is 0 after creating new instance of this class
and can be set to 0 by MovementIntegrator.resetCounters() method.
This method is provided for profiling and debugging needs only. It works as described above in the implementations, offered by this package, but there is no guarantee that it will return correct values in all implementations. If the implementation does not provide this counter, this method should return 0 always.
getCounterOfProcessedSymmetricInteractions in interface MovementIntegratorsymmetric interaction rules.public void resetCounters()
MovementIntegratorMovementIntegrator.getCounterOfProcessedItems(),
MovementIntegrator.getCounterOfCheckedNeighbours(), MovementIntegrator.getCounterOfProcessedInteractions()
and MovementIntegrator.getCounterOfProcessedSymmetricInteractions() methods.
resetCounters in interface MovementIntegratorpublic abstract void performIteration()
MovementIntegratorhaving centers and velocities and having masses,
according to the motion equations.
See comments to this interface for more details.
performIteration in interface MovementIntegratorpublic boolean isErrorInformationAvailable()
MovementIntegratorMovementIntegrator.maxLastCoordinateError(), MovementIntegrator.meanLastCoordinateError(),
MovementIntegrator.maxLastVelocityError(), MovementIntegrator.meanLastVelocityError() methods after
every MovementIntegrator.performIteration() call to get this information.
In other case, those methods return Double.NaN.
isErrorInformationAvailable in interface MovementIntegratorpublic double maxLastCoordinateError()
MovementIntegratorMovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case.
maxLastCoordinateError in interface MovementIntegratorpublic double maxLastVelocityError()
MovementIntegratorMovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case.
maxLastVelocityError in interface MovementIntegratorpublic double meanLastCoordinateError()
MovementIntegratorMovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case.
meanLastCoordinateError in interface MovementIntegratorpublic double meanLastVelocityError()
MovementIntegratorMovementIntegrator.performIteration() call, if this implementation
supports this feature,
or Double.NaN in other case.
meanLastVelocityError in interface MovementIntegrator
protected void calculateLeftSide(double[] resultDX,
double[] resultDY,
double[] resultDZ,
double[] resultDVX,
double[] resultDVY,
double[] resultDVZ,
double deltaT)
Δt dw/dt = Δt f(t, w)
— see the concrete equation sets in comments to MovementIntegrator interface.
The left sides of the equations (multiplied by Δt) are stored in the passed Java arrays resultDX, resultDY, resultDZ, resultDVX, resultDVY, resultDVZ: the element #k of these arrays will contain, correspondingly, the values
Δt * dxk/dt,
Δt * dyk/dt,
Δt * dzk/dt,
Δt * dvxk/dt,
Δt * dvyk/dt,
Δt * dvzk/dt.
— the derivatives of coordinates and velocity components for the item
itemSet.get(k).
If the item #k does not implement both HavingVelocity and HavingMass interface,
the corresponding elements of the passed array are filled by zero (0.0).
This method uses multithreading for optimizing calculations on multiprocessor system,
it the desired number of parallel task is set to a value m >1 by
setNumberOfParallelTasks(int) method. Namely, this method
splits the item set into m ranges and calculates the derivatives for them
in m parallel threads. Each range (or all item set in a case m=1)
is processed by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method, which really performs all necessary calculations.
Note: this method does not use the current Δt, returned by getDeltaT() method,
but uses the deltaT argument instead.
Note: this method uses some work memory, which must be allocated and correctly initialized by
preprocess() method before calling this method. After preprocess() call,
the item set should not be changed in any way, in other case this method will work incorrectly
and even can throw an exception.
resultDX - array for storing dxk/dt * Δt values.resultDY - array for storing dyk/dt * Δt values.resultDZ - array for storing dzk/dt * Δt values.resultDVX - array for storing dvxk/dt * Δt values.resultDVY - array for storing dvyk/dt * Δt values.resultDVZ - array for storing dvzk/dt * Δt values.deltaT - Δt value.java.lang.NullPointerException - if one of passed arrays is null.java.lang.IllegalArgumentException - if deltaT argument is negative (< 0.0).
protected void calculateLeftSide(double[] resultDX,
double[] resultDY,
double[] resultDZ,
double[] resultDVX,
double[] resultDVY,
double[] resultDVZ,
double deltaT,
int threadIndex,
int fromIndex,
int toIndex)
calculateLeftSide(double[], double[], double[], double[], double[], double[], double) method,
which processes only the specified range of items.
The range is specified by fromIndex and toIndex argument:
if fills only the elements of resultDX, resultDY, resultDZ,
resultDVX, resultDVY, resultDVZ arrays with indexes
fromIndex<=k<toIndex.
The argument threadIndex, from 0 to getNumberOfParallelTasks()-1,
specifies the index of the thread, which is executing this method,
and is used for choosing a separate work memory for every thread while parallel execution.
While single-thread execution, this argument should be 0.
This method is usually called from
calculateLeftSide(double[], double[], double[], double[], double[], double[], double) method only.
resultDX - array for storing dxk/dt * Δt values.resultDY - array for storing dyk/dt * Δt values.resultDZ - array for storing dzk/dt * Δt values.resultDVX - array for storing dvxk/dt * Δt values.resultDVY - array for storing dvyk/dt * Δt values.resultDVZ - array for storing dvzk/dt * Δt values.deltaT - Δt value.threadIndex - the index of thread, which calls this method.fromIndex - start index of processed items, inclusive.toIndex - end index of processed items, exclusive.java.lang.NullPointerException - if one of passed arrays is null.java.lang.IllegalArgumentException - if deltaT argument is negative (< 0.0).java.lang.IndexOutOfBoundsException - for illegal fromIndex and toIndex
(fromIndex < 0 || toIndex > n
|| fromIndex > toIndex),
or if threadIndex is out of
0..getNumberOfParallelTasks()-1 range.protected void preprocess()
performIteration() method
and before any call of
calculateLeftSide(double[], double[], double[], double[], double[], double[], double) or
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
methods, if the item set was corrected in any way after the last call of this method.
This implementation reallocates a temporary memory, used by
calculateLeftSide(double[], double[], double[], double[], double[], double[], double, int, int, int)
method, and calls itemSet.preprocess().
Please don't forget to call it from all overriding implementations.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||