Cantera  3.1.0a1
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
7
8namespace Cantera
9{
10
11Func1Factory* Func1Factory::s_factory = 0;
12std::mutex Func1Factory::s_mutex;
13
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
60{
61 std::unique_lock<std::mutex> lock(s_mutex);
62 if (!s_factory) {
64 }
65 return s_factory;
66}
67
69{
70 std::unique_lock<std::mutex> lock(s_mutex);
71 delete s_factory;
72 s_factory = 0;
73}
74
76std::mutex Math1FactoryA::s_mutex;
77
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
98{
99 std::unique_lock<std::mutex> lock(s_mutex);
100 if (!s_factory) {
102 }
103 return s_factory;
104}
105
107{
108 std::unique_lock<std::mutex> lock(s_mutex);
109 delete s_factory;
110 s_factory = 0;
111}
112
114std::mutex Math1FactoryB::s_mutex;
115
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
130{
131 std::unique_lock<std::mutex> lock(s_mutex);
132 if (!s_factory) {
134 }
135 return s_factory;
136}
137
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}
Implements a sum of Arrhenius terms.
Definition Func1.h:885
Implements a composite function.
Definition Func1.h:714
Implements a constant.
Definition Func1.h:404
Implements the cos() function.
Definition Func1.h:235
Implements the difference of two functions.
Definition Func1.h:481
Implements the exp() (exponential) function.
Definition Func1.h:264
void reg(const string &name, function< Func1 *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
Implements a Fourier cosine/sine series.
Definition Func1.h:840
Factory class to create Func1 objects.
static std::mutex s_mutex
Mutex for use when calling the factory.
static Func1Factory * s_factory
Pointer to the single instance of the factory.
void deleteFactory() override
Virtual abstract function that deletes the factory.
Func1Factory()
default constructor, which is defined as private
static Func1Factory * factory()
Return a pointer to the factory.
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
Implements a Gaussian function.
Definition Func1.h:766
Implements the log() (natural logarithm) function.
Definition Func1.h:295
Factory class to create Func1 compound objects - version A.
static Math1FactoryA * s_factory
Pointer to the single instance of the factory.
Math1FactoryA()
default constructor, which is defined as private
static std::mutex s_mutex
Mutex for use when calling the factory.
void deleteFactory() override
Virtual abstract function that deletes the factory.
static Math1FactoryA * factory()
Return a pointer to the factory.
Factory class to create Func1 compound objects - version B.
static std::mutex s_mutex
Mutex for use when calling the factory.
void deleteFactory() override
Virtual abstract function that deletes the factory.
Math1FactoryB()
default constructor, which is defined as private
static Math1FactoryB * factory()
Return a pointer to the factory.
static Math1FactoryB * s_factory
Pointer to the single instance of the factory.
Implements a periodic function.
Definition Func1.h:927
Implements the sum of a function and a constant.
Definition Func1.h:628
Implements a polynomial of degree n.
Definition Func1.h:801
Implements the pow() (power) function.
Definition Func1.h:324
Implements the product of two functions.
Definition Func1.h:527
Implements the ratio of two functions.
Definition Func1.h:671
Implements the sin() function.
Definition Func1.h:204
Implements the sum of two functions.
Definition Func1.h:436
Implements a tabulated function.
Definition Func1.h:356
Implements the product of a function and a constant.
Definition Func1.h:570
shared_ptr< Func1 > newFunc1(const string &func1Type, double coeff)
Create a new simple functor object (see Simple Functors).
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564