Refactoring
This commit is contained in:
1 parent
fd2e4f265c
commit
1b9044325b
7 files changed
+30
-97
No files matched your search
@@ -19,39 +19,28 @@ PLUGIN_EXPORT const char* plugin_description(){
|
||||
return "Explicit second-order Adams-Bashforth method with an RK4 start";
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void transform(const SolverParameters* parameters,
|
||||
PLUGIN_EXPORT void solver(const SolverParameters* parameters,
|
||||
SolutionPoint* output,
|
||||
size_t output_size){
|
||||
if (parameters == nullptr || output == nullptr || output_size == 0)
|
||||
return;
|
||||
|
||||
const State initial_state{1.0, 0.0, 0.0};
|
||||
State initial_state{1.0, 0.0, 0.0};
|
||||
output[0] = make_step(parameters->t_begin, initial_state);
|
||||
|
||||
if (output_size == 1)
|
||||
return;
|
||||
|
||||
State first_state = runge_kutta_step(initial_state, *parameters);
|
||||
output[1] = make_step(parameters->t_begin + parameters->step, first_state);
|
||||
|
||||
for (size_t index = 1; index + 1 < output_size; ++index){
|
||||
for (size_t index = 1; index + 1 < output_size; index++){
|
||||
State current = state_from_point(output[index]);
|
||||
State previous = state_from_point(output[index - 1]);
|
||||
State current_derivative = derivative(current, *parameters);
|
||||
State previous_derivative = derivative(previous, *parameters);
|
||||
double h = parameters->step;
|
||||
|
||||
State next{
|
||||
current.x1 + h * (1.5 * current_derivative.x1 -
|
||||
0.5 * previous_derivative.x1),
|
||||
current.x2 + h * (1.5 * current_derivative.x2 -
|
||||
0.5 * previous_derivative.x2),
|
||||
current.x3 + h * (1.5 * current_derivative.x3 -
|
||||
0.5 * previous_derivative.x3),
|
||||
State next{current.x1 + h * (1.5 * current_derivative.x1 - 0.5 * previous_derivative.x1),
|
||||
current.x2 + h * (1.5 * current_derivative.x2 - 0.5 * previous_derivative.x2),
|
||||
current.x3 + h * (1.5 * current_derivative.x3 - 0.5 * previous_derivative.x3),
|
||||
};
|
||||
|
||||
const double next_time = parameters->t_begin +
|
||||
static_cast<double>(index + 1) * h;
|
||||
double next_time = parameters->t_begin + static_cast<double>(index + 1) * h;
|
||||
output[index + 1] = make_step(next_time, next);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user