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  {
34  using namespace dealii;
35 
55  template <int dim>
57  {
58  public:
68  StructuredDataLookup(const unsigned int n_components,
69  const double scale_factor);
70 
77  explicit StructuredDataLookup(const double scale_factor);
78 
114  void reinit(const std::vector<std::string> &column_names,
115  std::vector<std::vector<double>> &&coordinate_values,
116  std::vector<Table<dim,double>> &&data_table,
117  const MPI_Comm mpi_communicator = MPI_COMM_SELF,
118  const unsigned int root_process = numbers::invalid_unsigned_int);
119 
137  void
138  load_ascii(const std::string &filename,
139  const MPI_Comm communicator);
140 
149  void
150  load_netcdf(const std::string &filename, const std::vector<std::string> &data_column_names = {});
151 
152 
167  void
168  load_file(const std::string &filename,
169  const MPI_Comm communicator);
170 
181  double
182  get_data(const Point<dim> &position,
183  const unsigned int component) const;
184 
194  Tensor<1,dim>
195  get_gradients(const Point<dim> &position,
196  const unsigned int component);
197 
204  std::vector<std::string>
205  get_column_names() const;
206 
212  bool
213  has_equidistant_coordinates() const;
214 
227  const std::vector<double> &
228  get_interpolation_point_coordinates(const unsigned int dimension) const;
229 
235  unsigned int
236  get_column_index_from_name(const std::string &column_name) const;
237 
243  std::string
244  get_column_name_from_index(const unsigned int column_index) const;
245 
249  double get_maximum_component_value(const unsigned int component) const;
250 
258  unsigned int get_number_of_coordinates(const unsigned int dimension) const;
259 
260  private:
264  unsigned int n_components;
265 
271  std::vector<std::string> data_component_names;
272 
278  std::vector<std::unique_ptr<Function<dim>>> data;
279 
283  std::array<std::vector<double>,dim> coordinate_values;
284 
288  std::vector<double> maximum_component_value;
289 
293  TableIndices<dim> table_points;
294 
299  const double scale_factor;
300 
306 
311  TableIndices<dim>
312  compute_table_indices(const TableIndices<dim> &sizes, const std::size_t idx) const;
313 
314  };
315 
320  template <int dim>
322  {
323  public:
327  AsciiDataBase();
328 
332  static
333  void
334  declare_parameters (ParameterHandler &prm,
335  const std::string &default_directory,
336  const std::string &default_filename,
337  const std::string &subsection_name = "Ascii data model");
338 
342  void
343  parse_parameters (ParameterHandler &prm,
344  const std::string &subsection_name = "Ascii data model");
345 
349  std::string data_directory;
350 
356  std::string data_file_name;
357 
364  double scale_factor;
365  };
366 
371  template <int dim>
373  {
374  public:
379 
384  virtual
385  void
386  initialize (const std::set<types::boundary_id> &boundary_ids,
387  const unsigned int components);
388 
395  void
396  update();
397 
401  double
402  get_data_component (const types::boundary_id boundary_indicator,
403  const Point<dim> &position,
404  const unsigned int component) const;
405 
409  double
410  get_maximum_component_value (const types::boundary_id boundary_indicator,
411  const unsigned int component) const;
412 
416  Tensor<1,dim-1>
417  vector_gradient(const types::boundary_id boundary_indicator,
418  const Point<dim> &p,
419  const unsigned int component) const;
420 
437  static
438  void
439  declare_parameters (ParameterHandler &prm,
440  const std::string &default_directory,
441  const std::string &default_filename,
442  const std::string &subsection_name = "Ascii data model",
443  const bool declare_time_dependent_parameters = true);
444 
458  void
459  parse_parameters (ParameterHandler &prm,
460  const std::string &subsection_name = "Ascii data model",
461  const bool parse_time_dependent_parameters = true);
462 
463  protected:
469 
475 
483 
489 
494  double time_weight;
495 
502 
507  std::map<types::boundary_id,
509 
513  std::map<types::boundary_id,
515 
519  void
520  update_data (const types::boundary_id boundary_id,
521  const bool reload_both_files);
522 
527  void
528  end_time_dependence ();
529 
533  std::string
534  create_filename (const int filenumber,
535  const types::boundary_id boundary_id) const;
536  };
537 
538 
539 
544  template <int dim>
546  {
547  public:
552 
557  virtual
558  void
559  initialize (const unsigned int components);
560 
561 
565  double
566  get_data_component (const Point<dim> &position,
567  const unsigned int component) const;
568 
572  static
573  void
574  declare_parameters (ParameterHandler &prm,
575  const std::string &default_directory,
576  const std::string &default_filename,
577  const std::string &subsection_name = "Ascii data model");
578 
582  void
583  parse_parameters (ParameterHandler &prm,
584  const std::string &subsection_name = "Ascii data model");
585 
586  protected:
591  std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim>> lookup;
592 
598  std::unique_ptr<aspect::Utilities::StructuredDataLookup<3>> slice_lookup;
599 
605 
611  Tensor<2,3> rotation_matrix;
612  };
613 
614 
619  template <int dim>
621  {
622  public:
627 
632  virtual
633  void
634  initialize (const unsigned int components);
635 
636 
640  double
641  get_data_component (const Point<dim> &position,
642  const unsigned int component) const;
643 
644 
648  static
649  void
650  declare_parameters (ParameterHandler &prm,
651  const std::string &default_directory,
652  const std::string &default_filename,
653  const std::string &subsection_name = "Ascii data model");
654 
658  void
659  parse_parameters (ParameterHandler &prm,
660  const std::string &subsection_name = "Ascii data model");
661 
662  protected:
667  std::vector<std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim-1>>> lookups;
668 
669  private:
670 
674  std::string data_directory;
675 
679  std::vector<std::string> data_file_names;
680 
685 
689  std::string interpolation_scheme;
690 
691 
692  };
693 
694 
698  template <int dim>
700  {
701  public:
706 
711  virtual
712  void
713  initialize (const MPI_Comm communicator);
714 
715 
719  double
720  get_data_component (const Point<1> &position,
721  const unsigned int component) const;
722 
729  std::vector<std::string>
730  get_column_names() const;
731 
746  const std::vector<double> &
747  get_interpolation_point_coordinates() const;
748 
754  unsigned int
755  get_column_index_from_name(const std::string &column_name) const;
756 
762  unsigned int
763  maybe_get_column_index_from_name(const std::string &column_name) const;
764 
770  std::string
771  get_column_name_from_index(const unsigned int column_index) const;
772  protected:
777  std::unique_ptr<aspect::Utilities::StructuredDataLookup<1>> lookup;
778  };
779  }
780 }
781 
782 #endif
std::unique_ptr< aspect::Utilities::StructuredDataLookup< 3 > > slice_lookup
std::map< types::boundary_id, std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > lookups
std::vector< std::unique_ptr< Function< dim > > > data
std::vector< std::string > data_component_names
void declare_parameters(ParameterHandler &prm)
std::vector< std::string > data_file_names
std::vector< double > maximum_component_value
std::vector< std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > lookups
std::unique_ptr< aspect::Utilities::StructuredDataLookup< 1 > > lookup
Definition: compat.h:59
std::map< types::boundary_id, std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > old_lookups
std::array< std::vector< double >, dim > coordinate_values
Definition: compat.h:42
std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim > > lookup