2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.commons.math.ode;
20
import org.apache.commons.math.ode.events.EventHandler;
23
* This class is used in the junit tests for the ODE integrators.
25
* <p>This specific problem is the following differential equation :
29
* And when x decreases down to 0, the state should be changed as follows :
33
* The theoretical solution of this problem is x = |sin(t+a)|
37
public class TestProblem4
38
extends TestProblemAbstract {
40
/** Serializable version identifier. */
41
private static final long serialVersionUID = -5910438521889015745L;
46
/** theoretical state */
49
/** Simple constructor. */
50
public TestProblem4() {
53
double[] y0 = { Math.sin(a), Math.cos(a) };
54
setInitialConditions(0.0, y0);
55
setFinalConditions(15);
56
double[] errorScale = { 1.0, 0.0 };
57
setErrorScale(errorScale);
58
y = new double[y0.length];
63
* @param problem problem to copy
65
public TestProblem4(TestProblem4 problem) {
68
y = problem.y.clone();
72
public TestProblem4 copy() {
73
return new TestProblem4(this);
77
public EventHandler[] getEventsHandlers() {
78
return new EventHandler[] { new Bounce(), new Stop() };
82
public void doComputeDerivatives(double t, double[] y, double[] yDot) {
88
public double[] computeTheoreticalState(double t) {
89
double sin = Math.sin(t + a);
90
double cos = Math.cos(t + a);
92
y[1] = (sin >= 0) ? cos : -cos;
96
private static class Bounce implements EventHandler {
98
private static final long serialVersionUID = 1356097180027801200L;
105
public double g(double t, double[] y) {
109
public int eventOccurred(double t, double[] y, boolean increasing) {
110
// this sign change is needed because the state will be reset soon
112
return EventHandler.RESET_STATE;
115
public void resetState(double t, double[] y) {
122
private static class Stop implements EventHandler {
124
private static final long serialVersionUID = 6975050568227951931L;
129
public double g(double t, double[] y) {
133
public int eventOccurred(double t, double[] y, boolean increasing) {
134
return EventHandler.STOP;
137
public void resetState(double t, double[] y) {