| Cantera 3.0.0

Loading...
Searching...
No Matches
Func1Factory.cpp
Go to the documentation of this file.
1//! @file Func1Factory.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#include "cantera/numerics/Func1Factory.h"
7
8 namespace Cantera
9{
10
11Func1Factory* Func1Factory::s_factory = 0;
12std::mutex Func1Factory::s_mutex;
13
14 Func1Factory::Func1Factory()
15{
16 reg("functor", [](const vector<double>& params) {
17 return new Func1();
18 });
19 reg("sin", [](const vector<double>& params) {
20 return new Sin1(params);
21 });
22 reg("cos", [](const vector<double>& params) {
23 return new Cos1(params);
24 });
25 reg("exp", [](const vector<double>& params) {
26 return new Exp1(params);
27 });
28 reg("log", [](const vector<double>& params) {
29 return new Log1(params);
30 });
31 reg("pow", [](const vector<double>& params) {
32 return new Pow1(params);
33 });
34 reg("constant", [](const vector<double>& params) {
35 return new Const1(params);
36 });
37 reg("polynomial", [](const vector<double>& params) {
38 return new Poly1(params);
39 });
40 reg("Fourier", [](const vector<double>& params) {
41 return new Fourier1(params);
42 });
43 reg("Gaussian", [](const vector<double>& params) {
44 return new Gaussian1(params);
45 });
46 reg("Arrhenius", [](const vector<double>& params) {
47 return new Arrhenius1(params);
48 });
49 reg("tabulated-linear", [](const vector<double>& params) {
50 return new Tabulated1(params);
51 });
52 reg("tabulated-previous", [](const vector<double>& params) {
53 auto fcn = new Tabulated1(params);
54 fcn->setMethod("previous");
55 return fcn;
56 });
57}
58
59 Func1Factory* Func1Factory::factory()
60{
61 std::unique_lock<std::mutex> lock(s_mutex);
62 if (!s_factory) {
63 s_factory = new Func1Factory;
64 }
65 return s_factory;
66}
67
68 void Func1Factory::deleteFactory()
69{
70 std::unique_lock<std::mutex> lock(s_mutex);
71 delete s_factory;
72 s_factory = 0;
73}
74
75 Math1FactoryA* Math1FactoryA::s_factory = 0;
76std::mutex Math1FactoryA::s_mutex;
77
78 Math1FactoryA::Math1FactoryA()
79{
80 reg("sum", [](const shared_ptr<Func1> f1, const shared_ptr<Func1> f2) {
81 return new Sum1(f1, f2);
82 });
83 reg("diff", [](const shared_ptr<Func1> f1, const shared_ptr<Func1> f2) {
84 return new Diff1(f1, f2);
85 });
86 reg("product", [](const shared_ptr<Func1> f1, const shared_ptr<Func1> f2) {
87 return new Product1(f1, f2);
88 });
89 reg("ratio", [](const shared_ptr<Func1> f1, const shared_ptr<Func1> f2) {
90 return new Ratio1(f1, f2);
91 });
92 reg("composite", [](const shared_ptr<Func1> f1, const shared_ptr<Func1> f2) {
93 return new Composite1(f1, f2);
94 });
95}
96
97 Math1FactoryA* Math1FactoryA::factory()
98{
99 std::unique_lock<std::mutex> lock(s_mutex);
100 if (!s_factory) {
101 s_factory = new Math1FactoryA;
102 }
103 return s_factory;
104}
105
106 void Math1FactoryA::deleteFactory()
107{
108 std::unique_lock<std::mutex> lock(s_mutex);
109 delete s_factory;
110 s_factory = 0;
111}
112
113 Math1FactoryB* Math1FactoryB::s_factory = 0;
114std::mutex Math1FactoryB::s_mutex;
115
116 Math1FactoryB::Math1FactoryB()
117{
118 reg("times-constant", [](const shared_ptr<Func1> f, double c) {
119 return new TimesConstant1(f, c);
120 });
121 reg("plus-constant", [](const shared_ptr<Func1> f, double c) {
122 return new PlusConstant1(f, c);
123 });
124 reg("periodic", [](const shared_ptr<Func1> f, double c) {
125 return new Periodic1(f, c);
126 });
127}
128
129 Math1FactoryB* Math1FactoryB::factory()
130{
131 std::unique_lock<std::mutex> lock(s_mutex);
132 if (!s_factory) {
133 s_factory = new Math1FactoryB;
134 }
135 return s_factory;
136}
137
138 void Math1FactoryB::deleteFactory()
139{
140 std::unique_lock<std::mutex> lock(s_mutex);
141 delete s_factory;
142 s_factory = 0;
143}
144
145shared_ptr<Func1> newFunc1(const string& func1Type, double coeff)
146{
147 return shared_ptr<Func1>(
148 Func1Factory::factory()->create(func1Type, {coeff}));
149}
150
151shared_ptr<Func1> newFunc1(const string& func1Type, const vector<double>& params)
152{
153 return shared_ptr<Func1>(
154 Func1Factory::factory()->create(func1Type, params));
155}
156
157shared_ptr<Func1> newFunc1(const string& func1Type, const shared_ptr<Func1> f1,
158 const shared_ptr<Func1> f2)
159{
160 return shared_ptr<Func1>(
161 Math1FactoryA::factory()->create(func1Type, f1, f2));
162}
163
164shared_ptr<Func1> newFunc1(const string& func1Type,
165 const shared_ptr<Func1> f, double coeff)
166{
167 return shared_ptr<Func1>(
168 Math1FactoryB::factory()->create(func1Type, f, coeff));
169}
170
171}
Func1Factory.h
Cantera::Arrhenius1
Implements a sum of Arrhenius terms.
Definition Func1.h:1291
Cantera::Composite1
Implements a composite function.
Definition Func1.h:1018
Cantera::Const1
Implements a constant.
Definition Func1.h:541
Cantera::Cos1
Implements the cos() function.
Definition Func1.h:324
Cantera::Diff1
Implements the difference of two functions.
Definition Func1.h:660
Cantera::Exp1
Implements the exp() (exponential) function.
Definition Func1.h:369
Cantera::Factory< Func1, const vector< double > & >::reg
void reg(const string &name, function< Func1 *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
Cantera::Fourier1
Implements a Fourier cosine/sine series.
Definition Func1.h:1226
Cantera::Func1Factory
Factory class to create Func1 objects.
Definition Func1Factory.h:24
Cantera::Func1Factory::s_mutex
static std::mutex s_mutex
Mutex for use when calling the factory.
Definition Func1Factory.h:43
Cantera::Func1Factory::s_factory
static Func1Factory * s_factory
Pointer to the single instance of the factory.
Definition Func1Factory.h:37
Cantera::Func1Factory::deleteFactory
void deleteFactory() override
Virtual abstract function that deletes the factory.
Definition Func1Factory.cpp:68
Cantera::Func1Factory::Func1Factory
Func1Factory()
default constructor, which is defined as private
Definition Func1Factory.cpp:14
Cantera::Func1Factory::factory
static Func1Factory * factory()
Return a pointer to the factory.
Definition Func1Factory.cpp:59
Cantera::Func1
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:96
Cantera::Gaussian1
Implements a Gaussian function.
Definition Func1.h:1096
Cantera::Log1
Implements the log() (natural logarithm) function.
Definition Func1.h:414
Cantera::Math1FactoryA
Factory class to create Func1 compound objects - version A.
Definition Func1Factory.h:58
Cantera::Math1FactoryA::s_factory
static Math1FactoryA * s_factory
Pointer to the single instance of the factory.
Definition Func1Factory.h:71
Cantera::Math1FactoryA::Math1FactoryA
Math1FactoryA()
default constructor, which is defined as private
Definition Func1Factory.cpp:78
Cantera::Math1FactoryA::s_mutex
static std::mutex s_mutex
Mutex for use when calling the factory.
Definition Func1Factory.h:77
Cantera::Math1FactoryA::deleteFactory
void deleteFactory() override
Virtual abstract function that deletes the factory.
Definition Func1Factory.cpp:106
Cantera::Math1FactoryA::factory
static Math1FactoryA * factory()
Return a pointer to the factory.
Definition Func1Factory.cpp:97
Cantera::Math1FactoryB
Factory class to create Func1 compound objects - version B.
Definition Func1Factory.h:91
Cantera::Math1FactoryB::s_mutex
static std::mutex s_mutex
Mutex for use when calling the factory.
Definition Func1Factory.h:110
Cantera::Math1FactoryB::deleteFactory
void deleteFactory() override
Virtual abstract function that deletes the factory.
Definition Func1Factory.cpp:138
Cantera::Math1FactoryB::Math1FactoryB
Math1FactoryB()
default constructor, which is defined as private
Definition Func1Factory.cpp:116
Cantera::Math1FactoryB::factory
static Math1FactoryB * factory()
Return a pointer to the factory.
Definition Func1Factory.cpp:129
Cantera::Math1FactoryB::s_factory
static Math1FactoryB * s_factory
Pointer to the single instance of the factory.
Definition Func1Factory.h:104
Cantera::Periodic1
Implements a periodic function.
Definition Func1.h:1352
Cantera::PlusConstant1
Implements the sum of a function and a constant.
Definition Func1.h:883
Cantera::Poly1
Implements a polynomial of degree n.
Definition Func1.h:1170
Cantera::Pow1
Implements the pow() (power) function.
Definition Func1.h:443
Cantera::Product1
Implements the product of two functions.
Definition Func1.h:733
Cantera::Ratio1
Implements the ratio of two functions.
Definition Func1.h:949
Cantera::Sin1
Implements the sin() function.
Definition Func1.h:275
Cantera::Sum1
Implements the sum of two functions.
Definition Func1.h:589
Cantera::Tabulated1
Implements a tabulated function.
Definition Func1.h:489
Cantera::TimesConstant1
Implements the product of a function and a constant.
Definition Func1.h:803
Cantera::newFunc1
shared_ptr< Func1 > newFunc1(const string &func1Type, double coeff)
Create a new simple functor object (see Simple Functors).
Definition Func1Factory.cpp:145
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564