pymead.core.geometry_collection.GeometryCollection#

class GeometryCollection(gui_obj=None)[source]#

Bases: DualRep

__init__(gui_obj=None)[source]#

The geometry collection is the primary class in pymead for housing all the available fundamental geometry types. Geometry, parameters, and constraints can be added using the nomenclature add_<object-name>(). For example, points can be added using geo_col.add_point(x=<x-value>, y=<y-value>).

Methods

add_airfoil(leading_edge, trailing_edge[, ...])

add_bezier(point_sequence[, default_nt, ...])

add_bspline(point_sequence, knot_sequence[, ...])

add_constraint(constraint_type, *constraint_args)

add_desvar(value, name[, lower, upper, ...])

Directly adds a design variable value to the geometry collection.

add_ferguson(point_sequence[, default_nt, ...])

add_line(point_sequence[, name, ...])

add_mea(airfoils[, name, assign_unique_name])

add_param(value[, name, lower, upper, ...])

Adds a parameter to the geometry collection sub-container "params", and modifies the name to make it unique if necessary.

add_point(x, y[, name, ...])

Adds a point by value to the geometry collection

add_polyline(source[, coords, start, end, ...])

add_pymead_obj_by_ref(pymead_obj[, ...])

This method adds a pymead object by passing it directly to the geometry collection.

add_reference_polyline([points, source, ...])

add_to_subcontainer(pymead_obj[, ...])

Adds an object to a sub-container within the geometry collection's container().

alphabetical_sub_container_key_list(...)

This method sorts a sub-container with the following rules:

assign_design_variable_values(dv_values[, ...])

Assigns a list or array of design variable values, possibly normalized by the bounds, to the design variables in the geometry collection 'desvar' container.

clear_container()

Clears all the entities in the geometry container.

clear_selected_objects()

container()

Retrieves the geometry container.

cover_point_xy(point)

demote_desvar_to_param(desvar)

Demotes a design variable to a parameter by removing the bounds.

deselect_object(pymead_obj)

equate_constraints(constraint1, constraint2)

expose_point_xy(point)

extract_design_variable_values([...])

Extracts the values of the design variables in the geometry collection 'desvar' container.

get_dict_rep()

get_metadata()

get_name_list(sub_container)

Gets a list of all the parameter or geometry names in a specified sub-container.

hover_enter_obj(pymead_obj)

hover_leave_obj(pymead_obj)

list_examples()

Gets a list of available example file names that can be used to create a new GeometryCollection object using the GeometryCollection.load_example method.

load_example(example_name, **kwargs)

Class method that creates a GeometryCollection object directly from a .jmea file.

load_file(jmea_file, **kwargs)

Class method that creates a GeometryCollection object directly from a .jmea file.

promote_param_to_desvar(param[, lower, upper])

Promotes a parameter to a design variable by adding bounds.

remove_from_subcontainer(pymead_obj)

Removes an object from the specified sub-container.

remove_pymead_obj(pymead_obj[, ...])

Removes a pymead object from the geometry collection.

remove_selected_objects()

replace_geo_objs(tool, target)

This static method is used to make sure that in param/desvar promotion/demotion, any references to geometric objects get replaced.

save_to_file(jmea_file)

Saves the GeometryCollection to a .jmea file.

select_object(pymead_obj)

set_from_dict_rep(d[, canvas, tree, gui_obj])

split_polyline(polyline, split)

switch_units(unit_type, old_unit, new_unit)

unique_namer(specified_name, name_list)

This static method creates unique names for parameters or geometry by incrementing the appended index, which is attached with a hyphen.

verify_all()

verify_constraints()

verify_desvar()

verify_params()

verify_point_movement()

write_to_iges(base_dir, file_name[, ...])

Writes all the Bézier curves in the geometry collection to an IGES file.

Attributes

add_desvar(value: float, name: str, lower: float | None = None, upper: float | None = None, unit_type: str | None = None, assign_unique_name: bool = True, point: Point | None = None, root: Point | None = None, rotation_handle: Point | None = None, enabled: bool = True, equation_str: str | None = None)[source]#

Directly adds a design variable value to the geometry collection.

Parameters:
  • value (float) – Value of the design variable

  • name (str) – Name of the design variable (might be overridden when adding to the ‘desvar’ sub-container).

  • lower (float or None) – Lower bound for the design variable. If None, a reasonable value will be chosen automatically. Default: None.

  • upper (float or None.) – Upper bound for the design variable. If None, a reasonable value will be chosen automatically. Default: None.

  • unit_type (str or None:) – The unit type of design variable to create. Default: None.

Returns:

The generated design variable

Return type:

DesVar

add_param(value: float, name: str | None = None, lower: float | None = None, upper: float | None = None, unit_type: str | None = None, assign_unique_name: bool = True, point: Point | None = None, root: Point | None = None, rotation_handle: Point | None = None, enabled: bool = True, equation_str: str | None = None)[source]#

Adds a parameter to the geometry collection sub-container "params", and modifies the name to make it unique if necessary.

Parameters:
  • value (float) – Parameter value

  • name (str or None) – Parameter name

  • lower (float or None) – Lower bound. If None, no bound will be set. Default: None.

  • upper (float or None) – Upper bound. If None, no bound will be set. Default: None.

  • unit_type (str or None:) – The unit type of design variable to create. Default: None.

Returns:

The generated parameter

Return type:

Param

add_point(x: float, y: float, name: str | None = None, relative_airfoil_name: str | None = None, assign_unique_name: bool = True)[source]#

Adds a point by value to the geometry collection

Parameters:
  • x (float) – \(x\)-location of the point

  • y (float) – \(y\)-location of the point

  • name (str) – Optional name for the point

Returns:

Object reference

Return type:

Point

add_pymead_obj_by_ref(pymead_obj: PymeadObj, assign_unique_name: bool = True) PymeadObj[source]#

This method adds a pymead object by passing it directly to the geometry collection. If the object is already associated with a geometry collection, a ValueError is raised.

Parameters:
  • pymead_obj (PymeadObj) – The pymead object to add to the collection

  • assign_unique_name (bool) – Whether to assign a unique name to the pymead object (by appending "-1" to the end of the name of the object if there are no objects with the same name, "-2" if there is one object with the same name, etc.). Default: True

Returns:

The modified pymead object

Return type:

PymeadObj

add_to_subcontainer(pymead_obj: PymeadObj, assign_unique_name: bool = True)[source]#

Adds an object to a sub-container within the geometry collection’s container(). Also performs the task of assigning a unique name to the object before insertion into the sub-container, if necessary.

Parameters:
  • pymead_obj (PymeadObj) – Object to add to the sub-container

  • assign_unique_name (bool) – Whether to assign the object a unique name before insertion into the sub-container. Default: True.

alphabetical_sub_container_key_list(sub_container: str)[source]#

This method sorts a sub-container with the following rules:

  • Text case does not matter

  • Any consecutive numerical strings should appear in descending order

  • For parameters with an associated index, the parameter with an implied index of 1 should appear first, provided it exists. For example, "Point-2.x" should come after "Point.x", and "myParam-5" should come after "myParam".

Parameters:

sub_container (str) – Sub-container from the geometry collection to sort alphabetically

Returns:

The alphabetically sorted list

Return type:

List[str]

assign_design_variable_values(dv_values: list, bounds_normalized: bool = False)[source]#

Assigns a list or array of design variable values, possibly normalized by the bounds, to the design variables in the geometry collection ‘desvar’ container.

Parameters:
  • dv_values (Union[Iterable, Sized]) – List or array of design variable values. Must be equal in length to the number of design variables in the ‘desvar’ container. Note that the value assignment will not necessarily take place in the same order as the order of the design variables in the GUI, but rather in the order they are present in the underlying dictionary.

  • bounds_normalized (bool) – Whether the specified dv_values are normalized by the design variable bounds. Default: False.

clear_container()[source]#

Clears all the entities in the geometry container.

container()[source]#

Retrieves the geometry container. Note that there is no “setter” method because geometry items should be added only be their respective methods. For example, a Param should be added using .add_param(). This allows for name validation, which ensures that every geometry item in the container has a unique name.

Returns:

Dictionary of geometry items

Return type:

dict

demote_desvar_to_param(desvar: DesVar)[source]#

Demotes a design variable to a parameter by removing the bounds. The DesVar will be removed from the ‘desvar’ sub-container, and the corresponding Param will be added to the ‘params’ sub-container.

Parameters:

desvar (DesVar) – Parameter to promote. If str, the Param will be identified by looking in the ‘params’ sub-container.

Returns:

The generated parameter

Return type:

Param

extract_design_variable_values(bounds_normalized: bool = False)[source]#

Extracts the values of the design variables in the geometry collection ‘desvar’ container.

Parameters:

bounds_normalized (bool) – Whether to normalize the design variable values by the bounds before extraction. Default: False.

Returns:

List of design variable values, normalized the bounds if specified.

Return type:

List[float]

get_name_list(sub_container: str)[source]#

Gets a list of all the parameter or geometry names in a specified sub-container.

Parameters:

sub_container (str) – Sub-container in the geometry collection. For example, "params", "lines", "points", etc.

Returns:

List of names found in the sub-container

Return type:

List[str]

static list_examples() List[str][source]#

Gets a list of available example file names that can be used to create a new GeometryCollection object using the GeometryCollection.load_example method.

Returns:

A list of .jmea example names (without the extension)

Return type:

List[str]

classmethod load_example(example_name: str, **kwargs)[source]#

Class method that creates a GeometryCollection object directly from a .jmea file.

Parameters:
  • example_name (str) – Name of an example file (with or without the .jmea extension). See GeometryCollection.list_examples for a complete list of example names

  • kwargs – Additional keyword arguments to pass to GeometryCollection.set_from_dict_rep. Should only be specified if this method is called from the GUI

Returns:

A new geometry collection object with the data loaded from the example file

Return type:

GeometryCollection

classmethod load_file(jmea_file: str, **kwargs)[source]#

Class method that creates a GeometryCollection object directly from a .jmea file.

Parameters:
  • jmea_file (str) – Absolute path to a .jmea file

  • kwargs – Additional keyword arguments to pass to GeometryCollection.set_from_dict_rep. Should only be specified if this method is called from the GUI

Returns:

A new geometry collection object with the data loaded from the .jmea file

Return type:

GeometryCollection

promote_param_to_desvar(param: Param, lower: float | None = None, upper: float | None = None)[source]#

Promotes a parameter to a design variable by adding bounds. The Param will be removed from the ‘params’ sub-container, and the corresponding DesVar will be added to the ‘desvar’ sub-container.

Parameters:
  • param (Param or str) – Parameter to promote. If str, the Param will be identified by looking in the ‘params’ sub-container.

  • lower (float or None) – Lower bound for the design variable. If None, a reasonable value will be chosen automatically. Default: None.

  • upper (float or none.) – Upper bound for the design variable. If None, a reasonable value will be chosen automatically. Default: None.

Returns:

The generated design variable.

Return type:

DesVar

remove_from_subcontainer(pymead_obj: PymeadObj)[source]#

Removes an object from the specified sub-container.

Parameters:

pymead_obj (PymeadObj) – Object to remove.

remove_pymead_obj(pymead_obj: PymeadObj, promotion_demotion: bool = False, constraint_removal: bool = False, equating_constraints: bool = False)[source]#

Removes a pymead object from the geometry collection.

Parameters:
  • pymead_obj (PymeadObj) – Pymead object to remove

  • promotion_demotion (bool) – When this flag is set to True, the ValueError normally raised when directly deleting a Param associated with a GeoCon is ignored. Default: False

  • constraint_removal (bool) – When this flag is set to True, the ValueError normally raise when directly deleting a Param associated with a constraint cluster rotation is ignored. Default: False

  • equating_constraints (bool) – When this flag is set to True and the pymead_obj is a Param, the associated constraints are not deleted

static replace_geo_objs(tool: Param, target: Param)[source]#

This static method is used to make sure that in param/desvar promotion/demotion, any references to geometric objects get replaced.

Parameters:
  • tool (Param or DesVar) – Object to be removed, and all geometric object references replaced with the target

  • target (Param or DesVar) – Object to add

save_to_file(jmea_file: str)[source]#

Saves the GeometryCollection to a .jmea file.

Parameters:

jmea_file (str) – Name of the file including the .jmea extension

static unique_namer(specified_name: str, name_list: List[str])[source]#

This static method creates unique names for parameters or geometry by incrementing the appended index, which is attached with a hyphen. A dot separator is used to distinguish between levels within the geometry collection hierarchy. For example, the \(x\)-location of the second point added is given by "Point-2.x". Note that, for parameters and design variables, the first parameter added with a given name will not have an index by default. For example, if a Param with name=="my_param" is added three times, the resulting names, in order, will be "my_param", "my_param-2", and "my_param-3".

If a parameter is removed, and another parameter with the same name added, the index assigned will be the maximum index plus one. In the previous example, if "my_param-2" is removed from the geometry collection and the addition of "my_param" requested, the actual name assigned will be "my_param-4". This is to prevent confusion between removed and added parameters, as well as to give an indication of the order in which the parameter was added.

Parameters:
  • specified_name (str) – Input name to be tested or modified for uniqueness. Does not need to have an index.

  • name_list (List[str]) – List of names extracted from a particular sub-container in the geometry collection, used to check the specified_name for uniqueness.

Returns:

The (possibly modified) specified_name

Return type:

str

write_to_iges(base_dir: str, file_name: str, translation: List[float] | None = None, scaling: List[float] | None = None, rotation: List[float] | None = None, transformation_order: str | None = None)[source]#

Writes all the Bézier curves in the geometry collection to an IGES file.

Parameters:
  • base_dir (str) – Directory where the IGES file will be stored

  • file_name (str) – Name of the IGES file (should include the .igs extension)

  • translation (List[float]) – How to translate the curves from the X-Z plane (in the form [tx, ty, tz])

  • scaling (List[float]) – How to scale the curves from the X-Z plane (in the form [sx, sy, sz])

  • rotation (List[float]) – How to rotate the curves from the X-Z plane (in the form [rx, ry, rz])

  • transformation_order (str) – Order in which the transformation takes place

Returns:

The full file path to the created IGES file

Return type:

str