-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.cpp
133 lines (130 loc) · 7.07 KB
/
config.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
#include "config.h"
Config::Config( const std::string &filename )
{
try {
using boost::property_tree::ptree;
ptree pt;
read_ini(filename, pt);
for( auto §ions : pt ) {
std::string section_name = sections.first.data();
if ( section_name.find( "TimeGrid" ) != std::string::npos ) {
time_config_part = Time_config_part( sections.second );
} else if ( section_name.find( "SpatialMesh" ) != std::string::npos ) {
mesh_config_part = Mesh_config_part( sections.second );
} else if (
section_name.find( "ParticleSourceBox." ) != std::string::npos ) {
std::string source_name = section_name.substr(section_name.find(".") + 1);
sources_config_part.push_back(
new Particle_source_box_config_part( source_name, sections.second ) );
} else if (
section_name.find( "ParticleSourceCylinder." ) != std::string::npos ) {
std::string source_name = section_name.substr(section_name.find(".") + 1);
sources_config_part.push_back(
new Particle_source_cylinder_config_part(
source_name, sections.second ) );
} else if (
section_name.find("ParticleSourceTubeAlongZ." ) != std::string::npos){
std::string source_name = section_name.substr(section_name.find(".") + 1);
sources_config_part.push_back(
new Particle_source_tube_along_z_config_part(
source_name, sections.second ) );
} else if ( section_name.find( "InnerRegionBox." ) != std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_box_config_part(
inner_region_name, sections.second ) );
} else if ( section_name.find("InnerRegionSphere.") != std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_sphere_config_part(
inner_region_name, sections.second ) );
} else if (
section_name.find( "InnerRegionCylinder." ) != std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_cylinder_config_part(
inner_region_name, sections.second ) );
} else if ( section_name.find( "InnerRegionTube." ) != std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_tube_config_part(
inner_region_name, sections.second ) );
} else if ( section_name.find( "InnerRegionTubeAlongZSegment." )
!= std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_tube_along_z_segment_config_part(
inner_region_name, sections.second ) );
} else if ( section_name.find( "InnerRegionConeAlongZ." )
!= std::string::npos ) {
std::string inner_region_name =
section_name.substr( section_name.find(".") + 1 );
inner_regions_config_part.push_back(
new Inner_region_cone_along_z_config_part(
inner_region_name, sections.second ) );
} else if ( section_name.find( "BoundaryConditions" ) != std::string::npos ) {
boundary_config_part = Boundary_config_part( sections.second );
} else if ( section_name.find(
"ExternalMagneticFieldUniform" ) != std::string::npos ) {
std::string field_name =
section_name.substr( section_name.find(".") + 1 );
fields_config_part.push_back(
new External_magnetic_field_uniform_config_part(
field_name, sections.second ) );
} else if ( section_name.find(
"ExternalElectricFieldUniform" ) != std::string::npos ) {
std::string field_name =
section_name.substr( section_name.find(".") + 1 );
fields_config_part.push_back(
new External_electric_field_uniform_config_part(
field_name, sections.second ) );
} else if ( section_name.find(
"ExternalMagneticFieldTinyexpr" ) != std::string::npos ) {
std::string field_name =
section_name.substr( section_name.find(".") + 1 );
fields_config_part.push_back(
new External_magnetic_field_tinyexpr_config_part(
field_name, sections.second ) );
} else if ( section_name.find(
"ExternalElectricFieldTinyexpr" ) != std::string::npos ) {
std::string field_name =
section_name.substr( section_name.find(".") + 1 );
fields_config_part.push_back(
new External_electric_field_tinyexpr_config_part(
field_name, sections.second ) );
} else if (
section_name.find( "ExternalElectricFieldOnRegularGrid" ) != std::string::npos
||
section_name.find("ExternalFieldElectricOnRegularGridFromH5File" )
!= std::string::npos ) {
std::string field_name =
section_name.substr( section_name.find(".") + 1 );
fields_config_part.push_back(
new External_electric_field_on_regular_grid_config_part(
field_name, sections.second ) );
} else if (
section_name.find( "ParticleInteractionModel" ) != std::string::npos ) {
particle_interaction_model_config_part =
Particle_interaction_model_config_part( sections.second );
} else if ( section_name.find( "OutputFilename" ) != std::string::npos ) {
output_filename_config_part =
Output_filename_config_part( sections.second );
} else {
std::cout << "Warning! Unknown section: " << section_name << std::endl;
}
}
return;
}
catch( std::exception& e ) {
std::cerr << "error: " << e.what() << "\n";
exit( EXIT_FAILURE);
}
catch( ... ) {
std::cerr << "Exception of unknown type!\n";
}
}