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 #include "SubStrings.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 // parse things like this:
38 // CTNAME 1 someName
39 // don't bother with the older comma-delimited format
40 
43 {
45 
46  if (!is.good())
47  {
48  return lookup;
49  }
50 
51  const regExp ctname
52  (
53  " *CTNA[^ ]*" // keyword - min 4 chars
54  "[[:space:]]+" // space delimited
55  "([0-9]+)" // 1: <digits>
56  "[[:space:]]+" // space delimited
57  "([^,[:space:]].*)", // 2: <name>
58  true // ignore case
59  );
60 
61  string line;
62  regExp::results_type groups;
63 
64  while (is.good() && is.getLine(line).good())
65  {
66  if (ctname.match(line, groups))
67  {
68  const label tableId = readLabel(groups.str(1));
69  const word tableName = word::validate(groups.str(2), true);
70 
71  if (!tableName.empty())
72  {
73  lookup.insert(tableId, tableName);
74  }
75  }
76  }
77 
78  return lookup;
79 }
80 
81 
83 (
84  Ostream& os,
85  const UList<point>& pts,
86  const label nFaces,
87  const UList<surfZone>& zoneLst
88 )
89 {
90  const word caseName = os.name().stem();
91 
92  os << "! STARCD file written " << clock::dateTime().c_str() << nl
93  << "! " << pts.size() << " points, " << nFaces << " faces" << nl
94  << "! case " << caseName << nl
95  << "! ------------------------------" << nl;
96 
97  forAll(zoneLst, zoneI)
98  {
99  os << "ctable " << zoneI + 1 << " shell" << " ,,,,,," << nl
100  << "ctname " << zoneI + 1 << " "
101  << zoneLst[zoneI].name() << nl;
102  }
103 
104  os << "! ------------------------------" << nl
105  << "*set icvo mxv - 1" << nl
106  << "vread " << caseName << ".vrt icvo,,,coded" << nl
107  << "cread " << caseName << ".cel icvo,,,add,coded" << nl
108  << "*set icvo" << nl
109  << "! end" << nl;
110 
111  os.flush();
112 }
113 
114 
115 // ************************************************************************* //
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
Lookup type of boundary radiation properties.
Definition: lookup.H:57
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
Definition: CStringList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
StringType str(size_t pos) const
Retrieve element at pos, converted to a string type.
Definition: SubStrings.H:96
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)
bool match(const std::string &text) const
True if the regex matches the entire text.
Definition: regExpPosix.C:187
Wrapper around POSIX extended regular expressions with some additional prefix-handling. The prefix-handling is loosely oriented on PCRE regular expressions and provides a simple means of tuning the expressions.
Definition: regExpPosix.H:80
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
A HashTable to objects of type <T> with a label key.
const pointField & pts