Commit c53459d4 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

STYLE: simplify if nesting in generic patch fields (#1269)

- use git show/diff -w when viewing
parent 93914423
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -59,19 +59,20 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
if (!dict.found("value"))
{
FatalIOErrorInFunction(dict)
<< "\n Cannot find 'value' entry"
<< nl << " Cannot find 'value' entry"
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl
<< " in file " << this->internalField().objectPath() << nl
<< " which is required to set the"
" values of the generic patch field." << nl
<< " (Actual type " << actualTypeName_ << ")" << nl
<< "\n Please add the 'value' entry to the write function "
"of the user-defined boundary-condition\n"
<< " (Actual type " << actualTypeName_ << ')' << nl << nl
<< " Please add the 'value' entry to the write function"
" of the user-defined boundary-condition" << nl
<< exit(FatalIOError);
}
......@@ -79,14 +80,17 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
......@@ -108,11 +112,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
key,
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
......@@ -123,7 +123,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
......@@ -143,18 +143,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -176,18 +176,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -203,27 +203,24 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -239,27 +236,24 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -281,18 +275,18 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -307,7 +301,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
......@@ -326,7 +320,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<scalarField>::New
(
this->size(),
patchSize,
fieldToken.number()
)
);
......@@ -347,7 +341,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<vectorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -361,7 +355,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<sphericalTensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -375,7 +369,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<symmTensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -394,7 +388,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
key,
autoPtr<tensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -407,14 +401,12 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}
}
}
}
......@@ -707,9 +699,11 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
if (key == "type" || key == "value")
{
if
continue;
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
......@@ -719,28 +713,23 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
{
if (scalarFields_.found(key))
{
scalarFields_.find(key)()
->writeEntry(key, os);
scalarFields_.cfind(key)()->writeEntry(key, os);
}
else if (vectorFields_.found(key))
{
vectorFields_.find(key)()
->writeEntry(key, os);
vectorFields_.cfind(key)()->writeEntry(key, os);
}
else if (sphTensorFields_.found(key))
{
sphTensorFields_.find(key)()
->writeEntry(key, os);
sphTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (symmTensorFields_.found(key))
{
symmTensorFields_.find(key)()
->writeEntry(key, os);
symmTensorFields_.cfind(key)()->writeEntry(key, os);
}
else if (tensorFields_.found(key))
{
tensorFields_.find(key)()
->writeEntry(key, os);
tensorFields_.cfind(key)()->writeEntry(key, os);
}
}
else
......@@ -748,7 +737,6 @@ void Foam::genericFaPatchField<Type>::write(Ostream& os) const
dEntry.write(os);
}
}
}
this->writeEntry("value", os);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -56,22 +56,23 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
:
calculatedFvPatchField<Type>(p, iF, dict),
actualTypeName_(dict.lookup("type")),
actualTypeName_(dict.get<word>("type")),
dict_(dict)
{
const label patchSize = this->size();
if (!dict.found("value"))
{
FatalIOErrorInFunction(dict)
<< "\n Cannot find 'value' entry"
<< nl << " Cannot find 'value' entry"
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl
<< " in file " << this->internalField().objectPath() << nl
<< " which is required to set the"
" values of the generic patch field." << nl
<< " (Actual type " << actualTypeName_ << ")" << nl
<< "\n Please add the 'value' entry to the write function "
"of the user-defined boundary-condition\n"
<< " (Actual type " << actualTypeName_ << ')' << nl << nl
<< " Please add the 'value' entry to the write function"
" of the user-defined boundary-condition" << nl
<< exit(FatalIOError);
}
......@@ -79,14 +80,17 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
{
if
(
dEntry.isStream()
&& dEntry.stream().size()
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
......@@ -108,11 +112,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
dEntry.keyword(),
autoPtr<scalarField>::New()
);
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
......@@ -123,7 +123,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
......@@ -143,18 +143,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -176,18 +176,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -203,27 +203,24 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -239,27 +236,24 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
fPtr->transfer
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -281,18 +275,18 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
)
);
if (fPtr->size() != this->size())
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
......@@ -307,7 +301,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
......@@ -326,7 +320,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<scalarField>::New
(
this->size(),
patchSize,
fieldToken.number()
)
);
......@@ -347,7 +341,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<vectorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -361,7 +355,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<sphericalTensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -375,7 +369,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<symmTensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -394,7 +388,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
key,
autoPtr<tensorField>::New
(
this->size(),
patchSize,
vs
)
);
......@@ -407,14 +401,12 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
}
}