Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
8aa7b135
Commit
8aa7b135
authored
Jul 26, 2018
by
mattijs
Browse files
ENH: refCast: give better error messages. Fixes
#953
.
parent
b2be9fa3
Changes
29
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/db/typeInfo/typeInfo.H
View file @
8aa7b135
...
...
@@ -100,6 +100,27 @@ inline To& dynamicCast(From& r)
}
//- Reference type cast template function,
// wraps dynamic_cast to handle bad_cast exception and generate a FatalError.
template
<
class
To
,
class
From
>
inline
To
&
dynamicCast
(
From
&
r
,
const
dictionary
&
d
)
{
try
{
return
dynamic_cast
<
To
&>
(
r
);
}
catch
(
std
::
bad_cast
&
)
{
FatalIOErrorInFunction
(
d
)
<<
"Attempt to cast type "
<<
typeid
(
r
).
name
()
<<
" to type "
<<
typeid
(
To
).
name
()
<<
abort
(
FatalIOError
);
return
dynamic_cast
<
To
&>
(
r
);
}
}
//- Reference type cast template function.
// As per dynamicCast, but handles type names via the virtual type() method.
template
<
class
To
,
class
From
>
...
...
@@ -121,6 +142,27 @@ inline To& refCast(From& r)
}
//- Reference type cast template function.
// As per dynamicCast, but handles type names via the virtual type() method.
template
<
class
To
,
class
From
>
inline
To
&
refCast
(
From
&
r
,
const
dictionary
&
d
)
{
try
{
return
dynamic_cast
<
To
&>
(
r
);
}
catch
(
std
::
bad_cast
&
)
{
FatalIOErrorInFunction
(
d
)
<<
"Attempt to cast type "
<<
r
.
type
()
<<
" to type "
<<
To
::
typeName
<<
abort
(
FatalIOError
);
return
dynamic_cast
<
To
&>
(
r
);
}
}
//- Check the typeid
template
<
class
TestType
,
class
Type
>
inline
bool
isType
(
const
Type
&
t
)
...
...
src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C
View file @
8aa7b135
...
...
@@ -51,7 +51,7 @@ Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
)
:
coupledPointPatchField
<
Type
>
(
p
,
iF
,
dict
),
cyclicPatch_
(
refCast
<
const
cyclicPointPatch
>
(
p
))
cyclicPatch_
(
refCast
<
const
cyclicPointPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
cyclicPointPatch
>
(
p
))
{
...
...
src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C
View file @
8aa7b135
...
...
@@ -49,7 +49,7 @@ Foam::processorPointPatchField<Type>::processorPointPatchField
)
:
coupledPointPatchField
<
Type
>
(
p
,
iF
,
dict
),
procPatch_
(
refCast
<
const
processorPointPatch
>
(
p
))
procPatch_
(
refCast
<
const
processorPointPatch
>
(
p
,
dict
))
{}
...
...
src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C
View file @
8aa7b135
...
...
@@ -52,7 +52,7 @@ Foam::processorCyclicPointPatchField<Type>::processorCyclicPointPatchField
)
:
coupledPointPatchField
<
Type
>
(
p
,
iF
,
dict
),
procPatch_
(
refCast
<
const
processorCyclicPointPatch
>
(
p
)),
procPatch_
(
refCast
<
const
processorCyclicPointPatch
>
(
p
,
dict
)),
receiveBuf_
(
0
)
{}
...
...
src/OpenFOAM/fields/pointPatchFields/constraint/symmetryPlane/symmetryPlanePointPatchField.C
View file @
8aa7b135
...
...
@@ -48,7 +48,7 @@ Foam::symmetryPlanePointPatchField<Type>::symmetryPlanePointPatchField
)
:
basicSymmetryPointPatchField
<
Type
>
(
p
,
iF
,
dict
),
symmetryPlanePatch_
(
refCast
<
const
symmetryPlanePointPatch
>
(
p
))
symmetryPlanePatch_
(
refCast
<
const
symmetryPlanePointPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
symmetryPlanePointPatch
>
(
p
))
{
...
...
src/finiteArea/fields/faPatchFields/basic/coupled/coupledFaPatchField.C
View file @
8aa7b135
...
...
@@ -76,7 +76,7 @@ Foam::coupledFaPatchField<Type>::coupledFaPatchField
const
dictionary
&
dict
)
:
lduInterfaceField
(
refCast
<
const
lduInterface
>
(
p
)),
lduInterfaceField
(
refCast
<
const
lduInterface
>
(
p
,
dict
)),
faPatchField
<
Type
>
(
p
,
iF
,
dict
)
{}
...
...
src/finiteArea/fields/faPatchFields/constraint/cyclic/cyclicFaPatchField.C
View file @
8aa7b135
...
...
@@ -75,7 +75,7 @@ Foam::cyclicFaPatchField<Type>::cyclicFaPatchField
)
:
coupledFaPatchField
<
Type
>
(
p
,
iF
,
dict
),
cyclicPatch_
(
refCast
<
const
cyclicFaPatch
>
(
p
))
cyclicPatch_
(
refCast
<
const
cyclicFaPatch
>
(
p
,
dict
))
{
if
(
!
isA
<
cyclicFaPatch
>
(
p
))
{
...
...
src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C
View file @
8aa7b135
...
...
@@ -92,7 +92,7 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
)
:
coupledFaPatchField
<
Type
>
(
p
,
iF
,
dict
),
procPatch_
(
refCast
<
const
processorFaPatch
>
(
p
))
procPatch_
(
refCast
<
const
processorFaPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
processorFaPatch
>
(
p
))
{
...
...
src/finiteArea/fields/faePatchFields/constraint/cyclic/cyclicFaePatchField.C
View file @
8aa7b135
...
...
@@ -74,7 +74,7 @@ Foam::cyclicFaePatchField<Type>::cyclicFaePatchField
)
:
coupledFaePatchField
<
Type
>
(
p
,
iF
,
dict
),
cyclicPatch_
(
refCast
<
const
cyclicFaPatch
>
(
p
))
cyclicPatch_
(
refCast
<
const
cyclicFaPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
cyclicFaPatch
>
(
p
))
{
...
...
src/finiteArea/fields/faePatchFields/constraint/processor/processorFaePatchField.C
View file @
8aa7b135
...
...
@@ -87,7 +87,7 @@ Foam::processorFaePatchField<Type>::processorFaePatchField
)
:
coupledFaePatchField
<
Type
>
(
p
,
iF
,
dict
),
procPatch_
(
refCast
<
const
processorFaPatch
>
(
p
))
procPatch_
(
refCast
<
const
processorFaPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
processorFaPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/basic/coupled/coupledFvPatchField.C
View file @
8aa7b135
...
...
@@ -75,7 +75,7 @@ Foam::coupledFvPatchField<Type>::coupledFvPatchField
const
bool
valueRequired
)
:
LduInterfaceField
<
Type
>
(
refCast
<
const
lduInterface
>
(
p
)),
LduInterfaceField
<
Type
>
(
refCast
<
const
lduInterface
>
(
p
,
dict
)),
fvPatchField
<
Type
>
(
p
,
iF
,
dict
,
valueRequired
)
{}
...
...
src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C
View file @
8aa7b135
...
...
@@ -49,7 +49,7 @@ Foam::cyclicFvPatchField<Type>::cyclicFvPatchField
)
:
coupledFvPatchField
<
Type
>
(
p
,
iF
,
dict
,
false
),
cyclicPatch_
(
refCast
<
const
cyclicFvPatch
>
(
p
))
cyclicPatch_
(
refCast
<
const
cyclicFvPatch
>
(
p
,
dict
))
{
if
(
!
isA
<
cyclicFvPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C
View file @
8aa7b135
...
...
@@ -51,7 +51,7 @@ Foam::cyclicACMIFvPatchField<Type>::cyclicACMIFvPatchField
:
cyclicACMILduInterfaceField
(),
coupledFvPatchField
<
Type
>
(
p
,
iF
,
dict
,
dict
.
found
(
"value"
)),
cyclicACMIPatch_
(
refCast
<
const
cyclicACMIFvPatch
>
(
p
))
cyclicACMIPatch_
(
refCast
<
const
cyclicACMIFvPatch
>
(
p
,
dict
))
{
if
(
!
isA
<
cyclicACMIFvPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/constraint/cyclicAMI/cyclicAMIFvPatchField.C
View file @
8aa7b135
...
...
@@ -48,7 +48,7 @@ Foam::cyclicAMIFvPatchField<Type>::cyclicAMIFvPatchField
:
cyclicAMILduInterfaceField
(),
coupledFvPatchField
<
Type
>
(
p
,
iF
,
dict
,
dict
.
found
(
"value"
)),
cyclicAMIPatch_
(
refCast
<
const
cyclicAMIFvPatch
>
(
p
))
cyclicAMIPatch_
(
refCast
<
const
cyclicAMIFvPatch
>
(
p
,
dict
))
{
if
(
!
isA
<
cyclicAMIFvPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
View file @
8aa7b135
...
...
@@ -76,7 +76,7 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
)
:
coupledFvPatchField
<
Type
>
(
p
,
iF
,
dict
,
dict
.
found
(
"value"
)),
procPatch_
(
refCast
<
const
processorFvPatch
>
(
p
)),
procPatch_
(
refCast
<
const
processorFvPatch
>
(
p
,
dict
)),
sendBuf_
(
0
),
receiveBuf_
(
0
),
outstandingSendRequest_
(
-
1
),
...
...
src/finiteVolume/fields/fvPatchFields/constraint/processorCyclic/processorCyclicFvPatchField.C
View file @
8aa7b135
...
...
@@ -51,7 +51,7 @@ Foam::processorCyclicFvPatchField<Type>::processorCyclicFvPatchField
)
:
processorFvPatchField
<
Type
>
(
p
,
iF
,
dict
),
procPatch_
(
refCast
<
const
processorCyclicFvPatch
>
(
p
))
procPatch_
(
refCast
<
const
processorCyclicFvPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
processorCyclicFvPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C
View file @
8aa7b135
...
...
@@ -73,7 +73,7 @@ Foam::symmetryPlaneFvPatchField<Type>::symmetryPlaneFvPatchField
)
:
basicSymmetryFvPatchField
<
Type
>
(
p
,
iF
,
dict
),
symmetryPlanePatch_
(
refCast
<
const
symmetryPlaneFvPatch
>
(
p
))
symmetryPlanePatch_
(
refCast
<
const
symmetryPlaneFvPatch
>
(
p
,
dict
))
{
if
(
!
isType
<
symmetryPlaneFvPatch
>
(
p
))
{
...
...
src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
View file @
8aa7b135
...
...
@@ -96,7 +96,8 @@ activeBaffleVelocityFvPatchVectorField
(
refCast
<
const
cyclicFvPatch
>
(
p
.
boundaryMesh
()[
cyclicPatchLabel_
]
p
.
boundaryMesh
()[
cyclicPatchLabel_
],
dict
).
neighbFvPatch
().
Sf
()
),
openFraction_
(
readScalar
(
dict
.
lookup
(
"openFraction"
))),
...
...
src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C
View file @
8aa7b135
...
...
@@ -115,7 +115,8 @@ activePressureForceBaffleVelocityFvPatchVectorField
initCyclicSf_
=
p
.
boundaryMesh
()[
cyclicPatchLabel_
].
Sf
();
nbrCyclicSf_
=
refCast
<
const
cyclicFvPatch
>
(
p
.
boundaryMesh
()[
cyclicPatchLabel_
]
p
.
boundaryMesh
()[
cyclicPatchLabel_
],
dict
).
neighbFvPatch
().
Sf
();
}
...
...
src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C
View file @
8aa7b135
...
...
@@ -94,7 +94,8 @@ mappedVelocityFluxFixedValueFvPatchField
const
mappedPatchBase
&
mpp
=
refCast
<
const
mappedPatchBase
>
(
this
->
patch
().
patch
()
this
->
patch
().
patch
(),
dict
);
if
(
mpp
.
mode
()
==
mappedPolyPatch
::
NEARESTCELL
)
{
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment