Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / tests / enforced_vertex.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2023  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import salome
22 import math
23
24 import GEOM
25 from salome.geom import geomBuilder
26 geompy = geomBuilder.New()
27
28 dist_coin = 10.1
29
30 p1 = geompy.MakeVertex(0., 0., 0.)
31 p2 = geompy.MakeVertex(100., 100., 100.)
32 box = geompy.MakeBoxTwoPnt(p1, p2)
33 geompy.addToStudy(box, "box")
34
35 p3 = geompy.MakeVertex(dist_coin, 0, dist_coin)
36 geompy.addToStudy(p3, "p3")
37
38 left = geompy.GetFaceNearPoint(box, p3)
39 geompy.addToStudyInFather(box, left, "left")
40
41 allEnforcedCoords = []
42 allEnforcedCoords.append(( dist_coin, 0, dist_coin ))
43 allEnforcedCoords.append(( 20, 0, 15.3 ))
44 allEnforcedCoords.append(( 25, 1, 25.3 ))
45 allEnforcedCoords.append(( 35, 1, 45.3 ))
46 allEnforcedCoords.append(( 35, 1, 55.3 ))
47
48 p4 = geompy.MakeVertex( *(allEnforcedCoords[1] ))
49 p5 = geompy.MakeVertex( *(allEnforcedCoords[2] ))
50 pp = geompy.MakeCompound( [p4,p5], theName="p4,p5" )
51 p6 = geompy.MakeVertex( *(allEnforcedCoords[3] ), theName="p6")
52 p7 = geompy.MakeVertex( *(allEnforcedCoords[4] ), theName="p7")
53
54 xyz7 = allEnforcedCoords[4]
55
56 # Mesh
57 # ====
58
59 import SMESH
60 from salome.smesh import smeshBuilder
61 smesh = smeshBuilder.New()
62
63 Mesh = smesh.Mesh(box, "Mesh")
64
65
66 algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf)
67 algo2d.SetGeometricMesh( 1 )
68 algo2d.SetAngleMesh( 4 )
69 algo2d.SetPhySize( 8 )
70
71 algo2d.SetEnforcedVertex(left, dist_coin, 0, dist_coin)
72 algo2d.AddEnforcedVertexGeom( pp )
73 algo2d.AddEnforcedVertexGeom( p6 )
74 algo2d.AddEnforcedVertex( *xyz7 )
75
76 assert Mesh.Compute()
77 assert not Mesh.FindCoincidentNodes( 1e-7 )
78
79 for x,y,z in allEnforcedCoords:
80
81     id_node = Mesh.FindNodeClosestTo( x,y,z )
82     xn, yn, zn = Mesh.GetNodeXYZ( id_node )
83
84     # compare X and Z
85     assert "%.2f, %.2f"%(x, z) == "%.2f, %.2f"%( xn, zn ), \
86         "%.2f, %.2f, %.2f != %.2f, %.2f, %.2f"%( xn, yn, zn, x,y,z )
87
88
89 salome.sg.updateObjBrowser()
90