Skip to content

Commit

Permalink
Add component selector
Browse files Browse the repository at this point in the history
  • Loading branch information
dkachuma committed Jul 5, 2024
1 parent 94a0e86 commit 0c89869
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ CO2BrineFluid( string const & name, Group * const parent ):
}
}

template< typename PHASE1, typename PHASE2, typename FLASH >
bool CO2BrineFluid< PHASE1, PHASE2, FLASH >::isThermal() const
{
return ( PHASE1::Enthalpy::catalogName() != PVTProps::NoOpPVTFunction::catalogName() &&
PHASE2::Enthalpy::catalogName() != PVTProps::NoOpPVTFunction::catalogName() );
}


template< typename PHASE1, typename PHASE2, typename FLASH >
std::unique_ptr< ConstitutiveBase >
CO2BrineFluid< PHASE1, PHASE2, FLASH >::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ class CO2BrineFluid : public MultiFluidBase

virtual string getCatalogName() const override { return catalogName(); }

virtual bool isThermal() const override;
static constexpr bool thermal()
{
return !( std::is_same< typename PHASE1::Enthalpy, PVTProps::NoOpPVTFunction >::value ||
std::is_same< typename PHASE2::Enthalpy, PVTProps::NoOpPVTFunction >::value );
}

virtual bool isThermal() const override
{
return thermal();
}

/**
* @brief Kernel wrapper class for CO2BrineFluid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,103 @@ void constitutiveUpdatePassThru( MultiFluidBase & fluid,
>::execute( fluid, std::forward< LAMBDA >( lambda ) );
}

namespace internal
{
// Lists the possible numbers of components supported by a fluid type
// Most of the fluid types support only 2 components so this is the default
template< typename FluidType >
struct Components
{
using type = camp::int_seq< integer, 2 >;
};

// Blackoiub fluid models support anything from 2 or 3 components
template<>
struct Components< DeadOilFluid >
{
using type = camp::int_seq< integer, 2, 3 >;
};
template<>
struct Components< BlackOilFluid >
{
using type = camp::int_seq< integer, 2, 3 >;
};

// Compositional fluid models support anything from 2 to 5 components
template<>
struct Components< CompositionalMultiphaseFluidPVTPackage >
{
using type = camp::int_seq< integer, 2, 3, 4, 5 >;
};
template<>
struct Components< CompositionalTwoPhaseLohrenzBrayClarkViscosity >
{
using type = camp::int_seq< integer, 2, 3, 4, 5 >;
};
template<>
struct Components< CompositionalTwoPhaseConstantViscosity >
{
using type = camp::int_seq< integer, 2, 3, 4, 5 >;
};

template< typename Components >
struct ComponentSelector
{};

template< integer ... Is >
struct ComponentSelector< camp::int_seq< integer, Is ... > >
{
template< typename FluidType, typename LAMBDA >
static void select( int numComps, FluidType & fluid, LAMBDA && lambda )
{
bool notSupported = false;
// With gcc8, the fold expression below issues a spurious warning
// warning: suggest parentheses around '&&' within '||' [-Wparentheses]
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94505
#if (defined(__GNUC__) && (__GNUC__ < 10))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
( ((numComps == Is) && (lambda( fluid, std::integral_constant< integer, Is >() ), true)) || ...) || (notSupported = true, false);
#if (defined(__GNUC__) && (__GNUC__ < 10))
#pragma GCC diagnostic pop
#endif
if( notSupported )
{
GEOS_THROW( "Unsupported number of components: " << numComps << " for fluid " << FluidType::catalogName(), SimulationError );
}
}
};

}

template< bool THERMAL = false, typename LAMBDA = NoOpFunc >
void constitutiveComponentUpdatePassThru( MultiFluidBase & fluidBase,
integer const numComps,
LAMBDA && lambda )
{
ConstitutivePassThruHandler< DeadOilFluid,
BlackOilFluid,
#ifdef GEOSX_USE_PVTPackage
CompositionalMultiphaseFluidPVTPackage,
#endif
CO2BrinePhillipsFluid,
CO2BrineEzrokhiFluid,
CO2BrinePhillipsThermalFluid,
CO2BrineEzrokhiThermalFluid,
CompositionalTwoPhaseLohrenzBrayClarkViscosity,
CompositionalTwoPhaseConstantViscosity
>::execute( fluidBase, [&]( auto & fluid )
{
using FluidType = TYPEOFREF( fluid );
if constexpr (!THERMAL || FluidType::thermal())
{
using Components = typename internal::Components< FluidType >::type;
internal::ComponentSelector< Components >::select( numComps, fluid, std::forward< LAMBDA >( lambda ));
}
} );
}

} // namespace constitutive

} // namespace geos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class BlackOilFluid : public BlackOilFluidBase

virtual string getCatalogName() const override { return catalogName(); }

static constexpr bool thermal(){ return false; }

/**
* @brief Kernel wrapper class for BlackOilFluid
* This kernel can be called on the GPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DeadOilFluid : public BlackOilFluidBase

virtual string getCatalogName() const override { return catalogName(); }

static constexpr bool thermal(){ return false; }

/**
* @brief Kernel wrapper class for DeadOilFluid
* This kernel can be called on the GPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CompositionalMultiphaseFluid : public MultiFluidBase

virtual string getCatalogName() const override { return catalogName(); }

static constexpr bool thermal(){ return false; }

// TODO: This method should be implemented if an incorrect extrapolation of the pressure and temperature is encountered in the kernel
/**
* @copydoc MultiFluidBase::checkTablesParameters( real64 pressure, real64 temperature )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CompositionalMultiphaseFluidPVTPackage : public MultiFluidBase

virtual string getCatalogName() const override { return catalogName(); }

static constexpr bool thermal(){ return false; }

// TODO: This method should be implemented if an incorrect extrapolation of the pressure and temperature is encountered in the kernel
/**
* @copydoc MultiFluidBase::checkTablesParameters( real64 pressure, real64 temperature )
Expand Down
1 change: 1 addition & 0 deletions src/coreComponents/constitutive/unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set( gtest_geosx_tests
testKValueInitialization.cpp
testLohrenzBrayClarkViscosity.cpp
testModifiedCamClay.cpp
testMultiFluidSelector.cpp
testNegativeTwoPhaseFlash.cpp
testNegativeTwoPhaseFlash9Comp.cpp
testParticleFluidEnums.cpp
Expand Down
110 changes: 110 additions & 0 deletions src/coreComponents/constitutive/unitTests/testMultiFluidSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

// Source includes
#include "codingUtilities/UnitTestUtilities.hpp"
#include "constitutive/fluid/multifluid/MultiFluidSelector.hpp"

using namespace geos;
using namespace geos::testing;
using namespace geos::constitutive;

template< typename FluidType >
class MultiFluidSelectorTest : public ::testing::Test
{
public:
MultiFluidSelectorTest():
m_node(),
m_parent( "parent", m_node )
{
m_model = &m_parent.registerGroup< FluidType >( "fluid" );
}
~MultiFluidSelectorTest() override = default;

MultiFluidBase & getFluid() const { return *m_model; }

protected:
conduit::Node m_node;
dataRepository::Group m_parent;
FluidType * m_model{};
};

using MultiFluidSelectorTestDeadOilFluid = MultiFluidSelectorTest< DeadOilFluid >;
using MultiFluidSelectorTestCO2BrinePhillipsThermalFluid = MultiFluidSelectorTest< CO2BrinePhillipsThermalFluid >;

TEST_F( MultiFluidSelectorTestDeadOilFluid, testValidComponents )
{
constitutiveComponentUpdatePassThru( getFluid(), 2, []( auto &, auto NC ){
integer constexpr numComps = NC();
EXPECT_EQ( numComps, 2 );
} );

constitutiveComponentUpdatePassThru( getFluid(), 3, []( auto &, auto NC ){
integer constexpr numComps = NC();
EXPECT_EQ( numComps, 3 );
} );
}

TEST_F( MultiFluidSelectorTestDeadOilFluid, testInvalidComponents )
{
EXPECT_THROW( constitutiveComponentUpdatePassThru( getFluid(), 1, []( auto &, auto ){
FAIL(); // Shouldn't be called
} ), SimulationError );

EXPECT_THROW( constitutiveComponentUpdatePassThru( getFluid(), 4, []( auto &, auto ){
FAIL(); // Shouldn't be called
} ), SimulationError );
}

TEST_F( MultiFluidSelectorTestDeadOilFluid, testThermal )
{
constitutiveComponentUpdatePassThru< true >( getFluid(), 2, []( auto &, auto ){
FAIL(); // Shouldn't be called
} );
}

TEST_F( MultiFluidSelectorTestCO2BrinePhillipsThermalFluid, testValidComponents )
{
constitutiveComponentUpdatePassThru( getFluid(), 2, []( auto &, auto NC ){
integer constexpr numComps = NC();
EXPECT_EQ( numComps, 2 );
} );
}

TEST_F( MultiFluidSelectorTestCO2BrinePhillipsThermalFluid, testInvalidComponents )
{
EXPECT_THROW( constitutiveComponentUpdatePassThru( getFluid(), 1, []( auto &, auto ){
FAIL(); // Shouldn't be called
} ), SimulationError );

EXPECT_THROW( constitutiveComponentUpdatePassThru( getFluid(), 3, []( auto &, auto ){
FAIL(); // Shouldn't be called
} ), SimulationError );
}

TEST_F( MultiFluidSelectorTestCO2BrinePhillipsThermalFluid, testThermal )
{
bool isTested = false;
constitutiveComponentUpdatePassThru< true >( getFluid(), 2, [&]( auto &, auto ){
isTested = true;
} );
EXPECT_TRUE( isTested );
}

int main( int argc, char * * argv )
{
::testing::InitGoogleTest( &argc, argv );
int const result = RUN_ALL_TESTS();
return result;
}

0 comments on commit 0c89869

Please sign in to comment.