diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C index 9ccaf089c0..f1ad35baae 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -778,6 +778,82 @@ void Foam::mappedPatchBase::calcAMI() const } +// Hack to read old (List-based) format. See Field.C. The difference +// is only that in case of falling back to old format it expects a non-uniform +// list instead of a single vector. +Foam::tmp Foam::mappedPatchBase::readListOrField +( + const word& keyword, + const dictionary& dict, + const label size +) +{ + tmp tfld(new pointField()); + pointField& fld = tfld(); + + if (size) + { + ITstream& is = dict.lookup(keyword); + + // Read first token + token firstToken(is); + + if (firstToken.isWord()) + { + if (firstToken.wordToken() == "uniform") + { + fld.setSize(size); + fld = pTraits(is); + } + else if (firstToken.wordToken() == "nonuniform") + { + is >> static_cast&>(fld); + if (fld.size() != size) + { + FatalIOErrorIn + ( + "mappedPatchBase::readListOrField" + "(const word& keyword, const dictionary&, const label)", + dict + ) << "size " << fld.size() + << " is not equal to the given value of " << size + << exit(FatalIOError); + } + } + else + { + FatalIOErrorIn + ( + "mappedPatchBase::readListOrField" + "(const word& keyword, const dictionary&, const label)", + dict + ) << "expected keyword 'uniform' or 'nonuniform', found " + << firstToken.wordToken() + << exit(FatalIOError); + } + } + else + { + if (is.version() == 2.0) + { + IOWarningIn + ( + "mappedPatchBase::readListOrField" + "(const word& keyword, const dictionary&, const label)", + dict + ) << "expected keyword 'uniform' or 'nonuniform', " + "assuming List format for backwards compatibility." + "Foam version 2.0." << endl; + + is.putBack(firstToken); + is >> static_cast&>(fld); + } + } + } + return tfld; +} + + // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * // Foam::mappedPatchBase::mappedPatchBase @@ -922,7 +998,8 @@ Foam::mappedPatchBase::mappedPatchBase case NONUNIFORM: { - offsets_ = pointField(dict.lookup("offsets")); + //offsets_ = pointField(dict.lookup("offsets")); + offsets_ = readListOrField("offsets", dict, patch_.size()); } break; @@ -941,7 +1018,8 @@ Foam::mappedPatchBase::mappedPatchBase else if (dict.found("offsets")) { offsetMode_ = NONUNIFORM; - offsets_ = pointField(dict.lookup("offsets")); + //offsets_ = pointField(dict.lookup("offsets")); + offsets_ = readListOrField("offsets", dict, patch_.size()); } else { @@ -1196,8 +1274,7 @@ void Foam::mappedPatchBase::write(Ostream& os) const } case NONUNIFORM: { - os.writeKeyword("offsets") << offsets_ << token::END_STATEMENT - << nl; + offsets_.writeEntry("offsets", os); break; } case NORMAL: diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index d5f6743edb..96d7958528 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -236,6 +236,13 @@ protected: //- Calculate AMI interpolator void calcAMI() const; + //- Helper to read field or non-uniform list from dictionary + static tmp readListOrField + ( + const word& keyword, + const dictionary& dict, + const label size + ); public: