Esempio n. 1
0
unsigned Voronoi(CONFIG &config, int ig)
{

    float r  = 0;
    float r0 = 0;
    int   jg = 0;
    Vector3d g; g << 0, 0, 0;
    Vector3d p; p << 0, 0, 0;
    int n = 0;
    time_t  time1, time2;
    time(&time1);

    float dx = 1.5; // light overlap;

    #pragma omp parallel for shared(config, n) private(p, g, jg, r, r0) schedule(dynamic, 1)
    for(int i = 0; i < config.atoms_grain; i++) // check all atoms of this grain
    {
        r = (config.atom_grain[i].r - config.grain[ig].r).norm() - dx; // distance to its center
        for(jg = 0; jg < config.grains; jg++) // compare to the another grain centers
        {
            for(p(0) = -1; p(0) <=1; p(0)++)
            {
                for(p(1) = -1; p(1) <=1; p(1)++)
                {
                    for(p(2) = -1; p(2) <=1; p(2)++)
                    {
                        g = p.array()*config.l.array();
                        r0 = (config.atom_grain[i].r - (config.grain[jg].r + g)).norm(); // distance from orig to other center
                        if (!((ig == jg) && (p.norm()==0))) // exclude selfcheckong
                        if (r > r0) break;
                    }
                    if(p(2)!=2) break;
                }
                if(p(1)!=2) break;
            }
            if(p(0)!=2) break;
        }

        #pragma omp critical
        if (jg==config.grains)
        {
            config.atom_box[config.atoms_box] = config.atom_grain[i];
            config.atoms_box++;
            n++;
        }

    }

    cout << "[" << ig << "] " << n ;
    time(&time2);
    cout << " Done in " << time2-time1 << " s.";
    cout << endl;

    return 0;
}
Esempio n. 2
0
unsigned SortGrig(CONFIG &config)
{
    time_t  time1, time2;
    time(&time1);

    Vector3d Lcell;
    Lcell = config.l / config.grid_size;


    // fill grid with indeces
    Vector3i r;
    int grid_id = 0;
    for(r[0] = 0; r[0] < config.grid_size ; r[0]++)
    {
        for(r[1] = 0; r[1] < config.grid_size ; r[1]++)
        {
            for(r[2] = 0; r[2] < config.grid_size ; r[2]++)
            {
                config.grid[grid_id].r = r;
                grid_id++;
            }
        }
    }

    // fill grid cell with atom indeces
    for(int i=0; i < config.atoms_box; i++)
    {
        // shift coords to positive values and divide by grid cell length
        // Eigen::ceil() appears from v3.3
        Vector3d r_reduced = (config.atom_box[i].r + config.shift).array() / Lcell.array();
        // convert reduced coords to linear array number
        int grid_id = floor(r_reduced[0]) * config.grid_size * config.grid_size + floor(r_reduced[1]) * config.grid_size + floor(r_reduced[2]);
        //cout << grid_id <<" "<< floor(r_reduced[0]) << " " << floor(r_reduced[1]) << " " << floor(r_reduced[2]) << endl;
        config.grid[grid_id].id.push_back(i);
    }

    time(&time2);
    if (config.time) cout << "Done in " << time2-time1 << " s." << endl;

//    int s=0;
//    for(unsigned i=0; i<config.grid.size(); i++)
//    {
//        s+=config.grid[i].id.size();
//        cout << i << " " << config.grid[i].id.size() << endl;
//    }
//    cout << "Size " << s << endl;

    return 0;
}
Esempio n. 3
0
std::pair<Vector3d, Vector3d> C3Trajectory::limit(const Vector3d &vmin, const Vector3d &vmax, const Vector3d &delta)
{
  Vector3d adelta = delta.array().abs();

  double maxtime = 0;
  for (int i = 0; i < 3; i++)
  {
    double time;
    if (delta(i) > 0)
    {
      time = adelta(i) / vmax(i);
    }
    else
    {
      time = adelta(i) / -vmin(i);
    }

    maxtime = max(time, maxtime);
  }

  assert(maxtime > 0);

  Vector3d av_prime = adelta / maxtime;
  Vector3d maxv_prime;
  Vector3d minv_prime;

  for (int i = 0; i < 3; i++)
  {
    if (delta(i) > 0.001)
    {
      maxv_prime(i) = av_prime(i);
      minv_prime(i) = vmin(i);
    }
    else if (delta(i) < -0.001)
    {
      maxv_prime(i) = vmax(i);
      minv_prime(i) = -av_prime(i);
    }
    else
    {
      maxv_prime(i) = 0;
      minv_prime(i) = 0;
    }
  }

  return make_pair(minv_prime, maxv_prime);
}
Esempio n. 4
0
//
// Decomposes the deformation gradient into elastic and plastic portions.
// This method assumes that the gamma values have previously been computed.
//
void
SoftBody::decomposeFs(uint32_t lo, uint32_t hi)
{
    auto f_it = defs.begin() + lo;
    auto p_it = plasticDefs.begin() + lo;
    auto e_it = elasticDefs.begin() + lo;
    auto g_it = gammas.begin() + lo;

    auto end = defs.begin() + hi;

    for (; f_it != end; ++f_it, ++p_it, ++e_it, ++g_it) {
        double det = f_it->singularValues().prod();
        Vector3d fHatStar = f_it->singularValues() / std::fabs(std::cbrt(det));

        *p_it = fHatStar.array().pow(*g_it);
        *e_it = f_it->singularValues().array() / p_it->array();
    }
}