hijacked_elements.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 // Header file for hijacked elements
27 
28 // Include guards to prevent multiple inclusion of the header
29 #ifndef OOMPH_HIJACKED_ELEMENTS_HEADER
30 #define OOMPH_HIJACKED_ELEMENTS_HEADER
31 
32 
33 // oomph-lib header
34 #include "elements.h"
35 #include "spines.h"
36 
37 namespace oomph
38 {
39  //========================================================================
43  //========================================================================
45  {
46  public:
51  {
52  // Set the default value of the pointer to the residuals multiplier.
53  // The default value is zero, so that the element is "completely hijacked"
54  // and the exisiting contributions to the residuals and jacobian are
55  // totally wiped
57  }
58 
60  virtual ~HijackedElementBase();
61 
65  {
67  }
68 
70  inline const double& residual_multiplier() const
71  {
72  return *Residual_multiplier_pt;
73  }
74 
76  inline double*& residual_multiplier_pt()
77  {
79  }
80 
81  protected:
87 
92 
99 
103 
106  void hijack_global_eqn(long* const& global_eqn_pt);
107 
110  void unhijack_global_eqn(long* const& global_eqn_pt);
111  };
112 
113 
114  //========================================================================
129  //========================================================================
130  template<class ELEMENT>
131  class Hijacked : public virtual ELEMENT, public virtual HijackedElementBase
132  {
133  public:
135  Hijacked() : ELEMENT(), HijackedElementBase() {}
136 
138  Hijacked(FiniteElement* const& element_pt, const int& face_index)
139  : ELEMENT(element_pt, face_index), HijackedElementBase()
140  {
141  }
142 
143 
146  Hijacked(FiniteElement* const& element_pt,
147  const int& face_index,
148  const unsigned& id = 0)
149  : ELEMENT(element_pt, face_index, id), HijackedElementBase()
150  {
151  }
152 
153 
160  Data* hijack_internal_value(const unsigned& n,
161  const unsigned& i,
162  const bool& return_data = true)
163  {
164  // Initialise pointer to zero
165  Data* temp_data_pt = 0;
166 
167  // If desired,
168  // Create a new Data object containing only the value that is to be
169  // hijacked
170  if (return_data)
171  {
172  temp_data_pt = new HijackedData(i, this->internal_data_pt(n));
173  }
174 
175  // Mark the value as hijacked
176  hijack_global_eqn(this->internal_data_pt(n)->eqn_number_pt(i));
177 
178  // Return the pointer to the data
179  return temp_data_pt;
180  }
181 
182 
188  Data* hijack_external_value(const unsigned& n,
189  const unsigned& i,
190  const bool& return_data = true)
191  {
192  // Initialise pointer to zero
193  Data* temp_data_pt = 0;
194  // If desired
195  // create a new Data object containing only the value that is to be
196  // hijacked
197  if (return_data)
198  {
199  temp_data_pt = new HijackedData(i, this->external_data_pt(n));
200  }
201 
202  // Mark the value as hijacked
203  hijack_global_eqn(this->external_data_pt(n)->eqn_number_pt(i));
204 
205  // Return the pointer to the data
206  return temp_data_pt;
207  }
208 
214  Data* hijack_nodal_value(const unsigned& n,
215  const unsigned& i,
216  const bool& return_data = true)
217  {
218  // Initialise pointer to zero
219  Data* temp_data_pt = 0;
220  // If desired
221  // create a new Data object containing only the value that is to be
222  // hijacked
223  if (return_data)
224  {
225  temp_data_pt = new HijackedData(i, this->node_pt(n));
226  }
227 
228  // Mark the value as hijacked
229  hijack_global_eqn(this->node_pt(n)->eqn_number_pt(i));
230 
231  // Return the pointer to the data, which may be null
232  return temp_data_pt;
233  }
234 
241  const unsigned& i,
242  const bool& return_data = true)
243  {
244  // Can we do the casting?
245  SolidNode* solid_node_pt = dynamic_cast<SolidNode*>(this->node_pt(n));
246  if (solid_node_pt == 0)
247  {
248  std::string error_message = "Failed to cast to SolidNode\n ";
249  error_message += "You may be trying to hijack a non-elastic element\n";
250 
251  throw OomphLibError(
253  }
254 
255  // Initialise pointer to zero
256  Data* temp_data_pt = 0;
257  // If desired
258  // create a new Data object containing only the value that is to be
259  // hijacked
260  if (return_data)
261  {
262  temp_data_pt =
263  new HijackedData(i, solid_node_pt->variable_position_pt());
264  }
265 
266  // Mark the value as hijacked
268  solid_node_pt->variable_position_pt()->eqn_number_pt(i));
269 
270  // Return the pointer to the data
271  return temp_data_pt;
272  }
273 
279  Data* hijack_nodal_spine_value(const unsigned& n,
280  const unsigned& i,
281  const bool& return_data = true)
282  {
283  // Can we actually do this casting
284  SpineNode* spine_node_pt = dynamic_cast<SpineNode*>(this->node_pt(n));
285  if (spine_node_pt == 0)
286  {
287  std::string error_message = "Failed to cast to SpineNode\n ";
288  error_message += "You may be trying to hijack a non-spine element\n";
289 
290  throw OomphLibError(
292  }
293 
294  // Initialise pointer to zero
295  Data* temp_data_pt = 0;
296  // If desired
297  // create a new Data object containing only the value that is to be
298  // hijacked
299  if (return_data)
300  {
301  temp_data_pt =
302  new HijackedData(i, spine_node_pt->spine_pt()->spine_height_pt());
303  }
304 
305  // Mark the data as hijacked
307  spine_node_pt->spine_pt()->spine_height_pt()->eqn_number_pt(i));
308 
309  // Return the pointer to the data
310  return temp_data_pt;
311  }
312 
313 
318  void assign_local_eqn_numbers(const bool& store_local_dof_pt)
319  {
320  // If things have already been allocated,
321  // clear the local hijacked array, so that if the equation numbers
322  // are reassigned after changes in the boundary conditions, the
323  // correct terms will be in the array.
325  {
327  }
328  // Otherwise allocate it
329  else
330  {
332  }
333 
334 
335  // Call the hijacked element's assign_local_eqn_numbers
336  ELEMENT::assign_local_eqn_numbers(store_local_dof_pt);
337 
338  // If any values have been hijacked, we need to find the corresponding
339  // local equation numbers
341  {
342  // Now loop over the local array that stores GLOBAL equation numbers
343  // to check if any of the local values have in fact been hijacked
344  // by "somebody"
345  unsigned n_dof = this->ndof();
346  for (unsigned i = 0; i < n_dof; i++)
347  {
348  // Loop over *all* hijacked data
349  for (std::set<long*>::iterator it =
351  it != Hijacked_global_eqn_number_pt->end();
352  ++it)
353  {
354  // If the hijacked (global!) equation is not pinned
355  if (*(*it) >= 0)
356  {
357  // Get the (unsigned) global equation number:
358  // Note that it is only unsigned AFTER the test above.
359  unsigned long hijacked_eqn_number = *(*it);
360 
361  // If a GLOBAL variable used by this element is hijacked add the
362  // variable's LOCAL index to the array
363  if (hijacked_eqn_number == this->eqn_number(i))
364  {
365  Hijacked_local_eqn_number_pt->push_back(i);
366  break;
367  }
368  }
369  }
370  }
371  }
372  }
373 
377  void get_residuals(Vector<double>& residuals)
378  {
379  // Get parent redisuals
380  ELEMENT::get_residuals(residuals);
381  // Multiply any hijacked dofs by the residual multiplier
382  //(default value is zero)
383  unsigned n_hijacked = Hijacked_local_eqn_number_pt->size();
384  for (unsigned i = 0; i < n_hijacked; i++)
385  {
386  residuals[(*Hijacked_local_eqn_number_pt)[i]] *= residual_multiplier();
387  }
388  }
389 
390 
395  void get_jacobian(Vector<double>& residuals, DenseMatrix<double>& jacobian)
396  {
397  // Call the element's get jacobian function
398  ELEMENT::get_jacobian(residuals, jacobian);
399  // Wipe any hijacked dofs
400  unsigned n_hijacked = Hijacked_local_eqn_number_pt->size();
401  unsigned n_dof = this->ndof();
402  for (unsigned i = 0; i < n_hijacked; i++)
403  {
404  // Multiply any hijacked dofs by the residual multiplier
405  //(default value is zero)
406  residuals[(*Hijacked_local_eqn_number_pt)[i]] *= residual_multiplier();
407  // Multiply the row in the Jacobian matrix by the residual
408  // multiplier for consistency
409  for (unsigned j = 0; j < n_dof; j++)
410  {
411  jacobian((*Hijacked_local_eqn_number_pt)[i], j) *=
413  }
414  }
415  }
416  };
417 
418 
419  //============================================================================
422  //============================================================================
423  template<class ELEMENT>
424  class FaceGeometry<Hijacked<ELEMENT>> : public virtual FaceGeometry<ELEMENT>
425  {
426  public:
428  FaceGeometry() : FaceGeometry<ELEMENT>() {}
429 
430  protected:
431  };
432 
433  //============================================================================
436  //============================================================================
437  template<class ELEMENT>
439  : public virtual FaceGeometry<FaceGeometry<ELEMENT>>
440  {
441  public:
444 
445  protected:
446  };
447 
448  //============================================================================
451  //============================================================================
452  template<class ELEMENT>
454  : public virtual FaceGeometry<FaceGeometry<ELEMENT>>
455  {
456  public:
459 
460  protected:
461  };
462 
463 
464 } // namespace oomph
465 
466 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Definition: nodes.h:86
long * eqn_number_pt(const unsigned &i)
Return the pointer to the equation number of the i-th stored variable.
Definition: nodes.h:358
FaceGeometry()
Constructor.
Definition: hijacked_elements.h:443
FaceGeometry()
Constructor.
Definition: hijacked_elements.h:428
FaceGeometry()
Constructor.
Definition: hijacked_elements.h:458
Definition: elements.h:4998
Definition: elements.h:1313
Definition: nodes.h:575
Definition: hijacked_elements.h:45
void unhijack_all_data()
Definition: hijacked_elements.h:64
double * Residual_multiplier_pt
Definition: hijacked_elements.h:98
const double & residual_multiplier() const
Return the value of the residual multiplier.
Definition: hijacked_elements.h:70
double *& residual_multiplier_pt()
Return the pointer to the residual multiplier.
Definition: hijacked_elements.h:76
std::set< long * > * Hijacked_global_eqn_number_pt
Definition: hijacked_elements.h:86
void unhijack_global_eqn(long *const &global_eqn_pt)
Definition: hijacked_elements.cc:79
void hijack_global_eqn(long *const &global_eqn_pt)
Definition: hijacked_elements.cc:62
HijackedElementBase()
Definition: hijacked_elements.h:49
Vector< int > * Hijacked_local_eqn_number_pt
Definition: hijacked_elements.h:91
virtual ~HijackedElementBase()
Destructor, destroy the storage for the equation numbers.
Definition: hijacked_elements.cc:41
static double Default_residual_multiplier
Definition: hijacked_elements.h:102
Definition: hijacked_elements.h:132
void get_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: hijacked_elements.h:395
Data * hijack_nodal_position_value(const unsigned &n, const unsigned &i, const bool &return_data=true)
Definition: hijacked_elements.h:240
Data * hijack_nodal_spine_value(const unsigned &n, const unsigned &i, const bool &return_data=true)
Definition: hijacked_elements.h:279
Hijacked(FiniteElement *const &element_pt, const int &face_index)
Constructor used for hijacking face elements.
Definition: hijacked_elements.h:138
Data * hijack_internal_value(const unsigned &n, const unsigned &i, const bool &return_data=true)
Definition: hijacked_elements.h:160
Data * hijack_external_value(const unsigned &n, const unsigned &i, const bool &return_data=true)
Definition: hijacked_elements.h:188
Hijacked()
Constructor, call the constructors of the base elements.
Definition: hijacked_elements.h:135
Hijacked(FiniteElement *const &element_pt, const int &face_index, const unsigned &id=0)
Definition: hijacked_elements.h:146
Data * hijack_nodal_value(const unsigned &n, const unsigned &i, const bool &return_data=true)
Definition: hijacked_elements.h:214
void get_residuals(Vector< double > &residuals)
Definition: hijacked_elements.h:377
void assign_local_eqn_numbers(const bool &store_local_dof_pt)
Definition: hijacked_elements.h:318
Definition: oomph_definitions.h:222
Definition: nodes.h:1686
Data *const & variable_position_pt() const
Pointer to variable_position data (const version)
Definition: nodes.h:1765
Definition: spines.h:328
Spine *& spine_pt()
Access function to spine.
Definition: spines.h:372
Data *& spine_height_pt()
Access function to Data object that stores the spine height.
Definition: spines.h:156
void get_residuals(const Vector< double > &param, const Vector< double > &unknowns, Vector< double > &residuals)
Global residual fct.
Definition: spring_contact.cc:65
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
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2