double_vector_with_halo.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 #ifndef OOMPH_DOUBLE_VECTOR_WITH_HALO_CLASS_HEADER
27 #define OOMPH_DOUBLE_VECTOR_WITH_HALO_CLASS_HEADER
28 
29 // Config header generated by autoconfig
30 #ifdef HAVE_CONFIG_H
31 #include <oomph-lib-config.h>
32 #endif
33 
34 #include <map>
35 #include "double_vector.h"
36 
37 namespace oomph
38 {
39  class DoubleVectorWithHaloEntries;
40 
41  //=====================================================================
50  //=====================================================================
52  {
56 
59  std::map<unsigned, unsigned> Local_index;
60 
64 
68 
72 
77 
81 
85 
86 
89 
90  public:
96  const Vector<unsigned>& required_global_eqn);
97 
99  inline unsigned n_halo_values() const
100  {
101  return Local_index.size();
102  }
103 
107  {
108  return Distribution_pt;
109  }
110 
113  void setup_halo_dofs(const std::map<unsigned, double*>& halo_data_pt,
114  Vector<double*>& halo_dof_pt);
115 
116 
118  inline unsigned local_index(const unsigned& global_eqn)
119  {
120  // Does the entry exist in the map
121  std::map<unsigned, unsigned>::iterator it = Local_index.find(global_eqn);
122  // If it does return it
123  if (it != Local_index.end())
124  {
125  return it->second;
126  }
127  // Otherwise throw an error
128  else
129  {
130  std::ostringstream error_stream;
131  error_stream << "Global equation " << global_eqn << " "
132  << "has not been set as halo\n";
133  throw OomphLibError(
134  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
135  return 0;
136  }
137  }
138  };
139 
140 
150  {
154 
157 
158  public:
161 
167  const LinearAlgebraDistribution* const& dist_pt,
169  const double& v = 0.0)
170  : DoubleVector(dist_pt, v)
171  {
172  // construct the halo scheme
174  }
175 
181  const LinearAlgebraDistribution& dist,
183  const double& v = 0.0)
184  : DoubleVector(dist, v)
185  {
186  // construct the halo scheme
188  }
189 
192 
193 
196  : DoubleVector(new_vector)
197  {
198  // Build the appropriate halo scheme
199  this->build_halo_scheme(new_vector.halo_scheme_pt());
200  }
201 
204  const DoubleVector& new_vector,
206  : DoubleVector(new_vector)
207  {
208  // Construct the halo scheme
210  }
211 
213  void operator=(const DoubleVectorWithHaloEntries& old_vector)
214  {
215  this->build(old_vector);
216  // Do some other stuff
217  this->build_halo_scheme(old_vector.halo_scheme_pt());
218  }
219 
221  inline double& global_value(const unsigned& i)
222  {
223  // Only need to worry about the distributed case if
224  // we have compiled with MPI
225 #ifdef OOMPH_HAS_MPI
226  if (this->distributed())
227  {
228  const unsigned first_row_local = this->first_row();
229  const unsigned n_row_local = this->nrow_local();
230 
231  // If we are in range then just call the local value
232  if ((i >= first_row_local) && (i < first_row_local + n_row_local))
233  {
234  return (*this)[i - first_row_local];
235  }
236  // Otherwise the entry is not stored in the local processor
237  // and we must have haloed it
238  else
239  {
240 #ifdef PARANOID
241  if (Halo_scheme_pt == 0)
242  {
243  std::ostringstream error_stream;
244  error_stream
245  << "Halo data requested, but no halo scheme has been setup\n"
246  << "You should call this->build_halo_scheme(halo_scheme_pt).\n"
247  << "You may wish to setup the scheme for the Problem using \n"
248  << "Problem::setup_dof_halo_scheme()\n";
249 
250  throw OomphLibError(error_stream.str(),
253  }
254 #endif
256  }
257  }
258  // If not distributed the global entry is
259  // the local entry
260  else
261 #endif
262  {
263  return (*this)[i];
264  }
265  }
266 
268  const double& global_value(const unsigned& i) const
269  {
270  // Only need to worry about the distributed case if
271  // we have compiled with MPI
272 #ifdef OOMPH_HAS_MPI
273  if (this->distributed())
274  {
275  const unsigned first_row_local = this->first_row();
276  const unsigned n_row_local = this->nrow_local();
277 
278  // If we are in range then just call the local value
279  if ((i >= first_row_local) && (i < first_row_local + n_row_local))
280  {
281  return (*this)[i - first_row_local];
282  }
283  // Otherwise the entry is not stored in the local processor
284  // and we must have haloed it
285  else
286  {
287 #ifdef PARANOID
288  if (Halo_scheme_pt == 0)
289  {
290  std::ostringstream error_stream;
291  error_stream
292  << "Halo data requested, but no halo scheme has been setup\n"
293  << "You should call this->build_halo_scheme(halo_scheme_pt).\n"
294  << "You may wish to setup the scheme for the Problem using \n"
295  << "Problem::setup_dof_halo_scheme()\n";
296 
297  throw OomphLibError(error_stream.str(),
300  }
301 #endif
303  }
304  }
305  // If not distributed the global entry is
306  // the local entry
307  else
308 #endif
309  {
310  return (*this)[i];
311  }
312  }
313 
314 
316  void synchronise();
317 
321 
324  {
325  return Halo_scheme_pt;
326  }
327 
330  {
331  return Halo_scheme_pt;
332  }
333 
334 
338  };
339 
340 } // namespace oomph
341 #endif
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
bool distributed() const
distribution is serial or distributed
Definition: linear_algebra_distribution.h:493
unsigned nrow_local() const
access function for the num of local rows on this processor.
Definition: linear_algebra_distribution.h:469
unsigned first_row() const
access function for the first row on this processor
Definition: linear_algebra_distribution.h:481
Definition: double_vector_with_halo.h:52
Vector< int > Haloed_n
Definition: double_vector_with_halo.h:67
LinearAlgebraDistribution *& distribution_pt()
Definition: double_vector_with_halo.h:106
Vector< int > Halo_displacement
Definition: double_vector_with_halo.h:84
Vector< int > Halo_n
Definition: double_vector_with_halo.h:80
unsigned n_halo_values() const
Return the number of halo values.
Definition: double_vector_with_halo.h:99
LinearAlgebraDistribution * Distribution_pt
Store the distribution that was used to setup the halo scheme.
Definition: double_vector_with_halo.h:88
std::map< unsigned, unsigned > Local_index
Definition: double_vector_with_halo.h:59
Vector< int > Haloed_displacement
Definition: double_vector_with_halo.h:71
void setup_halo_dofs(const std::map< unsigned, double * > &halo_data_pt, Vector< double * > &halo_dof_pt)
Definition: double_vector_with_halo.cc:225
Vector< unsigned > Haloed_eqns
Definition: double_vector_with_halo.h:63
DoubleVectorHaloScheme(LinearAlgebraDistribution *const &dist_pt, const Vector< unsigned > &required_global_eqn)
Definition: double_vector_with_halo.cc:36
unsigned local_index(const unsigned &global_eqn)
Return the local index associated with the global equation.
Definition: double_vector_with_halo.h:118
Vector< unsigned > Halo_eqns
Definition: double_vector_with_halo.h:76
Definition: double_vector_with_halo.h:150
DoubleVectorWithHaloEntries()
Constructor for an uninitialized DoubleVectorWithHaloEntries.
Definition: double_vector_with_halo.h:160
DoubleVectorWithHaloEntries(const LinearAlgebraDistribution *const &dist_pt, DoubleVectorHaloScheme *const &halo_scheme_pt=0, const double &v=0.0)
Definition: double_vector_with_halo.h:166
void build_halo_scheme(DoubleVectorHaloScheme *const &halo_scheme_pt)
Construct the halo scheme and storage for the halo data.
Definition: double_vector_with_halo.cc:379
DoubleVectorWithHaloEntries(const LinearAlgebraDistribution &dist, DoubleVectorHaloScheme *const &halo_scheme_pt=0, const double &v=0.0)
Definition: double_vector_with_halo.h:180
DoubleVectorWithHaloEntries(const DoubleVector &new_vector, DoubleVectorHaloScheme *const &halo_scheme_pt=0)
Copy constructor from any DoubleVector.
Definition: double_vector_with_halo.h:203
DoubleVectorHaloScheme *const & halo_scheme_pt() const
Access function for halo scheme (const version)
Definition: double_vector_with_halo.h:329
DoubleVectorHaloScheme * Halo_scheme_pt
Definition: double_vector_with_halo.h:153
const double & global_value(const unsigned &i) const
Direct access to the global entry (const version)
Definition: double_vector_with_halo.h:268
void synchronise()
Synchronise the halo data.
Definition: double_vector_with_halo.cc:269
void sum_all_halo_and_haloed_values()
Definition: double_vector_with_halo.cc:323
DoubleVectorHaloScheme *& halo_scheme_pt()
Access function for halo scheme.
Definition: double_vector_with_halo.h:323
double & global_value(const unsigned &i)
Direct access to global entry.
Definition: double_vector_with_halo.h:221
DoubleVectorWithHaloEntries(const DoubleVectorWithHaloEntries &new_vector)
Copy constructor from any DoubleVector.
Definition: double_vector_with_halo.h:195
void operator=(const DoubleVectorWithHaloEntries &old_vector)
assignment operator
Definition: double_vector_with_halo.h:213
Vector< double > Halo_value
Vector of the halo values.
Definition: double_vector_with_halo.h:156
~DoubleVectorWithHaloEntries()
Destructor.
Definition: double_vector_with_halo.h:191
Definition: double_vector.h:58
void build(const DoubleVector &old_vector)
Just copys the argument DoubleVector.
Definition: double_vector.cc:35
Definition: linear_algebra_distribution.h:64
Definition: oomph_definitions.h:222
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