ASPECT
structured_data.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2022 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 components,
69  const double scale_factor);
70 
77  explicit StructuredDataLookup(const double scale_factor);
78 
118  void reinit(const std::vector<std::string> &column_names,
119  std::vector<std::vector<double>> &&coordinate_values,
120  std::vector<Table<dim,double>> &&data_table,
121  const MPI_Comm &mpi_communicator = MPI_COMM_SELF,
122  const unsigned int root_process = numbers::invalid_unsigned_int);
123 
129  void
130  load_file(const std::string &filename,
131  const MPI_Comm &communicator);
132 
143  double
144  get_data(const Point<dim> &position,
145  const unsigned int component) const;
146 
156  Tensor<1,dim>
157  get_gradients(const Point<dim> &position,
158  const unsigned int component);
159 
166  std::vector<std::string>
167  get_column_names() const;
168 
174  bool
175  has_equidistant_coordinates() const;
176 
189  const std::vector<double> &
190  get_interpolation_point_coordinates(const unsigned int dimension) const;
191 
197  unsigned int
198  get_column_index_from_name(const std::string &column_name) const;
199 
205  std::string
206  get_column_name_from_index(const unsigned int column_index) const;
207 
211  double get_maximum_component_value(const unsigned int component) const;
212 
213  private:
217  unsigned int components;
218 
224  std::vector<std::string> data_component_names;
225 
231  std::vector<std::unique_ptr<Function<dim>>> data;
232 
236  std::array<std::vector<double>,dim> coordinate_values;
237 
241  std::vector<double> maximum_component_value;
242 
246  TableIndices<dim> table_points;
247 
252  const double scale_factor;
253 
259 
264  TableIndices<dim>
265  compute_table_indices(const TableIndices<dim> &sizes, const std::size_t idx) const;
266 
267  };
268 
273  template <int dim>
275  {
276  public:
280  AsciiDataBase();
281 
285  static
286  void
287  declare_parameters (ParameterHandler &prm,
288  const std::string &default_directory,
289  const std::string &default_filename,
290  const std::string &subsection_name = "Ascii data model");
291 
295  void
296  parse_parameters (ParameterHandler &prm,
297  const std::string &subsection_name = "Ascii data model");
298 
302  std::string data_directory;
303 
309  std::string data_file_name;
310 
317  double scale_factor;
318  };
319 
324  template <int dim>
326  {
327  public:
332 
337  virtual
338  void
339  initialize (const std::set<types::boundary_id> &boundary_ids,
340  const unsigned int components);
341 
348  void
349  update();
350 
354  double
355  get_data_component (const types::boundary_id boundary_indicator,
356  const Point<dim> &position,
357  const unsigned int component) const;
358 
362  double
363  get_maximum_component_value (const types::boundary_id boundary_indicator,
364  const unsigned int component) const;
365 
369  Tensor<1,dim-1>
370  vector_gradient(const types::boundary_id boundary_indicator,
371  const Point<dim> &p,
372  const unsigned int component) const;
373 
377  static
378  void
379  declare_parameters (ParameterHandler &prm,
380  const std::string &default_directory,
381  const std::string &default_filename,
382  const std::string &subsection_name = "Ascii data model");
383 
387  void
388  parse_parameters (ParameterHandler &prm,
389  const std::string &subsection_name = "Ascii data model");
390 
391  protected:
392 
406  std::array<unsigned int,dim-1>
407  get_boundary_dimensions (const types::boundary_id boundary_id) const;
408 
414 
420 
428 
434 
439  double time_weight;
440 
447 
452  std::map<types::boundary_id,
454 
458  std::map<types::boundary_id,
460 
464  void
465  update_data (const types::boundary_id boundary_id,
466  const bool reload_both_files);
467 
472  void
473  end_time_dependence ();
474 
478  std::string
479  create_filename (const int filenumber,
480  const types::boundary_id boundary_id) const;
481  };
482 
483 
484 
489  template <int dim, int spacedim=dim>
491  {
492  public:
497 
502  virtual
503  void
504  initialize (const unsigned int components);
505 
506 
510  double
511  get_data_component (const Point<spacedim> &position,
512  const unsigned int component) const;
513 
514  protected:
519  std::unique_ptr<aspect::Utilities::StructuredDataLookup<spacedim>> lookup;
520  };
521 
522 
527  template <int dim>
529  {
530  public:
535 
540  virtual
541  void
542  initialize (const unsigned int components);
543 
544 
548  double
549  get_data_component (const Point<dim> &position,
550  const unsigned int component) const;
551 
552 
556  static
557  void
558  declare_parameters (ParameterHandler &prm,
559  const std::string &default_directory,
560  const std::string &default_filename,
561  const std::string &subsection_name = "Ascii data model");
562 
566  void
567  parse_parameters (ParameterHandler &prm,
568  const std::string &subsection_name = "Ascii data model");
569 
570  protected:
575  std::vector<std::unique_ptr<aspect::Utilities::StructuredDataLookup<dim-1>>> lookups;
576 
577  private:
578 
582  std::string data_directory;
583 
587  std::vector<std::string> data_file_names;
588 
593 
597  std::string interpolation_scheme;
598 
599 
600  };
601 
602 
606  template <int dim>
608  {
609  public:
614 
619  virtual
620  void
621  initialize (const MPI_Comm &communicator);
622 
623 
627  double
628  get_data_component (const Point<1> &position,
629  const unsigned int component) const;
630 
637  std::vector<std::string>
638  get_column_names() const;
639 
654  const std::vector<double> &
655  get_interpolation_point_coordinates() const;
656 
662  unsigned int
663  get_column_index_from_name(const std::string &column_name) const;
664 
670  unsigned int
671  maybe_get_column_index_from_name(const std::string &column_name) const;
672 
678  std::string
679  get_column_name_from_index(const unsigned int column_index) const;
680  protected:
685  std::unique_ptr<aspect::Utilities::StructuredDataLookup<1>> lookup;
686  };
687 
688 
689 
690  template<int dim>
692  }
693 }
694 
695 #endif
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
std::map< types::boundary_id, std::unique_ptr< aspect::Utilities::StructuredDataLookup< dim-1 > > > old_lookups
std::array< std::vector< double >, dim > coordinate_values
std::unique_ptr< aspect::Utilities::StructuredDataLookup< spacedim > > lookup
Definition: compat.h:88