element_with_external_element.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 the class
27 // ElementWithExternalElement which stores pointers to external elements
28 
29 // Include guards to prevent multiple inclusion of the header
30 #ifndef OOMPH_ELEMENT_WITH_EXTERNAL_ELEMENT_HEADER
31 #define OOMPH_ELEMENT_WITH_EXTERNAL_ELEMENT_HEADER
32 
33 // Config header generated by autoconfig
34 #ifdef HAVE_CONFIG_H
35 #include <oomph-lib-config.h>
36 #endif
37 
38 // Oomph-lib headers
39 #include "elements.h"
40 
41 namespace oomph
42 {
43  //========================================================================
54  //========================================================================
56  {
57  public:
61  : FiniteElement(),
66  Ninteraction(0),
67  Nintpt(0),
77  {
78  }
79 
82 
85 
87  void operator=(const ElementWithExternalElement&) = delete;
88 
91  {
92  // If either of the storage arrays is zero, then storage has not
93  // yet been allocated. Both arrays are allocated at once, so
94  // if one is zero both will (should) be
96  {
97  return false;
98  }
99  else
100  {
101  return true;
102  }
103  }
104 
107  FiniteElement*& external_element_pt(const unsigned& interaction_index,
108  const unsigned& ipt)
109  {
110 #ifdef PARANOID
112 #endif
113 #ifdef RANGE_CHECKING
114  range_check(interaction_index, ipt);
115 #endif
116  // Return the appropriate entry in the storage array
117  return External_element_pt[Nintpt * interaction_index + ipt];
118  }
119 
121  FiniteElement* const& external_element_pt(const unsigned& interaction_index,
122  const unsigned& ipt) const
123  {
124 #ifdef PARANOID
126 #endif
127 #ifdef RANGE_CHECKING
128  range_check(interaction_index, ipt);
129 #endif
130  // Return the appropriate entry in the storage array
131  return External_element_pt[Nintpt * interaction_index + ipt];
132  }
133 
137  const unsigned& interaction_index, const unsigned& ipt)
138  {
139 #ifdef PARANOID
141 #endif
142 #ifdef RANGE_CHECKING
143  range_check(interaction_index, ipt);
144 #endif
145  return External_element_local_coord[Nintpt * interaction_index + ipt];
146  }
147 
150  const unsigned& interaction_index, const unsigned& ipt) const
151  {
152 #ifdef PARANOID
154 #endif
155 #ifdef RANGE_CHECKING
156  range_check(interaction_index, ipt);
157 #endif
158  return External_element_local_coord[Nintpt * interaction_index + ipt];
159  }
160 
161 
165  void output_external_elements(std::ostream& outfile,
166  const unsigned& interaction_index);
167 
172 
175 
178  inline void set_ninteraction(const unsigned& n_interaction)
179  {
180  Ninteraction = n_interaction;
181  }
182 
184  unsigned ninteraction() const
185  {
186  return Ninteraction;
187  }
188 
192  Vector<std::set<FiniteElement*>> const& external_elements_pt,
193  std::set<std::pair<Data*, unsigned>>& paired_interaction_data);
194 
198  Vector<std::set<FiniteElement*>> const& external_elements_pt,
199  std::set<Data*>& external_geometric_data_pt);
200 
206  {
208  }
209 
213  {
214  // Find out how many external field data there are
215  const unsigned n_external_interaction_field_data =
217  // Create and populate a temporary vector
218  Vector<Data*> temp_data(n_external_interaction_field_data);
219  for (unsigned i = 0; i < n_external_interaction_field_data; i++)
220  {
221  temp_data[i] = External_interaction_field_data_pt[i];
222  }
223  // Return the temporary data
224  return temp_data;
225  }
226 
227 
233  {
235  }
236 
239  {
241  }
242 
245  {
247  }
248 
252  {
253  // Find out how many external field data there are
254  const unsigned n_external_interaction_geometric_data =
256  // Create and populate a temporary vector
257  Vector<Data*> temp_data(n_external_interaction_geometric_data);
258  for (unsigned i = 0; i < n_external_interaction_geometric_data; i++)
259  {
261  }
262  // Return the temporary data
263  return temp_data;
264  }
265 
272  {
274  }
275 
279  {
281  }
282 
287  {
289  }
290 
295  {
297  }
298 
302  {
304  }
305 
314  void describe_local_dofs(std::ostream& out,
315  const std::string& curr_string) const;
316 
317  protected:
321  const bool& store_local_dof_pt)
322  {
323  // Call the external stuff first so that it is near the front of the
324  // list for fast searches when using indexing by global dof for
325  // analytic calculation of interaction blocks.
327  store_local_dof_pt);
328  // Now call the underlying equation numbering
330  store_local_dof_pt);
331  }
332 
337  const bool& store_local_dof_pt);
338 
339 
346  Vector<double>& residuals, DenseMatrix<double>& jacobian)
347  {
348  // Get the contribution from the external field data
350  jacobian);
351  // Get the contribution from the external geometric data
353  jacobian);
354  }
355 
361  DenseMatrix<double>& jacobian)
362  {
363  const unsigned n_dof = this->ndof();
364  // Allocate storage for the residuals
365  Vector<double> residuals(n_dof, 0.0);
366  // Get the residuals for the entire element
367  get_residuals(residuals);
368  // Call the jacobian calculation
370  }
371 
372 
379  Vector<double>& residuals, DenseMatrix<double>& jacobian);
380 
386  DenseMatrix<double>& jacobian)
387  {
388  const unsigned n_dof = this->ndof();
389  // Allocate storage for the residuals
390  Vector<double> residuals(n_dof, 0.0);
391  // Get the residuals for the entire element
392  get_residuals(residuals);
393  // Call the jacobian calculation
395  jacobian);
396  }
397 
404  Vector<double>& residuals, DenseMatrix<double>& jacobian);
405 
412  DenseMatrix<double>& jacobian)
413  {
414  const unsigned n_dof = this->ndof();
415  // Allocate storage for the residuals
416  Vector<double> residuals(n_dof, 0.0);
417  // Get the residuals for the entire element
418  get_residuals(residuals);
419  // Call the jacobian calculation
421  jacobian);
422  }
423 
428  DenseMatrix<double>& jacobian)
429  {
430  // Add the contribution to the residuals
432  // Allocate storage for the full residuals (residuals of entire element)
433  const unsigned n_dof = this->ndof();
434  Vector<double> full_residuals(n_dof);
435  // Get the residuals for the entire element
436  get_residuals(full_residuals);
437  // Add the internal and external by finite differences
438  fill_in_jacobian_from_internal_by_fd(full_residuals, jacobian);
439  fill_in_jacobian_from_external_by_fd(full_residuals, jacobian);
440  fill_in_jacobian_from_nodal_by_fd(full_residuals, jacobian);
442  jacobian);
443  }
444 
445 
451 
457 
462  const unsigned& i)
463  {
464  }
465 
471  const unsigned& i)
472  {
474  }
475 
476 
482 
488 
493  const unsigned& i)
494  {
495  }
496 
502  const unsigned& i)
503  {
505  }
506 
509 
512 
516 
520 
521  private:
524  {
525  // If either of the storage arrays is zero, then storage has not
526  // yet been allocated. Both arrays are allocated at once, so
527  // if one is zero both will (should) be
529  {
530  std::ostringstream error_stream;
531  error_stream
532  << "Storage for the external elements has not been allocated.\n"
533  << "initialise_external_element_storage() must be called.\n"
534  << "This tends to be done automatically during the multi-domain\n"
535  << "setup procedures -- you're most likely to get this error\n"
536  << "because you have not specified the number of interactions\n"
537  << "that your ElementWithExternalElement is involved in.\n"
538  << "You ought to specify this with a call to\n\n"
539  << " ElementWithExternalElement::set_ninteraction(...)\n\n";
540  throw OomphLibError(
541  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
542  }
543  }
544 
546  void range_check(const unsigned& interaction_index,
547  const unsigned& ipt) const
548  {
549  // Boolean flag used to indicate range error
550  bool range_error = false;
551  // String for the error message
552  std::ostringstream error_message;
553  // If there is a range error in the interaction index
554  if (interaction_index >= Ninteraction)
555  {
556  error_message << "Range Error: Interaction " << interaction_index
557  << " is not in the range (0," << Ninteraction - 1 << ")";
558  // There has been a range error
559  range_error = true;
560  }
561 
562  // If there is a range error in the integration point
563  if (ipt >= Nintpt)
564  {
565  error_message << "Range Error: Integration point " << ipt
566  << " is not in the range (0," << Nintpt - 1 << ")";
567  range_error = true;
568  }
569 
570 
571  // If there has been a range error report it
572  if (range_error)
573  {
574  throw OomphLibError(error_message.str(),
577  }
578  }
579 
581  unsigned Ninteraction;
582 
584  unsigned Nintpt;
585 
589 
592 
595 
596 
601 
606 
610 
614 
619 
623  };
624 } // namespace oomph
625 
626 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: nodes.h:86
Definition: element_with_external_element.h:56
virtual void update_before_external_interaction_field_fd()
Definition: element_with_external_element.h:450
void output_external_elements(std::ostream &outfile, const unsigned &interaction_index)
Definition: element_with_external_element.cc:798
ElementWithExternalElement(const ElementWithExternalElement &)=delete
Broken copy constructor.
unsigned Nexternal_interaction_field_data
Number of external interaction field data.
Definition: element_with_external_element.h:591
Vector< double > & external_element_local_coord(const unsigned &interaction_index, const unsigned &ipt)
Definition: element_with_external_element.h:136
FiniteElement *const & external_element_pt(const unsigned &interaction_index, const unsigned &ipt) const
Access function to source element, const version.
Definition: element_with_external_element.h:121
bool storage_has_been_allocated() const
Helper function to check if storage has actually been allocated.
Definition: element_with_external_element.h:90
void set_ninteraction(const unsigned &n_interaction)
Definition: element_with_external_element.h:178
bool external_geometric_data_is_included() const
Definition: element_with_external_element.h:301
void initialise_external_element_storage()
Definition: element_with_external_element.cc:76
void include_external_geometric_data()
Definition: element_with_external_element.h:286
unsigned Nexternal_element_storage
Definition: element_with_external_element.h:588
virtual void update_before_external_interaction_geometric_fd()
Definition: element_with_external_element.h:481
void operator=(const ElementWithExternalElement &)=delete
Broken assignment operator.
void describe_local_dofs(std::ostream &out, const std::string &curr_string) const
Definition: element_with_external_element.cc:205
virtual void reset_in_external_interaction_geometric_fd(const unsigned &i)
Definition: element_with_external_element.h:501
FiniteElement *& external_element_pt(const unsigned &interaction_index, const unsigned &ipt)
Definition: element_with_external_element.h:107
unsigned Nexternal_interaction_geometric_data
Number of external interaction geometric data.
Definition: element_with_external_element.h:594
virtual void reset_after_external_interaction_field_fd()
Definition: element_with_external_element.h:456
virtual void identify_all_geometric_data_for_external_interaction(Vector< std::set< FiniteElement * >> const &external_elements_pt, std::set< Data * > &external_geometric_data_pt)
Definition: element_with_external_element.cc:178
bool add_external_geometric_data()
Are we including external geometric data in the element's Jacobian.
Definition: element_with_external_element.h:238
unsigned nexternal_interaction_geometric_data() const
Definition: element_with_external_element.h:232
unsigned * External_interaction_field_data_index
Definition: element_with_external_element.h:609
void fill_in_jacobian_from_external_interaction_field_by_fd(DenseMatrix< double > &jacobian)
Definition: element_with_external_element.h:385
unsigned nexternal_interaction_field_data() const
Definition: element_with_external_element.h:205
virtual void reset_in_external_interaction_field_fd(const unsigned &i)
Definition: element_with_external_element.h:470
virtual ~ElementWithExternalElement()
The destructor, clean up any allocated memory.
Definition: element_with_external_element.cc:36
void ignore_external_interaction_data()
Definition: element_with_external_element.h:278
void fill_in_jacobian_from_external_interaction_field_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: element_with_external_element.cc:638
void check_storage_allocated() const
Helper function to check that storage has actually been allocated.
Definition: element_with_external_element.h:523
FiniteElement ** External_element_pt
Definition: element_with_external_element.h:600
void range_check(const unsigned &interaction_index, const unsigned &ipt) const
Helper function for range checking in the access functions.
Definition: element_with_external_element.h:546
Data ** External_interaction_field_data_pt
Definition: element_with_external_element.h:515
Vector< Data * > external_interaction_field_data_pt() const
Definition: element_with_external_element.h:212
Vector< double > * External_element_local_coord
Definition: element_with_external_element.h:605
int * External_interaction_field_data_local_eqn
Definition: element_with_external_element.h:613
void fill_in_jacobian_from_external_interaction_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: element_with_external_element.h:345
void fill_in_jacobian_from_external_interaction_by_fd(DenseMatrix< double > &jacobian)
Definition: element_with_external_element.h:360
virtual void reset_after_external_interaction_geometric_fd()
Definition: element_with_external_element.h:487
bool Add_external_geometric_data
Boolean flag to indicate whether to include the external geometric data.
Definition: element_with_external_element.h:511
bool add_external_interaction_data()
Are we including external data in the element's Jacobian.
Definition: element_with_external_element.h:244
void include_external_interaction_data()
Definition: element_with_external_element.h:294
virtual void update_in_external_interaction_geometric_fd(const unsigned &i)
Definition: element_with_external_element.h:492
Data ** External_interaction_geometric_data_pt
Definition: element_with_external_element.h:519
void assign_internal_and_external_local_eqn_numbers(const bool &store_local_dof_pt)
Definition: element_with_external_element.h:320
unsigned * External_interaction_geometric_data_index
Definition: element_with_external_element.h:618
bool Add_external_interaction_data
Boolean flag to indicate whether to include the external data.
Definition: element_with_external_element.h:508
void fill_in_jacobian_from_external_interaction_geometric_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: element_with_external_element.cc:720
virtual void identify_all_field_data_for_external_interaction(Vector< std::set< FiniteElement * >> const &external_elements_pt, std::set< std::pair< Data *, unsigned >> &paired_interaction_data)
Definition: element_with_external_element.cc:152
void ignore_external_geometric_data()
Definition: element_with_external_element.h:271
unsigned ninteraction() const
Return the number of interactions in the element.
Definition: element_with_external_element.h:184
Vector< Data * > external_interaction_geometric_data_pt() const
Definition: element_with_external_element.h:251
void fill_in_jacobian_from_external_interaction_geometric_by_fd(DenseMatrix< double > &jacobian)
Definition: element_with_external_element.h:411
void assign_external_interaction_data_local_eqn_numbers(const bool &store_local_dof_pt)
Definition: element_with_external_element.cc:246
unsigned Nintpt
Number of intergation point in the element.
Definition: element_with_external_element.h:584
unsigned Ninteraction
Number of interactions.
Definition: element_with_external_element.h:581
int * External_interaction_geometric_data_local_eqn
Definition: element_with_external_element.h:622
void fill_in_contribution_to_jacobian(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: element_with_external_element.h:427
virtual void update_in_external_interaction_field_fd(const unsigned &i)
Definition: element_with_external_element.h:461
ElementWithExternalElement()
Definition: element_with_external_element.h:60
void flush_all_external_element_storage()
Flush the storage for external elements.
Definition: element_with_external_element.cc:125
Vector< double > const & external_element_local_coord(const unsigned &interaction_index, const unsigned &ipt) const
Access function to get source element's coords, const version.
Definition: element_with_external_element.h:149
Definition: elements.h:1313
virtual void fill_in_jacobian_from_nodal_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: elements.cc:3660
virtual void fill_in_contribution_to_residuals(Vector< double > &residuals)
Definition: elements.h:357
unsigned ndof() const
Return the number of equations/dofs in the element.
Definition: elements.h:835
virtual void get_residuals(Vector< double > &residuals)
Definition: elements.h:980
virtual void assign_internal_and_external_local_eqn_numbers(const bool &store_local_dof_pt)
Definition: elements.cc:938
void fill_in_jacobian_from_external_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
Definition: elements.cc:1199
void fill_in_jacobian_from_internal_by_fd(Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
Definition: elements.cc:1102
Definition: oomph_definitions.h:222
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
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:36
std::ofstream out("Result.txt")