Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions scripts/test_submodule_updated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ declare -ar pr_hashes_array=( $(git submodule status | awk '{print $1}') )
# Initialize submodule paths
declare -ar paths_array=( $(git submodule status | awk '{print $2}') )

# Initialize differences between PR and origin/develop branches
declare -ar diff_array=( $(git diff --name-only origin/develop) )

# Initialize main branches for submodules
declare -Ar main_branches=(
["blt"]="origin/develop"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class DispersionBase : public ConstitutiveBase
{
public:

struct viewKeyStruct : public ConstitutiveBase::viewKeyStruct
{};

/**
* @brief Constructor for the abstract base class
* @param[in] name the name of the class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class PermeabilityBase : public ConstitutiveBase
{
public:

struct viewKeyStruct : public ConstitutiveBase::viewKeyStruct
{};

PermeabilityBase( string const & name, dataRepository::Group * const parent );

virtual void allocateConstitutiveData( dataRepository::Group & parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class SinglePhaseThermalConductivityBase : public ConstitutiveBase
{
public:

struct viewKeyStruct : public ConstitutiveBase::viewKeyStruct
{};

/**
* @brief Constructor for the abstract base class
* @param[in] name the name of the class
Expand Down
25 changes: 25 additions & 0 deletions src/coreComponents/constitutive/unitTests/FluidModelTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ class FluidModelTest : public ::testing::Test
real64 const relTol = relTolerance,
real64 const absTol = absTolerance );

/**
* @brief Tests numerical derivatives for several independent test points in one update pass.
* @details This preserves the same finite-difference checks as the single-point overload while
* avoiding repeated fluid allocation and cloning for each point.
*/
void testNumericalDerivatives( FluidModel * fluid,
stdVector< TestPoint > const & data,
real64 const perturbationLevel = 1.0e-4,
real64 const relTol = relTolerance,
real64 const absTol = absTolerance );

protected:
/**
* @brief Writes content to a file
Expand Down Expand Up @@ -252,6 +263,20 @@ class FluidModelTest : public ::testing::Test
real64 const absTol,
INDICES const ... indices );

template< integer NDIM, typename ... INDICES, integer USD1, integer USD2, integer USD3,
typename=std::enable_if_t< sizeof ... ( INDICES ) == NDIM-2 > >
static void testDerivativesAtOffset( string const propName,
string const testValues,
ArrayView< real64 const, NDIM, USD1 > const & valueArray,
ArrayView< real64 const, NDIM+1, USD2 > const & derivArray,
ArraySlice< real64 const, 1, USD3 > const & displacements,
real64 const valueScale,
string_array const & dofNames,
real64 const relTol,
real64 const absTol,
integer const offset,
INDICES const ... indices );

private:
void createFunctionManager();

Expand Down
308 changes: 186 additions & 122 deletions src/coreComponents/constitutive/unitTests/FluidModelTest_impl.hpp

Large diffs are not rendered by default.

40 changes: 18 additions & 22 deletions src/coreComponents/constitutive/unitTests/testDruckerPrager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ void testDruckerPragerDriver()
data.strainIncrement[0] = -1e-4;
real64 timeIncrement = 0;

for( localIndex loadstep=0; loadstep < 50; ++loadstep )
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
for( localIndex loadstep=0; loadstep < 50; ++loadstep )
{
real64 stress[6] = {0};
real64 stiffness[6][6] = {{0}};
cmw.smallStrainUpdate( k, 0, timeIncrement, data.strainIncrement, stress, stiffness );
} );
cm.saveConvergedState();
}
cmw.saveConvergedState( k, 0 );
}
} );

real64 stress[6] = {0};
getStress( cmw, stress );
Expand Down Expand Up @@ -225,31 +225,27 @@ void testDruckerPragerExtendedDriver()
StrainData data;
real64 timeIncrement = 0;
data.strainIncrement[0] = -1e-3;
real64 invariantP, invariantQ;
real64 deviator[6] = {0};

//FILE* fp = fopen("pq.txt","w");
for( localIndex loadstep=0; loadstep < 300; ++loadstep )
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
for( localIndex loadstep=0; loadstep < 300; ++loadstep )
{
real64 stress[6] = {0};
real64 stiffness[6][6] = {{0}};
cmw.smallStrainUpdate( k, 0, timeIncrement, data.strainIncrement, stress, stiffness );
} );
cmw.saveConvergedState( k, 0 );
}
} );

cm.saveConvergedState();
real64 stress[6] = {0};
getStress( cmw, stress );

real64 stress[6] = {0};
getStress( cmw, stress );
real64 invariantP, invariantQ;
real64 deviator[6] = {0};

twoInvariant::stressDecomposition( stress,
invariantP,
invariantQ,
deviator );
//fprintf(fp,"%.4e %.4e %.4e\n",invariantP,invariantQ,total);
}
//fclose(fp);
twoInvariant::stressDecomposition( stress,
invariantP,
invariantQ,
deviator );

// loading was set up to drive to residual strength, at which
// point the Q/(P-P0) ratio should equal the slope of residual yield surface:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ using TestData = std::tuple<
real64 const // Permeability (mD) (if required)
>;

struct InverseCapillaryPressureTestState
{
conduit::Node m_node;
std::unique_ptr< Group > m_parent{};
std::unique_ptr< FunctionManager > m_functionManager{};
std::unique_ptr< ConstitutiveManager > m_constitutiveManager{};

InverseCapillaryPressureTestState();
};

static InverseCapillaryPressureTestState & getInverseCapillaryPressureTestState()
{
static InverseCapillaryPressureTestState state;
return state;
}

template< typename CAP_PRESSURE, integer NUM_PHASE=2 >
class InverseCapillaryPressureTestFixture : public ::testing::TestWithParam< TestData< NUM_PHASE > >
{
Expand All @@ -61,14 +77,19 @@ class InverseCapillaryPressureTestFixture : public ::testing::TestWithParam< Tes
void testInversion( TestData< NUM_PHASE > const & testData );

private:
conduit::Node m_node;
std::unique_ptr< Group > m_parent{};
std::unique_ptr< FunctionManager > m_functionManager{};
std::unique_ptr< ConstitutiveManager > m_constitutiveManager{};
static InverseCapillaryPressureTestState & getState()
{
return getInverseCapillaryPressureTestState();
}
};

template< typename CAP_PRESSURE, integer NUM_PHASE >
InverseCapillaryPressureTestFixture< CAP_PRESSURE, NUM_PHASE >::InverseCapillaryPressureTestFixture()
{
getState();
}

InverseCapillaryPressureTestState::InverseCapillaryPressureTestState()
: m_parent( std::make_unique< Group >( "parent", m_node )),
m_functionManager( std::make_unique< FunctionManager >( FunctionManager::catalogName(), m_parent.get() )),
m_constitutiveManager( std::make_unique< ConstitutiveManager >( ConstitutiveManager::groupKeyStruct::constitutiveModelsString(), m_parent.get() ))
Expand Down Expand Up @@ -143,6 +164,7 @@ template< typename CAP_PRESSURE, integer NUM_PHASE >
void
InverseCapillaryPressureTestFixture< CAP_PRESSURE, NUM_PHASE >::testInversion( TestData< NUM_PHASE > const & testData )
{
InverseCapillaryPressureTestState & state = getState();
StackArray< real64, 2, NUM_PHASE, compflow::LAYOUT_PHASE > phaseVolumeFraction( 1, NUM_PHASE );
StackArray< real64, 3, NUM_PHASE, constitutive::cappres::LAYOUT_CAPPRES > capillaryPressure( 1, 1, NUM_PHASE );
StackArray< real64, 1, NUM_PHASE > jFunctionMultiplier( NUM_PHASE-1 );
Expand All @@ -157,11 +179,11 @@ InverseCapillaryPressureTestFixture< CAP_PRESSURE, NUM_PHASE >::testInversion( T
}

string const modelName = GEOS_FMT( "{}{}", CapPressureModel::catalogName(), NUM_PHASE );
CapPressureModel & model = m_constitutiveManager->getConstitutiveRelation< CapPressureModel >( modelName );
CapPressureModel & model = state.m_constitutiveManager->template getConstitutiveRelation< CapPressureModel >( modelName );

if constexpr (std::is_same_v< CapPressureModel, JFunctionCapillaryPressure >)
{
model.allocateConstitutiveData( *m_constitutiveManager, 2 );
model.allocateConstitutiveData( *state.m_constitutiveManager, 2 );
array3d< real64 > perm( 1, 1, 3 );
array2d< real64 > poro( 1, 2 );
perm( 0, 0, 0 ) = permeability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ void testModifiedCamClayDriver()

// run loading

for( localIndex loadstep=0; loadstep < 500; ++loadstep )
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
{
forAll< POLICY >( 1, [=] GEOS_HOST_DEVICE ( localIndex const k )
for( localIndex loadstep=0; loadstep < 500; ++loadstep )
{
real64 stressLocal[6] = {0};
real64 stiffnessLocal[6][6] = {{0}};
cmw.smallStrainUpdate( k, 0, timeIncrement, data.strainIncrement, stressLocal, stiffnessLocal );
} );
cm.saveConvergedState();
}
cmw.saveConvergedState( k, 0 );
}
} );

// get final stress state in p-q space

Expand All @@ -163,8 +163,6 @@ void testModifiedCamClayDriver()
// we now use a finite-difference check of tangent stiffness to confirm
// the analytical form is working properly.

SolidUtilities::checkSmallStrainStiffness( cmw, 0, 0, timeIncrement, data.strainIncrement, true );

EXPECT_TRUE( SolidUtilities::checkSmallStrainStiffness( cmw, 0, 0, timeIncrement, data.strainIncrement ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ TEST_F( MultiFluidBlackOilTestMass, numericalDerivatives )

real64 constexpr eps = 1.0e-6;

for( auto const & data : getTestData< MultiFluidBlackOilTestMass >())
{
Base::testNumericalDerivatives( fluid, data, eps );
}
Base::testNumericalDerivatives( fluid, getTestData< MultiFluidBlackOilTestMass >(), eps );
}

TEST_F( MultiFluidBlackOilTestMolar, numericalDerivatives )
Expand All @@ -166,10 +163,7 @@ TEST_F( MultiFluidBlackOilTestMolar, numericalDerivatives )

real64 constexpr eps = 1.0e-6;

for( auto const & data : getTestData< MultiFluidBlackOilTestMolar >())
{
Base::testNumericalDerivatives( fluid, data, eps );
}
Base::testNumericalDerivatives( fluid, getTestData< MultiFluidBlackOilTestMolar >(), eps );
}

TEST_P( MultiFluidBlackOilTestMolar, testFluidValues )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ class MultiFluidCO2BrineTestFixture : public FluidModelTest< typename FluidType<
constexpr real64 temperatures[] = { 367.65, 368.00, 368.75 };
constexpr real64 pressures[] = { 20.01e5, 75.01e5, 120.1e5 };
auto const samples = { Feed< 2 >{0.7, 0.3}, Feed< 2 >{0.01, 0.99}, Feed< 2 >{0.99, 0.01} };
stdVector< typename Base::TestPoint > testData;
testData.reserve( 27 );

for( auto const & sample : samples )
{
for( real64 const pressure : pressures )
{
for( real64 const temperature : temperatures )
{
typename Base::TestPoint const data ( pressure, temperature, sample );
Base::testNumericalDerivatives( fluid, data, eps );
testData.emplace_back( pressure, temperature, sample );
}
}
}
Base::testNumericalDerivatives( fluid, testData, eps );
}

static string getFluidName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ TYPED_TEST_SUITE( MultiFluidDeadOilTestFixture, TestTypes, NameGenerator );
TYPED_TEST( MultiFluidDeadOilTestFixture, numericalDerivatives )
{
DeadOilFluid * fluid = this->getFluid( this->getFluidName() );
stdVector< typename TestFixture::Base::TestPoint > testData;
testData.reserve( 3 );

for( real64 const pressure : { 1.24e7, 3.21e7, 5.01e7 } )
{
typename TestFixture::Base::TestPoint const data ( pressure, 297.15, { 0.1, 0.3, 0.6 } );
TestFixture::Base::testNumericalDerivatives( fluid, data );
testData.emplace_back( pressure, 297.15, Feed< 3 >{ 0.1, 0.3, 0.6 } );
}
TestFixture::Base::testNumericalDerivatives( fluid, testData );
}

} // testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class MultiFluidCompositionalMultiphaseTestFixture : public FluidModelTest< Comp

constexpr real64 pressures[] = { 10.0e5, 50.0e5, 100.0e5, 600.0e5 };
constexpr real64 temperatures[] = { 15.5, 24.0, 40.0, 80.0 };
stdVector< typename Base::TestPoint > testData;
testData.reserve( sampleCount * 16 );

for( integer sampleIndex = 0; sampleIndex < sampleCount; ++sampleIndex )
{
Expand All @@ -79,11 +81,11 @@ class MultiFluidCompositionalMultiphaseTestFixture : public FluidModelTest< Comp
{
for( real64 const temperature : temperatures )
{
typename Base::TestPoint const data ( pressure, units::convertCToK( temperature ), sample );
Base::testNumericalDerivatives( fluid, data, eps, relTol, absTol );
testData.emplace_back( pressure, units::convertCToK( temperature ), sample );
}
}
}
Base::testNumericalDerivatives( fluid, testData, eps, relTol, absTol );
}

static string getFluidName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class MultiFluidCompositionalMultiphaseTestFixture : public FluidModelTest<

constexpr real64 pressures[] = { 10.0e5, 50.0e5, 100.0e5, 600.0e5 };
constexpr real64 temperatures[] = { 15.5, 24.0, 40.0, 80.0 };
stdVector< typename Base::TestPoint > testData;
testData.reserve( sampleCount * 16 );

for( integer sampleIndex = 0; sampleIndex < sampleCount; ++sampleIndex )
{
Expand All @@ -99,11 +101,11 @@ class MultiFluidCompositionalMultiphaseTestFixture : public FluidModelTest<
{
for( real64 const temperature : temperatures )
{
typename Base::TestPoint const data ( pressure, units::convertCToK( temperature ), sample );
Base::testNumericalDerivatives( fluid, data, eps, relTol, absTol );
testData.emplace_back( pressure, units::convertCToK( temperature ), sample );
}
}
}
Base::testNumericalDerivatives( fluid, testData, eps, relTol, absTol );
}

static string getFluidName();
Expand Down
Loading