chfem.compute_properties

chfem.compute_properties.compute_property(property, array, mat_props=None, voxel_size=1e-06, solver=None, solver_tolerance=1e-06, solver_maxiter=10000, precondition=True, type_of_rhs=0, refinement=1, direction='all', output_fields=None, nf_filepath=None)[source]

Computes the effective property of a material using chfem.

This function calculates the effective thermal conductivity, linear elasticity, or permeability of a material sample characterized by a 3D domain. The domain is discretized into voxels, each assigned a material phase with specific properties. It interfaces with the chfem cuda/c library to perform image-based finite element analysis.

Parameters:
  • property (str) – The physical property to be computed (‘conductivity’, ‘elasticity’, ‘permeability’).

  • array (np.ndarray) – 3D numpy array representing the material domain, where each voxel’s value is the material phase.

  • mat_props (dict) – Material properties corresponding to each phase in the domain, provided as {phase_id: cond} for conductivity and {phase_id: (young, poisson)} for elasticity, None for permeability

  • voxel_size (float, optional) – The edge length of each voxel in the domain, defaults to 1e-6 meters.

  • solver (str, optional) – The type of solver to use (‘cg’ for Conjugate Gradient, ‘minres’ for MINimal RESidual). Defaults to ‘cg’ for conductivity and elasticity, and ‘minres’ for permeability. Options: ‘cg’, ‘minres’ (5 vectors implementations, faster but more memory), ‘cg3’, ‘minres3’ (3 vectors, slower but less memory), ‘cg2’, ‘minres2’ (2 vectors, less memory but not fields output).

  • solver_tolerance (float, optional) – The tolerance for the solver convergence criterion, defaults to 1e-6.

  • solver_maxiter (int, optional) – The maximum number of iterations for the solver, defaults to 10000.

  • precondition (bool, optional) – Flag to use preconditioning in the solver, defaults to True.

  • type_of_rhs (int, optional) – Type of the right-hand side in the system of equations, defaults to 0.

  • refinement (int, optional) – Refinement level for the domain discretization, defaults to 1.

  • direction (str, optional) – Direction for calculating the property (‘x’, ‘y’, ‘z’, ‘yz’, ‘xz’, ‘xy’, ‘all’), defaults to ‘all’.

  • output_fields (str, optional) – File path to output the fields (e.g., displacement, temperature), defaults to None.

  • nf_filepath (str, optional) – Provide the path to a Neutral File (.nf) to specify the simulation settings.

Returns:

The effective property coefficient.

Return type:

list

Example:

>>> import chfem
>>> array = np.zeros((80, 90, 100), dtype=np.uint8)
>>> array[20:60, 30:70, 30:70] = 255
>>> keff = chfem.compute_property('conductivity', array, mat_props={255: 1, 0: 0.1}, direction='x', output_fields="cubes")
>>> Ceff = chfem.compute_property('elasticity', array, mat_props={255: (200, 0.2), 0: (100, 0.3)}, direction='x', output_fields="cubes") 
>>> Keff = chfem.compute_property('permeability', array, direction='x', output_fields="cubes")

chfem.io

chfem.io.export_for_chfem(filename, array, analysis_type, mat_props=None, voxel_size=1, solver_type=0, rhs_type=0, refinement=1, export_raw=True, export_nf=True, solver_tolerance=1e-06, solver_maxiter=10000, tmp_nf_file=None)[source]

Export a numpy array to run an analysis in chfem

Parameters:
  • filename (string) – filepath and name

  • array (np.array) – array to be exported

  • analysis_type (int) – 0 = conductivity, 1 = elasticity, 2 = permeability

  • mat_props (dict) – material properties for each phase as a dictionary. For conductivity, use {phase_id: cond}. For elasticity, use {phase_id: (young, poisson)}. For permeability, use None.

  • voxel_size (float) – voxel size

  • solver_type (int) – 0 = pcg (default), 1 = cg, 2 = minres

  • rhs_type (int) – type of right hand side (0 or 1)

  • export_raw (bool) – export .raw file from numpy array

  • export_nf (bool) – export .nf file with simulations inputs for chfem

  • solver_tolerance (float) – solver tolerance for simulation

  • solver_maxiter (int) – maximum number of iterations

  • tmp_nf_file (file) – only for use within the python API

Example:

>>> export_for_chfem('200_fiberform', array, 2, solver_tolerance=1e-6, solver_maxiter=100000)
chfem.io.import_raw(filename, shape, dtype=<Mock name='mock.uint8' id='139889078840320'>)[source]

Reads a .raw file (input for chfem_exec) into a numpy array.

Parameters:
  • filename (str) – The path to the .raw file.

  • shape (tuple(int, int, int)) – The shape of the numpy array. Should be a tuple (z, y, x) for 3D data.

  • dtype (np.dtype) – The data type of the array. Defaults to np.uint8.

Returns:

A numpy array with the specified shape and dtype, containing the data from the raw file.

Return type:

np.ndarray

chfem.io.import_scalar_field_from_chfem(filename, domain_shape, rotate_domain=True)[source]

Import scalar field (e.g. temperature, pressure) output from chfem

Parameters:
  • filename (string) – file path and name of .bin file

  • domain_shape ((int, int, int)) – shape of domain for which the scalar field was generated

  • rotate_domain (bool) – rotate the domain to be in the same format as export

Returns:

scalar field (x,y,z)

Return type:

np.ndarray

chfem.io.import_stress_field_from_chfem(filename, domain_shape, rotate_domain=True)[source]

Import stress fields output from chfem

Parameters:
  • filename (string) – file path and name of .bin file

  • domain_shape ((int, int, int)) – shape of domain for which the scalar field was generated

  • rotate_domain (bool) – rotate the domain to be in the same format as export

Returns:

direct stresses (x,y,z,3) and shear stresses (x,y,z,3)

Return type:

(np.ndarray, np.ndarray)

chfem.io.import_vector_field_from_chfem(filename, domain_shape, rotate_domain=True, correct_direction=None)[source]

Import vector field (e.g. heat flux, displacement, velocity) output from chfem

Parameters:
  • filename (string) – file path and name of .bin file

  • domain_shape ((int, int, int)) – shape of domain for which the scalar field was generated

  • rotate_domain (bool) – rotate the domain to be in the same format as export

  • correct_direction (str) – correct orientation field according to simulation direction, expects ‘x’, ‘y’, or ‘z’

Returns:

vector field (x,y,z,3)

Return type:

np.ndarray