BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
thin_wall_observer.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * BubbleProfiler is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "thin_wall_observer.hpp"
19 #include "error.hpp"
20 #include "field_profiles.hpp"
21 
22 #include <iomanip>
23 
24 namespace BubbleProfiler {
25 
27  const std::string& output_file_)
28  : output_file(output_file_)
29 {
31 }
32 
34 {
35  if (!output_stream.is_open() || !output_stream.good()) {
36  throw IO_error("unable to write to file '" + output_file + "'");
37  }
38  output_stream << "# "
39  << std::setw(12) << "iteration" << ' '
40  << std::setw(16) << "rho" << ' '
41  << std::setw(16) << "perturbation" << ' '
42  << std::setw(16) << "profile"
43  << std::endl;
44 }
45 
47  const Field_profiles& perturbation)
48 {
49  if (!output_stream.is_open() || !output_stream.good()) {
50  throw IO_error("unable to write to file '" + output_file + "'");
51  }
52 
53  const auto coord_values = profile.get_spatial_grid();
54  const auto numerical_values = profile.get_field_profiles();
55  const auto perturbation_values = perturbation.get_field_profiles();
56 
57  const int n_grid_points = coord_values.size();
58  for (int i = 0; i < n_grid_points; ++i) {
59  output_stream << " "
60  << std::setw(12) << iteration_count << ' '
61  << std::setw(16) << std::setprecision(8)
62  << std::scientific << coord_values(i) << ' '
63  << std::setw(16) << std::setprecision(8)
64  << std::scientific << perturbation_values(i, 0) << ' '
65  << std::setw(16) << std::setprecision(8)
66  << std::scientific << numerical_values(i, 0) << std::endl;
67  }
68 }
69 
71  const Field_profiles& perturbation)
72 {
73  if (iteration_count == 0) {
75  }
76  write_data(profile, perturbation);
78 }
79 
80 } // namespace BubbleProfiler
contains the definition of the Field_profiles clas
const Eigen::VectorXd & get_spatial_grid() const
Get a vector of the grid point coordinates.
void write_data(const Field_profiles &, const Field_profiles &)
Thin_wall_observer(const std::string &output_file_)
Exception indicating generic input/output error.
Definition: error.hpp:122
void operator()(const Field_profiles &profile, const Field_profiles &perturbation)
Discretized set of field profiles.
const Eigen::MatrixXd & get_field_profiles() const
Get the field profile data in matrix form.