fastvpinns.FE.fespace2d module

The file fespace2d.py contains the main class that holds the information of all the Finite Element (FE) spaces of all the cells within the given mesh.

Author: Thivin Anandh D

Changelog: 30/Aug/2023 - Initial version

Known issues: None

Dependencies: None specified

class fastvpinns.FE.fespace2d.Fespace2D(mesh, cells, boundary_points, cell_type: str, fe_order: int, fe_type: str, quad_order: int, quad_type: str, fe_transformation_type: str, bound_function_dict: dict, bound_condition_dict: dict, forcing_function, output_path: str, generate_mesh_plot: bool = False)[source]

Bases: Fespace

Represents a finite element space in 2D.

Parameters:
  • mesh (Mesh) – The mesh object.

  • cells (ndarray) – The array of cell indices.

  • boundary_points (dict) – The dictionary of boundary points.

  • cell_type (str) – The type of cell.

  • fe_order (int) – The order of the finite element.

  • fe_type (str) – The type of finite element.

  • quad_order (int) – The order of the quadrature.

  • quad_type (str) – The type of quadrature.

  • fe_transformation_type (str) – The type of finite element transformation.

  • bound_function_dict (dict) – The dictionary of boundary functions.

  • bound_condition_dict (dict) – The dictionary of boundary conditions.

  • forcing_function (function) – The forcing function.

  • output_path (str) – The output path.

  • generate_mesh_plot (bool, optional) – Whether to generate a plot of the mesh. Defaults to False.

generate_dirichlet_boundary_data() ndarray[source]

Generate Dirichlet boundary data.

This function returns the boundary points and their corresponding values.

Returns:

A tuple containing two arrays: - The first array contains the boundary points as numpy arrays. - The second array contains the values of the boundary points as numpy arrays.

Return type:

Tuple[np.ndarray, np.ndarray]

generate_dirichlet_boundary_data_vector(component) ndarray[source]

Generate the boundary data vector for the Dirichlet boundary condition.

This function returns the boundary points and their corresponding values for a specific component.

Parameters:

component (int) – The component for which the boundary data vector is generated.

Returns:

The boundary points and their values as numpy arrays.

Return type:

tuple(numpy.ndarray, numpy.ndarray)

generate_plot(output_path) None[source]

Generate a plot of the mesh.

Parameters:

output_path (str) – The path to save the generated plot.

get_forcing_function_values(cell_index) ndarray[source]

Get the forcing function values at the quadrature points.

Parameters:

cell_index (int) – The index of the cell.

Returns:

The forcing function values at the quadrature points.

Return type:

np.ndarray

Raises:

ValueError – If cell_index is greater than the number of cells.

This function computes the forcing function values at the quadrature points for a given cell. It loops over all the basis functions and computes the integral using the actual coordinates and the basis functions at the quadrature points. The resulting values are stored in the forcing_at_quad attribute of the corresponding fe_cell object.

Note: The forcing function is evaluated using the forcing_function method of the fe_cell object.

Example usage:
>>> fespace = FESpace2D()
>>> cell_index = 0
>>> forcing_values = fespace.get_forcing_function_values(cell_index)
get_forcing_function_values_vector(cell_index, component) ndarray[source]

This function will return the forcing function values at the quadrature points based on the Component of the RHS Needed, for vector valued problems

Parameters:
  • cell_index (int) – The index of the cell

  • component (int) – The component of the RHS needed

Returns:

The forcing function values at the quadrature points

Return type:

np.ndarray

Raises:

ValueError – If cell_index is greater than the number of cells

get_quadrature_actual_coordinates(cell_index) ndarray[source]

Get the actual coordinates of the quadrature points for a given cell.

Parameters:

cell_index (int) – The index of the cell.

Returns:

An array containing the actual coordinates of the quadrature points.

Return type:

np.ndarray

Raises:

ValueError – If the cell_index is greater than the number of cells.

Example:

>>> fespace = FESpace2D()
>>> fespace.get_quadrature_actual_coordinates(0)
array([[0.1, 0.2],
        [0.3, 0.4],
        [0.5, 0.6]])
get_quadrature_weights(cell_index) ndarray[source]

Return the quadrature weights for a given cell.

Parameters:

cell_index (int) – The index of the cell for which the quadrature weights are needed.

Returns:

The quadrature weights for the given cell of dimension (N_Quad_Points, 1).

Return type:

np.ndarray

Raises:

ValueError – If cell_index is greater than the number of cells.

Example

>>> fespace = FESpace2D()
>>> weights = fespace.get_quadrature_weights(0)
>>> print(weights)
[0.1, 0.2, 0.3, 0.4]
get_sensor_data(exact_solution, num_points)[source]

Obtain sensor data (actual solution) at random points.

This method is used in the inverse problem to obtain the sensor data at random points within the domain. Currently, it only works for problems with an analytical solution. Methodologies to obtain sensor data for problems from a file are not implemented yet. It is also not implemented for external or complex meshes.

Parameters:
  • exact_solution (function) – A function that computes the exact solution at a given point.

  • num_points (int) – The number of random points to generate.

Returns:

A tuple containing the generated points and the exact solution at those points.

Return type:

tuple(numpy.ndarray, numpy.ndarray)

get_sensor_data_external(exact_sol, num_points, file_name)[source]

This method is used to obtain the sensor data from an external file.

Parameters:
  • exact_sol (array-like) – The exact solution values.

  • num_points (int) – The number of points to sample from the data.

  • file_name (str) – The path to the file containing the sensor data.

Returns:

A tuple containing two arrays: - points (ndarray): The sampled points from the data. - exact_sol (ndarray): The corresponding exact solution values.

Return type:

tuple

get_shape_function_grad_x(cell_index) ndarray[source]

Get the gradient of the shape function with respect to the x-coordinate.

Parameters:

cell_index (int) – The index of the cell.

Returns:

An array containing the gradient of the shape function with respect to the x-coordinate.

Return type:

np.ndarray

Raises:

ValueError – If the cell_index is greater than the number of cells.

This function returns the actual values of the gradient of the shape function on a given cell.

get_shape_function_grad_x_ref(cell_index) ndarray[source]

Get the gradient of the shape function with respect to the x-coordinate on the reference element.

Parameters:

cell_index (int) – The index of the cell.

Returns:

An array containing the gradient of the shape function with respect to the x-coordinate.

Return type:

np.ndarray

Raises:

ValueError – If the cell_index is greater than the number of cells.

get_shape_function_grad_y(cell_index) ndarray[source]

Get the gradient of the shape function with respect to y at the given cell index.

Parameters:

cell_index (int) – The index of the cell.

Returns:

The gradient of the shape function with respect to y.

Return type:

np.ndarray

Raises:

ValueError – If the cell_index is greater than the total number of cells.

get_shape_function_grad_y_ref(cell_index)[source]

Get the gradient of the shape function with respect to y at the reference element.

Parameters:

cell_index (int) – The index of the cell.

Returns:

The gradient of the shape function with respect to y at the reference element.

Return type:

np.ndarray

Raises:

ValueError – If cell_index is greater than the number of cells.

This function returns the gradient of the shape function with respect to y at the reference element for a given cell. The shape function gradient values are stored in the basis_grady_at_quad_ref array of the corresponding finite element cell. The cell_index parameter specifies the index of the cell for which the shape function gradient is required. If the cell_index is greater than the total number of cells, a ValueError is raised.

Note

The returned gradient values are copied from the basis_grady_at_quad_ref array to ensure immutability.

get_shape_function_val(cell_index) ndarray[source]

Get the actual values of the shape functions on a given cell.

Parameters:

cell_index (int) – The index of the cell.

Returns:

An array containing the actual values of the shape functions.

Return type:

np.ndarray

Raises:

ValueError – If the cell_index is greater than the number of cells.

set_finite_elements() None[source]

Assigns the finite elements to each cell.

This method initializes the finite element objects for each cell in the mesh. It creates an instance of the FE2D_Cell class for each cell, passing the necessary parameters. The finite element objects store information about the basis functions, gradients, Jacobians, quadrature points, weights, actual coordinates, and forcing functions associated with each cell.

After initializing the finite element objects, this method prints the shape details of various matrices and updates the total number of degrees of freedom (dofs) for the entire mesh.

Returns:

None