bluemira.geometry.parameterisations
Geometry parameterisations
Classes
A geometry parameterisation class facilitating geometry optimisation. |
|
Princeton D geometry parameterisation, with n_TF = ∞. |
|
Princeton D geometry parameterisation, with finite n_TF. |
|
Triple-arc up-down symmetric geometry parameterisation. |
|
Sextuple-arc up-down asymmetric geometry parameterisation. |
|
Simon McIntosh's Poly-Bézier-spline geometry parameterisation (19 variables). |
|
Tools Class containing methods to produce various PictureFrame variant limbs. |
|
Picture Frame sections |
|
Picture-frame geometry parameterisation. |
Module Contents
- class bluemira.geometry.parameterisations.GeometryParameterisation(variables: OptVariablesFrameT, **kwargs)
Bases:
abc.ABC,Generic[OptVariablesFrameT]A geometry parameterisation class facilitating geometry optimisation.
Notes
Subclass this base class when making a new GeometryParameterisation, adding a set of variables with initial values, and override the create_shape method.
- Parameters:
variables (OptVariablesFrameT)
- __slots__ = ('_variables', 'name')
- name = 'GeometryParameterisation'
- _variables
- property n_ineq_constraints: int
Number of inequality constraints in the GeometryParameterisation
- Return type:
int
- property variables: OptVariablesFrameT
The variables of the GeometryParameterisation
- Return type:
OptVariablesFrameT
- adjust_variable(name: str, value: float | None = None, lower_bound: float | None = None, upper_bound: float | None = None)
Adjust a variable in the GeometryParameterisation.
- Parameters:
name (str) – Name of the variable to adjust
value (float | None) – Value of the variable to set
lower_bound (float | None) – Value of the lower bound to set
upper_bound (float | None) – Value of the upper to set
- fix_variable(name: str, value: float | None = None)
Fix a variable in the GeometryParameterisation, removing it from optimisation but preserving a constant value.
- Parameters:
name (str) – Name of the variable to fix
value (float | None) – Value at which to fix the variable (will default to present value)
- f_ineq_constraint()
Inequality constraint function for the variable vector of the geometry parameterisation. This is used when internal consistency between different un-fixed variables is required.
- Raises:
GeometryParameterisationError – No inequality constraints
- property tolerance: numpy.typing.NDArray[numpy.float64]
Optimisation tolerance for the geometry parameterisation.
- Return type:
numpy.typing.NDArray[numpy.float64]
- get_x_norm_index(name: str) int
Get the index of a variable name in the modified-length x_norm vector
- Parameters:
name (str) – Variable name for which to get the index
- Return type:
Index of the variable name in the modified-length x_norm vector
- process_x_norm_fixed(x_norm: numpy.typing.NDArray[numpy.float64]) list[float]
Utility for processing a set of free, normalised variables, and folding the fixed un-normalised variables back into a single list of all actual values.
- Parameters:
x_norm (numpy.typing.NDArray[numpy.float64]) – Normalised vector of variable values
- Return type:
List of ordered actual (un-normalised) values
- abstract create_shape(label: str = '') bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the geometry.
- Parameters:
label (str) – Label to give the wire
- Returns:
CAD Wire of the geometry
- Return type:
- to_json(file: str)
Write the json representation of the GeometryParameterisation to a file.
- Parameters:
file (str) – The path to the file.
- classmethod from_json(file: pathlib.Path | str | TextIO) GeometryParameterisation
Create the GeometryParameterisation from a json file.
- Parameters:
file (pathlib.Path | str | TextIO) – The path to the file, or an open file handle that supports reading.
- Returns:
The GeometryParameterisation from a json file.
- Return type:
- static _annotator(ax: matplotlib.pyplot.Axes, key: str, xy1: tuple[float, float], xy2: tuple[float, float], xy3: tuple[float, float], arrowstyle: str = '<|-')
Create annotation arrow with label
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
key (str) – label of annotation
xy1 (tuple[float, float]) – Tuple for first arrow point
xy2 (tuple[float, float]) – Tuple for second arrow point
xy3 (tuple[float, float]) – Tuple for arrow label location
arrowstyle (str)
- static _angle_annotator(ax: matplotlib.pyplot.Axes, key: str, radius: float, centre: tuple[float, float], angles: tuple[float, float], centre_angle: float)
Create annotation arrow with label
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
key (str) – label of annotation
radius (float) – radius of arrow
centre (tuple[float, float]) – centre coordinate of arrow
angles (tuple[float, float])
centre_angle (float)
- static _draw_angle_annotation(ax, start_angle: float, angle: float, label: str, origin: tuple[float, float] = (0, 0), length: float = 1.0, arc_radius: float = 0.3, label_offset: float = 0.1)
Draw two lines forming an angle, an arc for the angle, and a label.
- Parameters:
ax – The axis to draw on.
start_angle (float) – angle of the first line
angle (float) – Angle in degrees for the second line (measured from horizontal).
label (str) – Label of angle
origin (tuple[float, float]) – (x, y) coordinates of the starting point.
length (float) – Length of the lines.
arc_radius (float) – Radius of the arc showing the angle.
label_offset (float) – Offset for the angle label.
- _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) tuple[float, float]
Adds labels to parameterisation plots
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
shape (bluemira.geometry.wire.BluemiraWire) – parameterisation wire
- Returns:
offset_ar_x – Suggested location for where to plot the next set of labels related to the radii in the parameterisation. (z-coordinates only)
offset_ar_z – Suggested location for where to plot the next set of labels related to the height in the parameterisation. (x-coordinates only)
- Return type:
tuple[float, float]
- plot(ax=None, *, labels=False, **kwargs)
Plot the geometry parameterisation
- Parameters:
ax (Optional[Axes]) – Matplotlib axes object
labels (bool) – Label variables on figure
kwargs (Dict) – Passed to matplotlib Axes.plot function
- Returns:
The geometry parameterisation.
- class bluemira.geometry.parameterisations.PrincetonD(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None)
Bases:
GeometryParameterisation[PrincetonDOptVariables]Princeton D geometry parameterisation, with n_TF = ∞.
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
Notes
The dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- x2: float
Radial position of outer limb [m]
- dz: float
Vertical offset from z=0 [m]
- __slots__ = ()
- n_ineq_constraints: int = 1
Number of inequality constraints in the GeometryParameterisation
- create_shape(label: str = '', n_points: int = 2000, *, with_tangency: bool = False) bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the Princeton D.
- Parameters:
label (str) – Label to give the wire
n_points (int) – The number of points to use when calculating the geometry of the Princeton D.
with_tangency (bool)
- Return type:
CAD Wire of the geometry
- f_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint for PrincetonD.
- Returns:
Inequality constraint for PrincetonD.
- Return type:
numpy.typing.NDArray[numpy.float64]
- df_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint gradient for PrincetonD.
- Returns:
Inequality constraint gradient for PrincetonD.
- Return type:
numpy.typing.NDArray[numpy.float64]
- class bluemira.geometry.parameterisations.PrincetonDDiscrete(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None, n_TF: int | None = None, tf_wp_width: float | None = None, tf_wp_depth: float | None = None, n_points: int = 50, tolerance: float = 0.001)
Bases:
PrincetonDPrinceton D geometry parameterisation, with finite n_TF.
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
n_TF (int | None)
tf_wp_width (float | None)
tf_wp_depth (float | None)
n_points (int)
tolerance (float)
- Raises:
GeometryParameterisationError – If n_TF is specified, tf_wp_width and tf_wp_depth must also be specified.
Notes
Fig. 42 Princeton D at finite n_TF
The dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- x2: float
Radial position of outer limb [m]
- dz: float
Vertical offset from z=0 [m]
Please note, when using this shape as a sweep path, you must use frenet=False. This is because of limitations in CAD, which we are trying to resolve. See #4267
- __slots__ = ('_n_TF', '_n_points', '_tf_wp_depth', '_tf_wp_width', '_tolerance')
- n_ineq_constraints: int = 1
Number of inequality constraints in the GeometryParameterisation
- _n_TF = None
- _tf_wp_width = None
- _tf_wp_depth = None
- _n_points = 50
- _tolerance = 0.001
- create_shape(label: str = '', n_points: int | None = None, *, tolerance: float | None = None, with_tangency: bool = False) bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the Princeton D.
- Parameters:
label (str) – Label to give the wire
n_points (int | None) – The number of points to use when calculating the geometry of the Princeton D.
tolerance (float | None)
with_tangency (bool)
- Return type:
CAD Wire of the geometry
- Raises:
GeometryParameterisationError – If x2 <= x1
- class bluemira.geometry.parameterisations.TripleArc(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None)
Bases:
GeometryParameterisation[TripleArcOptVaribles]Triple-arc up-down symmetric geometry parameterisation.
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
Notes
Source: [doi:10.12688/f1000research.28224.1](https://doi.org/10.12688/f1000research.28224.1)
The dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- dz: float
Vertical offset from z=0 [m]
- sl: float
Length of inboard straigh section [m]
- f1: float
radii of top and bottom left arc [m]
- f2: float
radii of top and bottom middle arc [m]
- a1: float
top left and bottom left arc angle [degrees]
- a2: float
top middle and bottom middle arc angle [degrees]
- __slots__ = ()
- n_ineq_constraints: int = 1
Number of inequality constraints in the GeometryParameterisation
- f_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint for TripleArc.
Constrain such that a1 + a2 is less than or equal to 180 degrees.
- Returns:
Inequality constraint for TripleArc.
- Return type:
numpy.typing.NDArray[numpy.float64]
- df_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint gradient for TripleArc.
- Returns:
Inequality constraint gradient for TripleArc.
- Return type:
numpy.typing.NDArray[numpy.float64]
- create_shape(label: str = '') bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the triple arc.
- Parameters:
label (str) – Label to give the wire
- Return type:
CAD Wire of the geometry
- _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) tuple[float, float]
Adds labels to parameterisation plots
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
shape (bluemira.geometry.wire.BluemiraWire) – parameterisation wire
- Returns:
Labels to parameterisation plots.
- Return type:
tuple[float, float]
- class bluemira.geometry.parameterisations.SextupleArc(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None)
Bases:
GeometryParameterisation[SextupleArcOptVariables]Sextuple-arc up-down asymmetric geometry parameterisation.
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
Notes
The dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- z1: float
Inboard limb height [m]
- r1 - r5: float
arc radius [m]
- a1 - a5: float
arc angle [degrees]
- __slots__ = ()
- n_ineq_constraints: int = 1
Number of inequality constraints in the GeometryParameterisation
- f_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint for SextupleArc.
Constrain such that sum of the 5 angles is less than or equal to 360 degrees.
- Returns:
Inequality constraint for SextupleArc.
- Return type:
numpy.typing.NDArray[numpy.float64]
- df_ineq_constraint() numpy.typing.NDArray[numpy.float64]
Inequality constraint gradient for SextupleArc.
- Returns:
Inequality constraint gradient for SextupleArc.
- Return type:
numpy.typing.NDArray[numpy.float64]
- create_shape(label: str = '') bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the sextuple arc.
- Parameters:
label (str) – Label to give the wire
- Return type:
CAD Wire of the geometry
- _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire)
Adds labels to parameterisation plots
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
shape (bluemira.geometry.wire.BluemiraWire) – parameterisation wire
- class bluemira.geometry.parameterisations.PolySpline(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None)
Bases:
GeometryParameterisation[PolySplineOptVariables]Simon McIntosh’s Poly-Bézier-spline geometry parameterisation (19 variables).
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
Notes
The dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- x2: float
Radial position of outer limb [m]
- z2: float
Outer note vertical shift [m]
- height: float
Full height [m]
- top: float
Horizontal shift []
- upper: float
Vertical shift []
- dz: float
Vertical offset [m]
- flat: float
Fraction of straight outboard leg []
- tilt: float
Outboard angle [degrees]
- bottom: float
Lower horizontal shift []
- lower: float
Lower vertical shift []
- l0s - l3s: float
Tension variable segment start
- l0e - l3e: float
Tension variable segment end
Tension variables control how strictly the spline adheres to the initialisation points. Low tension makes the splines smoother.
- __slots__ = ()
- create_shape(label: str = '') bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the poly spline.
- Parameters:
label (str) – Label to give the wire
- Return type:
CAD Wire of the geometry
- static _make_control_points(p0: list[float], p3: list[float], theta0: list[float], theta3: list[float], l_start: float, l_end: float) tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]]
Make 2 Bézier spline control points between two vertices.
- Returns:
Two Bézier spline control points.
- Parameters:
p0 (list[float])
p3 (list[float])
theta0 (list[float])
theta3 (list[float])
l_start (float)
l_end (float)
- Return type:
tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]]
- static _get_annotator_offset_z(shape: bluemira.geometry.wire.BluemiraWire, x_value: float) float
Gives the z-offset for the annotator.
- Returns:
z-Offset for the annotator.
- Return type:
float
- Parameters:
x_value (float)
- _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire)
Adds labels to parameterisation plots
- Parameters:
ax (matplotlib.pyplot.Axes) – Matplotlib axis instance
shape (bluemira.geometry.wire.BluemiraWire) – parameterisation wire
- class bluemira.geometry.parameterisations.PictureFrameTools
Tools Class containing methods to produce various PictureFrame variant limbs.
- static _make_domed_leg(x_out: float, x_curve_start: float, x_mid: float, z_top: float, z_mid: float, ri: float, axis: collections.abc.Iterable[float] = (0, -1, 0), *, flip: bool = False) bluemira.geometry.wire.BluemiraWire
Makes smooth dome for CP coils. This includes a initial straight section and a main curved dome section, with a transitioning ‘joint’ between them, producing smooth tangent curves.
- Parameters:
x_out (float) – Radial position of outer edge of limb [m]
x_curve_start (float) – Radial position of straight-curve transition of limb [m]
x_mid (float) – Radial position of inner edge of upper/lower limb [m]
z_top (float) – Vertical position of top of limb dome [m]
z_mid (float) – Vertical position of flat section [m]
ri (float) – Radius of inner corner transition. Nominally 0 [m]
axis (collections.abc.Iterable[float]) – [x,y,z] vector normal to plane of parameterisation
flip (bool) – True if limb is lower limb of section, False if upper
- Return type:
CAD Wire of the geometry
- static _make_flat_leg(x_mid: float, x_out: float, z: float, r_i: float, r_o: float, axis: collections.abc.Iterable[float] = (0, 1, 0), *, flip: bool = False) bluemira.geometry.wire.BluemiraWire
Makes a flat leg (top/bottom limb) with the option of one end rounded.
- Parameters:
x_mid (float) – Radial position of inner edge of limb [m]
x_out (float) – Radial position of outer edge of limb [m]
z (float) – Vertical position of limb [m]
r_i (float) – Radius of inner corner [m]
r_o (float) – Radius of outer corner [m]
axis (collections.abc.Iterable[float]) – [x,y,z] vector normal to plane of parameterisation
flip (bool) – True if limb is lower limb of section, False if upper
- Return type:
CAD Wire of the geometry
- static _make_tapered_inner_leg(x_in: float, x_mid: float, z_bot: float, z_taper: float, z_top: float, r_min: float, axis: tuple[float, float, float] = (0, 1, 0)) bluemira.geometry.wire.BluemiraWire
Makes a tapered inboard leg using a circle arc taper, symmetric about the midplane with the tapering beginning at a certain height and reaching a maximum taper at the midplane.
- Parameters:
x_in (float) – Radial position of innermost point of limb [m]
x_mid (float) – Radial position of outer edge of limb [m]
z_bot (float) – Vertical position of bottom of limb [m]
z_taper (float) – Vertical position of start of tapering [m]
z_top (float) – Vertical position of top of limb [m]
r_min (float) – Minimum radius of curvature [m]
axis (tuple[float, float, float]) – [x,y,z] vector normal to plane of parameterisation
- Return type:
CAD Wire of the geometry
- Raises:
GeometryParameterisationError – Input parameters cannot create shape
- _connect_to_outer_limb(top, bottom, *, top_curve: bool = False, bot_curve: bool = False) bluemira.geometry.wire.BluemiraWire
- Parameters:
top_curve (bool)
bot_curve (bool)
- Return type:
- _connect_straight_to_inner_limb(top: numpy.typing.NDArray[numpy.float64], bottom: numpy.typing.NDArray[numpy.float64]) bluemira.geometry.wire.BluemiraWire
- Parameters:
top (numpy.typing.NDArray[numpy.float64])
bottom (numpy.typing.NDArray[numpy.float64])
- Return type:
- static _inner_limb(p1: numpy.typing.NDArray[numpy.float64], p2: numpy.typing.NDArray[numpy.float64]) bluemira.geometry.wire.BluemiraWire
- Parameters:
p1 (numpy.typing.NDArray[numpy.float64])
p2 (numpy.typing.NDArray[numpy.float64])
- Return type:
- static _outer_limb(p1: numpy.typing.NDArray[numpy.float64], p2: numpy.typing.NDArray[numpy.float64]) bluemira.geometry.wire.BluemiraWire
- Parameters:
p1 (numpy.typing.NDArray[numpy.float64])
p2 (numpy.typing.NDArray[numpy.float64])
- Return type:
- class bluemira.geometry.parameterisations.PFrameSection(*args, **kwds)
Bases:
enum.EnumPicture Frame sections
- CURVED
- FLAT
- TAPERED_INNER
- __call__(*args, **kwargs)
Call linked function on access
- Returns:
Linked function.
- class bluemira.geometry.parameterisations.PictureFrame(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None, *, upper: str | PFrameSection = PFrameSection.FLAT, lower: str | PFrameSection = PFrameSection.FLAT, inner: str | PFrameSection | None = None)
Bases:
GeometryParameterisation[PictureFrameOptVariables],PictureFrameToolsPicture-frame geometry parameterisation.
- Parameters:
var_dict (bluemira.utilities.opt_variables.VarDictT | None) – Dictionary with which to update the default values of the parameterisation.
upper (str | PFrameSection)
lower (str | PFrameSection)
inner (str | PFrameSection | None)
Notes
The base dictionary keys in var_dict are:
- x1: float
Radial position of inner limb [m]
- x2: float
Radial position of outer limb [m]
- z1: float
Vertical position of top limb [m]
- z2: float
Vertical position of top limb [m]
- ri: float
Radius of inner corners [m]
- ro: float
Radius of outer corners [m]
For curved pictures frames ‘ro’ is ignored on curved sections but there are additional keys:
- z1_peak: float
Vertical position of top of limb dome [m]
- z2_peak: float
Vertical position of top of limb dome [m]
- x3: float
The radius to start the dome curve [m]
For tapered inner leg the additional keys are:
- x4: float
Radial position of outer limb [m]
- z3: float
Vertical position of top of tapered section [m]
- __slots__
- upper
- lower
- inner = None
- __deepcopy__(memo) PictureFrame
Picture Frame deepcopy
- Returns:
Deepcopy of Picture Frame.
- Return type:
- create_shape(label: str = '') bluemira.geometry.wire.BluemiraWire
Make a CAD representation of the picture frame.
- Parameters:
label (str) – Label to give the wire
- Return type:
CAD Wire of the Picture Frame geometry
- _make_inb_leg() bluemira.geometry.wire.BluemiraWire
- Return type:
- _make_upper_lower_leg(*, make_upper_section: bool, flip: bool) PFrameSection
- Parameters:
make_upper_section (bool)
flip (bool)
- Return type:
- _make_out_leg(top_leg: PFrameSection, bot_leg: PFrameSection) bluemira.geometry.wire.BluemiraWire
- Parameters:
top_leg (PFrameSection)
bot_leg (PFrameSection)
- Return type:
- _label_function(ax, shape)
Adds labels to parameterisation plots
- Parameters:
ax – Matplotlib axis instance
shape – parameterisation wire
- Returns:
offset_ar_x – Suggested location for where to plot the next set of labels related to the radii in the parameterisation. (z-coordinates only)
offset_ar_z – Suggested location for where to plot the next set of labels related to the height in the parameterisation. (x-coordinates only)