1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math.ode;
19
20 import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
21 import org.apache.commons.math.ode.events.EventHandler;
22
23
24
25
26
27 public abstract class TestProblemAbstract
28 implements FirstOrderDifferentialEquations {
29
30
31 private static final long serialVersionUID = -8521928974502839379L;
32
33
34 protected int n;
35
36
37 protected int calls;
38
39
40 protected double t0;
41
42
43 protected double[] y0;
44
45
46 protected double t1;
47
48
49 protected double[] errorScale;
50
51
52
53
54 protected TestProblemAbstract() {
55 n = 0;
56 calls = 0;
57 t0 = 0;
58 y0 = null;
59 t1 = 0;
60 errorScale = null;
61 }
62
63
64
65
66
67 protected TestProblemAbstract(TestProblemAbstract problem) {
68 n = problem.n;
69 calls = problem.calls;
70 t0 = problem.t0;
71 if (problem.y0 == null) {
72 y0 = null;
73 } else {
74 y0 = problem.y0.clone();
75 }
76 if (problem.errorScale == null) {
77 errorScale = null;
78 } else {
79 errorScale = problem.errorScale.clone();
80 }
81 t1 = problem.t1;
82 }
83
84
85
86
87
88 public abstract TestProblemAbstract copy();
89
90
91
92
93
94
95 protected void setInitialConditions(double t0, double[] y0) {
96 calls = 0;
97 n = y0.length;
98 this.t0 = t0;
99 this.y0 = y0.clone();
100 }
101
102
103
104
105
106 protected void setFinalConditions(double t1) {
107 this.t1 = t1;
108 }
109
110
111
112
113
114 protected void setErrorScale(double[] errorScale) {
115 this.errorScale = errorScale.clone();
116 }
117
118 public int getDimension() {
119 return n;
120 }
121
122
123
124
125
126 public double getInitialTime() {
127 return t0;
128 }
129
130
131
132
133
134 public double[] getInitialState() {
135 return y0;
136 }
137
138
139
140
141
142 public double getFinalTime() {
143 return t1;
144 }
145
146
147
148
149
150 public double[] getErrorScale() {
151 return errorScale;
152 }
153
154
155
156
157 public EventHandler[] getEventsHandlers() {
158 return new EventHandler[0];
159 }
160
161
162
163
164
165 public int getCalls() {
166 return calls;
167 }
168
169 public void computeDerivatives(double t, double[] y, double[] yDot) {
170 ++calls;
171 doComputeDerivatives(t, y, yDot);
172 }
173
174 abstract public void doComputeDerivatives(double t, double[] y, double[] yDot);
175
176
177
178
179
180
181 abstract public double[] computeTheoreticalState(double t);
182
183 }