Skip to content

Commit

Permalink
build fix, code simplification, input checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Tomin authored and Pavel Tomin committed Dec 20, 2024
1 parent cc4cb53 commit 736cc7c
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 368 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase
*/
void updateCompAmount( ElementSubRegionBase & subRegion ) const;

/**
* @brief Update components mass/moles if Z formulation is used
* @param subRegion the subregion storing the required fields
*/
void updateCompAmountZFormulation( ElementSubRegionBase & subRegion ) const;

/**
* @brief Update energy
* @param subRegion the subregion storing the required fields
Expand Down Expand Up @@ -197,18 +191,18 @@ class CompositionalMultiphaseBase : public FlowSolverBase
{ return m_useMass ? units::Unit::Mass : units::Unit::Mole; }

/**
* @brief assembles the accumulation and volume balance terms for all cells
* @brief assembles the accumulation other local terms for all cells
* @param time_n previous time value
* @param dt time step
* @param domain the physical domain object
* @param dofManager degree-of-freedom manager associated with the linear system
* @param localMatrix the system matrix
* @param localRhs the system right-hand side vector
*/
void assembleAccumulationAndVolumeBalanceTerms( DomainPartition & domain,
DofManager const & dofManager,
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const;
void assembleLocalTerms( DomainPartition & domain,
DofManager const & dofManager,
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const;

/**
* @brief assembles the flux terms for all cells
Expand Down Expand Up @@ -241,35 +235,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const = 0;

/**
* @brief assembles the accumulation term (Z formulation) for all cells
* @param time_n previous time value
* @param dt time step
* @param domain the physical domain object
* @param dofManager degree-of-freedom manager associated with the linear system
* @param localMatrix the system matrix
* @param localRhs the system right-hand side vector
*/
void assembleZFormulationAccumulation( DomainPartition & domain,
DofManager const & dofManager,
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const;

/**
* @brief assembles the flux terms (Z formulation) for all cells
* @param time_n previous time value
* @param dt time step
* @param domain the physical domain object
* @param dofManager degree-of-freedom manager associated with the linear system
* @param matrix the system matrix
* @param rhs the system right-hand side vector
*/
virtual void
assembleZFormulationFluxTerms( real64 const dt,
DomainPartition const & domain,
DofManager const & dofManager,
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const = 0;
/**@}*/


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ DECLARE_FIELD( globalCompFraction_n,
NO_WRITE,
"Global component fraction at the previous converged time step" );

DECLARE_FIELD( globalCompFraction_k,
"globalCompFraction_k",
array2dLayoutComp,
0,
NOPLOT,
NO_WRITE,
"Global component fraction updates at the previous sequential iteration" );
// may be needed later for sequential poromechanics implementation
//DECLARE_FIELD( globalCompFraction_k,
// "globalCompFraction_k",
// array2dLayoutComp,
// 0,
// NOPLOT,
// NO_WRITE,
// "Global component fraction updates at the previous sequential iteration" );

DECLARE_FIELD( faceGlobalCompFraction,
"faceGlobalCompFraction",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@ void CompositionalMultiphaseFVM::postInputInitialization()
{
CompositionalMultiphaseBase::postInputInitialization();

if( m_scalingType == ScalingType::Local && m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None )
if( m_scalingType == ScalingType::Local &&
m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None )
{
GEOS_ERROR( GEOS_FMT( "{}: line search is not supported for {} = {}", getName(), viewKeyStruct::scalingTypeString(), EnumStrings< ScalingType >::toString( ScalingType::Local )) );
GEOS_ERROR( GEOS_FMT( "{}: line search is not supported for {} = {}",
getName(), viewKeyStruct::scalingTypeString(),
EnumStrings< ScalingType >::toString( ScalingType::Local )) );
}

if( m_useZFormulation && m_dbcParams.useDBC ) // useZFormulation is not compatible with DBC
{
GEOS_ERROR( GEOS_FMT( "{}: '{}' is not compatible with {}",
getDataContext(), viewKeyStruct::useZFormulationFlagString(), viewKeyStruct::useDBCString() ) );
}
}

Expand Down Expand Up @@ -184,16 +193,20 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt,
typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper();

// Convective flux
if( m_isThermal )

if( m_useZFormulation )
{
thermalCompositionalMultiphaseFVMKernels::
FluxComputeKernelFactory::
// isothermal only for now
isothermalCompositionalMultiphaseFVMKernels::
FluxComputeZFormulationKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasCapPressure,
m_useTotalMassEquation,
m_useNewGravity,
fluxApprox.upwindingParams(),
getName(),
mesh.getElemManager(),
stencilWrapper,
Expand All @@ -203,9 +216,9 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt,
}
else
{
if( m_dbcParams.useDBC )
if( m_isThermal )
{
dissipationCompositionalMultiphaseFVMKernels::
thermalCompositionalMultiphaseFVMKernels::
FluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
Expand All @@ -218,129 +231,102 @@ void CompositionalMultiphaseFVM::assembleFluxTerms( real64 const dt,
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView(),
m_dbcParams.omega,
getNonlinearSolverParameters().m_numNewtonIterations,
m_dbcParams.continuation,
m_dbcParams.miscible,
m_dbcParams.kappamin,
m_dbcParams.contMultiplier );
localRhs.toView() );
}
else
{
isothermalCompositionalMultiphaseFVMKernels::
FluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasCapPressure,
m_useTotalMassEquation,
m_useNewGravity,
fluxApprox.upwindingParams(),
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
if( m_dbcParams.useDBC )
{
dissipationCompositionalMultiphaseFVMKernels::
FluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasCapPressure,
m_useTotalMassEquation,
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView(),
m_dbcParams.omega,
getNonlinearSolverParameters().m_numNewtonIterations,
m_dbcParams.continuation,
m_dbcParams.miscible,
m_dbcParams.kappamin,
m_dbcParams.contMultiplier );
}
else
{
isothermalCompositionalMultiphaseFVMKernels::
FluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasCapPressure,
m_useTotalMassEquation,
m_useNewGravity,
fluxApprox.upwindingParams(),
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
}
}
}

// Diffusive and dispersive flux
if( m_hasDiffusion || m_hasDispersion )
{
// Diffusive and dispersive flux

if( m_isThermal )
if( m_hasDiffusion || m_hasDispersion )
{
thermalCompositionalMultiphaseFVMKernels::
DiffusionDispersionFluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasDiffusion,
m_hasDispersion,
m_useTotalMassEquation,
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
}
else
{
isothermalCompositionalMultiphaseFVMKernels::
DiffusionDispersionFluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasDiffusion,
m_hasDispersion,
m_useTotalMassEquation,
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );

if( m_isThermal )
{
thermalCompositionalMultiphaseFVMKernels::
DiffusionDispersionFluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasDiffusion,
m_hasDispersion,
m_useTotalMassEquation,
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
}
else
{
isothermalCompositionalMultiphaseFVMKernels::
DiffusionDispersionFluxComputeKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasDiffusion,
m_hasDispersion,
m_useTotalMassEquation,
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
}
}
}

} );
} );
}

void CompositionalMultiphaseFVM::assembleZFormulationFluxTerms( real64 const dt,
DomainPartition const & domain,
DofManager const & dofManager,
CRSMatrixView< real64, globalIndex const > const & localMatrix,
arrayView1d< real64 > const & localRhs ) const
{
GEOS_MARK_FUNCTION;

forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &,
MeshLevel const & mesh,
arrayView1d< string const > const & )
{
NumericalMethodsManager const & numericalMethodManager = domain.getNumericalMethodManager();
FiniteVolumeManager const & fvManager = numericalMethodManager.getFiniteVolumeManager();
FluxApproximationBase const & fluxApprox = fvManager.getFluxApproximation( m_discretizationName );

string const & elemDofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() );

fluxApprox.forAllStencils( mesh, [&] ( auto & stencil )
{
typename TYPEOFREF( stencil ) ::KernelWrapper stencilWrapper = stencil.createKernelWrapper();

GEOS_ERROR_IF( m_isThermal, GEOS_FMT(
"{}: Z Formulation is currently not available for thermal simulations", getDataContext() ) );
GEOS_ERROR_IF( m_hasDiffusion || m_hasDispersion, GEOS_FMT(
"{}: Z Formulation is currently not available for Diffusion or Dispersion", getDataContext() ) );

// isothermal only for now
isothermalCompositionalMultiphaseFVMKernels::
FluxComputeZFormulationKernelFactory::
createAndLaunch< parallelDevicePolicy<> >( m_numComponents,
m_numPhases,
dofManager.rankOffset(),
elemDofKey,
m_hasCapPressure,
m_useTotalMassEquation,
m_useNewGravity,
fluxApprox.upwindingParams(),
getName(),
mesh.getElemManager(),
stencilWrapper,
dt,
localMatrix.toViewConstSizes(),
localRhs.toView() );
} );
} );
}

void CompositionalMultiphaseFVM::assembleStabilizedFluxTerms( real64 const dt,
DomainPartition const & domain,
DofManager const & dofManager,
Expand Down
Loading

0 comments on commit 736cc7c

Please sign in to comment.