oomph::AddedMainNumberingLookup Class Reference

#include <sum_of_matrices.h>

Public Member Functions

 AddedMainNumberingLookup ()
 Default constructor. More...
 
 AddedMainNumberingLookup (const Mesh *mesh_pt, const unsigned &dof_index)
 
 AddedMainNumberingLookup (const int *lookup_array, const unsigned &length)
 
 ~AddedMainNumberingLookup ()
 Destructor. More...
 
unsigned main_to_added (const int &main) const
 
int unsafe_main_to_added (const int &main) const
 
unsigned added_to_main (const unsigned &added) const
 
void build (const Mesh *mesh_pt, const unsigned &dof_index)
 
void build (const int *lookup_array, const unsigned &length)
 
void build (const Vector< const Node * > &bem_lookup, const unsigned &dof_index)
 Construct lookup using node vector. More...
 
void build_identity_map (const unsigned &n)
 Construct an identity map (mostly for testing). More...
 
const Vector< unsigned > * added_to_main_mapping_pt () const
 Const access function for mapping. More...
 
const std::map< unsigned, unsigned > * main_to_added_mapping_pt () const
 Const access function for mapping. More...
 

Private Member Functions

void construct_added_to_main_mapping (const Mesh *mesh_pt, const unsigned &dof_index)
 Set up the lookup from added matrix row/col to main matrix. More...
 
void construct_reverse_mapping ()
 Set up the main to added mapping using the added to main mapping. More...
 
 AddedMainNumberingLookup (const AddedMainNumberingLookup &dummy)=delete
 Inaccessible copy constructor. More...
 
void operator= (const AddedMainNumberingLookup &dummy)=delete
 Inaccessible assignment operator. More...
 

Private Attributes

Vector< unsignedAdded_to_main_mapping
 
std::map< unsigned, unsignedMain_to_added_mapping
 

Detailed Description

Class to store bi-directional lookup between added matrix row/col numbers to main matrix (SumOfMatrix) row/col numbers.

Constructor & Destructor Documentation

◆ AddedMainNumberingLookup() [1/4]

oomph::AddedMainNumberingLookup::AddedMainNumberingLookup ( )
inline

Default constructor.

50 {}

◆ AddedMainNumberingLookup() [2/4]

oomph::AddedMainNumberingLookup::AddedMainNumberingLookup ( const Mesh mesh_pt,
const unsigned dof_index 
)
inline

Real constructor: construct lookup from node numbers in mesh and global equation numbers. Useful for the case when the main matrix is a Jacobian and the added matrix is a contribution only on a certain mesh.

57  {
58  this->build(mesh_pt, dof_index);
59  }
void build(const Mesh *mesh_pt, const unsigned &dof_index)
Definition: sum_of_matrices.h:125

◆ AddedMainNumberingLookup() [3/4]

oomph::AddedMainNumberingLookup::AddedMainNumberingLookup ( const int lookup_array,
const unsigned length 
)
inline

Construct lookup schemes from int array (HLib's format for this data).

64  {
65  this->build(lookup_array, length);
66  }

◆ ~AddedMainNumberingLookup()

oomph::AddedMainNumberingLookup::~AddedMainNumberingLookup ( )
inline

Destructor.

69 {}

◆ AddedMainNumberingLookup() [4/4]

oomph::AddedMainNumberingLookup::AddedMainNumberingLookup ( const AddedMainNumberingLookup dummy)
privatedelete

Inaccessible copy constructor.

Member Function Documentation

◆ added_to_main()

unsigned oomph::AddedMainNumberingLookup::added_to_main ( const unsigned added) const
inline

Given a row/col number in the added matrix return the equivalent row/col number in the main matrix.

119  {
120  return Added_to_main_mapping[added];
121  }
Vector< unsigned > Added_to_main_mapping
Definition: sum_of_matrices.h:234

◆ added_to_main_mapping_pt()

const Vector<unsigned>* oomph::AddedMainNumberingLookup::added_to_main_mapping_pt ( ) const
inline

Const access function for mapping.

185  {
186  return &Added_to_main_mapping;
187  }

Referenced by oomph::SumOfMatrices::add_matrix().

◆ build() [1/3]

void oomph::AddedMainNumberingLookup::build ( const int lookup_array,
const unsigned length 
)
inline

Construct lookup schemes from int array (HLib's format for this data).

134  {
135 #ifdef PARANOID
136  // Check for negative entries just in case (since it's an integer
137  // array).
138  for (unsigned j = 0; j < length; j++)
139  {
140  if (lookup_array[j] < 0)
141  {
142  std::string err = "negative entry in lookup array!";
143  throw OomphLibError(
145  }
146  }
147 #endif
148 
149  // Copy array into mapping and generate the inverse lookup
150  Added_to_main_mapping.assign(lookup_array, lookup_array + length);
152  }
void construct_reverse_mapping()
Set up the main to added mapping using the added to main mapping.
Definition: sum_of_matrices.h:209
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
#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

References j, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::Global_string_for_annotation::string().

◆ build() [2/3]

void oomph::AddedMainNumberingLookup::build ( const Mesh mesh_pt,
const unsigned dof_index 
)
inline

Construct the lookup schemes given a mesh and the degree of freedom to lookup main equation numbers for.

126  {
127  construct_added_to_main_mapping(mesh_pt, dof_index);
129  }
void construct_added_to_main_mapping(const Mesh *mesh_pt, const unsigned &dof_index)
Set up the lookup from added matrix row/col to main matrix.
Definition: sum_of_matrices.h:197

◆ build() [3/3]

void oomph::AddedMainNumberingLookup::build ( const Vector< const Node * > &  bem_lookup,
const unsigned dof_index 
)
inline

Construct lookup using node vector.

156  {
157  const unsigned ni = bem_lookup.size();
158  Added_to_main_mapping.assign(ni, -1);
159 
160  for (unsigned i = 0; i < ni; i++)
161  {
162  Added_to_main_mapping[i] = bem_lookup[i]->eqn_number(dof_index);
163  }
164 
166  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References i.

◆ build_identity_map()

void oomph::AddedMainNumberingLookup::build_identity_map ( const unsigned n)
inline

Construct an identity map (mostly for testing).

170  {
171  Added_to_main_mapping.assign(n, 0);
172  for (unsigned j = 0; j < n; j++)
173  {
175  }
177  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11

References j, and n.

◆ construct_added_to_main_mapping()

void oomph::AddedMainNumberingLookup::construct_added_to_main_mapping ( const Mesh mesh_pt,
const unsigned dof_index 
)
inlineprivate

Set up the lookup from added matrix row/col to main matrix.

199  {
200  // Basically just copy from the node data.
201  Added_to_main_mapping.resize(mesh_pt->nnode());
202  for (unsigned nd = 0, nnode = mesh_pt->nnode(); nd < nnode; nd++)
203  {
204  Added_to_main_mapping[nd] = mesh_pt->node_pt(nd)->eqn_number(dof_index);
205  }
206  }

References oomph::Data::eqn_number(), oomph::Mesh::nnode(), and oomph::Mesh::node_pt().

◆ construct_reverse_mapping()

void oomph::AddedMainNumberingLookup::construct_reverse_mapping ( )
inlineprivate

Set up the main to added mapping using the added to main mapping.

210  {
211 #ifdef PARANOID
212  if (Added_to_main_mapping.size() == 0)
213  {
214  std::ostringstream error_msg;
215  error_msg << "Must set up Added_to_main_mapping first.";
216  throw OomphLibError(
218  }
219 #endif
220 
221  // Clear old data
222  Main_to_added_mapping.clear();
223 
224  // Copy from Added_to_main_mapping with order reversed.
225  for (unsigned j = 0; j < Added_to_main_mapping.size(); j++)
226  {
227  Main_to_added_mapping.insert(
228  std::make_pair(Added_to_main_mapping[j], j));
229  }
230  }
std::map< unsigned, unsigned > Main_to_added_mapping
Definition: sum_of_matrices.h:241

References j, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ main_to_added()

unsigned oomph::AddedMainNumberingLookup::main_to_added ( const int main) const
inline

Given a main matrix row/col number get the equivalent row/col in the added matrix. Throw an error if not found.

74  {
75  int result = unsafe_main_to_added(main);
76 #ifdef PARANOID
77  // If it's -1 then we failed to find it:
78  if (result == -1)
79  {
80  std::string err = "Main matrix row/col number " + to_string(main) +
81  " not found in lookup.";
82  throw OomphLibError(
84  }
85 
86  if (result < 0)
87  {
88  std::string err = "Something crazy went wrong here.";
89  throw OomphLibError(
91  }
92 #endif
93 
94  return unsigned(result);
95  }
int main(int argc, char *argv[])
Definition: T_protectiveWall.cpp:194
int unsafe_main_to_added(const int &main) const
Definition: sum_of_matrices.h:99
std::string to_string(T object, unsigned float_precision=8)
Definition: oomph_utilities.h:189

References main(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::Global_string_for_annotation::string(), and oomph::StringConversion::to_string().

◆ main_to_added_mapping_pt()

const std::map<unsigned, unsigned>* oomph::AddedMainNumberingLookup::main_to_added_mapping_pt ( ) const
inline

Const access function for mapping.

191  {
192  return &Main_to_added_mapping;
193  }

Referenced by oomph::SumOfMatrices::add_matrix().

◆ operator=()

void oomph::AddedMainNumberingLookup::operator= ( const AddedMainNumberingLookup dummy)
privatedelete

Inaccessible assignment operator.

◆ unsafe_main_to_added()

int oomph::AddedMainNumberingLookup::unsafe_main_to_added ( const int main) const
inline

Given a main matrix row/col number get the equivalent row/col in the added matrix. Return -1 if not found.

100  {
101  // Find the entry
102  std::map<unsigned, unsigned>::const_iterator it =
103  Main_to_added_mapping.find(unsigned(main));
104 
105  // Check the entry existed, it not then return -1.
106  if (it == main_to_added_mapping_pt()->end())
107  {
108  return -1;
109  }
110  else
111  {
112  return it->second;
113  }
114  }
const std::map< unsigned, unsigned > * main_to_added_mapping_pt() const
Const access function for mapping.
Definition: sum_of_matrices.h:190
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79

References Eigen::placeholders::end, and main().

Member Data Documentation

◆ Added_to_main_mapping

Vector<unsigned> oomph::AddedMainNumberingLookup::Added_to_main_mapping
private

Mapping from added matrix row/col numbers to main matrix row/col numbers.

◆ Main_to_added_mapping

std::map<unsigned, unsigned> oomph::AddedMainNumberingLookup::Main_to_added_mapping
private

Mapping from main matrix row/col numbers to added matrix row/col numbers. Note that we cannot use a vector here because the main matrix rows/cols mapped onto are probably not contiguous. Access times are O(log N) so if you need to iterate over all elements then use the pointer access functions and use stl iterators properly.


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