Ejemplo n.º 1
0
// returns infinite norm between analytic results and that in given cells
double get_norm(
	const std::vector<uint64_t>& cell_ids,
	const Grid& grid,
	MPI_Comm& comm
) {
	double
		density_local = 0,
		density_global = 0;
	for (const auto& cell_id: cell_ids) {
		const auto* const cell_data = grid[cell_id];
		if (cell_data == nullptr) {
			std::cerr << __FILE__ << "(" << __LINE__ << ")" << std::endl;
			abort();
		}
		density_local += (*cell_data)[Mass_Density()];
	}
	if (
		MPI_Allreduce(
			&density_local,
			&density_global,
			1,
			MPI_DOUBLE,
			MPI_SUM,
			comm
		) != MPI_SUCCESS
	) {
		std::cerr << __FILE__ << ":" << __LINE__
			<< ": Couldn't set reduce norm."
			<< std::endl;
		abort();
	}

	size_t
		cells_local = cell_ids.size(),
		cells_global = 0;
	if (
		MPI_Allreduce(
			&cells_local,
			&cells_global,
			1,
			MPI_UINT64_T,
			MPI_SUM,
			comm
		) != MPI_SUCCESS
	) {
		std::cerr << __FILE__ << ":" << __LINE__
			<< ": Couldn't set reduce norm."
			<< std::endl;
		abort();
	}

	density_global /= cells_global;

	return std::fabs(density_global - mass_density());
}
Ejemplo n.º 2
0
/*
Creates evenly spaced particles in given cells.
*/
void create_particles(
	const size_t values_per_cell,
	const std::vector<uint64_t>& cell_ids,
	Grid& grid
) {
	const pamhd::particle::Velocity Vel{};
	const pamhd::particle::Position Pos{};

	std::mt19937_64 random_source;
	for (const auto& cell_id: cell_ids) {
		random_source.seed(cell_id);

		const auto
			cell_min = grid.geometry.get_min(cell_id),
			cell_max = grid.geometry.get_max(cell_id),
			cell_length = grid.geometry.get_length(cell_id);
		const auto volume = cell_length[0] * cell_length[1] * cell_length[2];

		auto* const cell_data = grid[cell_id];
		if (cell_data == nullptr) {
			std::cerr << __FILE__ << "(" << __LINE__ << ")" << std::endl;
			abort();
		}

		std::uniform_real_distribution<>
			position_generator_x(cell_min[0], cell_max[0]),
			position_generator_y(cell_min[1], cell_max[1]),
			position_generator_z(cell_min[2], cell_max[2]);

		for (size_t i = 0; i < values_per_cell; i++) {
			pamhd::particle::Particle_Internal new_particle;
			new_particle[Vel][0] =
			new_particle[Vel][1] =
			new_particle[Vel][2] =
			new_particle[pamhd::particle::Charge_Mass_Ratio()] = 0;

			new_particle[Pos][0] = position_generator_x(random_source);
			new_particle[Pos][1] = position_generator_y(random_source);
			new_particle[Pos][2] = position_generator_z(random_source);

			new_particle[pamhd::particle::Mass()]
				= mass_density() * volume / values_per_cell;

			(*cell_data)[pamhd::particle::Particles_Internal()].push_back(new_particle);
		}
	}
}
Ejemplo n.º 3
0
int hpx_main()
{
    std::vector<double> large(64);

    auto zip_it_begin = hpx::util::make_zip_iterator(large.begin());
    auto zip_it_end = hpx::util::make_zip_iterator(large.end());

    hpx::parallel::for_each(
        hpx::parallel::datapar_execution, zip_it_begin, zip_it_end,
        [](auto t)
        {
            using comp_type = typename hpx::util::tuple_element<0, decltype(t)>::type;
            using var_type = typename hpx::util::decay<comp_type>::type;

            var_type mass_density = 0.0;
            mass_density(mass_density > 0.0) = 7.0;

            HPX_TEST(all_of(mass_density == 0.0));
        });

    return hpx::finalize();    // Handles HPX shutdown
}