File: utilsModule.py

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (69 lines) | stat: -rw-r--r-- 2,389 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#import unittest
#import random
#from yade.wrapper import *
#from yade import utils

import unittest
import random, math
import numpy as np
from yade.wrapper import *
from yade._customConverters import *
from yade import utils
from yade import *
from yade.minieigenHP import *


class TestUtils(unittest.TestCase):

	def setUp(self):
		pass  # no setup needed for tests here

	def testUserCreatedInteraction(self):
		O.engines = [
		        ForceResetter(),
		        InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Facet_Aabb(), Bo1_Box_Aabb()], label="collider"),
		        InteractionLoop(
		                [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom(),
		                 Ig2_Box_Sphere_ScGeom()],
		                [Ip2_FrictMat_FrictMat_FrictPhys()],  #for linear model only
		                [Law2_ScGeom_FrictPhys_CundallStrack(label="law")],  #for linear model only
		                label="interactionLoop"
		        ),
		        GlobalStiffnessTimeStepper(timeStepUpdateInterval=10, label="timeStepper"),
		        NewtonIntegrator(label="newton")
		]
		O.bodies.append(
		        [
		                utils.sphere((0, 0, 0), 0.5),
		                utils.sphere((2, 0, 0), 0.5),  #(0,1) no overlap , no contacts
		                utils.sphere((0.9, 0.9, 0), 0.5),  #(0,2) overlapping bounds, no contacts
		                utils.sphere((-0.99, 0, 0), 0.5)
		        ]
		)  #(0,3) overlaping + contact
		O.dt = 0
		O.dynDt = False
		O.step()
		i = utils.createInteraction(0, 1)
		self.assertTrue(i.iterBorn == 1 and i.iterMadeReal == 1)
		j = utils.createInteraction(0, 2)
		self.assertTrue(j.iterBorn == 1 and j.iterMadeReal == 1)
		self.assertRaises(RuntimeError, lambda: utils.createInteraction(0, 3))

	def testPointInsidePolygon(self):
		vertices = np.array([[0, 0], [4, 0], [4, 4], [0, 4]])
		point_inside = (2, 2)
		point_outside = (5, 5)
		point_edge = (4, 2)
		point_vertex = (0, 0)

		# Should return True when a point is inside.
		self.assertTrue(utils.pointInsidePolygon(point_inside, vertices))

		# Should return False when a point is outside.
		self.assertFalse(utils.pointInsidePolygon(point_outside, vertices))

		# Should return False when a point is on the edge.
		self.assertFalse(utils.pointInsidePolygon(point_edge, vertices))

		# Should return True when a point is on the vertex.
		self.assertTrue(utils.pointInsidePolygon(point_vertex, vertices))