| Cantera 3.0.0

Loading...
Searching...
No Matches
DomainFactory.h
Go to the documentation of this file.
1//! @file DomainFactory.h
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#ifndef DOMAIN_FACTORY_H
7#define DOMAIN_FACTORY_H
8
9#include "cantera/oneD/Domain1D.h"
10#include "cantera/base/FactoryBase.h"
11
12 namespace Cantera
13{
14
15//! Factory class to create domain objects
16//!
17//! This class is mainly used via the newDomain() function, for example:
18//!
19//! ```cpp
20//! shared_ptr<Domain1D> d1 = newDomain("Inlet", sol, "reactants");
21//! ```
22 class DomainFactory : public Factory<Domain1D, shared_ptr<Solution>, const string&>
23{
24 public:
25 /**
26 * Return a pointer to the factory. On the first call, a new instance is
27 * created. Since there is no need to instantiate more than one factory,
28 * on all subsequent calls, a pointer to the existing factory is returned.
29 */
30 static DomainFactory* factory();
31
32 void deleteFactory() override;
33
34 private:
35 //! Pointer to the single instance of the factory
36 static DomainFactory* s_factory;
37
38 //! default constructor, which is defined as private
39 DomainFactory();
40
41 //! Mutex for use when calling the factory
42 static std::mutex domain_mutex;
43};
44
45//! Create a Domain object of the specified type. An optional template argument will
46//! dynamically cast Domain1D to the desired specialization.
47//! @param domainType string identifying domain type.
48//! @param solution Solution holding ThermoPhase, Kinetics and Transport objects.
49//! @param id string identifier describing domain. If omitted, id defaults to the
50//! domain type identifier.
51//! @ingroup onedGroup
52 template <class T=Domain1D>
53shared_ptr<T> newDomain(
54 const string& domainType, shared_ptr<Solution> solution, const string& id="")
55{
56 string id_ = id;
57 if (id_ == "") {
58 id_ = domainType;
59 }
60 auto ret = std::dynamic_pointer_cast<T>(
61 shared_ptr<Domain1D>(
62 DomainFactory::factory()->create(domainType, solution, id_)));
63 if (!ret) {
64 throw CanteraError("newDomain",
65 "Invalid cast: unable to access 'Domain1D' as '{}'.", demangle(typeid(T)));
66 }
67 return ret;
68}
69
70}
71
72#endif
Domain1D.h
FactoryBase.h
File contains the FactoryBase class declarations.
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::DomainFactory
Factory class to create domain objects.
Definition DomainFactory.h:23
Cantera::DomainFactory::domain_mutex
static std::mutex domain_mutex
Mutex for use when calling the factory.
Definition DomainFactory.h:42
Cantera::DomainFactory::DomainFactory
DomainFactory()
default constructor, which is defined as private
Definition DomainFactory.cpp:18
Cantera::DomainFactory::deleteFactory
void deleteFactory() override
Virtual abstract function that deletes the factory.
Definition DomainFactory.cpp:88
Cantera::DomainFactory::s_factory
static DomainFactory * s_factory
Pointer to the single instance of the factory.
Definition DomainFactory.h:36
Cantera::DomainFactory::factory
static DomainFactory * factory()
Return a pointer to the factory.
Definition DomainFactory.cpp:79
Cantera::Factory
Factory class that supports registering functions to create objects.
Definition FactoryBase.h:69
Cantera::demangle
string demangle(const std::type_info &type)
Convert a type name to a human readable string, using boost::core::demangle if available.
Definition global.cpp:213
Cantera::newDomain
shared_ptr< T > newDomain(const string &domainType, shared_ptr< Solution > solution, const string &id="")
Create a Domain object of the specified type.
Definition DomainFactory.h:53
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564