Пример #1
0
void PlotGl::updateViewMatrix()
{
	tl::t_mat4 matScale = tl::make_mat<tl::t_mat4>(
		{{m_dMouseScale,              0,             0, 0},
		{            0,   m_dMouseScale,             0, 0},
		{            0,               0, m_dMouseScale, 0},
		{            0,               0,             0, 1}});

	tl::t_mat4 matR0 = tl::rotation_matrix_3d_z(tl::d2r<t_real>(m_dMouseRot[0]));
	tl::t_mat4 matR1 = tl::rotation_matrix_3d_x(tl::d2r<t_real>(-90. + m_dMouseRot[1]));
	matR0.resize(4,4,1); matR1.resize(4,4,1);
	matR0(3,3) = matR1(3,3) = 1.;
	for(short i=0; i<3; ++i) matR0(i,3)=matR0(3,i)=matR1(i,3)=matR1(3,i)=0.;
	tl::t_mat4 matRot0 = matR0, matRot1 = matR1;

	tl::t_mat4 matTrans = tl::make_mat<tl::t_mat4>(
		{{ 1, 0, 0,  0},
		{  0, 1, 0,  0},
		{  0, 0, 1, -2},
		{  0, 0, 0,  1}});

	{
		std::lock_guard<QMutex> _lck(m_mutex);
		m_matView = ublas::prod(matTrans, matRot1);
		m_matView = ublas::prod(m_matView, matRot0);
		m_matView = ublas::prod(m_matView, matScale);
	}
}
Пример #2
0
//------------------------------------------------------------------------------
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;
}