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