spines.cc
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// Version 1.0; svn revision $LastChangedRevision$
7 //LIC//
8 //LIC// $LastChangedDate$
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 //Functions for the SpineNode/SpineElement/SpineMesh classes
31 //oomph-lib headers
32 
33 #include "spines.h"
34 #include <cstdlib>
35 
36 namespace oomph
37 {
38 
39 
40 ///////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////
42 //Functions for the SpineNode class
43 ///////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////
45 
46 
47 //===================================================================
48 /// Update function, call the update function in the Node's SpineMesh.
49 //===================================================================
50 void SpineNode::node_update(const bool& update_all_time_levels_for_new_node)
51 {
53 
54  //Perform any auxiliary updates (i.e. reseting boundary conditions)
55  if(Aux_node_update_fct_pt != 0)
56  {
58  }
59 }
60 
61 
62 
63 
64 
65 ///////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////
67 //Functions for the SpineMesh class
68 ///////////////////////////////////////////////////////////////////
69 ///////////////////////////////////////////////////////////////////
70 
71 
72 //=============================================================
73 /// Destructor to clean up the memory allocated to the spines
74 //=============================================================
76 {
77  //Set the range of Spine_pt
78  unsigned long Spine_pt_range = Spine_pt.size();
79  //Loop over the entries in reverse and free memory
80  for(unsigned long i=Spine_pt_range;i>0;i--)
81  {
82  delete Spine_pt[i-1]; Spine_pt[i-1] = 0;
83  }
84 }
85 
86 //============================================================
87 /// Update function to update all nodes of mesh.
88 /// [Doesn't make sense to use this mesh with SolidElements anyway,
89 /// so we buffer the case if update_all_solid_nodes (which defaults
90 /// to false) is set to true.]
91 //============================================================
92 void SpineMesh::node_update(const bool& update_all_solid_nodes)
93 {
94 #ifdef PARANOID
95  if (update_all_solid_nodes)
96  {
97  std::string error_message =
98  "Doesn't make sense to use an SpineMesh with\n";
99  error_message +=
100  "SolidElements so specifying update_all_solid_nodes=true\n";
101  error_message += "doesn't make sense either\n";
102 
103  throw OomphLibError(error_message,
104  OOMPH_CURRENT_FUNCTION,
105  OOMPH_EXCEPTION_LOCATION);
106  }
107 #endif
108 
109  //Loop over all the nodes
110  unsigned long Node_pt_range = Node_pt.size();
111  for(unsigned long l=0;l<Node_pt_range;l++)
112  {
113 #ifdef PARANOID
114  if(!dynamic_cast<SpineNode*>(Node_pt[l]))
115  {
116  std::ostringstream error_stream;
117  error_stream
118  << "Error: Node " << l << "is a " << typeid(Node_pt[l]).name()
119  << ", not a SpineNode" << std::endl;
120  throw OomphLibError(error_stream.str(),
121  OOMPH_CURRENT_FUNCTION,
122  OOMPH_EXCEPTION_LOCATION);
123  }
124 #endif
125 
126  //Need to cast to spine node to get to update function
127  dynamic_cast<SpineNode*>(Node_pt[l])->node_update();
128  }
129 }
130 
131 //====================================================================
132 /// Assign (global) equation numbers to spines, nodes and elements
133 //====================================================================
136 {
137  //Find the current number of dofs
138  unsigned long equation_number = Dof_pt.size();
139 
140  // Loop over spines and set global equation numbers for the spine heights
141  // (they are the only Data items whose global eqn numbers are assigned
142  // here)
143  unsigned long Spine_pt_range = Spine_pt.size();
144  for(unsigned long i=0;i<Spine_pt_range;i++)
145  {
146  Spine_pt[i]->spine_height_pt()->assign_eqn_numbers(equation_number,Dof_pt);
147  }
148 
149  //Return the total number of equations
150  return(equation_number);
151 }
152 
153 //====================================================================
154 /// \short Function to describe the dofs of the Spine. The ostream
155 /// specifies the output stream to which the description
156 /// is written; the string stores the currently
157 /// assembled output that is ultimately written to the
158 /// output stream by Data::describe_dofs(...); it is typically
159 /// built up incrementally as we descend through the
160 /// call hierarchy of this function when called from
161 /// Problem::describe_dofs(...)
162 //====================================================================
163  void SpineMesh::describe_spine_dofs(std::ostream& out,
164  const std::string& current_string) const
165  {
166  // Describe spine heights.
167  unsigned long Spine_pt_range = Spine_pt.size();
168  for(unsigned long i=0;i<Spine_pt_range;i++)
169  {
170  std::stringstream conversion;
171  conversion <<" of Spine Height "<<i<<current_string;
172  std::string in(conversion.str());
174  }
175  }
176 
177 //====================================================================
178 /// Assign time stepper to spines data
179 //====================================================================
181  const bool &preserve_existing_data)
182 {
183  // Loop over spines and set the time stepper for the spine heights
184  // (they are the only Data that are additional to the standard nodal and
185  // elemental)
186  const unsigned long n_spine = this->nspine();
187  for(unsigned long i=0;i<n_spine;i++)
188  {
189  this->Spine_pt[i]->spine_height_pt()->set_time_stepper(time_stepper_pt,
190  preserve_existing_data);
191  }
192 }
193 
194 //====================================================================
195 /// Set the data associated with pinned spine values to be consistent
196 /// for continuation when using the continuation storage scheme
197 //====================================================================
199  ContinuationStorageScheme* const &continuation_stepper_pt)
200 {
201  // Loop over spines and set consistent values by using the function
202  // provided by the continuation storage scheme
203  const unsigned long n_spine = this->nspine();
204  for(unsigned long i=0;i<n_spine;i++)
205  {
206  continuation_stepper_pt->set_consistent_pinned_values(
207  this->Spine_pt[i]->spine_height_pt());
208  }
209 }
210 
211 
212 //=====================================================================
213 /// Return true if the pointer addresses data stored within the spines,
214 /// false if not.
215 //=====================================================================
217  double* const &parameter_pt)
218 {
219  // Loop over spines and check their data
220  const unsigned long n_spine = this->nspine();
221  for(unsigned long i=0;i<n_spine;i++)
222  {
223  if(this->Spine_pt[i]->spine_height_pt()
224  ->does_pointer_correspond_to_value(parameter_pt))
225  {return true;}
226  }
227 
228  //If we haven't found it yet, then it's not present in the spine data
229  return false;
230 }
231 
232 //=======================================================================
233 /// Overload the dump function so that the spine data is also dumped
234 //=======================================================================
235 void SpineMesh::dump(std::ofstream &dump_file) const
236 {
237  //Call the standard mesh dump function
238  Mesh::dump(dump_file);
239 
240  //Now loop over the spine data and dump the spine height data
241  //The ASSUMPTION is that the geometric data is stored elsewhere and will
242  //be dumped elsewhere
243 
244  //Find the number of spines
245  unsigned long n_spine = nspine();
246  // Doc number of spines
247  dump_file << n_spine << " # number of spines " << std::endl;
248 
249  //Loop over the spines
250  for(unsigned long s=0;s<n_spine;s++)
251  {
252  spine_pt(s)->spine_height_pt()->dump(dump_file);
253  }
254 }
255 
256 //========================================================================
257 /// Overload the read function so that the spine data is also read
258 //========================================================================
259 void SpineMesh::read(std::ifstream &restart_file)
260 {
261  //Call the standard mesh read function
262  Mesh::read(restart_file);
263 
264  //Now loop over the spine data and dump the spine height data
265  //The ASSUMPTION is that the geometric data is stored elsewhere and will
266  //be dumped elsewhere
267 
268  //Get the number of spines
269  unsigned long n_spine = nspine();
270 
271  std::string input_string;
272  // Read line up to termination sign
273  getline(restart_file,input_string,'#');
274  //Ignore the restr of the line
275  restart_file.ignore(80,'\n');
276 
277  //check the number of spines
278  unsigned long check_n_spine = atoi(input_string.c_str());
279 
280  if(check_n_spine != n_spine)
281  {
282  std::ostringstream error_stream;
283  error_stream
284  << "Number of spines in the restart file, " << check_n_spine
285  << std::endl << "does not equal the number of spines in the mesh "
286  << n_spine << std::endl;
287 
288  throw OomphLibError(error_stream.str(),
289  OOMPH_CURRENT_FUNCTION,
290  OOMPH_EXCEPTION_LOCATION);
291  }
292 
293  //Loop over the spines and read the data
294  for(unsigned long s=0;s<n_spine;s++)
295  {
296  spine_pt(s)->spine_height_pt()->read(restart_file);
297  }
298 }
299 
300 }
virtual ~SpineMesh()
Destructor to clean up the memory allocated to the spines.
Definition: spines.cc:75
bool does_pointer_correspond_to_value(double *const &parameter_pt)
Check whether the pointer parameter_pt addresses internal data values.
Definition: nodes.cc:533
unsigned long assign_global_spine_eqn_numbers(Vector< double *> &Dof_pt)
Assign spines to Spine_pt vector of element.
Definition: spines.cc:135
cstr elem_len * i
Definition: cfortran.h:607
void node_update(const bool &update_all_solid_nodes=false)
Update function to update all nodes of mesh [Doesn&#39;t make sense to use this mesh with SolidElements a...
Definition: spines.cc:92
virtual void dump(std::ofstream &dump_file, const bool &use_old_ordering=true) const
Dump the data in the mesh into a file for restart.
Definition: mesh.cc:1027
virtual void describe_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the dofs of the Node. The ostream specifies the output stream to which the descr...
Definition: nodes.cc:905
AuxNodeUpdateFctPt Aux_node_update_fct_pt
Pointer to auxiliary update function – this can be used to update any nodal values following the upd...
Definition: nodes.h:913
void set_consistent_pinned_spine_values_for_continuation(ContinuationStorageScheme *const &continuation_stepper_pt)
Set any pinned spine "history" values to be consistent for continuation problems. ...
Definition: spines.cc:198
void node_update(const bool &update_all_time_levels_for_new_node=false)
Update function, call the update function in the Node&#39;s SpineMesh.
Definition: spines.cc:50
void describe_spine_dofs(std::ostream &out, const std::string &current_string) const
Function to describe the dofs of the Spine. The ostream specifies the output stream to which the desc...
Definition: spines.cc:163
static char t char * s
Definition: cfortran.h:572
void set_time_stepper(TimeStepper *const &time_stepper_pt, const bool &preserve_existing_data)
Set a new timestepper by resizing the appropriate storage. If already assigned the equation numbering...
Definition: nodes.cc:392
void read(std::ifstream &restart_file)
Read data object from a file.
Definition: nodes.cc:635
virtual void assign_eqn_numbers(unsigned long &global_ndof, Vector< double *> &dof_pt)
Assign global equation numbers; increment global number of unknowns, global_ndof; and add any new dof...
Definition: nodes.cc:861
void dump(std::ostream &dump_file) const
Dump the data object to a file.
Definition: nodes.cc:608
virtual void spine_node_update(SpineNode *spine_node_pt)=0
Update function for given spine node – this must be implemented by all specific SpineMeshes.
GeneralisedTimestepper used to store the arclength derivatives and pervious solutions required in con...
Spine * Spine_pt
Private internal data pointer to a spine.
Definition: spines.h:316
TimeStepper *& time_stepper_pt()
Return the pointer to the timestepper.
Definition: nodes.h:246
void set_consistent_pinned_values(Data *const &data_pt)
Set consistent values of the derivatives and current value when the data is pinned. This must be done by the "timestepper" because only it knows the local storage scheme.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn&#39;t been defined.
void set_spine_time_stepper(TimeStepper *const &time_stepper_pt, const bool &preserve_existing_data)
Set the time stepper forthe spine data that is stored in the mesh.
Definition: spines.cc:180
void dump(std::ofstream &dump_file) const
Overload the dump function so that the spine data is dumped.
Definition: spines.cc:235
SpineMesh * Spine_mesh_pt
Pointer to SpineMesh that this node is a part of. (The mesh implements the node update function(s)) ...
Definition: spines.h:323
Data *& spine_height_pt()
Access function to Data object that stores the spine height.
Definition: spines.h:164
Spine *& spine_pt()
Access function to spine.
Definition: spines.h:347
bool does_pointer_correspond_to_spine_data(double *const &parameter_pt)
Check whether the pointer parameter_pt addresses data stored in the spines.
Definition: spines.cc:216
Base class for time-stepping schemes. Timestepper provides an approximation of the temporal derivativ...
Definition: timesteppers.h:219
virtual void read(std::ifstream &restart_file)
Read solution from restart file.
Definition: mesh.cc:1070
void read(std::ifstream &restart_file)
Overload the read function so that the spine data is read from the restart file.
Definition: spines.cc:259