// Meshes are already committed int online_regrid(Mesh &srcmesh, Mesh &dstmesh, IWeights &wts, int *regridConserve, int *regridMethod, int *regridScheme, int *unmappedaction) { // Conflict management int regridPoleType = ESMC_REGRID_POLETYPE_ALL; int regridPoleNPnts = 0; // Conservative regridding switch (*regridConserve) { case (ESMC_REGRID_CONSERVE_ON): { // Get the integration weights MEField<> *src_iwts = srcmesh.GetField("iwts"); if (!src_iwts) Throw() << "Integration weights needed for conservative regridding." <<std::endl; MEField<> *dst_iwts = dstmesh.GetField("iwts"); if (!dst_iwts) Throw() << "Integration weights needed for conservative regridding." <<std::endl; if (!csrv(srcmesh, dstmesh, wts, src_iwts, dst_iwts, regridMethod, regridScheme, ®ridPoleType, ®ridPoleNPnts, unmappedaction)) Throw() << "Conservative regridding error" << std::endl; } break; // NON Conservative regridding case (ESMC_REGRID_CONSERVE_OFF): { if (!regrid(srcmesh, dstmesh, wts, regridMethod, regridScheme, ®ridPoleType, ®ridPoleNPnts, unmappedaction)) Throw() << "Regridding error" << std::endl; // Remove non-locally owned weights (assuming destination mesh decomposition) wts.Prune(dstmesh, 0); } break; default: Throw() << "Regridding method:" << *regridConserve << " is not implemented"; } return 1; }
void WriteConsoleLog() { nsresult rv; nsCOMPtr<nsILocalFile> lfile; char* logFileEnv = PR_GetEnv("XRE_CONSOLE_LOG"); if (logFileEnv && *logFileEnv) { rv = XRE_GetFileFromPath(logFileEnv, getter_AddRefs(lfile)); if (NS_FAILED(rv)) return; } else { if (!gLogConsoleErrors) return; rv = gDirServiceProvider->GetUserAppDataDirectory(getter_AddRefs(lfile)); if (NS_FAILED(rv)) return; lfile->AppendNative(NS_LITERAL_CSTRING("console.log")); } PRFileDesc *file; rv = lfile->OpenNSPRFileDesc(PR_WRONLY | PR_APPEND | PR_CREATE_FILE, 0660, &file); if (NS_FAILED(rv)) return; nsCOMPtr<nsIConsoleService> csrv (do_GetService(NS_CONSOLESERVICE_CONTRACTID)); if (!csrv) { PR_Close(file); return; } nsIConsoleMessage** messages; PRUint32 mcount; rv = csrv->GetMessageArray(&messages, &mcount); if (NS_FAILED(rv)) { PR_Close(file); return; } if (mcount) { PRExplodedTime etime; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &etime); char datetime[512]; PR_FormatTimeUSEnglish(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", &etime); PR_fprintf(file, NS_LINEBREAK "*** Console log: %s ***" NS_LINEBREAK, datetime); } // From this point on, we have to release all the messages, and free // the memory allocated for the messages array. XPCOM arrays suck. nsXPIDLString msg; nsCAutoString nativemsg; for (PRUint32 i = 0; i < mcount; ++i) { rv = messages[i]->GetMessage(getter_Copies(msg)); if (NS_SUCCEEDED(rv)) { NS_CopyUnicodeToNative(msg, nativemsg); PR_fprintf(file, "%s" NS_LINEBREAK, nativemsg.get()); } NS_IF_RELEASE(messages[i]); } PR_Close(file); NS_Free(messages); }
// Mesh are not committed yet int offline_regrid(Mesh &srcmesh, Mesh &dstmesh, Mesh &dstmeshcpy, int *regridConserve, int *regridMethod, int *regridPoleType, int *regridPoleNPnts, char *srcGridFile, char *dstGridFile, char *wghtFile) { // Conflict management int regridScheme = ESMC_REGRID_SCHEME_FULL3D; int unmappedaction = ESMC_UNMAPPEDACTION_ERROR; IWeights wts; MEField<> *src_iwts, *dst_iwts, *dst_iwtscpy; switch (*regridConserve) { // Conservative regridding case (ESMC_REGRID_CONSERVE_ON): { // Add fields to mesh Context ctxt; ctxt.flip(); src_iwts = srcmesh.RegisterField("iwts", MEFamilyStd::instance(), MeshObj::ELEMENT, ctxt, 1, true); dst_iwts = dstmesh.RegisterField("iwts", MEFamilyStd::instance(), MeshObj::ELEMENT, ctxt, 1, true); // generate integration weights on the copy // TODO: remove this (and the dstcpy mesh passed in) when the // write bug with pole assimilation is fixed. dst_iwtscpy = dstmeshcpy.RegisterField("iwts", MEFamilyStd::instance(), MeshObj::ELEMENT, ctxt, 1, true); dstmeshcpy.Commit(); Integrate dig(dstmeshcpy); dig.clearWeights(dst_iwtscpy); if (regridScheme == ESMC_REGRID_SCHEME_FULL3D) { for (UInt i = 1; i <= 7; ++i) dig.AddPoleWeights(dstmeshcpy,i,dst_iwtscpy); } dig.intWeights(dst_iwtscpy); // Commit the meshes srcmesh.Commit(); dstmesh.Commit(); if (!csrv(srcmesh, dstmesh, wts, src_iwts, dst_iwts, regridMethod, ®ridScheme, regridPoleType, regridPoleNPnts, &unmappedaction)) Throw() << "Conservative regridding error" << std::endl; } break; // NON Conservative regridding case (ESMC_REGRID_CONSERVE_OFF): { // Commit the meshes srcmesh.Commit(); dstmesh.Commit(); dstmeshcpy.Commit(); if (!regrid(srcmesh, dstmesh, wts, regridMethod, ®ridScheme, regridPoleType, regridPoleNPnts, &unmappedaction)) Throw() << "Regridding error" << std::endl; // the mask MEField<> *mask = dstmesh.GetField("MASK_IO"); ThrowRequire(mask); wts.Prune(dstmesh, mask); } break; default: Throw() << "Regridding method:" << *regridConserve << " is not implemented"; } // Redistribute weights in an IO friendly decomposition if (Par::Rank() == 0) std::cout << "Writing weights to " << wghtFile << std::endl; GatherForWrite(wts); // Write the weights WriteNCMatFilePar(srcGridFile, dstGridFile, wghtFile, wts, srcmesh, dstmesh, dstmeshcpy, regridConserve, regridMethod, NCMATPAR_ORDER_SEQ); return 1; }