From af228db90a34fce83404cd154828c124df5f48c8 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 3 Aug 2011 12:00:26 +0100 Subject: [PATCH] Graceful exit when a field is not found --- .../preProcessing/setFields/setFields.C | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/applications/utilities/preProcessing/setFields/setFields.C b/applications/utilities/preProcessing/setFields/setFields.C index 38133bd05..bc8996a55 100644 --- a/applications/utilities/preProcessing/setFields/setFields.C +++ b/applications/utilities/preProcessing/setFields/setFields.C @@ -45,8 +45,18 @@ void setFieldType Istream& fieldValueStream ) { + // Read field and value together; otherwise there will be an input error + // when a field is not found. HJ, 3/Aug/2011 word fieldName(fieldValueStream); + typename GeoField::value_type value + ( + static_cast + ( + pTraits(fieldValueStream) + ) + ); + IOobject fieldHeader ( fieldName, @@ -63,27 +73,19 @@ void setFieldType GeoField field(fieldHeader, mesh); - typename GeoField::value_type value - ( - static_cast - ( - pTraits(fieldValueStream) - ) - ); - if (selectedCells.size() == field.size()) { field.internalField() = value; } else { - forAll(selectedCells, celli) + forAll (selectedCells, celli) { field[selectedCells[celli]] = value; } } - forAll(field.boundaryField(), patchi) + forAll (field.boundaryField(), patchi) { // Forced patch assignment. HJ, 1/Aug/2010 field.boundaryField()[patchi] == @@ -216,7 +218,7 @@ int main(int argc, char *argv[]) PtrList regions(setFieldsDict.lookup("regions")); - forAll(regions, regionI) + forAll (regions, regionI) { const entry& region = regions[regionI];