Initial commit
This commit is contained in:
commit
8400abab18
8 files changed
+979
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#include "api.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
PLUGIN_EXPORT std::uint32_t plugin_api_version(){
|
||||
return PLUGIN_API_VERSION;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT const char* plugin_name(){
|
||||
return "Adams-Bashforth 2";
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT const char* plugin_description(){
|
||||
return "Explicit second-order Adams-Bashforth method with an RK4 start";
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void func(const SolverParameters* parameters,
|
||||
SolutionPoint* output,
|
||||
std::size_t output_size){
|
||||
if (parameters == nullptr || output == nullptr || output_size == 0)
|
||||
return;
|
||||
|
||||
const 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 (std::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),
|
||||
};
|
||||
|
||||
const 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