constraint_elements.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 // Elements for adding constraints to a problem
6 // Base constraint element has:
7 // Lagrange multipliers to enforce constraints - internal data
8 // Indices of Lagrange multiplier dofs in internal data
9 // External (constrained) degrees of freedom
10 // Residual/Jacobian fill in
11 // Constraint functions
12 
13 // This represents the most general constraint element type
14 // - it can carry out procedures for automatically:
15 // identifying constrained degrees of freedom
16 // removing unenforcible constraints due to a lack of (unpinned) constrained degrees of freedom
17 // fill in residual and jacobian entries of constrained degrees of freedom and lagrange multipliers for general constraint functions
18 // Provided the constraint functions are suitably formulated so that the rows/columns of the lagrange multiplier are not entirely zero
19 // this will allow for general constraints to be applied to a problem, albeit in a rather inefficient way
20 
21 // More specific constraint elements are implemented to allow for less flexible constraints but more explicit, readable, and efficient implementations
22 
23 
24 // Apply constraints to specific setups - i.e. node pairs, elements and local coordinate pairs
25 
26 // Node-Node constraint element
27 // - a slightly more specific implementation with general constraint functions provided by function pointers but some additional member variables which
28 // store the nodes being constrained and the local indices of the degrees of freedom of those nodes to assist in writing constraint functions
29 
30 // SolidNode-SolidNode constraint element - a more specific version of Node-Node mortaring element which only constrains solid degrees of freedom
31 
32 // Element-Element constraint element
33 // - a slightly more specific implementation with general constraint functions provided by function pointers but some additional member variables which
34 // store the elements being constrained, the local coordinates in those elements being constrained and the local indices of the degrees of freedom of the
35 // elements/nodes of the elements to assist in writing constraint functions
36 
37 
38 // Apply equality constraint to specific setups - i.e. node pairs, elements and local coordinate pairs
39 
40 // Mortaring elements
41 // Node-Node mortaring element - a more specific implementation of the Node-Node constraint element which ensures all or some degrees of freedom of the two nodes are identical in value, including solid nodal
42 // automatically determine if the requested constraints are enforcible
43 // - if there are sufficient unpinned constrained degrees of freedom (must be at least one in each node for each constraint)
44 // - if there are sufficient degrees of freedom for the specified degrees of freedom indices
45 // - if the nodes are solid when mortaring of solid positions is specified
46 
47 // SolidNode-SolidNode mortaring element - a more specific version of Node-Node mortaring element which only ensures solid degrees of freedom are identical
48 
49 
50 
51 
52 //TODO need a way of identifying the mortaring space and building
53 // constraint elements.
54 //TODO need face mortaring elements to apply to the mortaring boundary
55 
56 
57 // IMPORTANT advice when using constraint elements
58 // Since the feasibility of the application of constraints is dependent on the pinned status of the constrained degrees of freedom the creation of constraint elements should always happen after any steps in
59 // which degrees of freedom in a problem are pinned.
60 
61 #ifndef CONSTRAINT_ELEMENTS_HEADER
62 #define CONSTRAINT_ELEMENTS_HEADER
63 
64 // Config header generated by autoconfig
65 #ifdef HAVE_CONFIG_H
66 #include <oomph-lib-config.h>
67 #endif
68 
69 //TODO why do I need to specify paths like this here but not elsewhere?
70 // oomph-lib headers
71 #include "../../../oomph-lib/src/generic/Vector.h"
72 #include "../../../oomph-lib/src/generic/nodes.h"
73 #include "../../../oomph-lib/src/generic/elements.h"
74 #include "../../../oomph-lib/src/generic/shape.h"
75 
76 
77 namespace oomph
78 {
79 
80  // Must call construct_lagrange_multipliers() in the constructor of any derived class
81  class ConstraintElement : public virtual GeneralisedElement
82  {
83  public:
84  // pass in all data which is to be included in the constraint calculations
86  {
87  build(data_pt);
88  }
89  // Constructor but with a non-reference argument - used in node-node constraint elements
90  // where a temporary vector of Data* is made
92  {
93  build(data_pt);
94  }
95 
96  // Fill in residual and jacobian procedures
97  // - Generic by finite differencing, override for more efficient implementation
98  virtual void fill_in_contribution_to_residuals(Vector<double>& residuals);
99 
100  // Determine how many lagrange multipliers are needed and if the constraint is enforcible
101  virtual void construct_lagrange_multipliers();
102 
103 private:
104  // Finish the element build
105  void build(Vector<Data*>& data_pt)
106  {
107  // Add the data as external data
108  Num_Constrained_Data = data_pt.size();
110  for(unsigned i=0; i<Num_Constrained_Data; i++)
111  {
112  // Add the external data - we want to add it to the finite differencing
114  }
115  }
116 
117  protected:
118  // Generic interface for evaluating constraint functions
119  // - must re-size the error vector to the number of constraints being enforced
121 
122  // Access functions for derived classes
124  {
126  }
128  {
130  }
132  {
134  }
135  const int lagrange_eqn(const unsigned& i)
136  {
137  // std::cout << "lagrange_eqn(" << i << ") ninternal_data " << ninternal_data() << std::endl;
138  #ifdef RANGE_CHECKING
139  if(i>=Num_Constraints)
140  {
141  throw OomphLibError(std::to_string(i) + " is greater than the number of constraints " + std::to_string(Num_Constraints),
144  }
145  #endif
147  }
148  Data* ext_data_pt(const unsigned& i)
149  {
150  #ifdef RANGE_CHECKING
152  {
153  throw OomphLibError(std::to_string(i) + " is greater than the number of constrained data " + std::to_string(Num_Constrained_Data),
156  }
157  #endif
159  }
160  const int ext_eqn(const unsigned& i, const unsigned& j)
161  {
162  #ifdef RANGE_CHECKING
164  {
165  throw OomphLibError(std::to_string(i) + " is greater than the number of constrained data " + std::to_string(Num_Constrained_Data),
168  }
169  #endif
171  }
172 
173  // The index of the external data pt corresponding to the constrained data
175  // The number of constrained data
177  // The index of the lagrange multiplier internal data
179  // The number of constraints (and also the number of lagrange multipliers)
180  unsigned Num_Constraints;
181  };
182 } // End namespace
183 
184 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: constraint_elements.h:82
Vector< unsigned > get_constrained_data_local_index()
Definition: constraint_elements.h:123
unsigned get_lagrange_multiplier_index()
Definition: constraint_elements.h:127
ConstraintElement(Vector< Data * > data_pt)
Definition: constraint_elements.h:91
unsigned Num_Constraints
Definition: constraint_elements.h:180
virtual void construct_lagrange_multipliers()
Definition: constraint_elements.cc:76
Data * lagrange_multiplier()
Definition: constraint_elements.h:131
virtual void fill_in_contribution_to_residuals(Vector< double > &residuals)
Definition: constraint_elements.cc:10
unsigned Num_Constrained_Data
Definition: constraint_elements.h:176
void build(Vector< Data * > &data_pt)
Definition: constraint_elements.h:105
const int lagrange_eqn(const unsigned &i)
Definition: constraint_elements.h:135
Vector< unsigned > Constrained_Data_Local_Index
Definition: constraint_elements.h:174
unsigned Lagrange_Multiplier_Index
Definition: constraint_elements.h:178
ConstraintElement(Vector< Data * > &data_pt)
Definition: constraint_elements.h:85
const int ext_eqn(const unsigned &i, const unsigned &j)
Definition: constraint_elements.h:160
virtual void evaluate_constraint_functions(Vector< double > &error)
Definition: constraint_elements.cc:146
Data * ext_data_pt(const unsigned &i)
Definition: constraint_elements.h:148
Definition: nodes.h:86
Definition: elements.h:73
Data *& external_data_pt(const unsigned &i)
Return a pointer to i-th external data object.
Definition: elements.h:659
Data *& internal_data_pt(const unsigned &i)
Return a pointer to i-th internal data object.
Definition: elements.h:622
unsigned add_external_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:307
int internal_local_eqn(const unsigned &i, const unsigned &j) const
Definition: elements.h:267
int external_local_eqn(const unsigned &i, const unsigned &j)
Definition: elements.h:311
Definition: oomph_definitions.h:222
int error
Definition: calibrate.py:297
std::string to_string(T object, unsigned float_precision=8)
Definition: oomph_utilities.h:189
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