Commit 2d0d7ad3 authored by Véronique Pommier-Maurussane's avatar Véronique Pommier-Maurussane
Browse files

corrections according to checkstyle and findbugs reports

parent 28061d05
......@@ -458,35 +458,35 @@ public class BoxAndSolarArraySpacecraft implements RadiationSensitive, DragSensi
}
/** {@inheritDoc} */
public void setAbsorptionCoefficient(double value) {
absorptionCoeff = value;
public void setAbsorptionCoefficient(final double value) {
absorptionCoeff = value;
diffuseReflectionCoeff = 1 - (absorptionCoeff + specularReflectionCoeff);
}
}
/** {@inheritDoc} */
public double getAbsorptionCoefficient() {
return absorptionCoeff;
}
public double getAbsorptionCoefficient() {
return absorptionCoeff;
}
/** {@inheritDoc} */
public void setReflectionCoefficient(double value) {
specularReflectionCoeff = value;
public void setReflectionCoefficient(final double value) {
specularReflectionCoeff = value;
diffuseReflectionCoeff = 1 - (absorptionCoeff + specularReflectionCoeff);
}
}
/** {@inheritDoc} */
public double getReflectionCoefficient() {
return specularReflectionCoeff;
}
public double getReflectionCoefficient() {
return specularReflectionCoeff;
}
/** {@inheritDoc} */
public void setDragCoefficient(double value) {
dragCoeff = value;
}
public void setDragCoefficient(final double value) {
dragCoeff = value;
}
/** {@inheritDoc} */
public double getDragCoefficient() {
return dragCoeff;
}
public double getDragCoefficient() {
return dragCoeff;
}
}
/* Copyright 2002-2010 CS Communication & Systèmes
* Licensed to CS Communication & Systèmes (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.forces;
import java.util.Collection;
......
......@@ -73,7 +73,7 @@ public class SphericalSpacecraft implements RadiationSensitive, DragSensitive {
this.dragCoeff = dragCoeff;
this.absorptionCoeff = absorptionCoeff;
this.specularReflectionCoeff = reflectionCoeff;
this.setKD();
this.setKP();
}
......@@ -90,46 +90,46 @@ public class SphericalSpacecraft implements RadiationSensitive, DragSensitive {
}
/** {@inheritDoc} */
public void setDragCoefficient(double value) {
dragCoeff = value;
this.setKD();
}
public void setDragCoefficient(final double value) {
dragCoeff = value;
this.setKD();
}
/** {@inheritDoc} */
public double getDragCoefficient() {
return dragCoeff;
}
public double getDragCoefficient() {
return dragCoeff;
}
/** {@inheritDoc} */
public void setAbsorptionCoefficient(double value) {
absorptionCoeff = value;
this.setKP();
}
public void setAbsorptionCoefficient(final double value) {
absorptionCoeff = value;
this.setKP();
}
/** {@inheritDoc} */
public double getAbsorptionCoefficient() {
return absorptionCoeff;
}
public double getAbsorptionCoefficient() {
return absorptionCoeff;
}
/** {@inheritDoc} */
public void setReflectionCoefficient(double value) {
specularReflectionCoeff = value;
this.setKP();
}
public void setReflectionCoefficient(final double value) {
specularReflectionCoeff = value;
this.setKP();
}
/** {@inheritDoc} */
public double getReflectionCoefficient() {
return specularReflectionCoeff;
}
public double getReflectionCoefficient() {
return specularReflectionCoeff;
}
/** Set kD value */
private void setKD() {
/** Set kD value. */
private void setKD() {
kD = dragCoeff * crossSection / 2;
}
}
/** Set kP value */
private void setKP() {
/** Set kP value. */
private void setKP() {
kP = crossSection * (1 + 4 * (1.0 - absorptionCoeff) * (1.0 - specularReflectionCoeff) / 9);
}
}
}
......@@ -53,12 +53,15 @@ public class DragForce implements ForceModelWithJacobians {
/** Serializable UID. */
private static final long serialVersionUID = 2574653656986559955L;
/** Error message for unknown parameter. */
private static final String UNKNOWN_PARAMETER_MESSAGE = "unknown parameter {0}";
/** Atmospheric model. */
private final Atmosphere atmosphere;
/** Spacecraft. */
private final DragSensitive spacecraft;
/** List of the parameters names. */
private final ArrayList<String> parametersNames = new ArrayList<String>();
......@@ -102,31 +105,32 @@ public class DragForce implements ForceModelWithJacobians {
}
/** {@inheritDoc} */
public void addContributionWithJacobians(SpacecraftState s,
TimeDerivativesEquationsWithJacobians adder) throws OrekitException {
}
public void addContributionWithJacobians(final SpacecraftState s,
final TimeDerivativesEquationsWithJacobians adder)
throws OrekitException {
}
/** {@inheritDoc} */
public Collection<String> getParametersNames() {
return parametersNames;
}
public Collection<String> getParametersNames() {
return parametersNames;
}
/** {@inheritDoc} */
public double getParameter(String name) throws IllegalArgumentException {
if (name.matches(DRAG_COEFFICIENT)) {
return spacecraft.getDragCoefficient();
} else {
throw OrekitException.createIllegalArgumentException("unknown parameter {0}", name);
}
}
public double getParameter(final String name) throws IllegalArgumentException {
if (name.matches(DRAG_COEFFICIENT)) {
return spacecraft.getDragCoefficient();
} else {
throw OrekitException.createIllegalArgumentException(UNKNOWN_PARAMETER_MESSAGE, name);
}
}
/** {@inheritDoc} */
public void setParameter(String name, double value) throws IllegalArgumentException {
if (name.matches(DRAG_COEFFICIENT)) {
spacecraft.setDragCoefficient(value);
} else {
throw OrekitException.createIllegalArgumentException("unknown parameter {0}", name);
}
public void setParameter(final String name, final double value) throws IllegalArgumentException {
if (name.matches(DRAG_COEFFICIENT)) {
spacecraft.setDragCoefficient(value);
} else {
throw OrekitException.createIllegalArgumentException(UNKNOWN_PARAMETER_MESSAGE, name);
}
}
}
......@@ -44,7 +44,7 @@ public interface DragSensitive extends Serializable {
* @throws OrekitException if acceleration cannot be computed
*/
Vector3D dragAcceleration(SpacecraftState state, double density, Vector3D relativeVelocity)
throws OrekitException;
throws OrekitException;
/** Set the drag coefficient.
* @param value drag coefficient
......
......@@ -55,6 +55,9 @@ public class SolarRadiationPressure implements ForceModelWithJacobians {
private static final String LOW_TRAJECTORY_MESSAGE =
"trajectory inside the Brillouin sphere (r = {0})";
/** Error message for unknown parameter. */
private static final String UNKNOWN_PARAMETER_MESSAGE = "unknown parameter {0}";
/** Sun radius (m). */
private static final double SUN_RADIUS = 6.95e8;
......@@ -69,7 +72,7 @@ public class SolarRadiationPressure implements ForceModelWithJacobians {
/** Spacecraft. */
private final RadiationSensitive spacecraft;
/** List of the parameters names. */
private final ArrayList<String> parametersNames = new ArrayList<String>();
......@@ -215,36 +218,39 @@ public class SolarRadiationPressure implements ForceModelWithJacobians {
}
/** {@inheritDoc} */
public void addContributionWithJacobians(SpacecraftState s,
TimeDerivativesEquationsWithJacobians adder) throws OrekitException {
}
public void addContributionWithJacobians(final SpacecraftState s,
final TimeDerivativesEquationsWithJacobians adder)
throws OrekitException {
}
/** {@inheritDoc} */
public Collection<String> getParametersNames() {
return parametersNames;
}
public Collection<String> getParametersNames() {
return parametersNames;
}
/** {@inheritDoc} */
public double getParameter(String name) throws IllegalArgumentException {
if (name.matches(ABSORPTION_COEFFICIENT)) {
return spacecraft.getAbsorptionCoefficient();
} else if (name.matches(REFLECTION_COEFFICIENT)) {
return spacecraft.getReflectionCoefficient();
} else {
throw OrekitException.createIllegalArgumentException("unknown parameter {0}", name);
}
}
public double getParameter(final String name)
throws IllegalArgumentException {
if (name.matches(ABSORPTION_COEFFICIENT)) {
return spacecraft.getAbsorptionCoefficient();
} else if (name.matches(REFLECTION_COEFFICIENT)) {
return spacecraft.getReflectionCoefficient();
} else {
throw OrekitException.createIllegalArgumentException(UNKNOWN_PARAMETER_MESSAGE, name);
}
}
/** {@inheritDoc} */
public void setParameter(String name, double value) throws IllegalArgumentException {
if (name.matches(ABSORPTION_COEFFICIENT)) {
spacecraft.setAbsorptionCoefficient(value);
} else if (name.matches(REFLECTION_COEFFICIENT)) {
spacecraft.setReflectionCoefficient(value);
} else {
throw OrekitException.createIllegalArgumentException("unknown parameter {0}", name);
}
}
public void setParameter(final String name, final double value)
throws IllegalArgumentException {
if (name.matches(ABSORPTION_COEFFICIENT)) {
spacecraft.setAbsorptionCoefficient(value);
} else if (name.matches(REFLECTION_COEFFICIENT)) {
spacecraft.setReflectionCoefficient(value);
} else {
throw OrekitException.createIllegalArgumentException(UNKNOWN_PARAMETER_MESSAGE, name);
}
}
/** This class defines the umbra entry/exit detector. */
private class UmbraDetector extends AbstractDetector {
......
......@@ -115,7 +115,7 @@ discrete events. Here is a short list of the features offered by the library:</p
(models changes, G-stop, simple notifications ...)</li>
<li>predefined discrete events
<ul>
<li>eclipse -both umbra and penumbra)</li>
<li>eclipse (both umbra and penumbra)</li>
<li>ascending and descending node crossing</li>
<li>apogee and perigee crossing</li>
<li>raising/setting with respect to a ground location
......
......@@ -126,6 +126,8 @@ public class NumericalPropagator implements Propagator {
/** Serializable UID. */
private static final long serialVersionUID = -2385169798425713766L;
// CHECKSTYLE: stop VisibilityModifierCheck
/** Attitude law. */
protected AttitudeLaw attitudeLaw;
......@@ -165,6 +167,8 @@ public class NumericalPropagator implements Propagator {
/** Current mode. */
protected int mode;
// CHECKSTYLE: resume VisibilityModifierCheck
/** Create a new instance of NumericalPropagator, based on orbit definition mu.
* After creation, the instance is empty, i.e. the attitude law is set to an
* unspecified default law and there are no perturbing forces at all.
......
......@@ -55,16 +55,16 @@ import org.orekit.time.AbsoluteDate;
* these for a simple numerical integration.
* </p>
* <p>
* The Jacobian for the six {@link EquinoctialOrbit equinoxial orbit parameters}
* The Jacobian for the six {@link EquinoctialOrbit equinoctial orbit parameters}
* (a, e<sub>x</sub>, e<sub>y</sub>, h<sub>x</sub>, h<sub>y</sub>, l<sub>v</sub>)
* and the mass is computed as a 7x7 array.
* </p>
* <p>
* Partial derivatives can also be computed for the 7 elements state vector with
* respect to {@link #selectedParameters selected parameters} from
* respect to {@link #selectParameters selected parameters} from
* {@link ForceModelWithJacobians force models}.
* </p>
*
*
* @see NumericalPropagator
* @see ForceModelWithJacobians
*
......@@ -73,10 +73,16 @@ import org.orekit.time.AbsoluteDate;
*/
public class NumericalPropagatorWithJacobians extends NumericalPropagator {
/** Serializable UID. */
private static final long serialVersionUID = 4139595812211569107L;
/** Serializable UID. */
private static final long serialVersionUID = 4139595812211569107L;
/** Absolute vectorial error field name. */
private static final String ABSOLUTE_TOLERANCE = "vecAbsoluteTolerance";
/** Force models used when extrapolating the Orbit. */
/** Relative vectorial error field name. */
private static final String RELATIVE_TOLERANCE = "vecRelativeTolerance";
/** Force models used when extrapolating the Orbit. */
private final List<ForceModelWithJacobians> forceModelsWJ;
/** State vector derivative with respect to the parameter. */
......@@ -98,7 +104,6 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
* called after creation, the integrated orbit will follow a keplerian
* evolution only.
* @param integrator numerical integrator to use for propagation.
* @see NumericalPropagator(FirstOrderIntegrator )
*/
public NumericalPropagatorWithJacobians(final FirstOrderIntegrator integrator) {
super(integrator);
......@@ -115,7 +120,7 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
if (!(model instanceof ForceModelWithJacobians)) {
forceModelsWJ.add(new ForceModelWrapper(model));
} else {
forceModelsWJ.add((ForceModelWithJacobians)model);
forceModelsWJ.add((ForceModelWithJacobians) model);
}
}
......@@ -138,7 +143,7 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
* @see ForceModelWithJacobians
* @see Parameterizable
*/
public void selectParameters(String[] parameters) {
public void selectParameters(final String[] parameters) {
selectedParameters = parameters.clone();
DY0DP = new double[7][selectedParameters.length];
for (final double[] row : DY0DP) {
......@@ -147,11 +152,11 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
}
/** Get the parameters selected for jacobian processing.
* @param parameters parameters considered for jacobian processing
* @return parameters considered for jacobian processing
* @see #selectParameters(String)
*/
public String[] getParameterNames() {
return selectedParameters;
return selectedParameters.clone();
}
/** Propagate towards a target date and compute partial derivatives.
......@@ -233,27 +238,27 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
stateVector[6] = initialState.getMass();
// set up parameters for jacobian computation
int noParam = 0;
int nbParam = selectedParameters.length;
double[] paramWJ = new double[nbParam];
double[] hP = new double[nbParam];
int noParam = 0;
final int nbParam = selectedParameters.length;
final double[] paramWJ = new double[nbParam];
final double[] hP = new double[nbParam];
for (final String parameter : selectedParameters) {
boolean found = false;
for (final ForceModelWithJacobians fmwj : forceModelsWJ) {
for (String parFMWJ : fmwj.getParametersNames()) {
if (parFMWJ.matches(parameter)) {
found = true;
paramWJ[noParam] = fmwj.getParameter(parFMWJ);
hP[noParam] = paramWJ[noParam] * Math.sqrt(MathUtils.EPSILON);
paramPairs.add(new ParameterPair(parameter, fmwj));
noParam++;
}
}
}
if (!found) {
throw new PropagationException("unknown parameter {0}", parameter);
}
boolean found = false;
for (final ForceModelWithJacobians fmwj : forceModelsWJ) {
for (String parFMWJ : fmwj.getParametersNames()) {
if (parFMWJ.matches(parameter)) {
found = true;
paramWJ[noParam] = fmwj.getParameter(parFMWJ);
hP[noParam] = paramWJ[noParam] * Math.sqrt(MathUtils.EPSILON);
paramPairs.add(new ParameterPair(parameter, fmwj));
noParam++;
}
}
}
if (!found) {
throw new PropagationException("unknown parameter {0}", parameter);
}
}
// if selectParameters was not invoked and then no parameter selected
......@@ -265,15 +270,15 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
}
// get hY from integrator tolerance array
double[] hY = getHy(integrator);
final double[] hY = getHy(integrator);
// resize integrator tolerance array
expandToleranceArray(integrator);
FirstOrderIntegratorWithJacobians integratorWJ =
new FirstOrderIntegratorWithJacobians(integrator,
new DifferentialEquations(),
paramWJ, hY, hP);
final FirstOrderIntegratorWithJacobians integratorWJ =
new FirstOrderIntegratorWithJacobians(integrator,
new DifferentialEquations(),
paramWJ, hY, hP);
try {
// mathematical integration
......@@ -294,9 +299,9 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
resetInitialState(new SpacecraftState(orbit, attitudeLaw.getAttitude(orbit), stateVector[6]));
} finally {
if (integrator != null) {
resetToleranceArray(integrator);
}
if (integrator != null) {
resetToleranceArray(integrator);
}
}
return initialState;
......@@ -332,76 +337,77 @@ public class NumericalPropagatorWithJacobians extends NumericalPropagator {
* @param integrator integrator
*/
private void expandToleranceArray(final FirstOrderIntegrator integrator) {
if (integrator instanceof AdaptiveStepsizeIntegrator) {
int n = stateVector.length;
int k = selectedParameters.length;
resizeArray(integrator, "vecAbsoluteTolerance", n * (n + 1 + k), true);
resizeArray(integrator, "vecRelativeTolerance", n * (n + 1 + k), false);
}
if (integrator instanceof AdaptiveStepsizeIntegrator) {
final int n = stateVector.length;
final int k = selectedParameters.length;
resizeArray(integrator, ABSOLUTE_TOLERANCE, n * (n + 1 + k), true);
resizeArray(integrator, RELATIVE_TOLERANCE, n * (n + 1 + k), false);
}
}
/** Reset integrator tolerance array to original size.
* @param integrator integrator
*/
private void resetToleranceArray(final FirstOrderIntegrator integrator) {
if (integrator instanceof AdaptiveStepsizeIntegrator) {
int n = stateVector.length;
resizeArray(integrator, "vecAbsoluteTolerance", n, true);
resizeArray(integrator, "vecRelativeTolerance", n, false);
}
if (integrator instanceof AdaptiveStepsizeIntegrator) {
final int n = stateVector.length;
resizeArray(integrator, ABSOLUTE_TOLERANCE, n, true);
resizeArray(integrator, RELATIVE_TOLERANCE, n, false);
}
}
/** Resize object internal array.
* @param instance instance concerned
* @param fieldName field name
* @param fieldName field name
* @param newSize new array size
* @param isAbsolute flag to fill the new array
*/
private void resizeArray(final Object instance, final String fieldName,
final int newSize, final boolean isAbsolute) {
try {
final Field arrayField = AdaptiveStepsizeIntegrator.class.getDeclaredField(fieldName);
arrayField.setAccessible(true);
final double[] originalArray = (double[]) arrayField.get(instance);
final int originalSize = originalArray.length;
double[] resizedArray = new double[newSize];
if (newSize > originalSize) {
// expand array
System.arraycopy(originalArray, 0, resizedArray, 0, originalSize);
final double filler = isAbsolute ? Double.POSITIVE_INFINITY : 0.0;
Arrays.fill(resizedArray, originalSize, newSize, filler);
} else {
// shrink array
System.arraycopy(originalArray, 0, resizedArray, 0, newSize);
}
arrayField.set(instance, resizedArray);
} catch (NoSuchFieldException nsfe) {
throw OrekitException.createInternalError(nsfe);
} catch (IllegalAccessException iae) {
throw OrekitException.createInternalError(iae);
}
try {
final Field arrayField = AdaptiveStepsizeIntegrator.class.getDeclaredField(fieldName);
arrayField.setAccessible(true);
final double[] originalArray = (double[]) arrayField.get(instance);
final int originalSize = originalArray.length;
final double[] resizedArray = new double[newSize];
if (newSize > originalSize) {
// expand array