oomph::DoubleVectorWithHaloEntries Class Reference

#include <double_vector_with_halo.h>

+ Inheritance diagram for oomph::DoubleVectorWithHaloEntries:

Public Member Functions

 DoubleVectorWithHaloEntries ()
 Constructor for an uninitialized DoubleVectorWithHaloEntries. More...
 
 DoubleVectorWithHaloEntries (const LinearAlgebraDistribution *const &dist_pt, DoubleVectorHaloScheme *const &halo_scheme_pt=0, const double &v=0.0)
 
 DoubleVectorWithHaloEntries (const LinearAlgebraDistribution &dist, DoubleVectorHaloScheme *const &halo_scheme_pt=0, const double &v=0.0)
 
 ~DoubleVectorWithHaloEntries ()
 Destructor. More...
 
 DoubleVectorWithHaloEntries (const DoubleVectorWithHaloEntries &new_vector)
 Copy constructor from any DoubleVector. More...
 
 DoubleVectorWithHaloEntries (const DoubleVector &new_vector, DoubleVectorHaloScheme *const &halo_scheme_pt=0)
 Copy constructor from any DoubleVector. More...
 
void operator= (const DoubleVectorWithHaloEntries &old_vector)
 assignment operator More...
 
doubleglobal_value (const unsigned &i)
 Direct access to global entry. More...
 
const doubleglobal_value (const unsigned &i) const
 Direct access to the global entry (const version) More...
 
void synchronise ()
 Synchronise the halo data. More...
 
void sum_all_halo_and_haloed_values ()
 
DoubleVectorHaloScheme *& halo_scheme_pt ()
 Access function for halo scheme. More...
 
DoubleVectorHaloScheme *const & halo_scheme_pt () const
 Access function for halo scheme (const version) More...
 
void build_halo_scheme (DoubleVectorHaloScheme *const &halo_scheme_pt)
 Construct the halo scheme and storage for the halo data. More...
 
- Public Member Functions inherited from oomph::DoubleVector
 DoubleVector ()
 Constructor for an uninitialized DoubleVector. More...
 
 DoubleVector (const LinearAlgebraDistribution *const &dist_pt, const double &v=0.0)
 
 DoubleVector (const LinearAlgebraDistribution &dist, const double &v=0.0)
 
 ~DoubleVector ()
 
 DoubleVector (const DoubleVector &new_vector)
 Copy constructor. More...
 
void operator= (const DoubleVector &old_vector)
 assignment operator More...
 
void build (const DoubleVector &old_vector)
 Just copys the argument DoubleVector. More...
 
void build (const LinearAlgebraDistribution &dist, const double &v)
 
void build (const LinearAlgebraDistribution *const &dist_pt, const double &v)
 
void build (const LinearAlgebraDistribution &dist, const Vector< double > &v)
 
void build (const LinearAlgebraDistribution *const &dist_pt, const Vector< double > &v)
 
void initialise (const double &v)
 initialise the whole vector with value v More...
 
void initialise (const Vector< double > v)
 
void clear ()
 wipes the DoubleVector More...
 
bool built () const
 
void set_external_values (const LinearAlgebraDistribution *const &dist_pt, double *external_values, bool delete_external_values)
 
void set_external_values (double *external_values, bool delete_external_values)
 
void redistribute (const LinearAlgebraDistribution *const &dist_pt)
 
doubleoperator[] (int i)
 [] access function to the (local) values of this vector More...
 
bool operator== (const DoubleVector &v)
 == operator More...
 
void operator+= (const DoubleVector &v)
 += operator with another vector More...
 
void operator-= (const DoubleVector &v)
 -= operator with another vector More...
 
void operator*= (const double &d)
 multiply by a double More...
 
void operator/= (const double &d)
 divide by a double More...
 
const doubleoperator[] (int i) const
 [] access function to the (local) values of this vector More...
 
double max () const
 returns the maximum coefficient More...
 
doublevalues_pt ()
 access function to the underlying values More...
 
doublevalues_pt () const
 access function to the underlying values (const version) More...
 
void output (std::ostream &outfile, const int &output_precision=-1) const
 output the global contents of the vector More...
 
void output (std::string filename, const int &output_precision=-1) const
 output the global contents of the vector More...
 
void output_local_values (std::ostream &outfile, const int &output_precision=-1) const
 output the local contents of the vector More...
 
void output_local_values (std::string filename, const int &output_precision=-1) const
 output the local contents of the vector More...
 
void output_local_values_with_offset (std::ostream &outfile, const int &output_precision=-1) const
 output the local contents of the vector More...
 
void output_local_values_with_offset (std::string filename, const int &output_precision=-1) const
 output the local contents of the vector More...
 
double dot (const DoubleVector &vec) const
 compute the dot product of this vector with the vector vec. More...
 
double norm () const
 compute the 2 norm of this vector More...
 
double norm (const CRDoubleMatrix *matrix_pt) const
 compute the A-norm using the matrix at matrix_pt More...
 
- Public Member Functions inherited from oomph::DistributableLinearAlgebraObject
 DistributableLinearAlgebraObject ()
 Default constructor - create a distribution. More...
 
 DistributableLinearAlgebraObject (const DistributableLinearAlgebraObject &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DistributableLinearAlgebraObject &)=delete
 Broken assignment operator. More...
 
virtual ~DistributableLinearAlgebraObject ()
 Destructor. More...
 
LinearAlgebraDistributiondistribution_pt () const
 access to the LinearAlgebraDistribution More...
 
unsigned nrow () const
 access function to the number of global rows. More...
 
unsigned nrow_local () const
 access function for the num of local rows on this processor. More...
 
unsigned nrow_local (const unsigned &p) const
 access function for the num of local rows on this processor. More...
 
unsigned first_row () const
 access function for the first row on this processor More...
 
unsigned first_row (const unsigned &p) const
 access function for the first row on this processor More...
 
bool distributed () const
 distribution is serial or distributed More...
 
bool distribution_built () const
 
void build_distribution (const LinearAlgebraDistribution *const dist_pt)
 
void build_distribution (const LinearAlgebraDistribution &dist)
 

Private Attributes

DoubleVectorHaloSchemeHalo_scheme_pt
 
Vector< doubleHalo_value
 Vector of the halo values. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 

Detailed Description

===================================================================== An extension of DoubleVector that allows access to certain global entries that are not stored locally. Synchronisation of these values must be performed manually by calling the synchronise() function. Synchronisation can only be from the haloed to the halo, but the local halo entries can all be summed and stored in the

haloed value.

Constructor & Destructor Documentation

◆ DoubleVectorWithHaloEntries() [1/5]

oomph::DoubleVectorWithHaloEntries::DoubleVectorWithHaloEntries ( )
inline

Constructor for an uninitialized DoubleVectorWithHaloEntries.

160 : DoubleVector(), Halo_scheme_pt(0) {}
DoubleVectorHaloScheme * Halo_scheme_pt
Definition: double_vector_with_halo.h:153
DoubleVector()
Constructor for an uninitialized DoubleVector.
Definition: double_vector.h:61

◆ DoubleVectorWithHaloEntries() [2/5]

oomph::DoubleVectorWithHaloEntries::DoubleVectorWithHaloEntries ( const LinearAlgebraDistribution *const &  dist_pt,
DoubleVectorHaloScheme *const &  halo_scheme_pt = 0,
const double v = 0.0 
)
inline

Constructor. Assembles a DoubleVectorWithHaloEntries with a prescribed distribution. Additionally every entry can be set (with argument v - defaults to 0).

170  : DoubleVector(dist_pt, v)
171  {
172  // construct the halo scheme
174  }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
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
DoubleVectorHaloScheme *& halo_scheme_pt()
Access function for halo scheme.
Definition: double_vector_with_halo.h:323

References build_halo_scheme(), and halo_scheme_pt().

◆ DoubleVectorWithHaloEntries() [3/5]

oomph::DoubleVectorWithHaloEntries::DoubleVectorWithHaloEntries ( const LinearAlgebraDistribution dist,
DoubleVectorHaloScheme *const &  halo_scheme_pt = 0,
const double v = 0.0 
)
inline

Constructor. Assembles a DoubleVectorWithHaloEntries with a prescribed distribution. Additionally every entry can be set (with argument v - defaults to 0).

184  : DoubleVector(dist, v)
185  {
186  // construct the halo scheme
188  }

References build_halo_scheme(), and halo_scheme_pt().

◆ ~DoubleVectorWithHaloEntries()

oomph::DoubleVectorWithHaloEntries::~DoubleVectorWithHaloEntries ( )
inline

Destructor.

191 {}

◆ DoubleVectorWithHaloEntries() [4/5]

oomph::DoubleVectorWithHaloEntries::DoubleVectorWithHaloEntries ( const DoubleVectorWithHaloEntries new_vector)
inline

Copy constructor from any DoubleVector.

196  : DoubleVector(new_vector)
197  {
198  // Build the appropriate halo scheme
199  this->build_halo_scheme(new_vector.halo_scheme_pt());
200  }

References build_halo_scheme(), and halo_scheme_pt().

◆ DoubleVectorWithHaloEntries() [5/5]

oomph::DoubleVectorWithHaloEntries::DoubleVectorWithHaloEntries ( const DoubleVector new_vector,
DoubleVectorHaloScheme *const &  halo_scheme_pt = 0 
)
inline

Copy constructor from any DoubleVector.

206  : DoubleVector(new_vector)
207  {
208  // Construct the halo scheme
210  }

References build_halo_scheme(), and halo_scheme_pt().

Member Function Documentation

◆ build_halo_scheme()

void oomph::DoubleVectorWithHaloEntries::build_halo_scheme ( DoubleVectorHaloScheme *const &  halo_scheme_pt)

Construct the halo scheme and storage for the halo data.

Construct the halo scheme and storage for the halo data

381  {
383 
384  if (Halo_scheme_pt != 0)
385  {
386  // Need to set up the halo data
387  unsigned n_halo_data = halo_scheme_pt->Local_index.size();
388 
389  // Resize the halo storage
390  Halo_value.resize(n_halo_data);
391 
392  // Now let's get the initial values from the other processors
393  this->synchronise();
394  }
395  }
std::map< unsigned, unsigned > Local_index
Definition: double_vector_with_halo.h:59
void synchronise()
Synchronise the halo data.
Definition: double_vector_with_halo.cc:269
Vector< double > Halo_value
Vector of the halo values.
Definition: double_vector_with_halo.h:156

References Halo_scheme_pt, halo_scheme_pt(), Halo_value, oomph::DoubleVectorHaloScheme::Local_index, and synchronise().

Referenced by DoubleVectorWithHaloEntries(), operator=(), oomph::PitchForkHandler::PitchForkHandler(), and oomph::Problem::setup_element_count_per_dof().

◆ global_value() [1/2]

double& oomph::DoubleVectorWithHaloEntries::global_value ( const unsigned i)
inline

Direct access to global entry.

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  }
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
unsigned local_index(const unsigned &global_eqn)
Return the local index associated with the global equation.
Definition: double_vector_with_halo.h:118
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::first_row(), Halo_scheme_pt, Halo_value, i, oomph::DoubleVectorHaloScheme::local_index(), oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by oomph::PitchForkHandler::get_dresiduals_dparameter(), oomph::PitchForkHandler::get_jacobian(), oomph::PitchForkHandler::get_residuals(), oomph::PitchForkHandler::PitchForkHandler(), and oomph::Problem::setup_element_count_per_dof().

◆ global_value() [2/2]

const double& oomph::DoubleVectorWithHaloEntries::global_value ( const unsigned i) const
inline

Direct access to the global entry (const version)

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  }

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::first_row(), Halo_scheme_pt, Halo_value, i, oomph::DoubleVectorHaloScheme::local_index(), oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ halo_scheme_pt() [1/2]

DoubleVectorHaloScheme*& oomph::DoubleVectorWithHaloEntries::halo_scheme_pt ( )
inline

Access function for halo scheme.

324  {
325  return Halo_scheme_pt;
326  }

References Halo_scheme_pt.

Referenced by build_halo_scheme(), DoubleVectorWithHaloEntries(), and operator=().

◆ halo_scheme_pt() [2/2]

DoubleVectorHaloScheme* const& oomph::DoubleVectorWithHaloEntries::halo_scheme_pt ( ) const
inline

Access function for halo scheme (const version)

330  {
331  return Halo_scheme_pt;
332  }

References Halo_scheme_pt.

◆ operator=()

void oomph::DoubleVectorWithHaloEntries::operator= ( const DoubleVectorWithHaloEntries old_vector)
inline

assignment operator

214  {
215  this->build(old_vector);
216  // Do some other stuff
217  this->build_halo_scheme(old_vector.halo_scheme_pt());
218  }
void build(const DoubleVector &old_vector)
Just copys the argument DoubleVector.
Definition: double_vector.cc:35

References oomph::DoubleVector::build(), build_halo_scheme(), and halo_scheme_pt().

◆ sum_all_halo_and_haloed_values()

void oomph::DoubleVectorWithHaloEntries::sum_all_halo_and_haloed_values ( )

Sum all the data, store in the master (haloed) data and then synchronise

Gather all ther data from multiple processors and sum the result which will be stored in the master copy and then synchronised to all copies. This requires two "all to all" communications

324  {
325 #ifdef OOMPH_HAS_MPI
326  // Only need to do anything if the DoubleVector is distributed
327  if (this->distributed())
328  {
329  // Send the Halo entries to the master processor
330  const unsigned n_send = Halo_scheme_pt->Halo_eqns.size();
331  Vector<double> send_data(n_send);
332  // Read out the data values
333  for (unsigned i = 0; i < n_send; i++)
334  {
335  send_data[i] = Halo_value[Halo_scheme_pt->Halo_eqns[i]];
336  }
337 
338  // Read out the number of entries to receive
339  const unsigned n_receive = Halo_scheme_pt->Haloed_eqns.size();
340  Vector<double> receive_data(n_receive);
341 
342  // Make sure that the send and receive data have size at least one
343  if (n_send == 0)
344  {
345  send_data.resize(1);
346  }
347  if (n_receive == 0)
348  {
349  receive_data.resize(1);
350  }
351  // Communicate
352  MPI_Alltoallv(&send_data[0],
353  &Halo_scheme_pt->Halo_n[0],
355  MPI_DOUBLE,
356  &receive_data[0],
359  MPI_DOUBLE,
360  this->distribution_pt()->communicator_pt()->mpi_comm());
361 
362 
363  // Now I need simply to update and sum my local values
364  for (unsigned i = 0; i < n_receive; i++)
365  {
366  (*this)[Halo_scheme_pt->Haloed_eqns[i]] += receive_data[i];
367  }
368 
369  // Then synchronise
370  this->synchronise();
371  }
372 #endif
373  }
Vector< int > Haloed_n
Definition: double_vector_with_halo.h:67
Vector< int > Halo_displacement
Definition: double_vector_with_halo.h:84
Vector< int > Halo_n
Definition: double_vector_with_halo.h:80
Vector< int > Haloed_displacement
Definition: double_vector_with_halo.h:71
Vector< unsigned > Haloed_eqns
Definition: double_vector_with_halo.h:63
Vector< unsigned > Halo_eqns
Definition: double_vector_with_halo.h:76

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DoubleVectorHaloScheme::Halo_displacement, oomph::DoubleVectorHaloScheme::Halo_eqns, oomph::DoubleVectorHaloScheme::Halo_n, Halo_scheme_pt, Halo_value, oomph::DoubleVectorHaloScheme::Haloed_displacement, oomph::DoubleVectorHaloScheme::Haloed_eqns, oomph::DoubleVectorHaloScheme::Haloed_n, i, and synchronise().

Referenced by oomph::PitchForkHandler::PitchForkHandler(), and oomph::Problem::setup_element_count_per_dof().

◆ synchronise()

void oomph::DoubleVectorWithHaloEntries::synchronise ( )

Synchronise the halo data.

Synchronise the halo data within the vector. This requires one "all to all" communnication.

270  {
271 #ifdef OOMPH_HAS_MPI
272  // Only need to do anything if the DoubleVector is distributed
273  if (this->distributed())
274  {
275  // Read out the number of entries to send
276  const unsigned n_send = Halo_scheme_pt->Haloed_eqns.size();
277  Vector<double> send_data(n_send);
278  // Read out the data values
279  for (unsigned i = 0; i < n_send; i++)
280  {
281  send_data[i] = (*this)[Halo_scheme_pt->Haloed_eqns[i]];
282  }
283 
284  // Read out the number of entries to receive
285  const unsigned n_receive = Halo_scheme_pt->Halo_eqns.size();
286  Vector<double> receive_data(n_receive);
287 
288  // Make sure that the send and receive data have size at least one
289  if (n_send == 0)
290  {
291  send_data.resize(1);
292  }
293  if (n_receive == 0)
294  {
295  receive_data.resize(1);
296  }
297  // Communicate
298  MPI_Alltoallv(&send_data[0],
301  MPI_DOUBLE,
302  &receive_data[0],
303  &Halo_scheme_pt->Halo_n[0],
305  MPI_DOUBLE,
306  this->distribution_pt()->communicator_pt()->mpi_comm());
307 
308 
309  // Now I need simply to update my local values
310  for (unsigned i = 0; i < n_receive; i++)
311  {
312  Halo_value[Halo_scheme_pt->Halo_eqns[i]] = receive_data[i];
313  }
314  }
315 #endif
316  }

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DoubleVectorHaloScheme::Halo_displacement, oomph::DoubleVectorHaloScheme::Halo_eqns, oomph::DoubleVectorHaloScheme::Halo_n, Halo_scheme_pt, Halo_value, oomph::DoubleVectorHaloScheme::Haloed_displacement, oomph::DoubleVectorHaloScheme::Haloed_eqns, oomph::DoubleVectorHaloScheme::Haloed_n, and i.

Referenced by build_halo_scheme(), and sum_all_halo_and_haloed_values().

Member Data Documentation

◆ Halo_scheme_pt

DoubleVectorHaloScheme* oomph::DoubleVectorWithHaloEntries::Halo_scheme_pt
private

Pointer to the lookup scheme that stores information about on which processor the required information is haloed

Referenced by build_halo_scheme(), global_value(), halo_scheme_pt(), sum_all_halo_and_haloed_values(), and synchronise().

◆ Halo_value

Vector<double> oomph::DoubleVectorWithHaloEntries::Halo_value
private

Vector of the halo values.

Referenced by build_halo_scheme(), global_value(), sum_all_halo_and_haloed_values(), and synchronise().


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