Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skip ci] added another animation style #212

Merged
merged 4 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/auto_format_pep8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
pip install black==22.1.0
- name: Run black
run: |
black . --line-length=120
black .
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip ci] Apply formatting changes"
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ def create_reactor_renders(
render_mesh = pyrender.Mesh.from_trimesh(trimesh_obj, smooth=False)
scene.add(render_mesh)

camera = pyrender.camera.PerspectiveCamera(
yfov=math.radians(90.0) # aspectRatio=2.0 could be added here
)
camera = pyrender.camera.PerspectiveCamera(yfov=math.radians(90.0)) # aspectRatio=2.0 could be added here

# sets the position of the camera using a matrix
cam = 2**-0.5
camera_pose = np.array(
[[1, 0, 0, 0], [0, cam, -cam, -350], [0, cam, cam, 350], [0, 0, 0, 1]]
)
camera_pose = np.array([[1, 0, 0, 0], [0, cam, -cam, -350], [0, cam, cam, 350], [0, 0, 0, 1]])

# adds a camera and a point light source at the same location
scene.add(camera, pose=camera_pose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This examples creates Gif animation of 50 reactors by creating individual
# images of reactors and stiching them together using Imagemagick into a Gif
# animation.
# animation. Two animations are made, of of a 3D render and one of a wireframe
# line drawing.

import math
import os
Expand Down Expand Up @@ -40,7 +41,8 @@ def create_reactor_renders(
lower_vv_thickness=10,
)

# saves the reactor geometry as separate stl files
# saves the reactor geometry as separate stl files that are later read in
# for the rendering
my_reactor.export_stl()

# assigns colours to each stl file
Expand All @@ -64,15 +66,11 @@ def create_reactor_renders(
render_mesh = pyrender.Mesh.from_trimesh(trimesh_obj, smooth=False)
scene.add(render_mesh)

camera = pyrender.camera.PerspectiveCamera(
yfov=math.radians(90.0) # aspectRatio=2.0 could be added here
)
camera = pyrender.camera.PerspectiveCamera(yfov=math.radians(90.0)) # aspectRatio=2.0 could be added here

# sets the position of the camera using a matrix
cam = 2**-0.5
camera_pose = np.array(
[[1, 0, 0, 0], [0, cam, -cam, -350], [0, cam, cam, 350], [0, 0, 0, 1]]
)
camera_pose = np.array([[1, 0, 0, 0], [0, cam, -cam, -350], [0, cam, cam, 350], [0, 0, 0, 1]])

# adds a camera and a point light source at the same location
scene.add(camera, pose=camera_pose)
Expand Down Expand Up @@ -103,5 +101,6 @@ def create_reactor_renders(
blanket_vv_gap=np.random.uniform(low=10, high=90),
)

# saves the plot as a gif, the convert comand requires imagemagick
os.system("convert -delay 20 -loop 0 render_*.png reactors.gif")
# The convert comand requires imagemagick
# saves the rendered png files as a gif
os.system("convert -delay 40 -loop 0 render_*.png reactors.gif")
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ def generate_random_reactor():
if input_arg in my_reactor.__dict__:
if isinstance(my_reactor.__dict__[input_arg], float):
rand_scale = random.uniform(0.8, 1.2)
setattr(
my_reactor, input_arg, my_reactor.__dict__[input_arg] * rand_scale
)
setattr(my_reactor, input_arg, my_reactor.__dict__[input_arg] * rand_scale)

return my_reactor


def create_reactor_renders(
render_number, number_of_images_in_x, number_of_images_in_y, reactor
):
def create_reactor_renders(render_number, number_of_images_in_x, number_of_images_in_y, reactor):

# saves the reactor geometry as separate stl files
reactor.export_stl()
Expand All @@ -78,15 +74,11 @@ def create_reactor_renders(
render_mesh = pyrender.Mesh.from_trimesh(trimesh_obj, smooth=False)
scene.add(render_mesh)

camera = pyrender.camera.PerspectiveCamera(
yfov=math.radians(90.0) # aspectRatio=2.0 could be added here
)
camera = pyrender.camera.PerspectiveCamera(yfov=math.radians(90.0)) # aspectRatio=2.0 could be added here

# sets the position of the camera using a matrix
cam = 2**-0.5
camera_pose = np.array(
[[1, 0, 0, 0], [0, cam, -cam, -650], [0, cam, cam, 650], [0, 0, 0, 1]]
)
camera_pose = np.array([[1, 0, 0, 0], [0, cam, -cam, -650], [0, cam, cam, 650], [0, 0, 0, 1]])

# adds a camera and a point light source at the same location
scene.add(camera, pose=camera_pose)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This examples creates Gif animation of 50 reactors by creating individual
# images of reactors and stiching them together using Imagemagick into a Gif
# animation. Two animations are made, of of a 3D render and one of a wireframe
# line drawing.

import math
import os

# to run this example you will need all of the following packages installed
import matplotlib.pyplot as plt
import numpy as np
import paramak

import svgwrite # required to write text to svg file
import svgutils.transform as sg # required to merge text svg files with wireframe svg file


def create_reactor_renders(
render_number,
inner_blanket_radius,
blanket_thickness,
blanket_height,
lower_blanket_thickness,
upper_blanket_thickness,
blanket_vv_gap,
upper_vv_thickness=10,
vv_thickness=10,
lower_vv_thickness=10,
):

# creates a reactor from the input arguments
my_reactor = paramak.FlfSystemCodeReactor(
rotation_angle=180,
inner_blanket_radius=inner_blanket_radius,
blanket_thickness=blanket_thickness,
blanket_height=blanket_height,
lower_blanket_thickness=lower_blanket_thickness,
upper_blanket_thickness=upper_blanket_thickness,
blanket_vv_gap=blanket_vv_gap,
upper_vv_thickness=upper_vv_thickness,
vv_thickness=vv_thickness,
lower_vv_thickness=lower_vv_thickness,
)

# exports line drawing of individual reactor
my_reactor.export_svg(
f"wireframe_{str(render_number).zfill(3)}.svg",
projectionDir=[1, -1, -0.1],
strokeWidth=2,
width=1000,
height=800,
)

svg_file_object = svgwrite.Drawing(
filename=f"text_{str(render_number).zfill(3)}.svg",
size=("1000px", "800px"),
)

lines_of_text_to_write = [
"Parametric reactor inputs",
f"Inner blanket radius {inner_blanket_radius/100:.1f}m",
f"Blanket thickness {blanket_thickness/100:.1f}m",
f"Blanket thickness {blanket_thickness/100:.1f}m",
f"Blanket height {blanket_height/100:.1f}m",
f"Lower blanket thickness {lower_blanket_thickness/100:.1f}m",
f"Upper blanket thickness {upper_blanket_thickness/100:.1f}m",
f"Blanket vv gap {blanket_vv_gap/100:.1f}m",
f"Upper vv thickness {upper_vv_thickness/100:.1f}m",
f"Vv thickness {vv_thickness/100:.1f}m",
f"Lower vv thickness {lower_vv_thickness/100:.1f}m",
]
y_value = 50
for line in lines_of_text_to_write:
y_value = y_value + 40
svg_file_object.add(svg_file_object.text(line, insert=(555, y_value), font_size=27))
svg_file_object.save()

background = sg.fromfile(f"wireframe_{str(render_number).zfill(3)}.svg")
forground = sg.fromfile(f"text_{str(render_number).zfill(3)}.svg")

root = forground.getroot()
background.append([root])

background.save(f"combined_{str(render_number).zfill(3)}.svg")


# loops through adding a random reactor render to the figure with each iteration
for i in range(50):
create_reactor_renders(
render_number=i,
inner_blanket_radius=np.random.uniform(low=50, high=90),
blanket_thickness=np.random.uniform(low=50, high=140),
blanket_height=np.random.uniform(low=400, high=550),
lower_blanket_thickness=np.random.uniform(low=20, high=70),
upper_blanket_thickness=np.random.uniform(low=20, high=70),
blanket_vv_gap=np.random.uniform(low=10, high=90),
)

# The convert comand requires imagemagick
# saves the line drawing svg files as a gif
os.system("convert -delay 40 -loop 0 combined_*.svg reactors_with_parameters.gif")
7 changes: 1 addition & 6 deletions paramak/parametric_components/blanket_cutter_parallels.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ def __init__(
)
self.gap_size = gap_size
self.thickness = thickness
super().__init__(
distance=self.distance,
azimuth_placement_angle=azimuth_placement_angle,
name=name,
**kwargs
)
super().__init__(distance=self.distance, azimuth_placement_angle=azimuth_placement_angle, name=name, **kwargs)
self.height = height
self.width = width

Expand Down
6 changes: 1 addition & 5 deletions paramak/parametric_components/blanket_cutters_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def __init__(
) -> None:

super().__init__(
extrude_both=True,
name=name,
azimuth_placement_angle=azimuth_placement_angle,
distance=distance,
**kwargs
extrude_both=True, name=name, azimuth_placement_angle=azimuth_placement_angle, distance=distance, **kwargs
)

self.azimuth_placement_angle = azimuth_placement_angle
Expand Down
22 changes: 5 additions & 17 deletions paramak/parametric_components/blanket_fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def __init__(
thickness,
start_angle: float,
stop_angle: float,
plasma: Optional[
Union[paramak.Plasma, paramak.PlasmaBoundaries, paramak.PlasmaFromPoints]
] = None,
plasma: Optional[Union[paramak.Plasma, paramak.PlasmaBoundaries, paramak.PlasmaFromPoints]] = None,
minor_radius: Optional[float] = 150.0,
major_radius: Optional[float] = 450.0,
triangularity: Optional[float] = 0.55,
Expand Down Expand Up @@ -155,9 +153,7 @@ def make_callable(self, attribute):
else:
# no list of angles is given
offset_values = attribute
list_of_angles = np.linspace(
self.start_angle, self.stop_angle, len(offset_values), endpoint=True
)
list_of_angles = np.linspace(self.start_angle, self.stop_angle, len(offset_values), endpoint=True)
interpolated_values = interp1d(list_of_angles, offset_values)

def fun(theta):
Expand Down Expand Up @@ -202,10 +198,7 @@ def outer_offset(theta):
# assemble
points = inner_points + outer_points
if self._overlapping_shape and self.allow_overlapping_shape is False:
msg = (
"BlanketFP: Some points with negative R coordinate have "
"been ignored."
)
msg = "BlanketFP: Some points with negative R coordinate have " "been ignored."
warnings.warn(msg)

self.points = points
Expand Down Expand Up @@ -273,11 +266,6 @@ def distribution(self, theta, pkg=np):
theta = np.radians(theta)
else:
theta = mpmath.radians(theta)
R = self.major_radius + self.minor_radius * pkg.cos(
theta + self.triangularity * pkg.sin(theta)
)
Z = (
self.elongation * self.minor_radius * pkg.sin(theta)
+ self.vertical_displacement
)
R = self.major_radius + self.minor_radius * pkg.cos(theta + self.triangularity * pkg.sin(theta))
Z = self.elongation * self.minor_radius * pkg.sin(theta) + self.vertical_displacement
return R, Z
22 changes: 5 additions & 17 deletions paramak/parametric_components/blanket_poloidal_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@ def segments_angles(self):
def segments_angles(self, value):
if value is not None:
if self.start_angle is not None or self.stop_angle is not None:
msg = (
"start_angle and stop_angle attributes will be "
+ "ignored if segments_angles is not None"
)
msg = "start_angle and stop_angle attributes will be " + "ignored if segments_angles is not None"
warnings.warn(msg)
elif self.num_segments is not None:
msg = (
"num_segment attribute will be ignored if "
+ "segments_angles is not None"
)
msg = "num_segment attribute will be ignored if " + "segments_angles is not None"
warnings.warn(msg)
self._segments_angles = value

Expand Down Expand Up @@ -100,9 +94,7 @@ def get_angles(self):
stop_on_success=True,
)
elif self.segments_angles is None:
angles = np.linspace(
self.start_angle, self.stop_angle, num=self.num_segments + 1
)
angles = np.linspace(self.start_angle, self.stop_angle, num=self.num_segments + 1)
else:
angles = self.segments_angles
return angles
Expand Down Expand Up @@ -152,9 +144,7 @@ def create_segment_cutters(self):
]

# Create cutters for each gap
for inner_point, outer_point in zip(
self.inner_points[:-1], self.outer_points[-1::-1]
):
for inner_point, outer_point in zip(self.inner_points[:-1], self.outer_points[-1::-1]):
# initialise cutter for gap
cutter = RotateStraightShape(
rotation_angle=self.rotation_angle,
Expand Down Expand Up @@ -205,9 +195,7 @@ def compute_lengths_from_angles(angles: List[float], distribution: Callable):
return lengths


def segments_optimiser(
length_limits, nb_segments_limits, distribution, angles, stop_on_success=True
):
def segments_optimiser(length_limits, nb_segments_limits, distribution, angles, stop_on_success=True):
"""Optimiser segmenting a given R(theta), Z(theta) distribution of points
with constraints regarding the number of segments and the length of the
segments.
Expand Down
18 changes: 3 additions & 15 deletions paramak/parametric_components/capsule_vacuum_vessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def radius(self, value):
if not isinstance(value, (float, int)):
raise ValueError("VacuumVessel.radius must be a number. Not", value)
if value <= 0:
msg = (
"VacuumVessel.radius must be a positive number above 0. " f"Not {value}"
)
msg = "VacuumVessel.radius must be a positive number above 0. " f"Not {value}"
raise ValueError(msg)
self._radius = value

Expand All @@ -54,9 +52,7 @@ def thickness(self, value):
msg = f"VacuumVessel.thickness must be a number. Not {value}"
raise ValueError(msg)
if value <= 0:
msg = (
f"VacuumVessel.thickness must be a positive number above 0. Not {value}"
)
msg = f"VacuumVessel.thickness must be a positive number above 0. Not {value}"
raise ValueError(msg)
self._thickness = value

Expand All @@ -72,15 +68,7 @@ def find_points(self):
top_outer_y = bottom_outer_y + (4 * radius)
top_outer_x = bottom_outer_x
inner_r = radius - thickness
(
bottom_outer_x,
bottom_outer_y,
thickness,
radius,
top_outer_x,
top_outer_y,
inner_r,
) = (
(bottom_outer_x, bottom_outer_y, thickness, radius, top_outer_x, top_outer_y, inner_r,) = (
float(bottom_outer_x),
float(bottom_outer_y),
float(thickness),
Expand Down
Loading