void glpk_wrapper::add(std::unordered_set<Enode *> const & es) { int idx = glp_add_rows(lp, es.size()); for (auto it = es.cbegin(); it != es.cend(); ++it) { set_constraint(idx, *it); idx += 1; } }
void CenterOfMass::do_setup_particle(Model *m, ParticleIndex pi, Refiner *refiner) { SingletonModifier* pre_mod = new core::CentroidOfRefined( refiner, Mass::get_mass_key(), IMP::core::XYZ::get_xyz_keys()); SingletonDerivativeModifier* post_mod = new core::WeightedDerivativesToRefined( refiner, Mass::get_mass_key(), IMP::core::XYZ::get_xyz_keys()); if (!core::XYZ::get_is_setup(m, pi)) core::XYZ::setup_particle(m, pi); if (!Mass::get_is_setup(m, pi)) Mass::setup_particle(m, pi, 0.0); pre_mod->apply_index(m, pi); // update with current state set_constraint(pre_mod, post_mod, m, pi); }
void glpk_wrapper::add(Enode * const e) { int idx = glp_add_rows(lp, 1); set_constraint(idx, e); }
//! @brief Constructor. //! @param theDomain: domain where the constraint is defined. //! @param tag: tag for the multi-freedom constraint. //! @param nodeRetain: identifier of the retained node. //! @param nodeConstr: identifier of the constrained node. //! @param LrgDsp: true if large displacement (geometric non-linearity) must be expected: 0 for constant constraint matrix(small deformations), 1 for time varying constraint matrix(large deformations), 2 for large deformations with length correction. XC::MFreedom_Joint2D::MFreedom_Joint2D(Domain *domain, int tag, int nodeRetain, int nodeConstr,int Maindof, int fixedend, int LrgDsp ) : MFreedom_Joint(domain,tag,CNSTRNT_TAG_MFreedom_Joint2D,nodeRetain,nodeConstr,LrgDsp), MainDOF(Maindof), AuxDOF(0), FixedEnd(fixedend) { setDomain(domain); // check for proper degrees of freedom int RnumDOF = RetainedNode->getNumberDOF(); int CnumDOF = ConstrainedNode->getNumberDOF(); if(RnumDOF != 4 || CnumDOF != 3 ) { std::cerr << "MFreedom_Joint2D::MFreedom_Joint2D - mismatch in numDOF\n DOF not supported by this type of constraint"; return; } // check the XC::main degree of freedom. Assign auxilary DOF if( MainDOF!= 2 && MainDOF!=3 ) { std::cerr << "MFreedom_Joint2D::MFreedom_Joint2D - Wrong main degree of freedom" ; return; } if(MainDOF == 2 ) AuxDOF = 3; if(MainDOF == 3 ) AuxDOF = 2; // check the fixed end flag if( FixedEnd!= 0 && FixedEnd!=1 ) { std::cerr << "XC::MFreedom_Joint2D::MFreedom_Joint2D - Wrong fixed end flag"; return; } // check for proper dimensions of coordinate space const Vector &crdR = RetainedNode->getCrds(); int dimR = crdR.Size(); const Vector &crdC = ConstrainedNode->getCrds(); int dimC = crdC.Size(); if(dimR != 2 || dimC != 2 ) { std::cerr << "MFreedom_Joint2D::MFreedom_Joint2D - mismatch in dimnesion\n dimension not supported by this type of constraint"; return; } // calculate the initial length of the rigid link double deltaX = crdC(0) - crdR(0); double deltaY = crdC(1) - crdR(1); Length0 = sqrt( deltaX*deltaX + deltaY*deltaY ); if( Length0 <= 1.0e-12 ) { std::cerr << "XC::MFreedom_Joint2D::MFreedom_Joint2D - The constraint length is zero\n"; } // allocate and set up the constranted and retained id's // allocate and set up the constraint matrix if( FixedEnd == 0 ) { // the end is released set_constrained_dofs(ID(CnumDOF-1)); set_retained_dofs(ID(RnumDOF-1)); constrDOF(0) = 0; constrDOF(1) = 1; retainDOF(0) = 0; retainDOF(1) = 1; retainDOF(2) = MainDOF; set_constraint(Matrix( CnumDOF-1 , RnumDOF-1 )); constraintMatrix(0,0) = 1.0 ; constraintMatrix(0,2) = -deltaY ; constraintMatrix(1,1) = 1.0 ; constraintMatrix(1,2) = deltaX ; } else { // the end is fixed constrDOF = ID(CnumDOF); retainDOF = ID(RnumDOF); constrDOF(0) = 0; constrDOF(1) = 1; constrDOF(2) = 2; retainDOF(0) = 0; retainDOF(1) = 1; retainDOF(2) = 2; retainDOF(3) = 3; constraintMatrix= Matrix(CnumDOF,RnumDOF); constraintMatrix(0,0) = 1.0 ; constraintMatrix(0,MainDOF) = -deltaY ; constraintMatrix(1,1) = 1.0 ; constraintMatrix(1,MainDOF) = deltaX ; constraintMatrix(2,AuxDOF) = 1.0 ; } if(constraintMatrix.isEmpty()) { std::cerr << getClassName() << "::" << __FUNCTION__ << "; ran out of memory \ncan not generate the constraint matrix"; exit(-1); } }