Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear algebra updates #2427

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

klevzoff
Copy link
Contributor

@klevzoff klevzoff commented May 9, 2023

This is a collection of LAI-related changes extracted from my multiscale branch to be reviewed separately. I will post some comments later highlighting the most important changes.

Rebaseline needed due to addition of new input parameters.

TODO:

@klevzoff klevzoff requested a review from castelletto1 May 9, 2023 09:26
@klevzoff klevzoff self-assigned this May 9, 2023
Comment on lines +186 to +198
std::array< Matrix const *, 2 > m_prolongators{};

/// Prolongation operators for each sub-block
std::array< Matrix, 2 > m_prolongators;
std::array< Matrix, 2 > m_prolongatorsOwned{};

/// Matrix blocks
BlockOperator< Vector, Matrix > m_matBlocks;

/// Individual block preconditioners
std::array< std::unique_ptr< PreconditionerBase< LAI > >, 2 > m_solvers;
/// Individual block preconditioner pointers
std::array< PreconditionerBase< LAI > *, 2 > m_solvers{};

/// Individual block preconditioner operators (when owned)
std::array< std::unique_ptr< PreconditionerBase< LAI > >, 2 > m_solversOwned{};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes add support for constructing a BlockPreconditioner out of sub-block solvers that exist elsewhere, which is occasionally useful (e.g. coupled multiscale smoother).

Comment on lines +91 to +102
constexpr char const * headFormat = "{:>4} {:>12} {:>9} {:>12}";
constexpr char const * lineFormat = "{:>4} {:>12.6e} {:>9.6f} {:>12.6e}";
integer const iter = m_result.numIterations;
if( iter == 0 )
{
GEOS_LOG_RANK_0( GEOS_FMT( "[{}] start iteration", methodName() ) );
GEOS_LOG_RANK_0( GEOS_FMT( headFormat, "iter", "resid.norm", "conv.rate", "rel.res.norm" ) );
}
real64 const norm = m_residualNorms[iter];
real64 const relNorm = m_residualNorms[0] > 0.0 ? norm / m_residualNorms[0] : 0.0;
real64 const convRate = iter > 0 ? norm / m_residualNorms[iter - 1] : 1.0;
GEOS_LOG_RANK_0( GEOS_FMT( lineFormat, iter, norm, convRate, relNorm ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iteration progress output improved to provide more information and match that of hypre

src/coreComponents/linearAlgebra/CMakeLists.txt Outdated Show resolved Hide resolved
src/coreComponents/linearAlgebra/CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines +36 to +94
template< typename CHILD, typename T >
void registerInputBlock( Group * parent, char const * const key, T & data )
{
parent->registerGroup( key, std::make_unique< CHILD >( key, parent, data ) ).setInputFlags( InputFlags::OPTIONAL );
}

class BlockParametersInput final : public dataRepository::Group
{
public:

/// Constructor
BlockParametersInput( string const & name,
Group * const parent,
LinearSolverParameters::Block & params );

virtual Group * createChild( string const & childKey, string const & childName ) override
{
GEOS_UNUSED_VAR( childKey, childName );
return nullptr;
}

/// Keys appearing in XML
struct viewKeyStruct
{
static constexpr char const * shapeString() { return "shape"; }
static constexpr char const * schurTypeString() { return "schurType"; }
static constexpr char const * scalingString() { return "scaling"; }
};

private:

LinearSolverParameters::Block & m_parameters;
};

BlockParametersInput::BlockParametersInput( string const & name,
Group * const parent,
LinearSolverParameters::Block & params )
:
Group( name, parent ),
m_parameters( params )
{
registerWrapper( viewKeyStruct::shapeString(), &m_parameters.shape ).
setDefaultValue( m_parameters.shape ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Block preconditioner shape, options: "
"``" + EnumStrings< LinearSolverParameters::Block::Shape >::concat( "``, ``" ) + "``" );

registerWrapper( viewKeyStruct::schurTypeString(), &m_parameters.schurType ).
setDefaultValue( m_parameters.schurType ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Schur complement type, options: "
"``" + EnumStrings< LinearSolverParameters::Block::SchurType >::concat( "``, ``" ) + "``" );

registerWrapper( viewKeyStruct::scalingString(), &m_parameters.scaling ).
setDefaultValue( m_parameters.scaling ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Block scaling type, options: "
"``" + EnumStrings< LinearSolverParameters::Block::Scaling >::concat( "``, ``" ) + "``" );
}
Copy link
Contributor Author

@klevzoff klevzoff May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new way of structuring linear solver parameter inputs: instead of an ever-growing list of prefixed attributes like

<LinearSolverParameters
  blockShape="..."
  blockSchurType="..."
  blockScaling="..."/>

we will start adding nested structure as follows:

<LinearSolverParameters>
  <Block
    shape="..."
    schurType="..."
    scaling="..."/>
</LinearSolverParameters>

This improves readability by indenting parameter blocks according to their logical structure and avoiding repetition of the prefixes. I use this extensively in multiscale work, but will also propose a similar refactoring for AMG parameters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice, specially if we want to expose some MGR options per level...

Comment on lines -333 to -362
FieldIdentifiers fieldsToBeSync;
fieldsToBeSync.addElementFields( { fields::flow::pressure::key() },
regionNames );

CommunicationTools::getInstance().synchronizeFields( fieldsToBeSync, mesh, domain.getNeighbors(), false );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This synchronization was useless because consistency of values is already guaranteed by virtue of ghosted cells being included in sets to which initial conditions are applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about other flow solvers?

Comment on lines +118 to +134
switch( linParams.preconditionerType )
{
default:
{
return LAInterface::createPreconditioner( linParams );
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch statement may seem pointless at the moment, but it's left as a placeholder for adding custom preconditioners (e.g. multiscale)

Comment on lines +279 to +282
/// Rigid body modes; TODO remove mutable hack
mutable array1d< ParallelVector > m_rigidBodyModes;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now mutable because it's populated on demand in createPreconditioner() function which is const. This is isn't great, but I don't have a better solution for now.

@klevzoff klevzoff added the flag: requires rebaseline Requires rebaseline branch in integratedTests label May 10, 2023
@klevzoff klevzoff force-pushed the feature/klevzoff/linear-algebra-updates branch 2 times, most recently from 6aa101b to a167fdc Compare May 12, 2023 06:12
@klevzoff klevzoff force-pushed the feature/klevzoff/linear-algebra-updates branch 2 times, most recently from dfbc927 to 742c689 Compare July 18, 2023 09:09
@klevzoff klevzoff force-pushed the feature/klevzoff/linear-algebra-updates branch from 742c689 to 9004d43 Compare October 8, 2023 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: ready for review flag: requires rebaseline Requires rebaseline branch in integratedTests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants