qugar.impl

Implicit domains module for QUGaR

Functions

create_unfitted_impl_domain(impl_func, cart_mesh)

Creates a new unfitted implicit domain using an implicit function.

create_disk(radius[, center, use_bzr])

Creates a 2D disk with the given radius and optional center.

create_sphere(radius[, center, use_bzr])

Creates a 3D sphere with the given radius and optional center.

create_ellipse(semi_axes[, ref_system, use_bzr])

Creates a 2D ellipse with the given semi-axes and optional reference system.

create_ellipsoid(semi_axes[, ref_system, ...])

Creates a 3D ellipsoid with the given semi-axes and optional reference system.

create_cylinder(radius, origin, axis[, use_bzr])

Creates a 3D cylinder with the given radius, origin, and axis.

create_annulus(inner_radius, outer_radius[, ...])

Creates a 2D annulus (a ring-shaped object) with the specified inner and outer radii, and optional center.

create_torus(major_radius, minor_radius[, ...])

Creates a 3D torus (a ring-shaped object) with the specified major and outer radii, and optional center and axis

create_constant(value, dim[, use_bzr])

Creates a constant implicit function with the specified value and dimension.

create_plane(origin, normal[, use_bzr])

Creates an implicit plane function.

create_line(origin, normal[, use_bzr])

Creates an implicit line function.

create_dim_linear(coefs[, affine_trans])

Creates a dimensional linear implicit function.

create_box([affine_trans, dim])

Creates a box (square in 2D or cube in 3D) with an optional affine transformation.

create_negative(func)

Creates a new implicit function that represents the negative of the input function.

create_functions_addition(lhs_func, rhs_func)

Creates a new implicit function that represents the addition of two given implicit functions.

create_functions_subtraction(lhs_func, rhs_func)

Creates a new implicit function that represents the subtraction of two given implicit functions.

create_affinely_transformed_functions(func, ...)

Creates a new implicit function that is an affine transformation of the given function.

create_Schoen(periods)

Creates a Schoen gyroid implicit function object.

create_Schoen_IWP(periods)

Creates a Schoen-IWP gyroid implicit function object.

create_Schoen_FRD(periods)

Creates a Schoen-FRD gyroid implicit function object.

create_Fischer_Koch_S(periods)

Creates a Fischer-Koch-S gyroid implicit function object.

create_Schwarz_Primitive(periods)

Creates a Schwarz Primitive gyroid implicit function object.

create_Schwarz_Diamond(periods)

Creates a Schwarz Diamond gyroid implicit function object.

Classes

UnfittedImplDomain(cart_mesh, cpp_object)

Class for storing an unfitted implicit domain and access its cut, full, and empty cells and facets.

ImplicitFunc(cpp_object)

Class for storing an implicit function that describes a domain.

class qugar.impl.ImplicitFunc(cpp_object: ImplicitFunc_2D | ImplicitFunc_3D)[source]

Bases: object

Class for storing an implicit function that describes a domain.

Constructor.

Parameters:

cpp_object (ImplicitFunc_2D | ImplicitFunc_3D) – Already generated implicit function binary object.

property cpp_object: ImplicitFunc_2D | ImplicitFunc_3D

Returns the C++ object.

Returns:

Underlying function C++ object.

Return type:

ImplicitFunc_2D | ImplicitFunc_3D

property dim: int

Gets the dimension of the function’s domain.

Returns:

Function’s dimension.

Return type:

int

class qugar.impl.UnfittedImplDomain(cart_mesh: CartesianMesh, cpp_object: UnfittedImplDomain_2D | UnfittedImplDomain_3D)[source]

Bases: UnfittedDomain

Class for storing an unfitted implicit domain and access its cut, full, and empty cells and facets.

Constructor.

Parameters:
qugar.impl.create_Fischer_Koch_S(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Fischer-Koch-S gyroid implicit function object.

This function generates a Fischer-Koch-S gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Fischer-Koch-S function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Fischer-Koch-S function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_Schoen(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Schoen gyroid implicit function object.

This function generates a Schoen gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Schoen function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Schoen function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_Schoen_FRD(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Schoen-FRD gyroid implicit function object.

This function generates a Schoen-FRD gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Schoen-FRD function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Schoen-FRD function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_Schoen_IWP(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Schoen-IWP gyroid implicit function object.

This function generates a Schoen-IWP gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Schoen-IWP function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Schoen-IWP function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_Schwarz_Diamond(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Schwarz Diamond gyroid implicit function object.

This function generates a Schwarz Diamond gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Schwarz Diamond function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Schwarz Diamond function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_Schwarz_Primitive(periods: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]]) ImplicitFunc[source]

Creates a Schwarz Primitive gyroid implicit function object.

This function generates a Schwarz Primitive gyroid implicit function based on the provided periods. The periods can be a list of floats or a NumPy array of float32 or float64 values. The dimension of the periods must be either 2 or 3.

Parameters:

periods (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – The periods for the Schwarz Primitive function. It can be a list of floats or a NumPy array.

Returns:

An implicit function object representing the Schwarz Primitive function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension of the periods is not 2 or 3.

qugar.impl.create_affinely_transformed_functions(func: ImplicitFunc, affine_transf: AffineTransf_2D | AffineTransf_3D) ImplicitFunc[source]

Creates a new implicit function that is an affine transformation of the given function.

Note that the polynomial nature of func (if it is the case) will not be preserved.

Parameters:
Returns:

A new implicit function that represents the affine transformation

of the original function.

Return type:

ImplicitFunc

qugar.impl.create_annulus(inner_radius: float | float32 | float64, outer_radius: float | float32 | float64, center: ndarray[Any, dtype[float32 | float64]] | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 2D annulus (a ring-shaped object) with the specified inner and outer radii, and optional center.

Parameters:
  • inner_radius (float | np.float32 | np.float64) – The inner radius of the annulus. Must be positive.

  • outer_radius (float | np.float32 | np.float64) – The outer radius of the annulus. Must be positive.

  • center (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The center coordinates of the annulus. Must be a 2-dimensional array. Defaults to None.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

An implicit function representing the created annulus.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the inner or outer radius is not positive.

  • AssertionError – If the center array, if provided, does not have exactly 2 coordinates.

qugar.impl.create_box(affine_trans: AffineTransf_2D | None = None, dim: int | None = None) ImplicitFunc[source]

Creates a box (square in 2D or cube in 3D) with an optional affine transformation.

A box, before transforming it affinely, is a domain [-1,1]^dim.

Parameters:
  • affine_trans (Optional[qugar.cpp.AffineTransf_2D | qugar.cpp.AffineTransf_2D]) – An optional affine transformation to apply to the box. If None, a default box is created.

  • dim (Optional[int]) – The dimension of the box. Must be either 2 or 3. If affine_trans is provided, this must match the dimension of the affine transformation. If None, defaults to 2.

Returns:

An implicit function representing the created box.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension is not 2 or 3, or if the dimension does not match the affine transformation.

qugar.impl.create_constant(value: float | float32 | float64, dim: int, use_bzr: bool = True) ImplicitFunc[source]

Creates a constant implicit function with the specified value and dimension.

Parameters:
  • value (float | np.float32 | np.float64) – The constant value for the implicit function.

  • dim (int) – The dimension of the implicit function. Must be 2 or 3.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

An instance of ImplicitFunc representing the constant function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the dimension is not 2 or 3.

qugar.impl.create_cylinder(radius: float | float32 | float64, origin: ndarray[Any, dtype[float32 | float64]], axis: ndarray[Any, dtype[float32 | float64]] | None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 3D cylinder with the given radius, origin, and axis.

Parameters:
  • radius (float | np.float32 | np.float64) – Cylider’s radius.

  • origin (npt.NDArray[np.float32 | np.float64]) – Cylinder’s origin (a point in the revolution axis).

  • axis (Optional[npt.NDArray[np.float32 | np.float64]]) – Cylinder’s axis. If not provided, the cylinder is aligned with the z-axis.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

_description_

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the radius is not positive.

  • AssertionError – If the origin array, if provided, does not have exactly 3 coordinates.

qugar.impl.create_dim_linear(coefs: list[float | float32 | float64] | ndarray[Any, dtype[float32 | float64]], affine_trans: AffineTransf_2D | None = None) ImplicitFunc[source]

Creates a dimensional linear implicit function.

Parameters:
  • coefs (list[float | np.float32 | np.float64] | npt.NDArray[np.float32 | np.float64]) – Coefficients for the linear function. Must be a list or numpy array of floats. 4 coefficients in 2D and 8 coefficients in 3D.

  • affine_trans (Optional[qugar.cpp.AffineTransf_2D | qugar.cpp.AffineTransf_2D]) – Optional affine transformation to be applied. If provided, it must be an instance of qugar.cpp.AffineTransf_2D or qugar.cpp.AffineTransf_2D.

Returns:

An instance of ImplicitFunc representing the created dimensional

linear function.

Return type:

ImplicitFunc

Raises:

AssertionError – If the size of coefs is not 4 or 8, or if the size of coefs does not match the expected dimension based on the optionally provided affine transformation.

qugar.impl.create_disk(radius: float | float32 | float64, center: ndarray[Any, dtype[float32 | float64]] | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 2D disk with the given radius and optional center.

Parameters:
  • radius (float | np.float32 | np.float64) – The radius of the disk.

  • center (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The center of the disk. Defaults to None. If not provided, the radius is centered at the origin.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to False.

Returns:

The implicit function representing the disk.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the radius is not positive.

  • AssertionError – If the origin array, if provided, does not have exactly 2 coordinates.

qugar.impl.create_ellipse(semi_axes: ndarray[Any, dtype[float32 | float64]], ref_system: RefSystem_2D | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 2D ellipse with the given semi-axes and optional reference system.

Parameters:
  • semi_axes (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The semi-axes of the ellipse. It must have two entries.

  • ref_system (Optional[qugar.cpp.RefSystem], optional) – The reference system of the ellipse. Defaults to None. If not provided, the ellipse is aligned with the Cartesian system.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

The implicit function representing the ellipse.

Return type:

ImplicitFunc

Raises:

AssertionError – If any of the semi_axes is not positive or it does not have exactly 2 coordinates.

qugar.impl.create_ellipsoid(semi_axes: ndarray[Any, dtype[float32 | float64]], ref_system: RefSystem_3D | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 3D ellipsoid with the given semi-axes and optional reference system.

Parameters:
  • semi_axes (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The semi-axes of the ellipsoid. It must have three entries.

  • ref_system (Optional[qugar.cpp.RefSystem], optional) – The reference system of the ellipsoid. Defaults to None. If not provided, the ellipsoid is aligned with the Cartesian system.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

The implicit function representing the ellipsoid.

Return type:

ImplicitFunc

Raises:

AssertionError – If any of the semi_axes is not positive or it does not have exactly 3 coordinates.

qugar.impl.create_functions_addition(lhs_func: ImplicitFunc, rhs_func: ImplicitFunc) ImplicitFunc[source]

Creates a new implicit function that represents the addition of two given implicit functions.

Parameters:
  • lhs_func (ImplicitFunc) – The left-hand side implicit function.

  • rhs_func (ImplicitFunc) – The right-hand side implicit function.

Returns:

A new implicit function representing the addition of the two input functions.

Return type:

ImplicitFunc

qugar.impl.create_functions_subtraction(lhs_func: ImplicitFunc, rhs_func: ImplicitFunc) ImplicitFunc[source]

Creates a new implicit function that represents the subtraction of two given implicit functions.

Parameters:
  • lhs_func (ImplicitFunc) – The left-hand side implicit function.

  • rhs_func (ImplicitFunc) – The right-hand side implicit function.

Returns:

A new implicit function representing the subtraction of the two input

functions.

Return type:

ImplicitFunc

qugar.impl.create_line(origin: ndarray[Any, dtype[float32 | float64]] | None, normal: ndarray[Any, dtype[float32 | float64]] | None, use_bzr: bool = True) ImplicitFunc[source]

Creates an implicit line function.

Parameters:
  • origin (Optional[npt.NDArray[np.float32 | np.float64]]) – The origin point of the line. If None, defaults to [0.0, 0.0].

  • normal (Optional[npt.NDArray[np.float32 | np.float64]]) – The normal vector of the line. If None, defaults to [1.0, 0.0].

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

An implicit function representing the line.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the origin array, if provided, does not have exactly 2 coordinates.

  • AssertionError – If the normal array, if provided, does not have exactly 2 coordinates.

qugar.impl.create_negative(func: ImplicitFunc) ImplicitFunc[source]

Creates a new implicit function that represents the negative of the input function.

Parameters:

func (ImplicitFunc) – The input function.

Returns:

A new implicit function representing the negative of the input function.

Return type:

ImplicitFunc

qugar.impl.create_plane(origin: ndarray[Any, dtype[float32 | float64]] | None, normal: ndarray[Any, dtype[float32 | float64]] | None, use_bzr: bool = True) ImplicitFunc[source]

Creates an implicit plane function.

Parameters:
  • origin (Optional[npt.NDArray[np.float32 | np.float64]]) – The origin point of the plane. If None, defaults to [0.0, 0.0, 0.0].

  • normal (Optional[npt.NDArray[np.float32 | np.float64]]) – The normal vector of the plane. If None, defaults to [1.0, 0.0, 0.0].

  • use_bzr (bool) – A flag indicating whether to use BZR. Defaults to True.

Returns:

An implicit function representing the plane.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the origin array, if provided, does not have exactly 3 coordinates.

  • AssertionError – If the normal array, if provided, does not have exactly 3 coordinates.

qugar.impl.create_sphere(radius: float | float32 | float64, center: ndarray[Any, dtype[float32 | float64]] | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 3D sphere with the given radius and optional center.

Parameters:
  • radius (float | np.float32 | np.float64) – The radius of the sphere.

  • center (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The center of the sphere. Defaults to None. If not provided, the radius is centered at the origin.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

The implicit function representing the sphere.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the radius is not positive.

  • AssertionError – If the origin array, if provided, does not have exactly 3 coordinates.

qugar.impl.create_torus(major_radius: float | float32 | float64, minor_radius: float | float32 | float64, center: ndarray[Any, dtype[float32 | float64]] | None = None, axis: ndarray[Any, dtype[float32 | float64]] | None = None, use_bzr: bool = True) ImplicitFunc[source]

Creates a 3D torus (a ring-shaped object) with the specified major and outer radii, and optional center and axis

Parameters:
  • major_radius (float | np.float32 | np.float64) – The major radius of the annulus. Must be positive.

  • minor_radius (float | np.float32 | np.float64) – The outer radius of the annulus. Must be positive.

  • center (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The center coordinates of the annulus. Must be a 3-dimensional array. Defaults to None.

  • axis (Optional[npt.NDArray[np.float32 | np.float64]], optional) – The axis coordinates of the torus (perpendicular to the torus plane). Must be a 3-dimensional array. Defaults to None.

  • use_bzr (bool, optional) – Flag to use Bezier representation. Defaults to True.

Returns:

An implicit function representing the created annulus.

Return type:

ImplicitFunc

Raises:
  • AssertionError – If the major or outer radius are not positive.

  • AssertionError – If the center array, if provided, does not have exactly 3 coordinates.

  • AssertionError – If the axis array, if provided, does not have exactly 3 coordinates.

qugar.impl.create_unfitted_impl_domain(impl_func: ImplicitFunc, cart_mesh: CartesianMesh) UnfittedImplDomain[source]

Creates a new unfitted implicit domain using an implicit function.

Parameters:
Returns:

Created unfitted implicit domain.

Return type:

UnfittedImplDomain