Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Surfaces.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // Reaktoro includes
21 #include <Reaktoro/Common/Types.hpp>
22 #include <Reaktoro/Core/SurfaceAreaModel.hpp>
23 
24 namespace Reaktoro {
25 
26 // Forward declarations
27 class PhaseList;
28 class Surface;
29 
32 using SurfaceGenerator = Fn<Vec<Surface>(PhaseList const& phases)>;
33 
37 {
38 public:
41 
44 
46  GeneralSurface(String const& name, SurfaceAreaModel const& area_model);
47 
49  auto setName(String const& name) -> GeneralSurface&;
50 
53 
55  auto set(SurfaceAreaModel const& model) -> GeneralSurface&;
56 
58  auto name() const -> String const&;
59 
61  auto areaModel() const -> SurfaceAreaModel const&;
62 
64  auto operator()(PhaseList const& phases) const -> Surface;
65 
66 private:
68  String surface_name;
69 
71  SurfaceAreaModel area_model;
72 };
73 
76 class Surfaces
77 {
78 public:
81 
84  template<typename... SurfaceConvertible>
85  explicit Surfaces(SurfaceConvertible const&... surfaces)
86  {
87  static_assert(sizeof...(surfaces) > 0);
88  addAux(surfaces...);
89  }
90 
92  template<typename T>
93  auto add(T const& item) -> void
94  {
95  static_assert(
96  isConvertible<T, Surface> ||
97  isConvertible<T, GeneralSurface> ||
98  isConvertible<T, SurfaceGenerator>);
99 
100  if constexpr(isConvertible<T, Surface>)
101  {
102  surface_generators.push_back([=](PhaseList const& phases) -> Vec<Surface> { return { item }; }); // item is a Surface object
103  }
104  else if constexpr(isConvertible<T, GeneralSurface>)
105  {
106  surface_generators.push_back([=](PhaseList const& phases) -> Vec<Surface> { return { item(phases) }; }); // item is a GeneralSurface object; use operator()(PhaseList) to convert to Surface
107  }
108  else
109  {
110  surface_generators.push_back(item); // item is already a SurfaceGenerator
111  }
112  }
113 
116  auto convert(PhaseList const& phases) const -> Vec<Surface>;
117 
118 private:
120  Vec<SurfaceGenerator> surface_generators;
121 
123  template<typename Arg, typename... Args>
124  auto addAux(const Arg& arg, const Args&... args) -> void
125  {
126  add(arg);
127  if constexpr (sizeof...(Args) > 0)
128  addAux(args...);
129  }
130 };
131 
132 } // namespace Reaktoro
Used to define a general surface.
Definition: Surfaces.hpp:37
GeneralSurface(String const &name)
Construct a GeneralSurface object with given unique surface name.
auto setAreaModel(SurfaceAreaModel const &model) -> GeneralSurface &
Set the area model of the surface.
GeneralSurface(String const &name, SurfaceAreaModel const &area_model)
Construct a GeneralSurface object with given unique surface name and area model.
auto set(SurfaceAreaModel const &model) -> GeneralSurface &
Set the area model of the surface (equivalent to GeneralSurface::setAreaModel).
GeneralSurface()
Construct a default GeneralSurface object.
auto areaModel() const -> SurfaceAreaModel const &
Return the area model of the surface.
auto name() const -> String const &
Return the name of the surface.
auto setName(String const &name) -> GeneralSurface &
Set the unique name of the surface.
A type used as a collection of phases.
Definition: PhaseList.hpp:29
Used to represent a surface across which chemical reactions take place.
Definition: Surface.hpp:31
Used to represent a collection of surfaces across which chemical reactions take place.
Definition: Surfaces.hpp:77
Surfaces()
Construct a Surfaces object.
auto add(T const &item) -> void
Add a surface generator into the Surfaces container.
Definition: Surfaces.hpp:93
auto convert(PhaseList const &phases) const -> Vec< Surface >
Convert this Surfaces object into a vector of Surface objects.
Surfaces(SurfaceConvertible const &... surfaces)
Construct a Surfaces object with given Surface, GeneralSurface, or SurfaceGenerator objects.
Definition: Surfaces.hpp:85
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Fn< Vec< Surface >(PhaseList const &phases)> SurfaceGenerator
The function type for the generation of surfaces with given phases in the chemical system.
Definition: Surfaces.hpp:32
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
std::function< F > Fn
Convenient alias for std::function<R(Args...)>.
Definition: Types.hpp:110