ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
TuningLogger.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <config/config.hpp>
25
26#if defined(ESPRESSO_P3M) || defined(ESPRESSO_DP3M)
27
28#include <utils/Vector.hpp>
29
30#include <cstdio>
31#include <string>
32
34public:
35 enum class Mode { Coulomb, Dipolar };
36 TuningLogger(bool verbose, std::string name, Mode mode)
37 : m_verbose{verbose}, m_name{std::move(name)}, m_mode{mode} {}
38
39 void log_tuning_start() const {
40 if (m_verbose) {
41 std::printf("mesh cao r_cut_iL alpha_L err "
42 "rs_err ks_err time [ms]\n");
43 }
44 }
45
46 template <typename... Types>
47 void log_success(double time, Types... parameter_set) const {
48 if (m_verbose) {
49 row(parameter_set...);
50 std::printf(" %-8.2f\n", time);
51 }
52 }
53
54 template <typename... Types>
55 void log_skip(std::string const &reason, Types... parameter_set) const {
56 if (m_verbose) {
57 row(parameter_set...);
58 std::printf(" %s\n", reason.c_str());
59 }
60 }
61
62 void log_cao_too_large(int mesh, int cao) const {
63 if (m_verbose) {
64 std::printf("%-4d %-3d cao too large for this mesh\n", mesh, cao);
65 }
66 }
67
68 void tuning_goals(double accuracy, double prefactor, double box_l,
69 std::size_t n_particles, double sum_prop) const {
70 if (m_verbose) {
71 std::string particle_trait;
72 std::string particle_property;
73 switch (m_mode) {
74 case Mode::Coulomb:
75 particle_trait = "charged";
76 particle_property = "Sum[q_i^2]";
77 break;
78 case Mode::Dipolar:
79 particle_trait = "magnetic";
80 particle_property = "Sum[mu_i^2]";
81 break;
82 }
83 std::printf("%s tune parameters: Accuracy goal = %.5e prefactor = %.5e\n"
84 "System: box_l = %.5e # %s part = %zu %s = %.5e\n",
85 m_name.c_str(), accuracy, prefactor, box_l,
86 particle_trait.c_str(), n_particles,
87 particle_property.c_str(), sum_prop);
88 }
89 }
90
91 void tuning_results(Utils::Vector3i const &mesh, int cao, double r_cut_iL,
92 double alpha_L, double accuracy, double time) const {
93 if (m_verbose) {
94 std::printf(
95 "\nresulting parameters: mesh: (%d, %d, %d), cao: %d, r_cut_iL: %.4e,"
96 "\n alpha_L: %.4e, accuracy: %.4e, time: %.2f\n",
97 mesh[0], mesh[1], mesh[2], cao, r_cut_iL, alpha_L, accuracy, time);
98 }
99 }
100
101 void report_fixed_cao(int cao) const {
102 if (m_verbose) {
103 std::printf("fixed cao %d\n", cao);
104 }
105 }
106
107 void report_fixed_r_cut_iL(double r_cut_iL) const {
108 if (m_verbose) {
109 std::printf("fixed r_cut_iL %f\n", r_cut_iL);
110 }
111 }
112
113 void report_fixed_mesh(Utils::Vector3i const &mesh) const {
114 if (m_verbose) {
115 std::printf("fixed mesh (%d, %d, %d)\n", mesh[0], mesh[1], mesh[2]);
116 }
117 }
118
119 auto const &get_name() const { return m_name; }
120
121private:
122 bool m_verbose;
123 std::string m_name;
124 Mode m_mode;
125
126 void row(int mesh, int cao, double r_cut_iL, double alpha_L, double accuracy,
127 double rs_err, double ks_err) const {
128 std::printf("%-4d %-3d %.5e %.5e %.3e %.3e %.3e", mesh, cao, r_cut_iL,
129 alpha_L, accuracy, rs_err, ks_err);
130 }
131};
132
133#endif // ESPRESSO_P3M or ESPRESSO_DP3M
Vector implementation and trait types for boost qvm interoperability.
TuningLogger(bool verbose, std::string name, Mode mode)
void log_tuning_start() const
void report_fixed_mesh(Utils::Vector3i const &mesh) const
void log_cao_too_large(int mesh, int cao) const
auto const & get_name() const
void report_fixed_cao(int cao) const
void tuning_results(Utils::Vector3i const &mesh, int cao, double r_cut_iL, double alpha_L, double accuracy, double time) const
void log_success(double time, Types... parameter_set) const
void report_fixed_r_cut_iL(double r_cut_iL) const
void tuning_goals(double accuracy, double prefactor, double box_l, std::size_t n_particles, double sum_prop) const
void log_skip(std::string const &reason, Types... parameter_set) const
STL namespace.