diff --git a/applications/utilities/mesh/advanced/runDynamicMesh/Make/files b/applications/utilities/mesh/advanced/runDynamicMesh/Make/files new file mode 100644 index 000000000..55ca1fb38 --- /dev/null +++ b/applications/utilities/mesh/advanced/runDynamicMesh/Make/files @@ -0,0 +1,3 @@ +runDynamicMesh.C + +EXE = $(FOAM_APPBIN)/runDynamicMesh diff --git a/applications/utilities/mesh/advanced/runDynamicMesh/Make/options b/applications/utilities/mesh/advanced/runDynamicMesh/Make/options new file mode 100644 index 000000000..9bb9fdd78 --- /dev/null +++ b/applications/utilities/mesh/advanced/runDynamicMesh/Make/options @@ -0,0 +1,12 @@ +EXE_INC = \ + -I$(LIB_SRC)/dynamicMesh/dynamicFvMesh/lnInclude \ + -I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/finiteVolume/lnInclude + +EXE_LIBS = \ + -ldynamicFvMesh \ + -ldynamicMesh \ + -lmeshTools \ + -lfiniteVolume \ + -L$(MESQUITE_LIB_DIR) -lmesquite diff --git a/applications/utilities/mesh/advanced/runDynamicMesh/createFields.H b/applications/utilities/mesh/advanced/runDynamicMesh/createFields.H new file mode 100644 index 000000000..979389f96 --- /dev/null +++ b/applications/utilities/mesh/advanced/runDynamicMesh/createFields.H @@ -0,0 +1,13 @@ + Info<< "Reading field alpha\n" << endl; + volScalarField alpha + ( + IOobject + ( + "alpha", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); diff --git a/applications/utilities/mesh/advanced/runDynamicMesh/runDynamicMesh.C b/applications/utilities/mesh/advanced/runDynamicMesh/runDynamicMesh.C new file mode 100644 index 000000000..b4d50f036 --- /dev/null +++ b/applications/utilities/mesh/advanced/runDynamicMesh/runDynamicMesh.C @@ -0,0 +1,80 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Application + runDynamicMesh + +Description + Creates dynamicFvMesh and updates it in a time loop. Reads indicator field + alpha used for dynamic mesh refinement to trigger refinement in certain + areas. + +Author + Vuko Vukcevic, Wikki Ltd. All rights reserved. + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" +#include "dynamicFvMesh.H" +#include "simpleControl.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ +# include "setRootCase.H" +# include "createTime.H" +# include "createDynamicFvMesh.H" + + simpleControl simple(mesh); + +# include "createFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + Info<< "\nStarting time loop\n" << endl; + + while (simple.loop()) + { + Info<< "Time = " << runTime.timeName() << nl << endl; + + bool meshChanged = mesh.update(); + + // Write only if mesh has changed + if (meshChanged) + { + runTime.write(); + } + + Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" + << " ClockTime = " << runTime.elapsedClockTime() << " s" + << nl << endl; + } + + Info<< "End\n" << endl; + + return(0); +} + + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/files b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/files index c8d0cc571..abcfb8261 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/files +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/files @@ -4,6 +4,7 @@ linearNormal/linearNormal.C linearRadial/linearRadial.C sigmaRadial/sigmaRadial.C wedge/wedge.C +gradedNormal/gradedNormal.C LIB = $(FOAM_LIBBIN)/libextrudeModel diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/options b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/options index 3c57befe4..afc486fed 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/options +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/Make/options @@ -1,8 +1,9 @@ EXE_INC = \ -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/dynamicMesh/lnInclude + -I$(LIB_SRC)/dynamicMesh/lnInclude \ + -I$(LIB_SRC)/ODE/lnInclude EXE_LIBS = \ -lmeshTools \ - -ldynamicMesh - + -ldynamicMesh \ + -lODE diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.C new file mode 100644 index 000000000..37bb95212 --- /dev/null +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.C @@ -0,0 +1,143 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "gradedNormal.H" +#include "addToRunTimeSelectionTable.H" +#include "BisectionRoot.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace extrudeModels +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(gradedNormal, 0); + +addToRunTimeSelectionTable(extrudeModel, gradedNormal, dictionary); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +gradedNormal::gradedNormal(const dictionary& dict) +: + extrudeModel(typeName, dict), + thickness_(readScalar(coeffDict_.lookup("thickness"))), + delta0_(readScalar(coeffDict_.lookup("initialCellLength"))), + expansionFactor_(1.0) +{ + // Sanity checks + if (thickness_ <= SMALL) + { + FatalErrorIn("gradedNormal(const dictionary&)") + << "thickness should be positive: " << thickness_ + << exit(FatalError); + } + + if (delta0_ <= SMALL) + { + FatalErrorIn("gradedNormal(const dictionary&)") + << "initialCellLength should be positive: " << delta0_ + << exit(FatalError); + } + + const scalar maxExpFactor = + coeffDict_.lookupOrDefault("maxExpansionFactor", 3.0); + + if (maxExpFactor <= SMALL) + { + FatalErrorIn("gradedNormal(const dictionary&)") + << "maxExpansionFactor should be positive: " << maxExpFactor + << exit(FatalError); + } + + const scalar bisectionTol = + coeffDict_.lookupOrDefault("bisectionTol", 1e-5); + + if (bisectionTol <= SMALL) + { + FatalErrorIn("gradedNormal(const dictionary&)") + << "bisectionTolerance should be positive: " << bisectionTol + << exit(FatalError); + } + + // Create expansion factor equation represented as a function object + expansionFactorEqn eqn(*this); + + // Calculate the expansionFactor using the bisection algorithm with the + // default tolerance of 1e-5 + BisectionRoot rootFinder + ( + eqn, + bisectionTol + ); + + // Search for the root in [0, 3], where upper bound 3 is default + expansionFactor_ = rootFinder.root + ( + 0.0, + maxExpFactor + ); + + // Report the result + Info<< "Calculated expansion factor: " << expansionFactor_ << endl; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +gradedNormal::~gradedNormal() +{} + + +// * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * * // + +point gradedNormal::operator() +( + const point& surfacePoint, + const vector& surfaceNormal, + const label layer +) const +{ + scalar d = 0.0; + + for (label i = 0; i < layer; ++i) + { + d += delta0_*pow(expansionFactor_, i); + } + + return surfacePoint + d*surfaceNormal; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace extrudeModels +} // End namespace Foam + +// ************************************************************************* // + diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.H b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.H new file mode 100644 index 000000000..bd2127bf0 --- /dev/null +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/gradedNormal/gradedNormal.H @@ -0,0 +1,158 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::extrudeModels::gradedNormal + +Description + Extrudes by transforming points normal to the surface. Input parameters are: + 1. Extrusion thickness (in meters), + 2. Initial delta (in meters), + 3. Number of layers. + + Expansion factor is calculated numerically using bisection algorithm. + +Author + Vuko Vukcevic. FMENA Zagreb. All rights reserved. + +\*---------------------------------------------------------------------------*/ + +#ifndef gradedNormal_H +#define gradedNormal_H + +#include "point.H" +#include "extrudeModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace extrudeModels +{ + +/*---------------------------------------------------------------------------*\ + Class gradedNormal Declaration +\*---------------------------------------------------------------------------*/ + +class gradedNormal +: + public extrudeModel +{ + // Private data + + //- Layer thickness + scalar thickness_; + + //- Initial delta (cell size at the extruded patch) + scalar delta0_; + + //- Expansion factor + scalar expansionFactor_; + + + // Expansion factor equation (functor class used by BisectionRoot) + class expansionFactorEqn + { + // Private data + + //- Const reference to underlying gradedNormal model + const gradedNormal& gnm_; + + + public: + + //- Construct given gradedNormal model + explicit expansionFactorEqn(const gradedNormal& gnm) + : + gnm_(gnm) + {} + + + //- Function call operator + scalar operator()(const scalar& x) const + { + scalar result = gnm_.thickness(); + + for (label i = 0; i <= gnm_.nLayers(); ++i) + { + result -= gnm_.delta0()*pow(x, i); + } + + return result; + } + }; + + +public: + + //- Runtime type information + TypeName("gradedNormal"); + + // Constructors + + //- Construct from components + gradedNormal(const dictionary& dict); + + + //- Destructor + ~gradedNormal(); + + + // Access functions + + //- Return const reference to thickness + const scalar& thickness() const + { + return thickness_; + } + + + //- Return const reference to initial delta + const scalar& delta0() const + { + return delta0_; + } + + + // Member Operators + + point operator() + ( + const point& surfacePoint, + const vector& surfaceNormal, + const label layer + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace extrudeModels +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // + diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C index 68c984865..015761d1b 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C @@ -103,6 +103,37 @@ bool domainDecomposition::writeDecomposition() label maxProcFaces = 0; + // Note: get cellLevel and pointLevel. Avoid checking whether they exist or + // not by hand. If they don't exist, simpy assume that the level is 0 + const labelIOList globalCellLevel + ( + IOobject + ( + "cellLevel", + this->facesInstance(), + polyMesh::meshSubDir, + *this, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + labelList(nCells(), 0) + ); + + const labelIOList globalPointLevel + ( + IOobject + ( + "pointLevel", + this->facesInstance(), + polyMesh::meshSubDir, + *this, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + labelList(nPoints(), 0) + ); + + // Write out the meshes for (label procI = 0; procI < nProcs_; procI++) { @@ -615,6 +646,39 @@ bool domainDecomposition::writeDecomposition() procBoundaryAddressing_[procI] ); boundaryProcAddressing.write(); + + // Create and write cellLevel and pointLevel information + const unallocLabelList& cellMap = cellProcAddressing; + labelIOList procCellLevel + ( + IOobject + ( + "cellLevel", + procMesh.facesInstance(), + procMesh.meshSubDir, + procMesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + labelList(globalCellLevel, cellMap) + ); + procCellLevel.write(); + + const unallocLabelList& pointMap = pointProcAddressing; + labelIOList procPointLevel + ( + IOobject + ( + "pointLevel", + procMesh.facesInstance(), + procMesh.meshSubDir, + procMesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + labelList(globalPointLevel, pointMap) + ); + procPointLevel.write(); } Info<< nl diff --git a/src/dynamicMesh/dynamicFvMesh/Make/files b/src/dynamicMesh/dynamicFvMesh/Make/files index 46aee8b5e..1e0932d17 100644 --- a/src/dynamicMesh/dynamicFvMesh/Make/files +++ b/src/dynamicMesh/dynamicFvMesh/Make/files @@ -10,6 +10,7 @@ dynamicMotionSolverFvMesh/dynamicMotionSolverFvMesh.C subsetMotionSolverFvMesh/subsetMotionSolverFvMesh.C dynamicInkJetFvMesh/dynamicInkJetFvMesh.C dynamicRefineFvMesh/dynamicRefineFvMesh.C +dynamicRefinePolyFvMesh/dynamicRefinePolyFvMesh.C mixerGgiFvMesh/mixerGgiFvMesh.C turboFvMesh/turboFvMesh.C diff --git a/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicMeshDict b/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicMeshDict new file mode 100644 index 000000000..b25b10d6e --- /dev/null +++ b/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicMeshDict @@ -0,0 +1,77 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | foam-extend: Open Source CFD | +| \\ / O peration | Version: 4.0 | +| \\ / A nd | Web: http://www.foam-extend.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object dynamicMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//dynamicFvMeshLib "libtopoChangerFvMesh.so"; +dynamicFvMesh dynamicRefinePolyFvMesh; +//staticFvMesh; + +mixerFvMeshCoeffs +{ + coordinateSystem + { + type cylindrical; + origin (0 0 0); + axis (0 0 1); + direction (1 0 0); + } + + rpm 10; + + slider + { + inside insideSlider; + outside outsideSlider; + } +} + +// Refinement +dynamicRefineFvMeshCoeffs +{ + // Refine every refineInterval timesteps + refineInterval 3; + + // Maximum refinement level (starts from 0) + maxRefinement 2; + + // Maximum cell limit (approximate) + maxCells 1000000; + + // volScalarField to base refinement on + field gamma; + + // Which cells to un/refine: based on point values (simple averaging). + // - refine pointCells of point value inbetween minLevel..maxLevel + // - unrefine pointCells that are within nBufferLayers of points marked + // for refinement. + minLevel 0.01; + maxLevel 0.99; + nBufferLayers 1; + + // Newly introduced patch points optionally get projected onto a surface + //projectSurfaces ("fixedWalls4.stl"); + //projectPatches (fixedWalls); + // Maximum project distance + //projectDistance 1; + + // Fluxes to adapt. For newly created faces or split faces the flux + // gets estimated from an interpolated volVectorField ('velocity') + // First is name of the flux to adapt, second is velocity that will + // be interpolated and inner-producted with the face area vector. + correctFluxes ((phi U)); +} + + +// ************************************************************************* // diff --git a/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicRefinePolyFvMesh.C b/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicRefinePolyFvMesh.C new file mode 100644 index 000000000..b7d966e01 --- /dev/null +++ b/src/dynamicMesh/dynamicFvMesh/dynamicRefinePolyFvMesh/dynamicRefinePolyFvMesh.C @@ -0,0 +1,1035 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "dynamicRefinePolyFvMesh.H" +#include "addToRunTimeSelectionTable.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "fvCFD.H" +#include "syncTools.H" +#include "pointFields.H" +#include "directTopoChange.H" +#include "cellSet.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(dynamicRefinePolyFvMesh, 0); + +addToRunTimeSelectionTable(dynamicFvMesh, dynamicRefinePolyFvMesh, IOobject); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +label dynamicRefinePolyFvMesh::count +( + const PackedBoolList& l, + const unsigned int val +) +{ + label n = 0; + forAll(l, i) + { + if (l.get(i) == val) + { + n++; + } + + // debug also serves to get-around Clang compiler trying to optimise + // out this forAll loop under O3 optimisation + + if (debug) + { + Info<< "n=" << n << endl; + } + } + + return n; +} + + +void dynamicRefinePolyFvMesh::readDict() +{ + dictionary refineDict + ( + IOdictionary + ( + IOobject + ( + "dynamicMeshDict", + time().constant(), + *this, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ).subDict(typeName + "Coeffs") + ); + + correctFluxes_ = List >(refineDict.lookup("correctFluxes")); + + dumpLevel_ = Switch(refineDict.lookup("dumpLevel")); +} + + +// Refines cells, maps fields and recalculates (an approximate) flux +autoPtr dynamicRefinePolyFvMesh::refine +( + const labelList& cellsToRefine +) +{ + // Mesh changing engine. + directTopoChange meshMod(*this); + + // Play refinement commands into mesh changer. + meshCutter_.setRefinement(cellsToRefine, meshMod); + + // Create mesh (with inflation), return map from old to new mesh. + //autoPtr map = meshMod.changeMesh(*this, true); + autoPtr map = meshMod.changeMesh(*this, false); + + Info<< "Refined from " + << returnReduce(map().nOldCells(), sumOp