FEM.Geometry package#

Meshing and geometry definitions

Submodules#

FEM.Geometry.Geometree module#

DEPRECATED

This class was my introduction to OctTrees. I implemented all geometry with this class. Then, I realized SciPy has a KDTree implementation, faster and better. IDK what to tink about it

class FEM.Geometry.Geometree.Geometree(boundary, n: int = 1, depth: int = 1)#

Bases: object

add_point(p: tuple) bool#
contains(p: tuple) bool#
draw(ax)#
draw_points(ax)#
graph_query_range(p, r)#
min_search_size = -1#
query_first_point_set()#
query_range(quadrant, plot=False, ax=None) bool#
query_range_point_radius(p, r=None, plot=False, ax=None)#
subdivide() None#
class FEM.Geometry.Geometree.Quadrant3D(p: tuple, dim: tuple)#

Bases: object

boxes_disjoint(e)#
contains(e) bool#
draw(ax)#
draw_(ax)#
intesects_quadrant(e) bool#
subdivide() list#
class FEM.Geometry.Geometree.Quadrant3DSpherical(p: tuple, r: tuple)#

Bases: Quadrant3D

contains(e) bool#

FEM.Geometry.Geometry module#

Geometry definitions.

class FEM.Geometry.Geometry.Delaunay(vertices: list, params: str, nvn: int = 1, holes_dict=None, fillets=None, fast=False, extra_segs=None)#

Bases: Geometry2D

Generate Delaunay triangulation using Triangle

Parameters:
  • vertices (list) – matrix containing the domain vertices coordinates

  • params (str) – Triangulation parameters, use the aux function _strdelaunay

  • nvn (int, optional) – Number of variables per node. Defaults to 1.

  • holes_dict (list, optional) – A list of holes dicts. Defaults to None.

  • fillets (list, optional) – A list of fillets. Defaults to None.

  • fast (bool, optional) – If True, the created elements will have have the fast propertie (see Element class docs)

extrude(h: float = 1.0, m: int = 5, **kargs) Geometry3D#
class FEM.Geometry.Geometry.Geometry(dictionary: list, gdls: list, types: list, nvn: int = 1, regions: list[Region] | None = None, fast=False)#

Bases: object

Define a general geometry structure

Parameters:
  • dictionary (list) – Matrix with element definitions. Each row is an element. The gdl are defined in columns

  • gdls (list) – List of domain coordinates

  • types (list) – Types of each element

  • nvn (int, optional) – Nunmber of variables per node. Defaults to 1.

  • regions (list, optional) – List of domain regions. Defaults to [].

  • fast (bool) – If True, the created elements will have have the fast propertie (see Element class docs)

addRegions(regions: list[Region]) None#

Adds regions to an already created geometry

Parameters:

regions (list[Region]) – Regions to be created

calculateCentroids() None#

Calculate elements centroids

calculateRegions() None#

Calculates the nodes of the geometry regions

cbFromRegion(region: int, value: float, nv: int = 1) list#

Generate a list of border conditions from specified border.

Parameters:
  • region (int) – region number

  • value (float) – Value of the bc

  • nv (int, optional) – Variable number, starts with 1. Defaults to 1.

Returns:

List of border conditions that can be concatenated or assigned to the geometry

Return type:

list

cbeAllRegions(value: float) None#

Set all regions border conditions to the specified value to all the variables.

Parameters:

value (float) – Value of the border condition

detectNonLocal(lr: float) list#

Detect adjacent elements between a distance Lr. Uses KDTrees

Parameters:

lr (float) – Distance to detect adjacent elements

Returns:

Non local element dictionary

Return type:

list

detectNonLocalLegacy(lr: float) list#

Detect adjacent elements between a distance Lr. Uses iterative approach :param lr: Distance to detect adjacent elements :type lr: float

Returns:

Non local element dictionary

Return type:

list

exportJSON(filename: str | None = None) str#

Export geometry definition as JSON file or JSON string

Parameters:

filename (str, optional) – If given, a JSON file is created. Defaults to None.

Returns:

JSON string

Return type:

str

generateElements() None#

Generate elements structure

giveElementsOfRegion(region: int, centroid=False) list#

Give elements over a region

Parameters:
  • region (int) – region number. Start with 0

  • centroid (bool) – To use the centroid as find method. Defaults to false. Use the nodes

Returns:

List of elements in the specified region

Return type:

list

giveNodesOfRegion(region: int) ndarray#

Give nodes over a region

Parameters:

region (int) – region number. Start with 0

Returns:

List of nodes in the specified region

Return type:

np.ndarray

giveRegions() list#

Returns a list of regions coordinates matrix

Returns:

List of regions coordinates matrix

Return type:

list

classmethod importJSON(filename: str, **kargs) Geometry#

Import geometry definition from JSON file

Parameters:

filename (str) – Path to the JSON file

Returns:

Geometry generated using the JSON file

Return type:

Geometry

initialize() None#

Calculates the total number of GDL’s and generates the elements structure

maskFromRegions() None#

Create the display mask from geometry regions

setCbe(cbe: list) None#

This method have to be used to assign essential boundary conditions. Thes method prevents to assign duplicated border conditions

Parameters:

cbe (list) – Border conditions to be applied

show() None#

Creates a geometry graph

class FEM.Geometry.Geometry.Geometry1D(dictionary: list, gdls: list, types: list, nvn: int = 1, fast=False)#

Bases: Geometry

Define an 1D geometry structure

Parameters:
  • dictionary (list) – Matrix with element definitions. Each row is an element. The gdl are defined in columns

  • gdls (list) – List of domain coordinates

  • types (list) – Types of each element

  • nvn (int, optional) – Nunmber of variables per node. Defaults to 1.

  • fast (bool, optional) – If True, the created elements will have have the fast propertie (see Element class docs)

generateElements() None#

Generate elements structure

show() None#

Create a geometry graph

class FEM.Geometry.Geometry.Geometry2D(dictionary: list, gdls: list, types: list, nvn: int = 1, regions: list[Region] | None = None, fast=False)#

Bases: Geometry

Creates a 2D geometry

Parameters:
  • dictionary (list) – Matrix with element definitions. Each row is an element. The gdl are defined in columns

  • gdls (list) – List of domain coordinates

  • types (list) – Types of each element

  • nvn (int, optional) – Nunmber of variables per node. Defaults to 1.

  • regions (list[Region], optional) – List of regions to apply in the geometry. Defaults to None.

  • fast (bool, optional) – If True, the created elements will have have the fast propertie (see Element class docs)

cbOnHole(hole: int, value: float, nv: int = 1, sa: float = 0, ea: float = 6.283185307179586) list#

Generate a list of border conditions from specified hole.

Parameters:
  • hole (int) – Hole index in wich load will be applied

  • value (float) – Value of the bc

  • nv (int, optional) – Variable number, starts with 1. Defaults to 1.

  • sa (float, optional) – Start face angle. Defaults to 0.

  • ea (float, optional) – Finish face angle. Defaults to \(2\pi\).

Returns:

List of border conditions that can be concatenated or assigned to the geometry

Return type:

list

generateBCFromCoords(x: float, y: float, value: float = 0, nv: int = 1) list#

Generates border conditions by coordinates. The border condition is applied to the nearest node

Parameters:
  • x (float) – X coordinate of point

  • y (float) – Y coordinate of point

  • value (float, optional) – Value of the border condition. Defaults to 0.

  • nv (int, optional) – Variable number. The first variable is 1. Defaults to 1.

Returns:

Matrix of border coordinates that can be concatenated

Return type:

list

generateRegionFromCoords(p0: list, p1: list) None#

Generates a geometry Region1D by specified coordinates

Parameters:
  • p0 (list) – region start point

  • p1 (list) – region end point

loadOnHole(hole: int, sa: float = 0, ea: float = 6.283185307179586, fx: Callable | None = None, fy: Callable | None = None) None#

Assign loads over a hole.

Parameters:
  • hole (int) – Hole index in wich load will be applied

  • sa (float, optional) – Start face angle. Defaults to 0.

  • ea (float, optional) – Finish face angle. Defaults to \(2\pi\).

  • fx (Callable, optional) – Load Function x component. Defaults to None.

  • fy (Callable, optional) – Load Function y component. Defaults to None.

loadOnRegion(region: int, fx: Callable | None = None, fy: Callable | None = None, add=None) None#

Assign a load over a geometry region.

The start point of region is the 0 point of load The end point of region is the end point of load

Load must be defined as a function (normal or lambda)

Parameters:
  • region (int) – region in wich load will be applied

  • fx (Callable, optional) – Load Function x component. Defaults to None.

  • fy (Callable, optional) – Load Function y component. Defaults to None.

loadOnRegionVF(region: int, f: Callable | None = None, add=None) None#

Assign a load over a geometry region.

The start point of region is the 0 point of load The end point of region is the end point of load

Load must be defined as a function (normal or lambda)

Parameters:
  • region (int) – region in wich load will be applied

  • f (Callable, optional) – Load Function. Defaults to None.

normalLoadOnRegion(region: int, f: Callable | None = None, add=None) None#

Assign a load over a geometry region.

The start point of region is the 0 point of load The end point of region is the end point of load

Load must be defined as a function (normal or lambda)

Parameters:
  • region (int) – region in wich load will be applied

  • f (Callable, optional) – Load Function. Defaults to None.

revolve(m=10, theta=6.283185307179586, **kargs)#
show(texto: int = 10, bolita: int = 0, draw_segs: bool = True, draw_labels: bool = False, draw_bc: bool = False, label_bc: bool = False) None#

Create a geometry graph

Parameters:
  • texto (int, optional) – Text size. Defaults to 10.

  • bolita (int, optional) – Node size. Defaults to 0.

  • draw_segs (bool, optional) – To draw or not draw the regions. Defaults to True.

  • draw_labels (bool, optional) – To draw or not draw element labels. Defaults to False.

  • draw_bc (bool, optional) – To draw border conditions. Defaults to False.

  • label_bc (bool, optional) – To draw labels on border conditions. Defaults to False.

class FEM.Geometry.Geometry.Geometry3D(dictionary: list, gdls: list, types: list, nvn: int = 1, regions: list[Region] | None = None, fast=False)#

Bases: Geometry

Creates a 3D geometry

Parameters:
  • dictionary (list) – Matrix with element definitions. Each row is an element. The gdl are defined in columns

  • gdls (list) – List of domain coordinates

  • types (list) – Types of each element

  • nvn (int, optional) – Nunmber of variables per node. Defaults to 1.

  • regions (list[Region], optional) – List of regions to apply in the geometry. Defaults to None.

  • fast (bool, optional) – If True, the created elements will have have the fast propertie (see Element class docs)

detectBorderElements(plot=False)#
detectBorderElementsLegacy()#
isBorder(e)#
show() None#

Creates a geometry graph

class FEM.Geometry.Geometry.Lineal(lenght: float, n: int, o: int, nvn: int = 1)#

Bases: Geometry1D

Generate a evenly spaced elements domain

Parameters:
  • lenght (float) – Domain lenght

  • n (int) – Number of elements

  • o (int) – Element order, can be 1 or 2

  • nvn (int, optional) – Number of variables per node. Defaults to 1.

FEM.Geometry.Region module#

Defines geometry region. Regions are used to set border conditions and loads to 2D and 3D problems

class FEM.Geometry.Region.Region(coords: ndarray, desc: str = '')#

Bases: object

Creates a general region

Parameters:

coords (np.ndarray) – Coordinates matrix of therefion. Each row is a coordinate, each column is a dimension.

setNodesOfRegion(geometry: Geometry, tol: float = 1e-05) None#

Calculates the nodes of the geometry which are inside the region.

Parameters:
  • geometry (Geometry) – Input geometry

  • tol (float, optional) – Near tolerance. Defaults to 10**(-5).

class FEM.Geometry.Region.Region1D(coords: ndarray, **kargs)#

Bases: Region

Creates a line region (1D element)

Parameters:

coords (np.ndarray) – Coordinate matrix. Must be of two rows and 2 or 3 columns. 2 columns for 2D region, 3 columns for 3D region.

isBetween(p: ndarray, tol: float = 1e-05) bool#

Check if a given point is inside the region.

Parameters:
  • p (np.ndarray) – Point to be tested

  • tol (float, optional) – Tolerance for check. Defaults to 1*10**(-5).

Returns:

True if the point is inside the region

Return type:

bool

class FEM.Geometry.Region.Region2D(coords: ndarray, **kargs)#

Bases: Region

Creates a square region (2D element)

Parameters:

coords (np.ndarray) – Coordinate matrix. Must be of four rows and 3 columns.

isBetween(p: ndarray, tol: float = 1e-05) bool#

Check if a given point is inside the region.

Parameters:
  • p (np.ndarray) – Point to be tested

  • tol (float, optional) – Tolerance for check. Defaults to 1*10**(-5).

Returns:

True if the point is inside the region

Return type:

bool

pointToPlaneDistance(p: ndarray) float#

Calculates the distance from a given point to the region.

Parameters:

p (np.ndarray) – Point to be tested

Returns:

Distance between the plane and the point

Return type:

float