ASPECT
structured_data.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _aspect_structured_data_h
23 #define _aspect_structured_data_h
24 
25 #include <aspect/global.h>
27 
28 #include <array>
29 
30 namespace aspect
31 {
32  namespace Utilities
33  {
48  using namespace ::Utilities;
49 
69  template <int dim>
71  {
72  public:
82  StructuredDataLookup(const unsigned int n_components,
83  const double scale_factor);
84 
91  explicit StructuredDataLookup(const double scale_factor);
92 
128  void reinit(const std::vector<std::string> &column_names,
129  std::vector<std::vector<double>> &&coordinate_values,
130  std::vector<Table<dim,double>> &&data_table,
131  const MPI_Comm mpi_communicator = MPI_COMM_SELF,
132  const unsigned int root_process = numbers::invalid_unsigned_int);
133 
151  void
152  load_ascii(const std::string &filename,
153  const MPI_Comm communicator);
154 
163  void
164  load_netcdf(const std::string &filename, const std::vector<std::string> &data_column_names = {});
165 
166 
181  void
182  load_file(const std::string &filename,
183  const MPI_Comm communicator);
184 
198  double
199  get_data(const Point<dim> &position,
200  const unsigned int component,
201  const bool crash_if_not_in_range = false) const;
202 
212  Tensor<1,dim>
213  get_gradients(const Point<dim> &position,
214  const unsigned int component);
215 
222  std::vector<std::string>
223  get_column_names() const;
224 
230  bool
232 
245  const std::vector<double> &
246  get_interpolation_point_coordinates(const unsigned int dimension) const;
247 
253  unsigned int
254  get_column_index_from_name(const std::string &column_name) const;
255 
261  std::string
262  get_column_name_from_index(const unsigned int column_index) const;
263 
267  double get_maximum_component_value(const unsigned int component) const;
268 
276  unsigned int get_number_of_coordinates(const unsigned int dimension) const;
277 
278  private:
282  unsigned int n_components;
283 
289  std::vector<std::string> data_component_names;
290 
296  std::vector<std::unique_ptr<Function<dim>>> data;
297 
301  std::array<std::vector<double>,dim> coordinate_values;
302 
306  std::vector<double> maximum_component_value;
307 
311  TableIndices<dim> table_points;
312 
317  const double scale_factor;
318 
324 
329  TableIndices<dim>
330  compute_table_indices(const TableIndices<dim> &sizes, const std::size_t idx) const;
331 
332  };
333 
338  template <int dim>
340  {
341  public:
345  AsciiDataBase();
346 
350  static
351  void
352  declare_parameters (ParameterHandler &prm,
353  const std::string &default_directory,
354  const std::string &default_filename,
355  const std::string &subsection_name = "Ascii data model");
356 
360  void
361  parse_parameters (ParameterHandler &prm,
362  const std::string &subsection_name = "Ascii data model");
363 
367  std::string data_directory;
368 
374  std::string data_file_name;
375 
382  double scale_factor;
383  };
384 
389  template <int dim>
391  {
392  public:
397 
402  virtual
403  void
404  initialize (const std::set<types::boundary_id> &boundary_ids,
405  const unsigned int components);
406 
413  void
414  update();
415 
419  double
420  get_data_component (const types::boundary_id boundary_indicator,
421  const Point<dim> &position,
422  const unsigned int component) const;
423 
427  double
428  get_maximum_component_value (const types::boundary_id boundary_indicator,
429  const unsigned int component) const;
430 
434  Tensor<1,dim-1>
435  vector_gradient(const types::boundary_id boundary_indicator,
436  const Point<dim> &p,
437  const unsigned int component) const;
438 
455  static
456  void
457  declare_parameters (ParameterHandler &prm,
458  const std::string &default_directory,
459  const std::string &default_filename,
460  const std::string &subsection_name = "Ascii data model",
461  const bool declare_time_dependent_parameters = true);
462 
476  void
477  parse_parameters (ParameterHandler &prm,
478  const std::string &subsection_name = "Ascii data model",
479  const bool parse_time_dependent_parameters = true);
480 
481  protected:
487 
493 
501 
507 
512  double time_weight;
513 
520 
525  std::map<types::boundary_id,
527 
531  std::map<types::boundary_id,
533 
537  void
538  update_data (const types::boundary_id boundary_id,
539  const bool reload_both_files);
540 
545  void
546  end_time_dependence ();
547 
551  std::string
552  create_filename (const int filenumber,
553  const types::boundary_id boundary_id) const;
554  };
555 
556 
557 
562  template <int dim>
564  {
565  public:
570 
575  virtual
576  void
577  initialize (const unsigned int components);
578 
579 
583  double
584  get_data_component (const Point<dim> &position,
585  const unsigned int component) const;
586 
590  static
591  void
592  declare_parameters (ParameterHandler &prm,
593  const std::string &default_directory,
594  const std::string &default_filename,
595  const std::string &subsection_name = "Ascii data model");
596 
600  void
601  parse_parameters (ParameterHandler &prm,
602  const std::string &subsection_name = "Ascii data model");
603 
604  protected:
609  std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim>> lookup;
610 
616  std::unique_ptr<aspect::Utilities::StructuredDataLookup<3>> slice_lookup;
617 
623 
629  Tensor<2,3> rotation_matrix;
630  };
631 
632 
637  template <int dim>
639  {
640  public:
645 
650  virtual
651  void
652  initialize (const unsigned int components);
653 
654 
658  double
659  get_data_component (const Point<dim> &position,
660  const unsigned int component) const;
661 
662 
666  static
667  void
668  declare_parameters (ParameterHandler &prm,
669  const std::string &default_directory,
670  const std::string &default_filename,
671  const std::string &subsection_name = "Ascii data model");
672 
676  void
677  parse_parameters (ParameterHandler &prm,
678  const std::string &subsection_name = "Ascii data model");
679 
680  protected:
685  std::vector<std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim-1>>> lookups;
686 
687  private:
688 
692  std::string data_directory;
693 
697  std::vector<std::string> data_file_names;
698 
703 
707  std::string interpolation_scheme;
708 
709 
710  };
711 
712 
716  template <int dim>
718  {
719  public:
724 
729  virtual
730  void
731  initialize (const MPI_Comm communicator);
732 
733 
737  double
738  get_data_component (const Point<1> &position,
739  const unsigned int component) const;
740 
747  std::vector<std::string>
748  get_column_names() const;
749 
764  const std::vector<double> &
766 
772  unsigned int
773  get_column_index_from_name(const std::string &column_name) const;
774 
780  unsigned int
781  maybe_get_column_index_from_name(const std::string &column_name) const;
782 
788  std::string
789  get_column_name_from_index(const unsigned int column_index) const;
790  protected:
795  std::unique_ptr<aspect::Utilities::StructuredDataLookup<1>> lookup;
796  };
797  }
798 }
799 
800 #endif
std::unique_ptr< aspect::Utilities::StructuredDataLookup< 3 > > slice_lookup
Tensor< 1, dim > get_gradients(const Point< dim > &position, const unsigned int component)
double get_data(const Point< dim > &position, const unsigned int component, const bool crash_if_not_in_range=false) const
std::string get_column_name_from_index(const unsigned int column_index) const
std::map< types::boundary_id, std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > lookups
void load_ascii(const std::string &filename, const MPI_Comm communicator)
std::vector< std::unique_ptr< Function< dim > > > data
double get_maximum_component_value(const unsigned int component) const
const std::vector< double > & get_interpolation_point_coordinates(const unsigned int dimension) const
std::vector< std::string > get_column_names() const
std::vector< std::string > data_component_names
void declare_parameters(ParameterHandler &prm)
void load_netcdf(const std::string &filename, const std::vector< std::string > &data_column_names={})
std::vector< std::string > data_file_names
std::vector< double > maximum_component_value
void load_file(const std::string &filename, const MPI_Comm communicator)
std::vector< std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > lookups
std::unique_ptr< aspect::Utilities::StructuredDataLookup< 1 > > lookup
Definition: compat.h:59
TableIndices< dim > compute_table_indices(const TableIndices< dim > &sizes, const std::size_t idx) const
std::map< types::boundary_id, std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > old_lookups
std::array< std::vector< double >, dim > coordinate_values
StructuredDataLookup(const unsigned int n_components, const double scale_factor)
void reinit(const std::vector< std::string > &column_names, std::vector< std::vector< double >> &&coordinate_values, std::vector< Table< dim, double >> &&data_table, const MPI_Comm mpi_communicator=MPI_COMM_SELF, const unsigned int root_process=numbers::invalid_unsigned_int)
unsigned int get_column_index_from_name(const std::string &column_name) const
unsigned int get_number_of_coordinates(const unsigned int dimension) const
std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim > > lookup