-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (84 loc) · 4.03 KB
/
Copy pathmain.cpp
File metadata and controls
103 lines (84 loc) · 4.03 KB
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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <map>
#include "OpenFOAMMeshReader.h"
#include "ExodusWriter.h"
#include "MergedMeshReader.h"
void printUsage(const char* programName) {
std::cout << "Usage: " << programName << " <OpenFOAM_case_dir> <output.exo>\n";
std::cout << " or: " << programName << " --multiple <case_dir1> <case_dir2> ... <output.exo>\n";
std::cout << "\nConverts OpenFOAM mesh(es) to Exodus II format with boundary patches as sidesets\n";
std::cout << "\nArguments:\n";
std::cout << " OpenFOAM_case_dir : Path to OpenFOAM case directory containing polyMesh\n";
std::cout << " output.exo : Output Exodus II file path\n";
std::cout << "\nMulti-mesh mode (--multiple):\n";
std::cout << " Merges multiple OpenFOAM meshes into a single Exodus file\n";
std::cout << " Each mesh's element blocks and sidesets remain separate\n";
std::cout << " Example: " << programName << " --multiple case1 case2 case3 merged.exo\n";
}
int main(int argc, char* argv[]) {
if (argc < 3) {
printUsage(argv[0]);
return 1;
}
try {
// Check if --multiple flag is present
std::string firstArg = argv[1];
bool multipleMode = (firstArg == "--multiple");
if (multipleMode) {
// Multi-mesh mode: --multiple case1 case2 ... output.exo
if (argc < 4) {
std::cerr << "Error: --multiple requires at least one case directory and an output file\n";
printUsage(argv[0]);
return 1;
}
// All arguments except first (--multiple) and last (output.exo) are case directories
std::vector<std::string> casePaths;
for (int i = 2; i < argc - 1; ++i) {
casePaths.push_back(argv[i]);
}
std::string outputPath = argv[argc - 1];
std::cout << "=== Multi-mesh merge mode ===" << std::endl;
std::cout << "Merging " << casePaths.size() << " OpenFOAM meshes into: " << outputPath << std::endl;
std::cout << std::endl;
// Read and merge all meshes
MergedMeshReader mergedReader(casePaths);
mergedReader.readMeshes();
std::cout << "\nWriting merged Exodus II file: " << outputPath << std::endl;
// Write merged mesh with custom naming to keep element blocks separate
ExodusWriter writer(outputPath);
writer.writeMesh(mergedReader,
mergedReader.getElementBlockNames(),
mergedReader.getSidesetNames());
std::cout << "\nMerge completed successfully!" << std::endl;
std::cout << "Element blocks from different meshes remain separate." << std::endl;
} else {
// Single mesh mode (backward compatible)
if (argc != 3) {
std::cerr << "Error: Single mesh mode requires exactly 2 arguments\n";
printUsage(argv[0]);
return 1;
}
std::string casePath = argv[1];
std::string outputPath = argv[2];
std::cout << "Reading OpenFOAM mesh from: " << casePath << std::endl;
OpenFOAMMeshReader reader(casePath);
reader.readMesh();
std::cout << "Mesh statistics:" << std::endl;
std::cout << " Points: " << reader.getNumPoints() << std::endl;
std::cout << " Cells: " << reader.getNumCells() << std::endl;
std::cout << " Boundary patches: " << reader.getNumBoundaryPatches() << std::endl;
std::cout << "\nWriting Exodus II file: " << outputPath << std::endl;
ExodusWriter writer(outputPath);
writer.writeMesh(reader);
std::cout << "Conversion completed successfully!" << std::endl;
std::cout << "Boundary patches written as sidesets." << std::endl;
}
return 0;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
}