Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneD domain factories and cleanup #1445

Merged
merged 24 commits into from Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
226ecb8
[oneD] Implement DomainFactory
ischoegl Feb 28, 2023
4142096
[oneD] Introduce Domain1D::type
ischoegl Feb 28, 2023
dcdc57e
[oneD] Deprecate StFlow::flowType
ischoegl Feb 28, 2023
8183736
[oneD] Introduce StFlow::isFree
ischoegl Feb 28, 2023
b1cd75f
[oneD] Move spreadRate to Boundary1D
ischoegl Feb 28, 2023
2f92c21
[oneD] Deprecate showSolution in favor of show
ischoegl Feb 28, 2023
0a83c46
[clib] Create domain_type3 to interface with Domain1D::type
ischoegl Feb 28, 2023
ca8d9ad
[oneD] Deprecate Domain1D::domainType
ischoegl Feb 28, 2023
c7ab2fd
[samples] Replace show_solution by show
ischoegl Feb 28, 2023
a5b6d1a
[matlab] Replace magic number domain types
ischoegl Feb 28, 2023
b395e51
[clib] Implement soln_setTransportModel
ischoegl Mar 7, 2023
adca91d
[unittest] Add coverage of new clib functions
ischoegl Mar 7, 2023
8c5d114
Add Interface to cantera/core.h
ischoegl Mar 5, 2023
3f2328f
[oneD] Construct Sim1D from shared pointers
ischoegl Mar 12, 2023
6ebae3b
[clib] Convert DomainCabinet to SharedCabinet
ischoegl Mar 12, 2023
655a8f9
[Python] Instantiate Domain1D objects from factory
ischoegl Feb 28, 2023
2dfa20e
[Python] Update Sim1D construction
ischoegl Mar 12, 2023
b6abd0c
[Python] Reintroduce FreeFlow and AxisymmetricFlow
ischoegl Mar 13, 2023
20f3bf2
[samples] Update oneD samples
ischoegl Mar 12, 2023
afda615
[unittest] Update test suite
ischoegl Mar 12, 2023
1a6063a
[sphinx] Add FreeFlow and AxisymmetricFlow
ischoegl Mar 13, 2023
72f9656
[clib] Replace doublereal in definition files
ischoegl Mar 13, 2023
b1bb919
[clib] Add bdry_setSpreadRate/bdry_spreadRate
ischoegl Mar 17, 2023
6d84d7f
[1D] Use StFlow::fixed_mdot when applicable
ischoegl Mar 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions doc/sphinx/cython/onedim.rst
Expand Up @@ -59,17 +59,17 @@ IdealGasFlow
.. autoclass:: IdealGasFlow(thermo)
:inherited-members:

IonFlow
^^^^^^^
.. autoclass:: IonFlow(thermo)

FreeFlow
^^^^^^^^
.. autoclass:: FreeFlow(thermo)

AxisymmetricStagnationFlow
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: AxisymmetricStagnationFlow(thermo)
AxisymmetricFlow
^^^^^^^^^^^^^^^^
.. autoclass:: AxisymmetricFlow(thermo)

IonFlow
^^^^^^^
.. autoclass:: IonFlow(thermo)

Boundaries
----------
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/clib/ct.h
Expand Up @@ -28,6 +28,8 @@ extern "C" {
CANTERA_CAPI int soln_thermo(int n);
CANTERA_CAPI int soln_kinetics(int n);
CANTERA_CAPI int soln_transport(int n);
//! note that soln_setTransportModel deletes the previous transport model
CANTERA_CAPI int soln_setTransportModel(int n, const char* model);
CANTERA_CAPI size_t soln_nAdjacent(int n);
CANTERA_CAPI int soln_adjacent(int n, int a);

Expand Down Expand Up @@ -158,6 +160,7 @@ extern "C" {
CANTERA_CAPI int trans_newDefault(int th, int loglevel);
CANTERA_CAPI int trans_new(const char* model, int th, int loglevel);
CANTERA_CAPI int trans_del(int n);
CANTERA_CAPI int trans_transportModel(int n, int lennm, char* nm);
CANTERA_CAPI double trans_viscosity(int n);
CANTERA_CAPI double trans_electricalConductivity(int n);
CANTERA_CAPI double trans_thermalConductivity(int n);
Expand Down
5 changes: 5 additions & 0 deletions include/cantera/clib/ctonedim.h
Expand Up @@ -15,8 +15,10 @@ extern "C" {
#endif

CANTERA_CAPI int ct_clearOneDim();
CANTERA_CAPI int domain_new(const char* type, int i, const char* id);
CANTERA_CAPI int domain_del(int i);
CANTERA_CAPI int domain_type(int i);
CANTERA_CAPI int domain_type3(int i, size_t lennm, char* nm);
CANTERA_CAPI size_t domain_index(int i);
CANTERA_CAPI size_t domain_nComponents(int i);
CANTERA_CAPI size_t domain_nPoints(int i);
Expand All @@ -38,8 +40,10 @@ extern "C" {

CANTERA_CAPI int bdry_setMdot(int i, double mdot);
CANTERA_CAPI int bdry_setTemperature(int i, double t);
CANTERA_CAPI int bdry_setSpreadRate(int i, double v);
CANTERA_CAPI int bdry_setMoleFractions(int i, const char* x);
CANTERA_CAPI double bdry_temperature(int i);
CANTERA_CAPI double bdry_spreadRate(int i);
CANTERA_CAPI double bdry_massFraction(int i, int k);
CANTERA_CAPI double bdry_mdot(int i);

Expand Down Expand Up @@ -70,6 +74,7 @@ extern "C" {
CANTERA_CAPI int sim1D_setProfile(int i, int dom, int comp,
size_t np, const double* pos, size_t nv, const double* v);
CANTERA_CAPI int sim1D_setFlatProfile(int i, int dom, int comp, double v);
CANTERA_CAPI int sim1D_show(int i, const char* fname);
CANTERA_CAPI int sim1D_showSolution(int i, const char* fname);
CANTERA_CAPI int sim1D_setTimeStep(int i, double stepsize, size_t ns, const int* nsteps);
CANTERA_CAPI int sim1D_getInitialSoln(int i);
Expand Down
1 change: 1 addition & 0 deletions include/cantera/core.h
Expand Up @@ -10,6 +10,7 @@
#define CT_INCL_CORE_H

#include "cantera/base/Solution.h"
#include "cantera/base/Interface.h"
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/kinetics/Kinetics.h"
#include "cantera/transport/Transport.h"
Expand Down
60 changes: 52 additions & 8 deletions include/cantera/oneD/Boundary1D.h
Expand Up @@ -41,6 +41,14 @@ class Boundary1D : public Domain1D
_init(1);
}

virtual string type() const {
return "boundary";
}

virtual bool isConnector() {
return true;
}

//! Set the temperature.
virtual void setTemperature(double t) {
m_temp = t;
Expand Down Expand Up @@ -75,6 +83,16 @@ class Boundary1D : public Domain1D
m_mdot = mdot;
}

//! Set tangential velocity gradient [1/s] at this boundary.
virtual void setSpreadRate(double V0) {
throw NotImplementedError("Boundary1D::setSpreadRate");
}

//! Tangential velocity gradient [1/s] at this boundary.
virtual double spreadRate() {
throw NotImplementedError("Boundary1D::spreadRate");
}

//! The total mass flow rate [kg/m2/s].
virtual double mdot() {
return m_mdot;
Expand Down Expand Up @@ -117,15 +135,17 @@ class Inlet1D : public Boundary1D

Inlet1D(shared_ptr<Solution> solution, const string& id="");

//! set spreading rate
virtual string type() const {
return "inlet";
}

virtual void setSpreadRate(double V0);

//! spreading rate
virtual double spreadRate() {
return m_V0;
}

virtual void showSolution(const double* x);
virtual void show(const double* x);

virtual size_t nSpecies() {
return m_nsp;
Expand Down Expand Up @@ -167,7 +187,11 @@ class Empty1D : public Boundary1D
m_id = id;
}

virtual void showSolution(const double* x) {}
virtual string type() const {
return "empty";
}

virtual void show(const double* x) {}

virtual void init();

Expand Down Expand Up @@ -195,6 +219,10 @@ class Symm1D : public Boundary1D
m_id = id;
}

virtual string type() const {
return "symmetry-plane";
}

virtual void init();

virtual void eval(size_t jg, double* xg, double* rg,
Expand All @@ -221,6 +249,10 @@ class Outlet1D : public Boundary1D
m_id = id;
}

virtual string type() const {
return "outlet";
}

virtual void init();

virtual void eval(size_t jg, double* xg, double* rg,
Expand All @@ -242,7 +274,11 @@ class OutletRes1D : public Boundary1D

OutletRes1D(shared_ptr<Solution> solution, const string& id="");

virtual void showSolution(const double* x) {}
virtual string type() const {
return "outlet-reservoir";
}

virtual void show(const double* x) {}

virtual size_t nSpecies() {
return m_nsp;
Expand Down Expand Up @@ -284,6 +320,10 @@ class Surf1D : public Boundary1D
m_id = id;
}

virtual string type() const {
return "surface";
}

virtual void init();

virtual void eval(size_t jg, double* xg, double* rg,
Expand All @@ -292,9 +332,9 @@ class Surf1D : public Boundary1D
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);

virtual void showSolution_s(std::ostream& s, const double* x);
virtual void show(std::ostream& s, const double* x);

virtual void showSolution(const double* x);
virtual void show(const double* x);
};

/**
Expand All @@ -307,6 +347,10 @@ class ReactingSurf1D : public Boundary1D
ReactingSurf1D();
ReactingSurf1D(shared_ptr<Solution> solution, const std::string& id="");

virtual string type() const {
return "reacting-surface";
}

virtual void setKinetics(shared_ptr<Kinetics> kin);

//! @deprecated To be removed after Cantera 3.0; replaced by setKinetics
Expand Down Expand Up @@ -339,7 +383,7 @@ class ReactingSurf1D : public Boundary1D
std::copy(x, x+m_nsp, m_fixed_cov.begin());
}

virtual void showSolution(const double* x);
virtual void show(const double* x);

protected:
InterfaceKinetics* m_kin = nullptr;
Expand Down
30 changes: 22 additions & 8 deletions include/cantera/oneD/Domain1D.h
Expand Up @@ -11,7 +11,7 @@
namespace Cantera
{

// domain types
// domain types (deprecated); to be removed after Cantera 3.0
const int cFlowType = 50;
const int cFreeFlow = 51;
const int cAxisymmetricStagnationFlow = 52;
Expand Down Expand Up @@ -53,8 +53,14 @@ class Domain1D
Domain1D& operator=(const Domain1D&) = delete;

//! Domain type flag.
int domainType() {
return m_type;
//! @deprecated To be changed after Cantera 3.0; for new behavior, see type.
int domainType();

//! String indicating the domain implemented.
//! @since New in Cantera 3.0.
//! @todo Transition back to domainType after Cantera 3.0
virtual string type() const {
return "domain";
}

//! The left-to-right location of this domain.
Expand All @@ -63,8 +69,8 @@ class Domain1D
}

//! True if the domain is a connector domain.
bool isConnector() {
return (m_type >= cConnectorType);
virtual bool isConnector() {
return false;
}

//! Set the solution manager.
Expand Down Expand Up @@ -466,10 +472,18 @@ class Domain1D
}
}

virtual void showSolution_s(std::ostream& s, const doublereal* x) {}
//! @deprecated To be removed after Cantera 3.0; replaced by show
virtual void showSolution_s(std::ostream& s, const double* x);

//! Print the solution.
//! @deprecated To be removed after Cantera 3.0; replaced by show
virtual void showSolution(const double* x);

//! Print the solution.
virtual void show(std::ostream& s, const double* x) {}

//! Print the solution.
virtual void showSolution(const doublereal* x);
virtual void show(const double* x);

doublereal z(size_t jlocal) const {
return m_z[jlocal];
Expand Down Expand Up @@ -546,7 +560,7 @@ class Domain1D
vector_fp m_z;
OneDim* m_container = nullptr;
size_t m_index;
int m_type = 0;
int m_type = 0; //!< @deprecated To be removed after Cantera 3.0

//! Starting location within the solution vector for unknowns that
//! correspond to this domain
Expand Down
74 changes: 74 additions & 0 deletions include/cantera/oneD/DomainFactory.h
@@ -0,0 +1,74 @@
//! @file DomainFactory.h

// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.

#ifndef DOMAIN_FACTORY_H
#define DOMAIN_FACTORY_H

#include "cantera/oneD/Domain1D.h"
#include "cantera/base/FactoryBase.h"

namespace Cantera
{

//! Factory class to create domain objects
//!
//! This class is mainly used via the newDomain() function, for example:
//!
//! ```cpp
//! shared_ptr<Domain1D> d1 = newDomain("Inlet", sol, "reactants");
//! ```
//!
//! @ingroup onedim
class DomainFactory : public Factory<Domain1D, shared_ptr<Solution>, const string&>
{
public:
/**
* Return a pointer to the factory. On the first call, a new instance is
* created. Since there is no need to instantiate more than one factory,
* on all subsequent calls, a pointer to the existing factory is returned.
*/
static DomainFactory* factory();

virtual void deleteFactory();

private:
//! Pointer to the single instance of the factory
static DomainFactory* s_factory;

//! default constructor, which is defined as private
DomainFactory();

//! Mutex for use when calling the factory
static std::mutex domain_mutex;
};

//! Create a Domain object of the specified type. An optional template argument will
//! dynamically cast Domain1D to the desired specialization.
//! @param domainType string identifying domain type.
//! @param solution Solution holding ThermoPhase, Kinetics and Transport objects.
//! @param id string identifier describing domain. If omitted, id defaults to the
//! domain type identifier.
//! @ingroup onedim
template <class T=Domain1D>
shared_ptr<T> newDomain(
const string& domainType, shared_ptr<Solution> solution, const string& id="")
{
string id_ = id;
if (id_ == "") {
id_ = domainType;
}
auto ret = std::dynamic_pointer_cast<T>(
shared_ptr<Domain1D>(
DomainFactory::factory()->create(domainType, solution, id_)));
if (!ret) {
throw CanteraError("newDomain",
"Invalid cast: unable to access 'Domain1D' as '{}'.", demangle(typeid(T)));
}
return ret;
}

}

#endif
2 changes: 2 additions & 0 deletions include/cantera/oneD/IonFlow.h
Expand Up @@ -40,6 +40,8 @@ class IonFlow : public StFlow
//! @param points initial number of grid points
IonFlow(shared_ptr<Solution> sol, const std::string& id="", size_t points = 1);

virtual string type() const;

//! set the solving stage
virtual void setSolvingStage(const size_t phase);

Expand Down