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 #include <set>
30 
31 namespace aspect
32 {
33  namespace Utilities
34  {
49  using namespace ::Utilities;
50 
70  template <int dim>
72  {
73  public:
83  StructuredDataLookup(const unsigned int n_components,
84  const double scale_factor);
85 
92  StructuredDataLookup(const unsigned int n_components,
93  const double scale_factor,
94  const std::set<unsigned int> &log_components);
95 
102  explicit StructuredDataLookup(const double scale_factor);
103 
139  void reinit(const std::vector<std::string> &column_names,
140  std::vector<std::vector<double>> &&coordinate_values,
141  std::vector<Table<dim,double>> &&data_table,
142  const MPI_Comm mpi_communicator = MPI_COMM_SELF,
143  const unsigned int root_process = numbers::invalid_unsigned_int);
144 
162  void
163  load_ascii(const std::string &filename,
164  const MPI_Comm communicator);
165 
174  void
175  load_netcdf(const std::string &filename, const std::vector<std::string> &data_column_names = {});
176 
177 
196  void
197  load_file(const std::string &filename,
198  const MPI_Comm communicator);
199 
213  double
214  get_data(const Point<dim> &position,
215  const unsigned int component,
216  const bool crash_if_not_in_range = false) const;
217 
228  get_gradients(const Point<dim> &position,
229  const unsigned int component);
230 
237  std::vector<std::string>
238  get_column_names() const;
239 
245  bool
247 
260  const std::vector<double> &
261  get_interpolation_point_coordinates(const unsigned int dimension) const;
262 
268  unsigned int
269  get_column_index_from_name(const std::string &column_name) const;
270 
276  std::string
277  get_column_name_from_index(const unsigned int column_index) const;
278 
282  double get_maximum_component_value(const unsigned int component) const;
283 
291  unsigned int get_number_of_coordinates(const unsigned int dimension) const;
292 
293  private:
297  unsigned int n_components;
298 
304  std::vector<std::string> data_component_names;
305 
311  std::vector<std::unique_ptr<Function<dim>>> data;
312 
316  std::array<std::vector<double>,dim> coordinate_values;
317 
321  std::vector<double> maximum_component_value;
322 
327 
332  const double scale_factor;
333 
338  std::set<unsigned int> log_components;
339 
345 
351  compute_table_indices(const TableIndices<dim> &sizes, const std::size_t idx) const;
352 
353  };
354 
359  template <int dim>
361  {
362  public:
366  AsciiDataBase();
367 
371  static
372  void
374  const std::string &default_directory,
375  const std::string &default_filename,
376  const std::string &subsection_name = "Ascii data model");
377 
381  void
382  parse_parameters (ParameterHandler &prm,
383  const std::string &subsection_name = "Ascii data model");
384 
388  std::string data_directory;
389 
395  std::string data_file_name;
396 
403  double scale_factor;
404  };
405 
410  template <int dim>
412  {
413  public:
418 
423  virtual
424  void
425  initialize (const std::set<types::boundary_id> &boundary_ids,
426  const unsigned int components);
427 
434  void
435  update();
436 
440  double
441  get_data_component (const types::boundary_id boundary_indicator,
442  const Point<dim> &position,
443  const unsigned int component) const;
444 
448  double
449  get_maximum_component_value (const types::boundary_id boundary_indicator,
450  const unsigned int component) const;
451 
455  Tensor<1,dim-1>
456  vector_gradient(const types::boundary_id boundary_indicator,
457  const Point<dim> &p,
458  const unsigned int component) const;
459 
476  static
477  void
479  const std::string &default_directory,
480  const std::string &default_filename,
481  const std::string &subsection_name = "Ascii data model",
482  const bool declare_time_dependent_parameters = true);
483 
497  void
498  parse_parameters (ParameterHandler &prm,
499  const std::string &subsection_name = "Ascii data model",
500  const bool parse_time_dependent_parameters = true);
501 
502  protected:
508 
514 
522 
528 
533  double time_weight;
534 
541 
546  std::map<types::boundary_id,
548 
552  std::map<types::boundary_id,
554 
558  void
559  update_data (const types::boundary_id boundary_id,
560  const bool reload_both_files);
561 
566  void
567  end_time_dependence ();
568 
572  std::string
573  create_filename (const int filenumber,
574  const types::boundary_id boundary_id) const;
575  };
576 
577 
578 
583  template <int dim>
585  {
586  public:
591 
596  virtual
597  void
598  initialize (const unsigned int components);
599 
600 
604  double
605  get_data_component (const Point<dim> &position,
606  const unsigned int component) const;
607 
611  static
612  void
614  const std::string &default_directory,
615  const std::string &default_filename,
616  const std::string &subsection_name = "Ascii data model");
617 
621  void
622  parse_parameters (ParameterHandler &prm,
623  const std::string &subsection_name = "Ascii data model");
624 
625  protected:
630  std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim>> lookup;
631 
637  std::unique_ptr<aspect::Utilities::StructuredDataLookup<3>> slice_lookup;
638 
644 
651  };
652 
653 
658  template <int dim>
660  {
661  public:
666 
671  virtual
672  void
673  initialize (const unsigned int components);
674 
675 
679  double
680  get_data_component (const Point<dim> &position,
681  const unsigned int component) const;
682 
683 
687  static
688  void
690  const std::string &default_directory,
691  const std::string &default_filename,
692  const std::string &subsection_name = "Ascii data model");
693 
697  void
698  parse_parameters (ParameterHandler &prm,
699  const std::string &subsection_name = "Ascii data model");
700 
701  protected:
706  std::vector<std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim-1>>> lookups;
707 
708  private:
712  std::vector<std::string> data_file_names;
713 
718 
722  std::string interpolation_scheme;
723 
724 
725  };
726 
727 
731  template <int dim>
733  {
734  public:
739 
744  virtual
745  void
746  initialize (const MPI_Comm communicator);
747 
748 
752  double
753  get_data_component (const Point<1> &position,
754  const unsigned int component) const;
755 
762  std::vector<std::string>
763  get_column_names() const;
764 
779  const std::vector<double> &
781 
787  unsigned int
788  get_column_index_from_name(const std::string &column_name) const;
789 
795  unsigned int
796  maybe_get_column_index_from_name(const std::string &column_name) const;
797 
803  std::string
804  get_column_name_from_index(const unsigned int column_index) const;
805  protected:
810  std::unique_ptr<aspect::Utilities::StructuredDataLookup<1>> lookup;
811  };
812  }
813 }
814 
815 #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