Repository navigation
Expand file tree
/
Copy pathsortRenumberGammaEdges.cpp
More file actions
110 lines (98 loc) · 3.11 KB
/
Copy pathsortRenumberGammaEdges.cpp
File metadata and controls
110 lines (98 loc) · 3.11 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
104
105
106
107
108
109
110
#include "Gamma/Gamma.h"
#include "Ugrid/Mapbc.h"
#include <iostream>
#include <filesystem> // C++17
namespace fs = std::filesystem;
int countDistinct(int a[], int size)
{
int i, j, count = 1;
for (i = 1; i < size; i++)
{
for (j = 0; j < i; j++)
{
if (a[i] == a[j])
{
break;
}
}
if (i == j)
{
count++;
}
}
return count;
}
int main(int argc, char *argv[])
{
// Confirm number of inputs
std::cout << "Number of inputs: " << argc - 1 << "\n";
if (argc != 4)
{
std::cout << "There should be three input arguments.\n";
return 1;
}
// Print all input arguments
for (int i = 1; i < argc; i++)
std::cout << "argv[" << i << "] = " << argv[i] << "\n";
// Check inputs
fs::path inputGridFile = argv[1];
fs::path outputGridFile = argv[2];
fs::path mapbcFile = argv[3];
if (!fs::exists(inputGridFile))
{
std::cout << "Input grid file " << inputGridFile.filename() << " not found.\n";
return 1;
}
if (inputGridFile.extension().compare(".meshb") != 0 && inputGridFile.extension().compare(".mesh") != 0)
{
std::cout << "Input grid file extension is " << inputGridFile.extension() << ". The extension should be .mesh or .meshb.\n";
return 1;
}
if (outputGridFile.extension().compare(".meshb") != 0 && outputGridFile.extension().compare(".mesh") != 0)
{
std::cout << "Output grid file extension is " << outputGridFile.extension() << ". The extension should be .mesh or .meshb.\n";
return 1;
}
if (fs::exists(outputGridFile))
{
std::cout << outputGridFile.filename() << " already exists. It will be overwritten.\n";
}
if (mapbcFile.extension().compare(".mapbc") != 0)
{
std::cout << "Mapbc file extension is " << mapbcFile.extension() << ". The extension should be .mapbc\n";
return 1;
}
if (fs::exists(mapbcFile))
{
std::cout << "Input Mapbc file " << mapbcFile.filename() << " not found.\n";
}
// Read Input Gamma mesh
Gamma gamma;
gamma.getMeshInfo(argv[1]);
gamma.getMeshData();
// Read Input Mapbc file
UgridNamespace::Mapbc mapbc;
mapbc.read(argv[3]);
// mapbc.write("test.mapbc");
// Check Mapbc file has sequential indicies starting from 1.
for (int i = 0; i < mapbc.nBoundaries; i++)
{
if (mapbc.boundary[i].index != i+1 )
{
std::cout << "This process was created for Mapbc files that have sequential indicies starting from 1. Process aborted.\n";
return 1;
}
}
for (int i = 0; i < gamma.NmbEdg; i++)
{
if ( gamma.edges[i].ref < 1 || gamma.edges[i].ref > mapbc.nBoundaries)
{
std::cout << "An edge reference is outside of the range of values specified in the Mapbc file. Process aborting.\n";
return 1;
}
gamma.edges[i].ref = mapbc.boundary[gamma.edges[i].ref-1].condition;
}
// write modifed mesh to file
gamma.writeMeshData(argv[2]);
return 0;
}