Cantera  3.2.0a2
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
11
12namespace Cantera
13{
14
15class Flow1D;
16class Boundary1D;
17
18//! Factory class to create domain objects
19//!
20//! This class is mainly used via the newDomain() function, for example:
21//!
22//! ```cpp
23//! shared_ptr<Domain1D> d1 = newDomain("Inlet", sol, "reactants");
24//! ```
25class DomainFactory : public Factory<Domain1D, shared_ptr<Solution>, const string&>
26{
27public:
28 /**
29 * Return a pointer to the factory. On the first call, a new instance is
30 * created. Since there is no need to instantiate more than one factory,
31 * on all subsequent calls, a pointer to the existing factory is returned.
32 */
33 static DomainFactory* factory();
34
35 void deleteFactory() override;
36
37private:
38 //! Pointer to the single instance of the factory
40
41 //! default constructor, which is defined as private
43
44 //! Mutex for use when calling the factory
45 static std::mutex domain_mutex;
46};
47
48//! Create a Domain object of the specified type. An optional template argument will
49//! dynamically cast Domain1D to the desired specialization.
50//! @param domainType string identifying domain type.
51//! @param solution Solution holding ThermoPhase, Kinetics and Transport objects.
52//! @param id string identifier describing domain. If omitted, id defaults to the
53//! domain type identifier.
54//! @ingroup onedGroup
55template <class T=Domain1D>
56shared_ptr<T> newDomain(
57 const string& domainType, shared_ptr<Solution> solution, const string& id="")
58{
59 string id_ = id;
60 if (id_ == "") {
61 id_ = domainType;
62 }
63 auto ret = std::dynamic_pointer_cast<T>(
64 shared_ptr<Domain1D>(
65 DomainFactory::factory()->create(domainType, solution, id_)));
66 if (!ret) {
67 throw CanteraError("newDomain",
68 "Invalid cast: unable to access 'Domain1D' as '{}'.", demangle(typeid(T)));
69 }
70 return ret;
71}
72
73//! Create a Boundary1D object of the specified type.
74//! @param domainType string identifying domain type.
75//! @param solution Solution holding ThermoPhase, Kinetics and Transport objects.
76//! @param id string identifier describing domain. If omitted, id defaults to the
77//! domain type identifier.
78//! @since New in %Cantera 3.2.
79//! @ingroup onedGroup
80shared_ptr<Boundary1D> newBoundary1D(
81 const string& domainType, shared_ptr<Solution> solution, const string& id="");
82
83//! Create a Flow1D object of the specified type.
84//! @param domainType string identifying domain type.
85//! @param solution Solution holding ThermoPhase, Kinetics and Transport objects.
86//! @param id string identifier describing domain. If omitted, id defaults to the
87//! domain type identifier.
88//! @since New in %Cantera 3.2.
89//! @ingroup onedGroup
90shared_ptr<Flow1D> newFlow1D(
91 const string& domainType, shared_ptr<Solution> solution, const string& id="");
92
93}
94
95#endif
File contains the FactoryBase class declarations.
Base class for exceptions thrown by Cantera classes.
Factory class to create domain objects.
static std::mutex domain_mutex
Mutex for use when calling the factory.
DomainFactory()
default constructor, which is defined as private
void deleteFactory() override
Virtual abstract function that deletes the factory.
static DomainFactory * s_factory
Pointer to the single instance of the factory.
static DomainFactory * factory()
Return a pointer to the factory.
Factory class that supports registering functions to create objects.
Definition FactoryBase.h:69
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:222
shared_ptr< T > newDomain(const string &domainType, shared_ptr< Solution > solution, const string &id="")
Create a Domain object of the specified type.
shared_ptr< Flow1D > newFlow1D(const string &domainType, shared_ptr< Solution > solution, const string &id)
Create a Flow1D object of the specified type.
shared_ptr< Boundary1D > newBoundary1D(const string &domainType, shared_ptr< Solution > solution, const string &id)
Create a Boundary1D object of the specified type.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595