-
Notifications
You must be signed in to change notification settings - Fork 9
/
particle_interaction_model.cpp
99 lines (84 loc) · 3.1 KB
/
particle_interaction_model.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
#include "particle_interaction_model.h"
Particle_interaction_model::Particle_interaction_model( Config &conf )
{
check_correctness_of_related_config_fields( conf );
get_values_from_config( conf );
}
Particle_interaction_model::Particle_interaction_model(
hid_t h5_particle_interaction_model_group )
{
herr_t status;
char h5_str_read_buffer[100]; // 'noninteracting' is the longest possible string
status = H5LTget_attribute_string( h5_particle_interaction_model_group, "./",
"particle_interaction_model",
h5_str_read_buffer );
hdf5_status_check( status );
particle_interaction_model = std::string( h5_str_read_buffer );
noninteracting = binary = pic = false;
if( particle_interaction_model == "noninteracting" ){
noninteracting = true;
} else if ( particle_interaction_model == "binary" ){
binary = true;
} else if ( particle_interaction_model == "PIC" ){
pic = true;
}
status = H5Gclose(h5_particle_interaction_model_group);
hdf5_status_check( status );
}
void Particle_interaction_model::check_correctness_of_related_config_fields( Config &conf )
{
std::string mode =
conf.particle_interaction_model_config_part.particle_interaction_model;
// 'noninteracting', 'binary', 'PIC'
if( mode != "noninteracting" && mode != "binary" && mode != "PIC" ){
std::cout << "Error: wrong value of 'particle_interaction_model': " + mode
<< std::endl;
std::cout << "Allowed values : 'noninteracting', 'binary', 'PIC'" << std::endl;
std::cout << "Aborting" << std::endl;
exit( EXIT_FAILURE );
}
}
void Particle_interaction_model::get_values_from_config( Config &conf )
{
noninteracting = binary = pic = false;
particle_interaction_model =
conf.particle_interaction_model_config_part.particle_interaction_model;
// todo: rewrite in civilized way.
if( particle_interaction_model == "noninteracting" ){
noninteracting = true;
} else if ( particle_interaction_model == "binary" ){
binary = true;
} else if ( particle_interaction_model == "PIC" ){
pic = true;
}
}
void Particle_interaction_model::print()
{
std::cout << "### Particle_interaction_model:" << std::endl;
std::cout << "Particle interaction model = "
<< particle_interaction_model << std::endl;
return;
}
void Particle_interaction_model::write_to_file( hid_t hdf5_file_id )
{
hid_t group_id;
herr_t status;
std::string hdf5_groupname = "/ParticleInteractionModel";
group_id = H5Gcreate( hdf5_file_id, hdf5_groupname.c_str(),
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
hdf5_status_check( group_id );
status = H5LTset_attribute_string( hdf5_file_id, hdf5_groupname.c_str(),
"particle_interaction_model",
particle_interaction_model.c_str() );
hdf5_status_check( status );
status = H5Gclose(group_id); hdf5_status_check( status );
return;
}
void Particle_interaction_model::hdf5_status_check( herr_t status )
{
if( status < 0 ){
std::cout << "Something went wrong while reading or writing Particle_interaction_model group. Aborting."
<< std::endl;
exit( EXIT_FAILURE );
}
}