Skip to content

Commit

Permalink
Additing validateDirichletBC and SourceFluxStats wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammara-14 committed Feb 1, 2025
1 parent bb6b0af commit 23c5240
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 17 deletions.
148 changes: 131 additions & 17 deletions src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "constitutive/capillaryPressure/capillaryPressureSelector.hpp"
#include "constitutive/relativePermeability/RelativePermeabilitySelector.hpp"

#include "fieldSpecification/EquilibriumInitialCondition.hpp"
#include "fieldSpecification/SourceFluxBoundaryCondition.hpp"
#include "physicsSolvers/fluidFlow/SourceFluxStatistics.hpp"

#include "constitutive/ConstitutivePassThru.hpp"
#include "constitutive/fluid/twophasefluid/TwoPhaseFluid.hpp"
Expand Down Expand Up @@ -677,13 +679,126 @@ void ImmiscibleMultiphaseFlow::applyBoundaryConditions( real64 const time_n,
namespace
{
char const bcLogMessage[] =
"CompositionalMultiphaseBase {}: at time {}s, "
"ImmiscibleMultiphaseFlow {}: at time {}s, "
"the <{}> boundary condition '{}' is applied to the element set '{}' in subRegion '{}'. "
"\nThe scale of this boundary condition is {} and multiplies the value of the provided function (if any). "
"\nThe total number of target elements (including ghost elements) is {}. "
"\nNote that if this number is equal to zero for all subRegions, the boundary condition will not be applied on this element set.";
}

bool ImmiscibleMultiphaseFlow::validateDirichletBC( DomainPartition & domain,

Check warning on line 689 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L689

Added line #L689 was not covered by tests
real64 const time ) const
{
constexpr integer MAX_NP = 2;
FieldSpecificationManager & fsManager = FieldSpecificationManager::getInstance();

Check warning on line 693 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L692-L693

Added lines #L692 - L693 were not covered by tests

bool bcConsistent = true;

Check warning on line 695 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L695

Added line #L695 was not covered by tests

forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &,

Check warning on line 697 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L697

Added line #L697 was not covered by tests
MeshLevel & mesh,
arrayView1d< string const > const & )
{
// map: regionName -> subRegionName -> setName -> numPhases to check pressure/phase are present consistent
map< string, map< string, map< string, ComponentMask< MAX_NP > > > > bcPresCompStatusMap;

Check warning on line 702 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L702

Added line #L702 was not covered by tests

// 1. Check pressure Dirichlet BCs
fsManager.apply< ElementSubRegionBase >( time,

Check warning on line 705 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L705

Added line #L705 was not covered by tests
mesh,
fields::flow::pressure::key(),
[&]( FieldSpecificationBase const &,

Check warning on line 708 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L708

Added line #L708 was not covered by tests
string const & setName,
SortedArrayView< localIndex const > const &,
ElementSubRegionBase & subRegion,
string const & )
{
// Check whether pressure has already been applied to this set
string const & subRegionName = subRegion.getName();
string const & regionName = subRegion.getParent().getParent().getName();

Check warning on line 716 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L715-L716

Added lines #L715 - L716 were not covered by tests

auto & subRegionSetMap = bcPresCompStatusMap[regionName][subRegionName];
if( subRegionSetMap.count( setName ) > 0 )

Check warning on line 719 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L718-L719

Added lines #L718 - L719 were not covered by tests
{
bcConsistent = false;
GEOS_WARNING( BCMessage::pressureConflict( regionName, subRegionName, setName,

Check warning on line 722 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L721-L722

Added lines #L721 - L722 were not covered by tests
fields::flow::pressure::key() ) );
}
subRegionSetMap[setName].setNumComp( m_numPhases );
} );

Check warning on line 726 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L725-L726

Added lines #L725 - L726 were not covered by tests
// 2. Check saturation Dirichlet BCs
fsManager.apply< ElementSubRegionBase >( time,

Check warning on line 728 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L728

Added line #L728 was not covered by tests
mesh,
fields::immiscibleMultiphaseFlow::phaseVolumeFraction::key(),
[&] ( FieldSpecificationBase const & fs,

Check warning on line 731 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L731

Added line #L731 was not covered by tests
string const & setName,
SortedArrayView< localIndex const > const &,
ElementSubRegionBase & subRegion,
string const & )
{
string const & subRegionName = subRegion.getName( );
string const & regionName = subRegion.getParent().getParent().getName();
integer const comp = fs.getComponent();

Check warning on line 739 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L737-L739

Added lines #L737 - L739 were not covered by tests

auto & subRegionSetMap = bcPresCompStatusMap[regionName][subRegionName];
if( subRegionSetMap.count( setName ) == 0 )

Check warning on line 742 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L741-L742

Added lines #L741 - L742 were not covered by tests
{
bcConsistent = false;
GEOS_WARNING( BCMessage::missingPressure( regionName, subRegionName, setName,

Check warning on line 745 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L744-L745

Added lines #L744 - L745 were not covered by tests
fields::flow::pressure::key() ) );
}
if( comp < 0 || comp >= m_numPhases )

Check warning on line 748 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L748

Added line #L748 was not covered by tests
{
bcConsistent = false;
GEOS_WARNING( BCMessage::invalidComponentIndex( comp, fs.getName(),

Check warning on line 751 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L750-L751

Added lines #L750 - L751 were not covered by tests
fields::immiscibleMultiphaseFlow::phaseVolumeFraction::key() ) );
return; // can't check next part with invalid component id

Check warning on line 753 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L753

Added line #L753 was not covered by tests
}

ComponentMask< MAX_NP > & compMask = subRegionSetMap[setName];
if( compMask[comp] )

Check warning on line 757 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L756-L757

Added lines #L756 - L757 were not covered by tests
{
bcConsistent = false;
fsManager.forSubGroups< EquilibriumInitialCondition >( [&] ( EquilibriumInitialCondition const & bc )

Check warning on line 760 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L759-L760

Added lines #L759 - L760 were not covered by tests
{
arrayView1d< string const > componentNames = bc.getComponentNames();
GEOS_WARNING( BCMessage::conflictingComposition( comp, componentNames[comp],

Check warning on line 763 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L762-L763

Added lines #L762 - L763 were not covered by tests
regionName, subRegionName, setName,
fields::immiscibleMultiphaseFlow::phaseVolumeFraction::key() ) );
} );

Check warning on line 766 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L766

Added line #L766 was not covered by tests
}
compMask.set( comp );

Check warning on line 768 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L768

Added line #L768 was not covered by tests
} );

// 3.2 Check consistency between composition BC applied to sets
// Note: for a temperature-only boundary condition, this loop does not do anything
for( auto const & regionEntry : bcPresCompStatusMap )

Check warning on line 773 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L773

Added line #L773 was not covered by tests
{
for( auto const & subRegionEntry : regionEntry.second )

Check warning on line 775 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L775

Added line #L775 was not covered by tests
{
for( auto const & setEntry : subRegionEntry.second )

Check warning on line 777 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L777

Added line #L777 was not covered by tests
{
ComponentMask< MAX_NP > const & compMask = setEntry.second;

Check warning on line 779 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L779

Added line #L779 was not covered by tests

fsManager.forSubGroups< EquilibriumInitialCondition >( [&] ( EquilibriumInitialCondition const & fs )

Check warning on line 781 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L781

Added line #L781 was not covered by tests
{
arrayView1d< string const > componentNames = fs.getComponentNames();
for( int ic = 0; ic < componentNames.size(); ic++ )

Check warning on line 784 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L783-L784

Added lines #L783 - L784 were not covered by tests
{
if( !compMask[ic] )

Check warning on line 786 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L786

Added line #L786 was not covered by tests
{
bcConsistent = false;
GEOS_WARNING( BCMessage::notAppliedOnRegion( ic, componentNames[ic],

Check warning on line 789 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L788-L789

Added lines #L788 - L789 were not covered by tests
regionEntry.first, subRegionEntry.first, setEntry.first,
fields::immiscibleMultiphaseFlow::phaseVolumeFraction::key() ) );
}
}
} );

Check warning on line 794 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L794

Added line #L794 was not covered by tests
}
}
}
} );

Check warning on line 798 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L798

Added line #L798 was not covered by tests

return bcConsistent;

Check warning on line 800 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L800

Added line #L800 was not covered by tests
}

void ImmiscibleMultiphaseFlow::applyDirichletBC( real64 const time_n,

Check warning on line 803 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L803

Added line #L803 was not covered by tests
real64 const dt,
Expand All @@ -694,12 +809,12 @@ void ImmiscibleMultiphaseFlow::applyDirichletBC( real64 const time_n,
{
GEOS_MARK_FUNCTION;

Check warning on line 810 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L810

Added line #L810 was not covered by tests

// // Only validate BC at the beginning of Newton loop
// if( m_nonlinearSolverParameters.m_numNewtonIterations == 0 )
// {
// bool const bcConsistent = validateDirichletBC( domain, time_n + dt );
// GEOS_ERROR_IF( !bcConsistent, GEOS_FMT( "CompositionalMultiphaseBase {}: inconsistent boundary conditions", getDataContext() ) );
// }
// Only validate BC at the beginning of Newton loop
if( m_nonlinearSolverParameters.m_numNewtonIterations == 0 )

Check warning on line 813 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L813

Added line #L813 was not covered by tests
{
bool const bcConsistent = validateDirichletBC( domain, time_n + dt );
GEOS_ERROR_IF( !bcConsistent, GEOS_FMT( "ImmiscibleMultiphaseFlow {}: inconsistent boundary conditions", getDataContext() ) );

Check warning on line 816 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L815-L816

Added lines #L815 - L816 were not covered by tests
}

FieldSpecificationManager & fsManager = FieldSpecificationManager::getInstance();

Check warning on line 819 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L819

Added line #L819 was not covered by tests

Expand All @@ -719,7 +834,7 @@ void ImmiscibleMultiphaseFlow::applyDirichletBC( real64 const time_n,
globalIndex const rankOffset = dofManager.rankOffset();
string const dofKey = dofManager.getKey( viewKeyStruct::elemDofFieldString() );

Check warning on line 835 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L834-L835

Added lines #L834 - L835 were not covered by tests

// 3. Call constitutive update, back-calculate target global component densities and apply to the system
// 3. Call constitutive update
fsManager.apply< ElementSubRegionBase >( time_n + dt,

Check warning on line 838 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L838

Added line #L838 was not covered by tests
mesh,
fields::flow::pressure::key(),
Expand Down Expand Up @@ -939,19 +1054,18 @@ void ImmiscibleMultiphaseFlow::applySourceFluxBC( real64 const time,
}
} );

// SourceFluxStatsAggregator::forAllFluxStatWrappers( subRegion, fs.getName(),
// [&]( SourceFluxStatsAggregator::WrappedStats & wrapper )
// {
// // set the new sub-region statistics for this timestep
// array1d< real64 > massProdArr{ m_numPhases };
// massProdArr[fluidPhaseId] = massProd.get();
// wrapper.gatherTimeStepStats( time, dt, massProdArr.toViewConst(), targetSet.size() );
// } );
SourceFluxStatsAggregator::forAllFluxStatWrappers( subRegion, fs.getName(),
[&]( SourceFluxStatsAggregator::WrappedStats & wrapper )

Check warning on line 1058 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L1057-L1058

Added lines #L1057 - L1058 were not covered by tests
{
// set the new sub-region statistics for this timestep
array1d< real64 > massProdArr{ m_numPhases };
massProdArr[fluidPhaseId] = massProd.get();
wrapper.gatherTimeStepStats( time, dt, massProdArr.toViewConst(), targetSet.size() );
} );
} );
} );
}

Check warning on line 1067 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L1061-L1067

Added lines #L1061 - L1067 were not covered by tests


real64 ImmiscibleMultiphaseFlow::calculateResidualNorm( real64 const & GEOS_UNUSED_PARAM( time_n ),

Check warning on line 1069 in src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreComponents/physicsSolvers/fluidFlow/ImmiscibleMultiphaseFlow.cpp#L1069

Added line #L1069 was not covered by tests
real64 const & GEOS_UNUSED_PARAM( dt ),
DomainPartition const & domain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ class ImmiscibleMultiphaseFlow : public FlowSolverBase

private:

/**
* @brief Utility function to validate the consistency of Dirichlet BC input
* @param[in] domain the domain partition
* @param[in] time the time at the end of the time step (time_n + dt)
*/
bool validateDirichletBC( DomainPartition & domain,
real64 const time ) const;

virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override;

};
Expand Down

0 comments on commit 23c5240

Please sign in to comment.