GEOS
MsrsbUtils.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2019 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2019 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2019 Total, S.A
8  * Copyright (c) 2019- GEOS/GEOSX Contributors
9  * All right reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
21 #ifndef GEOS_LINEARALGEBRA_MULTISCALE_MSRSBUTILS_HPP_
22 #define GEOS_LINEARALGEBRA_MULTISCALE_MSRSBUTILS_HPP_
23 
24 #include "common/DataTypes.hpp"
29 #include "mesh/DomainPartition.hpp"
30 #include "mesh/mpiCommunications/CommunicationTools.hpp"
31 
32 namespace geos
33 {
34 namespace multiscale
35 {
36 
37 class DofManager;
38 class MeshObjectManager;
39 class MeshLevel;
40 
41 namespace msrsb
42 {
43 
52 ArrayOfSets< localIndex >
54  bool ghostNodes,
55  MeshObjectManager const & dualManager,
56  bool ghostDuals );
57 
68  arrayView1d< localIndex const > const & seeds,
69  ArrayOfSetsView< localIndex const > const & supports );
70 
82 buildSupports( ArrayOfSetsView< localIndex const > const & fineObjectToSubdomain,
83  ArrayOfSetsView< localIndex const > const & subdomainToCoarseObject,
84  ArrayOfSetsView< localIndex const > const & coarseObjectToSubdomain );
85 
93 
103 buildProlongationSparsity( DofManager const & fineDofManager,
104  DofManager const & coarseDofManager,
105  string const & fieldName,
106  ArrayOfSetsView< localIndex const > const & supports );
107 
118 buildTentativeProlongation( DofManager const & fineDofManager,
119  DofManager const & coarseDofManager,
120  string const & fieldName,
121  ArrayOfSetsView< localIndex const > const & supports,
122  arrayView1d< localIndex const > const & initPart );
123 
132 void makeGlobalDofLists( DofManager const & dofManager,
133  string const & fieldName,
134  arrayView1d< integer const > const & indicator,
135  array1d< globalIndex > & boundaryDof,
136  array1d< globalIndex > & interiorDof );
137 
147  ArrayOfSetsView< localIndex const > const & connectivity,
148  arrayView1d< localIndex const > const & initialPartition );
149 
158  ArrayOfSetsView< localIndex const > const & support );
159 
169 template< typename MATRIX >
170 std::unique_ptr< LinearOperator< typename MATRIX::Vector > >
172  MATRIX const & prolongation )
173 {
174  std::unique_ptr< LinearOperator< typename MATRIX::Vector > > restriction;
175  if( params.galerkin )
176  {
177  // Make a transpose operator with a reference to P, which will be computed later
178  restriction = std::make_unique< TransposeOperator< MATRIX > >( prolongation );
179  }
180  else
181  {
182  // Make an explicit transpose of tentative (initial) P
183  MATRIX R;
184  prolongation.transpose( R );
185  restriction = std::make_unique< MATRIX >( std::move( R ) );
186  }
187  return restriction;
188 }
189 
198  real64 relTol );
199 
209 template< typename MATRIX >
210 MATRIX
212  MATRIX const & fineMatrix,
213  MATRIX const & prolongation,
214  LinearOperator< typename MATRIX::Vector > const & restrictionOp )
215 {
216  MATRIX coarseMatrix;
217  if( params.galerkin )
218  {
219  fineMatrix.multiplyPtAP( prolongation, coarseMatrix );
220  }
221  else
222  {
223  MATRIX const & restriction = dynamicCast< MATRIX const & >( restrictionOp );
224  fineMatrix.multiplyRAP( restriction, prolongation, coarseMatrix );
225  }
226 
227  if( params.droptol > 0.0 )
228  {
229  CRSMatrix< real64, globalIndex > mat = coarseMatrix.extract();
230  mat = dropEntries( mat.toViewConst(), params.droptol );
231  coarseMatrix.create( mat.toViewConst(), coarseMatrix.numLocalCols(), coarseMatrix.comm() );
232  }
233  return coarseMatrix;
234 }
235 
252  multiscale::DofManager const & dofManager,
253  string const & fieldName,
254  string const & prefix,
255  multiscale::MeshLevel & mesh,
256  multiscale::MeshObjectManager & fineManager,
257  std::function< void ( multiscale::MeshLevel &, std::vector< string > const & ) > const & writeFunc );
258 
259 } // namespace msrsb
260 } // namespace multiscale
261 } // namespace geos
262 
263 #endif //GEOS_LINEARALGEBRA_MULTISCALE_MSRSBUTILS_HPP_
void makeGlobalDofLists(DofManager const &dofManager, string const &fieldName, arrayView1d< integer const > const &indicator, array1d< globalIndex > &boundaryDof, array1d< globalIndex > &interiorDof)
Build lists of boundary and interior dof indices to use in MsRSB basis smoothing iteration.
ArrayOfSets< localIndex > buildLayeredSupport(integer numLayers, ArrayOfSetsView< localIndex const > const &connectivity, arrayView1d< localIndex const > const &initialPartition)
Build (possibly overlapping) supports consisting of a fixed number of layers added to initial (non-ov...
ArrayOfSets< localIndex > buildLocalConnectivity(MeshObjectManager const &nodeManager, bool ghostNodes, MeshObjectManager const &dualManager, bool ghostDuals)
Construct a local adjacency map between points (e.g. vertices) connected by duals (e....
std::unique_ptr< LinearOperator< typename MATRIX::Vector > > makeRestriction(LinearSolverParameters::Multiscale const &params, MATRIX const &prolongation)
Make a restriction operator.
Definition: MsrsbUtils.hpp:171
MATRIX computeRAP(LinearSolverParameters::Multiscale const &params, MATRIX const &fineMatrix, MATRIX const &prolongation, LinearOperator< typename MATRIX::Vector > const &restrictionOp)
Compute the triple product R*A*P with optional post-filtering.
Definition: MsrsbUtils.hpp:211
void writeProlongation(CRSMatrixView< real64 const, globalIndex const > const &prolongation, multiscale::DofManager const &dofManager, string const &fieldName, string const &prefix, multiscale::MeshLevel &mesh, multiscale::MeshObjectManager &fineManager, std::function< void(multiscale::MeshLevel &, std::vector< string > const &) > const &writeFunc)
Write the prolongation operator as a collection of fine-level fields (one per coarse point)
CRSMatrix< real64, globalIndex > dropEntries(CRSMatrixView< real64 const, globalIndex const > const &mat, real64 relTol)
Drop entries from the matrix that are below relTol times max abs value in current row.
ArrayOfSets< localIndex > buildSupports(ArrayOfSetsView< localIndex const > const &fineObjectToSubdomain, ArrayOfSetsView< localIndex const > const &subdomainToCoarseObject, ArrayOfSetsView< localIndex const > const &coarseObjectToSubdomain)
Build a map of support regions through subdomain adjacency.
array1d< localIndex > makeSeededPartition(ArrayOfSetsView< localIndex const > const &connectivity, arrayView1d< localIndex const > const &seeds, ArrayOfSetsView< localIndex const > const &supports)
Construct a non-overlapping partitioning (clustering) of points using point connectivity and a set of...
SparsityPattern< globalIndex > buildProlongationSparsity(DofManager const &fineDofManager, DofManager const &coarseDofManager, string const &fieldName, ArrayOfSetsView< localIndex const > const &supports)
Compute the sparsity pattern of the prolongation operator.
array1d< integer > findLayeredSupportBoundary(ArrayOfSetsView< localIndex const > const &connectivity, ArrayOfSetsView< localIndex const > const &support)
Given a layered support, find the global support boundary.
array1d< integer > findGlobalSupportBoundary(ArrayOfSetsView< localIndex const > const &fineObjectToSubdomain)
Compute an array of global support boundary indicators.
CRSMatrix< real64, globalIndex > buildTentativeProlongation(DofManager const &fineDofManager, DofManager const &coarseDofManager, string const &fieldName, ArrayOfSetsView< localIndex const > const &supports, arrayView1d< localIndex const > const &initPart)
Initialize a tentative prolongation operator according to a non-overlapping partitioning of points.
Abstract base class for linear operators.
Degree-of-freedom manager that works with multiscale mesh levels.
Definition: DofManager.hpp:37
Multiscale mesh level.
Definition: MeshLevel.hpp:47
Mesh object manager used in multiscale preconditioners to keep a simplified (node/cell only) represen...
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
Definition: DataTypes.hpp:305
LvArray::ArrayOfSetsView< T, INDEX_TYPE const, LvArray::ChaiBuffer > ArrayOfSetsView
View of array of variable-sized sets. See LvArray::ArrayOfSetsView for details.
Definition: DataTypes.hpp:293
LvArray::SparsityPattern< COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > SparsityPattern
Alias for Sparsity pattern class.
Definition: DataTypes.hpp:297
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
LvArray::ArrayOfSets< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfSets
Array of variable-sized sets. See LvArray::ArrayOfSets for details.
Definition: DataTypes.hpp:289
int integer
Signed integer type.
Definition: DataTypes.hpp:81
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
Multiscale preconditioner parameters.
integer galerkin
Whether to use Galerkin definition R = P^T (otherwise R = P_0^T)
real64 droptol
Dropping tolerance for coarse matrix values (relative to row max)