Ejemplo n.º 1
0
        /// Initialize again this constraint.
        public override void Reset(Ta mobjA,                       //< collidable object A
                                   Tb mobjB,                       //< collidable object B
                                   collision.ChCollisionInfo cinfo //< data for the contact pair
                                   )                               //where T1: IntInterface.IBase
        {
            // inherit base class:
            base.Reset(mobjA, mobjB, cinfo);

            ChBody oA = (this.objA as ChBody);
            ChBody oB = (this.objB as ChBody);

            Nx.Get_tuple_a().SetVariables(ref this.objA);
            Nx.Get_tuple_b().SetVariables(ref this.objB);
            Tu.Get_tuple_a().SetVariables(ref this.objA);
            Tu.Get_tuple_b().SetVariables(ref this.objB);
            Tv.Get_tuple_a().SetVariables(ref this.objA);
            Tv.Get_tuple_b().SetVariables(ref this.objB);

            // Calculate composite material properties
            ChMaterialCompositeNSC mat = new ChMaterialCompositeNSC(
                this.container.GetSystem().composition_strategy,
                (ChMaterialSurfaceNSC)(oA.GetMaterialSurfaceBase()),
                (ChMaterialSurfaceNSC)(oB.GetMaterialSurfaceBase()));

            // Check for a user-provided callback to modify the material
            if (this.container.GetAddContactCallback() != null)
            {
                this.container.GetAddContactCallback().OnAddContact(cinfo, mat);
            }

            Nx.Constraint2TuplesNall.SetFrictionCoefficient(mat.static_friction);
            Nx.Constraint2TuplesNall.SetCohesion(mat.cohesion);

            this.restitution = mat.restitution;
            this.dampingf    = mat.dampingf;
            this.compliance  = mat.compliance;
            this.complianceT = mat.complianceT;

            this.reactions_cache = cinfo.reaction_cache;

            // COMPUTE JACOBIANS


            // delegate objA to compute its half of jacobian
            oA.ComputeJacobianForContactPart(this.p1, ref this.contact_plane, ref Nx.Get_tuple_a(), ref Tu.Get_tuple_a(),
                                             ref Tv.Get_tuple_a(), false);

            // delegate objB to compute its half of jacobian
            oB.ComputeJacobianForContactPart(this.p2, ref this.contact_plane, ref Nx.Get_tuple_b(), ref Tu.Get_tuple_b(),
                                             ref Tv.Get_tuple_b(), true);

            if (reactions_cache != null)
            {
                react_force.x = reactions_cache[0];
                react_force.y = reactions_cache[1];
                react_force.z = reactions_cache[2];
                //GetLog() << "Reset Fn=" << (double)reactions_cache[0] << "  at cache address:" << (int)this->reactions_cache << "\n";
            }
            else
            {
                react_force = new ChVector(0, 0, 0);
            }
        }