Commit 2ba79464 authored by Dominik Thoennes's avatar Dominik Thoennes
Browse files

refactor remaining PetscInts

parent 002d134b
Pipeline #34425 failed with stages
in 38 minutes and 40 seconds
......@@ -61,7 +61,7 @@ inline void createFunctionFromVector( const P1StokesFunction< PetscReal >& func
createFunctionFromVector( function.p, numerator.p, vec, level, flag );
}
inline void applyDirichletBC( const P1StokesFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P1StokesFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
applyDirichletBC( numerator.uvw[0], mat, level );
applyDirichletBC( numerator.uvw[1], mat, level );
......
......@@ -62,7 +62,7 @@ inline void createFunctionFromVector( const P2P1TaylorHoodFunction< PetscReal >&
createFunctionFromVector( function.p, numerator.p, vec, level, flag );
}
inline void applyDirichletBC( const P2P1TaylorHoodFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P2P1TaylorHoodFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
applyDirichletBC( numerator.uvw[0], mat, level );
applyDirichletBC( numerator.uvw[1], mat, level );
......
......@@ -57,7 +57,7 @@ inline void createFunctionFromVector( const P2P2StokesFunction< PetscReal >& fun
createFunctionFromVector( function.p, numerator.p, vec, level, flag );
}
inline void applyDirichletBC( const P2P2StokesFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P2P2StokesFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
applyDirichletBC( numerator.uvw[0], mat, level );
applyDirichletBC( numerator.uvw[1], mat, level );
......
......@@ -613,7 +613,7 @@ inline void createFunctionFromVector( const uint_t&
inline void applyDirichletBC( const uint_t& Level,
Edge& edge,
std::vector< PetscInt >& mat,
std::vector< idx_t >& mat,
const PrimitiveDataID< FunctionMemory< idx_t >, Edge >& numeratorId )
{
auto numerator = edge.getData( numeratorId )->getPointer( Level );
......@@ -621,7 +621,7 @@ inline void applyDirichletBC( const uint_t&
for ( const auto& it : edgedof::macroedge::Iterator( Level ) )
{
const uint_t idx = edgedof::macroedge::indexFromHorizontalEdge( Level, it.col(), stencilDirection::EDGE_HO_C );
mat.push_back( static_cast< PetscInt >( numerator[idx] ) );
mat.push_back( static_cast< idx_t >( numerator[idx] ) );
}
}
#endif
......
......@@ -1084,7 +1084,7 @@ inline void createFunctionFromVector( const uint_t&
inline void applyDirichletBC( const uint_t& Level,
Face& face,
std::vector< PetscInt >& mat,
std::vector< idx_t >& mat,
const PrimitiveDataID< FunctionMemory< idx_t >, Face >& numeratorId )
{
auto numerator = face.getData( numeratorId )->getPointer( Level );
......@@ -1095,21 +1095,21 @@ inline void applyDirichletBC( const uint_t&
if ( it.row() != 0 )
{
const uint_t idx = edgedof::macroface::horizontalIndex( Level, it.col(), it.row() );
mat.push_back( static_cast< PetscInt >( numerator[idx] ) );
mat.push_back( numerator[idx] );
}
// Do not read vertical DoFs at left border
if ( it.col() != 0 )
{
const uint_t idx = edgedof::macroface::verticalIndex( Level, it.col(), it.row() );
mat.push_back( static_cast< PetscInt >( numerator[idx] ) );
mat.push_back( numerator[idx] );
}
// Do not read diagonal DoFs at diagonal border
if ( it.col() + it.row() != ( hyteg::levelinfo::num_microedges_per_edge( Level ) - 1 ) )
{
const uint_t idx = edgedof::macroface::diagonalIndex( Level, it.col(), it.row() );
mat.push_back( static_cast< PetscInt >( numerator[idx] ) );
mat.push_back( numerator[idx] );
}
}
}
......
......@@ -601,7 +601,7 @@ inline void createFunctionFromVector( const EdgeDoFFunction< PetscReal >& func
}
}
inline void applyDirichletBC( const EdgeDoFFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const EdgeDoFFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
for ( auto& it : numerator.getStorage()->getEdges() )
{
......
......@@ -156,7 +156,7 @@ inline void createFunctionFromVector( const P1Function< PetscReal >& func
}
}
inline void applyDirichletBC( const P1Function< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P1Function< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
for ( auto& it : numerator.getStorage()->getVertices() )
{
......@@ -219,7 +219,7 @@ inline void createFunctionFromVector( const P1VectorFunction< PetscReal >& func
}
}
inline void applyDirichletBC( const P1VectorFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P1VectorFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
for ( uint_t k = 0; k < numerator.getDimension(); k++ )
{
......
......@@ -809,14 +809,14 @@ inline void createFunctionFromVector( const uint_t&
inline void applyDirichletBC( const uint_t& level,
Edge& edge,
std::vector< PetscInt >& mat,
std::vector< idx_t >& mat,
const PrimitiveDataID< FunctionMemory< idx_t >, Edge >& numeratorId )
{
size_t rowsize = levelinfo::num_microvertices_per_edge( level );
for ( uint_t i = 1; i < rowsize - 1; i++ )
{
mat.push_back( static_cast< PetscInt >( edge.getData( numeratorId )->getPointer( level )[i] ) );
mat.push_back( edge.getData( numeratorId )->getPointer( level )[i] );
}
}
#endif
......
......@@ -1263,13 +1263,12 @@ inline void createFunctionFromVector( const uint_t&
inline void applyDirichletBC( const uint_t& level,
Face& face,
std::vector< PetscInt >& mat,
std::vector< idx_t >& mat,
const PrimitiveDataID< FunctionMemory< idx_t >, Face >& numeratorId )
{
for ( const auto& it : vertexdof::macroface::Iterator( level, 1 ) )
{
mat.push_back( static_cast< PetscInt >(
face.getData( numeratorId )->getPointer( level )[vertexdof::macroface::index( level, it.x(), it.y() )] ) );
mat.push_back( face.getData( numeratorId )->getPointer( level )[vertexdof::macroface::index( level, it.x(), it.y() )] );
}
}
......
......@@ -395,11 +395,11 @@ inline void createFunctionFromVector( Vertex&
}
inline void applyDirichletBC( Vertex& vertex,
std::vector< PetscInt >& mat,
std::vector< idx_t >& mat,
uint_t level,
const PrimitiveDataID< FunctionMemory< idx_t >, Vertex >& numeratorId )
{
mat.push_back( static_cast< PetscInt >( vertex.getData( numeratorId )->getPointer( level )[0] ) );
mat.push_back( vertex.getData( numeratorId )->getPointer( level )[0] );
}
#endif
......
......@@ -56,7 +56,7 @@ inline void createFunctionFromVector( const P2Function< PetscReal >& func
createFunctionFromVector( function.getEdgeDoFFunction(), numerator.getEdgeDoFFunction(), vec, level, flag );
}
inline void applyDirichletBC( const P2Function< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P2Function< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
applyDirichletBC( numerator.getVertexDoFFunction(), mat, level );
applyDirichletBC( numerator.getEdgeDoFFunction(), mat, level );
......@@ -89,7 +89,7 @@ inline void createFunctionFromVector( const P2VectorFunction< PetscReal >& func
}
}
inline void applyDirichletBC( const P2VectorFunction< idx_t >& numerator, std::vector< PetscInt >& mat, uint_t level )
inline void applyDirichletBC( const P2VectorFunction< idx_t >& numerator, std::vector< idx_t >& mat, uint_t level )
{
for ( uint_t k = 0; k < numerator.getDimension(); k++ )
{
......
......@@ -30,12 +30,13 @@
#ifdef HYTEG_BUILD_WITH_PETSC
namespace hyteg {
namespace petsc {
namespace hyteg::petsc {
/// \brief Auxilliary routine for pimping PETSC_VIEWER_ASCII_MATLAB file
void pimpMatlabFile( std::string fName, std::string matrixName, bool elimDirichletBC, std::vector< PetscInt >& indices )
void pimpMatlabFile( const std::string& fName,
const std::string& matrixName,
bool elimDirichletBC,
std::vector< idx_t >& indices )
{
// Make Matlab be a little talkative
std::ofstream ofs;
......@@ -81,7 +82,7 @@ void pimpMatlabFile( std::string fName, std::string matrixName, bool elimDirichl
///
template < class OperatorType >
void exportOperator( OperatorType& op,
std::string fName,
const std::string& fName,
std::string matrixName,
PetscViewerFormat format,
std::shared_ptr< PrimitiveStorage > storage,
......@@ -95,24 +96,24 @@ void exportOperator( OperatorType& op,
uint_t globalDoFs = hyteg::numberOfGlobalDoFs< typename OperatorType::srcType::Tag >( *storage, level );
if ( localDoFs != globalDoFs )
{
WALBERLA_ABORT( "localDoFs and globalDoFs must agree for exportOperator()!" );
WALBERLA_ABORT( "localDoFs and globalDoFs must agree for exportOperator()!" )
}
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Dimension of function space is " << globalDoFs );
WALBERLA_LOG_INFO_ON_ROOT( " * Dimension of function space is " << globalDoFs )
}
// Fire up PETSc
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Firing up PETSc" );
WALBERLA_LOG_INFO_ON_ROOT( " * Firing up PETSc" )
}
PETScManager pmgr;
// Create PETSc matrix
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Converting Operator to PETSc matrix" );
WALBERLA_LOG_INFO_ON_ROOT( " * Converting Operator to PETSc matrix" )
}
PETScSparseMatrix< OperatorType, OperatorType::srcType::template FunctionType > petscMatrix(
localDoFs, globalDoFs, matrixName.c_str() );
......@@ -121,14 +122,14 @@ void exportOperator( OperatorType& op,
petscMatrix.createMatrixFromOperator( op, level, numerator );
// Zero rows and columns of "Dirichlet DoFs"
std::vector< PetscInt > indices;
std::vector< idx_t > indices;
if ( elimDirichletBC )
{
if ( elimSymmetric )
{
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Performing symmetric elimination of Dirichlet DoFs" );
WALBERLA_LOG_INFO_ON_ROOT( " * Performing symmetric elimination of Dirichlet DoFs" )
}
indices = petscMatrix.applyDirichletBCSymmetrically( numerator, level );
}
......@@ -136,7 +137,7 @@ void exportOperator( OperatorType& op,
{
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Performing non-symmetric elimination of Dirichlet DoFs" );
WALBERLA_LOG_INFO_ON_ROOT( " * Performing non-symmetric elimination of Dirichlet DoFs" )
}
hyteg::petsc::applyDirichletBC( numerator, indices, level );
petscMatrix.applyDirichletBC( numerator, level );
......@@ -146,7 +147,7 @@ void exportOperator( OperatorType& op,
// Write out matrix
if ( beVerbose )
{
WALBERLA_LOG_INFO_ON_ROOT( " * Exporting Operator to file '" << fName << "'" );
WALBERLA_LOG_INFO_ON_ROOT( " * Exporting Operator to file '" << fName << "'" )
}
petscMatrix.print( fName.c_str(), format );
......@@ -161,7 +162,6 @@ void exportOperator( OperatorType& op,
}
}
} // namespace petsc
} // namespace hyteg
} // namespace hyteg::petsc
#endif
......@@ -116,15 +116,16 @@ class PETScSparseMatrix
void applyDirichletBC( const FunctionType< idx_t >& numerator, uint_t level )
{
std::vector< PetscInt > ind;
hyteg::petsc::applyDirichletBC( numerator, ind, level );
std::vector< idx_t > bcIndices;
hyteg::petsc::applyDirichletBC( numerator, bcIndices, level );
std::vector< PetscInt > PetscIntBcIndices( bcIndices.begin(), bcIndices.end() );
// This is required as the implementation of MatZeroRows() checks (for performance reasons?!)
// if there are zero diagonals in the matrix. If there are, the function halts.
// To disable that check, we need to allow setting MAT_NEW_NONZERO_LOCATIONS to true.
MatSetOption( mat, MAT_NEW_NONZERO_LOCATIONS, PETSC_TRUE );
MatZeroRows( mat, static_cast< PetscInt >( ind.size() ), ind.data(), 1.0, nullptr, nullptr );
MatZeroRows( mat, static_cast< PetscInt >( PetscIntBcIndices.size() ), PetscIntBcIndices.data(), 1.0, nullptr, nullptr );
MatAssemblyBegin( mat, MAT_FINAL_ASSEMBLY );
MatAssemblyEnd( mat, MAT_FINAL_ASSEMBLY );
......@@ -152,8 +153,9 @@ class PETScSparseMatrix
PETScVector< real_t, FunctionType >& rhsVec,
const uint_t& level )
{
std::vector< PetscInt > bcIndices;
std::vector< idx_t > bcIndices;
hyteg::petsc::applyDirichletBC( numerator, bcIndices, level );
std::vector< PetscInt > PetscIntBcIndices( bcIndices.begin(), bcIndices.end() );
PETScVector< real_t, FunctionType > dirichletSolutionVec(
dirichletSolution, numerator, level, All, "dirichletSolutionVec", rhsVec.getCommunicator() );
......@@ -163,23 +165,26 @@ class PETScSparseMatrix
// To disable that check, we need to allow setting MAT_NEW_NONZERO_LOCATIONS to true.
MatSetOption( mat, MAT_NEW_NONZERO_LOCATIONS, PETSC_TRUE );
MatZeroRowsColumns( mat, bcIndices.size(), bcIndices.data(), 1.0, dirichletSolutionVec.get(), rhsVec.get() );
MatZeroRowsColumns(
mat, PetscIntBcIndices.size(), PetscIntBcIndices.data(), 1.0, dirichletSolutionVec.get(), rhsVec.get() );
}
/// \brief Variant of applyDirichletBCSymmetrically() that only modifies the matrix itself
///
/// \return Vector with global indices of the Dirichlet DoFs
std::vector< PetscInt > applyDirichletBCSymmetrically( const FunctionType< idx_t >& numerator, const uint_t& level )
std::vector< idx_t > applyDirichletBCSymmetrically( const FunctionType< idx_t >& numerator, const uint_t& level )
{
std::vector< PetscInt > bcIndices;
std::vector< idx_t > bcIndices;
hyteg::petsc::applyDirichletBC( numerator, bcIndices, level );
std::vector< PetscInt > PetscIntBcIndices( bcIndices.begin(), bcIndices.end() );
// This is required as the implementation of MatZeroRowsColumns() checks (for performance reasons?!)
// if there are zero diagonals in the matrix. If there are, the function halts.
// To disable that check, we need to allow setting MAT_NEW_NONZERO_LOCATIONS to true.
MatSetOption( mat, MAT_NEW_NONZERO_LOCATIONS, PETSC_TRUE );
MatZeroRowsColumns( mat, static_cast< PetscInt >( bcIndices.size() ), bcIndices.data(), 1.0, nullptr, nullptr );
MatZeroRowsColumns(
mat, static_cast< PetscInt >( PetscIntBcIndices.size() ), PetscIntBcIndices.data(), 1.0, nullptr, nullptr );
return bcIndices;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment