void Foam::combustionModels::EDC<ReactionThermo>::correct() { tmp<volScalarField> tepsilon(this->turbulence().epsilon()); const volScalarField& epsilon = tepsilon(); tmp<volScalarField> tmu(this->turbulence().mu()); const volScalarField& mu = tmu(); tmp<volScalarField> tk(this->turbulence().k()); const volScalarField& k = tk(); tmp<volScalarField> trho(this->rho()); const volScalarField& rho = trho(); scalarField tauStar(epsilon.size(), 0); if (version_ == EDCversions::v2016) { tmp<volScalarField> ttc(this->chemistryPtr_->tc()); const volScalarField& tc = ttc(); forAll(tauStar, i) { const scalar nu = mu[i]/(rho[i] + small); const scalar Da = max(min(sqrt(nu/(epsilon[i] + small))/tc[i], 10), 1e-10); const scalar ReT = sqr(k[i])/(nu*epsilon[i] + small); const scalar CtauI = min(C1_/(Da*sqrt(ReT + 1)), 2.1377); const scalar CgammaI = max(min(C2_*sqrt(Da*(ReT + 1)), 5), 0.4082); const scalar gammaL = CgammaI*pow025(nu*epsilon[i]/(sqr(k[i]) + small)); tauStar[i] = CtauI*sqrt(nu/(epsilon[i] + small)); if (gammaL >= 1) { kappa_[i] = 1; } else { kappa_[i] = max ( min ( pow(gammaL, exp1_)/(1 - pow(gammaL, exp2_)), 1 ), 0 ); } } }
bool LDACalc(string datafile,string labelfile,string fea_resfile,string projection_mat_resfile){ if(fexist(fea_resfile)&&fexist(projection_mat_resfile)) return true; if(!fexist(datafile)||!fexist(labelfile)) return false; Matrix Fea; Fea.readfile(datafile); ifstream label_fin(labelfile.c_str()); vector<int> label; int temp; double size = Fea.Getrows(); while(!label_fin.eof()){ label_fin>>temp; label.push_back(temp); } label_fin.close(); //Sw computing Matrix Sw = zeros(Fea.Getcols(),Fea.Getcols()); vector<bool> t_flag(label.size(),false); for(vector<int>::size_type n=0;n<label.size();n++){ if(t_flag[n]) continue; vector<int> id = findVec(label,label[n]); for(vector<int>::size_type j=0;j<id.size();j++) t_flag[id[j]] = true; Matrix fea = Fea.select(id,1); vector<vector<double>> tmdata(1,fea.mean(1)); Matrix tmu(1,fea.Getcols()); tmu.setdata(tmdata); fea = fea - ones(fea.Getrows(),1)*tmu; Sw = Sw + fea.trans()*fea; } Sw = Sw/size; //St computing vector<vector<double>> mdata(1,Fea.mean(1)); Matrix mu(1,Fea.Getcols()); mu.setdata(mdata); Matrix St = Fea.trans()*Fea/size-mu.trans()*mu; //Generalized Eigen problem. vector<double> D(Sw.Getrows(),0); Matrix V(Sw.Getrows(),Sw.Getrows()); if(generalized_sym_eig(St, Sw, D, V)){ Matrix Fea_LDA = Fea * V; Fea_LDA.writefile(fea_resfile); V.writefile(projection_mat_resfile); return true; } else{ cout<<"Eigen Module Malfunctions."<<endl; return false; } }