From 3fc2ec183d6d4f0db67662c2afc60e34e89053ed Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 20 Jun 2016 20:57:47 +0100 Subject: [PATCH] ENH: potentialFoam: construct Phi with only types() so does not work for initialising 'complex' bcs. Instead now 'clone' from p. Fixes #153. --- .../basic/potentialFoam/createFields.H | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/applications/solvers/basic/potentialFoam/createFields.H b/applications/solvers/basic/potentialFoam/createFields.H index faad238312..af0adfd8f9 100644 --- a/applications/solvers/basic/potentialFoam/createFields.H +++ b/applications/solvers/basic/potentialFoam/createFields.H @@ -93,21 +93,48 @@ if (args.optionFound("writep")) Info<< "Constructing velocity potential field Phi\n" << endl; -volScalarField Phi +autoPtr PhiPtr; + +IOobject io ( - IOobject - ( - "Phi", - runTime.timeName(), - mesh, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE - ), + "Phi", + runTime.timeName(), mesh, - dimensionedScalar("Phi", dimLength*dimVelocity, 0), - p.boundaryField().types() + IOobject::MUST_READ, + IOobject::NO_WRITE ); +if (io.typeHeaderOk()) +{ + PhiPtr.reset(new volScalarField(io, mesh)); +} +else +{ + // Cannot just use p.boundaryField().types() since does not initialise + // complex boundary types. Instead re-clone them from p. + + io.readOpt() = IOobject::NO_READ; + PhiPtr.reset + ( + new volScalarField + ( + io, + mesh, + dimensionedScalar("Phi", dimLength*dimVelocity, 0), + p.boundaryField().types() + ) + ); + + const volScalarField::GeometricBoundaryField& bp = p.boundaryField(); + volScalarField::GeometricBoundaryField& bPhi = PhiPtr().boundaryField(); + + forAll(bp, patchI) + { + bPhi.set(patchI, bp[patchI].clone(PhiPtr().dimensionedInternalField())); + } +} +volScalarField& Phi = PhiPtr(); + label PhiRefCell = 0; scalar PhiRefValue = 0; setRefCell