Skip to content

Commit

Permalink
Added vector version of NaNInterface::getNaN
Browse files Browse the repository at this point in the history
Refs #12234
  • Loading branch information
joshuahansel committed Apr 24, 2020
1 parent 82245fb commit bffd8c9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
38 changes: 37 additions & 1 deletion modules/fluid_properties/include/interfaces/NaNInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ class NaNInterface
const enum NaNMessage _emit_on_nan;

/**
* Produces errors, warnings, or just quiet NaNs
* Throws an error or returns a NaN with or without a warning, with a default message
*/
Real getNaN() const { return getNaN("A NaN was produced."); }

/**
* Throws an error or returns NaNs with or without a warning, with a default message
*
* @param[in] n Vector size
*/
std::vector<Real> getNaNVector(const unsigned int & n) const
{
return getNaNVector(n, "A NaN was produced.");
}

/**
* Throws an error or returns a NaN with or without a warning
*/
template <typename... Args>
Real getNaN(Args &&... args) const
{
Expand All @@ -61,4 +74,27 @@ class NaNInterface
// return a quiet NaN
return std::nan("");
}

/**
* Throws an error or returns NaNs with or without a warning
*
* @param[in] n Vector size
*/
template <typename... Args>
std::vector<Real> getNaNVector(const unsigned int & n, Args &&... args) const
{
switch (_emit_on_nan)
{
case (NAN_MESSAGE_WARNING):
mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
break;
case (NAN_MESSAGE_ERROR):
mooseError(_moose_object->name(), ": ", std::forward<Args>(args)...);
break;
default:
break;
}
// return quiet NaNs
return std::vector<Real>(n, std::nan(""));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ class NaNInterfaceTestFluidProperties : public SinglePhaseFluidProperties, publi

virtual Real p_from_v_e(Real v, Real e) const override;
virtual void p_from_v_e(Real v, Real e, Real & p, Real & dp_dv, Real & dp_de) const override;

/**
* Returns a NaN vector of size 2
*/
std::vector<Real> returnNaNVector() const;
};
#pragma GCC diagnostic pop
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NaNInterfaceTestKernel::validParams()

params.addRequiredParam<UserObjectName>("nan_interface_test_fp",
"NaNInterfaceTestFluidProperties user object name");
params.addParam<bool>("test_vector_version", false, "Test getNaNVector? Else, test getNaN");

params.addClassDescription("Kernel to test NaNInterface using NaNInterfaceTestFluidProperties");

Expand All @@ -34,5 +35,11 @@ NaNInterfaceTestKernel::NaNInterfaceTestKernel(const InputParameters & parameter
Real
NaNInterfaceTestKernel::computeQpResidual()
{
return _nan_interface_test_fp.p_from_v_e(0, 0);
if (getParam<bool>("test_vector_version"))
{
const std::vector<Real> nan_vector = _nan_interface_test_fp.returnNaNVector();
return nan_vector[0];
}
else
return _nan_interface_test_fp.p_from_v_e(0, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ void
NaNInterfaceTestFluidProperties::p_from_v_e(Real, Real, Real &, Real &, Real &) const
{
}

std::vector<Real>
NaNInterfaceTestFluidProperties::returnNaNVector() const
{
return getNaNVector(2);
}
17 changes: 15 additions & 2 deletions modules/fluid_properties/test/tests/interfaces/nan_interface/tests
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
[Tests]
[./quiet_nan]
[./quiet_nan_scalar]
type = 'RunException'
input = 'nan_interface.i'
cli_args = 'Modules/FluidProperties/fp/emit_on_nan=warning'
allow_test_objects = True
method = 'DBG'
threading = '!pthreads'

requirement = 'The system should produce a warning when a NaN is produced and user required that the execution would not terminate'
requirement = 'The system should produce a warning when a scalar NaN is produced and user required that the execution would not terminate'
expect_err = "fp: A NaN was produced."
design = '/NaNInterface.md'
issues = '#12234 #12350'
[../]
[./quiet_nan_vector]
type = 'RunException'
input = 'nan_interface.i'
cli_args = 'Modules/FluidProperties/fp/emit_on_nan=warning Kernels/test_kernel/test_vector_version=true'
allow_test_objects = True
method = 'DBG'
threading = '!pthreads'

requirement = 'The system should produce a warning when a vector NaN is produced and user required that the execution would not terminate'
expect_err = "fp: A NaN was produced."
design = '/NaNInterface.md'
issues = '#12234 #12350'
Expand Down

0 comments on commit bffd8c9

Please sign in to comment.