Skip to content

Commit fe979ba

Browse files
authored
Merge pull request #51 from AI-RICE/pl_mg
Added needed function
2 parents d1e23f3 + 9d55cb0 commit fe979ba

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎machine_design/designs/design.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def add_rotor(self) -> None:
4040
def add_rotor_barrier(self, barrier_points, segment_type=None) -> None:
4141
self.geometry.add_rotor_barrier(self.m2d, barrier_points, segment_type)
4242

43+
def add_rotor_magnet(self, magnet_points, segment_type=None) -> None:
44+
self.geometry.add_rotor_magnet(self.m2d, magnet_points, segment_type=segment_type)
45+
4346
def delete_rotor(self) -> None:
4447
self.computation.delete_rotor_mesh()
4548
self.geometry.delete_rotor(self.m2d)

‎machine_design/designs/geometry.py‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,81 @@ def _assign_boundary_conditions(self, m2d: Maxwell2d) -> None:
193193
assignment="Region",
194194
)
195195
m2d.assign_vector_potential(assignment=id_bc_az, vector_value=0, boundary="A0")
196+
197+
def add_rotor_magnet(self, m2d: Maxwell2d, mag: np.ndarray, fill_height=0.9, fill_width=0.9, segment_type=None):
198+
modeler = m2d.modeler
199+
200+
if isinstance(mag, (list, tuple)):
201+
mag = np.concatenate([np.asarray(m) for m in mag], axis=0)
202+
203+
pts = np.asarray(mag)
204+
center = pts.mean(axis=0)
205+
206+
r = np.linalg.norm(center)
207+
if r < 1e-10:
208+
return
209+
210+
radial = center / r
211+
long_axis = np.array([-radial[1], radial[0]])
212+
213+
pts_centered = pts - center
214+
215+
proj_long = pts_centered @ long_axis
216+
proj_short = pts_centered @ radial
217+
218+
pts_scaled = center + (np.outer(proj_long * fill_height, long_axis) + np.outer(proj_short * fill_width, radial))
219+
220+
points = [[f"{x}mm", f"{y}mm", "0mm"] for x, y in pts_scaled]
221+
222+
mag_id = modeler.create_polyline(
223+
points=points,
224+
close_surface=True,
225+
cover_surface=True,
226+
name="Magnet",
227+
)
228+
cs_angle_deg = np.degrees(np.arctan2(radial[1], radial[0]))
229+
230+
self.assign_magnet_cs(m2d, mag_id, cs_angle_deg)
231+
mag_id.material_name = self.magnet
232+
mag_id.solve_inside = True
233+
mag_id.color = (255, 0, 0)
234+
mag_id.transparency = 0.0
235+
236+
modeler.set_working_coordinate_system("Global")
237+
238+
def _create_magnet_cs(self, m2d: Maxwell2d, name: str, angle_deg: float) -> None:
239+
m2d.modeler.create_coordinate_system(
240+
origin=[0, 0, 0],
241+
name=name,
242+
mode="axis",
243+
x_pointing=[float(np.cos(np.radians(angle_deg))), float(np.sin(np.radians(angle_deg))), 0],
244+
y_pointing=[float(-np.sin(np.radians(angle_deg))), float(np.cos(np.radians(angle_deg))), 0],
245+
)
246+
247+
def assign_magnet_cs(self, m2d: Maxwell2d, magnet_name: str, angle_deg: float) -> None:
248+
cs_name = f"CS_{magnet_name}"
249+
self._create_magnet_cs(m2d, cs_name, angle_deg)
250+
m2d.modeler[magnet_name].part_coordinate_system = cs_name
251+
252+
def _create_material(
253+
self,
254+
m2d: Maxwell2d,
255+
name: str,
256+
permeability: float,
257+
conductivity: float,
258+
density: float,
259+
coercivity: float | None = None,
260+
coercivity_dir: tuple[float, float, float] = (0.0, 0.0, 0.0),
261+
):
262+
if name.lower() in m2d.materials.material_keys:
263+
return m2d.materials[name]
264+
265+
mat = m2d.materials.add_material(name)
266+
mat.permeability = permeability
267+
mat.conductivity = conductivity
268+
mat.mass_density = density
269+
270+
if coercivity is not None:
271+
mat.set_magnetic_coercivity(value=coercivity, x=coercivity_dir[0], y=coercivity_dir[1], z=coercivity_dir[2])
272+
273+
return mat

‎motors/synrm_3f_36s_mag.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Anchor `synrm_3f_36s`: 3-phase synchronous reluctance machine, 36 stator slots."""
2+
3+
from ansys.aedt.core import Maxwell2d
4+
5+
from motors.synrm_3f_36s import Computation as Computation3f36s
6+
from motors.synrm_3f_36s import Geometry as Geometry3f36s
7+
8+
__all__ = ["Geometry", "Computation"]
9+
10+
11+
class Geometry(Geometry3f36s):
12+
def build_stator(self, m2d: Maxwell2d) -> None:
13+
super().build_stator(m2d)
14+
self.set_magnets()
15+
self._create_material(m2d, self.magnet, **self.magnet_props)
16+
17+
def set_magnets(self):
18+
self.magnet = "NdFeb"
19+
self.magnet_props = dict(permeability=1.05, conductivity=0, density=7500, coercivity=900000, coercivity_dir=(1.0, 0.0, 0.0))
20+
21+
22+
class Computation(Computation3f36s):
23+
pass

0 commit comments

Comments
 (0)