-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
91 lines (83 loc) · 2.92 KB
/
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
// #include <iostream>
// #include "FDTDField.hpp"
// #include "FDTDFieldTE.hpp"
// #include "FDTDFieldTM.hpp"
#include <FDTD_MANAGER/parallelFDTDField.hpp>
// #include <iomanip>
namespace mpi = boost::mpi;
int main(int argc, char const *argv[])
{
// Initialize the boost mpi environment and communicator
mpi::environment env;
std::shared_ptr<mpiInterface> gridComm = std::make_shared<mpiInterface>();
std::clock_t start;
std::string filename;
double duration= 0.0;
start = std::clock();
if (argc < 2)
{
std::cout << "Provide an input json file" << std::endl;
exit(1);
}
else
{
// Take in the file name and strip out all comments for the parser
filename = argv[1];
if(gridComm->rank() == 0)
stripComments(filename);
else
filename = "stripped_" + filename;
}
gridComm->barrier();
if(gridComm->rank() == 0)
std::cout << "Reading input file " << argv[1] << "..." << std::endl;
//construct the parser and pass it to the inputs
boost::property_tree::ptree propTree;
boost::property_tree::json_parser::read_json(filename,propTree);
parallelProgramInputs IP(propTree, filename);
gridComm->barrier();
if(gridComm->rank() == 0)
boost::filesystem::remove(filename) ;
if(gridComm->rank() == 0)
std::cout << "I TOOK ALL THE INPUT PARAMETERS" << std::endl;
double maxT = IP.tMax();
parallelFDTDFieldReal FF(IP, gridComm);
if(gridComm->rank() == 0)
std::cout << "made" << std::endl;
int nSteps = int(std::ceil( IP.tMax_ / (IP.courant_/IP.res_) ) );
for(int tt = 0; tt < nSteps; ++tt )
FF.step();
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
for(int ii = 0; ii < gridComm->size(); ii ++)
{
gridComm->barrier();
if(gridComm->rank() == ii)
std::cout << gridComm->rank() << "\t" << duration<<std::endl;
}
// Output the final flux for all flux objects, Polarization terms are because of units for continuous boxes defined by the z component (TE off grid is E fields, TM H fields)
for(auto & flux : FF.fluxArr() )
{
// flux->getFlux(FF.E_incd(), FF.H_incd(), FF.H_mn_incd());
if(FF.Ez_)
flux->getFlux(FF.E_incd(), FF.H_incd(), FF.H_mn_incd(), true);
else
flux->getFlux(FF.E_incd(), FF.H_incd(), FF.E_pl_incd(), false);
}
// Power outputs need incident fields for normalization
for(auto & dtc : FF.dtcFreqArr())
{
if(dtc->pow())
dtc->toFile(FF.E_incd(), FF.dt());
else
dtc->toFile();
}
// output scaling information
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
for(int ii = 0; ii < gridComm->size(); ii ++)
{
gridComm->barrier();
if(gridComm->rank() == ii)
std::cout << gridComm->rank() << "\t" << duration<<std::endl;
}
return 0;
}