void OpenSMOKE_GasStream::AssignMoleFractions(const vector<string> _names, const vector<double> _values) { BzzVector mole(mix->NumberOfSpecies()); for(int k=0; k<int(_names.size()); k++) mole[mix->recognize_species(_names[k])] = _values[k]; AssignMoleFractions(mole); }
// Equivalence Ratio (most general) BzzVector OpenSMOKE_GasStream::EquivalenceRatio(const double equivalence_ratio, const vector<string> fuel_names, BzzVector &moles_fuel, const vector<string> oxidizer_names, BzzVector &moles_oxidizer) { int j; int number_of_fuels = moles_fuel.Size(); int number_of_oxidizers = moles_oxidizer.Size(); BzzVector nC(number_of_fuels); BzzVector nH(number_of_fuels); BzzVector nO(number_of_fuels); BzzVector nOxidizers(number_of_oxidizers); int jC = mix->recognize_element_without_error("c"); int jH = mix->recognize_element_without_error("h"); int jO = mix->recognize_element_without_error("o"); if (jC>0) for(j=1;j<=number_of_fuels;j++) nC[j] = mix->elements[jC][mix->recognize_species(fuel_names[j])]; if (jH>0) for(j=1;j<=number_of_fuels;j++) nH[j] = mix->elements[jH][mix->recognize_species(fuel_names[j])]; if (jO>0) for(j=1;j<=number_of_fuels;j++) nO[j] = mix->elements[jO][mix->recognize_species(fuel_names[j])]; double nFuel = equivalence_ratio*moles_fuel.GetSumElements(); int jO2 = 0; for(j=1;j<=number_of_oxidizers;j++) if (oxidizer_names[j] == "O2") { jO2 = j; break;} double nO2 = ( 2.*Dot(nC,moles_fuel) + 0.50*Dot(nH,moles_fuel) - Dot(nO,moles_fuel))/2.; for(j=1;j<=number_of_oxidizers;j++) nOxidizers[j] = moles_oxidizer[j]/moles_oxidizer[jO2]*nO2; double n = nFuel + nOxidizers.GetSumElements(); BzzVector mole(mix->NumberOfSpecies()); for(j=1;j<=number_of_fuels;j++) mole[mix->recognize_species(fuel_names[j])] += equivalence_ratio*moles_fuel[j]/n; for(j=1;j<=number_of_oxidizers;j++) mole[mix->recognize_species(oxidizer_names[j])] += nOxidizers[j]/n; //for(j=1;j<=number_of_fuels;j++) // cout << fuel_names[j] << " " << mole[mix->recognize_species(fuel_names[j])] << endl; //for(j=1;j<=number_of_oxidizers;j++) // cout << oxidizer_names[j] << " " << mole[mix->recognize_species(oxidizer_names[j])] << endl; return mole; }
// Avogadro constant inline quantity N_sub_A() { return mole() / mole() * // to help msvc Rep( 6.02214199e+23L ) / mole(); }
ParticleSet* ParticleSetPool::createESParticleSet(xmlNodePtr cur, const string& target) { TinyVector<int,OHMMS_DIM> tilefactor; Tensor<int,OHMMS_DIM> tilematrix(1,0,0,0,1,0,0,0,1); double lr_cut=10; string h5name; string source("i"); string bc("p p p"); OhmmsAttributeSet attribs; attribs.add(h5name, "href"); attribs.add(tilefactor, "tile"); attribs.add(tilematrix, "tilematrix"); attribs.add(source, "source"); attribs.add(bc, "bconds"); attribs.add(lr_cut, "LR_dim_cutoff"); attribs.put(cur); ParticleSet* ions=getParticleSet(source); if(ions==0) { ions=new MCWalkerConfiguration; ions->setName(source); } //set the boundary condition ions->Lattice.LR_dim_cutoff=lr_cut; std::istringstream is(bc); char c; int idim=0; while(!is.eof() && idim<OHMMS_DIM) { if(is>>c) ions->Lattice.BoxBConds[idim++]=(c=='p'); } //initialize ions from hdf5 hid_t h5=-1; if(myComm->rank()==0) h5 = H5Fopen(h5name.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT); ESHDFIonsParser ap(*ions,h5,myComm); ap.put(cur); ap.expand(tilematrix); if(h5>-1) H5Fclose(h5); //failed to initialize the ions if(ions->getTotalNum() == 0) return 0; typedef ParticleSet::SingleParticleIndex_t SingleParticleIndex_t; vector<SingleParticleIndex_t> grid(OHMMS_DIM,SingleParticleIndex_t(1)); ions->Lattice.reset(); ions->Lattice.makeGrid(grid); if(SimulationCell==0) { SimulationCell = new ParticleSet::ParticleLayout_t(ions->Lattice); } //create the electrons MCWalkerConfiguration* qp = new MCWalkerConfiguration; qp->setName(target); qp->Lattice.copy(ions->Lattice); //qp->Lattice.reset(); //qp->Lattice.makeGrid(grid); app_log() << " Simulation cell radius = " << qp->Lattice.SimulationCellRadius << endl; app_log() << " Wigner-Seitz radius = " << qp->Lattice.WignerSeitzRadius << endl; SimulationCell->print(app_log()); myPool[target]=qp; myPool[source]=ions; //addParticleSet(qp); //addParticleSet(ions); {//get the number of electrons per spin vector<int> num_spin; xmlNodePtr cur1=cur->children; while(cur1!=NULL) { string cname1((const char*)cur1->name); if(cname1 == OrbitalBuilderBase::sd_tag) { num_spin.clear(); xmlNodePtr cur2=cur1->children; while(cur2!=NULL) { string cname2((const char*)cur2->name); if(cname2 == OrbitalBuilderBase::det_tag) { int n=0; OhmmsAttributeSet a; a.add(n,"size"); a.put(cur2); if(num_spin.size()<2) num_spin.push_back(n); } cur2=cur2->next; } } cur1=cur1->next; } //create species SpeciesSet& species=qp->getSpeciesSet(); //add up and down species.addSpecies("u"); if(num_spin.size()>1) species.addSpecies("d"); int chid=species.addAttribute("charge"); for(int i=0; i<num_spin.size(); ++i) species(chid,i)=-1.0; int mid=species.addAttribute("membersize"); for(int i=0; i<num_spin.size(); ++i) species(mid,i)=num_spin[i]; mid=species.addAttribute("mass"); for(int i=0; i<num_spin.size(); ++i) species(mid,i)=1.0; qp->create(num_spin); } //name it with the target qp->setName(target); //assign non-trivial positions for the quanmtum particles if(qp->Lattice.SuperCellEnum) { makeUniformRandom(qp->R); qp->R.setUnit(PosUnit::LatticeUnit); qp->convert2Cart(qp->R); qp->createSK(); } else { InitMolecularSystem mole(this); if(ions->getTotalNum()>1) mole.initMolecule(ions,qp); else mole.initAtom(ions,qp); } //for(int i=0; i<qp->getTotalNum(); ++i) // cout << qp->GroupID[i] << " " << qp->R[i] << endl; if(qp->getTotalNum() == 0 || ions->getTotalNum() == 0) { delete qp; delete ions; APP_ABORT("ParticleSetPool failed to create particlesets for the electron structure calculation"); return 0; } return qp; }