Commit 8f560a8a by Matthieu Schaller

### Re-arranged the time-step sequence. Still some debugging checks in place.

parent 26129ed0
 ... ... @@ -91,6 +91,9 @@ for i in range(402): E_tot_snap[i] = E_kin_snap[i] + E_pot_snap[i] Lz_snap[i] = np.sum(Lz) print "Starting energy:", E_kin_stats[0], E_pot_stats[0], E_tot_stats[0] print "Ending energy:", E_kin_stats[-1], E_pot_stats[-1], E_tot_stats[-1] # Plot energy evolution figure() plot(time_stats, E_kin_stats, "r-", lw=0.5, label="Kinetic energy") ... ...
 ... ... @@ -6,6 +6,9 @@ InternalUnitSystem: UnitCurrent_in_cgs: 1 # Amperes UnitTemp_in_cgs: 1 # Kelvin #Scheduler: # max_top_level_cells: 20 # Parameters governing the time integration TimeIntegration: time_begin: 0. # The starting time of the simulation (in internal units). ... ... @@ -42,5 +45,5 @@ PointMassPotential: position_y: 50. position_z: 50. mass: 1e10 # mass of external point mass in internal units timestep_mult: 0.03 # controls time step timestep_mult: 0.001 # controls time step
 ... ... @@ -96,6 +96,10 @@ grp1 = file.create_group("/PartType1") #generate particle positions radius = max_radius * (numpy.random.rand(numPart))**(1./3.) #radius = numpy.zeros(3) #radius[0] = 8. #radius[1] = 10. #radius[2] = 20. print '---------------------' print 'Radius: minimum = ',min(radius) print 'Radius: maximum = ',max(radius) ... ...
 ... ... @@ -50,8 +50,10 @@ __attribute__((always_inline)) INLINE static int cell_is_drifted( return (c->ti_old == e->ti_current); } /* Are cells / particles active for regular tasks ? */ /** * @brief Does a cell contain any active particle ? * @brief Does a cell contain any particle finishing their time-step now ? * * @param c The #cell. * @param e The #engine containing information about the current time. ... ... @@ -73,7 +75,7 @@ __attribute__((always_inline)) INLINE static int cell_is_active( } /** * @brief Are *all* particles in a cell active ? * @brief Are *all* particles in a cell finishing their time-step now ? * * @param c The #cell. * @param e The #engine containing information about the current time. ... ... @@ -94,7 +96,7 @@ __attribute__((always_inline)) INLINE static int cell_is_all_active( } /** * @brief Is this particle active ? * @brief Is this particle finishing its time-step now ? * * @param p The #part. * @param e The #engine containing information about the current time. ... ... @@ -118,7 +120,7 @@ __attribute__((always_inline)) INLINE static int part_is_active( } /** * @brief Is this g-particle active ? * @brief Is this g-particle finishing its time-step now ? * * @param gp The #gpart. * @param e The #engine containing information about the current time. ... ... @@ -141,4 +143,78 @@ __attribute__((always_inline)) INLINE static int gpart_is_active( return (ti_end == ti_current); } /* Are cells / particles active for kick1 tasks ? */ /** * @brief Does a cell contain any particle starting their time-step now ? * * @param c The #cell. * @param e The #engine containing information about the current time. * @return 1 if the #cell contains at least an active particle, 0 otherwise. */ __attribute__((always_inline)) INLINE static int cell_is_starting( const struct cell *c, const struct engine *e) { #ifdef SWIFT_DEBUG_CHECKS if (c->ti_beg_max > e->ti_current) error( "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and " "e->ti_current=%lld (t=%e)", c->ti_beg_max, c->ti_beg_max * e->timeBase, e->ti_current, e->ti_current * e->timeBase); #endif return (c->ti_beg_max == e->ti_current); } /** * @brief Is this particle starting its time-step now ? * * @param p The #part. * @param e The #engine containing information about the current time. * @return 1 if the #part is active, 0 otherwise. */ __attribute__((always_inline)) INLINE static int part_is_starting( const struct part *p, const struct engine *e) { const integertime_t ti_current = e->ti_current; const integertime_t ti_beg = get_integer_time_begin(ti_current+1, p->time_bin); #ifdef SWIFT_DEBUG_CHECKS if (ti_beg > ti_current) error( "particle in an impossible time-zone! p->ti_beg=%lld " "e->ti_current=%lld", ti_beg, ti_current); #endif return (ti_beg == ti_current); } /** * @brief Is this g-particle starting its time-step now ? * * @param gp The #gpart. * @param e The #engine containing information about the current time. * @return 1 if the #gpart is active, 0 otherwise. */ __attribute__((always_inline)) INLINE static int gpart_is_starting( const struct gpart *gp, const struct engine *e) { const integertime_t ti_current = e->ti_current; const integertime_t ti_beg = get_integer_time_begin(ti_current+1, gp->time_bin); #ifdef SWIFT_DEBUG_CHECKS if (ti_beg > ti_current) error( "g-particle in an impossible time-zone! gp->ti_beg=%lld " "e->ti_current=%lld", ti_beg, ti_current); #endif return (ti_beg == ti_current); } #endif /* SWIFT_ACTIVE_H */
 ... ... @@ -60,6 +60,8 @@ #include "space.h" #include "timers.h" int counter = 0; /* Global variables. */ int cell_next_tag = 0; ... ... @@ -1074,6 +1076,9 @@ void cell_drift(struct cell *c, const struct engine *e) { const double dt = (ti_current - ti_old) * timeBase; float dx_max = 0.f, dx2_max = 0.f, h_max = 0.f; /* if (c->gcount > 0) */ /* message("dt=%e, ti_old=%lld ti_current=%lld", dt, c->ti_old, e->ti_current); */ /* Check that we are actually going to move forward. */ if (ti_current < ti_old) error("Attempt to drift to the past"); ... ... @@ -1101,6 +1106,16 @@ void cell_drift(struct cell *c, const struct engine *e) { /* Drift... */ drift_gpart(gp, dt, timeBase, ti_old, ti_current); #ifdef ICHECK if (gp->id_or_neg_offset == ICHECK) { message("--- ti_current=%lld time=%e dt=%e---", e->ti_current, e->time, dt); counter++; message("Drift counter: %d", counter); printgParticle_single(gp); } #endif /* Compute (square of) motion since last cell construction */ const float dx2 = gp->x_diff[0] * gp->x_diff[0] + gp->x_diff[1] * gp->x_diff[1] + ... ...
 ... ... @@ -74,7 +74,7 @@ struct pcell { /* Stats on this cell's particles. */ double h_max; integertime_t ti_end_min, ti_end_max, ti_old; integertime_t ti_end_min, ti_end_max, ti_beg_max, ti_old; /* Number of particles in this cell. */ int count, gcount; ... ... @@ -224,6 +224,9 @@ struct cell { /*! Maximum end of (integer) time step in this cell. */ integertime_t ti_end_max; /*! Maximum beginning of (integer) time step in this cell. */ integertime_t ti_beg_max; /*! Last (integer) time the cell's content was drifted forward in time. */ integertime_t ti_old; ... ...
 ... ... @@ -20,6 +20,8 @@ #ifndef SWIFT_CONST_H #define SWIFT_CONST_H #include /* SPH Viscosity constants. */ #define const_viscosity_alpha 0.8f #define const_viscosity_alpha_min \ ... ... @@ -59,4 +61,9 @@ #define SOURCETERMS_NONE //#define SOURCETERMS_SN_FEEDBACK #define ICHECK 0 #define num_files 4 extern FILE* files_timestep[num_files]; #endif /* SWIFT_CONST_H */
 ... ... @@ -39,8 +39,23 @@ * @param ti_current Integer end of time-step */ __attribute__((always_inline)) INLINE static void drift_gpart( struct gpart *restrict gp, float dt, double timeBase, integertime_t ti_old, struct gpart *restrict gp, double dt, double timeBase, integertime_t ti_old, integertime_t ti_current) { #ifdef SWIFT_DEBUG_CHECKS if (gp->ti_drift != ti_old) error( "g-particle has not been drifted to the current time " "gp->ti_drift=%lld, " "c->ti_old=%lld, ti_current=%lld", gp->ti_drift, ti_old, ti_current); gp->ti_drift = ti_current; #endif //message("dt= %e", dt); //fprintf(files_timestep[gp->id_or_neg_offset], "drift: dt=%e\n", dt); /* Drift... */ gp->x[0] += gp->v_full[0] * dt; gp->x[1] += gp->v_full[1] * dt; ... ... @@ -63,7 +78,7 @@ __attribute__((always_inline)) INLINE static void drift_gpart( * @param ti_current Integer end of time-step */ __attribute__((always_inline)) INLINE static void drift_part( struct part *restrict p, struct xpart *restrict xp, float dt, struct part *restrict p, struct xpart *restrict xp, double dt, double timeBase, integertime_t ti_old, integertime_t ti_current) { #ifdef SWIFT_DEBUG_CHECKS ... ...