datToFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  datToFoam
29 
30 Group
31  grpMeshConversionUtilities
32 
33 Description
34  Reads in a datToFoam mesh file and outputs a points file.
35  Used in conjunction with blockMesh.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "argList.H"
40 #include "Time.H"
41 #include "Fstream.H"
42 #include "pointField.H"
43 #include "unitConversion.H"
44 
45 using namespace Foam;
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 int main(int argc, char *argv[])
50 {
52  (
53  "Reads in a datToFoam mesh file and outputs a points file.\n"
54  "Used in conjunction with blockMesh."
55  );
56 
58  argList::addArgument("dat file");
59 
60  argList args(argc, argv);
61 
62  if (!args.check())
63  {
64  FatalError.exit();
65  }
66 
67  #include "createTime.H"
68 
69  std::ifstream plot3dFile(args[1]);
70 
71  string line;
72  std::getline(plot3dFile, line);
73  std::getline(plot3dFile, line);
74 
75  IStringStream Istring(line);
76  word block;
77  string zoneName;
78  token punctuation;
79  label iPoints;
80  label jPoints;
81 
82  Istring >> block;
83  Istring >> block;
84  Istring >> zoneName;
85  Istring >> punctuation;
86  Istring >> block;
87  Istring >> iPoints;
88  Istring >> block;
89  Istring >> jPoints;
90 
91  Info<< "Number of vertices in i direction = " << iPoints << nl
92  << "Number of vertices in j direction = " << jPoints << endl;
93 
94  // We ignore the first layer of points in i and j the biconic meshes
95  const label nPointsij = (iPoints - 1)*(jPoints - 1);
96 
97  pointField points(nPointsij, Zero);
98 
99  for (direction comp = 0; comp < 2; ++comp)
100  {
101  label p = 0;
102 
103  for (label j = 0; j < jPoints; ++j)
104  {
105  for (label i = 0; i < iPoints; ++i)
106  {
107  scalar coord;
108  plot3dFile >> coord;
109 
110  // if statement ignores the first layer in i and j
111  if (i>0 && j>0)
112  {
113  points[p++][comp] = coord;
114  }
115  }
116  }
117  }
118 
119  // correct error in biconic meshes
120  forAll(points, i)
121  {
122  if (points[i][1] < 1e-07)
123  {
124  points[i][1] = 0.0;
125  }
126  }
127 
128  pointField pointsWedge(nPointsij*2, Zero);
129 
130  const scalar a = degToRad(0.1);
131  const tensor rotateZ
132  (
133  1.0, 0.0, 0.0,
134  0.0, 1.0, 0.0,
135  0.0, -::sin(a), ::cos(a)
136  );
137 
138  forAll(points, i)
139  {
140  pointsWedge[i] = (rotateZ & points[i]);
141  pointsWedge[i + nPointsij] =
143  (
144  vector(1.0, 1.0, -1.0),
145  pointsWedge[i]
146  );
147  }
148 
149  const fileName polyMeshPath(runTime.constantPath()/"polyMesh");
150  const fileName pointsFile(polyMeshPath/"points");
151  OFstream pFile(pointsFile);
152  if (!exists(polyMeshPath)) mkDir(polyMeshPath);
153 
154  Info<< "Writing points to: " << nl
155  << " " << pointsFile << endl;
156 
157  runTime.writeHeader(pFile, "vectorField");
158  pFile << pointsWedge;
159  runTime.writeEndDivider(pFile);
160 
161 
162  Info<< "End" << endl;
163 
164  return 0;
165 }
166 
167 
168 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Tensor< scalar >
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::exists
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:625
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::IOobject::writeEndDivider
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
Definition: IOobjectWriteHeader.C:109
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
unitConversion.H
Unit conversion functions.
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::TimePaths::constantPath
fileName constantPath() const
Return constant path.
Definition: TimePathsI.H:122
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
Foam::FatalError
error FatalError
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::error::exit
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:298
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:87
pointField.H
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Fstream.H
Input/output from file streams.
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::direction
uint8_t direction
Definition: direction.H:47
createTime.H
Foam::line
A line primitive.
Definition: line.H:59
Foam::IOobject::writeHeader
bool writeHeader(Ostream &os) const
Write header.
Definition: IOobjectWriteHeader.C:156
Foam::argList::check
bool check(bool checkArgs=argList::argsMandatory(), bool checkOpts=true) const
Definition: argList.C:1722
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
args
Foam::argList args(argc, argv)
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265