00001 // GenerationReaction.cpp: implementation of the GenerationReaction class. 00002 // 00004 00005 #include "GenerationReaction.h" 00006 00008 // Construction/Destruction 00010 00011 GenerationReaction::GenerationReaction(Chemical *Generator, Chemical *Product, RateConstant *k_g, std::string reactionName) 00012 :Reaction(reactionName) 00013 { 00014 // stoichiometry 00015 this->Generator = chemicals.size(); 00016 chemicals.push_back(Generator); 00017 numberOfEachChemicalChangedByReaction.push_back(0); 00018 00019 this->Product = chemicals.size(); 00020 chemicals.push_back(Product); 00021 numberOfEachChemicalChangedByReaction.push_back(+1); 00022 00023 // rates 00024 this->k_g = rateConstants.size(); 00025 rateConstants.push_back(k_g); 00026 00027 // put enough dummy chemicalJacobian elements on the vector 00028 // - they are recomputed every time you ask for the chemicalJacobian 00029 chemicalJacobian.push_back(new JElement(-1,-1)); 00030 00031 this->SetTeXForm(); 00032 } 00033 00034 GenerationReaction::~GenerationReaction() 00035 { 00036 00037 } 00038 00039 double GenerationReaction::GetRate() const 00040 { 00041 return rateConstants[k_g]->GetValue() * chemicals[Generator]->GetAmount(); 00042 } 00043 00044 void GenerationReaction::SetTeXForm() 00045 { 00046 std::stringstream stream; 00047 // TeX form of the reaction 00048 stream << rateConstants[k_g]->GetTeXName().c_str(); 00049 stream << "\\left [" << chemicals[Generator]->GetTeXName().c_str(); 00050 stream << "\\right ]"; 00051 // add a NULL 00052 //int namesize = (chemicals[Generator]->GetName()).length(); 00053 //stream << (chemicals[Generator]->GetName())[namesize]; 00054 stream << ends; 00055 // set the TeX string equal to what's in the stream 00056 m_sTeXForm = stream.str(); 00057 // free up the string 00058 // stream.rdbuf()->freeze(0); 00059 } 00060 00061 std::vector<Reaction::JElement *> *GenerationReaction::GetChemicalJacobian() 00062 { 00063 chemicalJacobian[0]->SetWithRespectTo(chemicals[Generator]->GetChemicalNumber()); 00064 chemicalJacobian[0]->SetJValue(rateConstants[k_g]->GetValue()); 00065 00066 return &chemicalJacobian; 00067 }