Search in sources :

Example 11 with BracketingNthOrderBrentSolver

use of org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver in project Orekit by CS-SI.

the class InterSatellitesRangeMeasurementCreator method handleStep.

public void handleStep(final SpacecraftState currentState, final boolean isLast) throws OrekitException {
    try {
        final AbsoluteDate date = currentState.getDate();
        final Vector3D position = currentState.toTransform().getInverse().transformPosition(antennaPhaseCenter1);
        final UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 5);
        final double downLinkDelay = solver.solve(1000, new UnivariateFunction() {

            public double value(final double x) throws OrekitExceptionWrapper {
                try {
                    final Vector3D other = ephemeris.propagate(date.shiftedBy(-x)).toTransform().getInverse().transformPosition(antennaPhaseCenter2);
                    final double d = Vector3D.distance(position, other);
                    return d - x * Constants.SPEED_OF_LIGHT;
                } catch (OrekitException oe) {
                    throw new OrekitExceptionWrapper(oe);
                }
            }
        }, -1.0, 1.0);
        final AbsoluteDate transitDate = currentState.getDate().shiftedBy(-downLinkDelay);
        final Vector3D otherAtTransit = ephemeris.propagate(transitDate).toTransform().getInverse().transformPosition(antennaPhaseCenter2);
        final double downLinkDistance = Vector3D.distance(position, otherAtTransit);
        if ((++count % 2) == 0) {
            // generate a two-way measurement
            final double upLinkDelay = solver.solve(1000, new UnivariateFunction() {

                public double value(final double x) throws OrekitExceptionWrapper {
                    final Vector3D self = currentState.shiftedBy(-downLinkDelay - x).toTransform().getInverse().transformPosition(antennaPhaseCenter1);
                    final double d = Vector3D.distance(otherAtTransit, self);
                    return d - x * Constants.SPEED_OF_LIGHT;
                }
            }, -1.0, 1.0);
            final Vector3D selfAtEmission = currentState.shiftedBy(-downLinkDelay - upLinkDelay).toTransform().getInverse().transformPosition(antennaPhaseCenter1);
            final double upLinkDistance = Vector3D.distance(otherAtTransit, selfAtEmission);
            addMeasurement(new InterSatellitesRange(0, 1, true, date, 0.5 * (downLinkDistance + upLinkDistance), 1.0, 10));
        } else {
            // generate a one-way measurement
            addMeasurement(new InterSatellitesRange(0, 1, false, date, downLinkDistance, 1.0, 10));
        }
    } catch (OrekitExceptionWrapper oew) {
        throw new OrekitException(oew.getException());
    } catch (OrekitException oe) {
        throw new OrekitException(oe);
    }
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) UnivariateSolver(org.hipparchus.analysis.solvers.UnivariateSolver) OrekitException(org.orekit.errors.OrekitException) AbsoluteDate(org.orekit.time.AbsoluteDate) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Example 12 with BracketingNthOrderBrentSolver

use of org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver in project Orekit by CS-SI.

the class RangeMeasurementCreator method handleStep.

public void handleStep(final SpacecraftState currentState, final boolean isLast) throws OrekitException {
    try {
        for (final GroundStation station : context.stations) {
            final AbsoluteDate date = currentState.getDate();
            final Frame inertial = currentState.getFrame();
            final Vector3D position = currentState.toTransform().getInverse().transformPosition(antennaPhaseCenter);
            if (station.getBaseFrame().getElevation(position, inertial, date) > FastMath.toRadians(30.0)) {
                final UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 5);
                final double downLinkDelay = solver.solve(1000, new UnivariateFunction() {

                    public double value(final double x) throws OrekitExceptionWrapper {
                        try {
                            final Transform t = station.getOffsetToInertial(inertial, date.shiftedBy(x));
                            final double d = Vector3D.distance(position, t.transformPosition(Vector3D.ZERO));
                            return d - x * Constants.SPEED_OF_LIGHT;
                        } catch (OrekitException oe) {
                            throw new OrekitExceptionWrapper(oe);
                        }
                    }
                }, -1.0, 1.0);
                final AbsoluteDate receptionDate = currentState.getDate().shiftedBy(downLinkDelay);
                final Vector3D stationAtReception = station.getOffsetToInertial(inertial, receptionDate).transformPosition(Vector3D.ZERO);
                final double downLinkDistance = Vector3D.distance(position, stationAtReception);
                final double upLinkDelay = solver.solve(1000, new UnivariateFunction() {

                    public double value(final double x) throws OrekitExceptionWrapper {
                        try {
                            final Transform t = station.getOffsetToInertial(inertial, date.shiftedBy(-x));
                            final double d = Vector3D.distance(position, t.transformPosition(Vector3D.ZERO));
                            return d - x * Constants.SPEED_OF_LIGHT;
                        } catch (OrekitException oe) {
                            throw new OrekitExceptionWrapper(oe);
                        }
                    }
                }, -1.0, 1.0);
                final AbsoluteDate emissionDate = currentState.getDate().shiftedBy(-upLinkDelay);
                final Vector3D stationAtEmission = station.getOffsetToInertial(inertial, emissionDate).transformPosition(Vector3D.ZERO);
                final double upLinkDistance = Vector3D.distance(position, stationAtEmission);
                addMeasurement(new Range(station, receptionDate, 0.5 * (downLinkDistance + upLinkDistance), 1.0, 10));
            }
        }
    } catch (OrekitExceptionWrapper oew) {
        throw new OrekitException(oew.getException());
    } catch (OrekitException oe) {
        throw new OrekitException(oe);
    }
}
Also used : Frame(org.orekit.frames.Frame) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) UnivariateSolver(org.hipparchus.analysis.solvers.UnivariateSolver) OrekitException(org.orekit.errors.OrekitException) Transform(org.orekit.frames.Transform) AbsoluteDate(org.orekit.time.AbsoluteDate) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Example 13 with BracketingNthOrderBrentSolver

use of org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver in project Orekit by CS-SI.

the class RangeRateMeasurementCreator method handleStep.

public void handleStep(final SpacecraftState currentState, final boolean isLast) throws OrekitException {
    for (final GroundStation station : context.stations) {
        final AbsoluteDate date = currentState.getDate();
        final Frame inertial = currentState.getFrame();
        final Vector3D position = currentState.getPVCoordinates().getPosition();
        final Vector3D velocity = currentState.getPVCoordinates().getVelocity();
        if (station.getBaseFrame().getElevation(position, inertial, date) > FastMath.toRadians(30.0)) {
            final UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 5);
            final double downLinkDelay = solver.solve(1000, new UnivariateFunction() {

                public double value(final double x) throws OrekitExceptionWrapper {
                    try {
                        final Transform t = station.getOffsetToInertial(inertial, date.shiftedBy(x));
                        final double d = Vector3D.distance(position, t.transformPosition(Vector3D.ZERO));
                        return d - x * Constants.SPEED_OF_LIGHT;
                    } catch (OrekitException oe) {
                        throw new OrekitExceptionWrapper(oe);
                    }
                }
            }, -1.0, 1.0);
            final AbsoluteDate receptionDate = currentState.getDate().shiftedBy(downLinkDelay);
            final PVCoordinates stationAtReception = station.getOffsetToInertial(inertial, receptionDate).transformPVCoordinates(PVCoordinates.ZERO);
            // line of sight at reception
            final Vector3D receptionLOS = (position.subtract(stationAtReception.getPosition())).normalize();
            // relative velocity, spacecraft-station, at the date of reception
            final Vector3D deltaVr = velocity.subtract(stationAtReception.getVelocity());
            final double upLinkDelay = solver.solve(1000, new UnivariateFunction() {

                public double value(final double x) throws OrekitExceptionWrapper {
                    try {
                        final Transform t = station.getOffsetToInertial(inertial, date.shiftedBy(-x));
                        final double d = Vector3D.distance(position, t.transformPosition(Vector3D.ZERO));
                        return d - x * Constants.SPEED_OF_LIGHT;
                    } catch (OrekitException oe) {
                        throw new OrekitExceptionWrapper(oe);
                    }
                }
            }, -1.0, 1.0);
            final AbsoluteDate emissionDate = currentState.getDate().shiftedBy(-upLinkDelay);
            final PVCoordinates stationAtEmission = station.getOffsetToInertial(inertial, emissionDate).transformPVCoordinates(PVCoordinates.ZERO);
            // line of sight at emission
            final Vector3D emissionLOS = (position.subtract(stationAtEmission.getPosition())).normalize();
            // relative velocity, spacecraft-station, at the date of emission
            final Vector3D deltaVe = velocity.subtract(stationAtEmission.getVelocity());
            // range rate at the date of reception
            final double rr = twoWay ? 0.5 * (deltaVr.dotProduct(receptionLOS) + deltaVe.dotProduct(emissionLOS)) : deltaVr.dotProduct(receptionLOS);
            addMeasurement(new RangeRate(station, date, rr, 1.0, 10, twoWay));
        }
    }
}
Also used : Frame(org.orekit.frames.Frame) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) UnivariateSolver(org.hipparchus.analysis.solvers.UnivariateSolver) PVCoordinates(org.orekit.utils.PVCoordinates) AbsoluteDate(org.orekit.time.AbsoluteDate) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrekitException(org.orekit.errors.OrekitException) Transform(org.orekit.frames.Transform)

Example 14 with BracketingNthOrderBrentSolver

use of org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver in project Orekit by CS-SI.

the class SecularAndHarmonicTest method findLatitudeCrossing.

private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate, final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator) throws OrekitException, MathRuntimeException {
    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {

        /**
         * {@inheritDoc}
         */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }
        }
    };
    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }
    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {
        if (2 * span > maxShift) {
            // let the Hipparchus exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }
        // expand the search interval
        span *= 2;
    }
    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) MathRuntimeException(org.hipparchus.exception.MathRuntimeException) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Aggregations

UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)14 BracketingNthOrderBrentSolver (org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)14 OrekitException (org.orekit.errors.OrekitException)14 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)11 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)9 AbsoluteDate (org.orekit.time.AbsoluteDate)9 UnivariateSolver (org.hipparchus.analysis.solvers.UnivariateSolver)8 MathRuntimeException (org.hipparchus.exception.MathRuntimeException)6 Frame (org.orekit.frames.Frame)6 Transform (org.orekit.frames.Transform)6 FastMath (org.hipparchus.util.FastMath)4 GeodeticPoint (org.orekit.bodies.GeodeticPoint)4 SpacecraftState (org.orekit.propagation.SpacecraftState)4 Field (org.hipparchus.Field)3 RealFieldElement (org.hipparchus.RealFieldElement)3 RealFieldUnivariateFunction (org.hipparchus.analysis.RealFieldUnivariateFunction)3 FieldBracketingNthOrderBrentSolver (org.hipparchus.analysis.solvers.FieldBracketingNthOrderBrentSolver)3 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)3 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)3 PVCoordinates (org.orekit.utils.PVCoordinates)3