예제 #1
0
파일: main.cpp 프로젝트: CCJY/coliru
int main ()  { 
    std::cout << computeK(std::integral_constant<int,1>(), 3.5) << ' ' << computeK(1, 3.5);
    return 0;
}    
예제 #2
0
//------------------------------------------------------------------------------
void PD_LPS_porosity_adrmc::evaluateStatic(int id, int i) {
  if (m_data(i, m_indexUnbreakable) >= 1)
    return;
#if CALCULATE_NUMMERICAL_PRINCIPAL_STRESS
  arma::vec eigval(m_dim);
#endif
  vector<pair<int, vector<double>>> &PDconnections =
      m_particles.pdConnections(id);
  const double shearCrit = m_C0 - m_ks * m_T;
  //    const double s_crit = 3.*m_T/40.e9;

  bool broken = false;
  if (m_dim == 2) {
    for (auto &con : PDconnections) {
      const int id_j = con.first;
      const int j = m_idToCol_v[id_j];

      if (m_data(j, m_indexUnbreakable) >= 1)
        continue;

      if (con.second[m_indexConnected] <= 0.5)
        continue;

      //            const double s = con.second[m_iStretch];

      const double sx = 0.5 * (m_data(i, m_indexStress[0]) + m_data(j, m_indexStress[0]));
      const double sy = 0.5 * (m_data(i, m_indexStress[1]) + m_data(j, m_indexStress[1]));
      const double sxy = 0.5 * (m_data(i, m_indexStress[2]) + m_data(j, m_indexStress[2]));

      const double first = 0.5 * (sx + sy);
      const double second = sqrt(0.25 * (sx - sy) * (sx - sy) + sxy * sxy);

      const double p_1 = first + second; // max
      const double p_2 = first - second; // min
#if USE_PRINCIPAL_STRESS
      const int criticalShear = p_2 <= m_C0 - m_ks * p_1;
#else
      const double shear_max = 0.5 * (p_1 - p_2);
      const double shear = shear_max * m_cos_theta;
      const double normal = 0.5 * (p_1 + p_2) + shear_max * m_sin_theta;
      const double criticalShear = shear > m_S0 - m_d * normal;
//            const double criticalShear = shear + m_d*normal - m_S0;
//            const double criticalTensile = p_1 - m_T;
#endif
      const int MC_valid = p_2 < shearCrit;
      const int criticalTensile = p_1 >= m_T;
      //            const int criticalTensile = s >= s_crit;

      if (MC_valid) {
        if (criticalShear) {
          m_data(i, m_indexBrokenNow) = 1;
          con.second[m_indexConnected] = 0;
          m_continueState = true;
          broken = true;
          //                    cout << "Shear\t " << id << " - " << id_j <<
          //                    "\tp1:" << p_1 << ", " << p_2 << endl;
        }
      }
      //            } else {
      //            }
      if (criticalTensile) {
        m_data(i, m_indexBrokenNow) = 1;
        con.second[m_indexConnected] = 0;
        m_continueState = true;
        broken = true;
        //                cout << "Tensile\t " << id << " - " << id_j <<
        //                "\tp1:" << p_1 << ", " << p_2 << endl;
      }
    }
  } else if (m_dim == 3) {
    arma::mat S(m_dim, m_dim);

    for (auto &con : PDconnections) {
      const int id_j = con.first;
      const int j = m_idToCol_v[id_j];

      if (m_data(j, m_indexUnbreakable) >= 1)
        continue;

      if (con.second[m_indexConnected] <= 0.5)
        continue;

      S(0, 0) = 0.5 * (m_data(i, m_indexStress[0]) + m_data(j, m_indexStress[0]));
      S(1, 1) = 0.5 * (m_data(i, m_indexStress[1]) + m_data(j, m_indexStress[1]));
      S(0, 1) = 0.5 * (m_data(i, m_indexStress[2]) + m_data(j, m_indexStress[2]));
      S(1, 0) = S(0, 1);
      S(2, 2) = 0.5 * (m_data(i, m_indexStress[3]) + m_data(j, m_indexStress[3]));
      S(0, 2) = 0.5 * (m_data(i, m_indexStress[4]) + m_data(j, m_indexStress[4]));
      S(2, 0) = S(0, 2);
      S(1, 2) = 0.5 * (m_data(i, m_indexStress[5]) + m_data(j, m_indexStress[5]));
      S(2, 1) = S(1, 2);

#if CALCULATE_NUMMERICAL_PRINCIPAL_STRESS
      arma::eig_sym(eigval, S);
      const double p_1 = eigval(2);
      const double p_2 = eigval(0);
#else
      const double I1 = S(0, 0) + S(1, 1) + S(2, 2);
      const double I2 = S(0, 0) * S(1, 1) + S(1, 1) * S(2, 2) +
                        S(3, 3) * S(0, 0) - pow(S(0, 1), 2) - pow(S(1, 2), 2) -
                        pow(S(0, 2), 2);
      const double I3 = S(0, 0) * S(1, 1) * S(2, 2) -
                        S(0, 0) * pow(S(1, 2), 2) - S(1, 1) * pow(S(0, 2), 2) -
                        S(2, 2) * pow(S(0, 1), 2) +
                        2 * S(0, 1) * S(1, 2) * S(0, 2);
      const double phi =
          1. / 3. * acos(0.5 * (2 * pow(I1, 3) - 9 * I1 * I2 + 27 * I3) /
                         pow(pow(I1, 2) - 3 * I2, 1.5));

      const double core = 2. / 3. * (sqrt(I1 * I1 - 3 * I2));
      const double s1 = I1 / 3. + core * cos(phi);
      const double s2 = I1 / 3. + core * cos(phi - 2. * M_PI / 3.);
      const double s3 = I1 / 3. + core * cos(phi - 4. * M_PI / 3.);

      double p_1 = s1;
      double p_2 = s2;

      if (s2 > p_1) {
        p_1 = s2;
        p_2 = s1;
      }
      if (s3 > p_1) {
        p_1 = s3;
      }

      if (p_2 < s3) {
        p_2 = s3;
      }
#endif
      const int criticalShear = p_2 <= m_C0 - m_ks * p_1;
      const int MC_valid = p_2 < shearCrit;
      const int criticalTensile = p_1 >= m_T;

      if (MC_valid) {
        if (criticalShear) {
          m_data(i, m_indexBrokenNow) = 1;
          con.second[m_indexConnected] = 0;
          broken = true;
        }
      } else {
        if (criticalTensile) {
          m_data(i, m_indexBrokenNow) = 1;
          con.second[m_indexConnected] = 0;
          broken = true;
        }
      }
    }
  }

  if (broken) {
    updateWeightedVolume(id, i);
    computeK(id, i);
    m_data(i, m_indexBrokenNow) = 0;
  }
}