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 );
214 template<
typename VECTOR >
217 std::vector< string >
const & selection,
224 for(
localIndex k = 0; k < LvArray::integerConversion< localIndex >( selection.size() ); ++k )
228 string const & dispDofKey = dofManager.
getKey( selection[k] );
231 numComponents = numComponents > 0 ? numComponents : numComponentsField;
232 GEOS_ERROR_IF( numComponents != numComponentsField,
"Rigid body modes called with different number of components." );
234 globalIndex const numLocalDofs = LvArray::integerConversion< globalIndex >( dofManager.
numLocalDofs( selection[k] ) );
235 for(
globalIndex i = 0; i < dofNumber.size(); ++i )
237 if( dofNumber[i] >= globalOffset && ( dofNumber[i] - globalOffset ) < numLocalDofs )
239 globalNodeList.emplace_back( LvArray::integerConversion< localIndex >( dofNumber[i] - globalOffset ) / numComponentsField );
244 localIndex const numNodes = globalNodeList.size();
249 localIndex const numRidigBodyModes = numComponents * ( numComponents + 1 ) / 2;
250 rigidBodyModes.resize( numRidigBodyModes );
251 for(
localIndex k = 0; k < numComponents; ++k )
253 rigidBodyModes[k].create( numNodes * numComponents,
MPI_COMM_GEOS );
255 forAll< parallelHostPolicy >( numNodes, [=](
localIndex const i )
257 values[numComponents * i + k] = 1.0;
259 rigidBodyModes[k].close();
260 rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
262 switch( numComponents )
267 rigidBodyModes[k].create( numNodes*numComponents,
MPI_COMM_GEOS );
270 forAll< parallelHostPolicy >( numNodes, [=](
localIndex const i )
272 values[numComponents * i + 0] = -nodePosition[globalNodeListView[i]][1];
273 values[numComponents * i + 1] = +nodePosition[globalNodeListView[i]][0];
275 rigidBodyModes[k].close();
280 rigidBodyModes[k].axpy( -rigidBodyModes[k].dot( rigidBodyModes[j] ), rigidBodyModes[j] );
282 rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
288 rigidBodyModes[k].create( numNodes*numComponents,
MPI_COMM_GEOS );
291 forAll< parallelHostPolicy >( numNodes, [=](
localIndex const i )
293 values[numComponents * i + 0] = +nodePosition[globalNodeListView[i]][1];
294 values[numComponents * i + 1] = -nodePosition[globalNodeListView[i]][0];
296 rigidBodyModes[k].close();
301 rigidBodyModes[k].axpy( -rigidBodyModes[k].dot( rigidBodyModes[j] ), rigidBodyModes[j] );
303 rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
306 rigidBodyModes[k].create( numNodes*numComponents,
MPI_COMM_GEOS );
309 forAll< parallelHostPolicy >( numNodes, [=](
localIndex const i )
311 values[numComponents * i + 1] = -nodePosition[globalNodeListView[i]][2];
312 values[numComponents * i + 2] = +nodePosition[globalNodeListView[i]][1];
314 rigidBodyModes[k].close();
319 rigidBodyModes[k].axpy( -rigidBodyModes[k].dot( rigidBodyModes[j] ), rigidBodyModes[j] );
321 rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
324 rigidBodyModes[k].create( numNodes*numComponents,
MPI_COMM_GEOS );
327 forAll< parallelHostPolicy >( numNodes, [=](
localIndex const i )
329 values[numComponents * i + 0] = +nodePosition[globalNodeListView[i]][2];
330 values[numComponents * i + 2] = -nodePosition[globalNodeListView[i]][0];
332 rigidBodyModes[k].close();
337 rigidBodyModes[k].axpy( -rigidBodyModes[k].dot( rigidBodyModes[j] ), rigidBodyModes[j] );
339 rigidBodyModes[k].scale( 1.0 / rigidBodyModes[k].norm2() );
344 GEOS_ERROR(
"Rigid body modes computation unsupported for " << numComponents <<
" components." );
void computeRigidBodyModes(MeshLevel const &mesh, DofManager const &dofManager, std::vector< string > const &selection, array1d< VECTOR > &rigidBodyModes)
Computes rigid body modes.
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.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
globalIndex globalOffset(string const &fieldName) const
integer numComponents(string const &fieldName="") const
FieldLocation location(string const &fieldName) const
Get the support location type of the field.
localIndex numLocalDofs(string const &fieldName) const
string const & getKey(string const &fieldName) const
Return the key used to record the field in the DofManager.
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...
Class facilitating the representation of a multi-level discretization of a MeshBody.
NodeManager const & getNodeManager() const
Get the node manager.
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.
array2d< real64, nodes::REFERENCE_POSITION_PERM > & referencePosition()
Get the mutable reference position array. This table will contain all the node coordinates.
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).
@ Node
location is node (like displacements in finite elements)
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Array< T, 1 > array1d
Alias for 1D array.