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