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-2018 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().nameLessExt();
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 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::word::validate
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Definition: word.C:45
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::clock::dateTime
static std::string dateTime()
Definition: clock.C:60
Foam::regExpCxx::match
bool match(const std::string &text) const
True if the regex matches the entire text.
Definition: regExpCxxI.H:289
clock.H
Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
static Map< word > readInpCellTable(ISstream &is)
Definition: STARCDsurfaceFormatCore.C:42
Foam::regExpCxx
Wrapper around C++11 regular expressions with some additional prefix-handling. The prefix-handling is...
Definition: regExpCxx.H:82
IFstream.H
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
os
OBJstream os(runTime.globalPath()/outputName)
Foam::regExpCxx::results_type
std::smatch results_type
Type for matches.
Definition: regExpCxx.H:114
SubStrings.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::readLabel
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:66
Foam::UList
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:103
Foam::line
A line primitive.
Definition: line.H:53
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
static void writeCase(Ostream &os, const UList< point > &pts, const label nFaces, const UList< surfZone > &zoneLst)
Definition: STARCDsurfaceFormatCore.C:83
STARCDsurfaceFormatCore.H