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
15
16namespace Cantera
17{
18
19class Kinetics;
20class 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 */
33 : public Factory<ReactionRate, const AnyMap&, const UnitStack&>
34{
35public:
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 */
42 std::unique_lock<std::mutex> lock(rate_mutex);
43 if (!s_factory) {
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
55private:
56 //! Pointer to the single instance of the factory
58
59 //! default constructor, which is defined as private
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
File contains the FactoryBase class declarations.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Factory class to construct reaction rate calculators.
static ReactionRateFactory * s_factory
Pointer to the single instance of the factory.
ReactionRateFactory()
default constructor, which is defined as private
static std::mutex rate_mutex
Mutex for use when calling the factory.
static ReactionRateFactory * factory()
Return a pointer to the factory.
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
shared_ptr< ReactionRate > newReactionRate(const std::string &type)
Create a new empty ReactionRate object.
Unit aggregation utility.
Definition: Units.h:99