forked from ImperialCollegeLondon/multifluids_icferst
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVertical_Integration_main.cpp
188 lines (162 loc) · 4.99 KB
/
Vertical_Integration_main.cpp
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
/* Copyright (C) 2006 Imperial College London and others.
Please see the AUTHORS file in the main source directory for a full list
of copyright holders.
Prof. C Pain
Applied Modelling and Computation Group
Department of Earth Science and Engineering
Imperial College London
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation,
version 2.1 of the License.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
#include <iostream>
#include <map>
#include <stdlib.h>
#include "confdefs.h"
#ifdef HAVE_MPI
#include <mpi.h>
#endif
#include "Usage.h"
#include "c++debug.h"
using namespace std;
extern "C"{
void vertical_integration(const char* target_basename, size_t target_basename_len,
const char* integrated_filename, size_t integrated_filename_len,
const char* output_basename, size_t output_basename_len,
double top, double bottom, double sizing, int result_continuity, int result_degree);
#ifdef HAVE_PYTHON
#include "python_statec.h"
#endif
}
void Usage(){
cerr << "Usage: vertical_intergation [OPTIONS] ... TARGET INTEGRATED OUTPUT\n"
<< "\n"
<< "Performs a vertical integration of a vtu via the use of supermeshing a\n"
<< "vertical extrusion.\n"
<< "\n"
<< "Options:\n"
<< "\n"
<< "-b\t\tBottom\n"
<< "-d\t\tDiscontinuous result (default false for degree > 0, true for degree == 0)\n"
<< "-h\t\tDisplay this help\n"
<< "-p\t\tResult degree (default 1)\n"
<< "-s\t\tSizing\n"
<< "-t\t\tTop (default 0.0)\n"
<< "-v\t\tVerbose mode" << endl;
}
int main(int argc, char** argv){
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
// Undo some MPI init shenanigans
int ierr = chdir(getenv("PWD"));
if (ierr == -1) {
cerr << "Unable to switch to directory " << getenv("PWD");
abort();
}
#endif
PetscInit(argc, argv);
#ifdef HAVE_PYTHON
// Initialize the Python Interpreter
python_init_();
#endif
// Modified version of flredecomp argument parsing
// Get any command line arguments
// Reset optarg so we can detect changes
optarg = NULL;
char c;
map<char, string> args;
while((c = getopt(argc, argv, "b:dhp:s:t:v")) != -1){
if (c != '?'){
if(optarg == NULL){
args[c] = "true";
}else{
args[c] = optarg;
}
}else{
if(isprint(optopt)){
cerr << "Unknown option " << optopt << endl;
}else{
cerr << "Unknown option " << hex << optopt << endl;
}
Usage();
exit(-1);
}
}
// Help
if(args.count('h')){
Usage();
exit(0);
}
// Verbosity
int verbosity = 0;
if(args.count('v') > 0){
verbosity = 3;
}
set_global_debug_level_fc(&verbosity);
// Options
double bottom, sizing, top = 0.0;
if(args.count('b') > 0){
bottom = atof(args['b'].c_str());
}else{
cerr << "Bottom required" << endl;
Usage();
exit(-1);
}
if(args.count('s') > 0){
sizing = atof(args['s'].c_str());
}else{
cerr << "Sizing required" << endl;
Usage();
exit(-1);
}
if(args.count('t') > 0){
top = atof(args['t'].c_str());
}
int result_degree = 1;
if(args.count('p') > 0){
result_degree = atoi(args['p'].c_str());
}
int result_continuity = args.count('d') > 0 ? -1 : (result_degree == 0 ? -1 : 0);
// Input / output
string target_basename, integrated_filename, integrated_fieldname, output_basename;
if(argc > optind + 3){
target_basename = argv[optind + 1];
integrated_filename = argv[optind + 2];
output_basename = argv[optind + 3];
}else if(argc == optind + 3){
target_basename = argv[optind];
integrated_filename = argv[optind + 1];
output_basename = argv[optind + 2];
}else{
Usage();
exit(-1);
}
size_t target_basename_len = target_basename.size();
size_t integrated_filename_len = integrated_filename.size();
size_t output_basename_len = output_basename.size();
vertical_integration(target_basename.c_str(), target_basename_len,
integrated_filename.c_str(), integrated_filename_len,
output_basename.c_str(), output_basename_len,
top, bottom, sizing, result_continuity, result_degree);
#ifdef HAVE_PYTHON
// Finalize the Python Interpreter
python_end_();
#endif
#ifdef HAVE_PETSC
PetscFinalize();
#endif
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 0;
}