From ef69c12106d5bce13e2e9aa2e52387e11a1e1cf7 Mon Sep 17 00:00:00 2001 From: Vuko Vukcevic Date: Wed, 25 Apr 2018 13:29:14 +0200 Subject: [PATCH] Graded normal extrude model --- src/mesh/extrudeModel/Make/files | 1 + src/mesh/extrudeModel/Make/options | 6 +- .../extrudeModel/gradedNormal/gradedNormal.C | 143 ++++++++++++++++ .../extrudeModel/gradedNormal/gradedNormal.H | 158 ++++++++++++++++++ 4 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 src/mesh/extrudeModel/gradedNormal/gradedNormal.C create mode 100644 src/mesh/extrudeModel/gradedNormal/gradedNormal.H diff --git a/src/mesh/extrudeModel/Make/files b/src/mesh/extrudeModel/Make/files index c8d0cc571..8941cb004 100644 --- a/src/mesh/extrudeModel/Make/files +++ b/src/mesh/extrudeModel/Make/files @@ -1,6 +1,7 @@ extrudeModel/extrudeModel.C extrudeModel/newExtrudeModel.C linearNormal/linearNormal.C +gradedNormal/gradedNormal.C linearRadial/linearRadial.C sigmaRadial/sigmaRadial.C wedge/wedge.C diff --git a/src/mesh/extrudeModel/Make/options b/src/mesh/extrudeModel/Make/options index c0517d317..d402ac311 100644 --- a/src/mesh/extrudeModel/Make/options +++ b/src/mesh/extrudeModel/Make/options @@ -1,8 +1,10 @@ EXE_INC = \ -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/dynamicMesh/lnInclude + -I$(LIB_SRC)/dynamicMesh/lnInclude \ + -I$(LIB_SRC)/ODE/lnInclude LIB_LIBS = \ -lmeshTools \ - -ldynamicMesh + -ldynamicMesh \ + -lODE diff --git a/src/mesh/extrudeModel/gradedNormal/gradedNormal.C b/src/mesh/extrudeModel/gradedNormal/gradedNormal.C new file mode 100644 index 000000000..d2cb5c152 --- /dev/null +++ b/src/mesh/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 + 1); + } + + return surfacePoint + d*surfaceNormal; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace extrudeModels +} // End namespace Foam + +// ************************************************************************* // + diff --git a/src/mesh/extrudeModel/gradedNormal/gradedNormal.H b/src/mesh/extrudeModel/gradedNormal/gradedNormal.H new file mode 100644 index 000000000..bd2127bf0 --- /dev/null +++ b/src/mesh/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 + +// ************************************************************************* // +