bool ZCE_Thread_Condition<ZCE_Thread_Recursive_Mutex>::duration_wait(ZCE_Thread_Recursive_Mutex *external_mutex, const ZCE_Time_Value &relative_time) { ZCE_Time_Value abs_time (ZCE_OS::gettimeofday()); abs_time += relative_time; return systime_wait(external_mutex, abs_time); }
/*------------------------------------------------------------------------*/ void fill_one_event (EVENT *ev, char *buff ) /*------------------------------------------------------------------------*/ { sscanf(&(buff[0]),"%4d", &(ev->yy) ); sscanf(&(buff[5]),"%2d", &(ev->mm) ); sscanf(&(buff[8]),"%2d", &(ev->dd) ); //sscanf(&(buff[11]),"%2d", &(ev->h) ); //sscanf(&(buff[13]),"%2d", &(ev->m) ); //sscanf(&(buff[15]),"%2d", &(ev->s) ); // sscanf(&(buff[20]),"%2d", &(ev->ms) ); //ev->ms = 10.*ev->ms; ev->h = 0; ev->m = 0; ev->ms = 0; printf("ev->yy %d, ev->mm %d,ev->dd %d, ev->h %d, ev->m %d, ev->s %d, ev->ms %d\n", ev->yy, ev->mm, ev->dd, ev->h, ev->m, ev->s, ev->ms); ev->jday = jday( ev->yy, ev->mm, ev->dd ); ev->t0 = abs_time (ev->yy, ev->jday, ev->h, ev->m, ev->s, ev->ms ); sprintf(ev->name,"%d_%d_%d_%d_%d_%d",ev->yy, ev->mm, ev->dd, ev->h, ev->m, ev->s ); printf(" ev->t0 %f\n",ev->t0); system(str); }
int main(int argc, char* argv[]) { // Instantiate a class with global functions. // Choose a Butcher's table or define your own. ButcherTable bt(butcher_table_type); if (bt.is_explicit()) info("Using a %d-stage explicit R-K method.", bt.get_size()); if (bt.is_diagonally_implicit()) info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Turn off adaptive time stepping if R-K method is not embedded. if (bt.is_embedded() == false && ADAPTIVE_TIME_STEP_ON == true) { warn("R-K method not embedded, turning off adaptive time stepping."); ADAPTIVE_TIME_STEP_ON = false; } // Load the mesh. Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("square.mesh", &basemesh); mesh.copy(&basemesh); // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Convert initial condition into a Solution<std::complex<double> >. CustomInitialCondition psi_time_prev(&mesh); // Initialize the weak formulation. double current_time = 0; CustomWeakFormGPRK wf(h, m, g, omega); // Initialize boundary conditions. DefaultEssentialBCConst<std::complex<double> > bc_essential("Bdy", 0.0); EssentialBCs<std::complex<double> > bcs(&bc_essential); // Create an H1 space with default shapeset. H1Space<std::complex<double> > space(&mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); info("ndof = %d", ndof); // Initialize the FE problem. DiscreteProblem<std::complex<double> > dp(&wf, &space); // Create a refinement selector. H1ProjBasedSelector<std::complex<double> > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); // Visualize initial condition. char title[100]; ScalarView sview_real("Initial condition - real part", new WinGeom(0, 0, 600, 500)); ScalarView sview_imag("Initial condition - imaginary part", new WinGeom(610, 0, 600, 500)); sview_real.show_mesh(false); sview_imag.show_mesh(false); sview_real.fix_scale_width(50); sview_imag.fix_scale_width(50); OrderView ord_view("Initial mesh", new WinGeom(445, 0, 440, 350)); ord_view.fix_scale_width(50); ScalarView time_error_view("Temporal error", new WinGeom(0, 400, 440, 350)); time_error_view.fix_scale_width(50); time_error_view.fix_scale_width(60); ScalarView space_error_view("Spatial error", new WinGeom(445, 400, 440, 350)); space_error_view.fix_scale_width(50); RealFilter real(&psi_time_prev); ImagFilter imag(&psi_time_prev); sview_real.show(&real); sview_imag.show(&imag); ord_view.show(&space); // Graph for time step history. SimpleGraph time_step_graph; if (ADAPTIVE_TIME_STEP_ON) info("Time step history will be saved to file time_step_history.dat."); // Time stepping: int num_time_steps = (int)(T_FINAL/time_step + 0.5); for(int ts = 1; ts <= num_time_steps; ts++) // Time stepping loop. double current_time = 0.0; int ts = 1; do { info("Begin time step %d.", ts); // Periodic global derefinement. if (ts > 1 && ts % UNREF_FREQ == 0) { info("Global mesh derefinement."); switch (UNREF_METHOD) { case 1: mesh.copy(&basemesh); space.set_uniform_order(P_INIT); break; case 2: mesh.unrefine_all_elements(); space.set_uniform_order(P_INIT); break; case 3: mesh.unrefine_all_elements(); //space.adjust_element_order(-1, P_INIT); space.adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: error("Wrong global derefinement method."); } ndof = Space<std::complex<double> >::get_num_dofs(&space); } info("ndof: %d", ndof); // Spatial adaptivity loop. Note: psi_time_prev must not be // changed during spatial adaptivity. Solution<std::complex<double> > ref_sln; Solution<std::complex<double> >* time_error_fn; if (bt.is_embedded() == true) time_error_fn = new Solution<std::complex<double> >(&mesh); else time_error_fn = NULL; bool done = false; int as = 1; double err_est; do { // Construct globally refined reference mesh and setup reference space. Space<std::complex<double> >* ref_space = Space<std::complex<double> >::construct_refined_space(&space); // Initialize discrete problem on reference mesh. DiscreteProblem<std::complex<double> >* ref_dp = new DiscreteProblem<std::complex<double> >(&wf, ref_space); RungeKutta<std::complex<double> > runge_kutta(ref_dp, &bt, matrix_solver_type); // Runge-Kutta step on the fine mesh. info("Runge-Kutta time step on fine mesh (t = %g s, time step = %g s, stages: %d).", current_time, time_step, bt.get_size()); bool verbose = true; try { runge_kutta.rk_time_step_newton(current_time, time_step, &psi_time_prev, &ref_sln, time_error_fn, false, false, verbose, NEWTON_TOL_FINE, NEWTON_MAX_ITER); } catch(Exceptions::Exception& e) { e.printMsg(); error("Runge-Kutta time step failed"); } /* If ADAPTIVE_TIME_STEP_ON == true, estimate temporal error. If too large or too small, then adjust it and restart the time step. */ double rel_err_time = 0; if (bt.is_embedded() == true) { info("Calculating temporal error estimate."); // Show temporal error. char title[100]; sprintf(title, "Temporal error est, spatial adaptivity step %d", as); time_error_view.set_title(title); time_error_view.show_mesh(false); RealFilter abs_time(time_error_fn); AbsFilter abs_tef(&abs_time); time_error_view.show(&abs_tef, HERMES_EPS_HIGH); rel_err_time = Global<std::complex<double> >::calc_norm(time_error_fn, HERMES_H1_NORM) / Global<std::complex<double> >::calc_norm(&ref_sln, HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) info("rel_err_time: %g%%", rel_err_time); } if (ADAPTIVE_TIME_STEP_ON) { if (rel_err_time > TIME_ERR_TOL_UPPER) { info("rel_err_time %g%% is above upper limit %g%%", rel_err_time, TIME_ERR_TOL_UPPER); info("Decreasing time step from %g to %g s and restarting time step.", time_step, time_step * TIME_STEP_DEC_RATIO); time_step *= TIME_STEP_DEC_RATIO; delete ref_space; delete ref_dp; continue; } else if (rel_err_time < TIME_ERR_TOL_LOWER) { info("rel_err_time = %g%% is below lower limit %g%%", rel_err_time, TIME_ERR_TOL_LOWER); info("Increasing time step from %g to %g s.", time_step, time_step * TIME_STEP_INC_RATIO); time_step *= TIME_STEP_INC_RATIO; delete ref_space; delete ref_dp; continue; } else { info("rel_err_time = %g%% is in acceptable interval (%g%%, %g%%)", rel_err_time, TIME_ERR_TOL_LOWER, TIME_ERR_TOL_UPPER); } // Add entry to time step history graph. time_step_graph.add_values(current_time, time_step); time_step_graph.save("time_step_history.dat"); } /* Estimate spatial errors and perform mesh refinement */ info("Spatial adaptivity step %d.", as); // Project the fine mesh solution onto the coarse mesh. Solution<std::complex<double> > sln; info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection<std::complex<double> >::project_global(&space, &ref_sln, &sln, matrix_solver_type); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); DiffFilter<std::complex<double> >* space_error_fn = new DiffFilter<std::complex<double> >(Hermes::vector<MeshFunction<std::complex<double> >*>(&ref_sln, &sln)); space_error_view.set_title(title); space_error_view.show_mesh(false); RealFilter abs_space(space_error_fn); AbsFilter abs_sef(&abs_space); space_error_view.show(&abs_sef); // Calculate element errors and spatial error estimate. info("Calculating spatial error estimate."); Adapt<std::complex<double> >* adaptivity = new Adapt<std::complex<double> >(&space); double err_rel_space = adaptivity->calc_err_est(&sln, &ref_sln) * 100; // Report results. info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", Space<std::complex<double> >::get_num_dofs(&space), Space<std::complex<double> >::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh. if (err_rel_space < SPACE_ERR_TOL) done = true; else { info("Adapting the coarse mesh."); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space<std::complex<double> >::get_num_dofs(&space) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. as++; } // Clean up. delete adaptivity; delete ref_space; delete ref_dp; delete space_error_fn; } while (done == false); // Clean up. if (time_error_fn != NULL) delete time_error_fn; // Visualize the solution and mesh. char title[100]; sprintf(title, "Solution - real part, Time %3.2f s", current_time); sview_real.set_title(title); sprintf(title, "Solution - imaginary part, Time %3.2f s", current_time); sview_imag.set_title(title); RealFilter real(&ref_sln); ImagFilter imag(&ref_sln); sview_real.show(&real); sview_imag.show(&imag); sprintf(title, "Mesh, time %g s", current_time); ord_view.set_title(title); ord_view.show(&space); // Copy last reference solution into psi_time_prev. psi_time_prev.copy(&ref_sln); // Increase current time and counter of time steps. current_time += time_step; ts++; } while (current_time < T_FINAL); // Wait for all views to be closed. View::wait(); return 0; }
/*------------------------------------------------------------------------*/ void mk_one_rec (SAC_DB *sdb, int ne, int ns, char *nseed, char *ch, char *DATAROOT) /*------------------------------------------------------------------------*/ { FILE *ff; static char resp_name[150]; char seisname,ch2[4]; char filename[300]; double t1; if ( sdb->rec[ne][ns].n > 0 ) return; sprintf(filename, "%s/%s.%s.SAC", sdb->ev[ne].name, sdb->st[ns].name, ch); if (ch[2]=='Z') sprintf(ch2,"BHZ"); if (ch[2]=='N') sprintf(ch2,"BHN"); if (ch[2]=='E') sprintf(ch2,"BHE"); if ( access(filename,F_OK) != 0) return; printf("filename %s iev %d ista %d\n",filename, ne,ns); if ( !read_sac (filename, sig1, &sd, NPTSMAX) ) { fprintf(stderr,"file %s not found\n", filename ); } printf(" sd.nzyear %d,sd.nzjday %d,sd.nzhour %d ,sd.nzmin %d,sd.nzsec %d,sd.nzmsec %d\n", sd.nzyear, sd.nzjday, sd.nzhour, sd.nzmin, sd.nzsec, sd.nzmsec); t1 = abs_time(sd.nzyear,sd.nzjday,sd.nzhour,sd.nzmin,sd.nzsec,sd.nzmsec); sdb->rec[ne][ns].t0 = t1; sdb->rec[ne][ns].dt = sd.delta; sdb->rec[ne][ns].n = sd.npts; /*---------- response file -----------*/ // sprintf(str,"ls %s/RESP*%s* > list_resp\0", sdb->ev[ne].name, sdb->st[ns].name); //here we change the polezero file to RESP file // sprintf(str,"ls ~/work/noise/northeast/PZs/SAC_%s_%s_PZs > list_resp\0", sdb->st[ns].name,ch2); // sprintf(str,"ls /home/zheng/work/noise/northeast/response_CH/RESP.%s.00.%s > list_resp\0", sdb->st[ns].name,ch2); // sprintf(str,"ls /mtera/weisen/for_yong/response_CH/RESP.%s.00.%s > list_resp\0", sdb->st[ns].name,ch2); sprintf(str,"ls /Users/jiayixie/Tianshan/RESP/RESP.%s.00.%s > list_resp",sdb->st[ns].name,ch2); // sprintf(str,"ls ~/work/noise/northeast/PZs/SAC_%s_%s_PZs > list_resp\0", sdb->st[ns].name,ch); printf("%s\n",str); system(str); ff = fopen("list_resp","r"); if ( fscanf(ff,"%s", resp_name ) == EOF ) { sdb->rec[ne][ns].n = 0; return; sprintf(resp_name,"no_resp"); } fclose(ff); sprintf(sdb->rec[ne][ns].resp_fname,"%s", resp_name); // we set the ft_name in cut_today_throw1.c, so we don;t need to declam it here //sprintf(sdb->rec[ne][ns].ft_name,"%s/%s/%s/%s.%s..%s.%d.%d",DATAROOT,shd1.knetwk,shd1.kstnm,shd1.kstnm,shd1.knetwk,shd1.kcmpnm,shd1.nzyear,shd1.nzjday); sprintf(sdb->rec[ne][ns].fname,"%s/%s.%s.SAC", sdb->ev[ne].name, sdb->st[ns].name, ch); // sprintf(sdb->rec[ne][ns].ft_fname,"%s/ft_%s.%s.SAC\0", sdb->ev[ne].name, sdb->st[ns].name, ch); sprintf(sdb->rec[ne][ns].chan,"%s", ch ); printf("make_one_rec sdb->rec[ne][ns].t0 %f\n",sdb->rec[ne][ns].t0); }
int main(int argc, char* argv[]) { // Choose a Butcher's table or define your own. ButcherTable bt(butcher_table_type); if (bt.is_explicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage explicit R-K method.", bt.get_size()); if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Turn off adaptive time stepping if R-K method is not embedded. if (bt.is_embedded() == false && ADAPTIVE_TIME_STEP_ON == true) { Hermes::Mixins::Loggable::Static::warn("R-K method not embedded, turning off adaptive time stepping."); ADAPTIVE_TIME_STEP_ON = false; } // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", basemesh); mesh->copy(basemesh); // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Convert initial condition into a Solution<complex>. MeshFunctionSharedPtr<complex> psi_time_prev(new CustomInitialCondition(mesh)); // Initialize the weak formulation. double current_time = 0; // Initialize weak formulation. CustomWeakFormGPRK wf(h, m, g, omega); // Initialize boundary conditions. DefaultEssentialBCConst<complex> bc_essential("Bdy", 0.0); EssentialBCs<complex> bcs(&bc_essential); // Create an H1 space with default shapeset. SpaceSharedPtr<complex> space(new H1Space<complex> (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. DiscreteProblem<complex> dp(&wf, space); // Create a refinement selector. H1ProjBasedSelector<complex> selector(CAND_LIST); // Visualize initial condition. char title[100]; ScalarView sview_real("Initial condition - real part", new WinGeom(0, 0, 600, 500)); ScalarView sview_imag("Initial condition - imaginary part", new WinGeom(610, 0, 600, 500)); sview_real.show_mesh(false); sview_imag.show_mesh(false); sview_real.fix_scale_width(50); sview_imag.fix_scale_width(50); OrderView ord_view("Initial mesh", new WinGeom(445, 0, 440, 350)); ord_view.fix_scale_width(50); ScalarView time_error_view("Temporal error", new WinGeom(0, 400, 440, 350)); time_error_view.fix_scale_width(50); time_error_view.fix_scale_width(60); ScalarView space_error_view("Spatial error", new WinGeom(445, 400, 440, 350)); space_error_view.fix_scale_width(50); MeshFunctionSharedPtr<double> real(new RealFilter(psi_time_prev)); MeshFunctionSharedPtr<double> imag(new ImagFilter(psi_time_prev)); sview_real.show(real); sview_imag.show(imag); ord_view.show(space); // Graph for time step history. SimpleGraph time_step_graph; if (ADAPTIVE_TIME_STEP_ON) Hermes::Mixins::Loggable::Static::info("Time step history will be saved to file time_step_history.dat."); // Time stepping: int num_time_steps = (int)(T_FINAL/time_step + 0.5); for(int ts = 1; ts <= num_time_steps; ts++) // Time stepping loop. double current_time = 0.0; int ts = 1; do { Hermes::Mixins::Loggable::Static::info("Begin time step %d.", ts); // Periodic global derefinement. if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { case 1: mesh->copy(basemesh); space->set_uniform_order(P_INIT); break; case 2: space->unrefine_all_mesh_elements(); space->set_uniform_order(P_INIT); break; case 3: space->unrefine_all_mesh_elements(); space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } ndof = Space<complex>::get_num_dofs(space); } Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Spatial adaptivity loop. Note: psi_time_prev must not be // changed during spatial adaptivity. MeshFunctionSharedPtr<complex> ref_sln(new Solution<complex>()); MeshFunctionSharedPtr<complex> time_error_fn(new Solution<complex>); bool done = false; int as = 1; double err_est; do { // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); Space<complex>::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); SpaceSharedPtr<complex> ref_space = refSpaceCreator.create_ref_space(); // Initialize discrete problem on reference mesh. DiscreteProblem<complex>* ref_dp = new DiscreteProblem<complex>(&wf, ref_space); RungeKutta<complex> runge_kutta(&wf, ref_space, &bt); // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, time step = %g s, stages: %d).", current_time, time_step, bt.get_size()); bool verbose = true; try { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL_FINE); runge_kutta.rk_time_step_newton(psi_time_prev, ref_sln, time_error_fn); } catch(Exceptions::Exception& e) { e.print_msg(); throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); } /* If ADAPTIVE_TIME_STEP_ON == true, estimate temporal error. If too large or too small, then adjust it and restart the time step. */ double rel_err_time = 0; if (bt.is_embedded() == true) { Hermes::Mixins::Loggable::Static::info("Calculating temporal error estimate."); // Show temporal error. char title[100]; sprintf(title, "Temporal error est, spatial adaptivity step %d", as); time_error_view.set_title(title); time_error_view.show_mesh(false); MeshFunctionSharedPtr<double> abs_time(new RealFilter(time_error_fn)); MeshFunctionSharedPtr<double> abs_tef(new AbsFilter(abs_time)); time_error_view.show(abs_tef); rel_err_time = Global<complex>::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / Global<complex>::calc_norm(ref_sln.get(), HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } if (ADAPTIVE_TIME_STEP_ON) { if (rel_err_time > TIME_ERR_TOL_UPPER) { Hermes::Mixins::Loggable::Static::info("rel_err_time %g%% is above upper limit %g%%", rel_err_time, TIME_ERR_TOL_UPPER); Hermes::Mixins::Loggable::Static::info("Decreasing time step from %g to %g s and restarting time step.", time_step, time_step * TIME_STEP_DEC_RATIO); time_step *= TIME_STEP_DEC_RATIO; delete ref_dp; continue; } else if (rel_err_time < TIME_ERR_TOL_LOWER) { Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%% is below lower limit %g%%", rel_err_time, TIME_ERR_TOL_LOWER); Hermes::Mixins::Loggable::Static::info("Increasing time step from %g to %g s.", time_step, time_step * TIME_STEP_INC_RATIO); time_step *= TIME_STEP_INC_RATIO; delete ref_dp; continue; } else { Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%% is in acceptable interval (%g%%, %g%%)", rel_err_time, TIME_ERR_TOL_LOWER, TIME_ERR_TOL_UPPER); } // Add entry to time step history graph. time_step_graph.add_values(current_time, time_step); time_step_graph.save("time_step_history.dat"); } /* Estimate spatial errors and perform mesh refinement */ Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); // Project the fine mesh solution onto the coarse mesh. MeshFunctionSharedPtr<complex> sln(new Solution<complex>); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection<complex> ogProjection; ogProjection.project_global(space, ref_sln, sln); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); MeshFunctionSharedPtr<complex> space_error_fn(new DiffFilter<complex>(Hermes::vector<MeshFunctionSharedPtr<complex> >(ref_sln, sln))); space_error_view.set_title(title); space_error_view.show_mesh(false); MeshFunctionSharedPtr<double> abs_space(new RealFilter(space_error_fn)); MeshFunctionSharedPtr<double> abs_sef(new AbsFilter(abs_space)); space_error_view.show(abs_sef); // Calculate element errors and spatial error estimate. Hermes::Mixins::Loggable::Static::info("Calculating spatial error estimate."); Adapt<complex> adaptivity(space); double err_rel_space = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", Space<complex>::get_num_dofs(space), Space<complex>::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh. if (err_rel_space < SPACE_ERR_TOL) done = true; else { Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); done = adaptivity.adapt(&selector); // Increase the counter of performed adaptivity steps. as++; } // Clean up. delete ref_dp; } while (done == false); // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution - real part, Time %3.2f s", current_time); sview_real.set_title(title); sprintf(title, "Solution - imaginary part, Time %3.2f s", current_time); sview_imag.set_title(title); MeshFunctionSharedPtr<double> real(new RealFilter(ref_sln)); MeshFunctionSharedPtr<double> imag(new ImagFilter(ref_sln)); sview_real.show(real); sview_imag.show(imag); sprintf(title, "Mesh, time %g s", current_time); ord_view.set_title(title); ord_view.show(space); // Copy last reference solution into psi_time_prev. psi_time_prev->copy(ref_sln); // Increase current time and counter of time steps. current_time += time_step; ts++; } while (current_time < T_FINAL); // Wait for all views to be closed. View::wait(); return 0; }
int main(int argc, char **argv) { char *s_arch; char *executable; cpu_arch_t arch; cpu_t *cpu; uint8_t *RAM; FILE *f; int ramsize; int r1, r2; uint64_t t1, t2, t3, t4; unsigned start_no = START_NO; int singlestep = SINGLESTEP_NONE; int log = 1; int print_ir = 1; /* parameter parsing */ if (argc < 3) { printf("Usage: %s executable [arch] [itercount] [entries]\n", argv[0]); return 0; } s_arch = argv[1]; executable = argv[2]; if (argc >= 4) start_no = atoi(argv[3]); if (!strcmp("mips", s_arch)) arch = CPU_ARCH_MIPS; else if (!strcmp("m88k", s_arch)) arch = CPU_ARCH_M88K; else if (!strcmp("arm", s_arch)) arch = CPU_ARCH_ARM; else if (!strcmp("fapra", s_arch)) arch = CPU_ARCH_FAPRA; else { printf("unknown architecture '%s'!\n", s_arch); return 0; } ramsize = 5*1024*1024; RAM = (uint8_t*)malloc(ramsize); cpu = cpu_new(arch, 0, 0); cpu_set_flags_codegen(cpu, CPU_CODEGEN_OPTIMIZE); cpu_set_flags_debug(cpu, 0 | (print_ir? CPU_DEBUG_PRINT_IR : 0) | (print_ir? CPU_DEBUG_PRINT_IR_OPTIMIZED : 0) | (log? CPU_DEBUG_LOG :0) | (singlestep == SINGLESTEP_STEP? CPU_DEBUG_SINGLESTEP : 0) | (singlestep == SINGLESTEP_BB? CPU_DEBUG_SINGLESTEP_BB : 0) ); cpu_set_ram(cpu, RAM); /* load code */ if (!(f = fopen(executable, "rb"))) { printf("Could not open %s!\n", executable); return 2; } cpu->code_start = START; cpu->code_end = cpu->code_start + fread(&RAM[cpu->code_start], 1, ramsize-cpu->code_start, f); fclose(f); cpu->code_entry = cpu->code_start + ENTRY; cpu_tag(cpu, cpu->code_entry); cpu_translate(cpu); /* force translation now */ printf("\n*** Executing...\n"); printf("number of iterations: %u\n", start_no); uint32_t *reg_pc, *reg_lr, *reg_param, *reg_result; switch (arch) { case CPU_ARCH_M88K: reg_pc = &((m88k_grf_t*)cpu->rf.grf)->sxip; reg_lr = &((m88k_grf_t*)cpu->rf.grf)->r[1]; reg_param = &((m88k_grf_t*)cpu->rf.grf)->r[2]; reg_result = &((m88k_grf_t*)cpu->rf.grf)->r[2]; break; case CPU_ARCH_MIPS: reg_pc = &((reg_mips32_t*)cpu->rf.grf)->pc; reg_lr = &((reg_mips32_t*)cpu->rf.grf)->r[31]; reg_param = &((reg_mips32_t*)cpu->rf.grf)->r[4]; reg_result = &((reg_mips32_t*)cpu->rf.grf)->r[4]; break; case CPU_ARCH_ARM: reg_pc = &((reg_arm_t*)cpu->rf.grf)->pc; reg_lr = &((reg_arm_t*)cpu->rf.grf)->r[14]; reg_param = &((reg_arm_t*)cpu->rf.grf)->r[0]; reg_result = &((reg_arm_t*)cpu->rf.grf)->r[0]; break; case CPU_ARCH_FAPRA: reg_pc = &((reg_fapra32_t*)cpu->rf.grf)->pc; reg_lr = &((reg_fapra32_t*)cpu->rf.grf)->r[0]; reg_param = &((reg_fapra32_t*)cpu->rf.grf)->r[3]; reg_result = &((reg_fapra32_t*)cpu->rf.grf)->r[3]; break; default: fprintf(stderr, "architecture %u not handled.\n", arch); exit(EXIT_FAILURE); } *reg_pc = cpu->code_entry; *reg_lr = RET_MAGIC; *reg_param = start_no; printf("GUEST run..."); fflush(stdout); t1 = abs_time(); cpu_run(cpu, debug_function); t2 = abs_time(); r1 = *reg_result; printf("done!\n"); printf("HOST run..."); fflush(stdout); t3 = abs_time(); r2 = fib(start_no); t4 = abs_time(); printf("done!\n"); cpu_free(cpu); printf("Time GUEST: %lld\n", t2-t1); printf("Time HOST: %lld\n", t4-t3); printf("Result HOST: %d\n", r2); printf("Result GUEST: %d\n", r1); printf("GUEST required \033[1m%.2f%%\033[22m of HOST time.\n", (float)(t2-t1)/(float)(t4-t3)*100); if (r1 == r2) printf("\033[1mSUCCESS!\033[22m\n\n"); else printf("\033[1mFAILED!\033[22m\n\n"); return 0; }