Flow123d  JS_before_hm-1713-g943b6bc16
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 
Substance::Substance
Substance()
Default constructor.
Definition: substance.cc:40
SubstanceList::substances_
std::shared_ptr< std::vector< Substance > > substances_
The actual list of substances.
Definition: substance.hh:92
Substance::name_
std::string name_
Name of a chemical substance.
Definition: substance.hh:55
SubstanceList
Definition: substance.hh:70
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
substance.hh
Classes for storing substance data.
std::vector< std::string >
Substance::name
std::string name() const
Getter for substance name.
Definition: substance.hh:43
Input::Array::begin
Iterator< ValueType > begin() const
Definition: accessors_impl.hh:145
SubstanceList::initialize
void initialize(const Input::Array &in_array)
Read from input array.
Definition: substance.cc:58
SubstanceList::names
const std::vector< std::string > & names()
Definition: substance.hh:85
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Input::Type::Record::allow_auto_conversion
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
accessors.hh
Input::Type::Default::obligatory
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
Input::Type::Record::declare_key
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
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Input::Type
Definition: balance.hh:41
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Substance::get_input_type
static const Input::Type::Record & get_input_type()
Input type for a substance.
Definition: substance.cc:29
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
Substance::molar_mass_
double molar_mass_
Molar mass [kg/mol] of the substance.
Definition: substance.hh:58
std::list
Definition: doxy_dummy_defs.hh:9
Input::Array::end
IteratorBase end() const
Definition: accessors_impl.hh:157
SubstanceList::names_
std::shared_ptr< std::vector< std::string > > names_
Auxiliary list of substance names used in some classes.
Definition: substance.hh:95
Substance
Definition: substance.hh:32