void tool_lookup(const vdfastvector<const char *>& args, const vdfastvector<const char *>& switches, bool amd64) { if (args.size() < 2) help_lookup(); char *s; sint64 addr = _strtoi64(args[1], &s, 16); if (*s) fail("lookup: invalid address \"%s\"", args[0]); vdautoptr<IVDSymbolSource> pss(VDCreateSymbolSourceLinkMap()); pss->Init(VDTextAToW(args[0]).c_str()); const VDSymbol *sym = pss->LookupSymbol(addr); if (!sym) fail("symbol not found for address %08x", addr); const char *fn; int line; if (pss->LookupLine(addr, fn, line)) printf("%08I64x %s + %x [%s:%d]\n", addr, sym->name, addr-sym->rva, fn, line); else printf("%08I64x %s + %x\n", addr, sym->name, addr-sym->rva); }
int main(int argc, char* argv[]) { // Load the mesh Mesh mesh; H2DReader mloader; mloader.load("domain.mesh", &mesh); for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // Create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // Enumerate basis functions space.assign_dofs(); // Initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, bilinear_form, bilinear_form_ord, SYM); wf.add_liform(0, linear_form, linear_form_ord); wf.add_liform_surf(0, linear_form_surf, linear_form_surf_ord, 2); // Visualize solution and mesh ScalarView sview("Coarse solution", 0, 100, 798, 700); OrderView oview("Polynomial orders", 800, 100, 798, 700); // Matrix solver UmfpackSolver solver; // Time measurement double cpu = 0; begin_time(); // Solve the problem Solution sln; LinSystem ls(&wf, &solver); ls.set_spaces(1, &space); ls.set_pss(1, &pss); ls.assemble(); ls.solve(1, &sln); // Time measurement cpu += end_time(); // View the solution and mesh sview.show(&sln); oview.show(&space); // Print timing information verbose("Total running time: %g sec", cpu); // wait for all views to be closed View::wait("Waiting for all views to be closed."); return 0; }
int main(int argc, char* argv[]) { if (argc < 2) error("Missing mesh file name parameter."); // load the mesh Mesh mesh; mesh.load(argv[1]); // uniform mesh refinements mesh.refine_all_elements(); mesh.refine_all_elements(); mesh.refine_all_elements(); mesh.refine_all_elements(); // initialize the shapeset and the cache L2Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create the L2 space L2Space space(&mesh, &shapeset); space.set_bc_types(bc_types); // set uniform polynomial degrees space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); /* BaseView bview; bview.show(&space); bview.wait_for_close(); */ Solution sln; // matrix solver UmfpackSolver umfpack; // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form)); wf.add_liform(0, callback(linear_form)); // assemble and solve the finite element problem LinSystem sys(&wf, &umfpack); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln); // visualize the solution ScalarView view1("Solution 1"); view1.show(&sln); view1.wait_for_keypress(); // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
// Type Ctrl-break (there's a "break" key on your PC keyboard) // to dump stack trace of all Java threads static void SigBreakHandler(int junk) { if (!printing_stack) { UNIMPLEMENTED(); printing_stack = 1; pss(); printing_stack = 0; } signal(SIGBREAK, SigBreakHandler); }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; H2DReader mloader; mloader.load("square.mesh", &mesh); // initial mesh refinements for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); mesh.refine_towards_boundary(1,INIT_BDY_REF_NUM); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_uniform_order(P_INIT); space.assign_dofs(); // previous solution for the Newton's iteration Solution u_prev; // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(jac), UNSYM, ANY, 1, &u_prev); wf.add_liform(0, callback(res), ANY, 1, &u_prev); // initialize the nonlinear system and solver UmfpackSolver umfpack; NonlinSystem nls(&wf, &umfpack); nls.set_spaces(1, &space); nls.set_pss(1, &pss); // use a constant function as the initial guess u_prev.set_const(&mesh, 3.0); nls.set_ic(&u_prev, &u_prev, PROJ_TYPE); // Newton's loop if (!nls.solve_newton_1(&u_prev, NEWTON_TOL, NEWTON_MAX_ITER)) error("Newton's method did not converge."); // visualise the solution and mesh ScalarView sview("Solution", 0, 0, 800, 600); OrderView oview("Mesh", 820, 0, 800, 600); char title[100]; sprintf(title, "Solution"); sview.set_title(title); sview.show(&u_prev); sprintf(title, "Mesh"); oview.set_title(title); oview.show(&space); // wait for keyboard or mouse input View::wait(); return 0; }
void appendIncludeLeafSetAsNewick(const char *fn, const OttIdSet & inc, const OttIdSet & ls) { PhyloStatementSource pss(-1, -1); const OttIdSet exc = set_difference_as_set(ls, inc); std::ofstream phyloStatementOut; PhyloStatement ps{inc, exc, ls, pss}; phyloStatementOut.open(fn, std::ios::app); ps.writeAsNewick(phyloStatementOut); phyloStatementOut << '\n'; phyloStatementOut.close(); }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; H2DReader mloader; mloader.load("square.mesh", &mesh); // initial mesh refinements for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); mesh.refine_towards_boundary(1,INIT_BDY_REF_NUM); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_uniform_order(P_INIT); space.assign_dofs(); // previous solution for the Newton's iteration Solution u_prev; // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(jac), UNSYM, ANY, 1, &u_prev); wf.add_liform(0, callback(res), ANY, 1, &u_prev); // initialize the nonlinear system and solver UmfpackSolver umfpack; NonlinSystem nls(&wf, &umfpack); nls.set_spaces(1, &space); nls.set_pss(1, &pss); // use a constant function as the initial guess u_prev.set_const(&mesh, 3.0); nls.set_ic(&u_prev, &u_prev, PROJ_TYPE); // Newton's loop bool success = nls.solve_newton_1(&u_prev, NEWTON_TOL, NEWTON_MAX_ITER); #define ERROR_SUCCESS 0 #define ERROR_FAILURE -1 if (success) { // should pass with NEWTON_MAX_ITER = 8 and fail with NEWTON_MAX_ITER = 7 printf("Success!\n"); return ERROR_SUCCESS; } else { printf("Failure!\n"); return ERROR_FAILURE; } }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; mesh.load("sample.mesh"); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create the x displacement space H1Space xdisp(&mesh, &shapeset); xdisp.set_bc_types(bc_types); xdisp.set_bc_values(bc_values); xdisp.set_uniform_order(P_INIT); int ndofs = xdisp.assign_dofs(0); // create the y displacement space H1Space ydisp(&mesh, &shapeset); ydisp.set_bc_types(bc_types); ydisp.set_bc_values(bc_values); ydisp.set_uniform_order(P_INIT); ndofs += ydisp.assign_dofs(ndofs); // initialize the weak formulation WeakForm wf(2); wf.add_biform(0, 0, callback(bilinear_form_0_0), SYM); // Note that only one symmetric part is wf.add_biform(0, 1, callback(bilinear_form_0_1), SYM); // added in the case of symmetric bilinear wf.add_biform(1, 1, callback(bilinear_form_1_1), SYM); // forms. wf.add_liform_surf(0, callback(linear_form_surf_0), 3); wf.add_liform_surf(1, callback(linear_form_surf_1), 3); // initialize the linear system and solver UmfpackSolver umfpack; LinSystem sys(&wf, &umfpack); sys.set_spaces(2, &xdisp, &ydisp); sys.set_pss(1, &pss); // assemble the stiffness matrix and solve the system Solution xsln, ysln; sys.assemble(); sys.solve(2, &xsln, &ysln); // visualize the solution ScalarView view("Von Mises stress [Pa]", 50, 50, 1200, 600); VonMisesFilter stress(&xsln, &ysln, lambda, mu); view.show(&stress, EPS_HIGH, FN_VAL_0, &xsln, &ysln, 1.5e5); // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; H2DReader mloader; mloader.load("domain.mesh", &mesh); // sample "manual" mesh refinement mesh.refine_element(0); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form)); wf.add_liform(0, callback(linear_form)); // initialize the linear system and solver UmfpackSolver umfpack; LinSystem sys(&wf, &umfpack); sys.set_spaces(1, &space); sys.set_pss(1, &pss); // assemble the stiffness matrix and solve the system Solution sln; sys.assemble(); sys.solve(1, &sln); // visualize the solution ScalarView view("Solution"); view.show(&sln); // wait for a view to be closed View::wait(); return 0; }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; mesh.load("domain.mesh"); for(int i=0; i<UNIFORM_REF_LEVEL; i++) mesh.refine_all_elements(); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, bilinear_form); wf.add_liform(0, linear_form); // initialize the linear system and solver UmfpackSolver umfpack; LinSystem sys(&wf, &umfpack); sys.set_spaces(1, &space); sys.set_pss(1, &pss); // assemble the stiffness matrix and solve the system Solution sln; sys.assemble(); sys.solve(1, &sln); // visualize the solution ScalarView view("Solution"); view.show(&sln); // wait for keyboard or mouse input printf("Waiting for keyboard or mouse input.\n"); View::wait(); return 0; }
void NetPlayDiag::OnStart(wxCommandEvent&) { // find path for selected game std::string ntmp, ptmp, path; std::istringstream nss(m_game_list->GetGameNames()), pss(m_game_list->GetGamePaths()); while(std::getline(nss,ntmp)) { std::getline(pss,ptmp); if (m_selected_game == ntmp) { path = ptmp; break; } } if (path.length()) netplay_ptr->StartGame(path); else PanicAlertT("Game not found!!"); }
char *GetSequence(char *f_name) { for (std::vector<music_file>::iterator i = ::music_data.begin(); i != ::music_data.end(); i++) { // If the file has already been loaded, return the existing data if (strcmp(f_name, i->name) == 0) return (char *)i->data; } // File hasn't been loaded, do that now gm::ManagerPtr pManager(gm::getManager()); camoto::stream::input_file_sptr psMusic(new camoto::stream::input_file()); try { psMusic->open(f_name); } catch (const camoto::stream::open_error& e) { fprintf(stderr, "Error opening %s\n", f_name); return NULL; } gm::MusicTypePtr pMusicType(pManager->getMusicTypeByCode("cmf-creativelabs")); if (!pMusicType->isInstance(psMusic)) { printf("File %s is not in CMF format!\n", f_name); return NULL; } camoto::SuppData suppData; gm::MusicPtr pMusic(pMusicType->read(psMusic, suppData)); assert(pMusic); camoto::stream::string_sptr pss(new camoto::stream::string()); gm::MusicTypePtr pMusicOutType(pManager->getMusicTypeByCode("imf-idsoftware-type1")); pMusicOutType->write(pss, suppData, pMusic, gm::MusicType::Default); music_file cmf; strcpy(cmf.name, f_name); std::string imfdata = pss->str(); int len = imfdata.length(); cmf.data = new uint8_t[len]; memcpy(cmf.data, imfdata.data(), len); ::music_data.push_back(cmf); printf("Loaded CMF file %s\n", cmf.name); return (char *)cmf.data; }
// get_debug_command() // // Read a command from standard input. // This is useful when you have a debugger // which doesn't support calling into functions. // void get_debug_command() { ssize_t count; int i,j; bool gotcommand; intptr_t addr; char buffer[256]; nmethod *nm; methodOop m; tty->print_cr("You have entered the diagnostic command interpreter"); tty->print("The supported commands are:\n"); for ( i=0; ; i++ ) { if ( CommandList[i].code == CMDID_ILLEGAL ) break; tty->print_cr(" %s \n", CommandList[i].name ); } while ( 1 ) { gotcommand = false; tty->print("Please enter a command: "); count = scanf("%s", buffer) ; if ( count >=0 ) { for ( i=0; ; i++ ) { if ( CommandList[i].code == CMDID_ILLEGAL ) { if (!gotcommand) tty->print("Invalid command, please try again\n"); break; } if ( strcmp(buffer, CommandList[i].name) == 0 ) { gotcommand = true; switch ( CommandList[i].code ) { case CMDID_PS: ps(); break; case CMDID_PSS: pss(); break; case CMDID_PSF: psf(); break; case CMDID_FINDM: tty->print("Please enter the hex addr to pass to findm: "); scanf("%I64X", &addr); m = (methodOop)findm(addr); tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m); break; case CMDID_FINDNM: tty->print("Please enter the hex addr to pass to findnm: "); scanf("%I64X", &addr); nm = (nmethod*)findnm(addr); tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm); break; case CMDID_PP: tty->print("Please enter the hex addr to pass to pp: "); scanf("%I64X", &addr); pp((void*)addr); break; case CMDID_EXIT: exit(0); case CMDID_HELP: tty->print("Here are the supported commands: "); for ( j=0; ; j++ ) { if ( CommandList[j].code == CMDID_ILLEGAL ) break; tty->print_cr(" %s -- %s\n", CommandList[j].name, CommandList[j].description ); } break; case CMDID_QUIT: return; break; case CMDID_BPT: BREAKPOINT; break; case CMDID_VERIFY: verify();; break; case CMDID_THREADS: threads();; break; case CMDID_HSFIND: tty->print("Please enter the hex addr to pass to hsfind: "); scanf("%I64X", &addr); tty->print("Calling hsfind(0x%I64X)\n", addr); hsfind(addr); break; default: case CMDID_ILLEGAL: break; } } } } } }
int main(int argc, char **argv) { ros::init(argc, argv, "initialize_demo_db", ros::init_options::AnonymousName); boost::program_options::options_description desc; desc.add_options() ("help", "Show help message") ("host", boost::program_options::value<std::string>(), "Host for the MongoDB.") ("port", boost::program_options::value<std::size_t>(), "Port for the MongoDB."); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 1; } ros::AsyncSpinner spinner(1); spinner.start(); ros::NodeHandle nh; planning_scene_monitor::PlanningSceneMonitor psm(ROBOT_DESCRIPTION); if (!psm.getPlanningScene()) { ROS_ERROR("Unable to initialize PlanningSceneMonitor"); return 1; } bool done = false; unsigned int attempts = 0; while (!done && attempts < 5) { attempts++; try { moveit_warehouse::PlanningSceneStorage pss(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); moveit_warehouse::ConstraintsStorage cs(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); moveit_warehouse::RobotStateStorage rs(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); pss.reset(); cs.reset(); rs.reset(); // add default planning scenes moveit_msgs::PlanningScene psmsg; psm.getPlanningScene()->getPlanningSceneMsg(psmsg); psmsg.name = "default"; pss.addPlanningScene(psmsg); ROS_INFO("Added default scene: '%s'", psmsg.name.c_str()); moveit_msgs::RobotState rsmsg; robot_state::robotStateToRobotStateMsg(psm.getPlanningScene()->getCurrentState(), rsmsg); rs.addRobotState(rsmsg, "default"); ROS_INFO("Added default state"); const std::vector<std::string> &gnames = psm.getRobotModel()->getJointModelGroupNames(); for (std::size_t i = 0 ; i < gnames.size() ; ++i) { const robot_model::JointModelGroup *jmg = psm.getRobotModel()->getJointModelGroup(gnames[i]); if (!jmg->isChain()) continue; const std::vector<std::string> &lnames = jmg->getLinkModelNames(); if (lnames.empty()) continue; moveit_msgs::OrientationConstraint ocm; ocm.link_name = lnames.back(); ocm.header.frame_id = psm.getRobotModel()->getModelFrame(); ocm.orientation.x = 0.0; ocm.orientation.y = 0.0; ocm.orientation.z = 0.0; ocm.orientation.w = 1.0; ocm.absolute_x_axis_tolerance = 0.1; ocm.absolute_y_axis_tolerance = 0.1; ocm.absolute_z_axis_tolerance = boost::math::constants::pi<double>(); ocm.weight = 1.0; moveit_msgs::Constraints cmsg; cmsg.orientation_constraints.resize(1, ocm); cmsg.name = ocm.link_name + ":upright"; cs.addConstraints(cmsg, psm.getRobotModel()->getName(), jmg->getName()); ROS_INFO("Added default constraint: '%s'", cmsg.name.c_str()); } done = true; ROS_INFO("Default MoveIt! Warehouse was reset. Done."); } catch(mongo_ros::DbConnectException &ex) { ROS_WARN("MongoDB does not appear to be initialized yet. Waiting for a few seconds before trying again ..."); ros::WallDuration(15.0).sleep(); } } ros::shutdown(); return 0; }
void TrajectoryVideoLookup::initializeFromWarehouse(const std::string& host, const size_t port) { moveit_warehouse::PlanningSceneStorage pss(host, port); ROS_INFO("Connected to Warehouse DB at host (%s) and port (%d)", host.c_str(), (int)port); // ask the warehouse for the scenes std::vector<std::string> ps_names; pss.getPlanningSceneNames( ps_names ); ROS_INFO("%d available scenes to display", (int)ps_names.size()); std::vector<std::string>::iterator scene_name = ps_names.begin(); for(; scene_name!=ps_names.end(); ++scene_name) { ROS_INFO("Retrieving scene %s", scene_name->c_str()); moveit_warehouse::PlanningSceneWithMetadata pswm; pss.getPlanningScene(pswm, *scene_name); moveit_msgs::PlanningScene ps_msg = static_cast<const moveit_msgs::PlanningScene&>(*pswm); // ask qarehosue for the queries std::vector<std::string> pq_names; pss.getPlanningQueriesNames( pq_names, *scene_name); ROS_INFO("%d available queries to display", (int)pq_names.size()); // iterate over the queries std::vector<std::string>::iterator query_name = pq_names.begin(); for(; query_name!=pq_names.end(); ++query_name) { ROS_INFO("Retrieving query %s", query_name->c_str()); moveit_warehouse::MotionPlanRequestWithMetadata mprwm; pss.getPlanningQuery(mprwm, *scene_name, *query_name); moveit_msgs::MotionPlanRequest mpr_msg = static_cast<const moveit_msgs::MotionPlanRequest&>(*mprwm); // ask warehouse for stored trajectories std::vector<moveit_warehouse::RobotTrajectoryWithMetadata> planning_results; pss.getPlanningResults(planning_results, *scene_name, *query_name); ROS_INFO("Loaded %d trajectories", (int)planning_results.size()); // animate each trajectory std::vector<moveit_warehouse::RobotTrajectoryWithMetadata>::iterator traj_w_mdata = planning_results.begin(); for(; traj_w_mdata!=planning_results.end(); ++traj_w_mdata) { moveit_msgs::RobotTrajectory rt_msg; rt_msg = static_cast<const moveit_msgs::RobotTrajectory&>(**traj_w_mdata); //date and time based filename boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); std::string time_as_string = boost::posix_time::to_simple_string(now); // create trajectory ID std::string trajectory_id = time_as_string; std::replace(trajectory_id.begin(), trajectory_id.end(), '/','_'); std::replace(trajectory_id.begin(), trajectory_id.end(), '-','_'); std::replace(trajectory_id.begin(), trajectory_id.end(), ' ','_'); std::replace(trajectory_id.begin(), trajectory_id.end(), ':','_'); // save into lookup put( trajectory_id, ps_msg ); put( trajectory_id, mpr_msg ); put( trajectory_id, rt_msg ); sleep(1); } } } }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; mesh.load("domain.mesh"); // a-priori mesh refinements mesh.refine_all_elements(); mesh.refine_towards_boundary(5, 4, false); mesh.refine_towards_boundary(1, 4); mesh.refine_towards_boundary(3, 4); // initialize the shapeset and the cache H1ShapesetBeuchler shapeset; PrecalcShapeset pss(&shapeset); // spaces for velocities and pressure H1Space xvel(&mesh, &shapeset); H1Space yvel(&mesh, &shapeset); H1Space press(&mesh, &shapeset); // initialize boundary conditions xvel.set_bc_types(xvel_bc_type); xvel.set_bc_values(xvel_bc_value); yvel.set_bc_types(yvel_bc_type); press.set_bc_types(press_bc_type); // set velocity and pressure polynomial degrees xvel.set_uniform_order(P_INIT_VEL); yvel.set_uniform_order(P_INIT_VEL); press.set_uniform_order(P_INIT_PRESSURE); // assign degrees of freedom int ndofs = 0; ndofs += xvel.assign_dofs(ndofs); ndofs += yvel.assign_dofs(ndofs); ndofs += press.assign_dofs(ndofs); // velocities from the previous time step and for the Newton's iteration Solution xprev, yprev, xiter, yiter, piter; xprev.set_zero(&mesh); yprev.set_zero(&mesh); xiter.set_zero(&mesh); yiter.set_zero(&mesh); piter.set_zero(&mesh); // set up weak formulation WeakForm wf(3); if (NEWTON_ON) { wf.add_biform(0, 0, callback(bilinear_form_sym_0_0_1_1), SYM); wf.add_biform(0, 0, callback(newton_bilinear_form_unsym_0_0), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(0, 1, callback(newton_bilinear_form_unsym_0_1), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(0, 2, callback(bilinear_form_unsym_0_2), ANTISYM); wf.add_biform(1, 0, callback(newton_bilinear_form_unsym_1_0), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(1, 1, callback(bilinear_form_sym_0_0_1_1), SYM); wf.add_biform(1, 1, callback(newton_bilinear_form_unsym_1_1), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(1, 2, callback(bilinear_form_unsym_1_2), ANTISYM); wf.add_liform(0, callback(newton_F_0), ANY, 5, &xprev, &yprev, &xiter, &yiter, &piter); wf.add_liform(1, callback(newton_F_1), ANY, 5, &xprev, &yprev, &xiter, &yiter, &piter); wf.add_liform(2, callback(newton_F_2), ANY, 2, &xiter, &yiter); } else { wf.add_biform(0, 0, callback(bilinear_form_sym_0_0_1_1), SYM); wf.add_biform(0, 0, callback(simple_bilinear_form_unsym_0_0_1_1), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(1, 1, callback(bilinear_form_sym_0_0_1_1), SYM); wf.add_biform(1, 1, callback(simple_bilinear_form_unsym_0_0_1_1), UNSYM, ANY, 2, &xprev, &yprev); wf.add_biform(0, 2, callback(bilinear_form_unsym_0_2), ANTISYM); wf.add_biform(1, 2, callback(bilinear_form_unsym_1_2), ANTISYM); wf.add_liform(0, callback(simple_linear_form), ANY, 1, &xprev); wf.add_liform(1, callback(simple_linear_form), ANY, 1, &yprev); } // visualization VectorView vview("velocity [m/s]", 0, 0, 1500, 470); ScalarView pview("pressure [Pa]", 0, 530, 1500, 470); vview.set_min_max_range(0, 1.6); vview.fix_scale_width(80); //pview.set_min_max_range(-0.9, 1.0); pview.fix_scale_width(80); pview.show_mesh(true); // matrix solver UmfpackSolver umfpack; // linear system LinSystem linsys(&wf, &umfpack); // nonlinear system NonlinSystem nonsys(&wf, &umfpack); if (NEWTON_ON) { // set up the nonlinear system nonsys.set_spaces(3, &xvel, &yvel, &press); nonsys.set_pss(1, &pss); } else { // set up the linear system linsys.set_spaces(3, &xvel, &yvel, &press); linsys.set_pss(1, &pss); } // main loop char title[100]; int num_time_steps = FINAL_TIME / TAU; for (int i = 1; i <= num_time_steps; i++) { TIME += TAU; info("\n---- Time step %d, time = %g -----------------------------------", i, TIME); // this is needed to update the time-dependent boundary conditions ndofs = 0; ndofs += xvel.assign_dofs(ndofs); ndofs += yvel.assign_dofs(ndofs); ndofs += press.assign_dofs(ndofs); if (NEWTON_ON) { Solution xsln, ysln, psln; int it = 1; double res_l2_norm; do { info("\n---- Time step %d, Newton iter %d ---------------------------------\n", i, it++); // assemble and solve nonsys.assemble(); nonsys.solve(3, &xsln, &ysln, &psln); res_l2_norm = nonsys.get_residuum_l2_norm(); info("Residuum L2 norm: %g\n", res_l2_norm); // want to see Newtons iterations //sprintf(title, "Time level %d, Newton iteration %d", i, it-1); //vview.set_title(title); //vview.show(&xsln, &ysln, EPS_LOW); //pview.show(&psln); //pview.wait_for_keypress(); xiter = xsln; yiter = ysln; piter = psln; } while (res_l2_norm > NEWTON_TOL); // visualization at the end of the time step sprintf(title, "Velocity, time %g", TIME); vview.set_title(title); vview.show(&xprev, &yprev, EPS_LOW); sprintf(title, "Pressure, time %g", TIME); pview.set_title(title); pview.show(&piter); // copying result of the Newton's iteration into xprev, yprev xprev.copy(&xiter); yprev.copy(&yiter); } else { // assemble and solve Solution xsln, ysln, psln; linsys.assemble(); linsys.solve(3, &xsln, &ysln, &psln); // visualization sprintf(title, "Velocity, time %g", TIME); vview.set_title(title); vview.show(&xsln, &ysln, EPS_LOW); sprintf(title, "Pressure, time %g", TIME); pview.set_title(title); pview.show(&psln); //pview.wait_for_keypress(); xprev = xsln; yprev = ysln; } // uncomment one of the following lines to generate a series of video frames //vview.save_numbered_screenshot("velocity%03d.bmp", i, true); //pview.save_numbered_screenshot("pressure%03d.bmp", i, true); // the frames can then be converted to a video file with the command // mencoder "mf://velocity*.bmp" -mf fps=20 -o velocity.avi -ovc lavc -lavcopts vcodec=mpeg4 } // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("screen-quad.mesh", &mesh); // mloader.load("screen-tri.mesh", &mesh); // initialize the shapeset and the cache HcurlShapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); // visualize solution and mesh ScalarView Xview_r("Electric field X - real", 0, 0, 450, 420); ScalarView Yview_r("Electric field Y - real", 460, 0, 450, 420); ScalarView Xview_i("Electric field X - imag", 920, 0, 450, 420); ScalarView Yview_i("Electric field Y - imag", 1380, 0, 450, 420); OrderView ord("Polynomial Orders", 0, 460, 450, 420); /* // view the basis functions VectorBaseView bview; vbview.show(&space); vbview.wait_for_keypress(); */ // matrix solver UmfpackSolver solver; // DOF and CPU convergence graphs SimpleGraph graph_dof_est, graph_dof_exact, graph_cpu_est, graph_cpu_exact; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculating error wrt. exact solution Solution ex; ex.set_exact(&mesh, exact); double err_exact = 100 * hcurl_error(&sln_coarse, &ex); info("Exact solution error: %g%%", err_exact); // visualization RealFilter real(&sln_coarse); ImagFilter imag(&sln_coarse); Xview_r.set_min_max_range(-3.0, 1.0); //Xview_r.show_scale(false); Xview_r.show(&real, EPS_NORMAL, FN_VAL_0); Yview_r.set_min_max_range(-4.0, 4.0); //Yview_r.show_scale(false); Yview_r.show(&real, EPS_NORMAL, FN_VAL_1); Xview_i.set_min_max_range(-1.0, 4.0); //Xview_i.show_scale(false); Xview_i.show(&imag, EPS_NORMAL, FN_VAL_0); Yview_i.set_min_max_range(-4.0, 4.0); //Yview_i.show_scale(false); Yview_i.show(&imag, EPS_NORMAL, FN_VAL_1); ord.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem ref(&sys); ref.assemble(); ref.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution HcurlOrthoHP hp(1, &space); double err_est_adapt = hp.calc_error(&sln_coarse, &sln_fine) * 100; double err_est_hcurl = hcurl_error(&sln_coarse, &sln_fine) * 100; info("Error estimate (adapt): %g%%", err_est_adapt); info("Error estimate (hcurl): %g%%", err_est_hcurl); // add entries to DOF convergence graphs graph_dof_exact.add_values(space.get_num_dofs(), err_exact); graph_dof_exact.save("conv_dof_exact.dat"); graph_dof_est.add_values(space.get_num_dofs(), err_est_hcurl); graph_dof_est.save("conv_dof_est.dat"); // add entries to CPU convergence graphs graph_cpu_exact.add_values(cpu, err_exact); graph_cpu_exact.save("conv_cpu_exact.dat"); graph_cpu_est.add_values(cpu, err_est_hcurl); graph_cpu_est.save("conv_cpu_est.dat"); // if err_est_adapt too large, adapt the mesh if (err_est_adapt < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); verbose("Total running time: %g sec", cpu); // wait for keyboard or mouse input View::wait("Waiting for all views to be closed."); return 0; }
int main(int argc, char* argv[]) { // load and refine mesh Mesh mesh; mesh.load("cathedral.mesh"); for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); mesh.refine_towards_boundary(2, 5); // set up shapeset H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // set up spaces H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // set initial condition Solution tsln; tsln.set_const(&mesh, T_INIT); // weak formulation WeakForm wf(1); wf.add_biform(0, 0, bilinear_form<double, double>, bilinear_form<Ord, Ord>); wf.add_biform_surf(0, 0, bilinear_form_surf<double, double>, bilinear_form_surf<Ord, Ord>, marker_air); wf.add_liform(0, linear_form<double, double>, linear_form<Ord, Ord>, ANY, 1, &tsln); wf.add_liform_surf(0, linear_form_surf<double, double>, linear_form_surf<Ord, Ord>, marker_air); // matrix solver UmfpackSolver umfpack; // linear system LinSystem ls(&wf, &umfpack); ls.set_spaces(1, &space); ls.set_pss(1, &pss); // visualisation ScalarView Tview("Temperature", 0, 0, 450, 600); char title[100]; sprintf(title, "Time %3.5f, exterior temperature %3.5f", TIME, temp_ext(TIME)); Tview.set_min_max_range(0,20); Tview.set_title(title); Tview.fix_scale_width(3); // time stepping int nsteps = (int)(FINAL_TIME/TAU + 0.5); bool rhsonly = false; for(int n = 1; n <= nsteps; n++) { info("\n---- Time %3.5f, time step %d, ext_temp %g ----------", TIME, n, temp_ext(TIME)); // assemble and solve ls.assemble(rhsonly); rhsonly = true; ls.solve(1, &tsln); // shifting the time variable TIME += TAU; // visualization of solution sprintf(title, "Time %3.2f, exterior temperature %3.5f", TIME, temp_ext(TIME)); Tview.set_title(title); Tview.show(&tsln); //Tview.wait_for_keypress(); } // Note: a separate example shows how to create videos // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("square_quad.mesh", &mesh); // initial mesh refinement for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); wf.add_liform(0, linear_form, linear_form_ord); // visualize solution and mesh ScalarView sview("Coarse solution", 0, 100, 798, 700); OrderView oview("Polynomial orders", 800, 100, 798, 700); // matrix solver UmfpackSolver solver; // prepare selector RefinementSelectors::H1UniformHP selector(ISO_ONLY, ADAPT_TYPE, 1.0, H2DRS_DEFAULT_ORDER, &shapeset); // DOF and CPU convergence graphs SimpleGraph graph_dof_est, graph_dof_exact, graph_cpu_est, graph_cpu_exact; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem ls(&wf, &solver); ls.set_spaces(1, &space); ls.set_pss(1, &pss); ls.assemble(); ls.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculate error wrt. exact solution ExactSolution exact(&mesh, fndd); double error = h1_error(&sln_coarse, &exact) * 100; info("\nExact solution error: %g%%", error); // view the solution sview.show(&sln_coarse); oview.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&ls); rs.assemble(); rs.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution H1AdaptHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Estimate of error: %g%%", err_est); // add entries to DOF convergence graphs graph_dof_exact.add_values(space.get_num_dofs(), error); graph_dof_exact.save("conv_dof_exact.dat"); graph_dof_est.add_values(space.get_num_dofs(), err_est); graph_dof_est.save("conv_dof_est.dat"); // add entries to CPU convergence graphs graph_cpu_exact.add_values(cpu, error); graph_cpu_exact.save("conv_cpu_exact.dat"); graph_cpu_est.add_values(cpu, err_est); graph_cpu_est.save("conv_cpu_est.dat"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, &selector, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); //sview.wait_for_keypress(); } while (done == false); verbose("Total running time: %g sec", cpu); // show the fine solution - this is the final result sview.set_title("Final solution"); sview.show(&sln_fine); // wait for keyboard or mouse input View::wait(); return 0; }
/** * Loads an actor object from the specified string. * * @param line A line describing the object to load * @return A pointer to a the created instance */ Actor * Actor::load(const std::string line, const std::map<std::string, Environment *> & envs, const std::map<std::string, Object *> & objs) { std::istringstream input(line); std::vector<std::string> tokens; std::string token; while (std::getline(input, token, ':')) { tokens.push_back(token); } // extract properties std::map<std::string, std::string> properties; std::istringstream pss(tokens[3]); while (std::getline(pss, token, ',')) { size_t eq_sign = token.find('='); properties.insert(std::pair<std::string, std::string>(token.substr(0, eq_sign), token.substr(eq_sign+1))); } // find type std::string & type = tokens[1]; std::map<std::string, std::string>::iterator prop_it; std::map<std::string, Environment *>::const_iterator env_it; std::map<std::string, Object *>::iterator obj_it; std::string current_room_id = properties.find("current_room")->second; Environment * current_room = envs.find(current_room_id)->second; int hp = str2int(properties.find("hp")->second); int strength = str2int(properties.find("strength")->second); Actor * actor = NULL; if (type == "Human") { // abstract! } else if (type == "Player") { bool has_heart = str2int(properties.find("has_heart")->second) != 0; int max_health = str2int(properties.find("max_health")->second); actor = new Player(current_room, hp, strength, has_heart, max_health); } else if (type == "Wizard") { bool has_heart = str2int(properties.find("has_heart")->second) != 0; int max_health = str2int(properties.find("max_health")->second); int magic = str2int(properties.find("magic")->second); int max_magic = str2int(properties.find("max_magic")->second); actor = new Wizard(current_room, hp, strength, has_heart, max_health, magic, max_magic); } else if (type == "Troll") { actor = new Troll(current_room, hp, strength); } else if (type == "Vampire") { actor = new Vampire(current_room, hp, strength); } else if (type == "VampireFactory") { int frequency = str2int(properties.find("frequency")->second); actor = new VampireFactory(current_room, frequency); } else { std::cerr << "Unrecognized actor type: " << type << std::endl; } // set general Actor properties, not already set std::string container_id = properties.find("container")->second; Object * cont_obj = objs.find(container_id)->second; Container * cont; if ((cont = dynamic_cast<Container *>(cont_obj))) { actor->container = cont; } return actor; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; mesh.load("screen-quad.mesh"); // mesh.load("screen-tri.mesh"); // initialize the shapeset and the cache HcurlShapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); // visualize solution and mesh ScalarView Xview_r("Electric field X - real", 0, 0, 320, 320); ScalarView Yview_r("Electric field Y - real", 325, 0, 320, 320); ScalarView Xview_i("Electric field X - imag", 650, 0, 320, 320); ScalarView Yview_i("Electric field Y - imag", 975, 0, 320, 320); OrderView ord("Polynomial Orders", 325, 400, 600, 600); // matrix solver UmfpackSolver solver; // convergence graph wrt. the number of degrees of freedom GnuplotGraph graph; graph.set_captions("Error Convergence for the Screen Problem in H(curl)", "Degrees of Freedom", "Error [%]"); graph.add_row("exact error", "k", "-", "o"); graph.add_row("error estimate", "k", "--"); graph.set_log_y(); // convergence graph wrt. CPU time GnuplotGraph graph_cpu; graph_cpu.set_captions("Error Convergence for the Screen Problem in H(curl)", "CPU Time", "Error [%]"); graph_cpu.add_row("exact error", "k", "-", "o"); graph_cpu.add_row("error estimate", "k", "--"); graph_cpu.set_log_y(); // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculating error wrt. exact solution Solution ex; ex.set_exact(&mesh, exact); double error = 100 * hcurl_error(&sln_coarse, &ex); info("Exact solution error: %g%%", error); // visualization RealFilter real(&sln_coarse); ImagFilter imag(&sln_coarse); Xview_r.set_min_max_range(-3.0, 1.0); Xview_r.show_scale(false); Xview_r.show(&real, EPS_NORMAL, FN_VAL_0); Yview_r.set_min_max_range(-4.0, 4.0); Yview_r.show_scale(false); Yview_r.show(&real, EPS_NORMAL, FN_VAL_1); Xview_i.set_min_max_range(-1.0, 4.0); Xview_i.show_scale(false); Xview_i.show(&imag, EPS_NORMAL, FN_VAL_0); Yview_i.set_min_max_range(-4.0, 4.0); Yview_i.show_scale(false); Yview_i.show(&imag, EPS_NORMAL, FN_VAL_1); ord.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem ref(&sys); ref.assemble(); ref.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution HcurlOrthoHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%%", err_est); // add entry to DOF convergence graph graph.add_values(0, space.get_num_dofs(), error); graph.add_values(1, space.get_num_dofs(), err_est); graph.save("conv_dof.gp"); // add entry to CPU convergence graph graph_cpu.add_values(0, cpu, error); graph_cpu.add_values(1, cpu, err_est); graph_cpu.save("conv_cpu.gp"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); verbose("Total running time: %g sec", cpu); // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("square_quad.mesh", &mesh); if(P_INIT == 1) P_INIT++; // this is because there are no degrees of freedom // on the coarse mesh lshape.mesh if P_INIT == 1 // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); wf.add_liform(0, callback(linear_form)); // visualize solution and mesh //ScalarView sview("Coarse solution", 0, 0, 500, 400); //OrderView oview("Polynomial orders", 505, 0, 500, 400); // matrix solver UmfpackSolver solver; // prepare selector RefinementSelectors::H1NonUniformHP selector(ISO_ONLY, ADAPT_TYPE, 1.0, H2DRS_DEFAULT_ORDER, &shapeset); // DOF and CPU convergence graphs SimpleGraph graph_dof_est, graph_dof_exact, graph_cpu_est, graph_cpu_exact; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem ls(&wf, &solver); ls.set_spaces(1, &space); ls.set_pss(1, &pss); ls.assemble(); ls.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculate error wrt. exact solution ExactSolution exact(&mesh, fndd); double error = h1_error(&sln_coarse, &exact) * 100; info("\nExact solution error: %g%%", error); // view the solution //sview.show(&sln_coarse); //oview.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&ls); rs.assemble(); rs.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution H1AdaptHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Estimate of error: %g%%", err_est); // add entries to DOF convergence graphs graph_dof_exact.add_values(space.get_num_dofs(), error); graph_dof_exact.save("conv_dof_exact.dat"); graph_dof_est.add_values(space.get_num_dofs(), err_est); graph_dof_est.save("conv_dof_est.dat"); // add entries to CPU convergence graphs graph_cpu_exact.add_values(cpu, error); graph_cpu_exact.save("conv_cpu_exact.dat"); graph_cpu_est.add_values(cpu, err_est); graph_cpu_est.save("conv_cpu_est.dat"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { done = hp.adapt(THRESHOLD, STRATEGY, &selector, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); // wait for keyboard or mouse input //sview.wait_for_keypress("Click into the mesh window and press any key to proceed."); } while (done == false); verbose("Total running time: %g sec", cpu); #define ERROR_SUCCESS 0 #define ERROR_FAILURE -1 int n_dof_allowed = 49; printf("n_dof_actual = %d\n", ndofs); printf("n_dof_allowed = %d\n", n_dof_allowed); // ndofs was 49 at the time this test was created if (ndofs <= n_dof_allowed) { printf("Success!\n"); return ERROR_SUCCESS; } else { printf("Failure!\n"); return ERROR_FAILURE; } }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("domain2.mesh", &mesh); // initial uniform subdivision //mesh.refine_all_elements(); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(dir_bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form_iron), SYM, 3); wf.add_biform(0, 0, callback(bilinear_form_wire), SYM, 2); wf.add_biform(0, 0, callback(bilinear_form_air), SYM, 1); wf.add_liform(0, callback(linear_form_wire), 2); // visualize solution and mesh ScalarView view("Vector potential A", 0, 0, 1000, 600); OrderView oview("Polynomial orders", 1100, 0, 900, 600); // matrix solver UmfpackSolver solver; // DOF and CPU convergence graphs SimpleGraph graph_dof_est, graph_dof_exact, graph_cpu_est, graph_cpu_exact; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); // time measurement cpu += end_time(); // assemble the stiffness matrix and solve the system sys.assemble(); sys.solve(1, &sln_coarse); // visualize the solution view.show(&sln_coarse, EPS_HIGH); oview.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&sys); rs.assemble(); rs.solve(1, &sln_fine); // calculate element errors and total error estimate H1OrthoHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%%", err_est); // add entries to DOF convergence graph graph_dof_est.add_values(space.get_num_dofs(), err_est); graph_dof_est.save("conv_dof.dat"); // add entries to CPU convergence graph graph_cpu_est.add_values(cpu, err_est); graph_cpu_est.save("conv_cpu.dat"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (done == false); verbose("Total running time: %g sec", cpu); // show the fine solution - this is the final result view.set_title("Final solution"); view.show(&sln_fine); // wait for keyboard or mouse input View::wait("Waiting for all views to be closed."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("square_quad.mesh", &mesh); // mloader.load("square_tri.mesh", &mesh); for (int i=0; i<INIT_REF_NUM; i++) mesh.refine_all_elements(); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); wf.add_liform(0, callback(linear_form)); // matrix solver UmfpackSolver solver; // prepare selector RefinementSelectors::H1NonUniformHP selector(ISO_ONLY, ADAPT_TYPE, CONV_EXP, H2DRS_DEFAULT_ORDER, &shapeset); // convergence graph wrt. the number of degrees of freedom GnuplotGraph graph; graph.set_log_y(); graph.set_captions("Error Convergence for the Inner Layer Problem", "Degrees of Freedom", "Error [%]"); graph.add_row("exact error", "k", "-", "o"); graph.add_row("error estimate", "k", "--"); // convergence graph wrt. CPU time GnuplotGraph graph_cpu; graph_cpu.set_captions("Error Convergence for the Inner Layer Problem", "CPU Time", "Error Estimate [%]"); graph_cpu.add_row("exact error", "k", "-", "o"); graph_cpu.add_row("error estimate", "k", "--"); graph_cpu.set_log_y(); // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem ls(&wf, &solver); ls.set_spaces(1, &space); ls.set_pss(1, &pss); ls.assemble(); ls.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculate error wrt. exact solution ExactSolution exact(&mesh, fndd); double error = h1_error(&sln_coarse, &exact) * 100; // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&ls); rs.assemble(); rs.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution H1AdaptHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Exact solution error: %g%%", error); info("Estimate of error: %g%%", err_est); // add entry to DOF convergence graph graph.add_values(0, space.get_num_dofs(), error); graph.add_values(1, space.get_num_dofs(), err_est); graph.save("conv_dof.gp"); // add entry to CPU convergence graph graph_cpu.add_values(0, cpu, error); graph_cpu.add_values(1, cpu, err_est); graph_cpu.save("conv_cpu.gp"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, &selector, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (done == false); verbose("Total running time: %g sec", cpu); #define ERROR_SUCCESS 0 #define ERROR_FAILURE -1 int n_dof_allowed = 4000; printf("n_dof_actual = %d\n", ndofs); printf("n_dof_allowed = %d\n", n_dof_allowed); if (ndofs <= n_dof_allowed) { printf("Success!\n"); return ERROR_SUCCESS; } else { printf("Failure!\n"); return ERROR_FAILURE; } }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("lshape3q.mesh", &mesh); // mloader.load("lshape3t.mesh", &mesh); // initialize the shapeset and the cache HcurlShapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space HcurlSpace space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form), SYM); wf.add_biform_surf(0, 0, callback(bilinear_form_surf)); wf.add_liform_surf(0, linear_form_surf, linear_form_surf_ord); // matrix solver UmfpackSolver solver; // convergence graph wrt. the number of degrees of freedom GnuplotGraph graph; graph.set_captions("Error Convergence for the Bessel Problem in H(curl)", "Degrees of Freedom", "Error [%]"); graph.add_row("exact error", "k", "-", "o"); graph.add_row("error estimate", "k", "--"); graph.set_log_y(); // convergence graph wrt. CPU time GnuplotGraph graph_cpu; graph_cpu.set_captions("Error Convergence for the Bessel Problem in H(curl)", "CPU Time", "Error [%]"); graph_cpu.add_row("exact error", "k", "-", "o"); graph_cpu.add_row("error estimate", "k", "--"); graph_cpu.set_log_y(); // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem sys(&wf, &solver); sys.set_spaces(1, &space); sys.set_pss(1, &pss); sys.assemble(); sys.solve(1, &sln_coarse); // time measurement cpu += end_time(); // calculating error wrt. exact solution ExactSolution ex(&mesh, exact); double err = 100 * hcurl_error(&sln_coarse, &ex); info("Exact solution error: %g%%", err); // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&sys); rs.assemble(); rs.solve(1, &sln_fine); // calculate error estimate wrt. fine mesh solution HcurlOrthoHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%%", err_est); // add entry to DOF convergence graph graph.add_values(0, space.get_num_dofs(), err); graph.add_values(1, space.get_num_dofs(), err_est); graph.save("conv_dof.gp"); // add entry to CPU convergence graph graph_cpu.add_values(0, cpu, err); graph_cpu.add_values(1, cpu, err_est); graph_cpu.save("conv_cpu.gp"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); verbose("Total running time: %g sec", cpu); #define ERROR_SUCCESS 0 #define ERROR_FAILURE -1 int n_dof_allowed = 3000; printf("n_dof_actual = %d\n", ndofs); printf("n_dof_allowed = %d\n", n_dof_allowed);// ndofs was 2680 at the time this test was created if (ndofs <= n_dof_allowed) { printf("Success!\n"); return ERROR_SUCCESS; } else { printf("Failure!\n"); return ERROR_FAILURE; } }
int main(int argc, char* argv[]) { // load the mesh file Mesh mesh; H2DReader mloader; mloader.load("domain.mesh", &mesh); for(int i=0; i<UNIFORM_REF_LEVEL; i++) mesh.refine_all_elements(); mesh.refine_towards_vertex(3, CORNER_REF_LEVEL); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create an H1 space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(bilinear_form)); wf.add_biform_surf(0, 0, callback(bilinear_form_surf), 1); wf.add_liform_surf(0, callback(linear_form_surf), 1); // initialize the linear system and solver UmfpackSolver umfpack; LinSystem sys(&wf, &umfpack); sys.set_spaces(1, &space); sys.set_pss(1, &pss); // testing n_dof and correctness of solution vector // for p_init = 1, 2, ..., 10 int success = 1; for (int p_init = 1; p_init <= 10; p_init++) { printf("********* p_init = %d *********\n", p_init); space.set_uniform_order(p_init); space.assign_dofs(); // assemble the stiffness matrix and solve the system Solution sln; sys.assemble(); sys.solve(1, &sln); scalar *sol_vector; int n_dof; sys.get_solution_vector(sol_vector, n_dof); printf("n_dof = %d\n", n_dof); double sum = 0; for (int i=0; i < n_dof; i++) sum += sol_vector[i]; printf("coefficient sum = %g\n", sum); // Actual test. The values of 'sum' depend on the // current shapeset. If you change the shapeset, // you need to correct these numbers. if (p_init == 1 && fabs(sum - 1146.15) > 1e-1) success = 0; if (p_init == 2 && fabs(sum - 1145.97) > 1e-1) success = 0; if (p_init == 3 && fabs(sum - 1145.97) > 1e-1) success = 0; if (p_init == 4 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 5 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 6 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 7 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 8 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 9 && fabs(sum - 1145.96) > 1e-1) success = 0; if (p_init == 10 && fabs(sum - 1145.96) > 1e-1) success = 0; } #define ERROR_SUCCESS 0 #define ERROR_FAILURE -1 if (success == 1) { printf("Success!\n"); return ERROR_SUCCESS; } else { printf("Failure!\n"); return ERROR_FAILURE; } }
int main(int argc, char* argv[]) { Mesh mesh; mesh.load("square.mesh"); for(int i = 0; i < REF_INIT; i++) mesh.refine_all_elements(); H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); space.assign_dofs(); WeakForm wf(1); if(TIME_DISCR == 1) { wf.add_biform(0, 0, bilinear_form_0_0_euler, UNSYM, ANY, 1, &Psi_iter); wf.add_liform(0, linear_form_0_euler, ANY, 2, &Psi_iter, &Psi_prev); } else { wf.add_biform(0, 0, bilinear_form_0_0_cranic, UNSYM, ANY, 1, &Psi_iter); wf.add_liform(0, linear_form_0_cranic, ANY, 2, &Psi_iter, &Psi_prev); } UmfpackSolver umfpack; NonlinSystem nls(&wf, &umfpack); nls.set_spaces(1, &space); nls.set_pss(1, &pss); char title[100]; ScalarView view("", 0, 0, 700, 600); //view.set_min_max_range(-0.5,0.5); // setting initial condition at zero time level Psi_prev.set_exact(&mesh, fn_init); nls.set_ic(&Psi_prev, &Psi_prev, PROJ_TYPE); Psi_iter.copy(&Psi_prev); // view initial guess for Newton's method /* sprintf(title, "Initial guess for the Newton's method"); view.set_title(title); view.show(&Psi_iter); view.wait_for_keypress(); */ Solution sln; // time stepping int nstep = (int)(T_FINAL/TAU + 0.5); for(int n = 1; n <= nstep; n++) { info("\n---- Time step %d -----------------------------------------------", n); // set initial condition for the Newton's iteration // actually needed only when space changes // otherwise initial solution vector is that one // from the previous time level //nls.set_ic(&Psi_iter, &Psi_iter); int it = 1; double res_l2_norm; do { info("\n---- Time step %d, Newton iter %d ---------------------------------\n", n, it++); nls.assemble(); nls.solve(1, &sln); res_l2_norm = nls.get_residuum_l2_norm(); info("Residuum L2 norm: %g\n", res_l2_norm); // want to see Newtons iterations /* sprintf(title, "Time level %d, Newton iteration %d", n, it-1); view.set_title(title); view.show(&sln); view.wait_for_keypress(); */ Psi_iter = sln; } while (res_l2_norm > NEWTON_TOL); // visualization of solution on the n-th time level sprintf(title, "Time level %d", n); //view.set_min_max_range(90,100); view.set_title(title); view.show(&Psi_iter); //view.wait_for_keypress(); // uncomment one of the following lines to generate a series of video frames //view.save_numbered_screenshot("sol%03d.bmp", n, true); //pview.save_numbered_screenshot("pressure%03d.bmp", i, true); // the frames can then be converted to a video file with the command // mencoder "mf://velocity*.bmp" -mf fps=20 -o velocity.avi -ovc lavc -lavcopts vcodec=mpeg4 // copying result of the Newton's iteration into Psi_prev Psi_prev.copy(&Psi_iter); } printf("Click into the image window and press 'q' to finish.\n"); View::wait(); return 0; }
int main(int argc, char **argv) { ros::init(argc, argv, "publish_warehouse_data", ros::init_options::AnonymousName); // time to wait in between publishing messages double delay = 0.001; boost::program_options::options_description desc; desc.add_options() ("help", "Show help message") ("host", boost::program_options::value<std::string>(), "Host for the MongoDB.") ("port", boost::program_options::value<std::size_t>(), "Port for the MongoDB.") ("scene", boost::program_options::value<std::string>(), "Name of scene to publish.") ("planning_requests", "Also publish the planning requests that correspond to the scene") ("planning_results", "Also publish the planning results that correspond to the scene") ("constraint", boost::program_options::value<std::string>(), "Name of constraint to publish.") ("state", boost::program_options::value<std::string>(), "Name of the robot state to publish.") ("delay", boost::program_options::value<double>()->default_value(delay), "Time to wait in between publishing messages (s)"); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); if (vm.count("help") || (!vm.count("scene") && !vm.count("constraint") && !vm.count("state"))) { std::cout << desc << std::endl; return 1; } try { delay = vm["delay"].as<double>(); } catch(...) { std::cout << desc << std::endl; return 2; } ros::AsyncSpinner spinner(1); spinner.start(); ros::NodeHandle nh; ros::Publisher pub_scene, pub_req, pub_res, pub_constr, pub_state; ros::Duration wait_time(delay); // publish the scene if (vm.count("scene")) { pub_scene = nh.advertise<moveit_msgs::PlanningScene>(PLANNING_SCENE_TOPIC, 10); bool req = vm.count("planning_requests"); bool res = vm.count("planning_results"); if (req) pub_req = nh.advertise<moveit_msgs::MotionPlanRequest>(PLANNING_REQUEST_TOPIC, 100); if (res) pub_res = nh.advertise<moveit_msgs::RobotTrajectory>(PLANNING_RESULTS_TOPIC, 100); moveit_warehouse::PlanningSceneStorage pss(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); ros::spinOnce(); std::vector<std::string> scene_names; pss.getPlanningSceneNames(vm["scene"].as<std::string>(), scene_names); for (std::size_t i = 0 ; i < scene_names.size() ; ++i) { moveit_warehouse::PlanningSceneWithMetadata pswm; if (pss.getPlanningScene(pswm, scene_names[i])) { ROS_INFO("Publishing scene '%s'", pswm->lookupString(moveit_warehouse::PlanningSceneStorage::PLANNING_SCENE_ID_NAME).c_str()); pub_scene.publish(static_cast<const moveit_msgs::PlanningScene&>(*pswm)); ros::spinOnce(); // publish optional data associated to the scene if (req || res) { std::vector<moveit_warehouse::MotionPlanRequestWithMetadata> planning_queries; std::vector<std::string> query_names; pss.getPlanningQueries(planning_queries, query_names, pswm->name); ROS_INFO("There are %d planning queries associated to the scene", (int)planning_queries.size()); ros::WallDuration(0.5).sleep(); for (std::size_t i = 0 ; i < planning_queries.size() ; ++i) { if (req) { ROS_INFO("Publishing query '%s'", query_names[i].c_str()); pub_req.publish(static_cast<const moveit_msgs::MotionPlanRequest&>(*planning_queries[i])); ros::spinOnce(); } if (res) { std::vector<moveit_warehouse::RobotTrajectoryWithMetadata> planning_results; pss.getPlanningResults(planning_results, query_names[i], pswm->name); for (std::size_t j = 0 ; j < planning_results.size() ; ++j) { pub_res.publish(static_cast<const moveit_msgs::RobotTrajectory&>(*planning_results[j])); ros::spinOnce(); } } } } wait_time.sleep(); } } } // publish constraints if (vm.count("constraint")) { moveit_warehouse::ConstraintsStorage cs(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); pub_constr = nh.advertise<moveit_msgs::Constraints>(CONSTRAINTS_TOPIC, 100); std::vector<std::string> cnames; cs.getKnownConstraints(vm["constraint"].as<std::string>(), cnames); for (std::size_t i = 0 ; i < cnames.size() ; ++i) { moveit_warehouse::ConstraintsWithMetadata cwm; if (cs.getConstraints(cwm, cnames[i])) { ROS_INFO("Publishing constraints '%s'", cwm->lookupString(moveit_warehouse::ConstraintsStorage::CONSTRAINTS_ID_NAME).c_str()); pub_constr.publish(static_cast<const moveit_msgs::Constraints&>(*cwm)); ros::spinOnce(); wait_time.sleep(); } } } // publish constraints if (vm.count("state")) { moveit_warehouse::RobotStateStorage rs(vm.count("host") ? vm["host"].as<std::string>() : "", vm.count("port") ? vm["port"].as<std::size_t>() : 0); pub_state = nh.advertise<moveit_msgs::RobotState>(STATES_TOPIC, 100); std::vector<std::string> rnames; rs.getKnownRobotStates(vm["state"].as<std::string>(), rnames); for (std::size_t i = 0 ; i < rnames.size() ; ++i) { moveit_warehouse::RobotStateWithMetadata rswm; if (rs.getRobotState(rswm, rnames[i])) { ROS_INFO("Publishing state '%s'", rswm->lookupString(moveit_warehouse::RobotStateStorage::STATE_NAME).c_str()); pub_state.publish(static_cast<const moveit_msgs::RobotState&>(*rswm)); ros::spinOnce(); wait_time.sleep(); } } } ros::WallDuration(1.0).sleep(); ROS_INFO("Done."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh, basemesh; basemesh.load("square.mesh"); for(int i = 0; i < REF_INIT; i++) basemesh.refine_all_elements(); mesh.copy(&basemesh); mesh.refine_towards_boundary(1,3); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); space.assign_dofs(); // enumerate basis functions space.assign_dofs(); Solution Tprev, // previous time step solution, for the time integration method Titer; // solution converging during the Newton's iteration // initialize the weak formulation WeakForm wf(1); if(TIME_DISCR == 1) { wf.add_biform(0, 0, callback(J_euler), UNSYM, ANY, 1, &Titer); wf.add_liform(0, callback(F_euler), ANY, 2, &Titer, &Tprev); } else { wf.add_biform(0, 0, callback(J_cranic), UNSYM, ANY, 1, &Titer); wf.add_liform(0, callback(F_cranic), ANY, 2, &Titer, &Tprev); } // matrix solver UmfpackSolver solver; // nonlinear system class NonlinSystem nls(&wf, &solver); nls.set_spaces(1, &space); nls.set_pss(1, &pss); // visualize solution and mesh ScalarView view("", 0, 0, 700, 600); view.fix_scale_width(80); OrderView ordview("", 700, 0, 700, 600); // error estimate as a function of physical time GnuplotGraph graph_err; graph_err.set_captions("","Time step","Error"); graph_err.add_row(); // error estimate as a function of DOF GnuplotGraph graph_dofs; graph_dofs.set_captions("","Time step","DOFs"); graph_dofs.add_row(); // initial condition at zero time level //Tprev.set_const(&mesh, 0.0); Tprev.set_dirichlet_lift(&space, &pss); Titer.set_dirichlet_lift(&space, &pss); nls.set_ic(&Titer, &Titer, PROJ_TYPE); // view initial guess for Newton's method // satisfies BC conditions char title[100]; sprintf(title, "Initial iteration"); view.set_title(title); view.show(&Titer); ordview.show(&space); //view.wait_for_keypress(); // this may cause graphics problems // time stepping loop int nstep = (int)(T_FINAL/TAU + 0.5); double cpu = 0.0; Solution sln_coarse, sln_fine; for(int n = 1; n <= nstep; n++) { info("\n---- Time step %d -----------------------------------------------------------------", n); // time measurement begin_time(); // perform periodic unrefinements if (n % UNREF_FREQ == 0) { mesh.copy(&basemesh); space.set_uniform_order(P_INIT); space.assign_dofs(); } // adaptivity loop int at = 0, ndofs; bool done = false; double err_est, cpu; do { info("\n---- Time step %d, adaptivity step %d ---------------------------------------------\n", n, ++at); // Newton's loop for coarse mesh solution int it = 1; double res_l2_norm; if (n > 1 || at > 1) nls.set_ic(&sln_fine, &Titer); else nls.set_ic(&Titer, &Titer); do { info("\n---- Time step %d, adaptivity step %d, Newton step %d (Coarse mesh solution)-------\n", n, at, it++); nls.assemble(); nls.solve(1, &sln_coarse); res_l2_norm = nls.get_residuum_l2_norm(); info("Residuum L2 norm: %g", res_l2_norm); Titer.copy(&sln_coarse); } while (res_l2_norm > NEWTON_TOL_COARSE); // Newton's loop for fine mesh solution it = 1; RefNonlinSystem rs(&nls); rs.prepare(); if (n > 1 || at > 1) rs.set_ic(&sln_fine, &Titer); else rs.set_ic(&Titer, &Titer); do { info("\n---- Time step %d, adaptivity step %d, Newton step %d (Fine mesh solution) --------\n", n, at, it++); rs.assemble(); rs.solve(1, &sln_fine); res_l2_norm = rs.get_residuum_l2_norm(); info("Residuum L2 norm: %g", res_l2_norm); Titer.copy(&sln_fine); } while (res_l2_norm > NEWTON_TOL_REF); // calculate error estimate wrt. fine mesh solution H1OrthoHP hp(1, &space); err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%", err_est); // visualization of solution on the n-th time level sprintf(title, "Temperature, time level %d", n); //view.set_min_max_range(0,100); view.set_title(title); //view.show(&Titer); // to see reference solution view.show(&sln_fine); // to see the solution // visualization of mesh on the n-th time level sprintf(title, "hp-mesh, time level %d", n); ordview.set_title(title); ordview.show(&space); // to see hp-mesh //view.wait_for_keypress(); // if err_est too large, adapt the mesh if (err_est < SPACE_H1_TOL) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } // time measurement cpu += end_time(); } while (!done); // add entry to both time and DOF error graphs graph_err.add_values(0, n, err_est); graph_err.save("error.txt"); graph_dofs.add_values(0, n, space.get_num_dofs()); graph_dofs.save("dofs.txt"); // copying result of the Newton's iteration into Tprev Tprev.copy(&Titer); } // time measurement cpu += end_time(); verbose("Total running time: %g sec", cpu); // wait for keyboard or mouse input View::wait("Waiting for keyboard or mouse input."); return 0; }
int main(int argc, char* argv[]) { // load the mesh Mesh mesh; H2DReader mloader; mloader.load("motor.mesh", &mesh); // initialize the shapeset and the cache H1Shapeset shapeset; PrecalcShapeset pss(&shapeset); // create finite element space H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_bc_values(bc_values); space.set_uniform_order(P_INIT); // enumerate basis functions space.assign_dofs(); // initialize the weak formulation WeakForm wf(1); wf.add_biform(0, 0, callback(biform1), SYM, 1); wf.add_biform(0, 0, callback(biform2), SYM, 2); // visualize solution, gradient, and mesh ScalarView sview("Coarse solution", 0, 0, 600, 1000); VectorView gview("Gradient", 610, 0, 600, 1000); OrderView oview("Polynomial orders", 1220, 0, 600, 1000); //gview.set_min_max_range(0.0, 400.0); // matrix solver UmfpackSolver solver; // DOF and CPU convergence graphs SimpleGraph graph_dof, graph_cpu; // adaptivity loop int it = 1, ndofs; bool done = false; double cpu = 0.0; Solution sln_coarse, sln_fine; do { info("\n---- Adaptivity step %d ---------------------------------------------\n", it++); // time measurement begin_time(); // solve the coarse mesh problem LinSystem ls(&wf, &solver); ls.set_spaces(1, &space); ls.set_pss(1, &pss); ls.assemble(); ls.solve(1, &sln_coarse); // time measurement cpu += end_time(); // view the solution -- this can be slow; for illustration only sview.show(&sln_coarse); gview.show(&sln_coarse, &sln_coarse, EPS_NORMAL, FN_DX_0, FN_DY_0); oview.show(&space); // time measurement begin_time(); // solve the fine mesh problem RefSystem rs(&ls); rs.assemble(); rs.solve(1, &sln_fine); // calculate element errors and total error estimate H1OrthoHP hp(1, &space); double err_est = hp.calc_error(&sln_coarse, &sln_fine) * 100; info("Error estimate: %g%%", err_est); // time measurement cpu += end_time(); // add entry to DOF convergence graph graph_dof.add_values(space.get_num_dofs(), err_est); graph_dof.save("conv_dof.dat"); // add entry to CPU convergence graph graph_cpu.add_values(cpu, err_est); graph_cpu.save("conv_cpu.dat"); // if err_est too large, adapt the mesh if (err_est < ERR_STOP) done = true; else { hp.adapt(THRESHOLD, STRATEGY, ADAPT_TYPE, ISO_ONLY, MESH_REGULARITY); ndofs = space.assign_dofs(); if (ndofs >= NDOF_STOP) done = true; } } while (done == false); verbose("Total running time: %g sec", cpu); // show the fine solution - this is the final result sview.set_title("Final solution"); sview.show(&sln_fine); gview.show(&sln_fine, &sln_fine, EPS_HIGH, FN_DX_0, FN_DY_0); // wait for all views to be closed View::wait(); return 0; }