Coverage for src/meshpy/core/conf.py: 99%
75 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-14 04:22 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-14 04:22 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2018-2025 MeshPy Authors
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22"""This module defines a global object that manages all kind of stuff regarding
23meshpy."""
25from enum import Enum as _Enum
26from enum import auto as _auto
29class Geometry(_Enum):
30 """Enum for geometry types."""
32 point = _auto()
33 line = _auto()
34 surface = _auto()
35 volume = _auto()
38class BoundaryCondition(_Enum):
39 """Enum for boundary condition types."""
41 dirichlet = _auto()
42 neumann = _auto()
43 locsys = _auto()
44 moment_euler_bernoulli = _auto()
45 beam_to_beam_contact = _auto()
46 beam_to_solid_volume_meshtying = _auto()
47 beam_to_solid_surface_meshtying = _auto()
48 beam_to_solid_surface_contact = _auto()
49 point_coupling = _auto()
50 point_coupling_penalty = _auto()
52 def is_point_coupling_pairwise(self) -> bool:
53 """Check whether the point coupling condition should be applied
54 pairwise.
56 Returns:
57 bool: True if the coupling should be applied individually between pairs of nodes,
58 rather than to the entire geometry set as a whole.
59 """
60 if self == self.point_coupling:
61 return False
62 elif self == self.point_coupling_penalty:
63 return True
64 else:
65 raise TypeError(f"Got unexpected coupling type: {self}")
68class BeamType(_Enum):
69 """Enum for beam types."""
71 reissner = _auto()
72 kirchhoff = _auto()
73 euler_bernoulli = _auto()
76class CouplingDofType(_Enum):
77 """Enum for coupling types."""
79 fix = _auto()
80 joint = _auto()
83class BeamToSolidInteractionType(_Enum):
84 """Enum for beam-to-solid interaction types."""
86 volume_meshtying = _auto()
87 surface_meshtying = _auto()
90class DoubleNodes(_Enum):
91 """Enum for handing double nodes in Neumann conditions."""
93 remove = _auto()
94 keep = _auto()
97class GeometricSearchAlgorithm(_Enum):
98 """Enum for VTK value types."""
100 automatic = _auto()
101 brute_force_cython = _auto()
102 binning_cython = _auto()
103 boundary_volume_hierarchy_arborx = _auto()
106class VTKGeometry(_Enum):
107 """Enum for VTK geometry types (for now cells and points)."""
109 point = _auto()
110 cell = _auto()
113class VTKTensor(_Enum):
114 """Enum for VTK tensor types."""
116 scalar = _auto()
117 vector = _auto()
120class VTKType(_Enum):
121 """Enum for VTK value types."""
123 int = _auto()
124 float = _auto()
127class MeshPy(object):
128 """A global object that stores options for the whole MeshPy application."""
130 def __init__(self):
131 self.set_default_values()
133 # Geometry types.
134 self.geo = Geometry
136 # Boundary conditions types.
137 self.bc = BoundaryCondition
139 # Beam types.
140 self.beam = BeamType
142 # Beam-to-solid interaction types.
143 self.beam_to_solid = BeamToSolidInteractionType
145 # Coupling types.
146 self.coupling_dof = CouplingDofType
148 # Handling of multiple nodes in Neumann bcs.
149 self.double_nodes = DoubleNodes
151 # Geometric search options.
152 self.geometric_search_algorithm = GeometricSearchAlgorithm
154 # VTK types.
155 # Geometry types, cell or point.
156 self.vtk_geo = VTKGeometry
157 # Tensor types, scalar or vector.
158 self.vtk_tensor = VTKTensor
159 # Data types, integer or float.
160 self.vtk_type = VTKType
162 def set_default_values(self):
163 """Set the configuration to the default values."""
165 # Set the epsilons for comparison of different types of values.
166 self.eps_quaternion = 1e-10
167 self.eps_pos = 1e-10
168 self.eps_knot_vector = 1e-10
170 # Allow the rotation of beams when connected and the triads do not
171 # match.
172 self.allow_beam_rotation = True
174 # Number of digits for node set output (this will be set in the
175 # Mesh.get_unique_geometry_sets() method.
176 self.vtk_node_set_format = "{:05}"
177 # Nan values for vtk data, since we currently can't set nan explicitly.
178 self.vtk_nan_int = -1
179 self.vtk_nan_float = 0.0
181 # Check for overlapping elements when creating an input file.
182 self.check_overlapping_elements = True
184 # Lines to be added to each created input file
185 self.input_file_meshpy_header = [
186 "-" * 40,
187 "This input file was created with MeshPy.",
188 "Copyright (c) 2018-2025 MeshPy Authors",
189 "https://imcs-compsim.github.io/meshpy/",
190 "-" * 40,
191 ]
194mpy = MeshPy()