20 #ifndef GEOS_LINEARALGEBRA_UTILITIES_LAIHELPERFUNCTIONS_HPP_ 
   21 #define GEOS_LINEARALGEBRA_UTILITIES_LAIHELPERFUNCTIONS_HPP_ 
   32 namespace LAIHelperFunctions
 
   42 template< 
typename MATRIX >
 
   44                    MPI_Comm 
const & comm,
 
   47   mat.createWithLocalSize( n, 1, comm );
 
   49   for( 
globalIndex i = mat.ilower(); i < mat.iupper(); ++i )
 
   51     mat.insert( i, i, 1.0 );
 
   64 template< 
typename MATRIX >
 
   66                               int const nDofPerNode,
 
   67                               string const & dofKey,
 
   68                               MATRIX & permutationMatrix )
 
   78   permutationMatrix.createWithLocalSize( numLocalRows, numLocalRows, 1, 
MPI_COMM_GEOS );
 
   83   permutationMatrix.open();
 
   86     if( dofNumber[a] >= 0 )
 
   88       for( 
int d = 0; d < nDofPerNode; ++d )
 
   90         globalIndex const rowIndex    = localToGlobal[a] * nDofPerNode + d;
 
   92         permutationMatrix.insert( rowIndex, columnIndex, 1.0 );
 
   96   permutationMatrix.close();
 
   97   permutationMatrix.set( 1.0 );
 
  108 template< 
typename MATRIX >
 
  110                               int const nDofPerCell,
 
  111                               string const & dofKey,
 
  112                               MATRIX & permutationMatrix )
 
  125     if( elementSubRegion.hasWrapper( dofKey ) )
 
  127       numLocalRows += elementSubRegion.getNumberOfLocalIndices() * nDofPerCell;
 
  130   permutationMatrix.createWithLocalSize( numLocalRows, numLocalRows, 1, 
MPI_COMM_GEOS );
 
  132   permutationMatrix.open();
 
  135     localIndex const numElems = elementSubRegion.size();
 
  141       if( dofNumber[k] >= 0 )
 
  143         for( 
int d = 0; d < nDofPerCell; ++d )
 
  145           globalIndex const rowIndex    = localToGlobal[k] * nDofPerCell + d;
 
  147           permutationMatrix.insert( rowIndex, columnIndex, 1.0 );
 
  152   permutationMatrix.close();
 
  153   permutationMatrix.set( 1.0 );
 
  164 template< 
typename VECTOR, 
typename MATRIX >
 
  166                       MATRIX 
const & permutationMatrix )
 
  168   VECTOR permutedVector;
 
  169   permutedVector.create( vector.localSize(), permutationMatrix.comm() );
 
  170   permutationMatrix.apply( vector, permutedVector );
 
  171   return permutedVector;
 
  180 template< 
typename MATRIX >
 
  182                       MATRIX 
const & permutationMatrix )
 
  184   MATRIX permutedMatrix;
 
  185   matrix.multiplyRARt( permutationMatrix, permutedMatrix );
 
  196 template< 
typename MATRIX >
 
  198                       MATRIX 
const & permutationMatrixLeft,
 
  199                       MATRIX 
const & permutationMatrixRight )
 
  201   MATRIX permutedMatrix;
 
  202   matrix.multiplyRAP( permutationMatrixLeft, permutationMatrixRight, permutedMatrix );
 
  215 template< 
typename VECTOR >
 
  223   integer const numComponents = nodePosition.size( 1 );
 
  224   integer const numRidigBodyModes = numComponents * ( numComponents + 1 ) / 2;
 
  229   for( 
localIndex k = 0; k < numComponents; ++k )
 
  233     forAll< parallelHostPolicy >( dofIndex.size(), [=]( 
localIndex const i )
 
  235       localIndex const localDof = LvArray::integerConversion< localIndex >( dofIndex[i] - dofOffset );
 
  236       if( 0 <= localDof && localDof < numLocalDof )
 
  238         values[localDof + k] = 1.0;
 
  241     rigidBodyModes[k].close();
 
  242     rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
 
  246   for( 
localIndex k = numComponents; k < numRidigBodyModes; ++k )
 
  250     integer const ind[2] = { ( k - numComponents + 1 ) % numComponents,
 
  251                              ( k - numComponents + 2 ) % numComponents };
 
  252     forAll< parallelHostPolicy >( dofIndex.size(), [=]( 
localIndex const i )
 
  254       localIndex const localDof = LvArray::integerConversion< localIndex >( dofIndex[i] - dofOffset );
 
  255       if( 0 <= localDof && localDof < numLocalDof )
 
  257         values[localDof + ind[0]] = -nodePosition( i, ind[1] );
 
  258         values[localDof + ind[1]] = +nodePosition( i, ind[0] );
 
  261     rigidBodyModes[k].close();
 
  264       rigidBodyModes[k].axpy( -rigidBodyModes[k].dot( rigidBodyModes[j] ), rigidBodyModes[j] );
 
  266     rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
 
  269   return rigidBodyModes;
 
MATRIX permuteMatrix(MATRIX const &matrix, MATRIX const &permutationMatrix)
Permute rows and columns of a square matrix.
 
void createPermutationMatrix(NodeManager const &nodeManager, int const nDofPerNode, string const &dofKey, MATRIX &permutationMatrix)
Create a permutation matrix for a given nodal variable.
 
void makeIdentity(localIndex const n, MPI_Comm const &comm, MATRIX &mat)
Create an identity matrix.
 
VECTOR permuteVector(VECTOR const &vector, MATRIX const &permutationMatrix)
Permute a vector.
 
array1d< VECTOR > computeRigidBodyModes(arrayView2d< real64 const, nodes::REFERENCE_POSITION_USD > const &nodePosition, arrayView1d< globalIndex const > const &dofIndex, globalIndex const dofOffset, localIndex const numLocalDof)
Computes rigid body modes.
 
#define GEOS_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
 
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
 
void forElementSubRegions(LAMBDA &&lambda)
This function is used to launch kernel function over the element subregions of all the subregion type...
 
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
 
arrayView1d< globalIndex > localToGlobalMap()
Get local to global map.
 
localIndex getNumberOfLocalIndices() const
Get the number of locally owned objects.
 
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
 
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
 
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
 
int MPI_COMM_GEOS
Global MPI communicator used by GEOSX.
 
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
 
array1d< globalIndex > globalIndex_array
A 1-dimensional array of geos::globalIndex types.
 
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
 
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
 
int integer
Signed integer type.
 
Array< T, 1 > array1d
Alias for 1D array.