Skip to content

Commit 7f615b3

Browse files
committed
draw rigidwall
1 parent 76a7f73 commit 7f615b3

File tree

11 files changed

+183
-26
lines changed

11 files changed

+183
-26
lines changed

src/ansys/dyna/core/pre/dynabase.py

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from ansys.api.dyna.v0.kwprocess_pb2 import * # noqa : F403
1515
from ansys.api.dyna.v0.kwprocess_pb2_grpc import * # noqa : F403
1616

17+
# from .kwprocess_pb2 import *
18+
# from .kwprocess_pb2_grpc import *
19+
1720

1821
class Motion(Enum):
1922
VELOCITY = 0
@@ -259,6 +262,18 @@ def __init__(self, x=0, y=0, z=0):
259262
self.z = z
260263

261264

265+
class BaseObj:
266+
"""Define the base object."""
267+
268+
def __init__(self):
269+
self.type = ""
270+
self.subtype = ""
271+
272+
def get_data(self) -> List:
273+
"""Get the data of the object."""
274+
return None
275+
276+
262277
class DynaBase:
263278
"""Contains methods for creating a general LS-DYNA keyword."""
264279

@@ -804,6 +819,12 @@ def create_general_keyword(self, opcode, keyworddata):
804819

805820
def add(self, obj):
806821
"""Add entities to an object."""
822+
823+
if obj.type == "rigidwall_cylinder" or obj.type == "rigidwall_sphere" or obj.type == "rigidwall_planar":
824+
data = obj.get_data()
825+
if data != None:
826+
model = self._parent.model
827+
model.add_rigidwall(data)
807828
self.entities.append(obj)
808829

809830
def set_transform(self, filename=None, idnoff=0, ideoff=0, idpoff=0, idmoff=0, idsoff=0, idfoff=0, transform=None):
@@ -1788,7 +1809,7 @@ class ThermalAnalysisTimestep(Enum):
17881809
VARIABLE = 1
17891810

17901811

1791-
class ThermalAnalysis:
1812+
class ThermalAnalysis(BaseObj):
17921813
"""Activates thermal analysis and defines associated control parameters."""
17931814

17941815
def __init__(self):
@@ -2591,7 +2612,7 @@ def create(self):
25912612
logging.info(f"Define temperature at {type} {id}.")
25922613

25932614

2594-
class RigidwallCylinder:
2615+
class RigidwallCylinder(BaseObj):
25952616
"""Defines a rigid wall with a cylinder form.
25962617
25972618
Parameters
@@ -2617,6 +2638,7 @@ def __init__(self, tail=Point(0, 0, 0), head=Point(0, 0, 0), radius=1, length=10
26172638
self.motion = -1
26182639
self.lcid = 0
26192640
self.dir = Direction(1, 0, 0)
2641+
self.type = "rigidwall_cylinder"
26202642

26212643
def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
26222644
"""Set the prescribed motion."""
@@ -2625,6 +2647,21 @@ def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
26252647
self.motion = motion.value
26262648
self.dir = dir
26272649

2650+
def get_data(self) -> List:
2651+
"""Get the rigidwall data."""
2652+
data = [
2653+
self.type,
2654+
self.tail.x,
2655+
self.tail.y,
2656+
self.tail.z,
2657+
self.head.x,
2658+
self.head.y,
2659+
self.head.z,
2660+
self.radius,
2661+
self.length,
2662+
]
2663+
return data
2664+
26282665
def create(self):
26292666
"""Create a rigidwall cylinder."""
26302667
parameter = [
@@ -2652,7 +2689,7 @@ def create(self):
26522689
logging.info("Cylinder Rigidwall Created...")
26532690

26542691

2655-
class RigidwallSphere:
2692+
class RigidwallSphere(BaseObj):
26562693
"""Defines a rigid wall with a sphere form.
26572694
26582695
Parameters
@@ -2676,6 +2713,7 @@ def __init__(self, center=Point(0, 0, 0), orient=Point(0, 0, 0), radius=1):
26762713
self.motion = -1
26772714
self.lcid = 0
26782715
self.dir = Direction(1, 0, 0)
2716+
self.type = "rigidwall_sphere"
26792717

26802718
def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
26812719
"""Set the prescribed motion."""
@@ -2684,6 +2722,20 @@ def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
26842722
self.motion = motion.value
26852723
self.dir = dir
26862724

2725+
def get_data(self) -> List:
2726+
"""Get the rigidwall data."""
2727+
data = [
2728+
self.type,
2729+
self.center.x,
2730+
self.center.y,
2731+
self.center.z,
2732+
self.orient.x,
2733+
self.orient.y,
2734+
self.orient.z,
2735+
self.radius,
2736+
]
2737+
return data
2738+
26872739
def create(self):
26882740
"""Create a rigidwall sphere."""
26892741
parameter = [
@@ -2710,7 +2762,7 @@ def create(self):
27102762
logging.info("Sphere Rigidwall Created...")
27112763

27122764

2713-
class RigidwallPlanar:
2765+
class RigidwallPlanar(BaseObj):
27142766
"""Defines planar rigid walls with either finite or infinite size.
27152767
27162768
Parameters
@@ -2730,6 +2782,12 @@ def __init__(self, tail=Point(0, 0, 0), head=Point(0, 0, 0), coulomb_friction_co
27302782
self.tail = tail
27312783
self.head = head
27322784
self.fric = coulomb_friction_coefficient
2785+
self.type = "rigidwall_planar"
2786+
2787+
def get_data(self) -> List:
2788+
"""Get the rigidwall data."""
2789+
data = [self.type, self.tail.x, self.tail.y, self.tail.z, self.head.x, self.head.y, self.head.z]
2790+
return data
27332791

27342792
def create(self):
27352793
"""Create planar rigid walls."""
@@ -2753,7 +2811,7 @@ class GravityOption(Enum):
27532811
DIR_Z = "Z"
27542812

27552813

2756-
class Gravity:
2814+
class Gravity(BaseObj):
27572815
"""Defines body force loads using global axes directions.
27582816
27592817
Body force loads are due to a prescribed base acceleration or

src/ansys/dyna/core/pre/dynadem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def save_file(self):
112112
DynaBase.save_file(self)
113113

114114

115-
class DEMAnalysis:
115+
class DEMAnalysis(BaseObj):
116116
"""Activates DEM analysis and defines associated control parameters."""
117117

118118
def __init__(self):

src/ansys/dyna/core/pre/dynaem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def create(self):
719719
return self.id
720720

721721

722-
class RogoCoil:
722+
class RogoCoil(BaseObj):
723723
"""Measures the total current flowing through a given section of the conductor.
724724
725725
Parameters

src/ansys/dyna/core/pre/dynaicfd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class ICFD_CouplingDirection(Enum):
246246
TWO_WAY_WEAK_COUPLING = 3
247247

248248

249-
class ICFDAnalysis:
249+
class ICFDAnalysis(BaseObj):
250250
"""Activates an ICFD analysis and defines associated control parameters."""
251251

252252
def __init__(self):
@@ -733,7 +733,7 @@ def create(self):
733733
return ret
734734

735735

736-
class MeshedVolume:
736+
class MeshedVolume(BaseObj):
737737
"""Defines the volume space to mesh.
738738
739739
Parameters

src/ansys/dyna/core/pre/dynamech.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def save_file(self, defaultsetting=1):
320320
DynaBase.save_file(self)
321321

322322

323-
class Airbag:
323+
class Airbag(BaseObj):
324324
"""Defines an airbag or control volume.
325325
326326
Parameters

src/ansys/dyna/core/pre/dynanvh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ResponseType(Enum):
5555
NODAL_FORCE = 3
5656

5757

58-
class FrequencyDomain:
58+
class FrequencyDomain(BaseObj):
5959
"""Provides a way of defining and solving frequency domain vibration and acoustic problems."""
6060

6161
def __init__(self):

src/ansys/dyna/core/pre/dynasale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, number, position, ratio):
4242
self.ratio = ratio
4343

4444

45-
class StructuredMesh:
45+
class StructuredMesh(BaseObj):
4646
"""Generates a structured 2D or 3D mesh and invokes the S-ALE solver."""
4747

4848
def __init__(self, control_points_x, control_points_y, control_points_z):

src/ansys/dyna/core/pre/dynasolution.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
from ansys.dyna.core.pre.model import Model
2121

22+
# from .kwprocess_pb2 import *
23+
# from .kwprocess_pb2_grpc import *
24+
25+
2226
# from .launcher import * # noqa : F403
2327

2428
CHUNK_SIZE = 1024 * 1024

src/ansys/dyna/core/pre/graphics/graphics.py

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class DisplayMeshType(enum.IntEnum):
1818

1919
FACE = 0
2020
BEAM = 1
21+
CYLINDER = 2
22+
SPHERE = 3
23+
PLANAR = 4
2124

2225

2326
class ColorByType(enum.IntEnum):
@@ -173,7 +176,7 @@ def __init__(self, model: pre.Model, use_trame: bool = False):
173176
"""Initialize graphics."""
174177
self._model = model
175178
self._display_data = {}
176-
self._display_spline_data = {}
179+
self._display_entity_data = {}
177180
self._plotter = None
178181
self._picker = None
179182
self._color_by_type = ColorByType.ZONE
@@ -223,6 +226,15 @@ def __update_display_data(self):
223226
self._display_data[part_id] = data
224227
self._init_velocity_data = self._model.get_init_velocity()
225228
self._bdy_spc = self._model.get_bdy_spc()
229+
# rigidwall
230+
self._display_entity_data.clear()
231+
num = len(self._model._rigidwall)
232+
for entity_id in range(1, num + 1):
233+
data = {}
234+
disp_mesh_data: list[_DisplayMesh] = [self.__get_entity_display_mesh_object(entity_id)]
235+
if len(disp_mesh_data) > 0:
236+
data["faces"] = disp_mesh_data
237+
self._display_entity_data[entity_id] = data
226238

227239
# self._model._sync_up_model()
228240

@@ -259,6 +271,44 @@ def __get_face_display_mesh_object(self, part_id: int):
259271
)
260272
return disp_mesh
261273

274+
def __get_entity_display_mesh_object(self, entity_id: int):
275+
"""Display the faces in an object.
276+
277+
Parameters
278+
----------
279+
entity_id : int
280+
ID of the entity to show the edges on.
281+
282+
Returns
283+
-------
284+
_DisplayMesh
285+
Displayed mesh.
286+
"""
287+
index = entity_id - 1
288+
rw = self._model._rigidwall[index]
289+
type = rw[0]
290+
if type == "rigidwall_cylinder":
291+
meshtype = DisplayMeshType.CYLINDER
292+
mesh = pv.Cylinder(
293+
center=[rw[1], rw[2], rw[3]], direction=[rw[4], rw[5], rw[6]], radius=rw[7], height=rw[8]
294+
)
295+
elif type == "rigidwall_sphere":
296+
meshtype = DisplayMeshType.SPHERE
297+
mesh = pv.Sphere(center=[rw[1], rw[2], rw[3]], direction=[rw[4], rw[5], rw[6]], radius=rw[7])
298+
elif type == "rigidwall_planar":
299+
meshtype = DisplayMeshType.PLANAR
300+
dir = [rw[4] - rw[1], rw[5] - rw[2], rw[6] - rw[3]]
301+
mesh = pv.Plane(center=[rw[1], rw[2], rw[3]], direction=dir, i_size=1000, j_size=1000)
302+
303+
disp_mesh = _DisplayMesh(
304+
type=meshtype,
305+
part_id=entity_id,
306+
graphics=self,
307+
model=self._model,
308+
mesh=mesh,
309+
)
310+
return disp_mesh
311+
262312
def __call__(
263313
self,
264314
parts: List = None,
@@ -519,6 +569,13 @@ def __draw_parts(self, parts: List = [], update: bool = False, spline: bool = Fa
519569
for key, disp_mesh_data in data.items()
520570
for disp_mesh in disp_mesh_data
521571
]
572+
573+
[
574+
disp_mesh.add_to_plotter(self._plotter)
575+
for entity_id, data in self._display_entity_data.items()
576+
for key, disp_mesh_data in data.items()
577+
for disp_mesh in disp_mesh_data
578+
]
522579
if self._sphinx_build == False:
523580
self._colorByTypeBt = self._plotter.add_checkbox_button_widget(
524581
self.__show_bdy_spc_callback,
@@ -739,8 +796,9 @@ def __init__(
739796
part_id: int,
740797
graphics: Graphics,
741798
model: pre.Model,
742-
vertices: np.array,
743-
facet_list: np.array,
799+
vertices: np.array = None,
800+
facet_list: np.array = None,
801+
mesh=None,
744802
part_name: str = "",
745803
):
746804
"""Initialize the parameters to display."""
@@ -750,6 +808,7 @@ def __init__(
750808
self._model = model
751809
self._vertices = vertices
752810
self._facet_list = facet_list
811+
self._mesh = mesh
753812
self._poly_data = None
754813
self._actor = None
755814
self._part_name = part_name
@@ -795,15 +854,21 @@ def add_to_plotter(self, plotter: Plotter):
795854
self._actor = plotter.add_mesh(
796855
self._poly_data, show_edges=True, scalars="colors", rgb=True, pickable=True
797856
)
857+
elif (
858+
self._type is DisplayMeshType.CYLINDER
859+
or self._type is DisplayMeshType.SPHERE
860+
or self._type is DisplayMeshType.PLANAR
861+
):
862+
surf = self._mesh
863+
fcolor = np.array(self.get_face_color())
864+
colors = np.tile(fcolor, (surf.n_faces, 1))
865+
surf["colors"] = colors
866+
surf.disp_mesh = self
867+
self._poly_data = surf
868+
self._actor = plotter.add_mesh(
869+
self._poly_data, show_edges=True, scalars="colors", rgb=True, pickable=True
870+
)
798871
return
799-
lines = []
800-
for line in self._facet_list:
801-
coord = self._vertices[line[1]]
802-
lines.append(coord)
803-
coord = self._vertices[line[2]]
804-
lines.append(coord)
805-
self._poly_data = np.array(lines)
806-
self._actor = plotter.add_lines(self._poly_data, color="purple", width=8)
807872

808873
def get_face_color(self):
809874
"""Get the colors of faces.

0 commit comments

Comments
 (0)