Skip to content

Commit

Permalink
fix: Regex validation bugfix & unit test (#3403)
Browse files Browse the repository at this point in the history
  • Loading branch information
MelReyCG authored Oct 18, 2024
1 parent 7eee999 commit b43e001
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/coreComponents/codingUtilities/EnumStrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct TypeRegex< ENUM, std::enable_if_t< internal::HasEnumStrings< ENUM > > >
static Regex get()
{
return Regex( EnumStrings< ENUM >::concat( "|" ),
"Input value must be one of { " + EnumStrings< ENUM >::concat( ", " ) + "}." );
"Input value must be one of { " + EnumStrings< ENUM >::concat( ", " ) + " }." );
}
};

Expand Down
27 changes: 27 additions & 0 deletions src/coreComponents/dataRepository/unitTests/testXmlWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <gtest/gtest.h>

#include "dataRepository/xmlWrapper.hpp"
#include "codingUtilities/EnumStrings.hpp"

using namespace geos;

Expand Down Expand Up @@ -328,6 +329,32 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple( "1 2", 0, true )));


enum class TestEnum { None, Default, Value, Value2 };
ENUM_STRINGS( TestEnum, "None", "Default", "Value", "Value2" );

class enumAttributeTestFixture : public AttributeReadTestFixture< TestEnum > {};

TEST_P( enumAttributeTestFixture, testParsing )
{
testParams = GetParam();
this->test();
}

INSTANTIATE_TEST_SUITE_P(
enumAttributeTests,
enumAttributeTestFixture,
::testing::Values( std::make_tuple( "None", TestEnum::None, false ),
std::make_tuple( "Default", TestEnum::Default, false ),
std::make_tuple( "Value", TestEnum::Value, false ),
std::make_tuple( "Value2", TestEnum::Value2, false ),
std::make_tuple( "0", TestEnum( 0 ), true ),
std::make_tuple( "4.", TestEnum( 0 ), true ),
std::make_tuple( "alpha", TestEnum( 0 ), true ),
std::make_tuple( "Val", TestEnum( 0 ), true ),
std::make_tuple( "Def ault", TestEnum( 0 ), true ),
std::make_tuple( "None123", TestEnum( 0 ), true ) ) );


TEST( testXmlWrapper, testGroupNamesFormats )
{
struct GroupNameTest
Expand Down
4 changes: 2 additions & 2 deletions src/coreComponents/dataRepository/xmlWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace xmlWrapper
void validateString( string const & value, Regex const & regex )
{
std::smatch m;
bool inputValidated = std::regex_search( value, m, std::regex( regex.m_regexStr ) );
if( !inputValidated || m.length() != ptrdiff_t( value.length() ) )
bool inputValidated = std::regex_match( value, m, std::regex( regex.m_regexStr ) );
if( !inputValidated )
{
ptrdiff_t errorId = ( m.size()>0 && m.position( 0 )==0 ) ? m.length() : 0;
GEOS_THROW( GEOS_FMT( "Input string validation failed at:\n"
Expand Down
70 changes: 70 additions & 0 deletions src/coreComponents/schema/schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@
<xsd:selector xpath="SinglePhaseReservoirPoromechanics" />
<xsd:field xpath="@name" />
</xsd:unique>
<xsd:unique name="SolversSinglePhaseReservoirPoromechanicsConformingFracturesUniqueName">
<xsd:selector xpath="SinglePhaseReservoirPoromechanicsConformingFractures" />
<xsd:field xpath="@name" />
</xsd:unique>
<xsd:unique name="SolversSinglePhaseWellUniqueName">
<xsd:selector xpath="SinglePhaseWell" />
<xsd:field xpath="@name" />
Expand Down Expand Up @@ -519,6 +523,10 @@
<xsd:selector xpath="SinglePhasePoromechanicsInitialization" />
<xsd:field xpath="@name" />
</xsd:unique>
<xsd:unique name="TasksSinglePhaseReservoirPoromechanicsConformingFracturesInitializationUniqueName">
<xsd:selector xpath="SinglePhaseReservoirPoromechanicsConformingFracturesInitialization" />
<xsd:field xpath="@name" />
</xsd:unique>
<xsd:unique name="TasksSinglePhaseReservoirPoromechanicsInitializationUniqueName">
<xsd:selector xpath="SinglePhaseReservoirPoromechanicsInitialization" />
<xsd:field xpath="@name" />
Expand Down Expand Up @@ -2197,6 +2205,7 @@ the relative residual norm satisfies:
<xsd:element name="SinglePhaseProppantFVM" type="SinglePhaseProppantFVMType" />
<xsd:element name="SinglePhaseReservoir" type="SinglePhaseReservoirType" />
<xsd:element name="SinglePhaseReservoirPoromechanics" type="SinglePhaseReservoirPoromechanicsType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsConformingFractures" type="SinglePhaseReservoirPoromechanicsConformingFracturesType" />
<xsd:element name="SinglePhaseWell" type="SinglePhaseWellType">
<xsd:unique name="SolversSinglePhaseWellWellControlsUniqueName">
<xsd:selector xpath="WellControls" />
Expand Down Expand Up @@ -3912,6 +3921,51 @@ Level 0 outputs no specific information for this solver. Higher levels require m
<!--stabilizationType => StabilizationType. Options are:
None- Add no stabilization to mass equation
Global- Add jump stabilization to all faces
Local- Add jump stabilization on interior of macro elements-->
<xsd:attribute name="stabilizationType" type="geos_stabilization_StabilizationType" default="None" />
<!--targetRegions => Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager.-->
<xsd:attribute name="targetRegions" type="groupNameRef_array" use="required" />
<!--writeLinearSystem => Write matrix, rhs, solution to screen ( = 1) or file ( = 2).-->
<xsd:attribute name="writeLinearSystem" type="integer" default="0" />
<!--name => A name is required for any non-unique nodes-->
<xsd:attribute name="name" type="groupName" use="required" />
</xsd:complexType>
<xsd:complexType name="SinglePhaseReservoirPoromechanicsConformingFracturesType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="LinearSolverParameters" type="LinearSolverParametersType" maxOccurs="1" />
<xsd:element name="NonlinearSolverParameters" type="NonlinearSolverParametersType" maxOccurs="1" />
</xsd:choice>
<!--cflFactor => Factor to apply to the `CFL condition <http://en.wikipedia.org/wiki/Courant-Friedrichs-Lewy_condition>`_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -->
<xsd:attribute name="cflFactor" type="real64" default="0.5" />
<!--initialDt => Initial time-step value required by the solver to the event manager.-->
<xsd:attribute name="initialDt" type="real64" default="1e+99" />
<!--isThermal => Flag indicating whether the problem is thermal or not. Set isThermal="1" to enable the thermal coupling-->
<xsd:attribute name="isThermal" type="integer" default="0" />
<!--logLevel => Sets the level of information to write in the standard output (the console typically).
Level 0 outputs no specific information for this solver. Higher levels require more outputs.
1
- Line search information
- Solution information (scaling, maximum changes, quality check)
- Convergence information
- Time step information
- Linear solver information
- Nonlinear solver information
- Solver timers information
- Coupling information
2
- The summary of declared fields and coupling-->
<xsd:attribute name="logLevel" type="integer" default="0" />
<!--reservoirAndWellsSolverName => Name of the reservoirAndWells solver used by the coupled solver-->
<xsd:attribute name="reservoirAndWellsSolverName" type="groupNameRef" use="required" />
<!--solidSolverName => Name of the solid solver used by the coupled solver-->
<xsd:attribute name="solidSolverName" type="groupNameRef" use="required" />
<!--stabilizationMultiplier => Constant multiplier of stabilization strength-->
<xsd:attribute name="stabilizationMultiplier" type="real64" default="1" />
<!--stabilizationRegionNames => Regions where stabilization is applied.-->
<xsd:attribute name="stabilizationRegionNames" type="groupNameRef_array" default="{}" />
<!--stabilizationType => StabilizationType. Options are:
None- Add no stabilization to mass equation
Global- Add jump stabilization to all faces
Local- Add jump stabilization on interior of macro elements-->
<xsd:attribute name="stabilizationType" type="geos_stabilization_StabilizationType" default="None" />
<!--targetRegions => Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager.-->
Expand All @@ -3927,6 +3981,8 @@ Local- Add jump stabilization on interior of macro elements-->
<xsd:element name="NonlinearSolverParameters" type="NonlinearSolverParametersType" maxOccurs="1" />
<xsd:element name="WellControls" type="WellControlsType" />
</xsd:choice>
<!--allowNegativePressure => Flag indicating if negative pressure is allowed-->
<xsd:attribute name="allowNegativePressure" type="integer" default="1" />
<!--cflFactor => Factor to apply to the `CFL condition <http://en.wikipedia.org/wiki/Courant-Friedrichs-Lewy_condition>`_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -->
<xsd:attribute name="cflFactor" type="real64" default="0.5" />
<!--initialDt => Initial time-step value required by the solver to the event manager.-->
Expand Down Expand Up @@ -4374,6 +4430,7 @@ Level 0 outputs no specific information for this solver. Higher levels require m
<xsd:element name="SinglePhasePoromechanicsConformingFracturesInitialization" type="SinglePhasePoromechanicsConformingFracturesInitializationType" />
<xsd:element name="SinglePhasePoromechanicsEmbeddedFracturesInitialization" type="SinglePhasePoromechanicsEmbeddedFracturesInitializationType" />
<xsd:element name="SinglePhasePoromechanicsInitialization" type="SinglePhasePoromechanicsInitializationType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsConformingFracturesInitialization" type="SinglePhaseReservoirPoromechanicsConformingFracturesInitializationType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsInitialization" type="SinglePhaseReservoirPoromechanicsInitializationType" />
<xsd:element name="SinglePhaseStatistics" type="SinglePhaseStatisticsType" />
<xsd:element name="SolidMechanicsStateReset" type="SolidMechanicsStateResetType" />
Expand Down Expand Up @@ -4554,6 +4611,19 @@ Level 0 outputs no specific information for this solver. Higher levels require m
<xsd:complexType name="SinglePhasePoromechanicsInitializationType">
<!--logLevel => Sets the level of information to write in the standard output (the console typically).
Level 0 outputs no specific information for this solver. Higher levels require more outputs.
1
- Initialization information-->
<xsd:attribute name="logLevel" type="integer" default="0" />
<!--poromechanicsSolverName => Name of the poromechanics solver-->
<xsd:attribute name="poromechanicsSolverName" type="groupNameRef" use="required" />
<!--solidMechanicsStatisticsName => Name of the solid mechanics statistics-->
<xsd:attribute name="solidMechanicsStatisticsName" type="groupNameRef" default="" />
<!--name => A name is required for any non-unique nodes-->
<xsd:attribute name="name" type="groupName" use="required" />
</xsd:complexType>
<xsd:complexType name="SinglePhaseReservoirPoromechanicsConformingFracturesInitializationType">
<!--logLevel => Sets the level of information to write in the standard output (the console typically).
Level 0 outputs no specific information for this solver. Higher levels require more outputs.
1
- Initialization information-->
<xsd:attribute name="logLevel" type="integer" default="0" />
Expand Down
18 changes: 18 additions & 0 deletions src/coreComponents/schema/schema.xsd.other
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
<xsd:element name="SinglePhaseProppantFVM" type="SinglePhaseProppantFVMType" />
<xsd:element name="SinglePhaseReservoir" type="SinglePhaseReservoirType" />
<xsd:element name="SinglePhaseReservoirPoromechanics" type="SinglePhaseReservoirPoromechanicsType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsConformingFractures" type="SinglePhaseReservoirPoromechanicsConformingFracturesType" />
<xsd:element name="SinglePhaseWell" type="SinglePhaseWellType" />
<xsd:element name="SolidMechanicsAugmentedLagrangianContact" type="SolidMechanicsAugmentedLagrangianContactType" />
<xsd:element name="SolidMechanicsEmbeddedFractures" type="SolidMechanicsEmbeddedFracturesType" />
Expand Down Expand Up @@ -1156,6 +1157,21 @@
<!--performStressInitialization => Flag to indicate that the solver is going to perform stress initialization-->
<xsd:attribute name="performStressInitialization" type="integer" />
</xsd:complexType>
<xsd:complexType name="SinglePhaseReservoirPoromechanicsConformingFracturesType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="LinearSolverParameters" type="LinearSolverParametersType" maxOccurs="1" />
<xsd:element name="NonlinearSolverParameters" type="NonlinearSolverParametersType" maxOccurs="1" />
<xsd:element name="SolverStatistics" type="SolverStatisticsType" />
</xsd:choice>
<!--discretization => Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified.-->
<xsd:attribute name="discretization" type="groupNameRef" />
<!--maxStableDt => Value of the Maximum Stable Timestep for this solver.-->
<xsd:attribute name="maxStableDt" type="real64" />
<!--meshTargets => MeshBody/Region combinations that the solver will be applied to.-->
<xsd:attribute name="meshTargets" type="geos_mapBase_lt_std_pair_lt_string_cm_-string-_gt__cm_-LvArray_Array_lt_string_cm_-1_cm_-camp_int_seq_lt_long_cm_-0l_gt__cm_-int_cm_-LvArray_ChaiBuffer_gt__cm_-std_integral_constant_lt_bool_cm_-true_gt_-_gt_" />
<!--performStressInitialization => Flag to indicate that the solver is going to perform stress initialization-->
<xsd:attribute name="performStressInitialization" type="integer" />
</xsd:complexType>
<xsd:complexType name="SinglePhaseWellType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="LinearSolverParameters" type="LinearSolverParametersType" maxOccurs="1" />
Expand Down Expand Up @@ -1337,6 +1353,7 @@
<xsd:element name="SinglePhasePoromechanicsConformingFracturesInitialization" type="SinglePhasePoromechanicsConformingFracturesInitializationType" />
<xsd:element name="SinglePhasePoromechanicsEmbeddedFracturesInitialization" type="SinglePhasePoromechanicsEmbeddedFracturesInitializationType" />
<xsd:element name="SinglePhasePoromechanicsInitialization" type="SinglePhasePoromechanicsInitializationType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsConformingFracturesInitialization" type="SinglePhaseReservoirPoromechanicsConformingFracturesInitializationType" />
<xsd:element name="SinglePhaseReservoirPoromechanicsInitialization" type="SinglePhaseReservoirPoromechanicsInitializationType" />
<xsd:element name="SinglePhaseStatistics" type="SinglePhaseStatisticsType" />
<xsd:element name="SolidMechanicsStateReset" type="SolidMechanicsStateResetType" />
Expand Down Expand Up @@ -1366,6 +1383,7 @@
<xsd:complexType name="SinglePhasePoromechanicsConformingFracturesInitializationType" />
<xsd:complexType name="SinglePhasePoromechanicsEmbeddedFracturesInitializationType" />
<xsd:complexType name="SinglePhasePoromechanicsInitializationType" />
<xsd:complexType name="SinglePhaseReservoirPoromechanicsConformingFracturesInitializationType" />
<xsd:complexType name="SinglePhaseReservoirPoromechanicsInitializationType" />
<xsd:complexType name="SinglePhaseStatisticsType" />
<xsd:complexType name="SolidMechanicsStateResetType" />
Expand Down

0 comments on commit b43e001

Please sign in to comment.