00001 // TrimerFormation.cpp: implementation of the CTrimerFormation class. 00002 // 00004 00005 #include "TrimerFormation.h" 00006 00008 // Construction/Destruction 00010 00011 CTrimerFormation::CTrimerFormation(Chemical *A, Chemical *B, Chemical *C, Chemical *Trimer, RateConstant *k_t, std::string reactionName) 00012 :Reaction(reactionName) 00013 { 00014 // stoichiometry 00015 this->A = chemicals.size(); 00016 chemicals.push_back(A); 00017 numberOfEachChemicalChangedByReaction.push_back(-1); 00018 00019 this->B = chemicals.size(); 00020 chemicals.push_back(B); 00021 numberOfEachChemicalChangedByReaction.push_back(-1); 00022 00023 this->C = chemicals.size(); 00024 chemicals.push_back(C); 00025 numberOfEachChemicalChangedByReaction.push_back(-1); 00026 00027 this->Trimer = chemicals.size(); 00028 chemicals.push_back(Trimer); 00029 numberOfEachChemicalChangedByReaction.push_back(+1); 00030 00031 // rates 00032 this->k_t = rateConstants.size(); 00033 rateConstants.push_back(k_t); 00034 00035 // put enough dummy chemicalJacobian elements on the vector 00036 // - they are recomputed every time you ask for the chemicalJacobian 00037 chemicalJacobian.push_back(new JElement(-1,-1)); 00038 chemicalJacobian.push_back(new JElement(-1,-1)); 00039 chemicalJacobian.push_back(new JElement(-1,-1)); 00040 00041 this->SetTeXForm(); 00042 00043 } 00044 00045 CTrimerFormation::~CTrimerFormation() 00046 { 00047 00048 } 00049 00050 double CTrimerFormation::GetRate() const 00051 { 00052 double amtA = chemicals[A]->GetAmount(); 00053 double amtB = chemicals[B]->GetAmount(); 00054 double amtC = chemicals[C]->GetAmount(); 00055 return rateConstants[k_t]->GetValue()*amtA*amtB*amtC; 00056 } 00057 00058 void CTrimerFormation::SetTeXForm() 00059 { 00060 strstream stream; 00061 // TeX form of the reaction 00062 stream << rateConstants[k_t]->GetTeXName().c_str(); 00063 stream << "\\left [" << chemicals[A]->GetTeXName().c_str(); 00064 stream << "\\right ]"; 00065 stream << " \\left [" << chemicals[B]->GetTeXName().c_str(); 00066 stream << "\\right ]"; 00067 stream << " \\left [" << chemicals[C]->GetTeXName().c_str(); 00068 stream << "\\right ]"; 00069 // add a NULL 00070 //int namesize = (chemicals[Generator]->GetName()).length(); 00071 //stream << (chemicals[Generator]->GetName())[namesize]; 00072 stream << ends; 00073 // set the TeX string equal to what's in the stream 00074 m_sTeXForm = stream.str(); 00075 // free up the string 00076 stream.rdbuf()->freeze(0); 00077 } 00078 00079 std::vector<Reaction::JElement *> *CTrimerFormation::GetChemicalJacobian() 00080 { 00081 double rate = rateConstants[k_t]->GetValue(); 00082 double amtA = chemicals[A]->GetAmount(); 00083 double amtB = chemicals[B]->GetAmount(); 00084 double amtC = chemicals[C]->GetAmount(); 00085 chemicalJacobian[0]->SetWithRespectTo(chemicals[A]->GetChemicalNumber()); 00086 chemicalJacobian[0]->SetJValue(rate*amtB*amtC); 00087 chemicalJacobian[1]->SetWithRespectTo(chemicals[B]->GetChemicalNumber()); 00088 chemicalJacobian[1]->SetJValue(rate*amtA*amtC); 00089 chemicalJacobian[2]->SetWithRespectTo(chemicals[C]->GetChemicalNumber()); 00090 chemicalJacobian[2]->SetJValue(rate*amtA*amtB); 00091 00092 return &chemicalJacobian; 00093 }