Flow123d  DF_patch_fe_data_tables-18aea81
substance.cc
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.cc
15  * @brief Classes for storing substance data.
16  * @author Jan Stebel
17  */
18 
19 #include <iostream>
20 #include <iomanip>
21 
22 #include "transport/substance.hh"
23 #include "input/accessors.hh"
24 
25 
26 using namespace Input::Type;
27 
28 
30  return Record("Substance", "Chemical substance.")
31  .declare_key("name", String(), Default::obligatory(), "Name of the substance.")
32  .declare_key("molar_mass", Double(0), Default("1"), "Molar mass of the substance [kg/mol].")
33  .allow_auto_conversion("name")
34  .close();
35 }
36 
37 
38 
39 
41  : name_(""),
42  molar_mass_(1)
43 {
44 }
45 
47 {
48  name_ = in_rec.val<std::string>("name");
49  molar_mass_ = in_rec.val<double>("molar_mass");
50 }
51 
52 
53 
54 
55 
56 
57 
59 {
60  substances_ = std::make_shared<std::vector<Substance> >();
61  names_ = std::make_shared<std::vector<std::string> >();
62 
63  for (auto it = in_array.begin<Input::Record>(); it != in_array.end(); ++it)
64  {
65  Substance s(*it);
66  (*substances_).push_back(s);
67  (*names_).push_back(s.name());
68  }
69 }
70 
72 {
73  substances_ = list.substances_;
74  names_ = list.names_;
75 }
76 
77 
79 {
80  substances_ = std::make_shared<std::vector<Substance> >();
81  names_ = std::make_shared<std::vector<std::string> >(names);
82 
83  // copy names to internal vectors
84  (*substances_).resize(names.size());
85  for (unsigned int i=0; i<names.size(); ++i) (*substances_)[i].name_ = names[i];
86  *names_ = names;
87 }
88 
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
Iterator< ValueType > begin() const
IteratorBase end() const
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
const Ret val(const string &key) const
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
Record type proxy class.
Definition: type_record.hh:182
virtual Record & allow_auto_conversion(const string &from_key)
Allows shorter input of the Record providing only value of the from_key given as the parameter.
Definition: type_record.cc:133
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:503
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
std::shared_ptr< std::vector< std::string > > names_
Auxiliary list of substance names used in some classes.
Definition: substance.hh:95
void initialize(const Input::Array &in_array)
Read from input array.
Definition: substance.cc:58
std::shared_ptr< std::vector< Substance > > substances_
The actual list of substances.
Definition: substance.hh:92
const std::vector< std::string > & names()
Definition: substance.hh:85
std::string name() const
Getter for substance name.
Definition: substance.hh:43
double molar_mass_
Molar mass [kg/mol] of the substance.
Definition: substance.hh:58
static const Input::Type::Record & get_input_type()
Input type for a substance.
Definition: substance.cc:29
Substance()
Default constructor.
Definition: substance.cc:40
std::string name_
Name of a chemical substance.
Definition: substance.hh:55
Classes for storing substance data.