Skip to content

Commit

Permalink
Shortening the lines to fix flagged content.
Browse files Browse the repository at this point in the history
(includes a minor endline_whitespace_check.hpp fix.
  • Loading branch information
Bcorde5 committed Jul 29, 2015
1 parent 0a9c866 commit 46c34da
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
104 changes: 76 additions & 28 deletions examples/1d_hydro/1d_hydro_upwind.cpp
Expand Up @@ -92,14 +92,15 @@ struct cell{
//
// cell c1, c2;
// c1 = c2; // invoked by this syntax
// Bryce: I think i'd like to change this so the "calculated" is not copied in the assignment op
// Bryce: I think i'd like to change this so the "calculated"
// is not copied in the assignment op
cell& operator=(
cell const& other
)
{
// first, we lock both the mutex of this cell, and the mutex of the other
// cell
// boost::lock_guard<hpx::lcos::local::mutex> this_lock(mtx), other_lock(other.mtx);
// boost::lock_guard<hpx::lcos::local::mutex> this_lock(mtx), other_lock(other.mtx);

rho = other.rho;
mom = other.mom;
Expand Down Expand Up @@ -177,7 +178,8 @@ struct time_element{


// Object to store the Fluid seperated in cell and computed by a Time Zone of tie Steps
// Will store the 2d grid created by the division of the fluid into cells and the computation over time
// Will store the 2d grid created by the division
// of the fluid into cells and the computation over time
// Will be able to Retrieve,remove,add a timestep to the grid

class One_Dimension_Grid
Expand All @@ -190,7 +192,8 @@ class One_Dimension_Grid
void addNewTimeStep();

public:
std::vector<time_element> time_array;//pointer to the Grid we will create whden the user starts a simulation
std::vector<time_element> time_array;
//pointer to the Grid we will create whden the user starts a simulation

};
void One_Dimension_Grid::remove_bottom_time_step()
Expand Down Expand Up @@ -245,8 +248,11 @@ double timestep_size(boost::uint64_t timestep)
grid.time_array.at(timestep).computed = true;
grid.time_array.at(timestep).dt = dx*0.033;// this should be fine unless
// the initial conditions are changed
if(timestep>0&&grid.time_array.at(timestep-1).computed)
grid.time_array[timestep].physics_time = (grid.time_array.at(timestep-1).physics_time+grid.time_array.at(timestep).dt);
if (timestep > 0 && grid.time_array.at(timestep - 1).computed)
{
double t = grid.time_array.at(timestep - 1).physics_time;
grid.time_array[timestep].physics_time = (t + grid.time_array.at(timestep).dt);
}
// time_array[timestep].dt = cfl_predict_factor*dt_cfl;
else if(timestep==0)
{
Expand All @@ -258,11 +264,17 @@ double timestep_size(boost::uint64_t timestep)
// send back the compute futures for the whole grid
// n_predict timesteps previous to the one we want to decide
// the timestep for
// cout << (boost::format("pushing back futures for ts calc, ts=%1% \n") % timestep) << flush;
// cout <<
// (boost::format("pushing back futures for ts calc, ts=%1% \n") % timestep)
// << flush;
if(timestep>=n_predict)
{
for (boost::uint64_t i=0;i<nx;i++)
grid.time_array.at(timestep).fluid_future.push_back(async<compute_action>(here,timestep-n_predict,i));
for (boost::uint64_t i = 0; i < nx; i++)
{
hpx::lcos::shared_future<cell> temp;
temp = async<compute_action>(here, timestep - n_predict, i)
grid.time_array.at(timestep).fluid_future.push_back(temp);
}
}

double dt_cfl = 1000.0;
Expand Down Expand Up @@ -324,26 +336,35 @@ double timestep_size(boost::uint64_t timestep)
,
1.25*grid.time_array.at(timestep-1).dt);

// cout << (boost::format("timestep = %1%, dt = %2%\n") % timestep % time_array[timestep].dt) << flush;
// cout <<
// (boost::format("timestep = %1%, dt = %2%\n") % timestep % time_array[timestep].dt)
// << flush;
return grid.time_array[timestep].dt;
}

cell compute(boost::uint64_t timestep, boost::uint64_t location)
{
boost::lock_guard<hpx::lcos::local::mutex> l(grid.time_array.at(timestep).fluid.at(location).mtx);
mutable temp = grid.time_array.at(timestep).fluid.at(location).mtx;
boost::lock_guard<hpx::lcos::local::mutex> l(temp);

// if it is already computed then just return the value
if (grid.time_array.at(timestep).fluid.at(location).computed == true)
return grid.time_array.at(timestep).fluid.at(location);

// cout << (boost::format("computing new value, loc = %1%,ts=%2% \n") % location % timestep) << flush;
// cout <<
// (boost::format("computing new value, loc = %1%,ts=%2% \n") % location % timestep)
// << flush;

//initial values
if (timestep == 0)
{
// cout << (boost::format("calling initial_sod, loc = %1%,ts=%2% \n") % location % timestep) << flush;
// cout <<
// (boost::format("calling initial_sod, loc = %1%,ts=%2% \n") % location % timestep)
// << flush;
grid.time_array.at(timestep).fluid.at(location) = initial_sod(location);
// cout << (boost::format("returning value, loc = %1%,ts=%2% \n") % location % timestep) << flush;
// cout <<
// (boost::format("returning value, loc = %1%,ts=%2% \n") % location % timestep)
// << flush;
grid.time_array.at(timestep).fluid.at(location).computed = true;
return grid.time_array.at(timestep).fluid.at(location);
}
Expand Down Expand Up @@ -459,11 +480,14 @@ cell compute(boost::uint64_t timestep, boost::uint64_t location)
//cout << (boost::format("gas is shocking!\n")) << flush;
now.tau = pow(e_internal,(1.0/fluid_gamma));
}
// cout << (boost::format("computing new value, loc = %1%, ts= %2%\n") % location % timestep) << flush;
// cout <<
// (boost::format("computing new value, loc = %1%, ts= %2%\n") % location % timestep)
// << flush;
// cout << (boost::format("loc = %1%, rho = %2%\n") % location % left.rho) << flush;
// cout << (boost::format("loc = %1%, mom = %2%\n") % location % left.mom) << flush;
// cout << (boost::format("loc = %1%, etot = %2%\n") % location % left.etot) << flush;
// cout << (boost::format("loc = %1%, vel left = %2%\n") % location % velocity_left) << flush;
// cout << (boost::format("loc = %1%, vel left = %2%\n") % location % velocity_left)
// << flush;

// if (location == 1)
// cout << (boost::format("calculating timestep = %1%\n") % timestep) << flush;
Expand All @@ -473,8 +497,13 @@ cell compute(boost::uint64_t timestep, boost::uint64_t location)
bool time_step_complete= false;
for(boost::uint64_t i=0;i<nx;i++)
{
if(grid.time_array[0].fluid.at(i).computed&&grid.time_array[1].fluid.at(i).computed)
time_step_complete=true;
if (grid.time_array[0].fluid.at(i).computed)
{
if (grid.time_array[1].fluid.at(i).computed)
time_step_complete = true;
else
time_step_complete = false;
}
else
time_step_complete=false;
}
Expand Down Expand Up @@ -535,7 +564,8 @@ cell initial_sod(boost::uint64_t location)
cell_here.tau = pow(e_internal,(1.0/fluid_gamma));
cell_here.etot = e_internal; // ONLY true when mom=0, not in general!

// cout << (boost::format("returning from initial_sod, loc = %1%\n") % location) << flush;
// cout << (boost::format("returning from initial_sod, loc = %1%\n") % location)
// << flush;
return cell_here;
}

Expand All @@ -545,7 +575,8 @@ cell get_analytic(double x_here, double time)

// values for analytic solution come from Patrick Motl's dissertation

// cout << (boost::format("calculating analytic... x=%1% t=%2%\n") % x_here % time) << flush;
// cout << (boost::format("calculating analytic... x=%1% t=%2%\n") % x_here % time)
// << flush;

double x_0 = -0.1;

Expand All @@ -565,7 +596,9 @@ cell get_analytic(double x_here, double time)
double p_4 = 0.3031;
double p_5 = 0.1;

double W = c_5*std::pow( (1.0+(fluid_gamma+1.0)*(p_4 - p_5)/(2.0*fluid_gamma*p_5)), 0.5 );
double div = (2.0*fluid_gamma*p_5)), 0.5 );

double W = c_5*std::pow( (1.0+(fluid_gamma+1.0)*(p_4 - p_5)/div;

double x_shock = x_0 + W*time;

Expand All @@ -579,9 +612,10 @@ cell get_analytic(double x_here, double time)
{
double w_2 = 2.0*(c_1+(x_here-x_0)/time)/(fluid_gamma+1.0);
double exponent = 2.0/(fluid_gamma-1.0);
double dividen = pow(fluid_gamma - 1.0, 1.0 / fluid_gamma);
output.rho = std::pow( (1.0-(fluid_gamma-1.0)*w_2/(2.0*c_1)), exponent);
output.mom = output.rho*w_2;
output.tau = pow( (1.0-0.5*(fluid_gamma-1)*(w_2/c_1)), exponent)/pow(fluid_gamma-1.0,1.0/fluid_gamma);
output.tau = pow( (1.0-0.5*(fluid_gamma-1)*(w_2/c_1)), exponent)/dividen;
}
else if (x_here < x_contact) // region 3
{
Expand Down Expand Up @@ -665,8 +699,13 @@ int hpx_main(
double tauoverrho = pow(e_internal,(1.0/fluid_gamma))/n.rho;
// double e_internal2 = pow(n.tau,fluid_gamma);

outfile << (boost::format("%1% %2% %3% %4% %5%\n") % x_here % n.rho % pressure_here % tauoverrho % velocity_here) << flush; });
// outfile << (boost::format("%1% %2% %3% %4% %5%\n") % x_here % n.rho % pressure_here % e_internal % e_internal2) << flush; });
outfile << (boost::format("%1%") % x_here);
outfile << (boost::format("%2%") % n.rho);
outfile << (boost::format("%3%") % pressure_here);
outfile << (boost::format("%4%") % tauoverrho);
outfile << (boost::format("%5%\n") % velocity_here) << flush;
// outfile << (boost::format("%1% %2% %3% %4% %5%\n") %
//x_here % n.rho % pressure_here % e_internal % e_internal2) << flush; });

outfile.close();

Expand All @@ -676,12 +715,17 @@ int hpx_main(
boost::uint64_t i;
// writing the "time array" to a file
grid.time_array[0].elapsed_time = grid.time_array[0].dt;
for (i=1;i<nt;i++)
grid.time_array[i].elapsed_time = grid.time_array[i-1].elapsed_time + grid.time_array[i].dt;
for (i = 1; i < nt; i++)
{
double temp = grid.time_array[i - 1].elapsed_time + grid.time_array[i].dt;
grid.time_array[i].elapsed_time = temp;
}

for (i =0;i<nt;i++)
{
outfile2 << (boost::format("%1% %2% %3%\n") % i % grid.time_array[i].dt % grid.time_array[i].elapsed_time) << flush;
outfile2 << (boost::format("%1%") % i);
outfile2 << (boost::format("%2%") % grid.time_array[i].dt);
outfile2 << (boost::format("%3%\n") % trid.time_array[i].elapsed_time) << flush;
}
outfile2.close();

Expand All @@ -696,7 +740,11 @@ int hpx_main(
double velocity_here = analytic.mom/analytic.rho;
double tauoverrho = analytic.tau/analytic.rho;
double pressure_here = get_pressure(analytic);
analytic_file << (boost::format("%1% %2% %3% %4% %5%\n") % x_here % analytic.rho % pressure_here % tauoverrho % velocity_here) << flush;
analytic_file << (boost::format("%1%") % x_here);
analytic_file << (boost::format("%2%") % analytic.rho);
analytic_file << (boost::format("%3%") % pressure_here);
analytic_file << (boost::format("%4%") % tauoverrho);
analytic_file << (boost::format("%5%\n") % velocity_here) << flush;
total_mass += grid.time_array[nt-1].fluid[i].rho*dx;
}
analytic_file.close();
Expand Down
5 changes: 4 additions & 1 deletion examples/1d_stencil/1d_stencil_3.cpp
Expand Up @@ -125,7 +125,10 @@ struct stepper
space& next = U[(t + 1) % 2];

for (std::size_t i = 0; i != np; ++i)
next[i] = heat_part(current[idx(i, -1, np)], current[i], current[idx(i, +1, np)]);
{
size_idx temp = idx(i, +1, np);
next[i] = heat_part(current[idx(i, -1, np)], current[i], current[temp]);
}
}

// Return the solution at time-step 'nt'.
Expand Down
7 changes: 5 additions & 2 deletions examples/1d_stencil/1d_stencil_3_omp.cpp
Expand Up @@ -142,8 +142,11 @@ struct stepper
// Visual Studio requires OMP loop variables to be signed :/
# pragma omp for schedule(static)
for (boost::int64_t i = 0; i < (boost::int64_t)np; ++i)
next[i] = heat_part(current[idx(i-1, np)], current[i], current[idx(i+1, np)]);
}
{
size_idx temp = idx(i + 1, np);
next[i] = heat_part(current[idx(i - 1, np)], current[i], current[temp]);
}
}
}
// Return the solution at time-step 'nt'.
return U[nt % 2];
Expand Down
2 changes: 1 addition & 1 deletion tools/inspect/endline_whitespace_check.hpp
Expand Up @@ -22,7 +22,7 @@ namespace boost

whitespace_check();
std::string a = "*Endline Whitespace*";
std::string b = "Unnecessary whitespace at end of file";
std::string b = "Unnecessary whitespace at end of line";
virtual const char * name() const { return a.c_str(); }
virtual const char * desc() const { return b.c_str(); }

Expand Down

0 comments on commit 46c34da

Please sign in to comment.