chfem.io module

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, xreduce_scale_factor=1e-14, 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. shape = (z,y,x)==[slice,row,col]

  • 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

  • xreduce_scale_factor (float) – stabilization factor for xreduce in 2-vector solvers

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

Returns:

dictionary with .nf data

Return type:

dict

Example:

>>> export_for_chfem('200_fiberform', array, 2, solver_tolerance=1e-6, solver_maxiter=100000)
chfem.io.import_nf(filename)[source]

Reads a .nf file (input for chfem_exec) into a python dict.

Parameters:

filename (str) – The path to the .nf file.

Returns:

dictionary with .nf data

Return type:

dict

chfem.io.import_raw(filename, shape=None, dtype=<Mock name='mock.uint8' id='139829146634768'>)[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, (y, x) for 2D data.

  • dtype (np.dtype or string) – 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=False, dtype=<Mock name='mock.float64' id='139829146635776'>)[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 (x,y,z) format. default is (z,y,x), same as export.

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

Returns:

scalar field

Return type:

np.ndarray

chfem.io.import_stress_field_from_chfem(filename, domain_shape, rotate_domain=False, dtype=<Mock name='mock.float64' id='139829146635776'>)[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 (x,y,z) format. default is (z,y,x), same as export.

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

Returns:

vector field ( stress_field, *domain_shape ) [ stress_field=3 (2D) or stress_field=6 (3D) ]

Return type:

(np.ndarray, np.ndarray)

chfem.io.import_vector_field_from_chfem(filename, domain_shape, rotate_domain=False, dtype=<Mock name='mock.float64' id='139829146635776'>)[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 (x,y,z) format. default is (z,y,x), same as export.

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

Returns:

vector field ( len(domain_shape), *domain_shape )

Return type:

np.ndarray