46 std::vector<T> m_values;
74 template <
typename Z = T>
83 std::getline(input_file_stream, line);
84 std::getline(input_file_stream, line);
88 std::getline(input_file_stream, line);
91 std::vector<std::string> splitted_line;
93 boost::trim_if(line, boost::is_any_of(
" \t"));
94 boost::split(splitted_line, line, boost::is_any_of(
" \t"), boost::token_compress_on);
96 const auto number_of_atoms = std::stoi(splitted_line[0]);
100 size_t grid_size {1};
101 for (
size_t i = 0; i < 3; i++) {
102 std::getline(input_file_stream, line);
105 boost::trim_if(line, boost::is_any_of(
" \t"));
106 boost::split(splitted_line, line, boost::is_any_of(
" \t"), boost::token_compress_on);
109 grid_size *=
static_cast<size_t>(std::stoll(splitted_line[0]));
114 for (
size_t i = 0; i < number_of_atoms; i++) {
115 std::getline(input_file_stream, line);
120 std::vector<double> field_values;
121 field_values.reserve(grid_size);
123 while (std::getline(input_file_stream, line)) {
126 boost::trim_if(line, boost::is_any_of(
" \t"));
127 boost::split(splitted_line, line, boost::is_any_of(
" \t"), boost::token_compress_on);
130 for (
const auto&
value : splitted_line) {
131 field_values.push_back(std::stod(
value));
135 input_file_stream.close();
165 std::string filename_extension;
166 std::string::size_type idx = filename.rfind(
'.');
168 if (idx != std::string::npos) {
169 filename_extension = filename.substr(idx + 1);
171 throw std::invalid_argument(
"Field::ReadGridFile(const std::string&): I did not find an extension in your given file name.");
176 if ((filename_extension !=
"rgrid") && (filename_extension !=
"igrid")) {
177 throw std::invalid_argument(
"Field::ReadGridFile(const std::string&): The given file is not an .igrid- or .rgrid-file.");
182 std::ifstream input_file_stream {filename};
183 if (!input_file_stream.good()) {
184 throw std::invalid_argument(
"validateAndOpen(const std::string&, const std::string&): The provided file name is illegible. Maybe you specified a wrong path?");
189 std::vector<Vector<double, N>> field_values;
192 while (std::getline(input_file_stream, line)) {
193 std::vector<std::string> splitted_line;
196 boost::trim_if(line, boost::is_any_of(
" \t"));
197 boost::split(splitted_line, line, boost::is_any_of(
" \t"), boost::token_compress_on);
202 std::vector<double> field_value_vector;
203 for (
size_t index = 4; index < 4 + N; index++) {
204 field_value_vector.push_back(std::stod(splitted_line[index]));
206 Eigen::Map<Eigen::VectorXd> field_value {field_value_vector.data(), N};
212 input_file_stream.close();
235 std::transform(this->m_values.begin(), this->m_values.end(), rhs.
values().begin(),
236 this->m_values.begin(), std::plus<T>());
266 std::vector<T> result;
267 result.reserve(this->
size());
269 std::transform(this->m_values.begin(), this->m_values.end(),
270 std::back_inserter(result), std::negate<T>());
317 size_t size()
const {
return this->m_values.size(); }
329 void map(
const std::function<
T(
const T&)>& function) {
331 std::transform(this->m_values.begin(), this->m_values.end(), this->m_values.begin(),
345 auto this_copy = *
this;
346 this_copy.map(function);
363 const T&
value(
const size_t index)
const {
return this->m_values[index]; }
372 T&
value(
const size_t index) {
return this->m_values[index]; }
377 const std::vector<T>&
values()
const {
return this->m_values; }
385template <
typename Scalar>
388template <
typename Scalar>
T_ T
Definition: Field.hpp:42
Field< T > operator-() const
Definition: Field.hpp:264
friend Field< T > operator+(Field< T > lhs, const Field< T > &rhs)
Definition: Field.hpp:252
const T & value(const size_t index) const
Definition: Field.hpp:363
static enable_if_t< std::is_same< Z, double >::value, Field< double > > ReadCubeFile(const std::string &filename)
Definition: Field.hpp:75
const std::vector< T > & values() const
Definition: Field.hpp:377
void map(const std::function< T(const T &)> &function)
Definition: Field.hpp:329
T & value(const size_t index)
Definition: Field.hpp:372
Field(const std::vector< T > &values)
Definition: Field.hpp:59
size_t size() const
Definition: Field.hpp:317
friend Field< T > operator-(Field< T > lhs, const Field< T > &rhs)
Definition: Field.hpp:303
Field< T > & operator+=(const Field< T > &rhs)
Definition: Field.hpp:233
Field< T > mapped(const std::function< T(const T &)> &function) const
Definition: Field.hpp:343
Field< T > & operator-=(const Field< T > &rhs)
Definition: Field.hpp:285
static Field< Vector< double, N > > ReadGridFile(const std::string &filename)
Definition: Field.hpp:162
Definition: Matrix.hpp:47
Definition: BaseOneElectronIntegralBuffer.hpp:25
typename std::enable_if< B, T >::type enable_if_t
Definition: type_traits.hpp:37
std::ifstream validateAndOpen(const std::string &filename, const std::string &extension)
Definition: miscellaneous.cpp:266