forked from martemyev/tethex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
153 lines (125 loc) · 4.01 KB
/
main.cpp
File metadata and controls
153 lines (125 loc) · 4.01 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
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
/*
* tethex - tetrahedra to hexahedra conversion
* Copyright (c) 2013 Mikhail Artemyev
* Report issues: github.com/martemyev/tethex/issues
*
* This program 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 2
* of the License, or (at your option) any later version.
* This program 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.
*/
#include "tethex.h"
#include "config.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#if defined(TESTING)
#include "testing.h"
#endif
using namespace tethex;
void read_parameters(int argc, char **argv,
std::string &in_file,
std::string &out_file,
int &verbosity);
void run(const std::string &in_file,
const std::string &out_file,
int verbosity);
int main(int argc, char **argv)
{
try
{
std::string in_file; // input file
std::string out_file; // output file
int verbosity; // verbosity level
read_parameters(argc, argv, in_file, out_file, verbosity);
#if defined(TESTING)
std::cout << "\nWe are starting short testing procedures!\n\n";
::testing::InitGoogleTest(&argc, argv);
int test_ret = RUN_ALL_TESTS();
std::cout << "\nTesting procedures finished (" << test_ret << " is returned)\n\n";
#endif
run(in_file, out_file, verbosity);
}
catch(int i)
{
return i;
}
catch(const std::exception &e)
{
std::cerr << "\n\n" << e.what() << std::endl;
return 2;
}
catch(...)
{
std::cerr << "\n\nUnknown exception has been thrown!" << std::endl;
return 3;
}
return 0;
}
void read_parameters(int argc, char **argv,
std::string &in_file,
std::string &out_file,
int &verbosity)
{
if (argc < 2)
{
std::cout << "\nUsage:\n" << argv[0] << " input.msh [output.msh verbosity]\n"
<< "where\n"
<< "input.msh file with mesh to be converted\n"
<< "output.msh (optional) file with hexahedral mesh (if ommited, the resulting file will be named input_hex.msh)\n"
<< "verbosity (optional) level of verbosity (0 - silent conversion, default 1)\n";
std::cout << std::endl;
throw 1;
}
in_file = std::string(argv[1]);
const size_t pos = in_file.find(".msh");
require(pos != in_file.npos, "Input file " + in_file + " is not native "
"Gmsh's mesh file. Its extension is not .msh");
if (argc > 2)
out_file = std::string(argv[2]);
else
{
out_file = in_file;
out_file.replace(pos, in_file.size(), "_hex.msh");
}
if (argc > 3)
verbosity = atoi(argv[3]);
else
verbosity = 1;
}
void run(const std::string &in_file,
const std::string &out_file,
int verbosity)
{
// time measurement
clock_t beg_time = clock();
Mesh mesh;
if (verbosity)
std::cout << "Reading " << in_file << " file..." << std::endl;
mesh.read(in_file);
if (verbosity)
std::cout << "Reading " << in_file << " file is done" << std::endl;
if (verbosity) mesh.info();
if (verbosity > 1) mesh.statistics(std::cout);
if (verbosity)
std::cout << "Converting simplices to bricks..." << std::endl;
mesh.convert();
if (verbosity)
std::cout << "Converting simplices to bricks is done" << std::endl;
if (verbosity) mesh.info();
if (verbosity > 1) mesh.statistics(std::cout);
if (verbosity)
std::cout << "Writing " << out_file << " file..." << std::endl;
mesh.write(out_file);
if (verbosity)
std::cout << "Writing " << out_file << " file is done" << std::endl;
// time measurement
clock_t total_time = clock() - beg_time;
if (verbosity)
std::cout << "\nTime of execution is " << (double)total_time / CLOCKS_PER_SEC
<< " sec " << std::endl;
}