001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.math.ode.nonstiff;
019    
020    import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
021    import org.apache.commons.math.ode.events.EventHandler;
022    
023    
024    public class StepProblem
025      implements FirstOrderDifferentialEquations, EventHandler {
026    
027      public StepProblem(double rateBefore, double rateAfter,
028                         double switchTime) {
029        this.rateAfter  = rateAfter;
030        this.switchTime = switchTime;
031        setRate(rateBefore);
032      }
033    
034      public void computeDerivatives(double t, double[] y, double[] yDot) {
035        yDot[0] = rate;
036      }
037    
038      public int getDimension() {
039        return 1;
040      }
041    
042      public void setRate(double rate) {
043        this.rate = rate;
044      }
045    
046      public int eventOccurred(double t, double[] y, boolean increasing) {
047        setRate(rateAfter);
048        return RESET_DERIVATIVES;
049      }
050    
051      public double g(double t, double[] y) {
052        return t - switchTime;
053      }
054    
055      public void resetState(double t, double[] y) {
056      }
057    
058      private double rate;
059      private double rateAfter;
060      private double switchTime;
061    
062      private static final long serialVersionUID = 7590601995477504318L;
063    
064    }