bluemira.geometry.parameterisations =================================== .. py:module:: bluemira.geometry.parameterisations .. autoapi-nested-parse:: Geometry parameterisations Classes ------- .. autoapisummary:: bluemira.geometry.parameterisations.GeometryParameterisation bluemira.geometry.parameterisations.PrincetonD bluemira.geometry.parameterisations.PrincetonDDiscrete bluemira.geometry.parameterisations.TripleArc bluemira.geometry.parameterisations.SextupleArc bluemira.geometry.parameterisations.PolySpline bluemira.geometry.parameterisations.PictureFrameTools bluemira.geometry.parameterisations.PFrameSection bluemira.geometry.parameterisations.PictureFrame Module Contents --------------- .. py:class:: GeometryParameterisation(variables: OptVariablesFrameT, **kwargs) Bases: :py:obj:`abc.ABC`, :py:obj:`Generic`\ [\ :py:obj:`OptVariablesFrameT`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.GeometryParameterisation :parts: 1 :private-bases: A geometry parameterisation class facilitating geometry optimisation. .. rubric:: Notes Subclass this base class when making a new GeometryParameterisation, adding a set of variables with initial values, and override the create_shape method. .. py:attribute:: __slots__ :value: ('_variables', 'name') .. py:attribute:: name :value: 'GeometryParameterisation' .. py:attribute:: _variables .. py:property:: n_ineq_constraints :type: int Number of inequality constraints in the GeometryParameterisation .. py:property:: variables :type: OptVariablesFrameT The variables of the GeometryParameterisation .. py:method:: adjust_variable(name: str, value: float | None = None, lower_bound: float | None = None, upper_bound: float | None = None) Adjust a variable in the GeometryParameterisation. :param name: Name of the variable to adjust :param value: Value of the variable to set :param lower_bound: Value of the lower bound to set :param upper_bound: Value of the upper to set .. py:method:: fix_variable(name: str, value: float | None = None) Fix a variable in the GeometryParameterisation, removing it from optimisation but preserving a constant value. :param name: Name of the variable to fix :param value: Value at which to fix the variable (will default to present value) .. py:method:: 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 .. py:property:: tolerance :type: numpy.typing.NDArray[numpy.float64] Optimisation tolerance for the geometry parameterisation. .. py:method:: get_x_norm_index(name: str) -> int Get the index of a variable name in the modified-length x_norm vector :param name: Variable name for which to get the index :rtype: Index of the variable name in the modified-length x_norm vector .. py:method:: 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. :param x_norm: Normalised vector of variable values :rtype: List of ordered actual (un-normalised) values .. py:method:: create_shape(label: str = '') -> bluemira.geometry.wire.BluemiraWire :abstractmethod: Make a CAD representation of the geometry. :param label: Label to give the wire :returns: CAD Wire of the geometry .. py:method:: to_json(file: str) Write the json representation of the GeometryParameterisation to a file. :param file: The path to the file. .. py:method:: from_json(file: pathlib.Path | str | TextIO) -> GeometryParameterisation :classmethod: Create the GeometryParameterisation from a json file. :param file: The path to the file, or an open file handle that supports reading. :returns: The GeometryParameterisation from a json file. .. py:method:: _annotator(ax: matplotlib.pyplot.Axes, key: str, xy1: tuple[float, float], xy2: tuple[float, float], xy3: tuple[float, float], arrowstyle: str = '<|-') :staticmethod: Create annotation arrow with label :param ax: Matplotlib axis instance :param key: label of annotation :param xy1: Tuple for first arrow point :param xy2: Tuple for second arrow point :param xy3: Tuple for arrow label location .. py:method:: _angle_annotator(ax: matplotlib.pyplot.Axes, key: str, radius: float, centre: tuple[float, float], angles: tuple[float, float], centre_angle: float) :staticmethod: Create annotation arrow with label :param ax: Matplotlib axis instance :param key: label of annotation :param radius: radius of arrow :param centre: centre coordinate of arrow .. py:method:: _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) :staticmethod: Draw two lines forming an angle, an arc for the angle, and a label. :param ax: The axis to draw on. :param start_angle: angle of the first line :param angle: Angle in degrees for the second line (measured from horizontal). :param label: Label of angle :param origin: (x, y) coordinates of the starting point. :param length: Length of the lines. :param arc_radius: Radius of the arc showing the angle. :param label_offset: Offset for the angle label. .. py:method:: _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) -> tuple[float, float] Adds labels to parameterisation plots :param ax: Matplotlib axis instance :param 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) .. py:method:: plot(ax=None, *, labels=False, **kwargs) Plot the geometry parameterisation :param ax: Matplotlib axes object :type ax: Optional[Axes] :param labels: Label variables on figure :type labels: bool :param kwargs: Passed to matplotlib Axes.plot function :type kwargs: Dict :returns: The geometry parameterisation. .. py:class:: PrincetonD(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None) Bases: :py:obj:`GeometryParameterisation`\ [\ :py:obj:`PrincetonDOptVariables`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.PrincetonD :parts: 1 :private-bases: Princeton D geometry parameterisation, with n_TF = ∞. :param var_dict: Dictionary with which to update the default values of the parameterisation. .. rubric:: Notes .. plot:: from bluemira.geometry.parameterisations import PrincetonD PrincetonD().plot(labels=True) 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] .. py:attribute:: __slots__ :value: () .. py:attribute:: n_ineq_constraints :type: int :value: 1 Number of inequality constraints in the GeometryParameterisation .. py:method:: create_shape(label: str = '', n_points: int = 2000, *, with_tangency: bool = False) -> bluemira.geometry.wire.BluemiraWire Make a CAD representation of the Princeton D. :param label: Label to give the wire :param n_points: The number of points to use when calculating the geometry of the Princeton D. :rtype: CAD Wire of the geometry .. py:method:: f_ineq_constraint() -> numpy.typing.NDArray[numpy.float64] Inequality constraint for PrincetonD. :returns: Inequality constraint for PrincetonD. .. py:method:: df_ineq_constraint() -> numpy.typing.NDArray[numpy.float64] Inequality constraint gradient for PrincetonD. :returns: Inequality constraint gradient for PrincetonD. .. py:class:: 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: :py:obj:`PrincetonD` .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.PrincetonDDiscrete :parts: 1 :private-bases: Princeton D geometry parameterisation, with finite n_TF. :param var_dict: Dictionary with which to update the default values of the parameterisation. :raises GeometryParameterisationError: If n_TF is specified, tf_wp_width and tf_wp_depth must also be specified. .. rubric:: Notes .. plot:: :caption: Princeton D at finite n_TF from bluemira.geometry.parameterisations import PrincetonDDiscrete PrincetonDDiscrete(n_TF=16, tf_wp_width=0.5, tf_wp_depth=0.8).plot(labels=True) 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 .. py:attribute:: __slots__ :value: ('_n_TF', '_n_points', '_tf_wp_depth', '_tf_wp_width', '_tolerance') .. py:attribute:: n_ineq_constraints :type: int :value: 1 Number of inequality constraints in the GeometryParameterisation .. py:attribute:: _n_TF :value: None .. py:attribute:: _tf_wp_width :value: None .. py:attribute:: _tf_wp_depth :value: None .. py:attribute:: _n_points :value: 50 .. py:attribute:: _tolerance :value: 0.001 .. py:method:: 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. :param label: Label to give the wire :param n_points: The number of points to use when calculating the geometry of the Princeton D. :rtype: CAD Wire of the geometry :raises GeometryParameterisationError: If x2 <= x1 .. py:class:: TripleArc(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None) Bases: :py:obj:`GeometryParameterisation`\ [\ :py:obj:`TripleArcOptVaribles`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.TripleArc :parts: 1 :private-bases: Triple-arc up-down symmetric geometry parameterisation. :param var_dict: Dictionary with which to update the default values of the parameterisation. .. rubric:: Notes .. plot:: from bluemira.geometry.parameterisations import TripleArc ta = TripleArc() ta.variables.dz.adjust(1.0) ta.plot(labels=True) 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] .. py:attribute:: __slots__ :value: () .. py:attribute:: n_ineq_constraints :type: int :value: 1 Number of inequality constraints in the GeometryParameterisation .. py:method:: 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. .. py:method:: df_ineq_constraint() -> numpy.typing.NDArray[numpy.float64] Inequality constraint gradient for TripleArc. :returns: Inequality constraint gradient for TripleArc. .. py:method:: create_shape(label: str = '') -> bluemira.geometry.wire.BluemiraWire Make a CAD representation of the triple arc. :param label: Label to give the wire :rtype: CAD Wire of the geometry .. py:method:: _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) -> tuple[float, float] Adds labels to parameterisation plots :param ax: Matplotlib axis instance :param shape: parameterisation wire :returns: Labels to parameterisation plots. .. py:class:: SextupleArc(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None) Bases: :py:obj:`GeometryParameterisation`\ [\ :py:obj:`SextupleArcOptVariables`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.SextupleArc :parts: 1 :private-bases: Sextuple-arc up-down asymmetric geometry parameterisation. :param var_dict: Dictionary with which to update the default values of the parameterisation. .. rubric:: Notes .. plot:: from bluemira.geometry.parameterisations import SextupleArc SextupleArc().plot(labels=True) 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] .. py:attribute:: __slots__ :value: () .. py:attribute:: n_ineq_constraints :type: int :value: 1 Number of inequality constraints in the GeometryParameterisation .. py:method:: 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. .. py:method:: df_ineq_constraint() -> numpy.typing.NDArray[numpy.float64] Inequality constraint gradient for SextupleArc. :returns: Inequality constraint gradient for SextupleArc. .. py:method:: create_shape(label: str = '') -> bluemira.geometry.wire.BluemiraWire Make a CAD representation of the sextuple arc. :param label: Label to give the wire :rtype: CAD Wire of the geometry .. py:method:: _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) Adds labels to parameterisation plots :param ax: Matplotlib axis instance :param shape: parameterisation wire .. py:class:: PolySpline(var_dict: bluemira.utilities.opt_variables.VarDictT | None = None) Bases: :py:obj:`GeometryParameterisation`\ [\ :py:obj:`PolySplineOptVariables`\ ] .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.PolySpline :parts: 1 :private-bases: Simon McIntosh's Poly-Bézier-spline geometry parameterisation (19 variables). :param var_dict: Dictionary with which to update the default values of the parameterisation. .. rubric:: Notes .. plot:: from bluemira.geometry.parameterisations import PolySpline PolySpline().plot(labels=True) 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. .. py:attribute:: __slots__ :value: () .. py:method:: create_shape(label: str = '') -> bluemira.geometry.wire.BluemiraWire Make a CAD representation of the poly spline. :param label: Label to give the wire :rtype: CAD Wire of the geometry .. py:method:: _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]] :staticmethod: Make 2 Bézier spline control points between two vertices. :returns: Two Bézier spline control points. .. py:method:: _get_annotator_offset_z(shape: bluemira.geometry.wire.BluemiraWire, x_value: float) -> float :staticmethod: Gives the z-offset for the annotator. :returns: z-Offset for the annotator. :rtype: float .. py:method:: _label_function(ax: matplotlib.pyplot.Axes, shape: bluemira.geometry.wire.BluemiraWire) Adds labels to parameterisation plots :param ax: Matplotlib axis instance :param shape: parameterisation wire .. py:class:: PictureFrameTools Tools Class containing methods to produce various PictureFrame variant limbs. .. py:method:: _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 :staticmethod: 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. :param x_out: Radial position of outer edge of limb [m] :param x_curve_start: Radial position of straight-curve transition of limb [m] :param x_mid: Radial position of inner edge of upper/lower limb [m] :param z_top: Vertical position of top of limb dome [m] :param z_mid: Vertical position of flat section [m] :param ri: Radius of inner corner transition. Nominally 0 [m] :param axis: [x,y,z] vector normal to plane of parameterisation :param flip: True if limb is lower limb of section, False if upper :rtype: CAD Wire of the geometry .. py:method:: _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 :staticmethod: Makes a flat leg (top/bottom limb) with the option of one end rounded. :param x_mid: Radial position of inner edge of limb [m] :param x_out: Radial position of outer edge of limb [m] :param z: Vertical position of limb [m] :param r_i: Radius of inner corner [m] :param r_o: Radius of outer corner [m] :param axis: [x,y,z] vector normal to plane of parameterisation :param flip: True if limb is lower limb of section, False if upper :rtype: CAD Wire of the geometry .. py:method:: _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 :staticmethod: 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. :param x_in: Radial position of innermost point of limb [m] :param x_mid: Radial position of outer edge of limb [m] :param z_bot: Vertical position of bottom of limb [m] :param z_taper: Vertical position of start of tapering [m] :param z_top: Vertical position of top of limb [m] :param r_min: Minimum radius of curvature [m] :param axis: [x,y,z] vector normal to plane of parameterisation :rtype: CAD Wire of the geometry :raises GeometryParameterisationError: Input parameters cannot create shape .. py:method:: _connect_to_outer_limb(top, bottom, *, top_curve: bool = False, bot_curve: bool = False) -> bluemira.geometry.wire.BluemiraWire .. py:method:: _connect_straight_to_inner_limb(top: numpy.typing.NDArray[numpy.float64], bottom: numpy.typing.NDArray[numpy.float64]) -> bluemira.geometry.wire.BluemiraWire .. py:method:: _inner_limb(p1: numpy.typing.NDArray[numpy.float64], p2: numpy.typing.NDArray[numpy.float64]) -> bluemira.geometry.wire.BluemiraWire :staticmethod: .. py:method:: _outer_limb(p1: numpy.typing.NDArray[numpy.float64], p2: numpy.typing.NDArray[numpy.float64]) -> bluemira.geometry.wire.BluemiraWire :staticmethod: .. py:class:: PFrameSection(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.PFrameSection :parts: 1 :private-bases: Picture Frame sections .. py:attribute:: CURVED .. py:attribute:: FLAT .. py:attribute:: TAPERED_INNER .. py:method:: __call__(*args, **kwargs) Call linked function on access :returns: Linked function. .. py:class:: 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: :py:obj:`GeometryParameterisation`\ [\ :py:obj:`PictureFrameOptVariables`\ ], :py:obj:`PictureFrameTools` .. autoapi-inheritance-diagram:: bluemira.geometry.parameterisations.PictureFrame :parts: 1 :private-bases: Picture-frame geometry parameterisation. :param var_dict: Dictionary with which to update the default values of the parameterisation. .. rubric:: Notes .. plot:: from bluemira.geometry.parameterisations import PictureFrame PictureFrame( inner="TAPERED_INNER", upper="FLAT", lower="CURVED", var_dict={'ri': {'value': 1}} ).plot(labels=True) 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] .. py:attribute:: __slots__ .. py:attribute:: upper .. py:attribute:: lower .. py:attribute:: inner :value: None .. py:method:: __deepcopy__(memo) -> PictureFrame Picture Frame deepcopy :returns: Deepcopy of Picture Frame. .. py:method:: create_shape(label: str = '') -> bluemira.geometry.wire.BluemiraWire Make a CAD representation of the picture frame. :param label: Label to give the wire :rtype: CAD Wire of the Picture Frame geometry .. py:method:: _make_inb_leg() -> bluemira.geometry.wire.BluemiraWire .. py:method:: _make_upper_lower_leg(*, make_upper_section: bool, flip: bool) -> PFrameSection .. py:method:: _make_out_leg(top_leg: PFrameSection, bot_leg: PFrameSection) -> bluemira.geometry.wire.BluemiraWire .. py:method:: _label_function(ax, shape) Adds labels to parameterisation plots :param ax: Matplotlib axis instance :param 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)