From 00ac073e172f8448eb65eafb0ec805fac5c8ffff Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 14 Dec 2016 13:00:14 +0000 Subject: [PATCH] ENH: fvMotionSolvers: added solidBodyDisplacementLaplacian Applies a displacementLaplacian on top of a solid-body motion function --- src/fvMotionSolver/Make/files | 1 + ...dBodyDisplacementLaplacianFvMotionSolver.C | 371 ++++++++++++++++++ ...dBodyDisplacementLaplacianFvMotionSolver.H | 155 ++++++++ 3 files changed, 527 insertions(+) create mode 100644 src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.C create mode 100644 src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.H diff --git a/src/fvMotionSolver/Make/files b/src/fvMotionSolver/Make/files index 550af29faa..3f43482922 100644 --- a/src/fvMotionSolver/Make/files +++ b/src/fvMotionSolver/Make/files @@ -2,6 +2,7 @@ fvMotionSolvers/fvMotionSolver/fvMotionSolver.C fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C fvMotionSolvers/displacement/surfaceAlignedSBRStress/surfaceAlignedSBRStressFvMotionSolver.C +fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.C fvMotionSolvers/componentDisplacement/componentLaplacian/displacementComponentLaplacianFvMotionSolver.C fvMotionSolvers/velocity/laplacian/velocityLaplacianFvMotionSolver.C diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.C new file mode 100644 index 0000000000..277593506b --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.C @@ -0,0 +1,371 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "solidBodyDisplacementLaplacianFvMotionSolver.H" +#include "motionInterpolation.H" +#include "motionDiffusivity.H" +#include "fvmLaplacian.H" +#include "addToRunTimeSelectionTable.H" +#include "OFstream.H" +#include "meshTools.H" +#include "mapPolyMesh.H" +#include "solidBodyMotionFunction.H" +#include "transformField.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(solidBodyDisplacementLaplacianFvMotionSolver, 0); + + addToRunTimeSelectionTable + ( + motionSolver, + solidBodyDisplacementLaplacianFvMotionSolver, + dictionary + ); + + addToRunTimeSelectionTable + ( + displacementMotionSolver, + solidBodyDisplacementLaplacianFvMotionSolver, + displacement + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::solidBodyDisplacementLaplacianFvMotionSolver:: +solidBodyDisplacementLaplacianFvMotionSolver +( + const polyMesh& mesh, + const IOdictionary& dict +) +: + displacementMotionSolver(mesh, dict, typeName), + fvMotionSolver(mesh), + SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())), + cellDisplacement_ + ( + IOobject + ( + "cellDisplacement", + mesh.time().timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvMesh_, + dimensionedVector + ( + "cellDisplacement", + pointDisplacement_.dimensions(), + Zero + ), + cellMotionBoundaryTypes(pointDisplacement_.boundaryField()) + ), + pointLocation_(nullptr), + interpolationPtr_ + ( + coeffDict().found("interpolation") + ? motionInterpolation::New(fvMesh_, coeffDict().lookup("interpolation")) + : motionInterpolation::New(fvMesh_) + ), + diffusivityPtr_ + ( + motionDiffusivity::New(fvMesh_, coeffDict().lookup("diffusivity")) + ), + frozenPointsZone_ + ( + coeffDict().found("frozenPointsZone") + ? fvMesh_.pointZones().findZoneID(coeffDict().lookup("frozenPointsZone")) + : -1 + ) +{ + IOobject io + ( + "pointLocation", + fvMesh_.time().timeName(), + fvMesh_, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ); + + if (debug) + { + Info<< "solidBodyDisplacementLaplacianFvMotionSolver:" << nl + << " diffusivity : " << diffusivityPtr_().type() << nl + << " frozenPoints zone : " << frozenPointsZone_ << endl; + } + + + if (io.typeHeaderOk(true)) + { + pointLocation_.reset + ( + new pointVectorField + ( + io, + pointMesh::New(fvMesh_) + ) + ); + + if (debug) + { + Info<< "solidBodyDisplacementLaplacianFvMotionSolver :" + << " Read pointVectorField " + << io.name() + << " to be used for boundary conditions on points." + << nl + << "Boundary conditions:" + << pointLocation_().boundaryField().types() << endl; + } + } +} + + +Foam::solidBodyDisplacementLaplacianFvMotionSolver:: +solidBodyDisplacementLaplacianFvMotionSolver +( + const polyMesh& mesh, + const IOdictionary& dict, + const pointVectorField& pointDisplacement, + const pointIOField& points0 +) +: + displacementMotionSolver(mesh, dict, pointDisplacement, points0, typeName), + fvMotionSolver(mesh), + SBMFPtr_(solidBodyMotionFunction::New(coeffDict(), mesh.time())), + cellDisplacement_ + ( + IOobject + ( + "cellDisplacement", + mesh.time().timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + fvMesh_, + dimensionedVector + ( + "cellDisplacement", + pointDisplacement_.dimensions(), + Zero + ), + cellMotionBoundaryTypes(pointDisplacement_.boundaryField()) + ), + pointLocation_(nullptr), + interpolationPtr_ + ( + coeffDict().found("interpolation") + ? motionInterpolation::New(fvMesh_, coeffDict().lookup("interpolation")) + : motionInterpolation::New(fvMesh_) + ), + diffusivityPtr_ + ( + motionDiffusivity::New(fvMesh_, coeffDict().lookup("diffusivity")) + ), + frozenPointsZone_ + ( + coeffDict().found("frozenPointsZone") + ? fvMesh_.pointZones().findZoneID(coeffDict().lookup("frozenPointsZone")) + : -1 + ) +{ + IOobject io + ( + "pointLocation", + fvMesh_.time().timeName(), + fvMesh_, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ); + + if (debug) + { + Info<< "solidBodyDisplacementLaplacianFvMotionSolver:" << nl + << " diffusivity : " << diffusivityPtr_().type() << nl + << " frozenPoints zone : " << frozenPointsZone_ << endl; + } + + + if (io.typeHeaderOk(true)) + { + pointLocation_.reset + ( + new pointVectorField + ( + io, + pointMesh::New(fvMesh_) + ) + ); + + if (debug) + { + Info<< "solidBodyDisplacementLaplacianFvMotionSolver :" + << " Read pointVectorField " + << io.name() + << " to be used for boundary conditions on points." + << nl + << "Boundary conditions:" + << pointLocation_().boundaryField().types() << endl; + } + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::solidBodyDisplacementLaplacianFvMotionSolver:: +~solidBodyDisplacementLaplacianFvMotionSolver() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::motionDiffusivity& +Foam::solidBodyDisplacementLaplacianFvMotionSolver::diffusivity() +{ + if (!diffusivityPtr_.valid()) + { + diffusivityPtr_ = motionDiffusivity::New + ( + fvMesh_, + coeffDict().lookup("diffusivity") + ); + } + return diffusivityPtr_(); +} + + +Foam::tmp +Foam::solidBodyDisplacementLaplacianFvMotionSolver::curPoints() const +{ + interpolationPtr_->interpolate + ( + cellDisplacement_, + pointDisplacement_ + ); + + tmp tnewPoints + ( + transformPoints(SBMFPtr_().transformation(), points0()) + ); + const pointField& newPoints = tnewPoints(); + + if (pointLocation_.valid()) + { + if (debug) + { + Info<< "solidBodyDisplacementLaplacianFvMotionSolver : applying " + << " boundary conditions on " << pointLocation_().name() + << " to new point location." + << endl; + } + + pointLocation_().primitiveFieldRef() = + newPoints + + pointDisplacement_.internalField(); + + pointLocation_().correctBoundaryConditions(); + + // Implement frozen points + if (frozenPointsZone_ != -1) + { + const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_]; + + forAll(pz, i) + { + pointLocation_()[pz[i]] = newPoints[pz[i]]; + } + } + + twoDCorrectPoints(pointLocation_().primitiveFieldRef()); + + return tmp(pointLocation_().primitiveField()); + } + else + { + tmp tcurPoints + ( + newPoints + pointDisplacement_.primitiveField() + ); + pointField& curPoints = tcurPoints.ref(); + + // Implement frozen points + if (frozenPointsZone_ != -1) + { + const pointZone& pz = fvMesh_.pointZones()[frozenPointsZone_]; + + forAll(pz, i) + { + curPoints[pz[i]] = newPoints[pz[i]]; + } + } + + twoDCorrectPoints(curPoints); + + return tcurPoints; + } +} + + +void Foam::solidBodyDisplacementLaplacianFvMotionSolver::solve() +{ + // The points have moved so before interpolation update + // the motionSolver accordingly + movePoints(fvMesh_.points()); + + diffusivity().correct(); + pointDisplacement_.boundaryFieldRef().updateCoeffs(); + + Foam::solve + ( + fvm::laplacian + ( + diffusivity().operator()(), + cellDisplacement_, + "laplacian(diffusivity,cellDisplacement)" + ) + ); +} + + +void Foam::solidBodyDisplacementLaplacianFvMotionSolver::updateMesh +( + const mapPolyMesh& mpm +) +{ + displacementMotionSolver::updateMesh(mpm); + + // Update diffusivity. Note two stage to make sure old one is de-registered + // before creating/registering new one. + diffusivityPtr_.clear(); +} + + +// ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.H new file mode 100644 index 0000000000..2f768b51f7 --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/solidBodyDisplacementLaplacian/solidBodyDisplacementLaplacianFvMotionSolver.H @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::solidBodyDisplacementLaplacianFvMotionSolver + +Group + grpMeshMotionSolvers + +Description + Applies Laplacian displacement solving on top of a transformation of + the initial points using a solid-body motion. + +See also + Foam::displacementLaplacian + +SourceFiles + solidBodyDisplacementLaplacianFvMotionSolver.C + +\*---------------------------------------------------------------------------*/ + +#ifndef solidBodyDisplacementLaplacianFvMotionSolver_H +#define solidBodyDisplacementLaplacianFvMotionSolver_H + +#include "displacementMotionSolver.H" +#include "fvMotionSolver.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward class declarations +class motionInterpolation; +class motionDiffusivity; +class solidBodyMotionFunction; + +/*---------------------------------------------------------------------------*\ + Class solidBodyDisplacementLaplacianFvMotionSolver Declaration +\*---------------------------------------------------------------------------*/ + +class solidBodyDisplacementLaplacianFvMotionSolver +: + public displacementMotionSolver, + public fvMotionSolver +{ + // Private data + + //- Motion function + autoPtr SBMFPtr_; + + //- Cell-centre motion field + mutable volVectorField cellDisplacement_; + + //- Optionally read point-position field. Used only for position + // boundary conditions. + mutable autoPtr pointLocation_; + + //- Interpolation used to transfer cell displacement to the points + autoPtr interpolationPtr_; + + //- Diffusivity used to control the motion + autoPtr diffusivityPtr_; + + //- Frozen points (that are not on patches). -1 or points that are + // fixed to be at points0_ location + label frozenPointsZone_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + solidBodyDisplacementLaplacianFvMotionSolver + ( + const solidBodyDisplacementLaplacianFvMotionSolver& + ); + + //- Disallow default bitwise assignment + void operator=(const solidBodyDisplacementLaplacianFvMotionSolver&); + + +public: + + //- Runtime type information + TypeName("solidBodyDisplacementLaplacian"); + + + // Constructors + + //- Construct from polyMesh and IOdictionary + solidBodyDisplacementLaplacianFvMotionSolver + ( + const polyMesh&, + const IOdictionary& + ); + + //- Construct from components + solidBodyDisplacementLaplacianFvMotionSolver + ( + const polyMesh& mesh, + const IOdictionary& dict, + const pointVectorField& pointDisplacement, + const pointIOField& points0 + ); + + + //- Destructor + ~solidBodyDisplacementLaplacianFvMotionSolver(); + + + // Member Functions + + //- Return reference to the diffusivity field + motionDiffusivity& diffusivity(); + + //- Return point location obtained from the current motion field + virtual tmp curPoints() const; + + //- Solve for motion + virtual void solve(); + + //- Update topology + virtual void updateMesh(const mapPolyMesh&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //