Cantera 2.6.0

ReactionRateFactory.h
Go to the documentation of this file.
1/**
2 * @file ReactionRateFactory.h
3 * Factory class for reaction rate objects. Used by classes that implement kinetics
4 * (see \ref reactionGroup and class \link Cantera::ReactionRate ReactionRate\endlink).
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
10#ifndef CT_NEWRATE_H
11#define CT_NEWRATE_H
12
13#include "cantera/base/FactoryBase.h"
14#include "cantera/kinetics/ReactionRate.h"
15
16 namespace Cantera
17{
18
19 class Kinetics;
20 class Units;
21
22/**
23 * Factory class to construct reaction rate calculators.
24 * The reaction factory is accessed through the static method factory:
25 *
26 * @code
27 * Rate* f = ReactionRateFactory::factory()->newReactionRate(type, c)
28 * @endcode
29 *
30 * @ingroup reactionGroup
31 */
32 class ReactionRateFactory
33 : public Factory<ReactionRate, const AnyMap&, const UnitStack&>
34{
35 public:
36 /**
37 * Return a pointer to the factory. On the first call, a new instance is
38 * created. Since there is no need to instantiate more than one factory,
39 * on all subsequent calls, a pointer to the existing factory is returned.
40 */
41 static ReactionRateFactory* factory() {
42 std::unique_lock<std::mutex> lock(rate_mutex);
43 if (!s_factory) {
44 s_factory = new ReactionRateFactory;
45 }
46 return s_factory;
47 }
48
49 virtual void deleteFactory() {
50 std::unique_lock<std::mutex> lock(rate_mutex);
51 delete s_factory;
52 s_factory = 0;
53 }
54
55 private:
56 //! Pointer to the single instance of the factory
57 static ReactionRateFactory* s_factory;
58
59 //! default constructor, which is defined as private
60 ReactionRateFactory();
61
62 //! Mutex for use when calling the factory
63 static std::mutex rate_mutex;
64};
65
66
67//! Create a new empty ReactionRate object
68/*!
69 * @param type string identifying type of reaction rate.
70 */
71shared_ptr<ReactionRate> newReactionRate(const std::string& type);
72
73//! Create a new Rate object using the specified parameters
74/*!
75 * @param rate_node AnyMap node describing reaction rate.
76 * @param rate_units Vector describing unit system of the reaction rate; each element
77 * specifies Unit and exponent applied to the unit.
78 */
79shared_ptr<ReactionRate> newReactionRate(
80 const AnyMap& rate_node, const UnitStack& rate_units);
81
82//! Create a new Rate object using the specified parameters
83/*!
84 * @param rate_node AnyMap node describing reaction rate.
85 */
86shared_ptr<ReactionRate> newReactionRate(const AnyMap& rate_node);
87
88}
89#endif
FactoryBase.h
File contains the FactoryBase class declarations.
ReactionRate.h
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::Factory
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Cantera::ReactionRateFactory
Factory class to construct reaction rate calculators.
Definition: ReactionRateFactory.h:34
Cantera::ReactionRateFactory::s_factory
static ReactionRateFactory * s_factory
Pointer to the single instance of the factory.
Definition: ReactionRateFactory.h:57
Cantera::ReactionRateFactory::ReactionRateFactory
ReactionRateFactory()
default constructor, which is defined as private
Definition: ReactionRateFactory.cpp:26
Cantera::ReactionRateFactory::rate_mutex
static std::mutex rate_mutex
Mutex for use when calling the factory.
Definition: ReactionRateFactory.h:63
Cantera::ReactionRateFactory::factory
static ReactionRateFactory * factory()
Return a pointer to the factory.
Definition: ReactionRateFactory.h:41
Cantera::ReactionRateFactory::deleteFactory
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Definition: ReactionRateFactory.h:49
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::newReactionRate
shared_ptr< ReactionRate > newReactionRate(const std::string &type)
Create a new empty ReactionRate object.
Definition: ReactionRateFactory.cpp:103
Cantera::UnitStack
Unit aggregation utility.
Definition: Units.h:99