-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (79 loc) · 2.4 KB
/
main.cpp
File metadata and controls
98 lines (79 loc) · 2.4 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
#include <iostream>
#include <vector>
#include <boost/bind.hpp>
#include <boost/program_options.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct Point {
double x;
double z;
};
struct Vector {
double Bx;
double Bz;
};
struct Loop {
double R;
double Z;
double I;
};
typedef std::vector<Point> mesh_t;
typedef std::vector<Vector> field_t;
typedef std::vector<Loop> loop_t;
BOOST_FUSION_ADAPT_STRUCT(
Point,
(double, x)
(double, z)
)
BOOST_FUSION_ADAPT_STRUCT(
Loop,
(double, R)
(double, Z)
(double, I)
)
BOOST_FUSION_ADAPT_STRUCT(
Vector,
(double, Bx)
(double, Bz)
)
#include "calculator.hpp"
#include "reader.hpp"
#include "outputter.hpp"
struct compute_field {
typedef void result_type;
void operator()(const Loop& loop, const mesh_t& iMesh, field_t& ioField) const {
magnetic_field(loop.R, loop.Z, loop.I, iMesh, ioField);
}
};
int main(int argc, char* argv[]) {
std::string mesh_filename, geometry_filename, field_filename;
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("mesh", boost::program_options::value<std::string>(&mesh_filename)->default_value("mesh.csv"), "name of the file containing the mesh.")
("geometry", boost::program_options::value<std::string>(&geometry_filename)->default_value("loops.csv"), "name of the file containing the geometry of current loops")
("field", boost::program_options::value<std::string>(&field_filename)->default_value("field.csv"), "name of the output file with computation of field")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
mesh_t aMesh;
field_t aField;
loop_t aGeometry;
reader geometry_reader(geometry_filename);
reader mesh_reader(mesh_filename);
geometry_reader(aGeometry);
mesh_reader(aMesh);
size_t elements_number = aMesh.size();
Vector null_vector = {0,0};
for(size_t index; index < elements_number; ++index) {
aField.push_back(null_vector);
}
std::for_each(aGeometry.begin(),aGeometry.end(),boost::bind(compute_field(),::_1,boost::cref(aMesh),boost::ref(aField)) );
writer write_field(field_filename);
write_field(aMesh, aField);
return 0;
}