Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
NDSolver.hh
Go to the documentation of this file.
1#pragma once
2
3#include "Storage.hh"
4#include "Compare.hh"
5#include "Exceptions.hh"
6#include "NTensor.hh"
7#include "NEvaluator.hh"
8
9namespace cadabra {
10
24
25 class NDSolver {
26 public:
27 // Initialise with an Ex containing the ODEs in standard form
28 // (that is, only 1st order derivatives on the lhs).
29 NDSolver(const Ex&);
30
31 typedef std::vector<double> state_type;
32
33 // Integration function.
34 void operator()(const state_type &x, state_type &dxdt, const double t);
35
36 // Observer function.
37 void operator()( const state_type &x , double t );
38
39 // Set and check ODE(s).
40 void set_ODEs(const Ex&);
41
42 // Set initial values.
43 void set_initial_value(const Ex&, double val);
44
45 // Set integration range for the independent variable.
46 void set_range(const Ex&, double from, double to);
47
48 // Set a condition which, when satisfied, will stop the integration.
49 void set_stop(const Ex&);
50
51 // Entry point.
52 std::vector<NTensor> integrate();
53
54 // Functions.
55 const std::vector<Ex>& functions() const;
56
57 private:
58 // Exception used by the observer function to terminate
59 // iteration in case an event happens.
60
61 class EventException : public CadabraException {
62 public:
63 EventException(std::string reason="");
64 };
65
66 Ex ODEs, stop;
67
68 // Information extracted from `ODEs`.
69 std::vector<Ex> variables;
70
71 // For each function in the ODEs we have one evaluator.
72 std::vector<NEvaluator> evaluators;
73
74 // For each condition in the `stop` expression we also have one evaluator.
75 std::vector<NEvaluator> stop_lhs_evaluators, stop_rhs_evaluators;
76 std::vector<bool> stop_conditions;
77
78 // Extract from `ODEs` the right-hand side expressions as
79 // well as the names of the functions to solve for.
80 void extract_from_ODEs();
81
82 // Evaluate the stop condition.
83 bool evaluate_stop(const state_type& x, const double t);
84
85 // Storage of the result of the integration.
86 std::vector<std::vector<double>> states;
87 std::vector<double> times;
88 std::map<Ex, double, tree_exact_less_no_wildcards_obj> initial_values;
90 double range_from, range_to;
91};
92
93};
const std::unordered_set< std::string > functions
Definition Keywords.cc:5
Definition Exceptions.hh:7
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1179