-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cc
105 lines (76 loc) · 2.41 KB
/
main.cc
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
/******************************************************************************
$Id: main.cc,v 1.21 2005/04/13 15:06:11 parteli Exp $
******************************************************************************/
#include <time.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <unistd.h>
#include "globals.h"
#include "dune_evolution.h"
//! Application class.
class CApp {
public:
CApp(int argc, char **argv);
virtual ~CApp();
//! Execute the simulation
virtual int Run();
private:
/*! Class handling parameter file. */
dunepar m_para;
/*! New top-level simulation object */
evolution *m_evol;
};
/*! Constructor scans command line and parameter file for global parameters.
The name of the parameter file can be given on the command line by
"parafile=..." and defaults to "default.par". The unique instance of the
duneglobals class is created via duneglobals::initialise(). Depending on the
parameter file version, a CPde object (for backward compatibility; version <
2.0) or a dune_evolution object is created. */
CApp::CApp(int argc, char **argv) : m_evol(0)
{
struct utsname u;
time_t t= time(NULL);
if( !uname(&u) )
cout << "Running on " << u.nodename << ", machine type " << u.machine << ", with process id " << getpid() << "\n";
cout << ctime( &t ) << "\n";
// find name for parameter file
// Format for command line arguments: <token>=<value>, for instance
// parafile=myparms.par
m_para.scan(argc, argv);
// Initialise global parameter object:
duneglobals::initialise( m_para );
m_evol= new dune_evol_3d(m_para);
}
/*! Destructor deletes all objects created in the constructor. */
CApp::~CApp()
{
delete m_evol;
}
int CApp::Run()
{
int iNt = m_para.getrequired<int>("Nt");
int iNt0 = m_para.getdefault<int>("Nt0", 0);
int saveinterval = m_para.getrequired<int>( "save.every" );
int step, savecounter;
savecounter= saveinterval - 1;
for (step= iNt; step > iNt0; --step, --savecounter) {
m_evol->step();
cout << "Main program: step " << evolution::steps() << " done, time is " << evolution::time() << " seconds\n";
if( savecounter<=0 ) {
dunedata::save_all_data();
savecounter= saveinterval;
}
}
if( savecounter!=saveinterval-1 || iNt==0 )
dunedata::save_all_data();
return 0;
}
////////////////
// main
//
int main(int argc, char **argv)
{
CApp App(argc, argv);
App.Run();
return 0;
}