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,338 +80,329 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
{
const keyType& key = dEntry.keyword();
if (key != "type" && key != "value")
if
(
key == "type"
|| key == "value"
|| !dEntry.isStream() || dEntry.stream().empty()
)
{
continue;
}
ITstream& is = dEntry.stream();
// Read first token
token firstToken(is);
if
(
firstToken.isWord()
&& firstToken.wordToken() == "nonuniform"
)
{
if
token fieldToken(is);
if (!fieldToken.isCompound())
{
if
(
fieldToken.isLabel()
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert(key, autoPtr<scalarField>::New());
}
else
{
FatalIOErrorInFunction(dict)
<< "\n token following 'nonuniform' "
"is not a compound"
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
else if
(
dEntry.isStream()
&& dEntry.stream().size()
fieldToken.compoundToken().type()
== token::Compound<List<scalar>>::typeName
)
{
ITstream& is = dEntry.stream();
auto fPtr = autoPtr<scalarField>::New();
// Read first token
token firstToken(is);
fPtr->transfer
(
dynamicCast<token::Compound<List<scalar>>>
(
fieldToken.transferCompoundToken(is)
)
);
if
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
scalarFields_.insert(key, fPtr);
}
else if
(
fieldToken.compoundToken().type()
== token::Compound<List<vector>>::typeName
)
{
auto fPtr = autoPtr<vectorField>::New();
fPtr->transfer
(
firstToken.isWord()
&& firstToken.wordToken() == "nonuniform"
)
dynamicCast<token::Compound<List<vector>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != patchSize)
{
token fieldToken(is);
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
if (!fieldToken.isCompound())
{
if
(
fieldToken.isLabel()
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
key,
autoPtr<scalarField>::New()
);
}
else
{
FatalIOErrorInFunction(dict)
<< "\n token following 'nonuniform' "
"is not a compound"
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
}
else if
vectorFields_.insert(key, fPtr);
}
else if
(
fieldToken.compoundToken().type()
== token::Compound<List<sphericalTensor>>::typeName
)
{
auto fPtr = autoPtr<sphericalTensorField>::New();
fPtr->transfer
(
dynamicCast<token::Compound<List<sphericalTensor>>>
(
fieldToken.compoundToken().type()
== token::Compound<List<scalar>>::typeName
fieldToken.transferCompoundToken(is)
)
{
auto fPtr = autoPtr<scalarField>::New();
);
fPtr->transfer
(
dynamicCast<token::Compound<List<scalar>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
scalarFields_.insert(key, fPtr);
}
else if
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
sphTensorFields_.insert(key, fPtr);
}
else if
(
fieldToken.compoundToken().type()
== token::Compound<List<symmTensor>>::typeName
)
{
auto fPtr = autoPtr<symmTensorField>::New();
fPtr->transfer
(
dynamicCast<token::Compound<List<symmTensor>>>
(
fieldToken.compoundToken().type()
== token::Compound<List<vector>>::typeName
fieldToken.transferCompoundToken(is)
)
{
auto fPtr = autoPtr<vectorField>::New();
);
fPtr->transfer
(
dynamicCast<token::Compound<List<vector>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
vectorFields_.insert(key, fPtr);
}
else if
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
symmTensorFields_.insert(key, fPtr);
}
else if
(
fieldToken.compoundToken().type()
== token::Compound<List<tensor>>::typeName
)
{
auto fPtr = autoPtr<tensorField>::New();
fPtr->transfer
(
dynamicCast<token::Compound<List<tensor>>>
(
fieldToken.compoundToken().type()
== token::Compound<List<sphericalTensor>>::typeName
fieldToken.transferCompoundToken(is)
)
{
auto fPtr = autoPtr<sphericalTensorField>::New();
);
fPtr->transfer
(
dynamicCast
<
token::Compound<List<sphericalTensor>>
>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
sphTensorFields_.insert(key, fPtr);
}
else if
if (fPtr->size() != patchSize)
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< patchSize << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
tensorFields_.insert(key, fPtr);
}
else
{
FatalIOErrorInFunction(dict)
<< "\n compound " << fieldToken.compoundToken()
<< " not supported"
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath() << nl
<< exit(FatalIOError);
}
}
else if
(
firstToken.isWord()
&& firstToken.wordToken() == "uniform"
)
{
token fieldToken(is);
if (!fieldToken.isPunctuation())
{
scalarFields_.insert
(
key,
autoPtr<scalarField>::New
(
fieldToken.compoundToken().type()
== token::Compound<List<symmTensor>>::typeName
patchSize,
fieldToken.number()
)
{
auto fPtr = autoPtr<symmTensorField>::New();
);
}
else
{
// Read as scalarList.
is.putBack(fieldToken);
scalarList l(is);
if (l.size() == vector::nComponents)
{
vector vs(l[0], l[1], l[2]);
fPtr->transfer
vectorFields_.insert
(
key,
autoPtr<vectorField>::New
(
dynamicCast
<
token::Compound<List<symmTensor>>
>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
symmTensorFields_.insert(key, fPtr);
}
else if
patchSize,
vs
)
);
}
else if (l.size() == sphericalTensor::nComponents)
{
sphericalTensor vs(l[0]);
sphTensorFields_.insert
(
fieldToken.compoundToken().type()
== token::Compound<List<tensor>>::typeName
)
{
auto fPtr = autoPtr<tensorField>::New();
key,
autoPtr<sphericalTensorField>::New
(
patchSize,
vs
)
);
}
else if (l.size() == symmTensor::nComponents)
{
symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
fPtr->transfer
symmTensorFields_.insert
(
key,
autoPtr<symmTensorField>::New
(
dynamicCast<token::Compound<List<tensor>>>
(
fieldToken.transferCompoundToken(is)
)
);
if (fPtr->size() != this->size())
{
FatalIOErrorInFunction(dict)
<< "\n size of field " << key
<< " (" << fPtr->size() << ')'
<< " is not the same size as the patch ("
<< this->size() << ')'
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
tensorFields_.insert(key, fPtr);
}
else
{
FatalIOErrorInFunction(dict)
<< "\n compound " << fieldToken.compoundToken()
<< " not supported"
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
patchSize,
vs
)
);
}
else if
(
firstToken.isWord()
&& firstToken.wordToken() == "uniform"
)
else if (l.size() == tensor::nComponents)
{
token fieldToken(is);
tensor vs
(
l[0], l[1], l[2],
l[3], l[4], l[5],
l[6], l[7], l[8]
);
if (!fieldToken.isPunctuation())
{
scalarFields_.insert
tensorFields_.insert
(
key,
autoPtr<tensorField>::New
(
key,
autoPtr<scalarField>::New
(
this->size(),
fieldToken.number()
)
);
}
else
{
// Read as scalarList.
is.putBack(fieldToken);
scalarList l(is);
if (l.size() == vector::nComponents)
{
vector vs(l[0], l[1], l[2]);
vectorFields_.insert
(
key,
autoPtr<vectorField>::New
(
this->size(),
vs
)