oomph::DoubleVector Class Reference

#include <double_vector.h>

+ Inheritance diagram for oomph::DoubleVector:

Public Member Functions

 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

doubleValues_pt
 the local vector More...
 
bool Internal_values
 
bool Built
 indicates that the vector has been built and is usable More...
 

Friends

std::ostream & operator<< (std::ostream &out, const DoubleVector &v)
 Ouput operator for DoubleVector. More...
 

Additional Inherited Members

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

Detailed Description

A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)

Constructor & Destructor Documentation

◆ DoubleVector() [1/4]

oomph::DoubleVector::DoubleVector ( )
inline

Constructor for an uninitialized DoubleVector.

61 : Values_pt(0), Internal_values(true), Built(false) {}
bool Internal_values
Definition: double_vector.h:323
bool Built
indicates that the vector has been built and is usable
Definition: double_vector.h:326
double * Values_pt
the local vector
Definition: double_vector.h:319

◆ DoubleVector() [2/4]

oomph::DoubleVector::DoubleVector ( const LinearAlgebraDistribution *const &  dist_pt,
const double v = 0.0 
)
inline

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

68  : Values_pt(0), Internal_values(true), Built(false)
69  {
70  this->build(dist_pt, v);
71  }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
void build(const DoubleVector &old_vector)
Just copys the argument DoubleVector.
Definition: double_vector.cc:35

References build(), and v.

◆ DoubleVector() [3/4]

oomph::DoubleVector::DoubleVector ( const LinearAlgebraDistribution dist,
const double v = 0.0 
)
inline

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

77  : Values_pt(0), Internal_values(true), Built(false)
78  {
79  this->build(dist, v);
80  }

References build(), and v.

◆ ~DoubleVector()

oomph::DoubleVector::~DoubleVector ( )
inline

Destructor - just calls this->clear() to delete the distribution and data

85  {
86  this->clear();
87  }
void clear()
wipes the DoubleVector
Definition: double_vector.h:142

References clear().

◆ DoubleVector() [4/4]

oomph::DoubleVector::DoubleVector ( const DoubleVector new_vector)
inline

Copy constructor.

92  Values_pt(0),
93  Internal_values(true),
94  Built(false)
95  {
96  this->build(new_vector);
97  }
DistributableLinearAlgebraObject()
Default constructor - create a distribution.
Definition: linear_algebra_distribution.h:438

References build().

Member Function Documentation

◆ build() [1/5]

void oomph::DoubleVector::build ( const DoubleVector old_vector)

Just copys the argument DoubleVector.

36  {
37  if (!(*this == old_vector))
38  {
39  // the vector owns the internal data
40  Internal_values = true;
41 
42  // reset the distribution and resize the data
43  this->build(old_vector.distribution_pt(), 0.0);
44 
45  // copy the data
46  if (this->distribution_built())
47  {
48  unsigned nrow_local = this->nrow_local();
49  const double* old_vector_values = old_vector.values_pt();
50  std::copy(old_vector_values, old_vector_values + nrow_local, Values_pt);
51  }
52  }
53  }
bool distribution_built() const
Definition: linear_algebra_distribution.h:500
unsigned nrow_local() const
access function for the num of local rows on this processor.
Definition: linear_algebra_distribution.h:469
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32

References copy(), oomph::DistributableLinearAlgebraObject::distribution_built(), oomph::DistributableLinearAlgebraObject::distribution_pt(), Internal_values, oomph::DistributableLinearAlgebraObject::nrow_local(), values_pt(), and Values_pt.

Referenced by oomph::OomphLibPreconditionerEpetraOperator::ApplyInverse(), build(), oomph::ComplexDampedJacobi< MATRIX >::complex_solve_helper(), oomph::DoubleVectorHelpers::concatenate(), oomph::DoubleVectorHelpers::concatenate_without_communication(), create_vector_ascend_row(), DoubleVector(), oomph::Problem::get_dofs(), oomph::Problem::get_inverse_mass_matrix_times_residuals(), oomph::Problem::get_jacobian(), oomph::Problem::get_residuals(), main(), oomph::TrilinosEpetraHelpers::multiply(), oomph::CRDoubleMatrix::multiply(), oomph::DenseDoubleMatrix::multiply(), oomph::CCDoubleMatrix::multiply(), oomph::CRDoubleMatrix::multiply_transpose(), oomph::DenseDoubleMatrix::multiply_transpose(), oomph::CCDoubleMatrix::multiply_transpose(), operator=(), oomph::DoubleVectorWithHaloEntries::operator=(), oomph::PitchForkHandler::PitchForkHandler(), BoussinesqPreconditioner::preconditioner_solve(), oomph::BlockDiagonalPreconditioner< MATRIX >::preconditioner_solve(), oomph::DummyBlockPreconditioner< MATRIX >::preconditioner_solve(), oomph::MatrixBasedDiagPreconditioner::preconditioner_solve(), oomph::MatrixBasedLumpedPreconditioner< MATRIX >::preconditioner_solve(), oomph::TrilinosPreconditionerBase::preconditioner_solve(), oomph::FSIPreconditioner::preconditioner_solve(), oomph::PseudoElasticFSIPreconditioner::preconditioner_solve(), oomph::LagrangeEnforcedFlowPreconditioner::preconditioner_solve(), oomph::NavierStokesSchurComplementPreconditioner::preconditioner_solve(), oomph::PressureBasedSolidLSCPreconditioner::preconditioner_solve(), oomph::SpaceTimeNavierStokesSubsidiaryPreconditioner::preconditioner_solve(), oomph::AugmentedBlockFoldLinearSolver::resolve(), oomph::BlockPitchForkLinearSolver::resolve(), oomph::AugmentedBlockPitchForkLinearSolver::resolve(), oomph::HSL_MA42::resolve(), run_it(), oomph::Problem::setup_element_count_per_dof(), oomph::DenseLU::solve(), oomph::TrilinosAztecOOSolver::solve(), oomph::AugmentedBlockFoldLinearSolver::solve(), oomph::AugmentedBlockPitchForkLinearSolver::solve(), oomph::HSL_MA42::solve(), oomph::CG< MATRIX >::solve(), oomph::BiCGStab< MATRIX >::solve(), oomph::GMRES< MATRIX >::solve(), oomph::AugmentedProblemGMRES::solve(), oomph::SuperLUSolver::solve(), oomph::MumpsSolver::solve(), oomph::HelmholtzGMRESMG< MATRIX >::solve(), oomph::HelmholtzFGMRESMG< MATRIX >::solve(), oomph::BlockHopfLinearSolver::solve_for_two_rhs(), oomph::GS< MATRIX >::solve_helper(), oomph::GS< CRDoubleMatrix >::solve_helper(), oomph::DampedJacobi< MATRIX >::solve_helper(), oomph::AugmentedProblemGMRES::solve_helper(), and oomph::SuperLUSolver::solve_transpose().

◆ build() [2/5]

void oomph::DoubleVector::build ( const LinearAlgebraDistribution dist,
const double v 
)
inline

Assembles a DoubleVector with distribution dist, if v is specified each element is set to v, otherwise each element is set to 0.0

111  {
112  this->build(&dist, v);
113  }

References build(), and v.

◆ build() [3/5]

void oomph::DoubleVector::build ( const LinearAlgebraDistribution dist,
const Vector< double > &  v 
)
inline

Assembles a DoubleVector with a distribution dist and coefficients taken from the vector v. Note. The vector v MUST be of length nrow()

124  {
125  this->build(&dist, v);
126  }

References build(), and v.

◆ build() [4/5]

void oomph::DoubleVector::build ( const LinearAlgebraDistribution *const &  dist_pt,
const double v 
)

Assembles a DoubleVector with distribution dist, if v is specified each element is set to v, otherwise each element is set to 0.0

Assembles a DoubleVector with distribution dist, if v is specified each row is set to v

61  {
62  // clean the memory
63  this->clear();
64 
65  // the vector owns the internal data
66  Internal_values = true;
67 
68  // Set the distribution
69  this->build_distribution(dist_pt);
70 
71  // update the values
72  if (dist_pt->built())
73  {
74  unsigned nrow_local = this->nrow_local();
75  Values_pt = new double[nrow_local];
76 
77  std::fill_n(Values_pt, nrow_local, v);
78  Built = true;
79  }
80  else
81  {
82  Built = false;
83  }
84  }
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507

References oomph::DistributableLinearAlgebraObject::build_distribution(), Built, oomph::LinearAlgebraDistribution::built(), clear(), Internal_values, oomph::DistributableLinearAlgebraObject::nrow_local(), v, and Values_pt.

◆ build() [5/5]

void oomph::DoubleVector::build ( const LinearAlgebraDistribution *const &  dist_pt,
const Vector< double > &  v 
)

Assembles a DoubleVector with a distribution dist and coefficients taken from the vector v. Note. The vector v MUST be of length nrow()

93  {
94  // clean the memory
95  this->clear();
96 
97  // the vector owns the internal data
98  Internal_values = true;
99 
100  // Set the distribution
101  this->build_distribution(dist_pt);
102 
103  // update the values
104  if (dist_pt->built())
105  {
106  // re-allocate memory which was deleted by clear()
107  unsigned nrow_local = this->nrow_local();
108  Values_pt = new double[nrow_local];
109 
110  // use the initialise method to populate the vector
111  this->initialise(v);
112  Built = true;
113  }
114  else
115  {
116  Built = false;
117  }
118  }
void initialise(const double &v)
initialise the whole vector with value v
Definition: double_vector.cc:123

References oomph::DistributableLinearAlgebraObject::build_distribution(), Built, oomph::LinearAlgebraDistribution::built(), clear(), initialise(), Internal_values, oomph::DistributableLinearAlgebraObject::nrow_local(), and Values_pt.

◆ built()

bool oomph::DoubleVector::built ( ) const
inline
155  {
156  return Built;
157  }

References Built.

Referenced by oomph::MumpsSolver::backsub(), oomph::SuperLUSolver::backsub_serial(), oomph::SuperLUSolver::backsub_transpose_serial(), oomph::Smoother::check_validity_of_solve_helper_inputs(), oomph::DoubleVectorHelpers::concatenate(), oomph::DoubleVectorHelpers::concatenate_without_communication(), oomph::TrilinosEpetraHelpers::copy_to_oomphlib_vector(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_vector(), oomph::TrilinosEpetraHelpers::create_epetra_vector_view_data(), dot(), oomph::Problem::get_jacobian(), oomph::Problem::get_residuals(), oomph::CRDoubleMatrix::lubksub(), oomph::TrilinosEpetraHelpers::multiply(), oomph::CRDoubleMatrix::multiply(), oomph::DenseDoubleMatrix::multiply(), oomph::CCDoubleMatrix::multiply(), oomph::CRDoubleMatrix::multiply_transpose(), oomph::DenseDoubleMatrix::multiply_transpose(), oomph::CCDoubleMatrix::multiply_transpose(), norm(), operator+=(), BoussinesqPreconditioner::preconditioner_solve(), oomph::BlockDiagonalPreconditioner< MATRIX >::preconditioner_solve(), oomph::MatrixBasedDiagPreconditioner::preconditioner_solve(), oomph::MatrixBasedLumpedPreconditioner< MATRIX >::preconditioner_solve(), oomph::ILUZeroPreconditioner< CCDoubleMatrix >::preconditioner_solve(), oomph::ILUZeroPreconditioner< CRDoubleMatrix >::preconditioner_solve(), oomph::HyprePreconditioner::preconditioner_solve(), oomph::IdentityPreconditioner::preconditioner_solve(), oomph::FSIPreconditioner::preconditioner_solve(), oomph::LagrangeEnforcedFlowPreconditioner::preconditioner_solve(), oomph::NavierStokesSchurComplementPreconditioner::preconditioner_solve(), oomph::PressureBasedSolidLSCPreconditioner::preconditioner_solve(), oomph::AugmentedBlockFoldLinearSolver::resolve(), oomph::BlockPitchForkLinearSolver::resolve(), oomph::AugmentedBlockPitchForkLinearSolver::resolve(), oomph::MumpsSolver::solve(), oomph::TrilinosAztecOOSolver::solve(), oomph::AugmentedBlockFoldLinearSolver::solve(), oomph::BlockPitchForkLinearSolver::solve(), oomph::AugmentedBlockPitchForkLinearSolver::solve(), oomph::BlockHopfLinearSolver::solve(), oomph::BiCGStab< MATRIX >::solve(), oomph::GMRES< MATRIX >::solve(), oomph::AugmentedProblemGMRES::solve(), oomph::FD_LU::solve(), oomph::SuperLUSolver::solve(), oomph::HelmholtzGMRESMG< MATRIX >::solve(), oomph::HelmholtzFGMRESMG< MATRIX >::solve(), oomph::BlockHopfLinearSolver::solve_for_two_rhs(), oomph::CG< MATRIX >::solve_helper(), oomph::BiCGStab< MATRIX >::solve_helper(), oomph::GMRES< MATRIX >::solve_helper(), oomph::AugmentedProblemGMRES::solve_helper(), oomph::HelmholtzGMRESMG< MATRIX >::solve_helper(), oomph::HelmholtzFGMRESMG< MATRIX >::solve_helper(), oomph::SuperLUSolver::solve_transpose(), oomph::DoubleVectorHelpers::split(), and oomph::DoubleVectorHelpers::split_without_communication().

◆ clear()

◆ dot()

double oomph::DoubleVector::dot ( const DoubleVector vec) const

compute the dot product of this vector with the vector vec.

compute the dot product of this vector with the vector vec

806  {
807 #ifdef PARANOID
808  // paranoid check that the vector is setup
809  if (!this->built())
810  {
811  std::ostringstream error_message;
812  error_message << "This vector must be setup.";
813  throw OomphLibError(
814  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
815  }
816  if (!vec.built())
817  {
818  std::ostringstream error_message;
819  error_message << "The input vector be setup.";
820  throw OomphLibError(
821  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
822  }
823  if (*this->distribution_pt() != *vec.distribution_pt())
824  {
825  std::ostringstream error_message;
826  error_message << "The distribution of this vector and the vector vec "
827  << "must be the same."
828  << "\n\n this: " << *this->distribution_pt()
829  << "\n vec: " << *vec.distribution_pt();
830  throw OomphLibError(
831  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
832  }
833 #endif
834 
835  // compute the local norm
836  unsigned nrow_local = this->nrow_local();
837  double n = 0.0;
838  const double* vec_values_pt = vec.values_pt();
839  for (unsigned i = 0; i < nrow_local; i++)
840  {
841  n += Values_pt[i] * vec_values_pt[i];
842  }
843 
844  // if this vector is distributed and on multiple processors then gather
845 #ifdef OOMPH_HAS_MPI
846  double n2 = n;
847  if (this->distributed() &&
848  this->distribution_pt()->communicator_pt()->nproc() > 1)
849  {
850  MPI_Allreduce(&n,
851  &n2,
852  1,
853  MPI_DOUBLE,
854  MPI_SUM,
855  this->distribution_pt()->communicator_pt()->mpi_comm());
856  }
857  n = n2;
858 #endif
859 
860  // and return;
861  return n;
862  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
bool distributed() const
distribution is serial or distributed
Definition: linear_algebra_distribution.h:493
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
bool built() const
Definition: double_vector.h:154
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References built(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, n, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, values_pt(), and Values_pt.

Referenced by oomph::AugmentedProblemGMRES::augmented_matrix_multiply(), oomph::Problem::calculate_continuation_derivatives_helper(), norm(), StabilityProblem< BASE_ELEMENT, PERTURBED_ELEMENT >::perform_power_method(), oomph::BlockPitchForkLinearSolver::resolve(), oomph::BlockPitchForkLinearSolver::solve(), oomph::CG< MATRIX >::solve_helper(), oomph::BiCGStab< MATRIX >::solve_helper(), and oomph::AugmentedProblemGMRES::solve_helper().

◆ initialise() [1/2]

◆ initialise() [2/2]

void oomph::DoubleVector::initialise ( const Vector< double v)

initialise the vector with coefficient from the vector v. Note: The vector v must be of length

139  {
140 #ifdef PARANOID
141  if (v.size() != this->nrow())
142  {
143  std::ostringstream error_message;
144  error_message << "The vector passed to initialise(...) must be of length "
145  << "nrow()";
146  throw OomphLibError(
147  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
148  }
149 #endif
150  unsigned begin_first_row = this->first_row();
151  unsigned end = begin_first_row + this->nrow_local();
152 
153  std::copy(v.begin() + begin_first_row, v.begin() + end, Values_pt);
154  }
unsigned first_row() const
access function for the first row on this processor
Definition: linear_algebra_distribution.h:481
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79

References copy(), Eigen::placeholders::end, oomph::DistributableLinearAlgebraObject::first_row(), oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, v, and Values_pt.

◆ max()

double oomph::DoubleVector::max ( ) const

returns the maximum coefficient

605  {
606  // the number of local rows
607  unsigned nrow = this->nrow_local();
608 
609  // get the local maximum
610  double max = 0.0;
611  for (unsigned i = 0; i < nrow; i++)
612  {
613  if (std::fabs(Values_pt[i]) > std::fabs(max))
614  {
615  max = std::fabs(Values_pt[i]);
616  }
617  }
618 
619  // now return the maximum
620 #ifdef OOMPH_HAS_MPI
621  // if this vector is not distributed then the local maximum is the global
622  // maximum
623  if (!this->distributed())
624  {
625  return max;
626  }
627  // else if the vector is distributed but only on a single processor
628  // then the local maximum is the global maximum
629  else if (this->distribution_pt()->communicator_pt()->nproc() == 1)
630  {
631  return max;
632  }
633  // otherwise use MPI_Allreduce to find the global maximum
634  else
635  {
636  double local_max = max;
637  MPI_Allreduce(&local_max,
638  &max,
639  1,
640  MPI_DOUBLE,
641  MPI_MAX,
642  this->distribution_pt()->communicator_pt()->mpi_comm());
643  return max;
644  }
645 #else
646  return max;
647 #endif
648  }
unsigned nrow() const
access function to the number of global rows.
Definition: linear_algebra_distribution.h:463
double max() const
returns the maximum coefficient
Definition: double_vector.cc:604
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:117

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), boost::multiprecision::fabs(), i, oomph::DistributableLinearAlgebraObject::nrow(), oomph::DistributableLinearAlgebraObject::nrow_local(), and Values_pt.

Referenced by SegregatedFSICollapsibleChannelProblem< ELEMENT >::actions_before_newton_convergence_check(), SegregatedFSICollapsibleChannelProblem< ELEMENT >::actions_before_segregated_convergence_check(), BaseCoupling< M, O >::checkResidual(), oomph::Problem::newton_solve(), BrethertonProblem< ELEMENT >::parameter_study(), oomph::SegregatableFSIProblem::segregated_solve(), oomph::SolidICProblem::set_newmark_initial_condition_consistently(), and HomogenisationProblem< ELEMENT >::sub_solve().

◆ norm() [1/2]

double oomph::DoubleVector::norm ( ) const

compute the 2 norm of this vector

868  {
869 #ifdef PARANOID
870  // paranoid check that the vector is setup
871  if (!this->built())
872  {
873  std::ostringstream error_message;
874  error_message << "This vector must be setup.";
875  throw OomphLibError(
876  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
877  }
878 #endif
879 
880  // compute the local norm
881  unsigned nrow_local = this->nrow_local();
882  double n = 0;
883  for (unsigned i = 0; i < nrow_local; i++)
884  {
885  n += Values_pt[i] * Values_pt[i];
886  }
887 
888  // if this vector is distributed and on multiple processors then gather
889 #ifdef OOMPH_HAS_MPI
890  double n2 = n;
891  if (this->distributed() &&
892  this->distribution_pt()->communicator_pt()->nproc() > 1)
893  {
894  MPI_Allreduce(&n,
895  &n2,
896  1,
897  MPI_DOUBLE,
898  MPI_SUM,
899  this->distribution_pt()->communicator_pt()->mpi_comm());
900  }
901  n = n2;
902 #endif
903 
904  // sqrt the norm
905  n = sqrt(n);
906 
907  // and return
908  return n;
909  }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134

References built(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, n, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, sqrt(), and Values_pt.

Referenced by oomph::ComplexDampedJacobi< MATRIX >::complex_solve_helper(), BaseStateProblem< BASE_ELEMENT >::doc_solution(), PerturbedStateProblem< BASE_ELEMENT, PERTURBED_ELEMENT >::doc_solution(), oomph::MyProblem::get_solution_norm(), oomph::HypreInterface::hypre_solve(), StabilityProblem< BASE_ELEMENT, PERTURBED_ELEMENT >::perform_power_method(), oomph::PitchForkHandler::PitchForkHandler(), oomph::CG< MATRIX >::solve_helper(), oomph::BiCGStab< MATRIX >::solve_helper(), oomph::GS< MATRIX >::solve_helper(), oomph::GS< CRDoubleMatrix >::solve_helper(), oomph::DampedJacobi< MATRIX >::solve_helper(), oomph::GMRES< MATRIX >::solve_helper(), and oomph::AugmentedProblemGMRES::solve_helper().

◆ norm() [2/2]

double oomph::DoubleVector::norm ( const CRDoubleMatrix matrix_pt) const

compute the A-norm using the matrix at matrix_pt

915  {
916 #ifdef PARANOID
917  // paranoid check that the vector is setup
918  if (!this->built())
919  {
920  std::ostringstream error_message;
921  error_message << "This vector must be setup.";
922  throw OomphLibError(
923  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
924  }
925  if (!matrix_pt->built())
926  {
927  std::ostringstream error_message;
928  error_message << "The input matrix be built.";
929  throw OomphLibError(
930  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
931  }
932  if (*this->distribution_pt() != *matrix_pt->distribution_pt())
933  {
934  std::ostringstream error_message;
935  error_message << "The distribution of this vector and the matrix at "
936  << "matrix_pt must be the same";
937  throw OomphLibError(
938  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
939  }
940 #endif
941 
942  // compute the matrix norm
943  DoubleVector x(this->distribution_pt(), 0.0);
944  matrix_pt->multiply(*this, x);
945  return sqrt(this->dot(x));
946  }
std::vector< double > DoubleVector
loads clump configuration
Definition: ClumpInput.h:26
double dot(const DoubleVector &vec) const
compute the dot product of this vector with the vector vec.
Definition: double_vector.cc:805
list x
Definition: plotDoE.py:28

References built(), oomph::CRDoubleMatrix::built(), oomph::DistributableLinearAlgebraObject::distribution_pt(), dot(), oomph::CRDoubleMatrix::multiply(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, sqrt(), and plotDoE::x.

◆ operator*=()

void oomph::DoubleVector::operator*= ( const double d)

multiply by a double

Multiply by double.

551  {
552 #ifdef PARANOID
553  if (!this->distribution_built())
554  {
555  std::ostringstream error_msg;
556  error_msg << "DoubleVector must be set up.";
557  throw OomphLibError(
559  }
560 #endif
561 
562  // Decided to keep this as a loop rather than use std::transform, because
563  // this is a very simple loop and should compile to the same code.
564  for (unsigned i = 0, ni = this->nrow_local(); i < ni; i++)
565  {
566  Values_pt[i] *= d;
567  }
568  }

References oomph::DistributableLinearAlgebraObject::distribution_built(), i, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Values_pt.

Referenced by operator/=().

◆ operator+=()

void oomph::DoubleVector::operator+= ( const DoubleVector v)

+= operator with another vector

+= operator

460  {
461 #ifdef PARANOID
462  // PARANOID check that this vector is setup
463  if (!this->built())
464  {
465  std::ostringstream error_message;
466  error_message << "This vector must be setup.";
467  throw OomphLibError(
468  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
469  }
470  // PARANOID check that the vector v is setup
471  if (!v.built())
472  {
473  std::ostringstream error_message;
474  error_message << "The vector v must be setup.";
475  throw OomphLibError(
476  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
477  }
478  // PARANOID check that the vectors have the same distribution
479  if (!(*v.distribution_pt() == *this->distribution_pt()))
480  {
481  std::ostringstream error_message;
482  error_message << "The vector v and this vector must have the same "
483  << "distribution.";
484  throw OomphLibError(
485  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
486  }
487 #endif //
488 
489  // cache nrow_local
490  double* v_values_pt = v.values_pt();
491  unsigned nrow_local = this->nrow_local();
492 
493  // Decided to keep this as a loop rather than use std::transform, because
494  // this is a very simple loop and should compile to the same code.
495  for (unsigned i = 0; i < nrow_local; i++)
496  {
497  Values_pt[i] += v_values_pt[i];
498  }
499  }

References built(), i, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, v, and Values_pt.

◆ operator-=()

void oomph::DoubleVector::operator-= ( const DoubleVector v)

-= operator with another vector

-= operator

505  {
506 #ifdef PARANOID
507  // PARANOID check that this vector is setup
508  if (!this->distribution_built())
509  {
510  std::ostringstream error_message;
511  error_message << "This vector must be setup.";
512  throw OomphLibError(
513  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
514  }
515  // PARANOID check that the vector v is setup
516  if (!v.built())
517  {
518  std::ostringstream error_message;
519  error_message << "The vector v must be setup.";
520  throw OomphLibError(
521  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
522  }
523  // PARANOID check that the vectors have the same distribution
524  if (!(*v.distribution_pt() == *this->distribution_pt()))
525  {
526  std::ostringstream error_message;
527  error_message << "The vector v and this vector must have the same "
528  << "distribution.";
529  throw OomphLibError(
530  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
531  }
532 #endif
533 
534  // cache nrow_local
535  double* v_values_pt = v.values_pt();
536  unsigned nrow_local = this->nrow_local();
537 
538  // Decided to keep this as a loop rather than use std::transform, because
539  // this is a very simple loop and should compile to the same code.
540  for (unsigned i = 0; i < nrow_local; i++)
541  {
542  Values_pt[i] -= v_values_pt[i];
543  }
544  }

References oomph::DistributableLinearAlgebraObject::distribution_built(), i, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, v, and Values_pt.

◆ operator/=()

void oomph::DoubleVector::operator/= ( const double d)

divide by a double

Divide by double.

574  {
575  // PARANOID checks are done inside operator *=
576 
577  // Decided to keep this as a loop rather than use std::transform, because
578  // this is a very simple loop and should compile to the same code.
579  double divisor = (1.0 / d);
580  this->operator*=(divisor);
581  }
void operator*=(const double &d)
multiply by a double
Definition: double_vector.cc:550

References operator*=().

◆ operator=()

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

assignment operator

101  {
102  this->build(old_vector);
103  }

References build().

◆ operator==()

bool oomph::DoubleVector::operator== ( const DoubleVector v)

== operator

427  {
428  // if v is not setup return false
429  if (v.built() && !this->built())
430  {
431  return false;
432  }
433  else if (!v.built() && this->built())
434  {
435  return false;
436  }
437  else if (!v.built() && !this->built())
438  {
439  return true;
440  }
441  else
442  {
443  const double* v_values_pt = v.values_pt();
444  unsigned nrow_local = this->nrow_local();
445  for (unsigned i = 0; i < nrow_local; i++)
446  {
447  if (Values_pt[i] != v_values_pt[i])
448  {
449  return false;
450  }
451  }
452  return true;
453  }
454  }

References i, oomph::DistributableLinearAlgebraObject::nrow_local(), v, and Values_pt.

◆ operator[]() [1/2]

double & oomph::DoubleVector::operator[] ( int  i)

[] access function to the (local) values of this vector

409  {
410 #ifdef RANGE_CHECKING
411  if (i >= int(this->nrow_local()))
412  {
413  std::ostringstream error_message;
414  error_message << "Range Error: " << i << " is not in the range (0,"
415  << this->nrow_local() - 1 << ")";
416  throw OomphLibError(
417  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
418  }
419 #endif
420  return Values_pt[i];
421  }

References i, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Values_pt.

◆ operator[]() [2/2]

const double & oomph::DoubleVector::operator[] ( int  i) const

[] access function to the (local) values of this vector

587  {
588 #ifdef RANGE_CHECKING
589  if (i >= int(this->nrow_local()))
590  {
591  std::ostringstream error_message;
592  error_message << "Range Error: " << i << " is not in the range (0,"
593  << this->nrow_local() - 1 << ")";
594  throw OomphLibError(
595  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
596  }
597 #endif
598  return Values_pt[i];
599  }

References i, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Values_pt.

◆ output() [1/2]

void oomph::DoubleVector::output ( std::ostream &  outfile,
const int output_precision = -1 
) const

output the global contents of the vector

output the contents of the vector

655  {
656  // temp pointer to values
657  double* temp;
658 
659  // number of global row
660  unsigned nrow = this->nrow();
661 
662 #ifdef OOMPH_HAS_MPI
663 
664  // number of local rows
665  int nrow_local = this->nrow_local();
666 
667  // gather from all processors
668  if (this->distributed() &&
669  this->distribution_pt()->communicator_pt()->nproc() > 1)
670  {
671  // number of processors
672  int nproc = this->distribution_pt()->communicator_pt()->nproc();
673 
674  // number of gobal row
675  unsigned nrow = this->nrow();
676 
677  // get the vector of first_row s and nrow_local s
678  int* dist_first_row = new int[nproc];
679  int* dist_nrow_local = new int[nproc];
680  for (int p = 0; p < nproc; p++)
681  {
682  dist_first_row[p] = this->first_row(p);
683  dist_nrow_local[p] = this->nrow_local(p);
684  }
685 
686  // gather
687  temp = new double[nrow];
688  MPI_Allgatherv(Values_pt,
689  nrow_local,
690  MPI_DOUBLE,
691  temp,
692  dist_nrow_local,
693  dist_first_row,
694  MPI_DOUBLE,
695  this->distribution_pt()->communicator_pt()->mpi_comm());
696 
697  // clean up
698  delete[] dist_first_row;
699  delete[] dist_nrow_local;
700  }
701  else
702  {
703  temp = Values_pt;
704  }
705 #else
706  temp = Values_pt;
707 #endif
708 
709  // output
710  // Store the precision so we can revert it.
711  std::streamsize old_precision = 0;
712  if (output_precision > 0)
713  {
714  old_precision = outfile.precision();
715  outfile << std::setprecision(output_precision);
716  }
717 
718  for (unsigned i = 0; i < nrow; i++)
719  {
720  outfile << i << " " << temp[i] << std::endl;
721  }
722 
723  // Revert the precision.
724  if (output_precision > 0)
725  {
726  outfile << std::setprecision(old_precision);
727  }
728 
729  // clean up if requires
730 #ifdef OOMPH_HAS_MPI
731  if (this->distributed() &&
732  this->distribution_pt()->communicator_pt()->nproc() > 1)
733  {
734  delete[] temp;
735  }
736 #endif
737  }
float * p
Definition: Tutorial_Map_using.cpp:9
OomphCommunicator * communicator_pt() const
const access to the communicator pointer
Definition: linear_algebra_distribution.h:335
int nproc() const
number of processors
Definition: communicator.h:157

References oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::DistributableLinearAlgebraObject::first_row(), i, oomph::OomphCommunicator::nproc(), oomph::DistributableLinearAlgebraObject::nrow(), oomph::DistributableLinearAlgebraObject::nrow_local(), p, and Values_pt.

Referenced by output().

◆ output() [2/2]

void oomph::DoubleVector::output ( std::string  filename,
const int output_precision = -1 
) const
inline

output the global contents of the vector

270  {
271  // Open file
272  std::ofstream some_file;
273  some_file.open(filename.c_str());
274  output(some_file, output_precision);
275  some_file.close();
276  }
void output(std::ostream &outfile, const int &output_precision=-1) const
output the global contents of the vector
Definition: double_vector.cc:653
string filename
Definition: MergeRestartFiles.py:39

References MergeRestartFiles::filename, and output().

◆ output_local_values() [1/2]

void oomph::DoubleVector::output_local_values ( std::ostream &  outfile,
const int output_precision = -1 
) const

output the local contents of the vector

744  {
745  // Number of local rows.
746  unsigned nrow_local = this->nrow_local();
747 
748  // output
749  // Store the precision so we can revert it.
750  std::streamsize old_precision = 0;
751  if (output_precision > 0)
752  {
753  old_precision = outfile.precision();
754  outfile << std::setprecision(output_precision);
755  }
756 
757  for (unsigned i = 0; i < nrow_local; i++)
758  {
759  outfile << i << " " << Values_pt[i] << std::endl;
760  }
761 
762  // Revert the precision.
763  if (output_precision > 0)
764  {
765  outfile << std::setprecision(old_precision);
766  }
767  }

References i, oomph::DistributableLinearAlgebraObject::nrow_local(), and Values_pt.

Referenced by output_local_values().

◆ output_local_values() [2/2]

void oomph::DoubleVector::output_local_values ( std::string  filename,
const int output_precision = -1 
) const
inline

output the local contents of the vector

285  {
286  // Open file
287  std::ofstream some_file;
288  some_file.open(filename.c_str());
289  output_local_values(some_file, output_precision);
290  some_file.close();
291  }
void output_local_values(std::ostream &outfile, const int &output_precision=-1) const
output the local contents of the vector
Definition: double_vector.cc:742

References MergeRestartFiles::filename, and output_local_values().

◆ output_local_values_with_offset() [1/2]

void oomph::DoubleVector::output_local_values_with_offset ( std::ostream &  outfile,
const int output_precision = -1 
) const

output the local contents of the vector

output the local contents of the vector with the first row offset.

774  {
775  // Number of local rows.
776  unsigned nrow_local = this->nrow_local();
777 
778  // First row on this processor.
779  unsigned first_row = this->first_row();
780 
781  // output
782  // Store the precision so we can revert it.
783  std::streamsize old_precision = 0;
784  if (output_precision > 0)
785  {
786  old_precision = outfile.precision();
787  outfile << std::setprecision(output_precision);
788  }
789 
790  for (unsigned i = 0; i < nrow_local; i++)
791  {
792  outfile << (i + first_row) << " " << Values_pt[i] << std::endl;
793  }
794 
795  // Revert the precision.
796  if (output_precision > 0)
797  {
798  outfile << std::setprecision(old_precision);
799  }
800  }

References oomph::DistributableLinearAlgebraObject::first_row(), i, oomph::DistributableLinearAlgebraObject::nrow_local(), and Values_pt.

Referenced by output_local_values_with_offset().

◆ output_local_values_with_offset() [2/2]

void oomph::DoubleVector::output_local_values_with_offset ( std::string  filename,
const int output_precision = -1 
) const
inline

output the local contents of the vector

300  {
301  // Open file
302  std::ofstream some_file;
303  some_file.open(filename.c_str());
304  output_local_values_with_offset(some_file, output_precision);
305  some_file.close();
306  }
void output_local_values_with_offset(std::ostream &outfile, const int &output_precision=-1) const
output the local contents of the vector
Definition: double_vector.cc:772

References MergeRestartFiles::filename, and output_local_values_with_offset().

◆ redistribute()

void oomph::DoubleVector::redistribute ( const LinearAlgebraDistribution *const &  dist_pt)

The contents of the vector are redistributed to match the new distribution. In a non-MPI rebuild this method works, but does nothing. NOTE 1: The current distribution and the new distribution must have the same number of global rows. NOTE 2: The current distribution and the new distribution must have the same Communicator.

The contents of the vector are redistributed to match the new distribution. In a non-MPI build this method works, but does nothing. NOTE 1: The current distribution and the new distribution must have the same number of global rows. NOTE 2: The current distribution and the new distribution must have the same Communicator.

166  {
167 #ifdef OOMPH_HAS_MPI
168 #ifdef PARANOID
169  if (!Internal_values)
170  {
171  // if this vector does not own the double* values then it cannot be
172  // distributed.
173  // note: this is not stictly necessary - would just need to be careful
174  // with delete[] below.
175  std::ostringstream error_message;
176  error_message << "This vector does not own its data (i.e. it has been "
177  << "passed in via set_external_values() and therefore "
178  << "cannot be redistributed";
179  throw OomphLibError(
180  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
181  }
182  // paranoid check that the nrows for both distributions is the
183  // same
184  if (dist_pt->nrow() != this->nrow())
185  {
186  std::ostringstream error_message;
187  error_message << "The number of global rows in the new distribution ("
188  << dist_pt->nrow() << ") is not equal to the number"
189  << " of global rows in the current distribution ("
190  << this->nrow() << ").\n";
191  throw OomphLibError(
192  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
193  }
194  // paranoid check that the current distribution and the new distribution
195  // have the same Communicator
196  OomphCommunicator temp_comm(*dist_pt->communicator_pt());
197  if (!(temp_comm == *this->distribution_pt()->communicator_pt()))
198  {
199  std::ostringstream error_message;
200  error_message << "The new distribution and the current distribution must "
201  << "have the same communicator.";
202  throw OomphLibError(
203  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
204  }
205 #endif
206 
207  // check the distributions are not the same
208  if (!((*this->distribution_pt()) == *dist_pt))
209  {
210  // get the rank and the number of processors
211  int my_rank = this->distribution_pt()->communicator_pt()->my_rank();
212  int nproc = this->distribution_pt()->communicator_pt()->nproc();
213 
214  // if both vectors are distributed
215  if (this->distributed() && dist_pt->distributed())
216  {
217  // new nrow_local and first_row data
218  Vector<unsigned> new_first_row_data(nproc);
219  Vector<unsigned> new_nrow_local_data(nproc);
220  Vector<unsigned> current_first_row_data(nproc);
221  Vector<unsigned> current_nrow_local_data(nproc);
222  for (int i = 0; i < nproc; i++)
223  {
224  new_first_row_data[i] = dist_pt->first_row(i);
225  new_nrow_local_data[i] = dist_pt->nrow_local(i);
226  current_first_row_data[i] = this->first_row(i);
227  current_nrow_local_data[i] = this->nrow_local(i);
228  }
229 
230  // compute which local rows are expected to be received from each
231  // processor / sent to each processor
232  Vector<unsigned> new_first_row_for_proc(nproc);
233  Vector<unsigned> new_nrow_local_for_proc(nproc);
234  Vector<unsigned> new_first_row_from_proc(nproc);
235  Vector<unsigned> new_nrow_local_from_proc(nproc);
236 
237  // for every processor compute first_row and nrow_local that will
238  // will sent and received by this processor
239  for (int p = 0; p < nproc; p++)
240  {
241  // start with data to be sent
242  if ((new_first_row_data[p] < (current_first_row_data[my_rank] +
243  current_nrow_local_data[my_rank])) &&
244  (current_first_row_data[my_rank] <
245  (new_first_row_data[p] + new_nrow_local_data[p])))
246  {
247  new_first_row_for_proc[p] =
248  std::max(current_first_row_data[my_rank], new_first_row_data[p]);
249  new_nrow_local_for_proc[p] =
250  std::min((current_first_row_data[my_rank] +
251  current_nrow_local_data[my_rank]),
252  (new_first_row_data[p] + new_nrow_local_data[p])) -
253  new_first_row_for_proc[p];
254  }
255 
256  // and data to be received
257  if ((new_first_row_data[my_rank] <
258  (current_first_row_data[p] + current_nrow_local_data[p])) &&
259  (current_first_row_data[p] <
260  (new_first_row_data[my_rank] + new_nrow_local_data[my_rank])))
261  {
262  new_first_row_from_proc[p] =
263  std::max(current_first_row_data[p], new_first_row_data[my_rank]);
264  new_nrow_local_from_proc[p] =
265  std::min(
266  (current_first_row_data[p] + current_nrow_local_data[p]),
267  (new_first_row_data[my_rank] + new_nrow_local_data[my_rank])) -
268  new_first_row_from_proc[p];
269  }
270  }
271 
272  // temporary storage for the new data
273  double* temp_data = new double[new_nrow_local_data[my_rank]];
274 
275  // "send to self" or copy Data that does not need to be sent else where
276  // to temp_data
277  if (new_nrow_local_for_proc[my_rank] != 0)
278  {
279  unsigned j =
280  new_first_row_for_proc[my_rank] - current_first_row_data[my_rank];
281  unsigned k =
282  new_first_row_for_proc[my_rank] - new_first_row_data[my_rank];
283  for (unsigned i = 0; i < new_nrow_local_for_proc[my_rank]; i++)
284  {
285  temp_data[k + i] = Values_pt[j + i];
286  }
287  }
288 
289  // send and receive circularly
290  for (int p = 1; p < nproc; p++)
291  {
292  // next processor to send to
293  unsigned dest_p = (my_rank + p) % nproc;
294 
295  // next processor to receive from
296  unsigned source_p = (nproc + my_rank - p) % nproc;
297 
298  // send and receive the value
299  MPI_Status status;
300  MPI_Sendrecv(Values_pt + new_first_row_for_proc[dest_p] -
301  current_first_row_data[my_rank],
302  new_nrow_local_for_proc[dest_p],
303  MPI_DOUBLE,
304  dest_p,
305  1,
306  temp_data + new_first_row_from_proc[source_p] -
307  new_first_row_data[my_rank],
308  new_nrow_local_from_proc[source_p],
309  MPI_DOUBLE,
310  source_p,
311  1,
312  this->distribution_pt()->communicator_pt()->mpi_comm(),
313  &status);
314  }
315 
316  // copy from temp data to Values_pt
317  delete[] Values_pt;
318  unsigned nrow_local = dist_pt->nrow_local();
319  Values_pt = new double[nrow_local];
320  for (unsigned i = 0; i < nrow_local; i++)
321  {
322  Values_pt[i] = temp_data[i];
323  }
324  delete[] temp_data;
325  }
326 
327  // if this vector is distributed but the new distributed is global
328  else if (this->distributed() && !dist_pt->distributed())
329  {
330  // copy existing Values_pt to temp_data
331  unsigned nrow_local = this->nrow_local();
332  double* temp_data = new double[nrow_local];
333  for (unsigned i = 0; i < nrow_local; i++)
334  {
335  temp_data[i] = Values_pt[i];
336  }
337 
338  // clear and resize Values_pt
339  delete[] Values_pt;
340  Values_pt = new double[this->nrow()];
341 
342  // create a int vector of first rows
343  int* dist_first_row = new int[nproc];
344  int* dist_nrow_local = new int[nproc];
345  for (int p = 0; p < nproc; p++)
346  {
347  dist_first_row[p] = this->first_row(p);
348  dist_nrow_local[p] = this->nrow_local(p);
349  }
350 
351  // gather the local vectors from all processors on all processors
352  int my_nrow_local(this->nrow_local());
353  MPI_Allgatherv(temp_data,
354  my_nrow_local,
355  MPI_DOUBLE,
356  Values_pt,
357  dist_nrow_local,
358  dist_first_row,
359  MPI_DOUBLE,
360  this->distribution_pt()->communicator_pt()->mpi_comm());
361 
362  // update the distribution
363  this->build_distribution(dist_pt);
364 
365  // delete the temp_data
366  delete[] temp_data;
367 
368  // clean up
369  delete[] dist_first_row;
370  delete[] dist_nrow_local;
371  }
372 
373  // if this vector is not distrubted but the target vector is
374  else if (!this->distributed() && dist_pt->distributed())
375  {
376  // cache the new nrow_local
377  unsigned nrow_local = dist_pt->nrow_local();
378 
379  // and first_row
380  unsigned first_row = dist_pt->first_row();
381 
382  // temp storage for the new data
383  double* temp_data = new double[nrow_local];
384 
385  // copy the data
386  for (unsigned i = 0; i < nrow_local; i++)
387  {
388  temp_data[i] = Values_pt[first_row + i];
389  }
390 
391  // copy to Values_pt
392  delete[] Values_pt;
393  Values_pt = temp_data;
394 
395  // update the distribution
396  this->build_distribution(dist_pt);
397  }
398 
399  // copy the Distribution
400  this->build_distribution(dist_pt);
401  }
402 #endif
403  }
int my_rank() const
my rank
Definition: communicator.h:176
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
char char char int int * k
Definition: level2_impl.h:374
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::DistributableLinearAlgebraObject::build_distribution(), oomph::LinearAlgebraDistribution::communicator_pt(), oomph::LinearAlgebraDistribution::distributed(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearAlgebraDistribution::first_row(), oomph::DistributableLinearAlgebraObject::first_row(), i, Internal_values, j, k, max, min, oomph::OomphCommunicator::my_rank(), oomph::OomphCommunicator::nproc(), oomph::LinearAlgebraDistribution::nrow(), oomph::DistributableLinearAlgebraObject::nrow(), oomph::LinearAlgebraDistribution::nrow_local(), oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, p, and Values_pt.

Referenced by oomph::MumpsSolver::backsub(), oomph::Problem::calculate_continuation_derivatives_helper(), oomph::Problem::get_jacobian(), main(), oomph::Problem::newton_solve(), oomph::Problem::newton_solve_continuation(), oomph::ILUZeroPreconditioner< CCDoubleMatrix >::preconditioner_solve(), oomph::ILUZeroPreconditioner< CRDoubleMatrix >::preconditioner_solve(), oomph::BlockPitchForkLinearSolver::resolve(), oomph::BlockPitchForkLinearSolver::solve(), oomph::CG< MATRIX >::solve(), oomph::BiCGStab< MATRIX >::solve(), oomph::GMRES< MATRIX >::solve(), oomph::AugmentedProblemGMRES::solve(), oomph::SuperLUSolver::solve(), oomph::MumpsSolver::solve(), oomph::HelmholtzGMRESMG< MATRIX >::solve(), oomph::HelmholtzFGMRESMG< MATRIX >::solve(), and oomph::SuperLUSolver::solve_transpose().

◆ set_external_values() [1/2]

void oomph::DoubleVector::set_external_values ( const LinearAlgebraDistribution *const &  dist_pt,
double external_values,
bool  delete_external_values 
)
inline

Allows are external data to be used by this vector. WARNING: The size of the external data must correspond to the LinearAlgebraDistribution dist_pt argument.

  1. When a rebuild method is called new internal values are created.
  2. It is not possible to redistribute(...) a vector with external values .
  3. External values are only deleted by this vector if delete_external_values = true.
170  {
171  // clean the memory
172  this->clear();
173 
174  // Set the distribution
175  this->build_distribution(dist_pt);
176  // Say that it's built
177  Built = true;
178 
179  // set the external values
180  set_external_values(external_values, delete_external_values);
181  }
void set_external_values(const LinearAlgebraDistribution *const &dist_pt, double *external_values, bool delete_external_values)
Definition: double_vector.h:167

References oomph::DistributableLinearAlgebraObject::build_distribution(), Built, and clear().

Referenced by oomph::OomphLibPreconditionerEpetraOperator::ApplyInverse(), oomph::Problem::get_jacobian(), and oomph::Problem::get_residuals().

◆ set_external_values() [2/2]

void oomph::DoubleVector::set_external_values ( double external_values,
bool  delete_external_values 
)
inline

Allows are external data to be used by this vector. WARNING: The size of the external data must correspond to the distribution of this vector.

  1. When a rebuild method is called new internal values are created.
  2. It is not possible to redistribute(...) a vector with external values .
  3. External values are only deleted by this vector if delete_external_values = true.
193  {
194 #ifdef PARANOID
195  // check that this distribution is setup
196  if (!this->distribution_built())
197  {
198  // if this vector does not own the double* values then it cannot be
199  // distributed.
200  // note: this is not stictly necessary - would just need to be careful
201  // with delete[] below.
202  std::ostringstream error_message;
203  error_message << "The distribution of the vector must be setup before "
204  << "external values can be set";
205  throw OomphLibError(error_message.str(),
208  }
209 #endif
210  if (Internal_values)
211  {
212  delete[] Values_pt;
213  }
214  Values_pt = external_values;
215  Internal_values = delete_external_values;
216  }

References oomph::DistributableLinearAlgebraObject::distribution_built(), Internal_values, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Values_pt.

◆ values_pt() [1/2]

double* oomph::DoubleVector::values_pt ( )
inline

◆ values_pt() [2/2]

double* oomph::DoubleVector::values_pt ( ) const
inline

access function to the underlying values (const version)

261  {
262  return Values_pt;
263  }

References Values_pt.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const DoubleVector v 
)
friend

Ouput operator for DoubleVector.

950  {
951  // Do the first value outside the loop to get the ", "s right.
952  out << "[" << v[0];
953 
954  for (unsigned i = 1, ni = v.nrow_local(); i < ni; i++)
955  {
956  out << ", " << v[i];
957  }
958  out << "]";
959 
960  return out;
961  }
std::ofstream out("Result.txt")

Member Data Documentation

◆ Built

bool oomph::DoubleVector::Built
private

indicates that the vector has been built and is usable

Referenced by build(), built(), clear(), initialise(), and set_external_values().

◆ Internal_values

bool oomph::DoubleVector::Internal_values
private

Boolean flag to indicate whether the vector's data (values_pt) is owned by this vector.

Referenced by build(), clear(), redistribute(), and set_external_values().

◆ Values_pt


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