HRESULT CDataBlockStore::AddData(const void *pNewData, UINT bufferSize, UINT *pCurOffset) { HRESULT hr = S_OK; if (bufferSize == 0) { if (pCurOffset) { *pCurOffset = 0; } goto lExit; } if (!m_pFirst) { VN( m_pFirst = NEW CDataBlock() ); if (m_IsAligned) { m_pFirst->EnableAlignment(); } m_pLast = m_pFirst; } if (pCurOffset) *pCurOffset = m_Size + m_Offset; VH( m_pLast->AddData(pNewData, bufferSize, &m_pLast) ); m_Size += bufferSize; lExit: return hr; }
BOOL grmWriteFile( HANDLE * ph, LPTSTR lpb ) { HANDLE h = 0; DWORD dwi, dww; dwi = dww = 0; if( ph && lpb ) { dwi = strlen(lpb); h = *ph; } if( ( VH(h) ) && ( dwi ) ) { if( ( WriteFile(h,lpb,dwi,&dww,NULL) ) && ( dwi == dww ) ) { // success } else { CloseHandle(h); h = (HANDLE)-1; *ph = h; dww = 0; } } return( (BOOL)dww ); }
Variant StreamMessageFactory::GetUserControlStream(uint16_t operation, uint32_t streamId) { Variant result; VH(result, HT_FULL, 2, 0, 0, RM_HEADER_MESSAGETYPE_USRCTRL, 0, true); M_USRCTRL_TYPE(result) = (uint16_t) operation; M_USRCTRL_TYPE_STRING(result) = RTMPProtocolSerializer::GetUserCtrlTypeString(operation); M_USRCTRL_STREAMID(result) = streamId; return result; }
_Use_decl_annotations_ HRESULT CDataBlock::AddData(const void *pvNewData, uint32_t bufferSize, CDataBlock **ppBlock) { HRESULT hr = S_OK; uint32_t bytesToCopy; const uint8_t *pNewData = (const uint8_t*) pvNewData; if (m_maxSize == 0) { // This is a brand new DataBlock, fill it up m_maxSize = std::max<uint32_t>(8192, bufferSize); VN( m_pData = new uint8_t[m_maxSize] ); } assert(m_pData == AlignToPowerOf2(m_pData, c_DataAlignment)); bytesToCopy = std::min(m_maxSize - m_size, bufferSize); memcpy(m_pData + m_size, pNewData, bytesToCopy); pNewData += bytesToCopy; if (m_IsAligned) { assert(m_size == AlignToPowerOf2(m_size, c_DataAlignment)); m_size += AlignToPowerOf2(bytesToCopy, c_DataAlignment); } else { m_size += bytesToCopy; } bufferSize -= bytesToCopy; *ppBlock = this; if (bufferSize != 0) { assert(nullptr == m_pNext); // make sure we're not overwriting anything // Couldn't fit all data into this block, spill over into next VN( m_pNext = new CDataBlock() ); if (m_IsAligned) { m_pNext->EnableAlignment(); } VH( m_pNext->AddData(pNewData, bufferSize, ppBlock) ); } lExit: return hr; }
HRESULT CDataBlock::AddData(const void *pvNewData, UINT bufferSize, CDataBlock **ppBlock) { HRESULT hr = S_OK; UINT bytesToCopy; const BYTE *pNewData = (const BYTE*) pvNewData; if (m_maxSize == 0) { // This is a brand new DataBlock, fill it up m_maxSize = max(8192, bufferSize); VN( m_pData = NEW BYTE[m_maxSize] ); } D3DXASSERT(m_pData == AlignToPowerOf2(m_pData, c_DataAlignment)); bytesToCopy = min(m_maxSize - m_size, bufferSize); memcpy(m_pData + m_size, pNewData, bytesToCopy); pNewData += bytesToCopy; if (m_IsAligned) { D3DXASSERT(m_size == AlignToPowerOf2(m_size, c_DataAlignment)); m_size += AlignToPowerOf2(bytesToCopy, c_DataAlignment); } else { m_size += bytesToCopy; } bufferSize -= bytesToCopy; *ppBlock = this; if (bufferSize != 0) { D3DXASSERT(NULL == m_pNext); // make sure we're not overwriting anything // Couldn't fit all data into this block, spill over into next VN( m_pNext = NEW CDataBlock() ); if (m_IsAligned) { m_pNext->EnableAlignment(); } VH( m_pNext->AddData(pNewData, bufferSize, ppBlock) ); } lExit: return hr; }
Variant StreamMessageFactory::GetFlexStreamSend(uint32_t channelId, uint32_t streamId, double timeStamp, bool isAbsolute, string function, Variant ¶meters) { Variant result; VH(result, HT_FULL, channelId, timeStamp, 0, RM_HEADER_MESSAGETYPE_FLEXSTREAMSEND, streamId, isAbsolute); result[RM_FLEXSTREAMSEND][RM_FLEXSTREAMSEND_UNKNOWNBYTE] = (uint8_t) 0; result[RM_FLEXSTREAMSEND][RM_FLEXSTREAMSEND_PARAMS][(uint32_t) 0] = function; FOR_MAP(parameters, string, Variant, i) { result[RM_FLEXSTREAMSEND][RM_FLEXSTREAMSEND_PARAMS][ result[RM_FLEXSTREAMSEND][RM_FLEXSTREAMSEND_PARAMS].MapSize()] = MAP_VAL(i); }
void MultiplyAdjoint ( int maxRank, std::complex<Real> alpha, const Dense<std::complex<Real> >& A, const Dense<std::complex<Real> >& B, LowRank<std::complex<Real> >& C ) { #ifndef RELEASE CallStackEntry entry("hmat_tools::MultiplyAdjoint (F := D D^H)"); #endif typedef std::complex<Real> Scalar; const int m = A.Height(); const int n = B.Height(); const int minDim = std::min( m, n ); const int r = std::min( minDim, maxRank ); // C.U := alpha A B^H MultiplyAdjoint( alpha, A, B, C.U ); // Get the economic SVD of C.U, C.U = U Sigma V^H, overwriting C.U with U. Vector<Real> s( minDim ); Dense<Scalar> VH( minDim, n ); const int lwork = lapack::SVDWorkSize( m, n ); std::vector<Scalar> work( lwork ); std::vector<Real> rwork( 5*minDim ); lapack::SVD ( 'O', 'S', m, n, C.U.Buffer(), C.U.LDim(), s.Buffer(), 0, 1, VH.Buffer(), VH.LDim(), &work[0], lwork, &rwork[0] ); // Truncate the SVD in-place C.U.Resize( m, r ); s.Resize( r ); VH.Resize( r, n ); C.V.SetType( GENERAL ); C.V.Resize( n, r ); // Put (Sigma V^H)^T = (V^H)^T Sigma into C.V const int VHLDim = VH.LDim(); for( int j=0; j<r; ++j ) { const Real sigma = s.Get(j); Scalar* RESTRICT VCol = C.V.Buffer(0,j); const Scalar* RESTRICT VHRow = VH.LockedBuffer(j,0); for( int i=0; i<n; ++i ) VCol[i] = sigma*VHRow[i*VHLDim]; } }
BOOL grmCloseFile( HANDLE * ph ) { HANDLE h = 0; BOOL bRet = FALSE; if( ph ) h = *ph; if( VH(h) ) { if( CloseHandle(h) ) bRet = TRUE; } h = 0; if( ph ) *ph = h; return bRet; }
void LatticeDefGrad<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // Compute LatticeDefGrad tensor from displacement gradient for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { for (int i=0; i < numDims; ++i) { for (int j=0; j < numDims; ++j) { latticeDefGrad(cell,qp,i,j) = defgrad(cell,qp,i,j); } } JH(cell,qp) = J(cell,qp); } } // Since Intrepid will later perform calculations on the entire workset size // and not just the used portion, we must fill the excess with reasonable // values. Leaving this out leads to inversion of 0 tensors. for (int cell=workset.numCells; cell < worksetSize; ++cell) for (int qp=0; qp < numQPs; ++qp) for (int i=0; i < numDims; ++i) latticeDefGrad(cell,qp,i,i) = 1.0; if (weightedAverage) { ScalarT Jbar, wJbar, vol; for (int cell=0; cell < workset.numCells; ++cell) { Jbar = 0.0; vol = 0.0; for (int qp=0; qp < numQPs; ++qp) { Jbar += weights(cell,qp) * std::log( 1 + VH(cell,qp)*(Ctotal(cell,qp) - CtotalRef(cell,qp)) ); vol += weights(cell,qp); } Jbar /= vol; // Jbar = std::exp(Jbar); for (int qp=0; qp < numQPs; ++qp) { for (int i=0; i < numDims; ++i) { for (int j=0; j < numDims; ++j) { wJbar = std::exp( (1-alpha) * Jbar + alpha * std::log( 1 + VH(cell,qp)*(Ctotal(cell,qp) - CtotalRef(cell,qp)))); latticeDefGrad(cell,qp,i,j) *= std::pow( wJbar ,-1./3. ); } } JH(cell,qp) *= wJbar; } } } else { for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { JH(cell,qp) *= (1 + VH(cell,qp)*(Ctotal(cell,qp) - CtotalRef(cell,qp))); for (int i=0; i < numDims; ++i) { for (int j=0; j < numDims; ++j) { latticeDefGrad(cell,qp,i,j) *= std::pow(JH(cell,qp) ,-1./3. ); } } } } } }
int tester(const std::string &root_name) { std::vector<std::string> species_str_list; species_str_list.push_back( "N2" ); species_str_list.push_back( "O2" ); species_str_list.push_back( "N" ); species_str_list.push_back( "O" ); species_str_list.push_back( "NO" ); species_str_list.push_back( "C" ); species_str_list.push_back( "C2" ); species_str_list.push_back( "CN" ); species_str_list.push_back( "CH4" ); species_str_list.push_back( "CH3" ); species_str_list.push_back( "H" ); unsigned int n_species = species_str_list.size(); Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list ); Antioch::ReactionSet<Scalar> reaction_set( chem_mixture ); Antioch::read_reaction_set_data_xml<Scalar>( root_name + "/test_parsing.xml", true, reaction_set ); //photochemistry set here std::vector<Scalar> hv,lambda; std::ifstream solar_flux(root_name + "/solar_flux.dat"); std::string line; //// the unit management here is tedious and useless, but it's got // all the steps, if ever someone needs a reference getline(solar_flux,line); Antioch::Units<Scalar> solar_wave("nm"); Antioch::Units<Scalar> solar_irra("W/m2/nm"); Antioch::Units<Scalar> i_unit = solar_irra - (Antioch::Constants::Planck_constant_unit<Scalar>() + Antioch::Constants::light_celerity_unit<Scalar>() - solar_wave); //photons.s-1 = irradiance/(h*c/lambda) i_unit += Antioch::Units<Scalar>("nm"); //supress bin in unit calculations while(!solar_flux.eof()) { Scalar l,i,di; solar_flux >> l >> i >> di; hv.push_back(i /(Antioch::Constants::Planck_constant<Scalar>() * Antioch::Constants::light_celerity<Scalar>() / l) // irr/(h*c/lambda): power -> number of photons.s-1 * i_unit.get_SI_factor()); //SI for cs, keep nm for bin lambda.push_back(l * solar_wave.factor_to_some_unit("nm")); //nm if(lambda.size() == 796)break; } solar_flux.close(); std::vector<Scalar> CH4_s,CH4_lambda; std::ifstream CH4_file(root_name + "/CH4_hv_cs.dat"); Scalar T = 2000.L; Scalar Tr = 1.; Antioch::Units<Scalar> unitA_m1("kmol/m3/s"),unitA_0("s-1"),unitA_1("m3/kmol/s"),unitA_2("m6/kmol2/s"); Scalar Rcal = Antioch::Constants::R_universal<Scalar>() * Antioch::Constants::R_universal_unit<Scalar>().factor_to_some_unit("cal/mol/K"); getline(CH4_file,line); Antioch::Units<Scalar> cs_input("cm2"); Antioch::Units<Scalar> lambda_input("ang"); Scalar factor_cs = cs_input.get_SI_factor() / lambda_input.factor_to_some_unit("nm"); while(!CH4_file.eof()) { Scalar l,s; CH4_file >> l >> s; CH4_s.push_back(s * factor_cs); CH4_lambda.push_back(l * lambda_input.factor_to_some_unit("nm")); if(CH4_s.size() == 137)break; } CH4_file.close(); Antioch::ParticleFlux<std::vector<Scalar> > photons(lambda,hv); Antioch::KineticsConditions<Scalar,std::vector<Scalar> > conditions(T); // // Molar densities std::vector<Scalar> molar_densities(n_species,5e-4); Scalar tot_dens((Scalar)n_species * 5e-4); ///Elementary, + Kooij - Arrhenius conversion tested std::vector<Scalar> k; Scalar A,beta,Ea,D; // N2 -> 2 N A = 7e18 * unitA_0.get_SI_factor(); beta = -1.6; k.push_back(HE(T,A,beta)); // O2 -> 2 O A = 2e18 * unitA_0.get_SI_factor(); D = -5e-3; k.push_back(Bert(T,A,D)); //NO -> N + O A = 5e12 * unitA_0.get_SI_factor(); Ea = 149943.0; k.push_back(Arrh(T,A,Ea,Rcal)); beta = 0.42; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal)); //N2 + O -> NO + N A = 5.7e9 * unitA_1.get_SI_factor(); beta = 0.42; k.push_back(BHE(T,A,beta,D)); //NO + O -> NO + N A = 8.4e9 * unitA_1.get_SI_factor(); beta = 0.4; Ea = 38526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal)); k.push_back(Arrh(T,A,Ea,Rcal)); //C2 -> 2 C A = 3.7e11 * unitA_0.get_SI_factor(); beta = -0.42; // Ea = 138812.8; // cal/mol Ea = 69900; // K k.push_back(Kooij(T,A,beta,Ea,Tr,Scalar(1))); //CN -> C + N A = 2.5e11 * unitA_0.get_SI_factor(); beta = 0.40; Ea = 174240.9; D = 0.05; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal)); ///Duplicate Scalar A2,beta2,Ea2,D2,A3,beta3,Ea3,D3,A4,Ea4; // N2 -> 2 N A = 7e18 * unitA_0.get_SI_factor(); beta = -1.6; A2 = 5e17 * unitA_0.get_SI_factor(); beta2 = 0.5; A3 = 3e18 * unitA_0.get_SI_factor(); beta3 = -0.6; k.push_back(HE(T,A,beta) + HE(T,A2,beta2) + HE(T,A3,beta3)); // O2 -> 2 O A = 2e18 * unitA_0.get_SI_factor(); D = -5e-2; A2 = 2e+16 * unitA_0.get_SI_factor(); D2 = 0.003; k.push_back(Bert(T,A,D) + Bert(T,A2,D2)); // NO -> N + O A = 5e+12 * unitA_0.get_SI_factor(); Ea = 149943.0; A2 = 3.5e+10 * unitA_0.get_SI_factor(); Ea2 = 1943.0; A3 = 1.5e+8 * unitA_0.get_SI_factor(); Ea3 = 149.0; A4 = 5.5e+8 * unitA_0.get_SI_factor(); Ea4 = 943.0; k.push_back(Arrh(T,A,Ea,Rcal) + Arrh(T,A2,Ea2,Rcal) + Arrh(T,A3,Ea3,Rcal) + Arrh(T,A4,Ea4,Rcal)); // N2 + O -> NO + N A = 5.7e+9 * unitA_1.get_SI_factor(); beta = 0.42; D = -5e-3; A2 = 7e+7 * unitA_1.get_SI_factor(); beta2 = 0.5; D2 = 2.5e-5; k.push_back(BHE(T,A,beta,D) + BHE(T,A2,beta2,D2)); //NO + O -> NO + N A = 8.4e+09 * unitA_1.get_SI_factor(); beta = 0.40; Ea = 38526.0; A2 = 4e+07 * unitA_1.get_SI_factor(); beta2 = 0.50; Ea2 = 40500.0; A3 = 5e+10 * unitA_1.get_SI_factor(); beta3 = 0.10; Ea3 = 15000.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) + Kooij(T,A2,beta2,Ea2,Tr,Rcal) + Kooij(T,A3,beta3,Ea3,Tr,Rcal)); //C2 -> 2 C A = 3.7e+11 * unitA_0.get_SI_factor(); beta = -0.42; Ea = 138812.8; A2 = 5.0e+10 * unitA_0.get_SI_factor(); beta2 = 1.32; Ea2 = 150500.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) + Kooij(T,A2,beta2,Ea2,Tr,Rcal)); //CN -> C + N A = 2.5e+11 * unitA_0.get_SI_factor(); beta = 0.40; D = -5e-3; Ea = 174240.9; A2 = 5e+10 * unitA_0.get_SI_factor(); beta2 = 0.50; D2 = -1.5e-2; Ea2 = 4240.9; A3 = 3.2e+10 * unitA_0.get_SI_factor(); beta3 = 1.20; D3 = -2.5e-5; Ea3 = 174.9; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal) + VH(T,A2,beta2,Ea2,D2,Tr,Rcal) + VH(T,A3,beta3,Ea3,D3,Tr,Rcal)); //three body // N2 -> 2 N A = 7e18 * unitA_1.get_SI_factor(); beta = -1.6; Ea = 149943.0; k.push_back(HE(T,A,beta) * (Scalar(n_species) - 2. + 4.2857 + 4.2857) * 5e-4); // O2 -> 2 O A = 2e18 * unitA_1.get_SI_factor(); D = -5e-3; k.push_back(Bert(T,A,D) * (Scalar(n_species) - 2. + 5.0 + 5.0) * 5e-4); //NO -> N + O A = 5e12 * unitA_1.get_SI_factor(); k.push_back(Arrh(T,A,Ea,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); //N2 + O -> NO + N A = 5.7e9 * unitA_2.get_SI_factor(); beta = 0.42; D = -5e-3; k.push_back(BHE(T,A,beta,D) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); //NO + O -> NO + N A = 8.4e9 * unitA_2.get_SI_factor(); beta = 0.4; Ea = 38526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); //C2 -> 2 C A = 3.7e11 * unitA_1.get_SI_factor(); beta = -0.42; Ea = 138812.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) * Scalar(n_species) * 5e-4); //CN -> C + N A = 2.5e11 * unitA_1.get_SI_factor(); beta = 0.40; Ea = 729372.4; D = 5e-3; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal) * Scalar(n_species) * 5e-4); ///Lindemann Falloff // falloff is k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F // F = 1 // N2 -> 2 N A = 7e18 * unitA_1.get_SI_factor(); beta = -1.6; A2 = 5e15 * unitA_0.get_SI_factor(); beta2 = 0.5; k.push_back(HE(T,A,beta) / (1./tot_dens + HE(T,A,beta)/HE(T,A2,beta2)) ); // O2 -> 2 O A = 5e17 * unitA_1.get_SI_factor(); D = -2.5e-5; A2 = 2e18 * unitA_0.get_SI_factor(); D2 = -5e-3; k.push_back(Bert(T,A,D) / (1./tot_dens + Bert(T,A,D)/Bert(T,A2,D2)) ); //NO -> N + O A = 5.e+12 * unitA_1.get_SI_factor(); Ea = 149943.0; A2 = 3e+15 * unitA_0.get_SI_factor(); Ea2 = 200000.0; k.push_back(Arrh(T,A,Ea,Rcal) / (1./tot_dens + Arrh(T,A,Ea,Rcal)/Arrh(T,A2,Ea2,Rcal)) ); //N2 + O -> NO + N A = 5e+9 * unitA_2.get_SI_factor(); beta = 0.6; D = -5e-4; A2 = 5.7e+9 * unitA_1.get_SI_factor(); beta2 = -0.42; D2 = -5e-3; k.push_back(BHE(T,A,beta,D) / (1./tot_dens + BHE(T,A,beta,D)/BHE(T,A2,beta2,D2)) ); //NO + O -> NO + N A = 8.4e+09 * unitA_2.get_SI_factor(); beta = 0.40; Ea = 38526.0; A2 = 8.4e+05 * unitA_1.get_SI_factor(); beta2 = 0.02; Ea2 = 3526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) / (1./tot_dens + Kooij(T,A,beta,Ea,Tr,Rcal)/Kooij(T,A2,beta2,Ea2,Tr,Rcal)) ); //C2 -> 2 C A = 3.7e+11 * unitA_1.get_SI_factor(); beta = -0.42; Ea = 138812.8; A2 = 3.7e+12 * unitA_0.get_SI_factor(); beta2 = -0.52; Ea2 = 135000.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) / (1./tot_dens + Kooij(T,A,beta,Ea,Tr,Rcal)/Kooij(T,A2,beta2,Ea2,Tr,Rcal)) ); //CN -> C + N A = 5e+10 * unitA_1.get_SI_factor(); beta = -0.10; D = 1.5e-3; Ea = 150240.9; A2 = 2.5e+11 * unitA_0.get_SI_factor(); beta2 = 0.40; D2 = -0.005; Ea2 = 174240.9; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal) / (1./tot_dens + VH(T,A,beta,Ea,D,Tr,Rcal)/VH(T,A2,beta2,Ea2,D2,Tr,Rcal)) ); //Troe falloff //falloff is k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F // F is complicated... Scalar Pr,k0,kinf; Scalar Fc,alpha,T1,T2,T3; alpha = 0.562; T1 = 5836; T2 = 8552; T3 = 91; Fc = FcentTroe(T,alpha,T3,T1,T2); // N2 -> 2 N A = 7.e+18 * unitA_1.get_SI_factor(); beta = -1.6; A2 = 5.e+15 * unitA_0.get_SI_factor(); beta2 = 0.5; k0 = HE(T,A,beta); kinf = HE(T,A2,beta2); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); // O2 -> 2 O A = 5e17 * unitA_1.get_SI_factor(); D = -2.5e-5; A2 = 2e18 * unitA_0.get_SI_factor(); D2 = -5e-3; k0 = Bert(T,A,D); kinf = Bert(T,A2,D2); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); //NO -> N + O A = 5.e+12 * unitA_1.get_SI_factor(); Ea = 149943.0; A2 = 3e+15 * unitA_0.get_SI_factor(); Ea2 = 200000.0; k0 = Arrh(T,A,Ea,Rcal); kinf = Arrh(T,A2,Ea2,Rcal); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); //N2 + O -> NO + N A = 5e+9 * unitA_2.get_SI_factor(); beta = 0.6; D = -5e-4; A2 = 5.7e+9 * unitA_1.get_SI_factor(); beta2 = -0.42; D2 = -5e-3; k0 = BHE(T,A,beta,D); kinf = BHE(T,A2,beta2,D2); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); //NO + O -> NO + N A = 8.4e+09 * unitA_2.get_SI_factor(); beta = 0.40; Ea = 38526.0; A2 = 8.4e+05 * unitA_1.get_SI_factor(); beta2 = 0.02; Ea2 = 3526.0; k0 = Kooij(T,A,beta,Ea,Tr,Rcal); kinf = Kooij(T,A2,beta2,Ea2,Tr,Rcal); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); //C2 -> 2 C A = 3.7e+11 * unitA_1.get_SI_factor(); beta = -0.42; Ea = 138812.8; A2 = 3.7e+12 * unitA_0.get_SI_factor(); beta2 = -0.52; Ea2 = 135000.8; k0 = Kooij(T,A,beta,Ea,Tr,Rcal); kinf = Kooij(T,A2,beta2,Ea2,Tr,Rcal); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); //CN -> C + N A = 5e+10 * unitA_1.get_SI_factor(); beta = -0.10; D = 1.5e-3; Ea = 150240.9; A2 = 2.5e+11 * unitA_0.get_SI_factor(); beta2 = 0.40; D2 = -0.005; Ea2 = 174240.9; k0 = VH(T,A,beta,Ea,D,Tr,Rcal); kinf = VH(T,A2,beta2,Ea2,D2,Tr,Rcal); Pr = tot_dens * k0/kinf; k.push_back(k0 / (1./tot_dens + k0/kinf) * FTroe(Fc,Pr)); // //photochemistry k.push_back(k_photo(lambda,hv,CH4_lambda,CH4_s)); conditions.add_particle_flux(photons,k.size()-1); //Constant k.push_back(2.5e11); const Scalar tol = (std::numeric_limits<Scalar>::epsilon() < 1e-17L)? std::numeric_limits<Scalar>::epsilon() * 5000: std::numeric_limits<Scalar>::epsilon() * 100; int return_flag(0); for(unsigned int ir = 0; ir < k.size(); ir++) { const Antioch::Reaction<Scalar> * reac = &reaction_set.reaction(ir); if(std::abs(k[ir] - reac->compute_forward_rate_coefficient(molar_densities,conditions))/k[ir] > tol) { std::cout << *reac << std::endl; std::cout << std::scientific << std::setprecision(16) << "Error in kinetics comparison\n" << "reaction #" << ir << "\n" << "temperature: " << T << " K" << "\n" << "theory: " << k[ir] << "\n" << "calculated: " << reac->compute_forward_rate_coefficient(molar_densities,conditions) << "\n" << "relative error = " << std::abs(k[ir] - reac->compute_forward_rate_coefficient(molar_densities,conditions))/k[ir] << "\n" << "tolerance = " << tol << std::endl; return_flag = 1; } } return return_flag; }
SVDInfo ScaLAPACKHelper ( const AbstractDistMatrix<F>& APre, AbstractDistMatrix<F>& UPre, AbstractDistMatrix<Base<F>>& sPre, AbstractDistMatrix<F>& V, const SVDCtrl<Base<F>>& ctrl ) { DEBUG_CSE AssertScaLAPACKSupport(); SVDInfo info; #ifdef EL_HAVE_SCALAPACK typedef Base<F> Real; DistMatrix<F,MC,MR,BLOCK> A( APre ); DistMatrixWriteProxy<Real,Real,STAR,STAR> sProx(sPre); DistMatrixWriteProxy<F,F,MC,MR,BLOCK> UProx(UPre); auto& s = sProx.Get(); auto& U = UProx.Get(); const int m = A.Height(); const int n = A.Width(); const int k = Min(m,n); auto approach = ctrl.bidiagSVDCtrl.approach; if( approach == THIN_SVD || approach == COMPACT_SVD ) { Zeros( U, m, k ); DistMatrix<F,MC,MR,BLOCK> VH( A.Grid() ); Zeros( VH, k, n ); s.Resize( k, 1 ); auto descA = FillDesc( A ); auto descU = FillDesc( U ); auto descVH = FillDesc( VH ); scalapack::SVD ( m, n, A.Buffer(), descA.data(), s.Buffer(), U.Buffer(), descU.data(), VH.Buffer(), descVH.data() ); const bool compact = ( approach == COMPACT_SVD ); if( compact ) { const Real twoNorm = ( k==0 ? Real(0) : s.Get(0,0) ); const Real thresh = bidiag_svd::APosterioriThreshold ( m, n, twoNorm, ctrl.bidiagSVDCtrl ); Int rank = k; for( Int j=0; j<k; ++j ) { if( s.Get(j,0) <= thresh ) { rank = j; break; } } s.Resize( rank, 1 ); U.Resize( m, rank ); VH.Resize( rank, n ); } Adjoint( VH, V ); } else LogicError ("Only Thin and Compact singular value options currently supported"); #endif return info; }
int tester(const std::string &input_name) { std::vector<std::string> species_str_list; species_str_list.push_back( "N2" ); species_str_list.push_back( "O2" ); species_str_list.push_back( "N" ); species_str_list.push_back( "O" ); species_str_list.push_back( "NO" ); species_str_list.push_back( "C" ); species_str_list.push_back( "C2" ); species_str_list.push_back( "CN" ); unsigned int n_species = species_str_list.size(); Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list ); Antioch::ReactionSet<Scalar> reaction_set( chem_mixture ); Antioch::read_reaction_set_data_xml<Scalar>( input_name, true, reaction_set ); Scalar T = 2000.L; Scalar Tr = 1.; Scalar Rcal = 1.9858775; // Molar densities std::vector<Scalar> molar_densities(n_species,5e-4); ///Elementary, + Kooij - Arrhenius conversion tested std::vector<Scalar> k; Scalar A,beta,Ea,D; A = 7e18; beta = -1.6; k.push_back(HE(T,A,beta)); A = 2e18; D = -5e-3; k.push_back(Bert(T,A,D)); A = 5e12; Ea = 149943.0; k.push_back(Arrh(T,A,Ea,Rcal)); beta = 0.42; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal)); A = 5.7e9; beta = 0.42; k.push_back(BHE(T,A,beta,D)); A = 8.4e9; beta = 0.4; Ea = 38526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal)); k.push_back(Arrh(T,A,Ea,Rcal)); A = 3.7e11; beta = -0.42; Ea = 138812.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal)); A = 2.5e11; beta = 0.40; Ea = 174240.9; D = 0.05; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal)); ///Duplicate Scalar A2,beta2,Ea2,D2,A3,beta3,Ea3,D3,A4,Ea4; A = 7e18; beta = -1.6; A2 = 5e17; beta2 = 0.5; A3 = 3e18; beta3 = -0.6; k.push_back(HE(T,A,beta) + HE(T,A2,beta2) + HE(T,A3,beta3)); A = 2e18; D = -5e-2; A2 = 2e+16; D2 = 0.003; k.push_back(Bert(T,A,D) + Bert(T,A2,D2)); A = 5e+12; Ea = 149943.0; A2 = 3.5e+10; Ea2 = 1943.0; A3 = 1.5e+8; Ea3 = 149.0; A4 = 5.5e+8; Ea4 = 943.0; k.push_back(Arrh(T,A,Ea,Rcal) + Arrh(T,A2,Ea2,Rcal) + Arrh(T,A3,Ea3,Rcal) + Arrh(T,A4,Ea4,Rcal)); A = 5.7e+9; beta = 0.42; D = -5e-3; A2 = 7e+7; beta2 = 0.5; D2 = 2.5e-5; k.push_back(BHE(T,A,beta,D) + BHE(T,A2,beta2,D2)); A = 8.4e+09; beta = 0.40; Ea = 38526.0; A2 = 4e+07; beta2 = 0.50; Ea2 = 40500.0; A3 = 5e+10; beta3 = 0.10; Ea3 = 15000.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) + Kooij(T,A2,beta2,Ea2,Tr,Rcal) + Kooij(T,A3,beta3,Ea3,Tr,Rcal)); A = 3.7e+11; beta = -0.42; Ea = 138812.8; A2 = 5.0e+10; beta2 = 1.32; Ea2 = 150500.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) + Kooij(T,A2,beta2,Ea2,Tr,Rcal)); A = 2.5e+11; beta = 0.40; D = -5e-3; Ea = 174240.9; A2 = 5e+10; beta2 = 0.50; D2 = -1.5e-2; Ea2 = 4240.9; A3 = 3.2e+10; beta3 = 1.20; D3 = -2.5e-5; Ea3 = 174.9; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal) + VH(T,A2,beta2,Ea2,D2,Tr,Rcal) + VH(T,A3,beta3,Ea3,D3,Tr,Rcal)); //three body A = 7e18; beta = -1.6; Ea = 149943.0; k.push_back(HE(T,A,beta) * (Scalar(n_species) - 2. + 4.2857 + 4.2857) * 5e-4); A = 2e18; D = -5e-3; k.push_back(Bert(T,A,D) * (Scalar(n_species) - 2. + 5.0 + 5.0) * 5e-4); A = 5e12; k.push_back(Arrh(T,A,Ea,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); A = 5.7e9; beta = 0.42; D = -5e-3; k.push_back(BHE(T,A,beta,D) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); A = 8.4e9; beta = 0.4; Ea = 38526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) * (Scalar(n_species) - 3. + 22.0 + 22.0 + 22.0) * 5e-4); A = 3.7e11; beta = -0.42; Ea = 138812.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) * Scalar(n_species) * 5e-4); A = 2.5e11; beta = 0.40; Ea = 729372.4; D = 5e-3; k.push_back(VH(T,A,beta,Ea,D) * Scalar(n_species) * 5e-4); ///Lindemann Falloff // falloff is k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F // F = 1 A = 7e18; beta = -1.6; A2 = 5e15; beta2 = 0.5; k.push_back(HE(T,A,beta) / (1./4e-3 + HE(T,A,beta)/HE(T,A2,beta2)) ); A = 5e17; D = -2.5e-5; A2 = 2e18; D2 = -5e-3; k.push_back(Bert(T,A,D) / (1./4e-3 + Bert(T,A,D)/Bert(T,A2,D2)) ); A = 5.e+12; Ea = 149943.0; A2 = 3e+15; Ea2 = 200000.0; k.push_back(Arrh(T,A,Ea,Rcal) / (1./4e-3 + Arrh(T,A,Ea,Rcal)/Arrh(T,A2,Ea2,Rcal)) ); A = 5e+9; beta = 0.6; D = -5e-4; A2 = 5.7e+9; beta2 = -0.42; D2 = -5e-3; k.push_back(BHE(T,A,beta,D) / (1./4e-3 + BHE(T,A,beta,D)/BHE(T,A2,beta2,D2)) ); A = 8.4e+09; beta = 0.40; Ea = 38526.0; A2 = 8.4e+05; beta2 = 0.02; Ea2 = 3526.0; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) / (1./4e-3 + Kooij(T,A,beta,Ea,Tr,Rcal)/Kooij(T,A2,beta2,Ea2,Tr,Rcal)) ); A = 3.7e+11; beta = -0.42; Ea = 138812.8; A2 = 3.7e+12; beta2 = -0.52; Ea2 = 135000.8; k.push_back(Kooij(T,A,beta,Ea,Tr,Rcal) / (1./4e-3 + Kooij(T,A,beta,Ea,Tr,Rcal)/Kooij(T,A2,beta2,Ea2,Tr,Rcal)) ); A = 5e+10; beta = -0.10; D = 1.5e-3; Ea = 150240.9; A2 = 2.5e+11; beta2 = 0.40; D2 = -0.005; Ea2 = 174240.9; k.push_back(VH(T,A,beta,Ea,D,Tr,Rcal) / (1./4e-3 + VH(T,A,beta,Ea,D,Tr,Rcal)/VH(T,A2,beta2,Ea2,D2,Tr,Rcal)) ); //Troe falloff //falloff is k(T,[M]) = k0*[M]/(1 + [M]*k0/kinf) * F = k0 * ([M]^-1 + k0 * kinf^-1)^-1 * F // F is complicated... Scalar Pr,k0,kinf; Scalar Fc,alpha,T1,T2,T3; alpha = 0.562; T1 = 5836; T2 = 8552; T3 = 91; Fc = FcentTroe(T,alpha,T3,T1,T2); A = 7.e+18; beta = -1.6; A2 = 5.e+15; beta2 = 0.5; k0 = HE(T,A,beta); kinf = HE(T,A2,beta2); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 5e17; D = -2.5e-5; A2 = 2e18; D2 = -5e-3; k0 = Bert(T,A,D); kinf = Bert(T,A2,D2); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 5.e+12; Ea = 149943.0; A2 = 3e+15; Ea2 = 200000.0; k0 = Arrh(T,A,Ea,Rcal); kinf = Arrh(T,A2,Ea2,Rcal); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 5e+9; beta = 0.6; D = -5e-4; A2 = 5.7e+9; beta2 = -0.42; D2 = -5e-3; k0 = BHE(T,A,beta,D); kinf = BHE(T,A2,beta2,D2); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 8.4e+09; beta = 0.40; Ea = 38526.0; A2 = 8.4e+05; beta2 = 0.02; Ea2 = 3526.0; k0 = Kooij(T,A,beta,Ea,Tr,Rcal); kinf = Kooij(T,A2,beta2,Ea2,Tr,Rcal); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 3.7e+11; beta = -0.42; Ea = 138812.8; A2 = 3.7e+12; beta2 = -0.52; Ea2 = 135000.8; k0 = Kooij(T,A,beta,Ea,Tr,Rcal); kinf = Kooij(T,A2,beta2,Ea2,Tr,Rcal); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); A = 5e+10; beta = -0.10; D = 1.5e-3; Ea = 150240.9; A2 = 2.5e+11; beta2 = 0.40; D2 = -0.005; Ea2 = 174240.9; k0 = VH(T,A,beta,Ea,D,Tr,Rcal); kinf = VH(T,A2,beta2,Ea2,D2,Tr,Rcal); Pr = 4e-3 * k0/kinf; k.push_back(k0 / (1./4e-3 + k0/kinf) * FTroe(Fc,Pr)); const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100; int return_flag(0); for(unsigned int ir = 0; ir < k.size(); ir++) { const Antioch::Reaction<Scalar> * reac = &reaction_set.reaction(ir); if(std::abs(k[ir] - reac->compute_forward_rate_coefficient(molar_densities,T))/k[ir] > tol) { std::cout << std::scientific << std::setprecision(16) << "Error in kinetics comparison\n" << "reaction #: " << ir << "\n" << "theory: " << k[ir] << "\n" << "calculated: " << reac->compute_forward_rate_coefficient(molar_densities,T) << "\n" << "relative error = " << std::abs(k[ir] - reac->compute_forward_rate_coefficient(molar_densities,T))/k[ir] << "\n" << "tolerance = " << tol << std::endl; return_flag = 1; } } return return_flag; }
int Pseudoinverse( size_t m, size_t n, const doublecomplex *A, size_t lda, doublecomplex *P, size_t ldp ){ integer info; CMat Acopy(Eigen::Map<const CMat,Eigen::Unaligned,Eigen::OuterStride<> >(A, m, n, Eigen::OuterStride<>(lda))); Eigen::Map<CMat,Eigen::Unaligned,Eigen::OuterStride<> > mP(P, n, m, Eigen::OuterStride<>(ldp)); if(m >= n){ // tall case RVec S(n); CMat VH(n,n); doublecomplex dum; integer lwork = -1; RVec rwork(5*n); zgesvd_( "O","A", m,n, Acopy.data(), Acopy.outerStride(), S.data(), NULL, m, VH.data(), VH.outerStride(), &dum, lwork, rwork.data(), &info ); lwork = (integer)dum.real(); CVec work(lwork); zgesvd_( "O","A", m,n, Acopy.data(), Acopy.outerStride(), S.data(), NULL, m, VH.data(), VH.outerStride(), work.data(), lwork, rwork.data(), &info ); mP = Acopy.adjoint(); { double threshold = 2 * std::numeric_limits<double>::epsilon() * S[0]; for(size_t i = 0; i < n; ++i){ if(S[i] < threshold){ break; } S[i] = 1./S[i]; } } mP = VH.adjoint() * S.asDiagonal() * mP; }else{ // wide case RVec S(m); CMat U(m,m); doublecomplex dum; integer lwork = -1; RVec rwork(5*m); zgesvd_( "A","O", m,n, Acopy.data(), Acopy.outerStride(), S.data(), U.data(), U.outerStride(), NULL, m, &dum, lwork, rwork.data(), &info ); lwork = (integer)dum.real(); CVec work(lwork); zgesvd_( "A","O", m,n, Acopy.data(), Acopy.outerStride(), S.data(), U.data(), U.outerStride(), NULL, m, work.data(), lwork, rwork.data(), &info ); mP = Acopy.adjoint(); { double threshold = 2 * std::numeric_limits<double>::epsilon() * S[0]; for(size_t i = 0; i < m; ++i){ if(S[i] < threshold){ break; } S[i] = 1./S[i]; } } mP = mP * S.asDiagonal() * U.adjoint(); } return info; }