Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/zzqbranch'
Browse files Browse the repository at this point in the history
  • Loading branch information
wenhuiuy committed Mar 4, 2024
2 parents 76a7f73 + c0fc555 commit 9fc2058
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 26 deletions.
70 changes: 65 additions & 5 deletions src/ansys/dyna/core/pre/dynabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from ansys.api.dyna.v0.kwprocess_pb2 import * # noqa : F403
from ansys.api.dyna.v0.kwprocess_pb2_grpc import * # noqa : F403

# from .kwprocess_pb2 import *
# from .kwprocess_pb2_grpc import *


class Motion(Enum):
VELOCITY = 0
Expand Down Expand Up @@ -259,6 +262,18 @@ def __init__(self, x=0, y=0, z=0):
self.z = z


class BaseObj:
"""Define the base object."""

def __init__(self):
self.type = ""
self.subtype = ""

def get_data(self) -> List:
"""Get the data of the object."""
return None


class DynaBase:
"""Contains methods for creating a general LS-DYNA keyword."""

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

def add(self, obj):
"""Add entities to an object."""

if obj.type == "rigidwall_cylinder" or obj.type == "rigidwall_sphere" or obj.type == "rigidwall_planar":
data = obj.get_data()
if data != None:
model = self._parent.model
model.add_rigidwall(data)
self.entities.append(obj)

def set_transform(self, filename=None, idnoff=0, ideoff=0, idpoff=0, idmoff=0, idsoff=0, idfoff=0, transform=None):
Expand Down Expand Up @@ -1788,14 +1809,15 @@ class ThermalAnalysisTimestep(Enum):
VARIABLE = 1


class ThermalAnalysis:
class ThermalAnalysis(BaseObj):
"""Activates thermal analysis and defines associated control parameters."""

def __init__(self):
self.defined_solver = False
self.defined_timestep = False
self.defined_nonlinear = False
self.stub = DynaBase.get_stub()
self.type = "analysis_thermal"

def set_timestep(self, timestep_control=ThermalAnalysisTimestep.FIXED, initial_timestep=0):
"""Set time step controls for the thermal solution in a thermal only or coupled structural/thermal analysis.
Expand Down Expand Up @@ -2591,7 +2613,7 @@ def create(self):
logging.info(f"Define temperature at {type} {id}.")


class RigidwallCylinder:
class RigidwallCylinder(BaseObj):
"""Defines a rigid wall with a cylinder form.
Parameters
Expand All @@ -2617,6 +2639,7 @@ def __init__(self, tail=Point(0, 0, 0), head=Point(0, 0, 0), radius=1, length=10
self.motion = -1
self.lcid = 0
self.dir = Direction(1, 0, 0)
self.type = "rigidwall_cylinder"

def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
"""Set the prescribed motion."""
Expand All @@ -2625,6 +2648,21 @@ def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
self.motion = motion.value
self.dir = dir

def get_data(self) -> List:
"""Get the rigidwall data."""
data = [
self.type,
self.tail.x,
self.tail.y,
self.tail.z,
self.head.x,
self.head.y,
self.head.z,
self.radius,
self.length,
]
return data

def create(self):
"""Create a rigidwall cylinder."""
parameter = [
Expand Down Expand Up @@ -2652,7 +2690,7 @@ def create(self):
logging.info("Cylinder Rigidwall Created...")


class RigidwallSphere:
class RigidwallSphere(BaseObj):
"""Defines a rigid wall with a sphere form.
Parameters
Expand All @@ -2676,6 +2714,7 @@ def __init__(self, center=Point(0, 0, 0), orient=Point(0, 0, 0), radius=1):
self.motion = -1
self.lcid = 0
self.dir = Direction(1, 0, 0)
self.type = "rigidwall_sphere"

def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
"""Set the prescribed motion."""
Expand All @@ -2684,6 +2723,20 @@ def set_motion(self, curve, motion=RWMotion.VELOCITY, dir=Direction(1, 0, 0)):
self.motion = motion.value
self.dir = dir

def get_data(self) -> List:
"""Get the rigidwall data."""
data = [
self.type,
self.center.x,
self.center.y,
self.center.z,
self.orient.x,
self.orient.y,
self.orient.z,
self.radius,
]
return data

def create(self):
"""Create a rigidwall sphere."""
parameter = [
Expand All @@ -2710,7 +2763,7 @@ def create(self):
logging.info("Sphere Rigidwall Created...")


class RigidwallPlanar:
class RigidwallPlanar(BaseObj):
"""Defines planar rigid walls with either finite or infinite size.
Parameters
Expand All @@ -2730,6 +2783,12 @@ def __init__(self, tail=Point(0, 0, 0), head=Point(0, 0, 0), coulomb_friction_co
self.tail = tail
self.head = head
self.fric = coulomb_friction_coefficient
self.type = "rigidwall_planar"

def get_data(self) -> List:
"""Get the rigidwall data."""
data = [self.type, self.tail.x, self.tail.y, self.tail.z, self.head.x, self.head.y, self.head.z]
return data

def create(self):
"""Create planar rigid walls."""
Expand All @@ -2753,7 +2812,7 @@ class GravityOption(Enum):
DIR_Z = "Z"


class Gravity:
class Gravity(BaseObj):
"""Defines body force loads using global axes directions.
Body force loads are due to a prescribed base acceleration or
Expand All @@ -2764,6 +2823,7 @@ def __init__(self, dir=GravityOption.DIR_Z, load=Curve(x=[0, 0], y=[0, 0])):
self.stub = DynaBase.get_stub()
self.dir = dir.value
self.load = load
self.type = "gravity"

def create(self):
"""Define a body force."""
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dyna/core/pre/dynadem.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ def save_file(self):
DynaBase.save_file(self)


class DEMAnalysis:
class DEMAnalysis(BaseObj):
"""Activates DEM analysis and defines associated control parameters."""

def __init__(self):
self.defined_des = False
self.stub = DynaBase.get_stub()
self.type = "analysis_dem"

def set_des(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dyna/core/pre/dynaem.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def create(self):
return self.id


class RogoCoil:
class RogoCoil(BaseObj):
"""Measures the total current flowing through a given section of the conductor.
Parameters
Expand All @@ -732,6 +732,7 @@ def __init__(self, set=None):
self.stub = DynaBase.get_stub()
self.set = set
self.id = 0
self.type = "rogocoil"

def create(self):
"""Create a Rogowsky coil."""
Expand Down
6 changes: 4 additions & 2 deletions src/ansys/dyna/core/pre/dynaicfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class ICFD_CouplingDirection(Enum):
TWO_WAY_WEAK_COUPLING = 3


class ICFDAnalysis:
class ICFDAnalysis(BaseObj):
"""Activates an ICFD analysis and defines associated control parameters."""

def __init__(self):
Expand All @@ -260,6 +260,7 @@ def __init__(self):
self.defined_coupling_dem = False
self.defined_mesh_adapt = False
self.stub = DynaBase.get_stub()
self.type = "analysis_icfd"

def set_type(self, analysis_type=ICFD_AnalysisType.TRANSIENT_ANALYSIS):
"""Set the type of the CFD analysis.
Expand Down Expand Up @@ -733,7 +734,7 @@ def create(self):
return ret


class MeshedVolume:
class MeshedVolume(BaseObj):
"""Defines the volume space to mesh.
Parameters
Expand All @@ -749,6 +750,7 @@ def __init__(self, surfaces):
self.embeded_surf = []
self.meshsize_surf = []
self.fluid_interfaces = []
self.type = "meshedvolume"

def embed_shell(self, embeded):
"""Define surfaces that the mesher is to embed inside the volume mesh.
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dyna/core/pre/dynamech.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def save_file(self, defaultsetting=1):
DynaBase.save_file(self)


class Airbag:
class Airbag(BaseObj):
"""Defines an airbag or control volume.
Parameters
Expand Down Expand Up @@ -377,6 +377,7 @@ def __init__(
self.sidtyp = 0
else:
self.sidtyp = 1
self.type = "airbag"

def create(self):
"""Create an airbag."""
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dyna/core/pre/dynanvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class ResponseType(Enum):
NODAL_FORCE = 3


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

def __init__(self):
self.stub = DynaBase.get_stub()
self.defined_frf = False
self.type = "frequency_domain"

def set_frequency_response_function(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dyna/core/pre/dynasale.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, number, position, ratio):
self.ratio = ratio


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

def __init__(self, control_points_x, control_points_y, control_points_z):
Expand All @@ -54,6 +54,7 @@ def __init__(self, control_points_x, control_points_y, control_points_z):
self.refine_factor_y = 1
self.refine_factor_z = 1
self.fillings = []
self.type = "structured_mesh"

def fill(
self,
Expand Down
4 changes: 4 additions & 0 deletions src/ansys/dyna/core/pre/dynasolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

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

# from .kwprocess_pb2 import *
# from .kwprocess_pb2_grpc import *


# from .launcher import * # noqa : F403

CHUNK_SIZE = 1024 * 1024
Expand Down
Loading

0 comments on commit 9fc2058

Please sign in to comment.