-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_Darcy.C
277 lines (227 loc) · 7.84 KB
/
main_Darcy.C
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// $Id$
//==============================================================================
//!
//! \file main_Darcy.C
//!
//! \date Mar 27 2015
//!
//! \author Yared Bekele
//!
//! \brief Main program for an isogeometric solver for Darcy flow.
//!
//==============================================================================
#include "DarcyAdvection.h"
#include "DarcyArgs.h"
#include "DarcyTransport.h"
#include "SIMDarcy.h"
#include "SIMDarcyAdap.h"
#include "SIMDarcySchedule.h"
#include "ASMenums.h"
#include "ASMmxBase.h"
#include "IFEM.h"
#include "LogStream.h"
#include "Profiler.h"
#include "SIM1D.h"
#include "SIM2D.h"
#include "SIM3D.h"
#include "SIMoptions.h"
#include "SIMSolver.h"
#include "TimeIntUtils.h"
#include "TimeStep.h"
#include <iostream>
#include <string>
#include <vector>
/*!
\brief Launch a simulator using a specified solver template.
\param infile The input file to parse
\param args Darcy arguments
*/
template<class Dim, template<class T> class Solver>
int runSimulator(char* infile, const DarcyArgs& args)
{
std::unique_ptr<Darcy> itg;
std::vector<unsigned char> nf;
if (args.tracer) {
nf = {2};
itg = std::make_unique<DarcyTransport>(Dim::dimension,0);
} else {
nf = {1};
itg = std::make_unique<Darcy>(Dim::dimension,0);
}
SIMDarcy<Dim> darcy(*itg,nf);
darcy.setAdaptiveNorm(args.adNorm);
Solver<SIMDarcy<Dim>> solver(darcy);
utl::profiler->start("Model input");
if (!darcy.read(infile) || !solver.read(infile))
return 1;
utl::profiler->stop("Model input");
if (!darcy.preprocess())
return 2;
darcy.init();
if (darcy.opt.dumpHDF5(infile))
solver.handleDataOutput(darcy.opt.hdf5,darcy.getProcessAdm());
int res = solver.solveProblem(infile,"Solving Darcy problem");
if (!res)
darcy.printFinalNorms(TimeStep());
return res;
}
/*!
\brief Launch a simulator using a specified solver template.
\param infile The input file to parse
\param args Darcy arguments
*/
template<class Dim>
int runSimulatorTransient(char* infile, const DarcyArgs& args)
{
std::unique_ptr<Darcy> itg;
std::vector<unsigned char> nf;
if (args.tracer) {
nf = {2};
itg = std::make_unique<DarcyTransport>(Dim::dimension, TimeIntegration::Order(args.timeMethod));
} else {
nf = {1};
itg = std::make_unique<Darcy>(Dim::dimension, TimeIntegration::Order(args.timeMethod));
}
SIMDarcy<Dim> darcy(*itg,nf);
SIMSolver<SIMDarcy<Dim>> solver(darcy);
utl::profiler->start("Model input");
if (!darcy.read(infile) || !solver.read(infile))
return 1;
utl::profiler->stop("Model input");
if (!darcy.preprocess())
return 2;
darcy.init();
if (darcy.opt.dumpHDF5(infile))
solver.handleDataOutput(darcy.opt.hdf5,darcy.getProcessAdm());
int res = solver.solveProblem(infile,"Solving Darcy problem");
if (!res)
darcy.printFinalNorms(solver.getTimePrm());
return res;
}
/*!
\brief Launch a simulator using a specified solver template.
\param infile The input file to parse
\param args Darcy arguments
*/
template<class Dim>
int runSimulatorScheduled(char* infile, const DarcyArgs& args)
{
Darcy dcy(Dim::dimension);
DarcyAdvection dcya(Dim::dimension,dcy,TimeIntegration::Order(args.timeMethod));
SIMDarcy<Dim> darcy(dcy);
SIMDarcyAdvection<Dim> darcya(dcya);
SIMDarcySchedule<Dim> schedule(darcy, darcya);
SIMSolver<SIMDarcySchedule<Dim>> solver(schedule);
utl::profiler->start("Model input");
if (!darcy.read(infile) || !darcya.read(infile) ||
!schedule.read(infile) || !solver.read(infile))
return 1;
utl::profiler->stop("Model input");
if (!darcy.preprocess() || ! darcya.preprocess())
return 2;
darcy.init();
darcya.init();
schedule.setupDependencies();
if (darcy.opt.dumpHDF5(infile))
solver.handleDataOutput(darcy.opt.hdf5,
darcy.getProcessAdm(),
darcy.opt.saveInc,
darcy.opt.restartInc);
int res = solver.solveProblem(infile,"Solving Darcy advection problem");
if (!res)
darcy.printFinalNorms(solver.getTimePrm());
return res;
}
/*!
\brief Choose a solver template and then launch a simulator.
\param infile The input file to parse
\param args Simulator arguments
*/
template<class Dim>
int runSimulator1(char* infile, const DarcyArgs& args)
{
if (args.adap)
return runSimulator<Dim,SIMDarcyAdap>(infile,args);
else if (args.scheduled)
return runSimulatorScheduled<Dim>(infile,args);
else if (args.timeMethod != TimeIntegration::NONE)
return runSimulatorTransient<Dim>(infile,args);
else
return runSimulator<Dim, SIMSolverStat>(infile,args);
}
/*!
\brief Main program for the isogeometric Darcy solver.
The input to the program is specified through the following
command-line arguments. The arguments may be given in arbitrary order.
\arg \a input-file : Input file with model definition
\arg -dense : Use the dense LAPACK matrix equation solver
\arg -spr : Use the SPR direct equation solver
\arg -superlu : Use the sparse SuperLU equation solver
\arg -samg : Use the sparse algebraic multi-grid equation solver
\arg -petsc : Use equation solver from PETSc library
\arg -lag : Use Lagrangian basis functions instead of splines/NURBS
\arg -spec : Use Spectral basis functions instead of splines/NURBS
\arg -LR : Use LR-spline basis functions instead of tensorial splines/NURBS
\arg -nGauss \a n : Number of Gauss points over a knot-span in each direction
\arg -vtf \a format : VTF-file format (-1=NONE, 0=ASCII, 1=BINARY)
\arg -nviz \a nviz : Number of visualization points over each knot-span
\arg -nu \a nu : Number of visualization points per knot-span in u-direction
\arg -nv \a nv : Number of visualization points per knot-span in v-direction
\arg -nw \a nw : Number of visualization points per knot-span in w-direction
\arg -hdf5 : Write primary and projected secondary solution to HDF5 file
\arg -2D : Use two-parametric simulation driver
\arg -adap : Use adaptive simulation driver with LR-splines discretization
*/
int main (int argc, char** argv)
{
Profiler prof(argv[0]);
utl::profiler->start("Initialization");
char* infile = nullptr;
DarcyArgs args;
IFEM::Init(argc,argv,"Darcy solver");
for (int i = 1; i < argc; i++)
if (args.parseArgComplex(argc,argv,i))
;
else if (argv[i] == infile || args.parseArg(argv[i]))
; // ignore the input file on the second pass
else if (SIMoptions::ignoreOldOptions(argc,argv,i))
; // ignore the obsolete option
else if (!infile) {
infile = argv[i];
if (!args.readXML(infile,false))
return 1;
i = 0;
}
else
std::cerr <<" ** Unknown option ignored: "<< argv[i] << std::endl;
if (!infile)
{
std::cout <<"usage: "<< argv[0]
<<" <inputfile> [-dense|-spr|-superlu[<nt>]|-samg|-petsc]\n"
<<" [-lag|-spec|-LR] [-1D|-2D] [-nGauss <n>] [-hdf5]\n"
<<" [-vtf <format> [-nviz <nviz>] [-nu <nu>] [-nv <nv>]"
<<" [-nw <nw>]]\n";
return 0;
}
if (args.adap)
IFEM::getOptions().discretization = ASM::LRSpline;
IFEM::cout <<"\nInput file: "<< infile;
IFEM::getOptions().print(IFEM::cout) << std::endl;
if (args.tracer)
IFEM::cout << "Including a tracer field." << std::endl;
if (args.timeMethod == TimeIntegration::BE)
IFEM::cout << "Using Backward-Euler time stepping." << std::endl;
else if (args.timeMethod == TimeIntegration::BDF2)
IFEM::cout << "Using BDF2 time stepping." << std::endl;
if (args.scheduled) {
IFEM::cout << "Including a tracer field." << std::endl;
IFEM::cout << "Updating pressure according to a schedule." << std::endl;
}
utl::profiler->stop("Initialization");
if (args.dim == 3)
return runSimulator1<SIM3D>(infile,args);
else if (args.dim == 2)
return runSimulator1<SIM2D>(infile,args);
else
return runSimulator1<SIM1D>(infile,args);
}