void AqueousNaClGenerator::addMolecule(double x, double y, double z, unsigned long id, int cid, ParticleContainer* particleContainer) {
	std::cout << "Add molecule at " << x << ", " << y << ", " << z << " with cid=" << cid << endl;

	vector<double> velocity = getRandomVelocity(_temperature);

	//double orientation[4] = {1, 0, 0, 0}; // default: in the xy plane
	// rotate by 30° along the vector (1/1/0), i.e. the angle bisector of x and y axis
	// o = cos 30° + (1 1 0) * sin 15°
	double orientation[4];
	getOrientation(15, 10, orientation);

	double I[3] = {0.,0.,0.};
	I[0] = _components[cid].I11();
	I[1] = _components[cid].I22();
	I[2] = _components[cid].I33();
	/*****  Copied from animake - initialize anular velocity *****/
	double w[3];
	for(int d=0; d < 3; d++) {
		w[d] = (I[d] == 0)? 0.0: ((randdouble(0,1) > 0.5)? 1: -1) *
				sqrt(2.0* randdouble(0,1)* _temperature / I[d]);
		w[d] = w[d] * MDGenerator::fs_2_mardyn;
	}
	/************************** End Copy **************************/

	Molecule m(id, &(_components[cid]), x, y, z, // position
			velocity[0], -velocity[1], velocity[2], // velocity
			orientation[0], orientation[1], orientation[2], orientation[3],
			w[0], w[1], w[2] );
	particleContainer->addParticle(m);
}
void Random::unitDiscSample(double &x, double &y)
{
	// pick a random point in the unit disc with uniform probability by using polar coords.
	// Note the sqrt(). For explanation why it's needed, see
	// http://mathworld.wolfram.com/DiskPointPicking.html
	double angle = randdouble() * 2 * PI;
	double rad = sqrt(randdouble());
	x = sin(angle) * rad;
	y = cos(angle) * rad;
}
Example #3
0
//generates a psuedo-random double between min and max
double randdouble(double min, double max)
{
    if (min>max)
    {
        return randdouble()*(min-max)+max;
    }
    else
    {
        return randdouble()*(max-min)+min;
    }
}
Example #4
0
void OneCLJGenerator::addParticle(int id, double x, double y, double z, ParticleContainer* particleContainer,
        Domain* domain, DomainDecompBase* domainDecomp) {
	vector<Component>& dcomponents = domain->getComponents();
	vector<double> v_;
	v_.resize(3);

	// Velocity
	for (int dim = 0; dim < 3; dim++) {
		v_[dim] = randdouble(-0.5, 0.5);
	}
	double dotprod_v = 0;
	for (unsigned int i = 0; i < v_.size(); i++) {
		dotprod_v += v_[i] * v_[i];
	}
	// Velocity Correction
	double vCorr = sqrt(3.0 * _temperature / dotprod_v);
	for (unsigned int i = 0; i < v_.size(); i++) {
		v_[i] *= vCorr;
	}

	Molecule m1 = Molecule(id, 0, x, y, z, v_[0], v_[1], v_[2], 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &dcomponents);
	particleContainer->addParticle(m1);
	//dcomponents[0].incrnumMolecules();
	//domain->setglobalRotDOF(dcomponents[0].rot_dof()+domain->getglobalRotDOF());
}
/**
 * Tell the Shooting AI whether or not it should fire at the target given the
 * target and where it's aiming.
 * This leads to the AI leading it shots.
 */
bool Blaster::shouldFire(Point3D* target, Point3D* aim) {
   const double maxRefireWaitTime = 1; // seconds
   const double minRefireWaitTime = 0.10; // seconds
   double randNum = randdouble();
   randNum = 1 - (randNum * randNum * randNum); // Weight towards high numbers.
   double randomRefireWaitTime = (randNum * 
    (maxRefireWaitTime - minRefireWaitTime)) + 
    minRefireWaitTime;

   if (ship->gameState->getGameTime() - timeLastFired < randomRefireWaitTime) {
      // Don't fire if we just fired. Not fun when AI fires too fast.
      return false;
   } else if (randdouble() < 0.1) {
      // 10% chance per frame of deciding not to fire.
      return false;
   }
   Vector3D targetToShip = *target - ship->shotOrigin;
   targetToShip.normalize();
   return (targetToShip - *aim).magnitude() < 0.6;
}
void Random::unitSphereSample(double &x, double &y, double &z)
{
    // pick a random point in the unit sphere with uniform probability by using polar coords.
	// http://mathworld.wolfram.com/SpherePointPicking.html
    double v = randdouble();
    double fi = 1 / cos(2 * v - 1);

    double u = cos(fi);
    double tita = 2 * PI * u;

    x = sqrt(1 - u * u) * cos(tita);
    y = sqrt(1 - u * u) * sin(tita);
    z = u;
}
Example #7
0
static ERL_NIF_TERM create_solution(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]){

    // struct timespec start, end;
    // long diff;
    // clock_gettime(CLOCK_MONOTONIC, &start);

    ERL_NIF_TERM term;
    ErlNifResourceType* sol_type;
    Solution* sol;
    unsigned int len;
    unsigned int i;

    CHECK(env, argc == 1)
    CHECK(env, enif_get_uint(env, argv[0], &len))

    sol_type = (ErlNifResourceType*) enif_priv_data(env);
    CHECK(env, sol_type)

    sol = (Solution*) enif_alloc_resource(sol_type, sizeof(Solution));
    CHECK(env, sol)
    
    term = enif_make_resource(env, sol);
    CHECK(env,term)
    enif_release_resource(sol);

    sol->len = len;
    sol->genotype = (double*) malloc(sizeof(double)*len);
    for (i=0;i<len;i++){
        sol->genotype[i] = randdouble(-50.0, 50.0);
    }

    // clock_gettime(CLOCK_MONOTONIC, &end);

    // diff = CLOCKS_PER_SEC * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec;
    // printf("create=%llu\n", (long long unsigned int) diff);


    return term;
}
Example #8
0
//generates a psuedo-random double between 0.0 and max
double randdouble(double max)
{
    return randdouble()*max;
}