More copy constructors and assignment operators.

This commit is contained in:
Harry Moffat 2010-06-25 19:59:27 +00:00
parent b7bc8a8eb6
commit 0cbec89c52
4 changed files with 213 additions and 21 deletions

View file

@ -102,7 +102,10 @@ namespace Cantera {
m_nirrev(0),
m_nrev(0),
m_finalized(false)
{
{
m_kdata = new GasKineticsData();
m_kdata->m_temp = 0.0;
m_rxnstoich = new ReactionStoichMgr();
*this = right;
}
//====================================================================================================================
@ -130,8 +133,7 @@ namespace Cantera {
m_falloff_concm = right.m_falloff_concm;
m_irrev = right.m_irrev;
// needs updating
m_rxnstoich = (right.m_rxnstoich);
*m_rxnstoich = *(right.m_rxnstoich);
m_fwdOrder = right.m_fwdOrder;
m_nirrev = right.m_nirrev;

View file

@ -24,12 +24,18 @@
using namespace std;
namespace Cantera {
//====================================================================================================================
// create stoichiometry managers for the reactants of all reactions,
// for the products of the reversible reactions, and for the
// products of the irreversible reactions.
ReactionStoichMgr::
ReactionStoichMgr() {
ReactionStoichMgr::ReactionStoichMgr() :
m_reactants(0),
m_revproducts(0),
m_irrevproducts(0)
#ifdef INCL_STOICH_WRITER
, m_rwriter(0)
#endif
{
m_reactants = new StoichManagerN;
m_revproducts = new StoichManagerN;
m_irrevproducts = new StoichManagerN;
@ -38,19 +44,54 @@ namespace Cantera {
#endif
m_dummy.resize(10,1.0);
}
//====================================================================================================================
// delete the three stoichiometry managers
ReactionStoichMgr::~ReactionStoichMgr() {
ReactionStoichMgr::~ReactionStoichMgr()
{
delete m_reactants;
delete m_revproducts;
delete m_irrevproducts;
// delete m_global;
#ifdef INCL_STOICH_WRITER
delete m_rwriter;
#endif
}
//====================================================================================================================
ReactionStoichMgr::ReactionStoichMgr(const ReactionStoichMgr &right) :
m_reactants(0),
m_revproducts(0),
m_irrevproducts(0)
#ifdef INCL_STOICH_WRITER
, m_rwriter(0)
#endif
{
m_reactants = new StoichManagerN(*right.m_reactants);
m_revproducts = new StoichManagerN(*right.m_revproducts);
m_irrevproducts = new StoichManagerN(*right.m_irrevproducts);
m_dummy = right.m_dummy;
#ifdef INCL_STOICH_WRITER
m_rwriter = new StoichManagerN(right.m_writer);
#endif
}
//====================================================================================================================
ReactionStoichMgr & ReactionStoichMgr::operator=(const ReactionStoichMgr &right)
{
if (this != &right) {
if (m_reactants) delete(m_reactants);
if (m_revproducts) delete(m_revproducts);
if (m_irrevproducts) delete(m_irrevproducts);
m_reactants = new StoichManagerN(*right.m_reactants);
m_revproducts = new StoichManagerN(*right.m_revproducts);
m_irrevproducts = new StoichManagerN(*right.m_irrevproducts);
m_dummy = right.m_dummy;
#ifdef INCL_STOICH_WRITER
if(m_writer) delete (m_writer);
m_rwriter = new StoichManagerN(right.m_writer);
#endif
}
return *this;
}
//====================================================================================================================
void ReactionStoichMgr::
add(int rxn, const vector_int& reactants, const vector_int& products,
bool reversible) {

View file

@ -70,6 +70,10 @@ namespace Cantera {
/// Destructor.
virtual ~ReactionStoichMgr();
ReactionStoichMgr(const ReactionStoichMgr &right);
ReactionStoichMgr & operator=(const ReactionStoichMgr &right);
/**
* Add a reaction with mass-action kinetics. Vectors
* 'reactants' and 'products' contain the integer species
@ -236,6 +240,9 @@ namespace Cantera {
void writeNetProductionRates(std::ostream& f);
void writeMultiplyReactants(std::ostream& f);
void writeMultiplyRevProducts(std::ostream& f);
protected:
StoichManagerN* m_reactants;
StoichManagerN* m_revproducts;
StoichManagerN* m_irrevproducts;

View file

@ -164,8 +164,26 @@ namespace Cantera {
public:
C1( int rxn = 0, int ic0 = 0)
: m_rxn (rxn), m_ic0 (ic0) {}
C1(int rxn = 0, int ic0 = 0) :
m_rxn (rxn),
m_ic0 (ic0)
{
}
C1(const C1 &right) :
m_rxn (right.m_rxn),
m_ic0 (right.m_ic0)
{
}
C1& operator=(const C1 &right)
{
if (this != &right) {
m_rxn = right.m_rxn;
m_ic0 = right.m_ic0;
}
return *this;
}
int data(std::vector<int>& ic) {
ic.resize(1);
@ -216,7 +234,9 @@ namespace Cantera {
}
private:
//! Reaction number
int m_rxn;
//! Species number
int m_ic0;
};
@ -231,6 +251,23 @@ namespace Cantera {
C2( int rxn = 0, int ic0 = 0, int ic1 = 0)
: m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1) {}
C2(const C2 &right) :
m_rxn(right.m_rxn),
m_ic0(right.m_ic0),
m_ic1(right.m_ic1)
{
}
C2& operator=(const C2 &right)
{
if (this != &right) {
m_rxn = right.m_rxn;
m_ic0 = right.m_ic0;
m_ic1 = right.m_ic1;
}
return *this;
}
int data(std::vector<int>& ic) {
ic.resize(2);
ic[0] = m_ic0;
@ -296,7 +333,8 @@ namespace Cantera {
* Species indecise -> index into the species vector for the
* two species.
*/
int m_ic0, m_ic1;
int m_ic0;
int m_ic1;
};
@ -309,6 +347,25 @@ namespace Cantera {
C3( int rxn = 0, int ic0 = 0, int ic1 = 0, int ic2 = 0)
: m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1), m_ic2 (ic2) {}
C3(const C3 &right) :
m_rxn(right.m_rxn),
m_ic0(right.m_ic0),
m_ic1(right.m_ic1),
m_ic2(right.m_ic2)
{
}
C3& operator=(const C3 &right)
{
if (this != &right) {
m_rxn = right.m_rxn;
m_ic0 = right.m_ic0;
m_ic1 = right.m_ic1;
m_ic2 = right.m_ic2;
}
return *this;
}
int data(std::vector<int>& ic) {
ic.resize(3);
ic[0] = m_ic0;
@ -367,7 +424,10 @@ namespace Cantera {
out[m_ic2] += s;
}
private:
int m_rxn, m_ic0, m_ic1, m_ic2;
int m_rxn;
int m_ic0;
int m_ic1;
int m_ic2;
};
@ -378,11 +438,17 @@ namespace Cantera {
*/
class C_AnyN {
public:
C_AnyN() : m_rxn (-1) {}
C_AnyN( int rxn, const vector_int& ic, const vector_fp& order,
const vector_fp& stoich)
: m_rxn (rxn) {
C_AnyN() :
m_n(0),
m_rxn(-1)
{
}
C_AnyN(int rxn, const vector_int& ic, const vector_fp& order, const vector_fp& stoich) :
m_n(0),
m_rxn(rxn)
{
m_n = ic.size();
m_ic.resize(m_n);
m_order.resize(m_n);
@ -394,6 +460,27 @@ namespace Cantera {
}
}
C_AnyN(const C_AnyN &right) :
m_n(right.m_n),
m_rxn(right.m_rxn),
m_ic(right.m_ic),
m_order(right.m_order),
m_stoich(right.m_stoich)
{
}
C_AnyN& operator=(const C_AnyN &right)
{
if (this != &right) {
m_n = right.m_n;
m_rxn = right.m_rxn;
m_ic = right.m_ic;
m_order = right.m_order;
m_stoich = right.m_stoich;
}
return *this;
}
int data(std::vector<int>& ic) {
ic.resize(m_n);
int n;
@ -627,7 +714,34 @@ namespace Cantera {
* DGG - the problem is that the number of reactions and species
* are not known initially.
*/
StoichManagerN() {}
StoichManagerN()
{
}
StoichManagerN(const StoichManagerN &right) :
m_c1_list(right.m_c1_list),
m_c2_list(right.m_c2_list),
m_c3_list(right.m_c3_list),
m_cn_list(right.m_cn_list),
m_n(right.m_n),
m_loc(right.m_loc)
{
}
StoichManagerN& operator=(const StoichManagerN &right)
{
if (this != &right) {
m_c1_list = right.m_c1_list;
m_c2_list = right.m_c2_list;
m_c3_list = right.m_c3_list;
m_cn_list = right.m_cn_list;
m_n = right.m_n;
m_loc = right.m_loc;
}
return *this;
}
/**
* Add a single reaction to the list of reactions that this
@ -795,7 +909,31 @@ namespace Cantera {
class StoichWriter {
public:
StoichWriter() {}
StoichWriter()
{
}
StoichWriter(const StoichWriter &right) :
m_mult(right.m_mult),
m_ir(right.m_ir),
m_dr(right.m_dr),
m_is(right.m_is),
m_ds(right.m_ds)
{
}
StoichWriter& operator=(const StoichWriter &right)
{
if (this != &right) {
m_mult = right.m_mult;
m_ir = right.m_ir;
m_dr = right.m_dr;
m_is = right.m_is;
m_ds = right.m_ds;
}
return *this;
}
void add(int rxn, const vector_int& k) {
int n, nn = k.size();
@ -841,7 +979,11 @@ namespace Cantera {
std::string decrRxn(int rxn) { return m_dr[rxn]; }
private:
std::map<int, std::string> m_mult, m_ir, m_dr, m_is, m_ds;
std::map<int, std::string> m_mult;
std::map<int, std::string> m_ir;
std::map<int, std::string> m_dr;
std::map<int, std::string> m_is;
std::map<int, std::string> m_ds;
};
#endif