File: ccmToFoam.C

package info (click to toggle)
openfoam 1812%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 220,284 kB
  • sloc: cpp: 1,038,902; sh: 14,536; ansic: 8,240; lex: 657; xml: 387; python: 300; awk: 212; makefile: 94; sed: 88; csh: 3
file content (309 lines) | stat: -rw-r--r-- 8,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2016 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    ccmToFoam

Group
    grpMeshConversionUtilities

Description
    Reads CCM files as written by PROSTAR/STARCCM and writes an
    OPENFOAM polyMesh.

Usage
    \b ccmToFoam [OPTION] ccmMesh

    Options:
      - \par -ascii
        Write in ASCII format instead of binary

      - \par -export
        re-export mesh in CCM format for post-processing

      - \par -list
        List some information about the geometry

      - \par -name \<name\>
        Provide alternative base name for export.
        Default is <tt>meshExport</tt>.

      - \par -noBaffles
        Remove any baffles by merging the faces.

      - \par -merge
        Merge in-place interfaces

      - \par -numbered
        Use numbered patch/zone (not names) directly from ccm ids.

      - \par -remap \<name\>
        Use specified remapping dictionary instead of
        <tt>constant/remapping</tt>

      - \par -scale \<factor\>
        Specify an alternative geometry scaling factor.
        The default is \b 1 (no scaling).

      - \par -solids
        Treat any solid cells present just like fluid cells.
        The default is to remove them.

Note
    - sub-domains (fluid | solid | porosity) are stored as separate domains
      within the CCM file. These are merged together to form a single mesh.
    - baffles are written as interfaces for later use

See also
    Foam::ccm::reader for more information about the File Locations

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "Time.H"
#include "ccm.H"
#include "regionSplit.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    argList::addNote
    (
        "Reads CCM files as written by PROSTAR/STARCCM and writes an OPENFOAM "
        " polyMesh. Multi-region support for PROSTAR meshes should be stable."
        " Multi-region merging for STARCCM meshes will not always be"
        " successful."
    );

    argList::noParallel();
    argList::addArgument("ccm-file", "The input .ccm or .ccmg file");
    argList::addBoolOption
    (
        "ascii",
        "Write in ASCII format instead of binary"
    );
    argList::addBoolOption
    (
        "export",
        "Re-export mesh in CCM format for post-processing"
    );
    argList::addBoolOption
    (
        "list",
        "List some information about the geometry"
    );
    argList::addOption
    (
        "remap",
        "name",
        "Use specified remapping dictionary instead of <constant/remapping>"
    );
    argList::addOption
    (
        "name",
        "name",
        "Provide alternative base name when re-exporting (implies -export). "
        "Default is <meshExport>."
    );
    argList::addBoolOption
    (
        "noBaffles",
        "Remove any baffles by merging the faces"
    );
    argList::addBoolOption
    (
        "merge",
        "Merge in-place interfaces"
    );
    argList::addBoolOption
    (
        "numbered",
        "Use numbered names (eg, patch_0, zone_0) only"
    );
    argList::addOption
    (
        "scale",
        "scale",
        "Geometry scaling factor - default is 1 (ie, no scaling)"
    );
    argList::addBoolOption
    (
        "solids",
        "Treat any solid cells present just like fluid cells. "
        "The default is to remove them."
    );

    argList::noFunctionObjects();  // Never use function objects

    argList args(argc, argv);
    Time runTime(args.rootPath(), args.caseName());

    runTime.functionObjects().off();  // Extra safety

    const bool optList = args.found("list");

    // exportName only has a size when export is in effect
    fileName exportName;
    if (args.readIfPresent("name", exportName))
    {
        const word ext = exportName.ext();
        // strip erroneous extension (.ccm, .ccmg, .ccmp)
        if (ext == "ccm" || ext == "ccmg" || ext == "ccmp")
        {
            exportName = exportName.lessExt();
        }
    }
    else if (args.found("export"))
    {
        exportName = ccm::writer::defaultMeshName;
        if (args.found("case"))
        {
            exportName += '-' + args.globalCaseName();
        }
    }

    // By default, no scaling
    const scalar scaleFactor = args.opt<scalar>("scale", 1);

    // Default to binary output, unless otherwise specified
    const IOstream::streamFormat format =
    (
        args.found("ascii")
      ? IOstream::ASCII
      : IOstream::BINARY
    );

    // Increase the precision of the points data
    IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));


    // Read control options
    // ~~~~~~~~~~~~~~~~~~~~

    ccm::reader::options rOpts;
    rOpts.removeBaffles(args.found("noBaffles"));
    rOpts.mergeInterfaces(args.found("merge"));

    if (args.found("numbered"))
    {
        rOpts.useNumberedNames(true);
    }

    if (args.found("solids"))
    {
        Info<< "treating solids like fluids" << endl;
        rOpts.keepSolid(true);
    }
    else
    {
        rOpts.keepSolid(false);
    }

    // CCM reader for reading geometry/solution
    ccm::reader reader(args[1], rOpts);

    // list the geometry information
    if (optList)
    {
        Info<< "mesh geometry information:" << endl;
        if (reader.hasGeometry())
        {
            Info<< nl << "cellTable:" << reader.cellTableInfo()
                << nl << "boundaryRegion:" << reader.boundaryTableInfo()
                << nl << "interfaces:" << reader.interfaceDefinitionsInfo()
                << endl;

            if
            (
                args.found("remap")
              ? reader.remapMeshInfo(runTime, args["remap"])
              : reader.remapMeshInfo(runTime)
            )
            {
                Info<< nl
                    << "Remapped cellTable:" << reader.cellTableInfo() << nl
                    << "Remapped boundaryRegion:" << reader.boundaryTableInfo()
                    << endl;
            }
        }
        else
        {
            Info<< "NONE" << endl;
        }

        return 0;
    }
    else if (reader.readGeometry(scaleFactor))
    {
        autoPtr<polyMesh> mesh =
        (
            args.found("remap")
          ? reader.mesh(runTime, args["remap"])
          : reader.mesh(runTime)
        );

        // report mesh bounding box information
        Info<< nl << "Bounding box size: " << mesh().bounds().span() << nl;

        // check number of regions
        regionSplit rs(mesh());

        Info<< "Number of regions: " << rs.nRegions();
        if (rs.nRegions() == 1)
        {
            Info<< " (OK)." << nl;
        }
        else
        {
            Info<< nl << nl
                << "**************************************************" << nl
                << "**  WARNING: the mesh has disconnected regions  **" << nl
                << "**************************************************" << nl;
        }
        Info<< endl;
        reader.writeMesh(mesh(), format);

        // exportName only has a size when export is in effect
        if (exportName.size())
        {
            const fileName geomName = exportName + ".ccmg";
            Info<< nl << "Re-exporting geometry as " << geomName << nl;
            ccm::writer(geomName, mesh()).writeGeometry();
        }
    }
    else
    {
        FatalErrorInFunction
            << "could not read geometry"
            << exit(FatalError);
    }

    Info<< "\nEnd\n" << endl;

    return 0;
}

// ************************************************************************* //