Skip to content
Snippets Groups Projects
Commit f084309b authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add refCast variant with an index to convey the context

- can be helpful, for example, when the refCast has been used on a
  boundary patch. Knowing which patch index triggered the problem
  helps with isolating the issue.
parent 55776069
No related branches found
No related tags found
No related merge requests found
......@@ -145,6 +145,30 @@ inline To& refCast(From& r)
}
//- Reference type cast template function.
// As per dynamicCast, but handles type names for the error messages
// via the virtual type() method.
// Can use index to convey the context.
template<class To, class From>
inline To& refCast(From& r, const label index)
{
try
{
return dynamic_cast<To&>(r);
}
catch (const std::bad_cast&)
{
FatalErrorInFunction
<< "Attempt to cast type " << r.type()
<< " to type " << To::typeName
<< " at index " << index
<< abort(FatalError);
return dynamic_cast<To&>(r);
}
}
//- Reference type cast template function.
// As per dynamicCast, but handles type names for the error messages
// via the virtual type() method.
......
......@@ -188,7 +188,8 @@ Foam::nutWallFunctionFvPatchScalarField::nutw
return
refCast<const nutWallFunctionFvPatchScalarField>
(
turbModel.nut()().boundaryField()[patchi]
turbModel.nut()().boundaryField()[patchi],
patchi
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment