Loading...
Searching...
No Matches
mergeMeshes.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) 2016-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Application
28 mergeMeshes
29
30Group
31 grpMeshManipulationUtilities
32
33Description
34 Merges two meshes.
35
36\*---------------------------------------------------------------------------*/
37
38#include "argList.H"
39#include "Time.H"
40#include "mergePolyMesh.H"
41#include "topoSet.H"
42#include "processorMeshes.H"
43
44using namespace Foam;
45
46void getRootCase(fileName& casePath)
47{
48 casePath.clean(); // Remove unneeded ".."
49
50 if (casePath.empty() || casePath == ".")
51 {
52 // handle degenerate form and '.'
53 casePath = cwd();
54 }
55 else if (casePath[0] != '/' && casePath.name() == "..")
56 {
57 // avoid relative cases ending in '..' - makes for very ugly names
58 casePath = cwd()/casePath;
59 casePath.clean(); // Remove unneeded ".."
60 }
61}
62
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66int main(int argc, char *argv[])
67{
69 (
70 "Merge two meshes"
71 );
72
73 #include "addOverwriteOption.H"
74
75 argList::addArgument("masterCase");
77 (
78 "masterRegion",
79 "name",
80 "Specify alternative mesh region for the master mesh"
81 );
82
83 argList::addArgument("addCase");
85 (
86 "addRegion",
87 "name",
88 "Specify alternative mesh region for the additional mesh"
89 );
91 (
92 "resultTime",
93 "time",
94 "Specify a time for the resulting mesh"
95 );
96
97 argList args(argc, argv);
98 if (!args.check())
99 {
100 FatalError.exit();
101 }
102
103 const bool overwrite = args.found("overwrite");
104
105 auto masterCase = args.get<fileName>(1);
106 auto addCase = args.get<fileName>(2);
107
108 const word masterRegion =
109 args.getOrDefault<word>("masterRegion", polyMesh::defaultRegion);
110
111 const word addRegion =
112 args.getOrDefault<word>("addRegion", polyMesh::defaultRegion);
113
114 // Since we don't use argList processor directory detection, add it to
115 // the casename ourselves so it triggers the logic inside TimePath.
116 const fileName& cName = args.caseName();
117 const auto pos = cName.find("processor");
118 if (pos != string::npos && pos != 0)
119 {
120 fileName processorName = cName.substr(pos);
121 masterCase += '/' + processorName;
122 addCase += '/' + processorName;
123 }
124
125
126 getRootCase(masterCase);
127 getRootCase(addCase);
128
129 Info<< "Master: " << masterCase << " region " << masterRegion << nl
130 << "mesh to add: " << addCase << " region " << addRegion << endl;
131
132 #include "createTimes.H"
133
134 Info<< "Reading master mesh for time = " << runTimeMaster.timeName() << nl;
135
136 Info<< "Create mesh\n" << endl;
137 mergePolyMesh masterMesh
138 (
140 (
141 masterRegion,
142 runTimeMaster.timeName(),
143 runTimeMaster
144 )
145 );
146
147 Info<< "Reading mesh to add for time = " << runTimeToAdd.timeName() << nl;
148 Info<< "Create mesh\n" << endl;
149 polyMesh meshToAdd
150 (
152 (
153 addRegion,
154 runTimeToAdd.timeName(),
155 runTimeToAdd
156 )
157 );
158
159 word meshInstance = masterMesh.pointsInstance();
160
161 const bool specifiedInstance =
162 (
163 !overwrite
164 && args.readIfPresent("resultTime", meshInstance)
165 );
166
167 if (specifiedInstance)
168 {
169 runTimeMaster.setTime(instant(meshInstance), 0);
170 }
171 else if (!overwrite)
172 {
173 runTimeMaster++;
174 }
175
176 Info<< "Writing combined mesh to " << runTimeMaster.timeName() << endl;
177
178 masterMesh.addMesh(meshToAdd);
179 masterMesh.merge();
180
181 if (overwrite || specifiedInstance)
182 {
183 masterMesh.setInstance(meshInstance);
184 }
185
186 masterMesh.write();
187 topoSet::removeFiles(masterMesh);
189
190 Info<< "End\n" << endl;
191
192 return 0;
193}
194
195
196// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
A class for handling file names.
Definition fileName.H:75
static bool clean(std::string &str)
Cleanup filename string, possibly applies other transformations such as changing the path separator e...
Definition fileName.C:192
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition fileNameI.H:192
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition instant.H:56
Add a given mesh to the original mesh to create a single new mesh.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition topoSet.C:693
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for OpenFOAM.
fileName cwd()
The physical or logical current working directory path name.
Definition POSIX.C:592
dimensionedScalar pos(const dimensionedScalar &ds)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)