Skip to content

Commit

Permalink
[Func1] Update factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jun 29, 2023
1 parent 8424b80 commit fa57517
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
23 changes: 8 additions & 15 deletions include/cantera/numerics/Func1Factory.h
Expand Up @@ -108,37 +108,30 @@ class Math1FactoryB : public Factory<Func1, const shared_ptr<Func1>, double>
};


//! Create a new Func1 functor object.
//! @param func1Type string identifying function type.
//! @param coeff Coefficient; definition depends on the function type.
shared_ptr<Func1> newFunc1(const string& func1Type, double coeff=1.);

//! Create a new Func1 functor object.
//! @param func1Type string identifying function type.
//! @param n Integer; definition depends on the function type.
//! @param params Parameter vector; definition depends on the function type.
shared_ptr<Func1> newFunc1(const string& func1Type, size_t n=0,
const vector<double>& params={})
{
return shared_ptr<Func1>(
Func1Factory::factory()->create(func1Type, n, params));
}
const vector<double>& params={});

//! Create a new Func1 functor object based on mathematical operations.
//! @param mathType String identifying operation.
//! @param f1 First Func1 object.
//! @param f2 Second Func1 object.
shared_ptr<Func1> newMath1(const string& mathType, const shared_ptr<Func1> f1,
const shared_ptr<Func1> f2)
{
return shared_ptr<Func1>(
Math1FactoryA::factory()->create(mathType, f1, f2));
}
const shared_ptr<Func1> f2);

//! Create a new Func1 functor object based on mathematical operations.
//! @param mathType String identifying operation.
//! @param f Func1 object.
//! @param c Coefficient.
shared_ptr<Func1> newMath1(const string& mathType, const shared_ptr<Func1> f, double c)
{
return shared_ptr<Func1>(
Math1FactoryB::factory()->create(mathType, f, c));
}
shared_ptr<Func1> newMath1(const string& mathType, const shared_ptr<Func1> f, double c);

}

Expand Down
51 changes: 47 additions & 4 deletions src/numerics/Func1Factory.cpp
Expand Up @@ -13,6 +13,9 @@ std::mutex Func1Factory::domain_mutex;

Func1Factory::Func1Factory()
{
reg("functor", [](size_t n, const vector<double>& params) {
return new Func1();
});
reg("sin", [](size_t n, const vector<double>& params) {
return new Sin1(n, params);
});
Expand All @@ -22,6 +25,9 @@ Func1Factory::Func1Factory()
reg("exp", [](size_t n, const vector<double>& params) {
return new Exp1(n, params);
});
reg("log", [](size_t n, const vector<double>& params) {
return new Log1(n, params);
});
reg("pow", [](size_t n, const vector<double>& params) {
return new Pow1(n, params);
});
Expand All @@ -40,6 +46,14 @@ Func1Factory::Func1Factory()
reg("arrhenius", [](size_t n, const vector<double>& params) {
return new Arrhenius1(n, params);
});
reg("tabulated-linear", [](size_t n, const vector<double>& params) {
return new Tabulated1(n, params);
});
reg("tabulated-previous", [](size_t n, const vector<double>& params) {
auto fcn = new Tabulated1(n, params);
fcn->setMethod("previous");
return fcn;
});
}

Func1Factory* Func1Factory::factory()
Expand Down Expand Up @@ -101,11 +115,14 @@ std::mutex Math1FactoryB::domain_mutex;

Math1FactoryB::Math1FactoryB()
{
reg("times-constant", [](const shared_ptr<Func1> f1, double c) {
return new TimesConstant1(f1, c);
reg("times-constant", [](const shared_ptr<Func1> f, double c) {
return new TimesConstant1(f, c);
});
reg("plus-constant", [](const shared_ptr<Func1> f, double c) {
return new PlusConstant1(f, c);
});
reg("plus-constant", [](const shared_ptr<Func1> f1, double c) {
return new PlusConstant1(f1, c);
reg("periodic", [](const shared_ptr<Func1> f, double c) {
return new Periodic1(f, c);
});
}

Expand All @@ -125,4 +142,30 @@ void Math1FactoryB::deleteFactory()
s_factory = 0;
}

shared_ptr<Func1> newFunc1(const string& func1Type, double c)
{
return shared_ptr<Func1>(
Func1Factory::factory()->create(func1Type, 0, {c}));
}

shared_ptr<Func1> newFunc1(const string& func1Type, size_t n,
const vector<double>& params)
{
return shared_ptr<Func1>(
Func1Factory::factory()->create(func1Type, n, params));
}

shared_ptr<Func1> newMath1(const string& mathType, const shared_ptr<Func1> f1,
const shared_ptr<Func1> f2)
{
return shared_ptr<Func1>(
Math1FactoryA::factory()->create(mathType, f1, f2));
}

shared_ptr<Func1> newMath1(const string& mathType, const shared_ptr<Func1> f, double c)
{
return shared_ptr<Func1>(
Math1FactoryB::factory()->create(mathType, f, c));
}

}

0 comments on commit fa57517

Please sign in to comment.