// Save report of document comparison // -- input is index of documents to compare // -- uses file dialog to locate filename and type of output // -- saves comparison in either .pdf or .xml format void DocumentListCtrl::SaveReportFor (int document1, int document2, bool unique, bool ignore) { wxFileName filename1 (GetPathname (document1)); wxFileName filename2 (GetPathname (document2)); wxString newname = wxString::Format ("%s-%s", filename1.GetName().c_str(), filename2.GetName().c_str()); wxFileDialog dialog (NULL, "Create and save report", wxEmptyString, newname, "pdf|*.pdf|xml|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR); if (dialog.ShowModal () == wxID_OK) { wxBusyCursor wait; wxBusyInfo info ("Saving comparison report, please wait ...", this); wxFileName path (dialog.GetPath ()); if (dialog.GetFilterIndex () == 0 || (path.GetExt () == "pdf")) { path.SetExt ("pdf"); // force .pdf as extension PdfReport pdfreport (_ferretparent->GetDocumentList (), unique, ignore); pdfreport.WritePdfReport (path.GetFullPath (), document1, document2); } else // if (dialog.GetFilterIndex () == 1 || (path.GetExt () == "xml")) { path.SetExt ("xml"); // force .xml as extension XmlReport xmlreport (_ferretparent->GetDocumentList (), unique, ignore); xmlreport.WriteXmlReport (path.GetFullPath (), document1, document2); } } }
void checkSphWallLubricationForce() { const uint_t timestep (timeloop_->getCurrentTimeStep()+1); // variables for output of total force - requires MPI-reduction pe::Vec3 forceSphr1(0); // temporary variables real_t gap (0); for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt ) { pe::SphereID sphereI = ( curSphereIt.getBodyID() ); if ( sphereI->getID() == id1_ ) { for( auto globalBodyIt = globalBodyStorage_->begin(); globalBodyIt != globalBodyStorage_->end(); ++globalBodyIt) { if( globalBodyIt->getID() == id2_ ) { pe::PlaneID planeJ = static_cast<pe::PlaneID>( globalBodyIt.getBodyID() ); gap = pe::getSurfaceDistance(sphereI, planeJ); break; } } break; } } } WALBERLA_MPI_SECTION() { mpi::reduceInplace( gap, mpi::MAX ); } WALBERLA_ROOT_SECTION() { if (gap < real_comparison::Epsilon<real_t>::value ) { gap = walberla::math::Limits<real_t>::inf(); WALBERLA_LOG_INFO_ON_ROOT( "Sphere still too far from wall to calculate gap!" ); } else { WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere and wall: " << gap ); } } // get force on sphere for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt ) { if( bodyIt->getID() == id1_ ) { forceSphr1 += bodyIt->getForce(); } } } // MPI reduction of pe forces over all processes WALBERLA_MPI_SECTION() { mpi::reduceInplace( forceSphr1[0], mpi::SUM ); mpi::reduceInplace( forceSphr1[1], mpi::SUM ); mpi::reduceInplace( forceSphr1[2], mpi::SUM ); } WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1); if ( print_ ) { WALBERLA_ROOT_SECTION() { std::ofstream file1; std::string filename1("Gap_LubricationForceBody1.txt"); file1.open( filename1.c_str(), std::ofstream::app ); file1.setf( std::ios::unitbuf ); file1.precision(15); file1 << gap << " " << forceSphr1[0] << std::endl; file1.close(); } } WALBERLA_ROOT_SECTION() { if ( timestep == uint_t(26399) ) { // according to the formula from Ding & Aidun 2003 // F = 6 * M_PI * rho_L * nu_L * relative velocity of both bodies=relative velocity of the sphere * r * r * 1/gap // the correct analytically calculated value is 339.292006996217 // in this geometry setup the relative error is 0.183515322065561 % real_t analytical = real_c(6.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(-vel_[0]) * radius_ * radius_ * real_c(1.0)/gap; real_t relErr = std::fabs( analytical - forceSphr1[0] ) / analytical * real_c(100.0); WALBERLA_CHECK_LESS( relErr, real_t(1) ); } } }
void checkSphSphLubricationForce() { const uint_t timestep (timeloop_->getCurrentTimeStep()+1); // variables for output of total force - requires MPI-reduction pe::Vec3 forceSphr1(0); pe::Vec3 forceSphr2(0); // temporary variables real_t gap (0); // calculate gap between the two spheres for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt ) { pe::SphereID sphereI = ( curSphereIt.getBodyID() ); if ( sphereI->getID() == id1_ ) { for( auto blockIt2 = blocks_->begin(); blockIt2 != blocks_->end(); ++blockIt2 ) { for( auto oSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt2, bodyStorageID_); oSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++oSphereIt ) { pe::SphereID sphereJ = ( oSphereIt.getBodyID() ); if ( sphereJ->getID() == id2_ ) { gap = pe::getSurfaceDistance( sphereI, sphereJ ); break; } } } break; } } } WALBERLA_MPI_SECTION() { mpi::reduceInplace( gap, mpi::MAX ); } WALBERLA_ROOT_SECTION() { if (gap < real_comparison::Epsilon<real_t>::value ) { // shadow copies have not been synced yet as the spheres are outside the overlap region gap = walberla::math::Limits<real_t>::inf(); WALBERLA_LOG_INFO_ON_ROOT( "Spheres still too far apart to calculate gap!" ); } else { WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere 1 and 2: " << gap ); } } // get force on spheres for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt ) { if( bodyIt->getID() == id1_ ) { forceSphr1 += bodyIt->getForce(); } else if( bodyIt->getID() == id2_ ) { forceSphr2 += bodyIt->getForce(); } } } // MPI reduction of pe forces over all processes WALBERLA_MPI_SECTION() { mpi::reduceInplace( forceSphr1[0], mpi::SUM ); mpi::reduceInplace( forceSphr1[1], mpi::SUM ); mpi::reduceInplace( forceSphr1[2], mpi::SUM ); mpi::reduceInplace( forceSphr2[0], mpi::SUM ); mpi::reduceInplace( forceSphr2[1], mpi::SUM ); mpi::reduceInplace( forceSphr2[2], mpi::SUM ); } WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1); WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id2_ << " : " << forceSphr2); if ( print_ ) { WALBERLA_ROOT_SECTION() { std::ofstream file1; std::string filename1("Gap_LubricationForceBody1.txt"); file1.open( filename1.c_str(), std::ofstream::app ); file1.setf( std::ios::unitbuf ); file1.precision(15); file1 << gap << " " << forceSphr1[0] << std::endl; file1.close(); std::ofstream file2; std::string filename2("Gap_LubricationForceBody2.txt"); file2.open( filename2.c_str(), std::ofstream::app ); file2.setf( std::ios::unitbuf ); file2.precision(15); file2 << gap << " " << forceSphr2[0] << std::endl; file2.close(); } } WALBERLA_ROOT_SECTION() { if ( timestep == uint_t(1000) ) { // both force x-components should be the same only with inverted signs WALBERLA_CHECK_FLOAT_EQUAL ( forceSphr2[0], -forceSphr1[0] ); // according to the formula from Ding & Aidun 2003 // F = 3/2 * M_PI * rho_L * nu_L * relative velocity of both spheres * r * r * 1/gap // the correct analytically calculated value is 339.2920063998 // in this geometry setup the relative error is 0.1246489711 % real_t analytical = real_c(3.0)/real_c(2.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(2.0) * real_c(vel_[0]) * radius_ * radius_ * real_c(1.0)/gap; real_t relErr = std::fabs( analytical - forceSphr2[0] ) / analytical * real_c(100.0); WALBERLA_CHECK_LESS( relErr, real_t(1) ); } } }
void recurse_directory(const fs::path& p) { try { boost::regex expr(include); std::string extension(fs::extension(p)); if( extension == ".h" || extension == ".c" || extension == ".hpp" || extension == ".cpp" ) { fs::ifstream file(p); std::string line; while(file) { std::getline(file, line); std::string::const_iterator begin(line.begin()); std::string::const_iterator end(line.end()); boost::match_flag_type flags(boost::match_default); boost::match_results<std::string::const_iterator> what; while(boost::regex_search(begin, end , what, expr, flags)) { std::string filename1(p.string()); std::string filename2(what[1].first, what[1].second); filename2 = fs::path(filename2).string(); std::cout << '"' << filename1 << "\" -> \"" << filename2 << "\";" << std::endl; begin = what[0].second; flags |= boost::match_prev_avail; flags |= boost::match_not_bob; } } } else { if(fs::is_directory(p)) { std::string cluster; try { cluster = fs::basename(fs::absolute(p).filename()); } catch(std::exception& e) { std::clog << "exception in: " << __FILE__ << " at: " << __LINE__ << ": " << e.what() << std::endl; } std::cout << "subgraph \"cluster_" << cluster << "\"{\nlabel = \"" << cluster << "\";" << std::endl; fs::directory_iterator end; for(fs::directory_iterator it(p); it != end; ++it) { std::string extension(fs::extension(*it)); if( extension == ".h" || extension == ".c" || extension == ".hpp" || extension == ".cpp" ) { std::cout << '"' << it->path().filename() << "\";" << std::endl; } } std::cout << '}' << std::endl; for(fs::directory_iterator it(p); it != end; ++it) { recurse_directory(*it); } } } } catch(std::exception& e) { std::clog << "exception in: " << __FILE__ << " at: " << __LINE__ << ": " << e.what() << std::endl; } }
MathCell* MathParser::ParseTag(wxXmlNode* node, bool all) { // wxYield(); MathCell* tmp = NULL; MathCell* cell = NULL; bool warning = all; wxString altCopy; while (node) { // Parse tags if (node->GetType() == wxXML_ELEMENT_NODE) { wxString tagName(node->GetName()); if (tagName == wxT("v")) { // Variables (atoms) if (cell == NULL) cell = ParseText(node->GetChildren(), TS_VARIABLE); else cell->AppendCell(ParseText(node->GetChildren(), TS_VARIABLE)); } else if (tagName == wxT("t")) { // Other text if (cell == NULL) cell = ParseText(node->GetChildren(), TS_DEFAULT); else cell->AppendCell(ParseText(node->GetChildren(), TS_DEFAULT)); } else if (tagName == wxT("n")) { // Numbers if (cell == NULL) cell = ParseText(node->GetChildren(), TS_NUMBER); else cell->AppendCell(ParseText(node->GetChildren(), TS_NUMBER)); } else if (tagName == wxT("h")) { // Hidden cells (*) MathCell* tmp = ParseText(node->GetChildren()); tmp->m_isHidden = true; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("p")) { // Parenthesis if (cell == NULL) cell = ParseParenTag(node); else cell->AppendCell(ParseParenTag(node)); } else if (tagName == wxT("f")) { // Fractions if (cell == NULL) cell = ParseFracTag(node); else cell->AppendCell(ParseFracTag(node)); } else if (tagName == wxT("e")) { // Exponentials if (cell == NULL) cell = ParseSupTag(node); else cell->AppendCell(ParseSupTag(node)); } else if (tagName == wxT("i")) { // Subscripts if (cell == NULL) cell = ParseSubTag(node); else cell->AppendCell(ParseSubTag(node)); } else if (tagName == wxT("fn")) { // Functions if (cell == NULL) cell = ParseFunTag(node); else cell->AppendCell(ParseFunTag(node)); } else if (tagName == wxT("g")) { // Greek constants MathCell* tmp = ParseText(node->GetChildren(), TS_GREEK_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("s")) { // Special constants %e,... MathCell* tmp = ParseText(node->GetChildren(), TS_SPECIAL_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("fnm")) { // Function names MathCell* tmp = ParseText(node->GetChildren(), TS_FUNCTION); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("q")) { // Square roots if (cell == NULL) cell = ParseSqrtTag(node); else cell->AppendCell(ParseSqrtTag(node)); } else if (tagName == wxT("d")) { // Differentials if (cell == NULL) cell = ParseDiffTag(node); else cell->AppendCell(ParseDiffTag(node)); } else if (tagName == wxT("sm")) { // Sums if (cell == NULL) cell = ParseSumTag(node); else cell->AppendCell(ParseSumTag(node)); } else if (tagName == wxT("in")) { // integrals if (cell == NULL) cell = ParseIntTag(node); else cell->AppendCell(ParseIntTag(node)); } else if (tagName == wxT("mspace")) { if (cell == NULL) cell = new TextCell(wxT(" ")); else cell->AppendCell(new TextCell(wxT(" "))); } else if (tagName == wxT("at")) { if (cell == NULL) cell = ParseAtTag(node); else cell->AppendCell(ParseAtTag(node)); } else if (tagName == wxT("a")) { if (cell == NULL) cell = ParseAbsTag(node); else cell->AppendCell(ParseAbsTag(node)); } else if (tagName == wxT("ie")) { if (cell == NULL) cell = ParseSubSupTag(node); else cell->AppendCell(ParseSubSupTag(node)); } else if (tagName == wxT("lm")) { if (cell == NULL) cell = ParseLimitTag(node); else cell->AppendCell(ParseLimitTag(node)); } else if (tagName == wxT("r")) { if (cell == NULL) cell = ParseTag(node->GetChildren()); else cell->AppendCell(ParseTag(node->GetChildren())); } else if (tagName == wxT("tb")) { if (cell == NULL) cell = ParseTableTag(node); else cell->AppendCell(ParseTableTag(node)); } else if ((tagName == wxT("mth")) || (tagName == wxT("line"))) { MathCell *tmp = ParseTag(node->GetChildren()); if (tmp != NULL) tmp->ForceBreakLine(true); else tmp = new TextCell(wxT(" ")); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("lbl")) { MathCell* tmp = ParseText(node->GetChildren(), TS_LABEL); tmp->ForceBreakLine(true); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("st")) { MathCell* tmp = ParseText(node->GetChildren(), TS_STRING); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("hl")) { bool highlight = m_highlight; m_highlight = true; MathCell* tmp = ParseTag(node->GetChildren()); m_highlight = highlight; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("img")) { wxString filename(node->GetChildren()->GetContent()); #if !wxUSE_UNICODE wxString filename1(filename.wc_str(wxConvUTF8), *wxConvCurrent); filename = filename1; #endif ImgCell *tmp; if (m_fileSystem) // loading from zip tmp = new ImgCell(filename, false, m_fileSystem); #if wxCHECK_VERSION(2,9,0) else if (node->GetAttribute(wxT("del"), wxT("yes")) != wxT("no")) #else else if (node->GetPropVal(wxT("del"), wxT("yes")) != wxT("no")) #endif tmp = new ImgCell(filename, true, NULL); else tmp = new ImgCell(filename, false, NULL); #if wxCHECK_VERSION(2,9,0) if (node->GetAttribute(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #else if (node->GetPropVal(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #endif if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("slide"))
//LEGO‚RGB‚Lab void LegoRGB_to_Lab(Model& m) { string line; istringstream ssline; CColor temp; string temps; vector<string> iro; vector<CColor> tempLegoColor; int BackColorNum(0); int i(0); //LEGO string filename("lego_color_rgb.txt"); //string filename("lego_color_rgb_tree.txt"); //string filename("lego_color_rgb_palette.txt"); ifstream fin(directory[0] + filename); if (!fin){ cout << filename << " lego_color_rgb.txt was not found!!! " << endl; exit(-1); } //########################### //########################### while (!fin.eof()){ getline(fin, line); if (line.size() == 0 || line[0] == '\n') continue; //Block_colorNum++; ssline.str(line); ssline >> temp.r >> temp.g >> temp.b >> temps; temp.r = temp.r / 255.0; temp.g = temp.g / 255.0; temp.b = temp.b / 255.0; iro.push_back(temps); tempLegoColor.push_back(temp); ssline.clear(); //ssline } //########################### // //########################### for (i = 0; i < iro.size(); i++) cout << i << ":" << iro[i] << endl; for (;;){ cout << " " << endl; cout << "0-" << iro.size() - 1 << ":choose one of that color, Other: not " << endl; //cin >> BackColorNum; BackColorNum = 2; if (-1 < BackColorNum && BackColorNum < iro.size()) { cout << iro[BackColorNum] << " was chosen." << endl; m.BackColor = tempLegoColor[BackColorNum]; cout << "RGB to Hue: " << RGBtoHue(m.BackColor.r, m.BackColor.g, m.BackColor.b) << endl; for (i = 0; i < iro.size(); i++){ if (i == BackColorNum) continue; m.LegoColor.push_back(tempLegoColor[i]); } break; } else break; } for (i = 0; i < iro.size(); i++) { cout << "iro[" << i << "] m.LegoColor[" << i << "] r." << m.LegoColor[i].r<<" g." << m.LegoColor[i].g<<" b." << m.LegoColor[i].b << endl; } //################################# // //################################# string filename1("BrickTable.txt"); ifstream fin1(directory[0] + filename1); if (!fin1){ cout << filename1 << " could not find!!" << endl; exit(-1); } unsigned designID; getline(fin1, line); //1s–ÚiDesign IDj ssline.str(line); for (i = 0; i < 7; i++){ ssline >> designID; table.DesignID.push_back(designID); } ssline.clear(); //ssline‚Ì‘S—v‘f‚ðíœ table.itemNos.resize(7); unsigned colorID; unsigned itemnos; int k(0); while (!fin1.eof()){ getline(fin1, line); if (line.size() == 0 || line[0] == '\n') continue; if (k != BackColorNum){ ssline.str(line); ssline >> colorID; table.ColorID.push_back(colorID); //cout << "colorID " << colorID << "-k" << k << " -table.ColorID " << table.ColorID[k] << endl; for (i = 0; i < 7; i++){ ssline >> itemnos; table.itemNos[i].push_back(itemnos); // cout << "itemnos " << itemnos << " table.itemNos[" << i << "]\n"; } } k++; ssline.clear(); //ssline‚Ì‘S—v‘f‚ðíœ }
int test_main(int, char*[]) { #if !defined __BORLANDC__ fs::path const tmpdir(fs::complete("/tmp")); fs::create_directory(tmpdir); #endif // !defined __BORLANDC__ std::string filename0("/tmp/eraseme"); { std::ofstream os(filename0.c_str(), ios_out_trunc_binary()); BOOST_TEST(os.good()); os << "a=a\n" << "No equal sign--line should be ignored.\n" << "\n" << "b=b\n" << "c=\n" << "d==\n" << "e=1=.\n" << "f= f \r\n" << "this=a test\n" << "z=2\n" << "y=-3.142\n" << "x=2.718 \n" << "w= 2.718\n" << "v= 2.718 \n" << "u=\n" << "t= \n" << "s= \n" ; } name_value_pairs n_v_pairs_0(filename0); std::map<std::string, std::string> m0 = n_v_pairs_0.map(); BOOST_TEST(0 == std::remove(filename0.c_str())); BOOST_TEST_EQUAL(15, m0.size()); // Test string_value(). BOOST_TEST_EQUAL("a" , n_v_pairs_0.string_value("a")); BOOST_TEST_EQUAL("b" , n_v_pairs_0.string_value("b")); BOOST_TEST_EQUAL("" , n_v_pairs_0.string_value("c")); BOOST_TEST_EQUAL("=" , n_v_pairs_0.string_value("d")); BOOST_TEST_EQUAL("1=." , n_v_pairs_0.string_value("e")); #ifndef LMI_MSW BOOST_TEST_EQUAL(" f \r" , n_v_pairs_0.string_value("f")); #else // LMI_MSW BOOST_TEST_EQUAL(" f " , n_v_pairs_0.string_value("f")); #endif // LMI_MSW BOOST_TEST_EQUAL("a test", n_v_pairs_0.string_value("this")); // Test numeric_value(). BOOST_TEST_EQUAL( 2.0 , n_v_pairs_0.numeric_value("z")); BOOST_TEST_EQUAL(-3.142 , n_v_pairs_0.numeric_value("y")); BOOST_TEST_EQUAL( 2.718 , n_v_pairs_0.numeric_value("x")); BOOST_TEST_EQUAL( 2.718 , n_v_pairs_0.numeric_value("w")); BOOST_TEST_EQUAL( 2.718 , n_v_pairs_0.numeric_value("v")); BOOST_TEST_EQUAL( 0.0 , n_v_pairs_0.numeric_value("u")); BOOST_TEST_EQUAL( 0.0 , n_v_pairs_0.numeric_value("t")); BOOST_TEST_EQUAL( 0.0 , n_v_pairs_0.numeric_value("s")); BOOST_TEST_EQUAL("2.718" , n_v_pairs_0.string_numeric_value("v")); BOOST_TEST_EQUAL("0" , n_v_pairs_0.string_numeric_value("s")); std::string filename1("/tmp/nonexistent_name_value_pairs_test_file"); name_value_pairs n_v_pairs_1(filename1); std::map<std::string, std::string> m1 = n_v_pairs_1.map(); BOOST_TEST_EQUAL(0, m1.size()); return EXIT_SUCCESS; }