PetscExtensions

class PetscExtensions

Public Functions

PetscExtensions() = delete

Delete all constructors, all access should be static

PetscExtensions(const PetscExtensions&) = delete

Delete all constructors, all access should be static

Public Static Functions

static PetscErrorCode VecParallelFromSequential(Vec sequential, Vec *parallel)

Creates a parallel vector from a given sequential vector.

The parallel vector must already be created using either VecCreate followed by VecSetFromOptions, or from a VecDuplicate call.

Parameters:
  • sequential – the sequential vector to prallelize.

  • parallel – [out] the parallel vector to populate.

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode VecSequentialFromParallel(Vec parallel, Vec *sequential)

Creates a sequential vector from a given parallel vector.

The sequential vector will be created in the function, so a fresh Vec object can be passed.

Parameters:
  • parallel – the parallel vector to sequentialize.

  • sequential – [out] the sequential vector to populate.

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode VecGetOffProcessIndex(Vec parallelVector, PetscInt index, PetscScalar *result)

Fetches a value from a parallel vector that is not stored in the local vector.

This may not be the most efficient way of doing so, but it is fast enough not to bottleneck the code with large finite element analysis meshes to solve. It works as follows:

  1. Get a local sequential copy of the parallel vector of length 1

  2. Perform scatter operation for only the given index to retrieve

  3. Clean up and return the result

Parameters:
  • parallelVector – the parallel vector to access.

  • index – the index to retrieve from

  • result – [out] resulting value from the desired index.

Returns:

0 on success, PetscError otherwise.

template<typename T>
static inline PetscErrorCode VecParallelFromStdVector(std::vector<T> stdVector, Vec parallel)

Creates a parallel vector from a given C++ std vector.

The parallel vector must already be created using either VecCreate followed by VecSetFromOptions, or from a VecDuplicate call. This function simply populates the parallel vector with the contents of the std vector. This function is parallelized.

Note

This version of the overloaded function uses a templated vector type which is cast to PetscScalar. It should only be used if the vector type can safely be cast to PetscScalar.

Parameters:
  • stdVector – the std vector to prallelize.

  • parallel – [out] the parallel vector to populate.

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode VecParallelFromStdVector(std::vector<PetscScalar> stdVector, Vec parallel)

Creates a parallel vector from a given C++ std vector.

The parallel vector must already be created using either VecCreate followed by VecSetFromOptions, or from a VecDuplicate call. This function simply populates the parallel vector with the contents of the std vector. This function is parallelized.

Parameters:
  • stdVector – the std vector to prallelize.

  • parallel – [out] the parallel vector to populate.

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode VecLeftShift(Vec input, Vec *output)

Shifts all elements in the input vector down one index.

Note that this is an explicit shift, not a rotate. The last element in the vector is set to 0. This is a parallelized implementation, and is not optimized for sequential vectors.

Parameters:
  • input – the vector to shift.

  • output – [out] the shifted vector.

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode VecContainsNanOrInf(Vec input, PetscBool *out)

Parses a vector and returns whether or not it contains Not a Number or Infinite values.

Parameters:

input – the vector to parse.

Returns:

PetscTrue if Nan or Infinite numbers are found, PetscFalse otherwise.

static PetscErrorCode PrintVecMinMaxMean(Vec vector, const char *name)

Convenience function to print the minimum, maximum, and mean values of a vector.

Parameters:
  • vector – the vector to print values of.

  • name – name of the vector to print to print (for debug purposes).

Returns:

0 on success, PetscError otherwise.

static PetscErrorCode PrintVec(Vec vector, const char *name)

Convenience function to print all elements in a vector.

Parameters:
  • vector – the vector to print values of.

  • name – name of the vector to print to print (for debug purposes).

Returns:

0 on success, PetscError otherwise.