FVM package

Submodules

FVM.boundaryCondition module

class fame.FVM.boundaryCondition.BoundaryCondition(mesh, *args, **kwargs)[source]

Bases: object

Initializes the BoundaryCondition object. :type mesh: :param mesh: The mesh object. :type mesh: StructuredMesh :param valueType: ‘scalar’, ‘vector’, or ‘tensor’. :type valueType: str

applyBoundaryCondition(x=None, y=None, z=None, value=0.0, tolerance=1e-06)[source]
getBoundaryMatrix()[source]
class fame.FVM.boundaryCondition.BoundaryCondition1D(mesh, *args, **kwargs)[source]

Bases: BoundaryCondition

Initializes the BoundaryCondition object. :type mesh: :param mesh: The mesh object. :type mesh: StructuredMesh :param valueType: ‘scalar’, ‘vector’, or ‘tensor’. :type valueType: str

applyBoundaryCondition(x=None, y=None, z=None, value=0.0, tolerance=1e-06)[source]
class fame.FVM.boundaryCondition.BoundaryCondition3D(mesh, *args, **kwargs)[source]

Bases: BoundaryCondition

Initializes the BoundaryCondition object. :type mesh: :param mesh: The mesh object. :type mesh: StructuredMesh :param valueType: ‘scalar’, ‘vector’, or ‘tensor’. :type valueType: str

applyBoundaryCondition(x=None, y=None, z=None, value=0.0, tolerance=1e-06)[source]

Apply boundary condition to a face based on x, y, z coordinates.

Parameters:
  • x (float, optional) – Coordinates of the target face.

  • y (float, optional) – Coordinates of the target face.

  • z (float, optional) – Coordinates of the target face.

  • value (float or np.array) – Boundary condition value (scalar, vector, or tensor).

  • tolerance (float) – Tolerance to identify nearby faces.

Returns:

Faces to which the boundary condition was applied.

FVM.discretization module

class fame.FVM.discretization.Discretization(mesh, solver, property, boundaryCondition)[source]

Bases: object

Initializes the Discretization class.

Parameters:
  • mesh (StructuredMesh) – The mesh object containing cells and shared face information.

  • solver (Solver) – The solver object containing matrix A and vector b.

  • property (MaterialProperty) – MaterialProperty object with material and property information.

  • boundaryCondition (BoundaryCondition) – BoundaryCondition object for applying boundary conditions.

discretizeHeatDiffusion()[source]

Discretize the 3D heat diffusion equation and populate the sparse matrix A and vector b from the solver class. Uses temperature-dependent thermal conductivity from the MaterialProperty class.

FVM.finiteVolumeMethod module

class fame.FVM.finiteVolumeMethod.FVM(config)[source]

Bases: object

applyBoundaryConditions(**kwargs)
discretize(**kwargs)
interpolateNodeFromCell(**kwargs)
loadMaterialProperty(**kwargs)
meshGeneration()[source]
simulate()[source]
solveEquations(**kwargs)
visualizeResults(**kwargs)
class fame.FVM.finiteVolumeMethod.FVM1D(config)[source]

Bases: FVM

meshGeneration(**kwargs)
visualizeResults(**kwargs)
class fame.FVM.finiteVolumeMethod.FVM3D(config)[source]

Bases: FVM

meshGeneration(**kwargs)

FVM.mesh module

class fame.FVM.mesh.StructuredMesh(bounds, divisions, **kwargs)[source]

Bases: object

Initializes the StructuredMesh.

Parameters:
  • bounds (tuple) – Bounds of the grid as ((x_min, x_max), (y_min, y_max), (z_min, z_max)).

  • divisions (tuple) – Number of divisions along x, y, z as (div_x, div_y, div_z).

class fame.FVM.mesh.StructuredMesh1D(bounds, divisions, **kwargs)[source]

Bases: StructuredMesh, vtkPolyData

Initializes the StructuredMesh.

Parameters:
  • bounds (tuple) – Bounds of the grid as ((x_min, x_max), (y_min, y_max), (z_min, z_max)).

  • divisions (tuple) – Number of divisions along x, y, z as (div_x, div_y, div_z).

GetDimensions()[source]

Returns the dimensions for the 1D mesh.

For a 1D mesh, the x-dimension is derived from the number of cells, and y and z dimensions are always 1.

Returns:

(nx, ny, nz)

Return type:

tuple

GetNumberOfCells(self) int[source]

C++: vtkIdType GetNumberOfCells() override;

Standard vtkDataSet interface.

calculateArea(vtk_points, includeNormal=False)[source]

Return the constant face area if nothing is specified

getCellVolume(cell_id)[source]

Calculate the volume of a 1D cell using its length and face area.

Parameters:

cell_id (int) – ID of the cell.

Returns:

Volume of the cell.

Return type:

float

Raises:

ValueError – If the cell ID is out of range.

getFacesByCoordinates(x=None, tolerance=1e-06)[source]

Retrieve face IDs by proximity to x-coordinate in 1D mesh.

Parameters:
  • x (float, optional) – x-coordinate to filter faces.

  • tolerance (float, optional) – Distance tolerance for matching faces.

Returns:

List of face IDs within the tolerance of the provided x-coordinate.

Return type:

list

Raises:

ValueError – If x is not provided.

getSharedCellsInfo(cell_id)[source]

Retrieve shared cells information for a specific cell.

Parameters:

cell_id (int) – ID of the cell.

Returns:

Information about shared cells and shared vertices.

Return type:

dict

class fame.FVM.mesh.StructuredMesh3D(bounds, divisions, **kwargs)[source]

Bases: StructuredMesh, vtkStructuredGrid

Initializes the StructuredMesh.

Parameters:
  • bounds (tuple) – Bounds of the grid as ((x_min, x_max), (y_min, y_max), (z_min, z_max)).

  • divisions (tuple) – Number of divisions along x, y, z as (div_x, div_y, div_z).

GetNumberOfCells(self) int[source]

C++: vtkIdType GetNumberOfCells() override;

Standard vtkDataSet API methods. See vtkDataSet for more information.

calculateArea(vtk_points, includeNormal=False)[source]

Calculate the area of a planar polygon using the Shoelace Formula.

Parameters:

vtk_points (vtk.vtkPoints) – vtkPoints object containing 3D coordinates of the polygon vertices.

Returns:

The computed area of the planar polygon.

Return type:

float

getCellCenter(cell_id)[source]

Retrieve the center of a specific cell.

Parameters:

cell_id (int) – ID of the cell.

Returns:

Center of the cell (x, y, z).

Return type:

tuple

getCellIdByFaceId(face_id)[source]

Retrieve the cell ID that owns a specific face ID.

Parameters:

face_id (int) – ID of the face to search for.

Returns:

The cell ID that owns the specified face.

Return type:

int

Raises:

ValueError – If the face ID does not belong to any cell.

getCellVolume(cell_id)[source]

Calculate the volume of a cell using the Gauss Divergence Theorem.

Parameters:

cell_id (int) – ID of the cell.

Returns:

Volume of the cell.

Return type:

float

getFaceByCenter(center, tolerance=1e-06)[source]

Retrieve all face IDs sorted by proximity to a center point, optionally filtered by a tolerance.

Parameters:
  • center (tuple or list) – Target center point (x, y, z).

  • tolerance (float, optional) – Distance tolerance. Defaults to 1e-9.

Returns:

List of face IDs sorted by proximity to the center point.

Return type:

list

getFaceById(face_id)[source]

Retrieve face points by face ID.

getFacesByCoordinates(x=None, y=None, z=None, tolerance=None)[source]

Retrieve face IDs by proximity to x, y, or z coordinates, optionally within a tolerance.

Parameters:
  • x (float, optional) – x-coordinate to filter faces.

  • y (float, optional) – y-coordinate to filter faces.

  • z (float, optional) – z-coordinate to filter faces.

  • tolerance (float, optional) – Distance tolerance. If provided, returns all faces within the tolerance along specified axes.

Returns:

List of face IDs within the tolerance of the provided coordinates.

Return type:

list

Raises:

ValueError – If none of x, y, z are provided.

getSharedCellsInfo(cell_id)[source]

Retrieve shared cells information for a specific cell.

Parameters:

cell_id (int) – ID of the cell.

Returns:

Information about shared cells and shared vertices.

Return type:

dict

listFacesByPoint(point_id)[source]

Retrieve all faces associated with a given point.

FVM.physics module

FVM.property module

class fame.FVM.property.MaterialProperty(materialName, properties=None)[source]

Bases: object

Initialize a material with multiple properties.

Parameters:
  • materialName – Name of the material (e.g., ‘Aluminum’)

  • properties – Dictionary of properties (e.g., {‘thermal_conductivity’: {…}, ‘heat_capacity’: {…}})

add_property(propertyName, baseValue, referenceTemperature=298.15, method='constant', coefficients=None)[source]

Add or update a property for the material.

Parameters:
  • propertyName – Name of the property (e.g., ‘thermal_conductivity’)

  • baseValue – Value at reference temperature (referenceTemperature)

  • referenceTemperature – Reference temperature (default is 298.15 K)

  • method

    Method for temperature dependency (‘constant’, ‘linear’, ‘polynomial’, ‘exponential’)

    1. Constant: \(material property = baseValue\)

    2. Polynomial: \(material property = baseValue \cdot (1+c_0 \cdot {(\Delta T})^n + c_1 \cdot {(\Delta T})^{n-1} + ... + c_n)\)

    3. Exponential: \(material property = a_{0} \cdot e^{\beta\Delta T}\)

  • coefficients – Coefficients for polynomial or exponential models

evaluate(propertyName, temperature)[source]

Evaluate a specific property at a given temperature.

Parameters:
  • propertyName – Property to evaluate (e.g., ‘thermal_conductivity’)

  • temperature – Temperature at which to evaluate the property

Returns:

Evaluated property value

FVM.solver module

class fame.FVM.solver.Solver(A, b, backend='scipy')[source]

Bases: object

Initialize the solver with the matrix A, vector b, and backend.

Parameters: A: scipy.sparse matrix (A in Ax = b) b: numpy array (b in Ax = b) backend: str, one of [“scipy”, “jax”, “petsc”]

plotSparseMatrix(matrix, filename='matrix.jpeg')[source]

Saves a visualization of the sparse matrix as a .jpeg image.

Parameters:
  • matrix (sp.spmatrix) – Sparse matrix to visualize.

  • filename (str) – Output file name for the image.

solve(method='bicgstab', preconditioner='none')[source]

Solve the system Ax = b using the selected backend and method.

Parameters:
  • method – str, optional (default=”bicgstab”) The solver method to use (e.g., “bicgstab”, “cg”, “gmres”).

  • preconditioner – str, optional (default=”none”) Preconditioner type (e.g., “jacobi”) or “none” for no preconditioning. For PETSc, passed directly to pc.setType().

Returns:

numpy array

The solution vector.

Return type:

solution

FVM.visualization module

class fame.FVM.visualization.MeshWriter(mesh)[source]

Bases: object

Initialize with a StructuredMesh instance.

Parameters:

mesh (StructuredMesh) – The structured mesh object containing the grid and scalar data.

class fame.FVM.visualization.MeshWriter1D(mesh)[source]

Bases: MeshWriter

Initialize with a StructuredMesh instance.

Parameters:

mesh (StructuredMesh) – The structured mesh object containing the grid and scalar data.

writeVTS(output_dir, variables, time=None, step=None)[source]
class fame.FVM.visualization.MeshWriter3D(mesh)[source]

Bases: MeshWriter

Definition of 3D mesh writer.

Initialize with a StructuredMesh instance.

Parameters:

mesh (StructuredMesh) – The structured mesh object containing the grid and scalar data.

writeVTS(output_dir, variables, time=None, step=None)[source]

Writes a single timestep data to a .vts file and updates the PVD file. For steady-state, it writes a single time step.

Parameters:
  • output_dir (str) – Directory to save the output .vts file and PVD file.

  • variables (dict) – Dictionary of variables for the timestep.

  • time (float, optional) – Time value for the current timestep. Defaults to 0.0 for steady-state.

  • step (int, optional) – Step index for naming the .vts file. Defaults to 0 for steady-state.

Module contents