Flow123d  release_2.2.0-41-g0958a8d
substance.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file substance.hh
15  * @brief Classes for storing substance data.
16  * @author Jan Stebel
17  */
18 
19 #ifndef SUBSTANCE_HH_
20 #define SUBSTANCE_HH_
21 
22 
23 
24 
25 #include "input/accessors.hh"
26 
27 
28 /**
29  * Class Substance is a storage for data which are specific for a (chemical) substance.
30  * The purpose is to easily share them among equations (e.g. between transport and reactions).
31  */
32 class Substance {
33 
34 public:
35 
36  /// Default constructor.
37  Substance();
38 
39  /// Initialization from input tree.
40  Substance(const Input::Record &in_rec);
41 
42  /// Getter for substance name.
43  std::string name() const { return name_; }
44 
45  /// Getter for molar mass.
46  double molar_mass() const { return molar_mass_; }
47 
48 
49  /// Input type for a substance.
50  static const Input::Type::Record & get_input_type();
51 
52 protected:
53 
54  /// Name of a chemical substance.
55  std::string name_;
56 
57  /// Molar mass [kg/mol] of the substance.
58  double molar_mass_;
59 
60  friend class SubstanceList;
61 };
62 
63 
64 /**
65  * SubstanceList is an envelope around a vector of substances, which provides
66  * some additional functionality such as:
67  * - various ways of initialization (fron JSON input, reference, or list of names)
68  * - export of vector of names (required e.g. by some field classes)
69  */
71 
72 public:
73 
74  /// Read from input array.
75  void initialize(const Input::Array &in_array);
76 
77  /// Bind to existing list.
78  void initialize(SubstanceList &list);
79 
80  /// Construct from a list of names.
81  void initialize(const std::vector<std::string> &names);
82 
83  inline const Substance &operator[](unsigned int index) { return (*substances_)[index]; }
84 
85  inline const std::vector<std::string> &names() { return (*names_); }
86 
87  unsigned int size() const { return substances_->size(); }
88 
89 private:
90 
91  /// The actual list of substances.
92  std::shared_ptr<std::vector<Substance> > substances_;
93 
94  /// Auxiliary list of substance names used in some classes.
95  std::shared_ptr<std::vector<std::string> > names_;
96 };
97 
98 
99 
100 
101 
102 
103 
104 
105 #endif // SUBSTANCE_HH_
Accessor to input data conforming to declared Array.
Definition: accessors.hh:567
Substance()
Default constructor.
Definition: substance.cc:40
const std::vector< std::string > & names()
Definition: substance.hh:85
static const Input::Type::Record & get_input_type()
Input type for a substance.
Definition: substance.cc:29
const Substance & operator[](unsigned int index)
Definition: substance.hh:83
unsigned int size() const
Definition: substance.hh:87
double molar_mass() const
Getter for molar mass.
Definition: substance.hh:46
std::string name_
Name of a chemical substance.
Definition: substance.hh:55
double molar_mass_
Molar mass [kg/mol] of the substance.
Definition: substance.hh:58
std::shared_ptr< std::vector< std::string > > names_
Auxiliary list of substance names used in some classes.
Definition: substance.hh:95
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
std::shared_ptr< std::vector< Substance > > substances_
The actual list of substances.
Definition: substance.hh:92
Record type proxy class.
Definition: type_record.hh:182
std::string name() const
Getter for substance name.
Definition: substance.hh:43