29 #include <boost/algorithm/string/classification.hpp> 30 #include <boost/algorithm/string/split.hpp> 31 #include <boost/algorithm/string/trim.hpp> 32 #include <boost/lexical_cast.hpp> 37 std::istream& input_stream_)
43 std::istream& input_stream_,
const std::string& delimiters_)
50 std::istream& input_stream_,
const std::string& delimiters_,
51 const std::string& line_comment_start_)
69 if (!input_stream.good()) {
70 throw IO_error(
"cannot read from provided stream");
77 while (std::getline(input_stream, line)) {
87 throw IO_error(
"no valid grid points found");
92 +
" points from input stream");
94 "Found values for " + std::to_string(
n_fields)
101 if (pos != std::string::npos) {
102 line = line.substr(0, pos);
108 std::vector<std::string> fields;
109 boost::split(fields, line, boost::is_any_of(
delimiters),
110 boost::token_compress_on);
112 if (fields.empty()) {
113 throw IO_error(
"no valid fields found in line: " + line);
116 const std::size_t current_n_fields = fields.size() - 1;
117 if (current_n_fields == 0) {
118 throw IO_error(
"no field values given in line: " + line);
123 throw IO_error(
"incorrect number of fields in line: " + line);
132 const double grid_value = boost::lexical_cast<
double>(fields[0]);
135 for (std::size_t i = 0; i <
n_fields; ++i) {
136 const double field_value = boost::lexical_cast<
double>(fields[i + 1]);
139 }
catch (
const boost::bad_lexical_cast& error) {
140 throw IO_error(
"unable to read input data in line: " + line);
146 const Eigen::VectorXd& ,
147 int n_dimensions,
double domain_start,
double domain_end,
148 double initial_step_size,
double interpolation_points_fraction)
153 "number of fields in guess does not match number in potential");
156 const double stored_domain_start =
spatial_grid.front();
159 if (domain_start >= 0.) {
160 if (
Abs(stored_domain_start - domain_start) >
tolerance) {
162 "stored domain start does not match requested domain start");
166 if (domain_end >= 0.) {
169 "stored domain end does not match requested domain end");
178 if (domain_start >= 0. && domain_end >= 0.) {
179 const std::size_t requested_n_grid_points = 1 +
static_cast<std::size_t
>(
180 std::ceil((domain_end - domain_start) / initial_step_size));
183 "number of stored grid points does not match desired grid size");
185 const double rho_incr = (domain_end - domain_start) /
186 (requested_n_grid_points - 1.);
187 for (std::size_t i = 0; i < requested_n_grid_points; ++i) {
188 const double current_rho = domain_start + i * rho_incr;
190 throw Setup_error(
"spatial coordinate at grid point " 192 +
" does not match required value");
200 Field_profiles profile_guess(grid, profiles, interpolation_points_fraction);
203 return profile_guess;
208 Eigen::VectorXd grid(
216 Eigen::MatrixXd profiles(n_grid_points,
n_fields);
217 for (std::size_t i = 0; i <
n_fields; ++i) {
contains the definition of the Field_profiles clas
std::string line_comment_start
contains the definition of the Instream_profile_guesser class
void log_message(Log_level level, const std::string &msg) const
logging::Basic_logger logger
std::vector< double > spatial_grid
Eigen::MatrixXd get_field_values() const
returns the values of the fields read from the stream
Eigen::VectorXd get_spatial_grid() const
returns the values of the spacetime coordinate read from the stream
void set_number_of_dimensions(int d)
void strip_comments(std::string &) const
Exception indicating generic input/output error.
std::vector< std::vector< double > > field_values
void read_profiles(std::istream &)
read a profile guess from the given stream
virtual Field_profiles get_profile_guess(const Potential &, const Eigen::VectorXd &, int, double, double, double, double) override
Calculate an initial guess for the bubble profile.
virtual std::size_t get_number_of_fields() const =0
Exception indicating general setup error.
Abstract base class for a generic potential.
void process_line(const std::string &)
Discretized set of field profiles.
Instream_profile_guesser(std::istream &)
reads a profile guess from the given input stream