void AAKR::normalize(Math::Matrix& mean, Math::Matrix& std) { // Resize mean and standard deviation variables. mean.resizeAndFill(1, sampleSize(), 0); std.resizeAndFill(1, sampleSize(), 0); // Compute mean. for (unsigned i = 0; i < sampleSize(); i++) mean(i) = sum(m_data.get(0, m_num_values - 1, i, i)) / m_num_values; // Compute standard deviation. for (unsigned j = 0; j < sampleSize(); j++) { double sum = 0; // Sum of the power of two difference // between the value and the mean. for (unsigned i = 0; i < m_num_values; i++) sum += std::pow(m_data(i, j) - mean(j), 2); // Standard deviation. std(j) = std::sqrt(sum / m_num_values); // Normalize each member of the data set. for (unsigned i = 0; i < m_num_values; i++) { if (std(j)) m_norm(i, j) = (m_data(i, j) - mean(j)) / std(j); else m_norm(i, j) = 0; } } }
QVariant ribi::QtUblasVectorDoubleModel::data(const QModelIndex &index, int role) const { //Removing this line will cause checkboxes to appear if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant(); assert(index.isValid()); const int row = index.row(); #ifndef NDEBUG const int col = index.column(); assert(row >= 0); assert(row < this->rowCount()); assert(row < boost::numeric_cast<int>(m_data.size())); assert(col == 0); #endif #ifdef RETURN_DOUBLE_723465978463059835 return m_data(row); #else //Convert to string, otherwise the number digits behind the comma //will be set to 2, e.g. 0.01 const std::string s = boost::lexical_cast<std::string>(m_data(row)); return QString(s.c_str()); #endif }
//------------------------------------------------------------------------------ double PD_OSP::calculateDilationTerm(const std::pair<int, int> &idCol) { const int pId = idCol.first; const int col_i = idCol.second; const double d_i = m_data(col_i, m_indexD); vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double r_i[3]; double r0_i[3]; for(int d=0; d<m_dim; d++) { r_i[d] = m_r(d, col_i); r0_i[d] = m_r0(d, col_i); } const int nConnections = PDconnections.size(); double dr_ij[3]; double theta_i = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_indexConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double d_j = m_data(j, m_indexD); const double vol_j = m_data(j, m_indexVolume); const double dr0 = con.second[m_indexDr0]; const double volumeScaling = con.second[m_indexVolumeScaling]; const double d_ij = 0.5*(d_i + d_j); double dr2 = 0; double A_ij = 0; // The lambda-factor for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - r_i[d]; dr2 += dr_ij[d]*dr_ij[d]; A_ij += dr_ij[d]*(m_r0(d, j) - r0_i[d]); } const double dr = sqrt(dr2); A_ij /= (dr0*dr); double ds = dr - dr0; // To avoid roundoff errors if (fabs(ds) < THRESHOLD) ds = 0.0; const double s = ds/dr0; theta_i += d_ij*s*A_ij*vol_j*volumeScaling; } return m_delta*theta_i; }
//------------------------------------------------------------------------------ double PD_LPS::calculatePotentialEnergyDensity(const std::pair<int, int> &idCol) { const int pId = idCol.first; const int i = idCol.second; const double m_i = m_data(i, m_iMass); vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double r_i[m_dim]; double r0_i[m_dim]; for(int d=0; d<m_dim; d++) { r_i[d] = m_r(d, i); r0_i[d] = m_r0(d, i); } const int nConnections = PDconnections.size(); double dr_ij[m_dim]; double alpha = 0; if(m_dim == 3) alpha = 15*m_mu/m_i; else alpha = 8*m_mu/m_i; double theta_i = this->computeDilation(idCol); double W_i = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; const double volumeScaling = con.second[m_iVolumeScaling]; double dr2 = 0; for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - r_i[d]; dr2 += dr_ij[d]*dr_ij[d]; } const double dr = sqrt(dr2); double ds = dr - dr0; const double extension_term = alpha*(pow(ds - theta_i*dr0/m_dim, 2)); W_i += (extension_term)*vol_j*volumeScaling; } W_i += m_k*(pow(theta_i, 2)); return 0.5* W_i; }
float VolumeSampler::sampleTrilinear(float x, float y, float z) const { if(!inBox(x,y,z)) return 0; // otherwise do trilinear interpolation. float xnf = x*m_data.nx() - 0.5f; float ynf = y*m_data.ny() - 0.5f; float znf = z*m_data.nz() - 0.5f; int xn = int(xnf); int yn = int(ynf); int zn = int(znf); int xnp1 = min(xn+1, m_data.nx()-1); int ynp1 = min(yn+1, m_data.ny()-1); int znp1 = min(zn+1, m_data.nz()-1); float xl = xnf - xn; float yl = ynf - yn; float zl = znf - zn; return lerp(zl, lerp(yl, lerp(xl, m_data(xn,yn,zn), m_data(xnp1,yn,zn)), lerp(xl, m_data(xn,ynp1,zn), m_data(xnp1,ynp1,zn))), lerp(yl, lerp(xl, m_data(xn,yn,znp1), m_data(xnp1,yn,znp1)), lerp(xl, m_data(xn,ynp1,znp1), m_data(xnp1,ynp1,znp1))) ); }
bool CStreamHandler::OnData(int channel, void * data, size_t len) { if (m_data) { m_data(channel, data, len, m_prv); return true; } return false; }
//------------------------------------------------------------------------------ void PD_LPS::calculateMass() { bool analytical = false; // Calculateing the one-body forces #ifdef USE_OPENMP #pragma omp parallel for #endif for(int i=0; i<m_particles.nParticles(); i++) { pair<int, int> id_col(i, i); const int pId = id_col.first; const int col_i = id_col.second; vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); const int nConnections = PDconnections.size(); double m = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double volumeScaling = con.second[m_iVolumeScaling]; const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; m += dr0*dr0*vol_j*volumeScaling; } if(analytical) { if(m_dim == 3) { m = 4.*M_PI/5.*pow(m_delta, 5); }else { m = m_h*M_PI/2.*pow(m_delta, 4); } } m_data(col_i, m_iMass) = m; } }
std::ostream& image<T>::serialize(std::ostream& sout) const { libbase::trace << "Saving image" << std::flush; // header data const int chan = channels(); assert(chan > 0); const int rows = m_data(0).size().rows(); const int cols = m_data(0).size().cols(); libbase::trace << " (" << cols << "x" << rows << "x" << chan << ")..." << std::flush; // write file descriptor if (chan == 1 && m_maxval == 1) sout << "P4" << std::endl; // bitmap else if (chan == 1 && m_maxval > 1) sout << "P5" << std::endl; // graymap else if (chan == 3) sout << "P6" << std::endl; // pixmap else failwith("Image format not supported"); // write comment sout << "# file written by libimage" << std::endl; // write image size sout << cols << " " << rows << std::endl; // if needed, write maxval if (chan > 1 || m_maxval > 1) sout << m_maxval << std::endl; // write image data for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) for (int c = 0; c < chan; c++) { int p; if (typeid(T) == typeid(double) || typeid(T) == typeid(float)) p = int(round(m_data(c)(i, j) * m_maxval)); else p = int(m_data(c)(i, j)); assert(p >= 0 && p <= m_maxval); if (m_maxval > 255) // 16-bit binary files (MSB first) { sout.put(p >> 8); p &= 0xff; } sout.put(p); }
//------------------------------------------------------------------------------ double PD_LPS::computeDilation(const std::pair<int, int> &idCol) { const int pId = idCol.first; const int i = idCol.second; const double m_i = m_data(i, m_iMass); vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); const int nConnections = PDconnections.size(); double dr_ij[m_dim]; double theta_i = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; const double volumeScaling = con.second[m_iVolumeScaling]; double dr2 = 0; for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - m_r(d, i); dr2 += dr_ij[d]*dr_ij[d]; } const double dr = sqrt(dr2); const double ds = dr - dr0; theta_i += dr0*ds*vol_j*volumeScaling; } return theta_i*m_dim/m_i; }
bool ribi::QtUblasVectorDoubleModel::setData(const QModelIndex &index, const QVariant &value, int /* role */) { const int row = index.row(); #ifndef NDEBUG const int col = index.column(); assert(row < boost::numeric_cast<int>(m_data.size())); assert(col == 0); #endif m_data(row) = value.toDouble(); ///This line below is needed to let multiple views synchronize emit dataChanged(index,index); //Editing succeeded! return true; }
void PlotSignalWidget::createPlotPath(QPainterPath& path) { double dValue; QPointF qSamplePosition; //create lines from one to the next sample for(qint32 i=0; i < m_data.cols(); ++i) { dValue = m_data(0,i)*m_dScaleY; qSamplePosition.setY(dValue); qSamplePosition.setX(path.currentPosition().x()+m_dDx); path.lineTo(qSamplePosition); path.moveTo(qSamplePosition); } qDebug("Plot-PainterPath created!"); }
//------------------------------------------------------------------------------ void PD_LPS_ADR_STRAIN::evaluateStatic(int id_i, int i) { if (m_data(i, m_iUnbreakable) >= 1) return; vector<pair<int, vector<double>>> &PDconnections = m_particles.pdConnections(id_i); bool broken = false; const double theta_i = m_data(i, m_iTheta); for (auto &con : PDconnections) { const int id_j = con.first; const int j = m_idToCol_v[id_j]; if (m_data(j, m_iUnbreakable) >= 1) continue; if (con.second[m_iConnected] <= 0.5) continue; const double s = con.second[m_iStretch]; const double theta_j = m_data(j, m_iTheta); const double s_d = std::max(s - theta_i / 3., s - theta_j / 3.); if (s > m_stretchCrit) { m_data(i, m_indexBrokenNow) = 1; con.second[m_iConnected] = 0; m_continueState = true; broken = true; } else if (s_d > m_shearCrit) { m_data(i, m_indexBrokenNow) = 1; con.second[m_iConnected] = 0; m_continueState = true; broken = true; } } if (broken) { updateWeightedVolume(id_i, i); // m_data(i, m_indexBrokenNow) = 0; } }
void operator () () { m_data(); }
//------------------------------------------------------------------------------ void PD_OSP::calculateForces(const std::pair<int, int> &idCol) { const int pId = idCol.first; const int col_i = idCol.second; const double a_i = m_data(col_i, m_indexA); const double b_i = m_data(col_i, m_indexB); const double d_i = m_data(col_i, m_indexD); const double theta_i = m_data(col_i, m_indexTheta); vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double r_i[3]; double r0_i[3]; double f_i[3]; for(int d=0; d<m_dim; d++) { f_i[d] = 0; r_i[d] = m_r(d, col_i); r0_i[d] = m_r0(d, col_i); } const int nConnections = PDconnections.size(); double dr_ij[3]; double thetaNew = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_indexConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double a_j = m_data(j, m_indexA); const double b_j = m_data(j, m_indexB); const double d_j = m_data(j, m_indexD); const double theta_j = m_data(j, m_indexTheta); const double vol_j = m_data(j, m_indexVolume); const double dr0 = con.second[m_indexDr0]; const double volumeScaling = con.second[m_indexVolumeScaling]; const double a_ij = 0.5*(a_i + a_j); const double b_ij = 0.5*(b_i + b_j); const double d_ij = 0.5*(d_i + d_j); const double Gd_ij = con.second[m_indexForceScalingDilation]; const double Gb_ij = con.second[m_indexForceScalingBond]; double dr2 = 0; double A_ij = 0; // The lambda-factor for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - r_i[d]; dr2 += dr_ij[d]*dr_ij[d]; A_ij += dr_ij[d]*(m_r0(d, j) - r0_i[d]); } const double dr = sqrt(dr2); A_ij /= (dr0*dr); double ds = dr - dr0; // To avoid roundoff errors if (fabs(ds) < THRESHOLD) ds = 0.0; const double s = ds/dr0; const double fbond = (a_ij*d_ij*Gd_ij*A_ij/dr0*(theta_i + theta_j) + b_ij*Gb_ij*s) *vol_j*volumeScaling/dr; for(int d=0; d<m_dim; d++) { f_i[d] += dr_ij[d]*fbond; } thetaNew += d_ij*s*A_ij*vol_j*volumeScaling; con.second[m_indexStretch] = s; } for(int d=0; d<m_dim; d++) { m_F(d, col_i) += m_delta*f_i[d]; } m_data(col_i, m_indexThetaNew) = m_delta*thetaNew; }
//------------------------------------------------------------------------------ double PD_LPS::calculateStableMass(const std::pair<int, int> &idCol, double dt) { const int pId = idCol.first; const int a = idCol.second; const double vol_a = m_data(a, m_iVolume); const double m_a = m_data(a, m_iMass); const arma::mat & matR0 = m_particles.r0(); double beta = 0; if(m_dim == 3) beta = 15*m_mu; else beta = 8*m_mu; const double alpha_a = beta/m_a; double m[m_dim]; double dr0[m_dim]; for(int d=0; d<m_dim; d++) { m[d] = 0; } vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double k[m_dim]; for(int i=0; i<m_dim; i++) { for(int d=0; d<m_dim; d++) { k[d] = 0; } for(auto &con:PDconnections) { if(con.second[m_iConnected] <= 0.5) continue; const int id_b = con.first; const int b = m_pIds[id_b]; for(int d=0; d<m_dim; d++) { dr0[d] = matR0(d, a) - matR0(d, b); } const double m_b = m_data(b, m_iMass); const double dr0Len = con.second[m_iDr0]; const double vol_b = m_data(b, m_iVolume); const double volumeScaling = con.second[m_iVolumeScaling]; const double Va = vol_a *volumeScaling; const double Vb = vol_b *volumeScaling; const double alpha_b = beta/m_b; const double gb_ij = con.second[m_iForceScalingBond]; const double gd_ij = con.second[m_iForceScalingDilation]; const double dr0Len2 = pow(dr0Len, 2); double coeff = gd_ij*3*dr0Len*(3*m_k - 5*m_mu)*(Vb/pow(m_a,2) + Va/pow(m_b,2)); coeff += gb_ij*(alpha_a + alpha_b); coeff *= Vb/dr0Len2; double sum_xyz = 0; for(int j=0; j<m_dim; j++) { sum_xyz += fabs(dr0[j]); } k[i] += fabs(dr0[i])*coeff*sum_xyz; } m[i] = k[i]; } double stiffness = 0; for(int d=0;d<m_dim; d++) { if(m[d]>stiffness) { stiffness = m[d]; } } double stableMass = 4*0.25*pow(dt, 2)*stiffness; return stableMass; }
Reference dereference(type<Reference>, const Node& x) const { return m_data(x); }
//------------------------------------------------------------------------------ void PD_OSP::updateState(const std::pair<int, int> &idCol) { const int col_i = idCol.second; m_data(col_i, m_indexTheta) = m_data(col_i, m_indexThetaNew); }
//------------------------------------------------------------------------------ void PD_LPS_porosity_adrmc::calculateForces(const int id, const int i) { const double theta_i = m_data(i, m_iTheta); const double m_i = m_data(i, m_iMass); const double a_i = m_data(i, m_iA); const double b_i = m_data(i, m_iA); vector<pair<int, vector<double>>> &PDconnections = m_particles.pdConnections(id); const int nConnections = PDconnections.size(); double dr0_ij[m_dim]; double dr_ij[m_dim]; _F.zeros(); double thetaNew = 0; int nConnected = 0; //---------------------------------- // TMP - standard stress calc from // m_data(i, m_indexStress[0]) = 0; // m_data(i, m_indexStress[1]) = 0; // m_data(i, m_indexStress[2]) = 0; //---------------------------------- for (int l_j = 0; l_j < nConnections; l_j++) { auto &con = PDconnections[l_j]; if (con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_idToCol_v[id_j]; const double m_j = m_data(j, m_iMass); const double theta_j = m_data(j, m_iTheta); const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; const double volumeScaling = con.second[m_iVolumeScaling]; const double vol = vol_j * volumeScaling; const double w = weightFunction(dr0); const double a_j = m_data(j, m_iA); const double b_j = m_data(j, m_iB); double dr2 = 0; for (int d = 0; d < m_dim; d++) { dr0_ij[d] = m_r0(j, d) - m_r0(i, d); dr_ij[d] = m_r(j, d) - m_r(i, d); dr2 += dr_ij[d] * dr_ij[d]; } const double dr = sqrt(dr2); const double ds = dr - dr0; double bond = (b_i * theta_i / m_i + b_j * theta_j / m_j) * dr0; bond += (a_i / m_i + a_j / m_j) * ds; bond *= w * vol / dr; thetaNew += w * dr0 * ds * vol; for (int d = 0; d < m_dim; d++) { m_F(i, d) += dr_ij[d] * bond; for (int d2 = 0; d2 < m_dim; d2++) { _F(d, d2) += w * dr_ij[d] * dr0_ij[d2] * vol; } } con.second[m_iStretch] = ds / dr0; //---------------------------------- // TMP - standard stres calc from // m_data(i, m_indexStress[0]) += 0.5*dr_ij[0]*dr_ij[0]*bond; // m_data(i, m_indexStress[1]) += 0.5*dr_ij[1]*dr_ij[1]*bond; // m_data(i, m_indexStress[2]) += 0.5*dr_ij[0]*dr_ij[1]*bond; //---------------------------------- nConnected++; } if (nConnections <= 3) { m_data(i, m_iThetaNew) = 0; } else { m_data(i, m_iThetaNew) = m_dim / m_i * thetaNew; } //---------------------------------- // TMP - standard stres calc from //---------------------------------- // if(nConnected > 5) { // computeStress(id, i, nConnected); // } computeStress(id, i, nConnected); //-------------------- m_continueState = false; }
/// /// \brief access an element of the tensor in the range [0, size()) /// tscalar operator()(tindex i) const { return m_data(i); }
//------------------------------------------------------------------------------ void PD_LPS::calculateForces(const std::pair<int, int> &idCol) { const int pId = idCol.first; const int i = idCol.second; const double theta_i = m_data(i, m_iTheta); const double m_i = m_data(i, m_iMass); double alpha; if(m_dim == 3) alpha = 15*m_mu; else alpha = 8*m_mu; const double c = (3*m_k - 5*m_mu); vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double r_i[m_dim]; double r0_i[m_dim]; double f_i[m_dim]; for(int d=0; d<m_dim; d++) { f_i[d] = 0; r_i[d] = m_r(d, i); r0_i[d] = m_r0(d, i); } const int nConnections = PDconnections.size(); double dr_ij[m_dim]; double thetaNew = 0; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double m_j = m_data(j, m_iMass); const double theta_j = m_data(j, m_iTheta); const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; const double volumeScaling = con.second[m_iVolumeScaling]; const double gb_ij = con.second[m_iForceScalingBond]; const double gd_ij = con.second[m_iForceScalingDilation]; double dr2 = 0; for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - r_i[d]; dr2 += dr_ij[d]*dr_ij[d]; } const double dr = sqrt(dr2); const double ds = dr - dr0; double bond = gd_ij*c*(theta_i/m_i + theta_j/m_j)*dr0; bond += gb_ij*alpha*(1./m_i + 1./m_j)*ds; bond *= vol_j*volumeScaling/dr; thetaNew += dr0*ds*vol_j*volumeScaling; for(int d=0; d<m_dim; d++) { m_F(d, i) += dr_ij[d]*bond; } con.second[m_iStretch] = ds/dr0; } m_data(i, m_iThetaNew) = m_dim/m_i*thetaNew; }
//------------------------------------------------------------------------------ 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; } }
bool THashString::operator==( const THashString& copy ) const { return (m_data()&©.m_data())? m_data()->hash == copy.m_data()->hash : false; }
const tstring& THashString::str() const { static tstring empty; if (m_data()) return m_data()->str; return empty; }
const tchar* THashString::c_str() const { if (m_data()) return str().c_str(); return NULL; }
//------------------------------------------------------------------------------ void PD_LPS2::calculateForces(const int id, const int i) { const double theta_i = m_theta[i]; const double m_i = m_mass[i]; vector<pair<int, vector<double>>> &PDconnections = m_particles.pdConnections(id); const int nConnections = PDconnections.size(); double dr_ij[m_dim]; if (m_dim == 3) { vector<double *> d_stress; for (int i = 0; i < 6; i++) d_stress.push_back(m_data.colptr(m_indexStress[i])); //---------------------------------- // TMP - standard stres calc from for (int k = 0; k < 6; k++) d_stress[k][i] = 0; //---------------------------------- for (int l_j = 0; l_j < nConnections; l_j++) { auto &con = PDconnections[l_j]; const int id_j = con.first; const int j = m_idToCol_v[id_j]; vector<double> &con_data = con.second; if (con_data[m_iConnected] <= 0.5) continue; const double m_j = m_mass[j]; const double theta_j = m_theta[j]; const double vol_j = m_volume[j]; const double volumeScaling = con_data[m_iVolumeScaling]; const double volume = vol_j * volumeScaling; const double dr0 = con_data[m_iDr0]; const double w = weightFunction(dr0); dr_ij[0] = m_x[j] - m_x[i]; dr_ij[1] = m_y[j] - m_y[i]; dr_ij[2] = m_z[j] - m_z[i]; double dr2 = dr_ij[0] * dr_ij[0] + dr_ij[1] * dr_ij[1] + dr_ij[2] * dr_ij[2]; const double dr = sqrt(dr2); const double ds = dr - dr0; double bond = m_c * (theta_i * m_i + theta_j * m_j) * dr0; bond += m_alpha * (m_i + m_j) * ds; bond *= w * volume / dr; m_Fx[i] += dr_ij[0] * bond; m_Fy[i] += dr_ij[1] * bond; m_Fz[i] += dr_ij[2] * bond; con_data[m_iStretch] = ds / dr0; //---------------------------------- // TMP - standard stres calc from d_stress[0][i] += 0.5 * dr_ij[0] * dr_ij[0] * bond; d_stress[1][i] += 0.5 * dr_ij[1] * dr_ij[1] * bond; d_stress[2][i] += 0.5 * dr_ij[0] * dr_ij[1] * bond; d_stress[3][i] += 0.5 * dr_ij[2] * dr_ij[2] * bond; d_stress[4][i] += 0.5 * dr_ij[0] * dr_ij[2] * bond; d_stress[5][i] += 0.5 * dr_ij[1] * dr_ij[2] * bond; //---------------------------------- } } else { // dim2 //---------------------------------- // TMP - standard stres calc from MD for (int k = 0; k < 3; k++) m_data(i, m_indexStress[k]) = 0; //---------------------------------- for (int l_j = 0; l_j < nConnections; l_j++) { auto &con = PDconnections[l_j]; vector<double> &con_data = con.second; if (con_data[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_idToCol_v[id_j]; const double m_j = m_mass[j]; const double theta_j = m_theta[j]; const double vol_j = m_volume[j]; const double volumeScaling = con_data[m_iVolumeScaling]; const double volume = vol_j * volumeScaling; const double dr0 = con_data[m_iDr0]; const double w = weightFunction(dr0); dr_ij[0] = m_x[j] - m_x[i]; dr_ij[1] = m_y[j] - m_y[i]; double dr2 = dr_ij[0] * dr_ij[0] + dr_ij[1] * dr_ij[1]; const double dr = sqrt(dr2); const double ds = dr - dr0; double bond = m_c * (theta_i * m_i + theta_j * m_j) * dr0; bond += m_alpha * (m_i + m_j) * ds; bond *= w * volume / dr; m_Fx[i] += dr_ij[0] * bond; m_Fy[i] += dr_ij[1] * bond; con_data[m_iStretch] = ds / dr0; //---------------------------------- // TMP - standard stres calc from MD m_data(i, m_indexStress[0]) += 0.5 * dr_ij[0] * dr_ij[0] * bond; m_data(i, m_indexStress[1]) += 0.5 * dr_ij[1] * dr_ij[1] * bond; m_data(i, m_indexStress[2]) += 0.5 * dr_ij[0] * dr_ij[1] * bond; } } m_continueState = false; }
void Reservoir::store(int t) { m_data(span::all,t) = m_output; }
//------------------------------------------------------------------------------ void PD_LPS::calculateStress(const std::pair<int, int> &idCol, const int (&indexStress)[6]) { const int pId = idCol.first; const int i = idCol.second; const double theta_i = m_data(i, m_iTheta); const double m_i = m_data(i, m_iMass); double beta = 0; if(m_dim == 3) beta = 15*m_mu; else beta = 8*m_mu; const double alpha_i = beta/m_i; vector<pair<int, vector<double>>> & PDconnections = m_particles.pdConnections(pId); double r_i[3]; double r0_i[3]; for(int d=0; d<m_dim; d++) { r_i[d] = m_r(d, i); r0_i[d] = m_r0(d, i); } const int nConnections = PDconnections.size(); double dr_ij[m_dim]; for(int l_j=0; l_j<nConnections; l_j++) { auto &con = PDconnections[l_j]; if(con.second[m_iConnected] <= 0.5) continue; const int id_j = con.first; const int j = m_pIds[id_j]; const double m_j = m_data(j, m_iMass); const double theta_j = m_data(j, m_iTheta); const double vol_j = m_data(j, m_iVolume); const double dr0 = con.second[m_iDr0]; const double volumeScaling = con.second[m_iVolumeScaling]; const double alpha_j = beta/m_j; const double gb_ij = con.second[m_iForceScalingBond]; const double gd_ij = con.second[m_iForceScalingDilation]; double dr2 = 0; for(int d=0; d<m_dim; d++) { dr_ij[d] = m_r(d, j) - r_i[d]; dr2 += dr_ij[d]*dr_ij[d]; } const double dr = sqrt(dr2); const double ds = dr - dr0; double bond_ij = gd_ij*(3*m_k - 5*m_mu)*(theta_i/m_i + theta_j/m_j)*dr0; bond_ij += gb_ij*(alpha_i + alpha_j)*ds; bond_ij *= vol_j*volumeScaling/dr; m_data(i, indexStress[0]) += 0.5*bond_ij*dr_ij[X]*dr_ij[X]; m_data(i, indexStress[1]) += 0.5*bond_ij*dr_ij[Y]*dr_ij[Y]; m_data(i, indexStress[3]) += 0.5*bond_ij*dr_ij[X]*dr_ij[Y]; if(m_dim == 3) { m_data(i, indexStress[2]) += 0.5*bond_ij*dr_ij[Z]*dr_ij[Z]; m_data(i, indexStress[4]) += 0.5*bond_ij*dr_ij[X]*dr_ij[Z]; m_data(i, indexStress[5]) += 0.5*bond_ij*dr_ij[Y]*dr_ij[Z]; } } }
//------------------------------------------------------------------------------ void PD_OSP::calculatePotentialEnergy(const std::pair<int, int> &idCol, int indexPotential) { int col_i = idCol.second; double vol_i = m_data(col_i, m_indexVolume); m_data(col_i, indexPotential) += calculatePotentialEnergyDensity(idCol)*vol_i; }
tscalar& operator()(tindex i) { return m_data(i); }
thash32 THashString::hash() const { if (m_data()) return m_data()->hash; return 0; }