|
| 1 | +/*---------------------------------------------------------------------------*\ |
| 2 | + ========= | |
| 3 | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| 4 | + \\ / O peration | Website: https://openfoam.org |
| 5 | + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation |
| 6 | + \\/ M anipulation | |
| 7 | +------------------------------------------------------------------------------- |
| 8 | +License |
| 9 | + This file is originating from OpenFOAM and modified by the |
| 10 | + authors described below. |
| 11 | +
|
| 12 | + OpenFOAM is free software: you can redistribute it and/or modify it |
| 13 | + under the terms of the GNU General Public License as published by |
| 14 | + the Free Software Foundation, either version 3 of the License, or |
| 15 | + (at your option) any later version. |
| 16 | +
|
| 17 | + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT |
| 18 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 19 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 20 | + for more details. |
| 21 | +
|
| 22 | + You should have received a copy of the GNU General Public License |
| 23 | + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. |
| 24 | +
|
| 25 | +Application |
| 26 | + wedgeMesh |
| 27 | +
|
| 28 | +Description |
| 29 | + Create a wedge from a 2D cartesian mesh. |
| 30 | +
|
| 31 | +Authors |
| 32 | + Stanislau Stasheuski, Aalto University, 2023 |
| 33 | + |
| 34 | +
|
| 35 | + Kristjan Krebelj, University of Ljubljana, 2020 |
| 36 | +
|
| 37 | + Henry Weller, CFD-Direct, 2022. |
| 38 | +
|
| 39 | +\*---------------------------------------------------------------------------*/ |
| 40 | + |
| 41 | +#include "argList.H" |
| 42 | +#include "Time.H" |
| 43 | +#include "polyMesh.H" |
| 44 | +#include "unitConversion.H" |
| 45 | +#include "emptyPolyPatch.H" |
| 46 | + |
| 47 | +using namespace Foam; |
| 48 | + |
| 49 | +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
| 50 | + |
| 51 | +label parseComponent(const word& axisName) { |
| 52 | + if (axisName == "X") |
| 53 | + { |
| 54 | + return vector::X; |
| 55 | + } |
| 56 | + else if (axisName == "Y") |
| 57 | + { |
| 58 | + return vector::Y; |
| 59 | + } |
| 60 | + else if (axisName == "Z") |
| 61 | + { |
| 62 | + return vector::Z; |
| 63 | + } |
| 64 | + |
| 65 | + FatalErrorInFunction |
| 66 | + << "Invalid axis name.\nValid names are: X, Y, Z" |
| 67 | + << exit(FatalError); |
| 68 | + return -1; // prevent comilation warning |
| 69 | +} |
| 70 | + |
| 71 | +int main(int argc, char *argv[]) |
| 72 | +{ |
| 73 | + #include "addRegionOption.H" |
| 74 | + |
| 75 | + argList::addNote |
| 76 | + ( |
| 77 | + "Creates a wedge from a 2D cartesian mesh by specifying normals to wedge plane\n" |
| 78 | + "and axis patch." |
| 79 | + ); |
| 80 | + |
| 81 | + argList::validArgs.append("plane"); |
| 82 | + argList::validArgs.append("axis normal"); |
| 83 | + argList::validArgs.append("angle[0-5]"); |
| 84 | + |
| 85 | + #include "setRootCase.H" |
| 86 | + #include "createTime.H" |
| 87 | + #include "createNamedPolyMesh.H" |
| 88 | + |
| 89 | + const label plane = parseComponent(args.argRead<word>(1)), |
| 90 | + axis = parseComponent(args.argRead<word>(2)); |
| 91 | + const scalar wedgeAngle = args.argRead<scalar>(3); |
| 92 | + |
| 93 | + Foam::word meshRegionName = polyMesh::defaultRegion; |
| 94 | + args.optionReadIfPresent("region", meshRegionName); |
| 95 | + |
| 96 | + const fileName meshRegionSubDir = meshRegionName != polyMesh::defaultRegion |
| 97 | + ? meshRegionName/polyMesh::meshSubDir |
| 98 | + : fileName(polyMesh::meshSubDir); |
| 99 | + |
| 100 | + pointIOField points |
| 101 | + ( |
| 102 | + IOobject |
| 103 | + ( |
| 104 | + "points", |
| 105 | + runTime.findInstance(meshRegionSubDir, "points"), |
| 106 | + meshRegionSubDir, |
| 107 | + runTime, |
| 108 | + IOobject::MUST_READ, |
| 109 | + IOobject::NO_WRITE, |
| 110 | + false |
| 111 | + ) |
| 112 | + ); |
| 113 | + |
| 114 | + const point midPoint = gAverage(points); |
| 115 | + |
| 116 | + Info<< "Wedge: " << wedgeAngle << " deg" << nl << endl; |
| 117 | + |
| 118 | + const scalar halfCos = Foam::cos(degToRad(0.5*wedgeAngle)), |
| 119 | + halfSin = Foam::sin(degToRad(0.5*wedgeAngle)); |
| 120 | + |
| 121 | + forAll(points, pointI) |
| 122 | + { |
| 123 | + points[pointI].replace( |
| 124 | + plane, |
| 125 | + points[pointI].component(plane) < midPoint.component(plane) |
| 126 | + ? - halfSin*points[pointI].component(axis) |
| 127 | + : + halfSin*points[pointI].component(axis) |
| 128 | + ); |
| 129 | + points[pointI].replace( |
| 130 | + axis, |
| 131 | + halfCos*points[pointI].component(axis) |
| 132 | + ); |
| 133 | + } |
| 134 | + |
| 135 | + Info<< "Writing points into directory " << points.path() << nl << endl; |
| 136 | + points.write(); |
| 137 | + |
| 138 | + Info<< "End\n" << endl; |
| 139 | + |
| 140 | + return 0; |
| 141 | +} |
| 142 | + |
| 143 | + |
| 144 | +// ************************************************************************* // |
0 commit comments