Example #1
0
void generate_random_value(grnxx::GeoPoint *value) {
  if ((rng() % 256) == 0) {
    *value = grnxx::GeoPoint::na();
  } else {
    grnxx::Float latitude(-90.0 + (180.0 * rng() / rng.max()));
    grnxx::Float longitude(-180.0 + (360.0 * rng() / rng.max()));
    *value = grnxx::GeoPoint(latitude, longitude);
  }
}
Example #2
0
 /**
 *  初期化
 *  @todo:固定シードを与える
 */
 inline void init() {
     std::random_device rng;
     std::array<uint32_t, 16> rng_seed;
     std::generate(rng_seed.begin(), rng_seed.end(), std::ref(rng));
     std::seed_seq rng_seed_seq(rng_seed.begin(), rng_seed.end());
     mt.seed(rng_seed_seq);
 }
Example #3
0
void generate_random_value(grnxx::Float *value) {
  if ((rng() % 256) == 0) {
    *value = grnxx::Float::na();
  } else {
    *value = grnxx::Float(1.0 * rng() / rng.max());
  }
}
Example #4
0
 GlobalBucket(const std::string& hostname, int16_t port, void (*killall)(void))
     //: killall_(killall), joinLock_(false), joinMaster_(false) {
     : killall_(killall), joinLock_(false), joinMaster_(false), debug_(std::cerr) {
     me_.hostname = hostname;
     me_.port     = port;
     randGen_.seed(std::chrono::system_clock::now().time_since_epoch().count());
     pthread_mutex_init(&hostLock_, NULL);
 }
    void set_seed( uint64_t s ) {
      gen.seed(s);

      for(int i = 0; i < table_first_dim; ++i) {
        for( uint64_t j = 0; j < table_second_dim; ++j) {
          table[i][j] = (hash_type) gen();
        }
      }
    }
Example #6
0
namespace Random
{
	std::mt19937_64 generator;
	std::normal_distribution<double> normdist;
	std::uniform_real_distribution<double> uniformDist;
	
	void seed(int i)
	{	generator.seed(i);
	}
	
	double uniform(double start, double end)
	{	return start + (end-start)*uniformDist(generator);
	}

	double normal(double mean, double sigma, double cap)
	{	double r = sigma*normdist(generator);
		if(cap>0.0) while(fabs(r)>cap) r = sigma*normdist(generator); //regenerate till cap is satisfied
		return mean + r;
	}

	complex normalComplex(double sigma)
	{	return sigma * complex(normdist(generator), normdist(generator));
	}
}
Example #7
0
> size_t initialize(
	Init_Cond& init_cond,
	const double simulation_time,
	const std::vector<uint64_t>& cells,
	Grid& grid,
	std::mt19937_64& random_source,
	const double particle_temp_nrj_ratio,
	const unsigned long long int first_particle_id,
	const unsigned long long int particle_id_increase,
	const bool replace,
	const bool verbose
) {
	if (verbose && grid.get_rank() == 0) {
		std::cout << "Setting default particle state... ";
		std::cout.flush();
	}

	size_t nr_particles_created = 0;
	auto current_id_start = first_particle_id;
	for (const auto cell_id: cells) {
		random_source.seed(cell_id);

		const auto
			cell_start = grid.geometry.get_min(cell_id),
			cell_end = grid.geometry.get_max(cell_id),
			cell_length = grid.geometry.get_length(cell_id),
			cell_center = grid.geometry.get_center(cell_id);

		// classify cells for setting non-default initial state
		init_cond.add_cell(
			cell_id,
			cell_start,
			cell_end
		);

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

		// set default state
		const auto
			number_density
				= init_cond.default_data.get_data(
					Number_Density_T(),
					cell_center,
					simulation_time
				),
			temperature
				= init_cond.default_data.get_data(
					Temperature_T(),
					cell_center,
					simulation_time
				),
			charge_mass_ratio
				= init_cond.default_data.get_data(
					Charge_Mass_Ratio_T(),
					cell_center,
					simulation_time
				),
			species_mass
				= init_cond.default_data.get_data(
					Particle_Species_Mass_T(),
					cell_center,
					simulation_time
				);
		const auto bulk_velocity
			= init_cond.default_data.get_data(
				Bulk_Velocity_T(),
				cell_center,
				simulation_time
			);
		const auto nr_particles
			= init_cond.default_data.get_data(
				Nr_Particles_In_Cell_T(),
				cell_center,
				simulation_time
			);

		auto new_particles
			= create_particles<
				Particle,
				Particle_Mass_T,
				Particle_Charge_Mass_Ratio_T,
				Particle_Position_T,
				Particle_Velocity_T,
				Particle_ID_T,
				Particle_Species_Mass_T
			>(
				bulk_velocity,
				Eigen::Vector3d{cell_start[0], cell_start[1], cell_start[2]},
				Eigen::Vector3d{cell_end[0], cell_end[1], cell_end[2]},
				Eigen::Vector3d{temperature, temperature, temperature},
				nr_particles,
				charge_mass_ratio,
				species_mass * number_density * cell_length[0] * cell_length[1] * cell_length[2],
				species_mass,
				particle_temp_nrj_ratio,
				random_source,
				current_id_start,
				particle_id_increase
			);
		nr_particles_created += nr_particles;

		if (replace) {
			(*cell_data)[Particles_T()] = std::move(new_particles);
		} else {
			(*cell_data)[Particles_T()].insert(
				(*cell_data)[Particles_T()].end(),
				new_particles.begin(),
				new_particles.end()
			);
		}

		current_id_start += nr_particles * particle_id_increase;
	}

	// set non-default initial conditions
	if (verbose && grid.get_rank() == 0) {
		std::cout << "done\nSetting non-default initial particle state... ";
		std::cout.flush();
	}
	for (size_t bdy_id = 0; bdy_id < init_cond.get_number_of_boundaries(); bdy_id++) {
		for (const auto& cell_id: init_cond.get_cells(bdy_id)) {
			const auto
				cell_start = grid.geometry.get_min(cell_id),
				cell_end = grid.geometry.get_max(cell_id),
				cell_length = grid.geometry.get_length(cell_id),
				cell_center = grid.geometry.get_center(cell_id);

			const auto
				number_density
					= init_cond.get_data(
						Number_Density_T(),
						bdy_id,
						cell_center,
						simulation_time
					),
				temperature
					= init_cond.get_data(
						Temperature_T(),
						bdy_id,
						cell_center,
						simulation_time
					),
				charge_mass_ratio
					= init_cond.get_data(
						Charge_Mass_Ratio_T(),
						bdy_id,
						cell_center,
						simulation_time
					),
				species_mass
					= init_cond.get_data(
						Particle_Species_Mass_T(),
						bdy_id,
						cell_center,
						simulation_time
					);
			const auto bulk_velocity
				= init_cond.get_data(
					Bulk_Velocity_T(),
					bdy_id,
					cell_center,
					simulation_time
				);
			const auto nr_particles
				= init_cond.get_data(
					Nr_Particles_In_Cell_T(),
					bdy_id,
					cell_center,
					simulation_time
				);

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

			auto new_particles
				= create_particles<
					Particle,
					Particle_Mass_T,
					Particle_Charge_Mass_Ratio_T,
					Particle_Position_T,
					Particle_Velocity_T,
					Particle_ID_T,
					Particle_Species_Mass_T
				>(
					bulk_velocity,
					Eigen::Vector3d{cell_start[0], cell_start[1], cell_start[2]},
					Eigen::Vector3d{cell_end[0], cell_end[1], cell_end[2]},
					Eigen::Vector3d{temperature, temperature, temperature},
					nr_particles,
					charge_mass_ratio,
					species_mass * number_density * cell_length[0] * cell_length[1] * cell_length[2],
					species_mass,
					particle_temp_nrj_ratio,
					random_source,
					current_id_start,
					particle_id_increase
				);
			nr_particles_created += nr_particles;

			if (replace) {
				(*cell_data)[Particles_T()] = std::move(new_particles);
			} else {
				(*cell_data)[Particles_T()].insert(
					(*cell_data)[Particles_T()].end(),
					new_particles.begin(),
					new_particles.end()
				);
			}

			current_id_start += nr_particles * particle_id_increase;
		}
	}
	if (verbose && grid.get_rank() == 0) {
		std::cout << "done" << std::endl;
	}

	return nr_particles_created;
}
Example #8
0
	/**@brief Generator a random nuber between 0 and 1 in the range [0,1)
	 *
	 * @return a double in [0,1)
	 */
	double unifRand() {
		return mtGen_() / (static_cast<double>(mtGen_.max()) + 1);
	}
Example #9
0
	/**@brief seed mtGen_ with the given seed
	 *
	 * @param givenSeed
	 */
	void seedNum(uint64_t givenSeed) {
		currentSeed_ = givenSeed;
		mtGen_.seed(givenSeed);
	}
Example #10
0
void init_random() {
  uint64_t timeSeed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
  std::seed_seq ss = {uint32_t(timeSeed & 0xffffffff), uint32_t(timeSeed>>32)};
  rng.seed(ss);
}
Example #11
0
	void seed(int i)
	{	generator.seed(i);
	}
Example #12
0
void test_scored_subexpression() {
  // Create a database with the default options.
  auto db = grnxx::open_db("");

  // Create a table with the default options.
  auto table = db->create_table("Table");

  constexpr size_t NUM_ROWS = 1 << 16;

  // Generate random values.
  grnxx::Array<grnxx::Float> float_values;
  grnxx::Array<grnxx::Int> ref_values;
  float_values.resize(NUM_ROWS);
  ref_values.resize(NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    float_values[i] = grnxx::Float(1.0 * rng() / rng.max());
//    ref_values[i] = mersenne_twister() % NUM_ROWS;
    ref_values[i] = grnxx::Int(0);
  }

  // Create columns for Float and Int values.
  auto float_column = table->create_column("Float", GRNXX_FLOAT);
  grnxx::ColumnOptions options;
  options.reference_table_name = "Table";
  auto ref_column = table->create_column("Ref", GRNXX_INT, options);

  // Store generated values into columns.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id = table->insert_row();
    assert(row_id.match(grnxx::Int(i)));
    float_column->set(row_id, float_values[i]);
  }
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    ref_column->set(grnxx::Int(i), ref_values[i]);
  }

  // Generate a list of records.
  grnxx::Array<grnxx::Record> records;
  auto cursor = table->create_cursor();
  assert(cursor->read_all(&records) == table->num_rows());

  // Set scores (Float).
  auto builder = grnxx::ExpressionBuilder::create(table);
  builder->push_column("Float");
  auto expression = builder->release();
  expression->adjust(&records);

  // Test an expression (Ref.(_score > 0.5)).
  builder->push_column("Ref");
  builder->begin_subexpression();
  builder->push_score();
  builder->push_constant(grnxx::Float(0.5));
  builder->push_operator(GRNXX_GREATER);
  builder->end_subexpression();
  expression = builder->release();

  expression->filter(&records);
  size_t count = 0;
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    if (float_values[i].raw() > 0.5) {
      assert(records[count].row_id.match(grnxx::Int(i)));
      ++count;
    }
  }
  assert(records.size() == count);
}
Example #13
0
unsigned long myrand_init(unsigned long s) 
{
  standard.seed(s);
  return s;
}
Example #14
0
File: f.cpp Project: xhae/Contests
 // This is equivalent to srand().
 static void seed(uint64_t new_seed = std::mt19937_64::default_seed) {
     rng.seed(new_seed);
 }