Example usage for org.apache.commons.math3.ode.nonstiff AdamsBashforthIntegrator AdamsBashforthIntegrator

List of usage examples for org.apache.commons.math3.ode.nonstiff AdamsBashforthIntegrator AdamsBashforthIntegrator

Introduction

In this page you can find the example usage for org.apache.commons.math3.ode.nonstiff AdamsBashforthIntegrator AdamsBashforthIntegrator.

Prototype

public AdamsBashforthIntegrator(final int nSteps, final double minStep, final double maxStep,
        final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance)
        throws IllegalArgumentException 

Source Link

Document

Build an Adams-Bashforth integrator with the given order and step control parameters.

Usage

From source file:de.uni_erlangen.lstm.modelaccess.Model.java

/**
 * Run the model using set parameters// w w  w. j a  va2  s . com
 */
public void simulate() {
    finished = false;
    /*
     * Integrator selection 
     */
    //FirstOrderIntegrator integrator = new HighamHall54Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
    //FirstOrderIntegrator integrator = new DormandPrince54Integrator(1.0e-12, 100.0, 1.0e-12, 1.0e-12);
    //FirstOrderIntegrator integrator = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
    //FirstOrderIntegrator integrator = new GraggBulirschStoerIntegrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
    FirstOrderIntegrator integrator = new AdamsBashforthIntegrator(2, 1.0e-14, 100.0, 1.0e-10, 1.0e-10);
    //FirstOrderIntegrator integrator = new AdamsMoultonIntegrator(2, 1.0e-8, 100.0, 1.0e-10, 1.0e-10);

    // influent values, digester parameters, S_H_ion, dae system
    final DAEModel ode = new DAEModel(u, param, S_H_ion, dae, fix_pH);
    //FirstOrderDifferentialEquations ode = model; 

    // Records progress
    StepHandler progHandler = new StepHandler() {
        public void init(double t0, double[] y0, double t) {
        }

        public void handleStep(StepInterpolator interpolator, boolean isLast) {
            progress = interpolator.getCurrentTime();
        }
    };
    integrator.addStepHandler(progHandler);

    /*
     * Continuous model recorded in CSV
     */
    if (onlineRecord) {
        final CSVWriter writer = new CSVWriter();
        StepHandler stepHandler = new StepHandler() {
            double prevT = 0.0;

            public void init(double t0, double[] y0, double t) {
            }

            public void handleStep(StepInterpolator interpolator, boolean isLast) {
                double t = interpolator.getCurrentTime();
                if (t - prevT > resolution) {
                    // Add time to the beginning of the array
                    double[] timemodel = new double[ode.getDimensions().length + 1];
                    timemodel[0] = t;

                    // We need to pull variables (S_h2 and acid-base) directly from the model if using DAE
                    for (int i = 1; i < timemodel.length; i++) {
                        timemodel[i] = ode.getDimensions()[i - 1];
                    }

                    writer.WriteArray(output_file, timemodel, true);
                    prevT = t;
                }
            }
        };
        integrator.addStepHandler(stepHandler);
    }

    /*
     * Add event handlers for discrete events
     * maxCheck - maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
      * conv - convergence threshold in the event time search
      * maxIt - upper limit of the iteration count in the event time search
     */
    if (events.size() > 0) {
        for (DiscreteEvent event : events) {
            double maxCheck = Double.POSITIVE_INFINITY;
            double conv = 1.0e-20;
            int maxIt = 100;
            integrator.addEventHandler(event, maxCheck, conv, maxIt);
        }
    }

    integrator.integrate(ode, start, x, end, x);

    /*
     * Return the time that the discrete event occurred
     */
    if (events.size() > 0) {
        for (DiscreteEvent event : events) {
            if (event.getTime() < end) {
                end = event.getTime();
            }
        }
    }

    // We need to pull variables (S_h2 and acid-base) directly from the model
    x = ode.getDimensions();

    finished = true;
}

From source file:org.orekit.propagation.conversion.AdamsBashforthIntegratorBuilder.java

/** {@inheritDoc} */
public AbstractIntegrator buildIntegrator(final Orbit orbit) throws PropagationException {
    final double[][] tol = NumericalPropagator.tolerances(dP, orbit, OrbitType.CARTESIAN);
    return new AdamsBashforthIntegrator(nSteps, minStep, maxStep, tol[0], tol[1]);
}

From source file:ummisco.gaml.extensions.maths.ode.utils.solver.AdamsBashforthSolver.java

public AdamsBashforthSolver(final int nSteps, final double minStep, final double maxStep,
        final double scalAbsoluteTolerance, final double scalRelativeTolerance,
        final GamaMap<String, IList<Double>> integrated_val) {
    super((minStep + maxStep) / 2, new AdamsBashforthIntegrator(nSteps, minStep, maxStep, scalAbsoluteTolerance,
            scalRelativeTolerance), integrated_val);
}