implicit_midpoint_rule.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2022 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 #ifndef OOMPH_IMPLICIT_MIDPOINT_RULE_H
27 #define OOMPH_IMPLICIT_MIDPOINT_RULE_H
28 
29 // oomph-lib headers
30 #include "Vector.h"
31 #include "nodes.h"
32 #include "matrices.h"
33 #include "timesteppers.h"
34 #include "explicit_timesteppers.h"
35 
36 namespace oomph
37 {
38  // Forward decl. so that we can have function of Problem*
39  class Problem;
40 
41 
43  class IMRBase : public TimeStepper
44  {
45  public:
47  IMRBase(const bool& adaptive = false)
48  : TimeStepper(2, 1) // initialise weights later
49  {
51  Is_steady = false;
52  Type = "Midpoint method";
54 
55  // If adaptive then we are storing predicted values in slot
56  // 4. Otherwise we aren't storing them so leave it as -1.
57  if (adaptive)
58  {
60  }
61 
62 
63  // Storage for weights needs to be 2x(2 + 0/2) (the +2 is extra history
64  // for ebdf3 predictor if adaptive). This means we provide ways to
65  // calculate the zeroth and first derivatives and in calculations we
66  // use 2 + 0/2 time values.
67 
68  // But actually (for some reason...) the amount of data storage
69  // allocated for the timestepper in each node is determined by the
70  // size of weight. So we need to store an extra dummy entry in order
71  // to have storage space for the predicted value at t_{n+1}.
72 
73  // Just leave space for predictor values anyway, it's not expensive.
74  Weight.resize(2, 5, 0.0);
75 
76  // Assume that set_weights() or make_steady() is called before use to
77  // set up the values stored in Weight.
78  }
79 
81  virtual ~IMRBase() {}
82 
84  virtual void set_weights() = 0;
85 
88  virtual unsigned nprev_values_for_value_at_evaluation_time() const = 0;
89 
91  unsigned order() const
92  {
93  return 2;
94  }
95 
97  unsigned ndt() const
98  {
99  return nprev_values();
100  }
101 
103  unsigned nprev_values() const
104  {
105  return 4;
106  }
107 
110  void shift_time_values(Data* const& data_pt);
111 
114  void shift_time_positions(Node* const& node_pt);
115 
119 
123 
125  void assign_initial_values_impulsive(Data* const& data_pt)
126  {
127  std::string err = "Not implemented";
128  throw OomphLibError(
130  }
132  {
133  std::string err = "Not implemented";
134  throw OomphLibError(
136  }
137 
138 
139  void calculate_predicted_positions(Node* const& node_pt)
140  {
141  std::string err = "Not implemented";
142  throw OomphLibError(
144  }
145 
146  double temporal_error_in_position(Node* const& node_pt, const unsigned& i)
147  {
148  std::string err = "Not implemented";
149  throw OomphLibError(
151  }
152 
153  // Adaptivity
154  void calculate_predicted_values(Data* const& data_pt);
155  double temporal_error_in_value(Data* const& data_pt, const unsigned& i);
156  };
157 
166  class IMR : public IMRBase
167  {
168  public:
173 
174 
176  IMR(const bool& adaptive = false) : IMRBase(adaptive) {}
177 
179  virtual ~IMR() {}
180 
182  void set_weights()
183  {
184  // Set the weights for zero-th derivative (i.e. the value to use in
185  // newton solver calculations, implicit midpoint method uses the
186  // average of previous and current values).
187  Weight(0, 0) = 0.5;
188  Weight(0, 1) = 0.5;
189 
190  // Set the weights for 1st time derivative
191  double dt = Time_pt->dt(0);
192  Weight(1, 0) = 1.0 / dt;
193  Weight(1, 1) = -1.0 / dt;
194  }
195 
199  {
200  return 2;
201  }
202 
203  private:
205  IMR(const IMR& dummy) {}
206 
208  void operator=(const IMR& dummy) {}
209  };
210 
211 
219  class IMRByBDF : public IMRBase
220  {
221  public:
223  IMRByBDF(const bool& adaptive = false) : IMRBase(adaptive)
224  {
225  Update_pinned = true;
226  }
227 
229  virtual ~IMRByBDF() {}
230 
232  void set_weights()
233  {
234  // Use weights from bdf1
235  double dt = Time_pt->dt(0);
236  Weight(1, 0) = 1.0 / dt;
237  Weight(1, 1) = -1.0 / dt;
238  }
239 
244  {
245  return 1;
246  }
247 
249  void actions_before_timestep(Problem* problem_pt);
250 
253  void actions_after_timestep(Problem* problem_pt);
254 
257 
258  private:
260  IMRByBDF(const IMRByBDF& dummy) {}
261 
263  void operator=(const IMRByBDF& dummy) {}
264  };
265 
266 } // namespace oomph
267 
268 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: nodes.h:86
void resize(const unsigned long &n)
Definition: matrices.h:498
Implicit midpoint rule base class for the two implementations.
Definition: implicit_midpoint_rule.h:44
virtual ~IMRBase()
Destructor.
Definition: implicit_midpoint_rule.h:81
void calculate_predicted_values(Data *const &data_pt)
Definition: implicit_midpoint_rule.cc:111
void assign_initial_values_impulsive(Data *const &data_pt)
not implemented (??ds TODO)
Definition: implicit_midpoint_rule.h:125
void shift_time_values(Data *const &data_pt)
Definition: implicit_midpoint_rule.cc:39
virtual void set_weights()=0
Setup weights for time derivative calculations.
void shift_time_positions(Node *const &node_pt)
Definition: implicit_midpoint_rule.cc:57
void set_predictor_weights()
Definition: implicit_midpoint_rule.h:122
double temporal_error_in_position(Node *const &node_pt, const unsigned &i)
Definition: implicit_midpoint_rule.h:146
unsigned ndt() const
Number of timestep increments that are required by the scheme.
Definition: implicit_midpoint_rule.h:97
void set_error_weights()
Definition: implicit_midpoint_rule.h:118
unsigned order() const
Actual order (accuracy) of the scheme.
Definition: implicit_midpoint_rule.h:91
virtual unsigned nprev_values_for_value_at_evaluation_time() const =0
unsigned nprev_values() const
??ds
Definition: implicit_midpoint_rule.h:103
double temporal_error_in_value(Data *const &data_pt, const unsigned &i)
Definition: implicit_midpoint_rule.cc:122
void calculate_predicted_positions(Node *const &node_pt)
Definition: implicit_midpoint_rule.h:139
void assign_initial_positions_impulsive(Node *const &node_pt)
Definition: implicit_midpoint_rule.h:131
IMRBase(const bool &adaptive=false)
Constructor with initialisation.
Definition: implicit_midpoint_rule.h:47
Definition: implicit_midpoint_rule.h:220
void operator=(const IMRByBDF &dummy)
Inaccessible assignment operator.
Definition: implicit_midpoint_rule.h:263
bool Update_pinned
Should we update pinned variables after the half-step?
Definition: implicit_midpoint_rule.h:256
void actions_after_timestep(Problem *problem_pt)
Definition: implicit_midpoint_rule.cc:204
unsigned nprev_values_for_value_at_evaluation_time() const
Definition: implicit_midpoint_rule.h:243
void set_weights()
Setup weights for time derivative calculations.
Definition: implicit_midpoint_rule.h:232
IMRByBDF(const IMRByBDF &dummy)
Inaccessible copy constructor.
Definition: implicit_midpoint_rule.h:260
IMRByBDF(const bool &adaptive=false)
Constructor with initialisation.
Definition: implicit_midpoint_rule.h:223
virtual ~IMRByBDF()
Destructor.
Definition: implicit_midpoint_rule.h:229
void actions_before_timestep(Problem *problem_pt)
Half the timestep before starting solve.
Definition: implicit_midpoint_rule.cc:140
Definition: implicit_midpoint_rule.h:167
IMR(const IMR &dummy)
Inaccessible copy constructor.
Definition: implicit_midpoint_rule.h:205
virtual ~IMR()
Destructor, predictor_pt handled by base.
Definition: implicit_midpoint_rule.h:179
void operator=(const IMR &dummy)
Inaccessible assignment operator.
Definition: implicit_midpoint_rule.h:208
unsigned nprev_values_for_value_at_evaluation_time() const
Definition: implicit_midpoint_rule.h:198
IMR(const bool &adaptive=false)
Constructor with initialisation.
Definition: implicit_midpoint_rule.h:176
void set_weights()
Setup weights for time derivative calculations.
Definition: implicit_midpoint_rule.h:182
Definition: nodes.h:906
Definition: oomph_definitions.h:222
Definition: problem.h:151
Definition: timesteppers.h:231
DenseMatrix< double > Weight
Storage for the weights associated with the timestepper.
Definition: timesteppers.h:237
bool Predict_by_explicit_step
Definition: timesteppers.h:260
Time * Time_pt
Pointer to discrete time storage scheme.
Definition: timesteppers.h:234
std::string Type
Definition: timesteppers.h:241
bool Is_steady
Definition: timesteppers.h:251
int Predictor_storage_index
Definition: timesteppers.h:273
bool Adaptive_Flag
Definition: timesteppers.h:245
double & dt(const unsigned &t=0)
Definition: timesteppers.h:136
int adaptive
Definition: jeffery_hamel.cc:106
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86