ASPECT
utilities.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 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 #ifndef _aspect_material_model_utilities_h
22 #define _aspect_material_model_utilities_h
23 
24 #include <aspect/global.h>
25 #include <deal.II/base/point.h>
26 #include <deal.II/base/symmetric_tensor.h>
27 #include <deal.II/fe/component_mask.h>
28 #include <deal.II/base/signaling_nan.h>
29 #include <deal.II/base/parameter_handler.h>
30 
31 namespace aspect
32 {
33  template <int dim> class SimulatorAccess;
34  namespace Utilities
35  {
36  using namespace dealii;
37  using namespace ::Utilities;
38 
39  template <int dim>
40  class StructuredDataLookup;
41  }
42  namespace MaterialModel
43  {
44  using namespace dealii;
45 
46  template <int dim> class MaterialModelOutputs;
47  template <int dim> struct EquationOfStateOutputs;
48 
54  namespace MaterialUtilities
55  {
56  namespace Lookup
57  {
65  {
66  public:
67 
68  double
69  specific_heat(const double temperature,
70  const double pressure) const;
71 
72  double
73  density(const double temperature,
74  const double pressure) const;
75 
76  double
77  thermal_expansivity(const double temperature,
78  const double pressure) const;
79 
80  double
81  seismic_Vp(const double temperature,
82  const double pressure) const;
83 
84  double
85  seismic_Vs(const double temperature,
86  const double pressure) const;
87 
88  double
89  enthalpy(const double temperature,
90  const double pressure) const;
91 
97  double
98  dHdT (const double temperature,
99  const double pressure) const;
100 
106  double
107  dHdp (const double temperature,
108  const double pressure) const;
109 
122  std::array<std::pair<double, unsigned int>,2>
123  enthalpy_derivatives(const std::vector<double> &temperatures,
124  const std::vector<double> &pressures,
125  const unsigned int n_substeps = 1) const;
126 
127  double
128  dRhodp (const double temperature,
129  const double pressure) const;
130 
135  unsigned int
136  dominant_phase (const double temperature,
137  const double pressure) const;
138 
143  bool
144  has_dominant_phase() const;
145 
150  std::vector<std::string>
151  phase_volume_column_names() const;
152 
157  double
158  phase_volume_fraction(const int phase_id,
159  const double temperature,
160  const double pressure) const;
161 
166  std::array<double,2>
167  get_pT_steps() const;
168 
169 
176  const std::vector<std::string> &
177  get_dominant_phase_names() const;
178 
179  protected:
187  double
188  value (const double temperature,
189  const double pressure,
190  const Table<2, double> &values,
191  const bool interpol) const;
192 
198  unsigned int
199  value (const double temperature,
200  const double pressure,
201  const Table<2, unsigned int> &values) const;
202 
206  double get_nT(const double temperature) const;
207 
211  double get_np(const double pressure) const;
212 
213  ::Table<2,double> density_values;
214  ::Table<2,double> thermal_expansivity_values;
215  ::Table<2,double> specific_heat_values;
216  ::Table<2,double> vp_values;
217  ::Table<2,double> vs_values;
218  ::Table<2,double> enthalpy_values;
219  ::Table<2,unsigned int> dominant_phase_indices;
220 
227  std::vector<std::string> phase_column_names;
228  std::vector<::Table<2,double>> phase_volume_fractions;
229 
230  double delta_press;
231  double min_press;
232  double max_press;
233  double delta_temp;
234  double min_temp;
235  double max_temp;
236  unsigned int n_temperature;
237  unsigned int n_pressure;
238  unsigned int n_phases;
239  unsigned int n_columns;
242  std::vector<std::string> dominant_phase_names;
243  };
244 
250  {
251  public:
252  HeFESToReader(const std::string &material_filename,
253  const std::string &derivatives_filename,
254  const bool interpol,
255  const MPI_Comm comm);
256  };
257 
263  {
264  public:
265  PerplexReader(const std::string &filename,
266  const bool interpol,
267  const MPI_Comm comm);
268  };
269 
275  {
276  public:
277 
281  void
282  initialize(const MPI_Comm comm,
283  const std::string &data_directory,
284  const std::string &material_file_name);
285 
289  double
290  specific_heat(const double entropy,
291  const double pressure) const;
292 
296  double
297  density(const double entropy,
298  const double pressure) const;
299 
303  double
304  thermal_expansivity(const double entropy,
305  const double pressure) const;
306 
310  double
311  temperature(const double entropy,
312  const double pressure) const;
313 
317  double
318  seismic_vp(const double entropy,
319  const double pressure) const;
320 
324  double
325  seismic_vs(const double entropy,
326  const double pressure) const;
327 
331  Tensor<1, 2>
332  density_gradient(const double entropy,
333  const double pressure) const;
334 
335  private:
339  std::unique_ptr<Utilities::StructuredDataLookup<2>> material_lookup;
340  };
341  }
342 
358  std::vector<double>
359  compute_only_composition_fractions(const std::vector<double> &compositional_fields,
360  const std::vector<unsigned int> &indices_to_use);
361 
380  std::vector<double>
381  compute_composition_fractions(const std::vector<double> &compositional_fields,
382  const ComponentMask &field_mask = ComponentMask());
383 
391  std::vector<double>
392  compute_volumes_from_masses(const std::vector<double> &masses,
393  const std::vector<double> &densities,
394  const bool return_as_fraction);
395 
405  {
410  };
411 
412 
413 
420  parse_compositional_averaging_operation (const std::string &parameter_name,
421  const ParameterHandler &prm);
422 
423 
424 
444  double average_value (const std::vector<double> &volume_fractions,
445  const std::vector<double> &parameter_values,
446  const CompositionalAveragingOperation &average_type);
447 
448 
449 
464  template <int dim>
465  void
467  const std::vector<double> &mass_fractions,
468  const std::vector<double> &volume_fractions,
469  const unsigned int i,
471 
472 
473 
477  namespace PhaseUtilities
478  {
485  {
488  };
489  }
490 
507  double phase_average_value (const std::vector<double> &phase_function_values,
508  const std::vector<unsigned int> &n_phase_transitions_per_composition,
509  const std::vector<double> &parameter_values,
510  const unsigned int composition_index,
512 
513 
514 
520  template <int dim>
522  {
527  PhaseFunctionInputs(const double temperature,
528  const double pressure,
529  const double depth,
530  const double pressure_depth_derivative,
531  const unsigned int phase_transition_index);
532 
533  double temperature;
534  double pressure;
535  double depth;
537 
550  };
551 
560  template <int dim>
562  {
563  public:
564 
569  void initialize();
570 
577  double compute_value (const PhaseFunctionInputs<dim> &in) const;
578 
584  double compute_derivative () const;
585 
589  unsigned int n_phase_transitions () const;
590 
594  unsigned int n_phases () const;
595 
599  unsigned int n_phases_over_all_chemical_compositions () const;
600 
604  const std::vector<unsigned int> &
605  n_phase_transitions_for_each_chemical_composition () const;
606 
610  const std::vector<unsigned int> &
611  n_phases_for_each_chemical_composition () const;
612 
619  const std::vector<unsigned int> &
620  n_phase_transitions_for_each_composition () const;
621 
628  const std::vector<unsigned int> &
629  n_phases_for_each_composition () const;
630 
637  static
638  void
639  declare_parameters (ParameterHandler &prm);
640 
647  void
648  parse_parameters (ParameterHandler &prm);
649 
650 
651  private:
655  std::string data_directory;
656 
660  std::vector<std::string> material_file_names;
661 
665  std::vector<double> minimum_temperature;
666 
670  std::vector<double> maximum_temperature;
671 
675  std::vector<double> interval_temperature;
676 
680  std::vector<double> minimum_pressure;
681 
685  std::vector<double> maximum_pressure;
686 
690  std::vector<double> interval_pressure;
691 
696  std::vector<std::unique_ptr<Utilities::StructuredDataLookup<2>>> material_lookup;
697 
704  std::vector<unsigned int> transition_indicators;
705 
709  std::unique_ptr<std::vector<unsigned int>> n_phase_transitions_per_composition;
710 
714  std::vector<unsigned int> n_phases_per_composition;
715 
720 
724  std::vector<unsigned int> n_phases_per_chemical_composition;
725 
729  unsigned int n_phases_total;
730 
735  };
736 
744  template <int dim>
746  {
747  public:
753  double compute_value (const PhaseFunctionInputs<dim> &in) const;
754 
759  double compute_derivative (const PhaseFunctionInputs<dim> &in) const;
760 
764  unsigned int n_phase_transitions () const;
765 
769  unsigned int n_phases () const;
770 
774  unsigned int n_phases_over_all_chemical_compositions () const;
775 
780  double get_transition_slope (const unsigned int phase_transition_index) const;
781 
785  double get_transition_depth (const unsigned int phase_transition_index) const;
786 
790  const std::vector<unsigned int> &
791  n_phase_transitions_for_each_chemical_composition () const;
792 
796  const std::vector<unsigned int> &
797  n_phases_for_each_chemical_composition () const;
798 
805  const std::vector<unsigned int> &
806  n_phase_transitions_for_each_composition () const;
807 
814  const std::vector<unsigned int> &
815  n_phases_for_each_composition () const;
816 
823  static
824  void
825  declare_parameters (ParameterHandler &prm);
826 
833  void
834  parse_parameters (ParameterHandler &prm);
835 
836 
837  private:
842  std::vector<double> transition_depths;
843  std::vector<double> transition_pressures;
844  std::vector<double> transition_temperatures;
845  std::vector<double> transition_widths;
846  std::vector<double> transition_pressure_widths;
847  std::vector<double> transition_slopes;
850 
858 
862  std::unique_ptr<std::vector<unsigned int>> n_phase_transitions_per_composition;
863 
867  std::vector<unsigned int> n_phases_per_composition;
868 
873 
877  std::vector<unsigned int> n_phases_per_chemical_composition;
878 
882  unsigned int n_phases_total;
883 
888  };
889  }
890  }
891 }
892 
893 
894 #endif
void fill_averaged_equation_of_state_outputs(const EquationOfStateOutputs< dim > &eos_outputs, const std::vector< double > &mass_fractions, const std::vector< double > &volume_fractions, const unsigned int i, MaterialModelOutputs< dim > &out)
std::vector< unsigned int > n_phases_per_composition
Definition: utilities.h:867
std::unique_ptr< Utilities::StructuredDataLookup< 2 > > material_lookup
Definition: utilities.h:339
std::vector<::Table< 2, double > > phase_volume_fractions
Definition: utilities.h:228
void declare_parameters(ParameterHandler &prm)
std::unique_ptr< std::vector< unsigned int > > n_phase_transitions_per_composition
Definition: utilities.h:709
std::unique_ptr< std::vector< unsigned int > > n_phase_transitions_per_composition
Definition: utilities.h:862
std::vector< unsigned int > n_phase_transitions_per_chemical_composition
Definition: utilities.h:719
double average_value(const std::vector< double > &volume_fractions, const std::vector< double > &parameter_values, const CompositionalAveragingOperation &average_type)
std::vector< std::unique_ptr< Utilities::StructuredDataLookup< 2 > > > material_lookup
Definition: utilities.h:696
double phase_average_value(const std::vector< double > &phase_function_values, const std::vector< unsigned int > &n_phase_transitions_per_composition, const std::vector< double > &parameter_values, const unsigned int composition_index, const PhaseUtilities::PhaseAveragingOperation operation=PhaseUtilities::arithmetic)
std::vector< unsigned int > n_phase_transitions_per_chemical_composition
Definition: utilities.h:872
CompositionalAveragingOperation parse_compositional_averaging_operation(const std::string &parameter_name, const ParameterHandler &prm)
std::vector< unsigned int > n_phases_per_chemical_composition
Definition: utilities.h:877
Definition: compat.h:59
std::vector< double > compute_volumes_from_masses(const std::vector< double > &masses, const std::vector< double > &densities, const bool return_as_fraction)
std::vector< double > compute_only_composition_fractions(const std::vector< double > &compositional_fields, const std::vector< unsigned int > &indices_to_use)
Definition: compat.h:42
std::vector< double > compute_composition_fractions(const std::vector< double > &compositional_fields, const ComponentMask &field_mask=ComponentMask())