mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
committed by
Andrew Heather
parent
5577606997
commit
f084309b37
@ -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.
|
//- Reference type cast template function.
|
||||||
// As per dynamicCast, but handles type names for the error messages
|
// As per dynamicCast, but handles type names for the error messages
|
||||||
// via the virtual type() method.
|
// via the virtual type() method.
|
||||||
|
|||||||
@ -188,7 +188,8 @@ Foam::nutWallFunctionFvPatchScalarField::nutw
|
|||||||
return
|
return
|
||||||
refCast<const nutWallFunctionFvPatchScalarField>
|
refCast<const nutWallFunctionFvPatchScalarField>
|
||||||
(
|
(
|
||||||
turbModel.nut()().boundaryField()[patchi]
|
turbModel.nut()().boundaryField()[patchi],
|
||||||
|
patchi
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user