STARCDsurfaceFormatCore.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 OpenFOAM Foundation
9  Copyright (C) 2016-2022 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 \*---------------------------------------------------------------------------*/
28 
30 #include "clock.H"
31 #include "regExp.H"
32 #include "IFstream.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 // parse things like this:
37 // CTNAME 1 someName
38 // don't bother with the older comma-delimited format
39 
42 {
44 
45  if (!is.good())
46  {
47  return lookup;
48  }
49 
50  const regExp ctname
51  (
52  " *CTNA[^ ]*" // keyword - min 4 chars
53  "[[:space:]]+" // space delimited
54  "([0-9]+)" // 1: <digits>
55  "[[:space:]]+" // space delimited
56  "([^,[:space:]].*)", // 2: <name>
57  true // ignore case
58  );
59 
60  string line;
61  regExp::results_type groups;
62 
63  while (is.good() && is.getLine(line).good())
64  {
65  if (ctname.match(line, groups))
66  {
67  const label tableId = readLabel(groups.str(1));
68  const word tableName = word::validate(groups.str(2), true);
69 
70  if (!tableName.empty())
71  {
72  lookup.insert(tableId, tableName);
73  }
74  }
75  }
76 
77  return lookup;
78 }
79 
80 
82 (
83  Ostream& os,
84  const UList<point>& pts,
85  const label nFaces,
86  const UList<surfZone>& zoneLst
87 )
88 {
89  const word caseName = os.name().stem();
90 
91  os << "! STARCD file written " << clock::dateTime().c_str() << nl
92  << "! " << pts.size() << " points, " << nFaces << " faces" << nl
93  << "! case " << caseName << nl
94  << "! ------------------------------" << nl;
95 
96  forAll(zoneLst, zoneI)
97  {
98  os << "ctable " << zoneI + 1 << " shell" << " ,,,,,," << nl
99  << "ctname " << zoneI + 1 << " "
100  << zoneLst[zoneI].name() << nl;
101  }
102 
103  os << "! ------------------------------" << nl
104  << "*set icvo mxv - 1" << nl
105  << "vread " << caseName << ".vrt icvo,,,coded" << nl
106  << "cread " << caseName << ".cel icvo,,,add,coded" << nl
107  << "*set icvo" << nl
108  << "! end" << nl;
109 
110  os.flush();
111 }
112 
113 
114 // ************************************************************************* //
static Map< word > readInpCellTable(ISstream &is)
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Definition: word.C:39
A line primitive.
Definition: line.H:52
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
bool match(const std::string &text) const
True if the regex matches the entire text.
Definition: regExpCxxI.H:282
Lookup type of boundary radiation properties.
Definition: lookup.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
A class for handling words, derived from Foam::string.
Definition: word.H:63
static void writeCase(Ostream &os, const UList< point > &pts, const label nFaces, const UList< surfZone > &zoneLst)
static std::string dateTime()
The current wall-clock date/time (in local time) as a string in ISO-8601 format (yyyy-mm-ddThh:mm:ss)...
Definition: clock.C:53
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:69
OBJstream os(runTime.globalPath()/outputName)
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
std::smatch results_type
Type for matches.
Definition: regExpCxx.H:123
Wrapper around C++11 regular expressions with some additional prefix-handling. The prefix-handling is...
Definition: regExpCxx.H:78
A HashTable to objects of type <T> with a label key.
const pointField & pts