ASPECT
structured_data.h
Go to the documentation of this file.
1 // ------------------------------------------------------
2 //
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 //
5 // SPDX-FileCopyrightText: Copyright (C) 2014-2026 by the ASPECT authors.
6 //
7 // This file is part of ASPECT.
8 //
9 // Detailed license information governing the source code and
10 // contributions can be found in the folder LICENSES and in
11 // LICENSE and CONTRIBUTING.md at the top level directory.
12 //
13 // ------------------------------------------------------
14 
15 
16 #ifndef _aspect_structured_data_h
17 #define _aspect_structured_data_h
18 
19 #include <aspect/global.h>
21 
22 #include <array>
23 #include <set>
24 
25 namespace aspect
26 {
27  namespace Utilities
28  {
43  using namespace ::Utilities;
44 
64  template <int dim>
66  {
67  public:
77  StructuredDataLookup(const unsigned int n_components,
78  const double scale_factor);
79 
86  StructuredDataLookup(const unsigned int n_components,
87  const double scale_factor,
88  const std::set<unsigned int> &log_components);
89 
96  explicit StructuredDataLookup(const double scale_factor);
97 
133  void reinit(const std::vector<std::string> &column_names,
134  std::vector<std::vector<double>> &&coordinate_values,
135  std::vector<Table<dim,double>> &&data_table,
136  const MPI_Comm mpi_communicator = MPI_COMM_SELF,
137  const unsigned int root_process = numbers::invalid_unsigned_int);
138 
156  void
157  load_ascii(const std::string &filename,
158  const MPI_Comm communicator);
159 
168  void
169  load_netcdf(const std::string &filename, const std::vector<std::string> &data_column_names = {});
170 
171 
190  void
191  load_file(const std::string &filename,
192  const MPI_Comm communicator);
193 
207  double
208  get_data(const Point<dim> &position,
209  const unsigned int component,
210  const bool crash_if_not_in_range = false) const;
211 
222  get_gradients(const Point<dim> &position,
223  const unsigned int component);
224 
231  std::vector<std::string>
232  get_column_names() const;
233 
239  bool
241 
254  const std::vector<double> &
255  get_interpolation_point_coordinates(const unsigned int dimension) const;
256 
262  unsigned int
263  get_column_index_from_name(const std::string &column_name) const;
264 
270  std::string
271  get_column_name_from_index(const unsigned int column_index) const;
272 
276  double get_maximum_component_value(const unsigned int component) const;
277 
285  unsigned int get_number_of_coordinates(const unsigned int dimension) const;
286 
287  private:
291  unsigned int n_components;
292 
298  std::vector<std::string> data_component_names;
299 
305  std::vector<std::unique_ptr<Function<dim>>> data;
306 
310  std::array<std::vector<double>,dim> coordinate_values;
311 
315  std::vector<double> maximum_component_value;
316 
321 
326  const double scale_factor;
327 
332  std::set<unsigned int> log_components;
333 
339 
345  compute_table_indices(const TableIndices<dim> &sizes, const std::size_t idx) const;
346 
347  };
348 
353  template <int dim>
355  {
356  public:
360  AsciiDataBase();
361 
365  static
366  void
368  const std::string &default_directory,
369  const std::string &default_filename,
370  const std::string &subsection_name = "Ascii data model");
371 
375  void
376  parse_parameters (ParameterHandler &prm,
377  const std::string &subsection_name = "Ascii data model");
378 
382  std::string data_directory;
383 
389  std::string data_file_name;
390 
397  double scale_factor;
398  };
399 
404  template <int dim>
406  {
407  public:
412 
417  virtual
418  void
419  initialize (const std::set<types::boundary_id> &boundary_ids,
420  const unsigned int components);
421 
428  void
429  update();
430 
434  double
435  get_data_component (const types::boundary_id boundary_indicator,
436  const Point<dim> &position,
437  const unsigned int component) const;
438 
442  double
443  get_maximum_component_value (const types::boundary_id boundary_indicator,
444  const unsigned int component) const;
445 
449  Tensor<1,dim-1>
450  vector_gradient(const types::boundary_id boundary_indicator,
451  const Point<dim> &p,
452  const unsigned int component) const;
453 
470  static
471  void
473  const std::string &default_directory,
474  const std::string &default_filename,
475  const std::string &subsection_name = "Ascii data model",
476  const bool declare_time_dependent_parameters = true);
477 
491  void
492  parse_parameters (ParameterHandler &prm,
493  const std::string &subsection_name = "Ascii data model",
494  const bool parse_time_dependent_parameters = true);
495 
496  protected:
502 
508 
516 
522 
527  double time_weight;
528 
535 
540  std::map<types::boundary_id,
542 
546  std::map<types::boundary_id,
548 
552  void
553  update_data (const types::boundary_id boundary_id,
554  const bool reload_both_files);
555 
560  void
561  end_time_dependence ();
562 
566  std::string
567  create_filename (const int filenumber,
568  const types::boundary_id boundary_id) const;
569  };
570 
571 
572 
577  template <int dim>
579  {
580  public:
585 
590  virtual
591  void
592  initialize (const unsigned int components);
593 
594 
598  double
599  get_data_component (const Point<dim> &position,
600  const unsigned int component) const;
601 
605  static
606  void
608  const std::string &default_directory,
609  const std::string &default_filename,
610  const std::string &subsection_name = "Ascii data model");
611 
615  void
616  parse_parameters (ParameterHandler &prm,
617  const std::string &subsection_name = "Ascii data model");
618 
619  protected:
624  std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim>> lookup;
625 
631  std::unique_ptr<aspect::Utilities::StructuredDataLookup<3>> slice_lookup;
632 
638 
645  };
646 
647 
652  template <int dim>
654  {
655  public:
660 
665  virtual
666  void
667  initialize (const unsigned int components);
668 
669 
673  double
674  get_data_component (const Point<dim> &position,
675  const unsigned int component) const;
676 
677 
681  static
682  void
684  const std::string &default_directory,
685  const std::string &default_filename,
686  const std::string &subsection_name = "Ascii data model");
687 
691  void
692  parse_parameters (ParameterHandler &prm,
693  const std::string &subsection_name = "Ascii data model");
694 
695  protected:
700  std::vector<std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim-1>>> lookups;
701 
702  private:
706  std::vector<std::string> data_file_names;
707 
712 
716  std::string interpolation_scheme;
717 
718 
719  };
720 
721 
725  template <int dim>
727  {
728  public:
733 
738  virtual
739  void
740  initialize (const MPI_Comm communicator);
741 
742 
746  double
747  get_data_component (const Point<1> &position,
748  const unsigned int component) const;
749 
756  std::vector<std::string>
757  get_column_names() const;
758 
773  const std::vector<double> &
775 
781  unsigned int
782  get_column_index_from_name(const std::string &column_name) const;
783 
789  unsigned int
790  maybe_get_column_index_from_name(const std::string &column_name) const;
791 
797  std::string
798  get_column_name_from_index(const unsigned int column_index) const;
799  protected:
804  std::unique_ptr<aspect::Utilities::StructuredDataLookup<1>> lookup;
805  };
806  }
807 }
808 
809 #endif
constexpr unsigned int invalid_unsigned_int
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
std::set< unsigned int > log_components
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
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
unsigned int boundary_id
std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim > > lookup