generalised_timesteppers.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_GENERALISED_TIMESTEPPERS_HEADER
27 #define OOMPH_GENERALISED_TIMESTEPPERS_HEADER
28 
29 #include <typeinfo>
30 
31 // Config header generated by autoconfig
32 #ifdef HAVE_CONFIG_H
33 #include <oomph-lib-config.h>
34 #endif
35 
36 // OOMPH-LIB headers
37 #include "timesteppers.h"
38 
39 namespace oomph
40 {
41  //======================================================================
49  //====================================================================
51  {
52  protected:
53  // Set the number of entries that correspond to dof storage
55 
56  // Vector that represents the storage entries
57  // Vector<unsigned> Dof_storage_index;
58 
61  GeneralisedTimeStepper(const unsigned& n_tstorage,
62  const unsigned& max_deriv,
63  const unsigned& ndof_storage_entries = 1)
64  : TimeStepper(n_tstorage, max_deriv),
66  {
67  // Dof_storage_index.resize(1,0.0);
68  }
69 
72 
75 
77  void operator=(const GeneralisedTimeStepper&) = delete;
78 
79  public:
81  unsigned ndof_storage_entries() const
82  {
83  return Ndof_storage_entries;
84  }
85 
87  // unsigned dof_storage_index(const unsigned &i) {return
88  // Dof_storage_index[i];}
89  };
90 
91  //========================================================================
99  //====================================================================
101  {
102  // Store the offset for the derivatives
104 
105  // Store the offset for the current values of the dofs
107 
108  public:
113  : GeneralisedTimeStepper(3, 2),
116  {
117  Type = "ContinuationStorageScheme";
118  Is_steady = true;
119  }
120 
121 
124 
126  void modify_storage(GeneralisedTimeStepper* const& time_stepper_pt)
127  {
128  // Get the number of "dofs" in the existing timestepper
129  this->Ndof_storage_entries = time_stepper_pt->ndof_storage_entries();
130  // Get the current amount of storage
131  unsigned n_tstorage = time_stepper_pt->ntstorage();
132 
133  // Find the offsets which is always relative to the number of dofs stored
134  // in the existing timestepper
135  Dof_derivative_offset = n_tstorage;
136  Dof_current_offset = n_tstorage + this->Ndof_storage_entries;
137 
138  // Set the new amount of storage twice the dofs to store parameter
139  // derivatives and initial values plus the original storage
140  unsigned n_new_tstorage = 2 * this->Ndof_storage_entries + n_tstorage;
141 
142  // Resize the weights accordingly
143  Weight.resize(3, n_new_tstorage, 0.0);
144  // Set the weight for the zero-th derivative which is always 1.0
145  Weight(0, 0) = 1.0;
146  }
147 
148 
150  void operator=(const ContinuationStorageScheme&) = delete;
151 
154  unsigned order() const
155  {
156  return 0;
157  }
158 
161  {
162  Is_steady = true;
163  }
164 
167  void assign_initial_values_impulsive(Data* const& data_pt)
168  {
170  "Cannot perform impulsive start for ContinuationStorageScheme",
173  }
174 
178  {
180  "Cannot perform impulsive start for ContinuationStorageScheme",
183  }
184 
186  void shift_time_values(Data* const& data_pt)
187  {
188  throw OomphLibError(
189  "Cannot shift time values forContinuationStorageScheme",
192  }
193 
195  void shift_time_positions(Node* const& node_pt)
196  {
197  throw OomphLibError(
198  "Cannot shift time positions forContinuationStorageScheme",
201  }
202 
204  void set_weights() {}
205 
207  unsigned nprev_values() const
208  {
209  return 0;
210  }
211 
213  unsigned ndt() const
214  {
215  return 0;
216  }
217 
221  void set_consistent_pinned_values(Data* const& data_pt)
222  {
223 #ifdef PARANOID
224  // If the data is not associated with the continuation time stepper then
225  // complain
226  if (this != data_pt->time_stepper_pt())
227  {
228  std::ostringstream error_stream;
229  error_stream
230  << "Data object " << data_pt << " has timestepper of type "
231  << typeid(data_pt->time_stepper_pt()).name() << "\n"
232  << "Please set the data's timestepper to be a "
233  << "ContinuationStorageScheme before calling this function\n";
234  throw OomphLibError(
235  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
236  }
237 #endif
238 
239  // Loop over the values in the data object
240  const unsigned n_value = data_pt->nvalue();
241  for (unsigned i = 0; i < n_value; ++i)
242  {
243  // Only bother to do anything if the value is pinned and not a copy
244  if (data_pt->is_pinned(i) && (data_pt->is_a_copy(i) == false))
245  {
246  // ASSUMPTION storage is always at the "front"
247  for (unsigned t = 0; t < this->Ndof_storage_entries; t++)
248  {
249  // Set the stored derivatve to be zero
250  data_pt->set_value(Dof_derivative_offset + t, i, 0.0);
251  // Set the stored current value to be the same as the present value
252  data_pt->set_value(Dof_current_offset + t, i, data_pt->value(t, i));
253  }
254  }
255  }
256  }
257 
261  void set_consistent_pinned_positions(Node* const& node_pt)
262  {
263  // Only need to do anything if this is a solid node
264  if (SolidNode* const solid_node_pt = dynamic_cast<SolidNode*>(node_pt))
265  {
266 #ifdef PARANOID
267  // If the data is not associated with the continuation time stepper then
268  // complain
269  if (this != node_pt->position_time_stepper_pt())
270  {
271  std::ostringstream error_stream;
272  error_stream
273  << "Node object " << node_pt << " has position timestepper of type "
274  << typeid(node_pt->position_time_stepper_pt()).name() << "\n"
275  << "Please set the Node's position timestepper to be a "
276  << "ContinuationStorageScheme before calling this function\n";
277  throw OomphLibError(error_stream.str(),
280  }
281 #endif
282 
283  // Find the number of coordinates
284  const unsigned n_dim = solid_node_pt->ndim();
285  // Find the number of position types
286  const unsigned n_position_type = solid_node_pt->nposition_type();
287 
288  // Loop over physical coordinates
289  for (unsigned i = 0; i < n_dim; i++)
290  {
291  // Set the appropriate values if it's not a copy
292  if (solid_node_pt->position_is_a_copy(i) == false)
293  {
294  // Loop over generalised dofs
295  for (unsigned k = 0; k < n_position_type; k++)
296  {
297  // If it's pinned then set the "history" values
298  if (solid_node_pt->position_is_pinned(k, i))
299  {
300  for (unsigned t = 0; t < Ndof_storage_entries; t++)
301  {
302  // Set the derivative to 0
303  solid_node_pt->x_gen(Dof_derivative_offset + t, k, i) = 0.0;
304  // Set the stored current value to the present value
305  solid_node_pt->x_gen(Dof_current_offset + t, k, i) =
306  solid_node_pt->x_gen(t, k, i);
307  }
308  }
309  }
310  }
311  }
312  }
313  }
314 
315  // Return the stored derivative offset
317  {
318  return Dof_derivative_offset;
319  }
320 
321  // Return the offset for the current values
323  {
324  return Dof_current_offset;
325  }
326  };
327 
328 } // namespace oomph
329 
330 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: generalised_timesteppers.h:101
void operator=(const ContinuationStorageScheme &)=delete
Broken assignment operator.
void shift_time_positions(Node *const &node_pt)
Broken shifting of time positions.
Definition: generalised_timesteppers.h:195
void assign_initial_values_impulsive(Data *const &data_pt)
Definition: generalised_timesteppers.h:167
void set_consistent_pinned_values(Data *const &data_pt)
Definition: generalised_timesteppers.h:221
ContinuationStorageScheme(const ContinuationStorageScheme &)=delete
Broken copy constructor.
void modify_storage(GeneralisedTimeStepper *const &time_stepper_pt)
Modify the scheme based on the underlying timestepper.
Definition: generalised_timesteppers.h:126
void set_weights()
Set the weights (Do nothing)
Definition: generalised_timesteppers.h:204
void assign_initial_positions_impulsive(Node *const &node_pt)
Definition: generalised_timesteppers.h:177
void shift_time_values(Data *const &data_pt)
Broken shifting of time values.
Definition: generalised_timesteppers.h:186
unsigned nprev_values() const
Number of previous values available.
Definition: generalised_timesteppers.h:207
unsigned Dof_current_offset
Definition: generalised_timesteppers.h:106
unsigned dof_current_offset()
Definition: generalised_timesteppers.h:322
unsigned Dof_derivative_offset
Definition: generalised_timesteppers.h:103
unsigned order() const
Definition: generalised_timesteppers.h:154
unsigned dof_derivative_offset()
Definition: generalised_timesteppers.h:316
void set_consistent_pinned_positions(Node *const &node_pt)
Definition: generalised_timesteppers.h:261
void undo_make_steady()
This is a steady scheme, so you can't do this.
Definition: generalised_timesteppers.h:160
unsigned ndt() const
Number of timestep increments that need to be stored by the scheme.
Definition: generalised_timesteppers.h:213
ContinuationStorageScheme()
Definition: generalised_timesteppers.h:112
Definition: nodes.h:86
TimeStepper *& time_stepper_pt()
Return the pointer to the timestepper.
Definition: nodes.h:238
void set_value(const unsigned &i, const double &value_)
Definition: nodes.h:271
virtual bool is_a_copy() const
Definition: nodes.h:253
unsigned nvalue() const
Return number of values stored in data object (incl pinned ones).
Definition: nodes.h:483
double value(const unsigned &i) const
Definition: nodes.h:293
bool is_pinned(const unsigned &i) const
Test whether the i-th variable is pinned (1: true; 0: false).
Definition: nodes.h:417
void resize(const unsigned long &n)
Definition: matrices.h:498
Definition: generalised_timesteppers.h:51
unsigned ndof_storage_entries() const
Return the number of entries that correspond to dof storage.
Definition: generalised_timesteppers.h:81
void operator=(const GeneralisedTimeStepper &)=delete
Broken assignment operator.
unsigned Ndof_storage_entries
Definition: generalised_timesteppers.h:54
GeneralisedTimeStepper(const GeneralisedTimeStepper &)=delete
Broken copy constructor.
GeneralisedTimeStepper()
Broken empty constructor.
Definition: generalised_timesteppers.h:71
GeneralisedTimeStepper(const unsigned &n_tstorage, const unsigned &max_deriv, const unsigned &ndof_storage_entries=1)
Definition: generalised_timesteppers.h:61
Definition: nodes.h:906
TimeStepper *& position_time_stepper_pt()
Return a pointer to the position timestepper.
Definition: nodes.h:1022
Definition: oomph_definitions.h:222
Definition: oomph_definitions.h:267
Definition: nodes.h:1686
Definition: timesteppers.h:231
DenseMatrix< double > Weight
Storage for the weights associated with the timestepper.
Definition: timesteppers.h:237
unsigned ntstorage() const
Definition: timesteppers.h:601
std::string Type
Definition: timesteppers.h:241
bool Is_steady
Definition: timesteppers.h:251
char char char int int * k
Definition: level2_impl.h:374
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
string name
Definition: plotDoE.py:33
t
Definition: plotPSD.py:36
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86