q = body.q() v = body.velocity() # # initial data # dataPlot[0, 0] = t0 dataPlot[0, 1] = q[2] dataPlot[0, 2] = v[2] k = 1 # time loop while(simulation.hasNextEvent()): broadphase.buildInteractions(bouncingBox.currentTime()) simulation.computeOneStep() dataPlot[k, 0] = simulation.nextTime() dataPlot[k, 1] = q[2] dataPlot[k, 2] = v[2] if (broadphase.collisionWorld().getDispatcher().getNumManifolds() > 0): if bouncingBox.nonSmoothDynamicalSystem().topology().\ numberOfIndexSet() > 1: index1 = simulation.indexSet(1) if (index1.size() == 4): dataPlot[k, 3] = norm(index1.interactions()[0].lambda_(1)) + \ norm(index1.interactions()[1].lambda_(1)) + \ norm(index1.interactions()[2].lambda_(1)) + \ norm(index1.interactions()[3].lambda_(1))
def run(self, with_timer=False, time_stepping=None, space_filter=None, body_class=None, shape_class=None, face_class=None, edge_class=None, length_scale=1, t0=0, T=10, h=0.0005, multipoints_iterations=True, theta=0.50001, Newton_max_iter=20, set_external_forces=None, solver=Numerics.SICONOS_FRICTION_3D_NSGS, itermax=100000, tolerance=1e-8): """ Run a simulation from inputs in hdf5 file. parameters are: with_timer : use a timer for log output (default False) length_scale : gravity is multiplied by this factor. 1. for meters (default). 1./100 for centimeters. This parameter may be needed for small objects because of Bullet collision margin (0.04). t0 : starting time (default 0) T : end time (default 10) h : timestep (default 0.0005) multiPointIterations : use bullet "multipoint iterations" (default True) theta : parameter for Moreau-Jean OSI (default 0.50001) Newton_max_iter : maximum number of iterations for integrator Newton loop (default 20) set_external_forces : method for external forces (default earth gravity) solver : default Numerics.SICONOS_FRICTION_3D_NSGS itermax : maximum number of iteration for solver tolerance : friction contact solver tolerance """ from Siconos.Kernel import \ Model, MoreauJeanOSI, TimeDiscretisation,\ GenericMechanical, FrictionContact, NewtonImpactFrictionNSL from Siconos.Numerics import SICONOS_FRICTION_3D_AlartCurnierNewton from Siconos.Mechanics.ContactDetection.Bullet import \ btConvexHullShape, btCollisionObject, \ btBoxShape, btQuaternion, btTransform, btConeShape, \ BulletSpaceFilter, cast_BulletR, \ BulletWeightedShape, BulletDS, BulletTimeStepping if set_external_forces is not None: self._set_external_forces = set_external_forces if time_stepping is None: time_stepping = BulletTimeStepping if space_filter is None: space_filter = BulletSpaceFilter # Model # model = Model(t0, T) # (1) OneStepIntegrators joints = list(self.joints()) self._osi = MoreauJeanOSI(theta) # (2) Time discretisation -- timedisc = TimeDiscretisation(t0, h) if len(joints) > 0: osnspb = GenericMechanical(SICONOS_FRICTION_3D_AlartCurnierNewton) else: osnspb = FrictionContact(3, solver) osnspb.numericsSolverOptions().iparam[0] = itermax osnspb.numericsSolverOptions().dparam[0] = tolerance osnspb.setMaxSize(16384) osnspb.setMStorageType(1) #osnspb.setNumericsVerboseMode(False) # keep previous solution osnspb.setKeepLambdaAndYState(True) # (5) broadphase contact detection self._broadphase = space_filter(model) if not multipoints_iterations: print(""" ConvexConvexMultipointIterations and PlaneConvexMultipointIterations are unset """) else: if hasattr(self._broadphase, 'collisionConfiguration'): self._broadphase.collisionConfiguration().\ setConvexConvexMultipointIterations() self._broadphase.collisionConfiguration().\ setPlaneConvexMultipointIterations() # (6) Simulation setup with (1) (2) (3) (4) (5) simulation = time_stepping(timedisc) simulation.insertIntegrator(self._osi) simulation.insertNonSmoothProblem(osnspb) simulation.setNewtonMaxIteration(Newton_max_iter) k = 1 self.importScene(body_class, shape_class, face_class, edge_class) model.initialize(simulation) self.outputStaticObjects() self.outputDynamicObjects() while simulation.hasNextEvent(): print ('step', k) log(self._broadphase.buildInteractions, with_timer)\ (model.currentTime()) log(simulation.computeOneStep, with_timer)() log(self.outputDynamicObjects, with_timer)() log(self.outputVelocities, with_timer)() log(self.outputContactForces, with_timer)() log(self.outputSolverInfos, with_timer)() log(simulation.nextStep, with_timer)() log(self._out.flush)() print ('') k += 1