Skip to content

Commit

Permalink
Add 'precision' non-mandatory options for ForceEnergy and PotentialEn…
Browse files Browse the repository at this point in the history
…ergy observables
  • Loading branch information
mlsample committed Apr 20, 2024
1 parent dbdc726 commit 7def8c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Observables/ForceEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void ForceEnergy::get_settings(input_file &my_inp, input_file &sim_inp) {
BaseObservable::get_settings(my_inp, sim_inp);

getInputString(&my_inp, "print_group", _group_name, 0);
getInputString(&my_inp, "precision", _precision, 0);
}

std::string ForceEnergy::get_output_string(llint curr_step) {
Expand All @@ -37,5 +38,10 @@ std::string ForceEnergy::get_output_string(llint curr_step) {
}
U /= _config_info->N();

return Utils::sformat("% 10.6lf", U);
if (_precision == "") {
return Utils::sformat("% 10.6lf", U);
}
else {
return Utils::sformat("% 10." + _precision + "lf", U);
}
}
1 change: 1 addition & 0 deletions src/Observables/ForceEnergy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class ForceEnergy: public BaseObservable {
protected:
std::string _group_name;
std::string _precision;
public:
ForceEnergy();
virtual ~ForceEnergy();
Expand Down
15 changes: 13 additions & 2 deletions src/Observables/PotentialEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,31 @@ void PotentialEnergy::get_settings(input_file &my_inp, input_file &sim_inp) {
BaseObservable::get_settings(my_inp, sim_inp);

getInputBool(&my_inp, "split", &_split, 0);
getInputString(&my_inp, "precision", _precision, 0);
}

std::string PotentialEnergy::get_output_string(llint curr_step) {
if(!_split) {
number energy = get_potential_energy();

return Utils::sformat("% 10.6lf", energy);
if (_precision == "") {
return Utils::sformat("% 10.6lf", energy);
}
else {
return Utils::sformat("% 10." + _precision + "lf", energy);
}
}
else {
std::string res("");
auto energies = _config_info->interaction->get_system_energy_split(_config_info->particles(), _config_info->lists);
for(auto energy_item : energies) {
number contrib = energy_item.second / _config_info->N();
res = Utils::sformat("%s % 10.6lf", res.c_str(), contrib);
if (_precision == "") {
res = Utils::sformat("%s % 10.6lf", res.c_str(), contrib);
}
else {
res = Utils::sformat("%s % 10." + _precision + "lf", res.c_str(), contrib);
}
}

return res;
Expand Down
2 changes: 2 additions & 0 deletions src/Observables/PotentialEnergy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
class PotentialEnergy: public BaseObservable {
protected:
bool _split;
std::string _precision;

public:
PotentialEnergy();
virtual ~PotentialEnergy();
Expand Down

0 comments on commit 7def8c7

Please sign in to comment.