DOLFIN
DOLFIN C++ interface
MultiStageScheme.h
1 // Copyright (C) 2013 Johan Hake
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2013-02-15
19 // Last changed: 2014-03-05
20 
21 #ifndef __BUTCHERSCHEME_H
22 #define __BUTCHERSCHEME_H
23 
24 #include <memory>
25 #include <vector>
26 
27 #include <dolfin/common/Variable.h>
28 #include <dolfin/function/Function.h>
29 #include <dolfin/fem/Form.h>
30 
31 namespace dolfin
32 {
33  // Forward declarations
34  class Form;
35  class Function;
36  class DirichletBC;
37  class Constant;
38 
40 
41  class MultiStageScheme : public Variable
42  {
43  public:
44 
46  MultiStageScheme(std::vector<std::vector<std::shared_ptr<const Form>>> stage_forms,
47  std::shared_ptr<const Form> last_stage,
48  std::vector<std::shared_ptr<Function> > stage_solutions,
49  std::shared_ptr<Function> u,
50  std::shared_ptr<Constant> t,
51  std::shared_ptr<Constant> dt,
52  std::vector<double> dt_stage_offset,
53  std::vector<int> jacobian_indices,
54  unsigned int order,
55  const std::string name,
56  const std::string human_form,
57  std::vector<std::shared_ptr<const DirichletBC>> bcs = {});
58 
60  std::vector<std::vector<std::shared_ptr<const Form>>>& stage_forms();
61 
63  std::shared_ptr<const Form> last_stage();
64 
66  std::vector<std::shared_ptr<Function> >& stage_solutions();
67 
69  std::shared_ptr<Function> solution();
70 
72  std::shared_ptr<const Function> solution() const;
73 
75  std::shared_ptr<Constant> t();
76 
78  std::shared_ptr<Constant> dt();
79 
81  const std::vector<double>& dt_stage_offset() const;
82 
84  unsigned int order() const;
85 
87  std::vector<std::shared_ptr<const DirichletBC>> bcs() const;
88 
90  bool implicit(unsigned int stage) const;
91 
93  bool implicit() const;
94 
97  int jacobian_index(unsigned int stage) const;
98 
100  virtual std::string str(bool verbose) const;
101 
102  private:
103 
104  // Check sanity of arguments
105  void _check_arguments();
106 
107  // Vector of forms for the different RK stages
108  std::vector<std::vector<std::shared_ptr<const Form>>> _stage_forms;
109 
110  // A linear combination of solutions for the last stage
111  std::shared_ptr<const Form> _last_stage;
112 
113  // Solutions for the different stages
114  std::vector<std::shared_ptr<Function>> _stage_solutions;
115 
116  // The solution
117  std::shared_ptr<Function> _u;
118 
119  // The local time
120  std::shared_ptr<Constant> _t;
121 
122  // The local time step
123  std::shared_ptr<Constant> _dt;
124 
125  // The time step offset. (c from the ButcherTableau)
126  std::vector<double> _dt_stage_offset;
127 
128  // Map for distinct storage of jacobians
129  std::vector<int> _jacobian_indices;
130 
131  // The order of the scheme
132  unsigned int _order;
133 
134  // Is the scheme implicit
135  bool _implicit;
136 
137  // A pretty print representation of the form
138  std::string _human_form;
139 
140  // The boundary conditions
141  std::vector<std::shared_ptr<const DirichletBC>> _bcs;
142 
143  };
144 
145 }
146 
147 #endif
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: MultiStageScheme.cpp:136
std::vector< std::vector< std::shared_ptr< const Form > > > & stage_forms()
Return the stages.
Definition: MultiStageScheme.cpp:54
Common base class for DOLFIN variables.
Definition: Variable.h:35
std::shared_ptr< const Form > last_stage()
Return the last stage.
Definition: MultiStageScheme.cpp:59
std::vector< std::shared_ptr< const DirichletBC > > bcs() const
Return boundary conditions.
Definition: MultiStageScheme.cpp:99
Definition: adapt.h:29
const std::vector< double > & dt_stage_offset() const
Return local timestep.
Definition: MultiStageScheme.cpp:89
bool implicit() const
Return true if the whole scheme is implicit.
Definition: MultiStageScheme.cpp:118
unsigned int order() const
Return the order of the scheme.
Definition: MultiStageScheme.cpp:94
std::shared_ptr< Constant > t()
Return local time.
Definition: MultiStageScheme.cpp:79
MultiStageScheme(std::vector< std::vector< std::shared_ptr< const Form >>> stage_forms, std::shared_ptr< const Form > last_stage, std::vector< std::shared_ptr< Function > > stage_solutions, std::shared_ptr< Function > u, std::shared_ptr< Constant > t, std::shared_ptr< Constant > dt, std::vector< double > dt_stage_offset, std::vector< int > jacobian_indices, unsigned int order, const std::string name, const std::string human_form, std::vector< std::shared_ptr< const DirichletBC >> bcs={})
Constructor.
Definition: MultiStageScheme.cpp:32
Place-holder for forms and solutions for a multi-stage Butcher tableau based method.
Definition: MultiStageScheme.h:41
std::string name() const
Return name.
Definition: Variable.cpp:71
std::shared_ptr< Function > solution()
Return solution variable.
Definition: MultiStageScheme.cpp:69
std::shared_ptr< Constant > dt()
Return local timestep.
Definition: MultiStageScheme.cpp:84
std::vector< std::shared_ptr< Function > > & stage_solutions()
Return stage solutions.
Definition: MultiStageScheme.cpp:64
int jacobian_index(unsigned int stage) const
Definition: MultiStageScheme.cpp:123