void CanteraGas::initialize() { // suppress thermo warnings to simplify output. Without this warnings printed for every thread created Cantera::suppress_thermo_warnings(); // XML Information File rootXmlNode = Cantera::get_XML_File(mechanismFile); if (rootXmlNode == NULL) { throw DebugException((format( "Error parsing Cantera XML file '%s'.") % mechanismFile).str()); } phaseXmlNode = rootXmlNode->findNameID("phase", phaseID); if (phaseXmlNode == NULL) { throw DebugException((format( "Error finding phase '%s' in '%s'.") % phaseID % mechanismFile).str()); } // Initialize the default thermodynamic properties object Cantera::importPhase(*phaseXmlNode, &thermo); // Initialize the default chemical kinetics object if (kineticsModel == "standard") { kinetics = new Cantera::GasKinetics(&thermo); } else if (kineticsModel == "interp") { kinetics = new InterpKinetics(&thermo); } else { throw DebugException("Unknown kinetics model specified."); } kinetics->init(); Cantera::installReactionArrays(*phaseXmlNode, *kinetics, phaseID); // Initialize the default transport properties object if (transportModel == "Multi") { transport = new Cantera::MultiTransport(); } else if (transportModel == "Mix") { transport = new Cantera::MixTransport(); } else if (transportModel == "Approx") { ApproxMixTransport* atran = new ApproxMixTransport(); atran->setThreshold(transportThreshold); transport = atran; } else { throw DebugException("Error: Invalid transport model specified."); } transport->init(&thermo); nSpec = thermo.nSpecies(); Dbin.setZero(nSpec,nSpec); isInitialized = true; }
int SundialsIda::getRootInfo() { int flag = IDAGetRootInfo(sundialsMem, &rootsFound[0]); if (check_flag(&flag, "IDAGetRootInfo", 1)) throw DebugException("SundialsIda::getRootInfo: error in IDAGetRootInfo."); return flag; }
int SundialsCvode::getRootInfo() { int flag = CVodeGetRootInfo(sundialsMem, &rootsFound[0]); if (check_flag(&flag, "CVodeGetRootInfo", 1)) { throw DebugException("SundialsCvode::getRootInfo: error in CVodeGetRootInfo"); } return flag; }
sdVector::sdVector(unsigned int N) { alloc = true; v = N_VNew_Serial(N); n = N; if (SundialsCvode::check_flag((void *)v, "N_VNew_Serial", 0)) { throw DebugException("sdVector: error allocating vector"); } }
int SundialsCvode::integrateToTime(realtype t) { assert(mathUtils::notnan(y)); int flag = CVode(sundialsMem, t, y.forSundials(), &tInt, CV_NORMAL); if (flag != CV_SUCCESS) { errorCount += 1; if (errorCount > errorStopCount) { throw DebugException("CVODE Integrator had too many errors"); } } return flag; }
int SundialsCvode::integrateOneStep(realtype tf) { assert(mathUtils::notnan(y)); CVodeSetStopTime(sundialsMem, tf); int flag = CVode(sundialsMem, tf, y.forSundials(), &tInt, CV_ONE_STEP); if (flag != CV_SUCCESS && flag != CV_TSTOP_RETURN) { errorCount += 1; if (errorCount > errorStopCount) { throw DebugException("CVODE Integrator had too many errors"); } } return flag; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); if (!mutex) { DebugLastError("CreateMutex failed"); return 1; } if (GetLastError() == ERROR_ALREADY_EXISTS) { DebugLastError("Named pipe exists, another engine instance appears to be running"); return 1; } int argc; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); std::wstring locale(argc >= 2 ? argv[1] : L""); Communication::browserSID = argc >= 3 ? argv[2] : L""; LocalFree(argv); Dictionary::Create(locale); filterEngine = CreateFilterEngine(locale); updater.reset(new Updater(filterEngine->GetJsEngine())); for (;;) { try { Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeName, Communication::Pipe::MODE_CREATE); AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pipe), 0, 0)); if (!thread) { delete pipe; DebugLastError("CreateThread failed"); return 1; } } catch (std::runtime_error e) { DebugException(e); return 1; } } return 0; }
void Updater::Download() { AdblockPlus::ServerResponse response = jsEngine->GetWebRequest()->GET(url, AdblockPlus::HeaderList()); if (response.status != AdblockPlus::WebRequest::NS_OK || response.responseStatus != 200) { std::stringstream ss; ss << "Update download failed (status: " << response.status << ", "; ss << "response: " << response.responseStatus << ")"; Debug(ss.str()); return; } AdblockPlus::FileSystemPtr fileSystem = jsEngine->GetFileSystem(); std::string utfTempFile = ToUtf8String(tempFile); try { // Remove left-overs from previous update attempts fileSystem->Remove(utfTempFile); } catch (const std::exception&) { } try { std::tr1::shared_ptr<std::istream> fileData(new std::istringstream(response.responseText)); fileSystem->Write(utfTempFile, fileData); } catch (const std::exception& e) { DebugException(e); return; } OnDownloadSuccess(); }
Void Init() { #if defined(NULL_IAT) if (!InitFunction(&g_func)) DebugException(); #endif CMem::CreateGlobalHeap(); // AddVectoredExceptionHandler(True, VectoredHandler); INTEL_STATIC SPatch p[] = { { 0xB8, 1, 0x3B98C }, // 验证 // { 0x24EB, 2, 0x4B14F }, // 边界 // { 0xD5EB, 2, 0x4B17E }, // 边界 { 0xEB, 1, 0x4B14F }, // 边界 { 0xEB, 1, 0x4B17E }, // 边界 { 0xEB, 1, 0x483D1 }, // 边界 { 0xEB, 1, 0x4AADA }, // 边界 { 0xEB, 1, 0x4AB12 }, // 边界 { SWAP2('【'), 4, 0x49C7B }, { SWAP2('【'), 4, 0x49CA0 }, { SWAP2('】'), 4, 0x49EF6 }, { SWAP2('】'), 4, 0x49F1B }, #if defined (MY_DEBUG) { (UInt32)MyCreateFontIndirectA, 4, 0x5B044 }, { (UInt32)MyGetGlyphOutlineA, 4, 0x5B04C }, #endif }; INTEL_STATIC SFuncPatch f[] = { { CALL, 0x2F2E1, DecodeImage, 0x00 }, { CALL, 0x23EAA, MylstrcmpiA, 0x01 }, // { CALL, 0x2F065, MylstrcmpA, 0x01 }, { CALL, 0x43904, GetSeSize, 0x00 }, { CALL, 0x4392D, ReadSe, 0x00 }, }; WChar szPath[MAX_PATH]; DWORD i; #if defined (MY_DEBUG) PatchMemory(p, countof(p), f, countof(f), MYAPI(GetModuleHandleW)(0)); #else PatchMemoryNoVP(p, countof(p), f, countof(f), MYAPI(GetModuleHandleW)(0)); #endif #if defined(NULL_IAT) HMODULE hVorbisfile = g_func.LoadStayedLibraryA("vorbisfile.dll", &g_func); #else HMODULE hVorbisfile = LoadLibraryExW(L"vorbisfile.dll", NULL, 0); #endif GetFuncAddress(vorbis_func.ov_clear, hVorbisfile, "ov_clear"); GetFuncAddress(vorbis_func.ov_open_callbacks, hVorbisfile, "ov_open_callbacks"); GetFuncAddress(vorbis_func.ov_test_callbacks, hVorbisfile, "ov_test_callbacks"); GetFuncAddress(vorbis_func.ov_pcm_seek, hVorbisfile, "ov_pcm_seek"); GetFuncAddress(vorbis_func.ov_pcm_total, hVorbisfile, "ov_pcm_total"); GetFuncAddress(vorbis_func.ov_read, hVorbisfile, "ov_read"); GetFuncAddress(vorbis_func.ov_time_total, hVorbisfile, "ov_time_total"); i = MYAPI(GetModuleFileNameW)(NULL, szPath, countof(szPath)); while (szPath[--i] != '\\'); ++i; *(PULONG64)&szPath[i] = TAG4W('save'); szPath[i + 4] = 0; MYAPI(CreateDirectoryW)(szPath, NULL); #if defined(USE_CACHE) g_ImageCache.Init(); #endif }
void SundialsIda::initialize() { sundialsMem = IDACreate(); if (check_flag((void *)sundialsMem, "IDACreate", 0)) { throw DebugException("SundialsIda::initialize: error in IDACreate"); } IDASetUserData(sundialsMem, theDAE); int flag; if (calcIC) { // Pick an appropriate initial condition for ydot and algebraic components of y flag = IDASetId(sundialsMem, componentId.forSundials()); } flag = IDAInit(sundialsMem, f, t0, y.forSundials(), ydot.forSundials()); if (check_flag(&flag, "IDAMalloc", 1)) { throw DebugException("SundialsIda::initialize: error in IDAInit"); } IDASVtolerances(sundialsMem, reltol, abstol.forSundials()); if (findRoots) { rootsFound.resize(nRoots); // Call IDARootInit to specify the root function g with nRoots components flag = IDARootInit(sundialsMem, nRoots, g); if (check_flag(&flag, "IDARootInit", 1)) { throw DebugException("SundialsIda::initialize: error in IDARootInit"); } } // Call IDASpbcg to specify the IDASpbcg dense linear solver flag = IDASpbcg(sundialsMem, 0); if (check_flag(&flag, "IDASpbcg", 1)) { throw DebugException("SundialsIda::initialize: error in IDASpbcg"); } if (imposeConstraints) { flag = IDASetConstraints(sundialsMem, constraints.forSundials()); if (check_flag(&flag, "IDASetConstraints", 1)) { throw DebugException("SundialsIda::initialize: error in IDASetConstraints"); } } // this seems to work better using the default J-v function rather than specifying our own... //flag = IDASpilsSetJacTimesVecFn(sundialsMem, JvProd, theDAE); //if (check_flag(&flag, "IDASpilsSetJacTimesVecFn", 1)) { // throw myException("SundialsIda::initialize: error in IDASpilsSetJacTimesVecFn"); //} flag = IDASpilsSetPreconditioner(sundialsMem, preconditionerSetup, preconditionerSolve); if (check_flag(&flag, "IDASpilsSetPreconditioner", 1)) { throw DebugException("SundialsIda::initialize: error in IDASpilsSetPreconditioner"); } if (calcIC) { flag = IDACalcIC(sundialsMem, IDA_YA_YDP_INIT, t0+1e-4); if (check_flag(&flag, "IDACalcIC", 1)) { logFile.write("IDACalcIC Error"); throw DebugException("SundialsIda::initialize: error in IDACalcIC"); } flag = IDAGetConsistentIC(sundialsMem, y0.forSundials(), ydot0.forSundials()); if (check_flag(&flag, "IDAGetConsistentIC", 1)) { throw DebugException("SundialsIda::initialize: error in IDAGetConsistentIC"); } } }
void SundialsCvode::initialize() { int flag = 0; if (_initialized) { // Starting over with a new IC, but the same ODE flag = CVodeReInit(sundialsMem, t0, y.forSundials()); if (check_flag(&flag, "CVodeReInit", 1)) { throw DebugException("SundialsCvode::reInitialize: error in CVodeReInit"); } CVodeSetMaxNumSteps(sundialsMem, maxNumSteps); CVodeSetMinStep(sundialsMem, minStep); return; } // On the first call to initialize, need to allocate and set up // the Sundials solver, set tolerances and link the ODE functions sundialsMem = CVodeCreate(linearMultistepMethod, nonlinearSolverMethod); if (check_flag((void *)sundialsMem, "CVodeCreate", 0)) { throw DebugException("SundialsCvode::initialize: error in CVodeCreate"); } flag = CVodeInit(sundialsMem, f, t0, y.forSundials()); if (check_flag(&flag, "CVodeMalloc", 1)) { throw DebugException("SundialsCvode::initialize: error in CVodeMalloc"); } CVodeSVtolerances(sundialsMem, reltol, abstol.forSundials()); CVodeSetUserData(sundialsMem, theODE); CVodeSetMaxNumSteps(sundialsMem, maxNumSteps); CVodeSetMinStep(sundialsMem, minStep); if (findRoots) { rootsFound.resize(nRoots); // Call CVodeRootInit to specify the root function g with nRoots components flag = CVodeRootInit(sundialsMem, nRoots, g); if (check_flag(&flag, "CVodeRootInit", 1)) { throw DebugException("SundialsCvode::initialize: error in CVodeRootInit"); } } if (bandwidth_upper == -1 && bandwidth_lower == -1) { // Call CVDense to specify the CVDENSE dense linear solver flag = CVDense(sundialsMem, nEq); if (check_flag(&flag, "CVDense", 1)) { throw DebugException("SundialsCvode::initialize: error in CVDense"); } // Set the Jacobian routine to denseJac (user-supplied) flag = CVDlsSetDenseJacFn(sundialsMem, denseJac); if (check_flag(&flag, "CVDlsSetDenseJacFn", 1)) { throw DebugException("SundialsCvode::initialize: error in CVDlsSetDenseJacFn"); } } else { // Call CVDense to specify the CVBAND Banded linear solver flag = CVBand(sundialsMem, nEq, bandwidth_upper, bandwidth_lower); if (check_flag(&flag, "CVBand", 1)) { throw DebugException("SundialsCvode::initialize: error in CVBand"); } // Set the Jacobian routine to bandJac (user-supplied) flag = CVDlsSetBandJacFn(sundialsMem, bandJac); if (check_flag(&flag, "CVDlsSetBandJacFn", 1)) { throw DebugException("SundialsCvode::initialize: error in CVDlsSetBandJacFn"); } } _initialized = true; }