oomph::ConstraintElement Class Reference

#include <constraint_elements.h>

+ Inheritance diagram for oomph::ConstraintElement:

Public Member Functions

 ConstraintElement (Vector< Data * > &data_pt)
 
 ConstraintElement (Vector< Data * > data_pt)
 
virtual void fill_in_contribution_to_residuals (Vector< double > &residuals)
 
virtual void construct_lagrange_multipliers ()
 
- Public Member Functions inherited from oomph::GeneralisedElement
 GeneralisedElement ()
 Constructor: Initialise all pointers and all values to zero. More...
 
virtual ~GeneralisedElement ()
 Virtual destructor to clean up any memory allocated by the object. More...
 
 GeneralisedElement (const GeneralisedElement &)=delete
 Broken copy constructor. More...
 
void operator= (const GeneralisedElement &)=delete
 Broken assignment operator. More...
 
Data *& internal_data_pt (const unsigned &i)
 Return a pointer to i-th internal data object. More...
 
Data *const & internal_data_pt (const unsigned &i) const
 Return a pointer to i-th internal data object (const version) More...
 
Data *& external_data_pt (const unsigned &i)
 Return a pointer to i-th external data object. More...
 
Data *const & external_data_pt (const unsigned &i) const
 Return a pointer to i-th external data object (const version) More...
 
unsigned long eqn_number (const unsigned &ieqn_local) const
 
int local_eqn_number (const unsigned long &ieqn_global) const
 
unsigned add_external_data (Data *const &data_pt, const bool &fd=true)
 
bool external_data_fd (const unsigned &i) const
 
void exclude_external_data_fd (const unsigned &i)
 
void include_external_data_fd (const unsigned &i)
 
void flush_external_data ()
 Flush all external data. More...
 
void flush_external_data (Data *const &data_pt)
 Flush the object addressed by data_pt from the external data array. More...
 
unsigned ninternal_data () const
 Return the number of internal data objects. More...
 
unsigned nexternal_data () const
 Return the number of external data objects. More...
 
unsigned ndof () const
 Return the number of equations/dofs in the element. More...
 
void dof_vector (const unsigned &t, Vector< double > &dof)
 Return the vector of dof values at time level t. More...
 
void dof_pt_vector (Vector< double * > &dof_pt)
 Return the vector of pointers to dof values. More...
 
void set_internal_data_time_stepper (const unsigned &i, TimeStepper *const &time_stepper_pt, const bool &preserve_existing_data)
 
void assign_internal_eqn_numbers (unsigned long &global_number, Vector< double * > &Dof_pt)
 
void describe_dofs (std::ostream &out, const std::string &current_string) const
 
virtual void describe_local_dofs (std::ostream &out, const std::string &current_string) const
 
void add_internal_value_pt_to_map (std::map< unsigned, double * > &map_of_value_pt)
 
virtual void assign_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void complete_setup_of_dependencies ()
 
virtual void get_residuals (Vector< double > &residuals)
 
virtual void get_jacobian (Vector< double > &residuals, DenseMatrix< double > &jacobian)
 
virtual void get_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &mass_matrix)
 
virtual void get_jacobian_and_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
 
virtual void get_dresiduals_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam)
 
virtual void get_djacobian_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam)
 
virtual void get_djacobian_and_dmass_matrix_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam, DenseMatrix< double > &dmass_matrix_dparam)
 
virtual void get_hessian_vector_products (Vector< double > const &Y, DenseMatrix< double > const &C, DenseMatrix< double > &product)
 
virtual void get_inner_products (Vector< std::pair< unsigned, unsigned >> const &history_index, Vector< double > &inner_product)
 
virtual void get_inner_product_vectors (Vector< unsigned > const &history_index, Vector< Vector< double >> &inner_product_vector)
 
virtual unsigned self_test ()
 
virtual void compute_norm (Vector< double > &norm)
 
virtual void compute_norm (double &norm)
 
virtual unsigned ndof_types () const
 
virtual void get_dof_numbers_for_unknowns (std::list< std::pair< unsigned long, unsigned >> &dof_lookup_list) const
 

Protected Member Functions

virtual void evaluate_constraint_functions (Vector< double > &error)
 
Vector< unsignedget_constrained_data_local_index ()
 
unsigned get_lagrange_multiplier_index ()
 
Datalagrange_multiplier ()
 
const int lagrange_eqn (const unsigned &i)
 
Dataext_data_pt (const unsigned &i)
 
const int ext_eqn (const unsigned &i, const unsigned &j)
 
- Protected Member Functions inherited from oomph::GeneralisedElement
unsigned add_internal_data (Data *const &data_pt, const bool &fd=true)
 
bool internal_data_fd (const unsigned &i) const
 
void exclude_internal_data_fd (const unsigned &i)
 
void include_internal_data_fd (const unsigned &i)
 
void clear_global_eqn_numbers ()
 
void add_global_eqn_numbers (std::deque< unsigned long > const &global_eqn_numbers, std::deque< double * > const &global_dof_pt)
 
virtual void assign_internal_and_external_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void assign_all_generic_local_eqn_numbers (const bool &store_local_dof_pt)
 
virtual void assign_additional_local_eqn_numbers ()
 
int internal_local_eqn (const unsigned &i, const unsigned &j) const
 
int external_local_eqn (const unsigned &i, const unsigned &j)
 
void fill_in_jacobian_from_internal_by_fd (Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_internal_by_fd (DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_external_by_fd (Vector< double > &residuals, DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
void fill_in_jacobian_from_external_by_fd (DenseMatrix< double > &jacobian, const bool &fd_all_data=false)
 
virtual void update_before_internal_fd ()
 
virtual void reset_after_internal_fd ()
 
virtual void update_in_internal_fd (const unsigned &i)
 
virtual void reset_in_internal_fd (const unsigned &i)
 
virtual void update_before_external_fd ()
 
virtual void reset_after_external_fd ()
 
virtual void update_in_external_fd (const unsigned &i)
 
virtual void reset_in_external_fd (const unsigned &i)
 
virtual void fill_in_contribution_to_jacobian (Vector< double > &residuals, DenseMatrix< double > &jacobian)
 
virtual void fill_in_contribution_to_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &mass_matrix)
 
virtual void fill_in_contribution_to_jacobian_and_mass_matrix (Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
 
virtual void fill_in_contribution_to_dresiduals_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam)
 
virtual void fill_in_contribution_to_djacobian_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam)
 
virtual void fill_in_contribution_to_djacobian_and_dmass_matrix_dparameter (double *const &parameter_pt, Vector< double > &dres_dparam, DenseMatrix< double > &djac_dparam, DenseMatrix< double > &dmass_matrix_dparam)
 
virtual void fill_in_contribution_to_hessian_vector_products (Vector< double > const &Y, DenseMatrix< double > const &C, DenseMatrix< double > &product)
 
virtual void fill_in_contribution_to_inner_products (Vector< std::pair< unsigned, unsigned >> const &history_index, Vector< double > &inner_product)
 
virtual void fill_in_contribution_to_inner_product_vectors (Vector< unsigned > const &history_index, Vector< Vector< double >> &inner_product_vector)
 

Protected Attributes

Vector< unsignedConstrained_Data_Local_Index
 
unsigned Num_Constrained_Data
 
unsigned Lagrange_Multiplier_Index
 
unsigned Num_Constraints
 

Private Member Functions

void build (Vector< Data * > &data_pt)
 

Additional Inherited Members

- Static Public Attributes inherited from oomph::GeneralisedElement
static bool Suppress_warning_about_repeated_internal_data
 
static bool Suppress_warning_about_repeated_external_data = true
 
static double Default_fd_jacobian_step = 1.0e-8
 
- Static Protected Attributes inherited from oomph::GeneralisedElement
static DenseMatrix< doubleDummy_matrix
 
static std::deque< double * > Dof_pt_deque
 

Constructor & Destructor Documentation

◆ ConstraintElement() [1/2]

oomph::ConstraintElement::ConstraintElement ( Vector< Data * > &  data_pt)
inline
85  : Num_Constraints(0)
86  {
87  build(data_pt);
88  }
unsigned Num_Constraints
Definition: constraint_elements.h:180
void build(Vector< Data * > &data_pt)
Definition: constraint_elements.h:105

References build().

◆ ConstraintElement() [2/2]

oomph::ConstraintElement::ConstraintElement ( Vector< Data * >  data_pt)
inline
91  : Num_Constraints(0)
92  {
93  build(data_pt);
94  }

References build().

Member Function Documentation

◆ build()

void oomph::ConstraintElement::build ( Vector< Data * > &  data_pt)
inlineprivate
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  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
unsigned Num_Constrained_Data
Definition: constraint_elements.h:176
Vector< unsigned > Constrained_Data_Local_Index
Definition: constraint_elements.h:174
unsigned add_external_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:307

References oomph::GeneralisedElement::add_external_data(), Constrained_Data_Local_Index, i, and Num_Constrained_Data.

Referenced by ConstraintElement().

◆ construct_lagrange_multipliers()

void oomph::ConstraintElement::construct_lagrange_multipliers ( )
virtual

Reimplemented in oomph::NodeNodeMortaringElement.

77  {
78  // Get the number of constraints by calling evaluate_constraint_functions
79  Vector<double> test_error;
81  Num_Constraints = test_error.size();
82 
83  // Create the lagrange multipliers
84  // - by default we want to include the lagrange multipliers in any finite differencing
86 
87 
88  // TODO THE BELOW REQUIRES THAT EQN NUMBERS HAVE BEEN ASSIGNED....HOW TO AVOID THIS REQUIREMENT??
89  // IT WOULD BE NICE TO HAVE AN AUTOMATIC CHECK THAT A CONSTRAINT IS ENFORCIBLE.
90  // Could resolve this by adding a function to check if the lagrange multipliers are enforcible
91  // which can be called after the equation numbers have been assigned.
92  // Or could just remove this check. If the user is trying to over constrain the system then
93  // they'll be made aware of that when the Jacobian is singular.
94 
95  // Determine if each constraint is enforcible
96  // - construct the jacobian and check if the rows/columns of the lagrange multipliers are zero
97  // - this assumes that there is no point at which the derivatives of the constraint functions
98  // vanish which is a sensible assumption if they do then the problem could mysteriously become
99  // singular without warning. Therefore by assuming that the constraint functions do not vanish
100  // the only way a lagrange multiplier row/column of the jacobian is singular is if it has no
101  // dependence on any unpinned degrees of freedom.
102 
103  // // Calculate the jacobian
104  // Vector<double> residuals(this->ndof());
105  // DenseMatrix<double> jacobian(this->ndof());
106  // fill_in_contribution_to_jacobian(residuals, jacobian);
107 
108  // // Interrogate the rows/columns of each lagrange multiplier and check that they are not zero.
109  // // if they are then pin that lagrange multiplier
110  // for(unsigned i=0; i<Num_Constraints; i++)
111  // {
112  // // Get the local equation of the lagrange multiplier
113  // const int l_index = lagrange_eqn(i);
114 
115  // // Loop over external data
116  // for(unsigned j=0; j<Num_Constrained_Data; j++)
117  // {
118  // // Loop over the dofs in that external data
119  // const unsigned num_dofs = external_data_pt(j)->nvalue();
120  // for(unsigned k=0; k<num_dofs; k++)
121  // {
122  // // Get the local equation of the external dof
123  // const int ext_index = external_local_eqn(j, k);
124  // // If the external dof is pinned then skip it
125  // if(ext_index < 0) continue;
126  // if(abs(jacobian(l_index,ext_index)) > FiniteElement::Tolerance_for_singular_jacobian || abs(jacobian(ext_index,l_index)) > FiniteElement::Tolerance_for_singular_jacobian)
127  // {
128  // // If the entry is non-zero then the constraint is enforcible, stop checking
129  // goto constraintIsEnforcible;
130  // }
131  // }
132  // }
133  // // If we have got to here then there are no non-zero entries in the lagrange multiplier column/row of the jacobian so it is unenforcible
134  // lagrange_multiplier()->pin(i);
135  // #ifdef PARANOID
136  // // Tell the user
137  // std::cout << "A constraint is unenforcible because there are not sufficient unpinned dofs the constraint is dependent on.\nPinning corresponding lagrange multiplier" << std::endl;
138  // #endif
139 
140  // // Using a goto because we have 2 nested for loops
141  // constraintIsEnforcible:
142  // continue;
143  // }
144  }
unsigned Lagrange_Multiplier_Index
Definition: constraint_elements.h:178
virtual void evaluate_constraint_functions(Vector< double > &error)
Definition: constraint_elements.cc:146
unsigned add_internal_data(Data *const &data_pt, const bool &fd=true)
Definition: elements.cc:62

References oomph::GeneralisedElement::add_internal_data(), evaluate_constraint_functions(), Lagrange_Multiplier_Index, and Num_Constraints.

◆ evaluate_constraint_functions()

void oomph::ConstraintElement::evaluate_constraint_functions ( Vector< double > &  error)
protectedvirtual

Reimplemented in oomph::ElementElementMortaringElement.

147  {
148  // Throw an error
149  throw OomphLibError("evaluate_constraint_functions has not been implemented for this element.\nIt must be implemented in any class which inherits from ConstraintElement",
152  }
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by construct_lagrange_multipliers(), and fill_in_contribution_to_residuals().

◆ ext_data_pt()

Data* oomph::ConstraintElement::ext_data_pt ( const unsigned i)
inlineprotected
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  }
Data *& external_data_pt(const unsigned &i)
Return a pointer to i-th external data object.
Definition: elements.h:659
std::string to_string(T object, unsigned float_precision=8)
Definition: oomph_utilities.h:189

References Constrained_Data_Local_Index, oomph::GeneralisedElement::external_data_pt(), i, Num_Constrained_Data, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::StringConversion::to_string().

Referenced by oomph::NodeElementSolidOnlyMortaringElement::fill_in_contribution_to_jacobian_mortared_nodes(), fill_in_contribution_to_residuals(), oomph::NodeNodeConstraintElement::node_pt(), oomph::NodeElementSolidOnlyMortaringElement::position_in_element(), and oomph::NodeNodeConstraintElement::solid_node_pt().

◆ ext_eqn()

const int oomph::ConstraintElement::ext_eqn ( const unsigned i,
const unsigned j 
)
inlineprotected
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  }
int external_local_eqn(const unsigned &i, const unsigned &j)
Definition: elements.h:311
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Constrained_Data_Local_Index, oomph::GeneralisedElement::external_local_eqn(), i, j, Num_Constrained_Data, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::StringConversion::to_string().

Referenced by oomph::NodeElementSolidOnlyMortaringElement::fill_in_contribution_to_jacobian_mortared_nodes(), and oomph::NodeNodeMortaringElement::fill_in_contribution_to_jacobian_mortared_nodes().

◆ fill_in_contribution_to_residuals()

void oomph::ConstraintElement::fill_in_contribution_to_residuals ( Vector< double > &  residuals)
virtual

Add the elemental contribution to the residuals vector. Note that this function will NOT initialise the residuals vector. It must be called after the residuals vector has been initialised to zero.

Reimplemented from oomph::GeneralisedElement.

Reimplemented in oomph::NodeNodeMortaringElement, and oomph::NodeElementSolidOnlyMortaringElement.

11  {
12  // Compute the residual by finite differencing the constraints
13  // R_{x_i} = \lambda_k \frac{\partial g_k}{\partial x_i}
14  // R_{\lambda_i} = g_i
15 
16  // Use the default finite difference step
17  const double fd_step = Default_fd_jacobian_step;
18 
19  // Get the error
20  Vector<double> error;
22 
23  // Create test_error vector
24  Vector<double> test_error;
25 
26  // Update the residual entry for each of the lagrange multipliers
27  for(unsigned i=0; i<Num_Constraints; i++)
28  {
29  // Get the local equation of the lagrange multiplier
30  const int l_index = lagrange_eqn(i);
31 
32  // R_{\lambda_i} = g_i
33  residuals[l_index] = error[i];
34  }
35 
36  // For each of the external data finite difference the constraint equations to find the residual entry
37  for (unsigned i=0; i<Num_Constrained_Data; i++)
38  {
39  // Get the number of values at the external data
40  const unsigned n_value = ext_data_pt(i)->nvalue();
41  for(unsigned j=0; j<n_value; j++)
42  {
43  // Get the local equation of the external dof
44  const int ext_index = external_local_eqn(i, j);
45 
46  // If it is pinned then skip it
47  if(ext_index < 0) continue;
48 
49  // Get a pointer to the External data value
50  double* const value_pt = ext_data_pt(i)->value_pt(j);
51 
52  // Save the old value of the External data
53  const double old_var = *value_pt;
54 
55  // Increment the value of the External data
56  *value_pt += fd_step;
57 
58  // Evaluate the constraint functions at the new variables value
60 
61  // R_{x_i} = \lambda_k \frac{\partial g_k}{\partial x_i}
62  double sum = 0.0;
63  // Do finite differences
64  for (unsigned k = 0; k < Num_Constraints; k++)
65  {
66  if(lagrange_multiplier()->is_pinned(k)) continue;
67  sum += lagrange_multiplier()->value(k) * (test_error[k] - error[k]) / fd_step;
68  }
69 
70  // Add to the residuals
71  residuals[ext_index] = sum;
72  }
73  }
74  }
Data * lagrange_multiplier()
Definition: constraint_elements.h:131
const int lagrange_eqn(const unsigned &i)
Definition: constraint_elements.h:135
Data * ext_data_pt(const unsigned &i)
Definition: constraint_elements.h:148
double * value_pt(const unsigned &i) const
Definition: nodes.h:324
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
static double Default_fd_jacobian_step
Definition: elements.h:1198
char char char int int * k
Definition: level2_impl.h:374
int error
Definition: calibrate.py:297

References oomph::GeneralisedElement::Default_fd_jacobian_step, calibrate::error, evaluate_constraint_functions(), ext_data_pt(), oomph::GeneralisedElement::external_local_eqn(), i, j, k, lagrange_eqn(), lagrange_multiplier(), Num_Constrained_Data, Num_Constraints, oomph::Data::nvalue(), oomph::Data::value(), and oomph::Data::value_pt().

◆ get_constrained_data_local_index()

Vector<unsigned> oomph::ConstraintElement::get_constrained_data_local_index ( )
inlineprotected
124  {
126  }

References Constrained_Data_Local_Index.

◆ get_lagrange_multiplier_index()

unsigned oomph::ConstraintElement::get_lagrange_multiplier_index ( )
inlineprotected
128  {
130  }

References Lagrange_Multiplier_Index.

◆ lagrange_eqn()

const int oomph::ConstraintElement::lagrange_eqn ( const unsigned i)
inlineprotected
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  }
int internal_local_eqn(const unsigned &i, const unsigned &j) const
Definition: elements.h:267

References i, oomph::GeneralisedElement::internal_local_eqn(), Lagrange_Multiplier_Index, Num_Constraints, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::StringConversion::to_string().

Referenced by oomph::NodeElementSolidOnlyMortaringElement::fill_in_contribution_to_jacobian_mortared_nodes(), oomph::NodeNodeMortaringElement::fill_in_contribution_to_jacobian_mortared_nodes(), and fill_in_contribution_to_residuals().

◆ lagrange_multiplier()

Member Data Documentation

◆ Constrained_Data_Local_Index

Vector<unsigned> oomph::ConstraintElement::Constrained_Data_Local_Index
protected

◆ Lagrange_Multiplier_Index

◆ Num_Constrained_Data

unsigned oomph::ConstraintElement::Num_Constrained_Data
protected

◆ Num_Constraints


The documentation for this class was generated from the following files: