femio package
Subpackages
- femio.formats package
- femio.util package
- Submodules
- femio.util.brick_generator module
- femio.util.random_generator module
- femio.util.string_parser module
HeaderData
ListStringSeries
StringSeries
StringSeries.concat()
StringSeries.connect()
StringSeries.connect_all()
StringSeries.delimit()
StringSeries.expand_include()
StringSeries.extract_captures()
StringSeries.find_match()
StringSeries.indices_match_clusters()
StringSeries.indices_matches()
StringSeries.read_array()
StringSeries.read_file()
StringSeries.read_files()
StringSeries.split_vertical()
StringSeries.split_vertical_all()
StringSeries.strip()
StringSeries.to_dict_fem_attributes()
StringSeries.to_fem_attribute()
StringSeries.to_header_data()
StringSeries.to_values()
- Module contents
Submodules
femio.config module
femio.fem_attribute module
- class femio.fem_attribute.FEMAttribute(name, ids, data, *, data_unit='unit_unknown', silent=False, generate_id2index=False, time_series=False, original_shape=None, parent=None)
Bases:
object
Represents one attribute of FEM data such as node, element, displacement, …
- name
String indicating the name of the attribute.
- Type:
str
- ids
Ndattay of ints indicating either IDs e.g. node ID, element ID.
- Type:
numpy.ndarray[int]
- data
Ndarray of data content.
- Type:
numpy.ndarray
- data_unit
String indicating unit of the data.
- Type:
str
- time_series
If True, it indicates time series data.
- Type:
bool
- property data
- property data_frame
- filter_with_ids(ids)
- classmethod from_dict(name, dict_data, **kwargs)
Create FEMAttribute object from the specified dict_data.
- Parameters:
name (str) – Name of the attribute.
dict_data (Dict[str, numpy.ndarray]) – Dict mapping from attribute (ID or data) name to its values.
- Return type:
- property ids
- ids2indices(ids, id2index=None)
Return indices corresponding input ids.
- Parameters:
ids (numpy.ndarray or femio.FEMElementalAttribute) – IDs.
id2index (pandas.DataFrame, optional) – DataFrame of IDs and indices. If not fed and self does not have it, this function raises ValueError.
- Returns:
indices – Indices corresponding to ids.
- Return type:
numpy.ndarray
- property iloc
- classmethod load(name, file_, **kwargs)
Load npz file to create FEMAttribute object.
- Parameters:
name (str) – Name of the attribute.
file (file, str, or path.Path) – File or file name to which the data is saved.
- Return type:
- property loc
- save(file_)
Save the contents.
- Parameters:
file (file, str, or path.Path) – File or file name to which the data is saved.
- Return type:
None
- to_dict(prefix=None)
Convert to dict.
- Parameters:
prefix (str, optional) – If fed, add f”{prefix}/” to the dictionary key.
- Returns:
Dictionay which maps f”{attribute_name}_ids” or f”{attribute_name}_data” to data contents.
- Return type:
Dict[str, numpy.ndarray]
- update(ids, values, *, allow_overwrite=False)
Update FEMAttribute with new ids and values.
- Parameters:
ids (List[str], List[int], or int) – IDs of new rows.
values (numpy.ndarray, float, or int) – Values of new rows.
allow_overwrite (bool, optional) – If True, allow overwrite existing rows. The default is False.
- update_data(values)
- property values
femio.fem_attributes module
- class femio.fem_attributes.FEMAttributes(attributes=None, names=None, ids=None, list_arrays=None, *, is_elemental=False)
Bases:
object
Represents dictionary of FEMAttributes.
- data
or Dict[str, femio.FEMElementalAttribute]
- Type:
Dict[str, femio.FEMAttribute]
- are_same_lengths()
See if the attributes have the same lengths.
- extract_dict(ids)
Extract FEMAttributes data with IDs.
- Parameters:
ids (List[str], List[int], str, or int) – IDs of FEMAttributes to extract.
- Returns:
extracted_dict – Extracted dict mapping from attribute names to attribute values.
- Return type:
Dict[str, np.ndarray]
- filter_with_ids(ids)
- classmethod from_dict(dict_data, **kwargs)
Create FEMAttributes object from the specified dict_data.
- Parameters:
dict_data (Dict[str, numpy.ndarray]) – Dict mapping from attribute (ID or data) name to its values.
- Return type:
- classmethod from_meshio(ids, dict_data, is_elemental=False)
- get_attribute_data(key, *, mandatory=True)
Get contents of the specified attribute.
- Parameters:
key (str or List[str]) – key to access the data.
mandatory (bool, optional) – If True, raise ValueError if no data is found. The default is True.
- Returns:
data
- Return type:
numpy.ndarray or List[numpy.ndarray]
- get_attribute_ids(key, *, mandatory=True)
Get IDs of the specified attribute.
- Parameters:
key (str or List[str]) – key to access the data.
mandatory (bool, optional) – If True, raise ValueError if no data is found. The default is True.
- Returns:
data
- Return type:
numpy.ndarray or List[numpy.ndarray]
- get_data_length()
- get_n_material(fem_attributes=None)
Count the number of material properties contained in the fem_attributes.
- Parameters:
fem_attributes (FEMAttributes, optional) – If not fed, self will be used.
- Returns:
has_material
- Return type:
bool
- has_material(fem_attributes=None)
Check if fem_attributes have materials.
- Parameters:
fem_attributes (FEMAttributes, optional) – If not fed, self will be used.
- Returns:
has_material
- Return type:
bool
- items()
- keys()
- classmethod load(npz_file_name, **kwargs)
Load data from npz file.
- Parameters:
npz_file (file, str, or pathlib.Path) – Npz file.
- Return type:
- overwrite(name, data, *, ids=None)
Overwrite data.
Paremeters
- name: str
Attribute name to be overwritten.
- data: numpy.ndarray
New data to overwrite with.
- ids: numpy.ndarray
IDs for new data.
- pop(key, default=None)
Pop data contents.
- Parameters:
key (str or List[str]) – key to access the data.
- Returns:
data
- Return type:
numpy.ndarray or List[numpy.ndarray]
- reset()
Reset data contents.
- Parameters:
None
- Return type:
None
- save(file_)
Save the contents.
- Parameters:
file (file, str, or path.Path) – File or file name to which the data is saved.
- Return type:
None
- set_attribute_data(key, data, *, allow_overwrite=False, name=None)
Set attribute data.
- Parameters:
key (str) – Key of the new data.
data (numpy.ndarray) – New data which has the same length as these of existing attributes.
allow_overwrite (bool, optional) – If True, allow overwriting existing data. The default is False.
name (str, optional) – The name of the new attribute. The default is the same as the key.
- to_dict()
Convert to dict.
- Parameters:
prefix (str, optional) – If fed, add f”{prefix}/” to the dictionary key.
- Returns:
Dictionay which maps f”{attribute_name}_ids” or f”{attribute_name}_data” to data contents.
- Return type:
Dict[str, numpy.ndarray]
- to_meshio()
- update(dict_attributes)
Update FEMAttribute data with new dictionary.
- Parameters:
dict_attributes (Dict[str, FEMAttribute] or FEMAttributes)
- Return type:
None
- update_data(ids, data_dict, *, allow_overwrite=False, raise_overwrite=False)
Update data with new data_dict.
- Parameters:
ids (List[str], List[int], str, or int) – IDs of FEMAttributes.
data_dict (Dict[str, np.ndarray]) – Dictionary of data mapping from property names to property values.
allow_overwrite (bool, optional) – If True, allow overwrite existing rows. The default is False.
raise_overwrite (bool, optional) – If True, raise ValueError when one tries to overwrite data. The default is False.
- update_time_series(list_dict_attributes)
Update FEMAttribute data with new dictionary.
- Parameters:
list_dict_attributes – List[Dict[str, FEMAttribute]] or List[FEMAttributes]
- Return type:
None
- values()
femio.fem_data module
- class femio.fem_data.FEMData(nodes=None, elements=None, *, nodal_data=None, elemental_data=None, node_groups=None, element_groups=None, materials=None, sections=None, constraints=None, settings=None, file_names=None)
Bases:
GraphProcessorMixin
,GeometryProcessorMixin
,SignalProcessorMixin
Represents FEM data generary.
- file_names
util.string.StringSeries object indicating source files.
- nodes
FEMAttribute object. ids: Node IDs. data: Node positions.
- elements
FEMAttribute object or dict of FEMAttribute objects. ids: Element IDs. data: Node IDs composing the element.
- nodal_data
dict with key = string, value = FEMAttribute object. ids of each component corresponds to node IDs.
- elemental_data
dict with key = string, value = FEMAttribute object. ids of each component corresponds to node IDs.
- node_groups
dict with key = string, value = ndarray of ints of IDs.
- element_groups
dict with key = string, value = ndarray of ints of IDs.
- materials
dict with key = string, value = FEMMaterial object.
- sections
list of dicts with keys == [‘EGRP’, ‘MATERIALS’] indicating material asignments to element groups.
- settings
dict with key = string, value = any object.
- add_extension_if_needed(file_name, ext)
- add_static_material()
Add simple material data for static analysis.
- static convert_polyhedron(now_ids, new_ids, poly)
- create_element_group_from_node_group(element_group_name, node_group_name, kind='all')
Create new surface group from a node group.
An element is in the created group when (all / any) of the nodes is contained in the node group.
- Parameters:
element_group_name (str) – The name of new element group.
node_group_name (str) – The name of original node group.
kind ({'all', 'any'}, default 'all') – Type of creation rule.
- create_node_group(group_name, selected)
Create new node_group.
- Parameters:
group_name (str) – The name of new node group.
selected (np.ndarray, bool) – 1D mask array, containing data with boolean type.
- cut_elements_with_node_ids(node_ids)
- cut_with_element_ids(element_ids)
- cut_with_element_type(element_type)
- cut_with_node_ids(node_ids)
- extract_with_element_indices(element_indices)
Extract a sub-FEMData object with the specified element indices.
- Parameters:
element_indices (numpy.ndarray[int]) – Element indices to extract the data.
- Returns:
sub_fem_data – Extracted FEMData object.
- Return type:
femio.FEMData
- face_data_csr()
- classmethod from_meshio(meshio_data)
Construct FEMData object from meshio.Mesh object.
- Parameters:
meshio_data (meshio.Mesh)
- Returns:
fem_data
- Return type:
- generate_graph_fem_data(adjs, *, mode='nodal', attribute_name='data')
Generate FEMData of the specified graphs.
- Parameters:
adjs (List[scipy.sparse]) – Adjacency matrices with the same shape and the same non-zero profile.
mode (str, optional) – ‘nodal’ or ‘elemental’.
attribute_name (str, optional) – The name of the edge feature. The default is ‘data’.
- Returns:
graph_fem_data – FEMData object of the specified graph.
- Return type:
femio.FEMData
- static hex_to_polyhedron(dat, node_ids, argsort)
- overwritten_material_exists()
Check if material is overwritten.
- Returns:
overwritten_material_exists
- Return type:
bool
- static prism_to_polyhedron(dat, node_ids, argsort)
- static pyr_to_polyhedron(dat, node_ids, argsort)
- classmethod read_directory(file_type, dir_name, *, read_mesh_only=False, recursive=False, read_npy=True, save=True, read_res=True, stem=None, time_series=False)
Initialize FEMData object from directory.
- Parameters:
file_type (Sting indicating type of FEM. The following formats are) –
- supported:
’fistr’: FrontISTR
’ucd’: UCD old format
dir_name (String of directory name.)
read_mesh_only (Bool. If true, read mesh (nodes and elements) and) – ignore material data, results and so on. Default is False.
recursive (Bool if make recursive search.)
read_npy (Bool if read npy files when exist)
stem (Stem of files to be read.)
- classmethod read_files(file_type, file_names, *, read_mesh_only=False, time_series=False)
Initialize FEMData object from files.
- Parameters:
file_type –
Sting indicating type of FEM. The following formats are supported:
’fistr’: FrontISTR
’ucd’: UCD old format
’obj’: Wavefront obj format
’stl’: Stereolithography format
file_names – List of strings indicating file names. Order of files is arbitrary.
read_mesh_only – Bool. If true, read mesh (nodes and elements) and ignore material data, results and so on. Default is False.
time_series – bool, optional [False] If True, parse files as time series data.
- classmethod read_meshio_file(file_names, read_mesh_only=False)
Read files supported with meshio and create FEMData object.
- Parameters:
file_names (femio.util.StringSeries) – File names.
read_mesh_only (bool, optional [False]) – If true, read mesh (nodes and elements) and ignore material data, results and so on.
- Returns:
fem_data
- Return type:
- classmethod read_npy_directory(dir_name, *, read_mesh_only=False)
Initialize FEMData object from directory with npy files. :param dir_name: String of directory name. :param read_mesh_only: Bool. If true, read mesh (nodes and elements) and
ignore material data, results and so on. Default is False.
- Parameters:
recursive – Bool if make recursive search.
- remove_useless_nodes()
Remove useless nodes which are not referenced from elements.
- Parameters:
None
- Returns:
FEMAttribute object
- Return type:
resultant_nodes
- resolve_degeneracy()
Resolve degeneracy in hex elements, and return resolved new FEMData.
- save(dir_name, *, save_mesh_only=False)
Write FEM data into the specified format.
- Parameters:
dir_name – str or pathlib.Path Directory name to be saved.
save_mesh_only – Bool, optional, [False] If true, save only node and element information.
- static tet_to_polyhedron(dat, node_ids, argsort)
- to_facets(remove_duplicates=True, return_dict_facets=False, dict_facets=None)
Convert the FEMData object to the facet data including facets inside the solid.
- Parameters:
remove_duplicates (bool, optional) – If True, remove duplicated faces and remain only one. The default is True.
return_dict_facets (bool, optional) – If True, also return dict_facets.
- Returns:
Facets FEMData object.
- Return type:
- to_first_order()
Convert the FEMData object to the first order data.
- Returns:
First order FEMData object.
- Return type:
- to_meshio()
- to_polyhedron()
- to_surface(*, remove_unnecessary_nodes=True)
Convert the FEMData object to the surface data.
- Parameters:
remove_unnecessary_nodes (bool, optional) – If True, remove nodes unnecessary for surface. The default is True.
- Returns:
Surface FEMData object.
- Return type:
- write(file_type, file_name=None, *, overwrite=False, write_msh_only=False, include_displacement=False)
Write FEM data into the specified format.
- Parameters:
file_type –
Sting indicating type of FEM. The following formats are supported:
’fistr’: FrontISTR
’ucd’: UCD old format
’stl’: stereolithography format
’obj’: Wavefront OBJ format
file_name – File name of the output file. If not fed, input_filename.out.ext will be the output file name.
overwrite – Bool, if True, allow averwrite files (Default: False.)
write_msh_only – Bool, if True, omit writing cnt file (Default: False,) for file_type == ‘fistr’ case.
femio.fem_elemental_attribute module
- class femio.fem_elemental_attribute.FEMElementalAttribute(name, data=None, *, ids=None, use_object=False, silent=False, time_series=False, element_type=None, **kwargs)
Bases:
dict
Reperesents FEM element.
- ELEMENT_TYPES = ['line', 'line2', 'spring', 'tri', 'tri2', 'quad', 'quad2', 'polygon', 'tet', 'tet2', 'pyr', 'pyr2', 'prism', 'prism2', 'hex', 'hex2', 'hexprism', 'polyhedron', 'unknown']
- property data
- detect_element_type(element_data)
- property dict_type_ids
- property element_type
- filter_with_ids(ids)
- classmethod from_dict(name, dict_data, **kwargs)
Create FEMElementalAttribute object from the specified dict_data.
- Parameters:
name (str) – Name of the attribute.
dict_data (Dict[str, numpy.ndarray]) – Dict mapping from element type name to its values.
- Return type:
- classmethod from_meshio(cell_data)
- generate_elemental_attribute(name, ids, data)
Generate elemental attribute from IDs and data.
- Parameters:
name (str) – The name of the attribute.
ids (List[int] or List[str]) – Attribute IDs. All IDs should be in the element IDs.
data (numpy.ndarray) – Attribute data.
- Returns:
elemental_attribute – Generated FEMElementalAttribute object.
- Return type:
- get_attribute_ids()
- get_n_element_type()
- property id2index
- property ids
- property ids_types
- is_first_order()
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- classmethod load(name, file_, **kwargs)
Load npz file to create FEMAttribute object.
- Parameters:
name (str) – Name of the attribute.
file (file, str, or path.Path) – File or file name to which the data is saved.
- Return type:
- save(file_)
Save the contents.
- Parameters:
file (file, str, or path.Path) – File or file name to which the data is saved.
- Return type:
None
- to_dict(prefix=None)
Convert to dict.
- Parameters:
prefix (str, optional) – If fed, add f”{prefix}/” to the dictionary key.
- Returns:
Dictionay which maps f”{attribute_name}_ids” or f”{attribute_name}_data” to data contents.
- Return type:
Dict[str, numpy.ndarray]
- to_first_order()
- to_meshio(nodes)
Convert to meshio-like cell data. It assumes self is elements (not elemental_data).
- Parameters:
nodes (FEMAttribute) – Node data.
- Returns:
cell_info – Dict mapping from cell type to cell connectivity data.
- Return type:
dict[str, numpy.ndarray]
- to_surface(surface_ids)
Convert the FEMElementalAttribute object to surface.
- Parameters:
surface_ids (numpy.ndarray) – [n_facet, n_node_per_facet]-shaped array of surface IDs.
- Returns:
FEMElementalAttribute object of the surface.
- Return type:
- to_vtk(nodes)
- property types
- property unique_types
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values
femio.fem_writer module
femio.functions module
- femio.functions.align_nnz(sparses)
Align a sparse matrices to have the same nnz profile as ref.
- Parameters:
sparses (List[scipy.sparse.csr_matrix] or List[scipy.sparse.coo_matrix])
- Return type:
scipy.sparse.csr_matrix
- femio.functions.calculate_array_from_eigens(eigenvalues, eigenvectors, to_engineering=False)
- femio.functions.calculate_principal_components(in_array, *, from_engineering=False, order=None)
Calculate eigenvalues and eigenvectors of the input arrays which are parts of symmetric matrices.
- Parameters:
in_array – numpy.ndarray (n, 6) shaped array to form symmetric matrices.
from_engineering – bool, optional [False] If True, treat in_array as engineering-strain-like data.
order – array-like, optional [[0, 1, 2, 3, 4, 5]] The order of in_array. The order should be [11, 22, 33, 12, 23, 31] order.
- Returns:
- numpy.ndarray
(n, 3) shaped array of eigenvalues.
- eigenvectors: numpy.ndarray
(n, 9) shaped array of eigenvectors.
- Return type:
eigenvalues
- femio.functions.calculate_symmetric_matrices_from_eigens(eigenvalues, eigenvectors)
- femio.functions.convert_array2symmetric_matrix(in_array, *, from_engineering=False, order=None)
Convert (n, 6) shaped array to (n, 3, 3) symmetric matrix.
- Parameters:
in_array – numpy.ndarray (n, 6) shaped array.
from_engineering – bool, optional [False] If True, treat in_array as engineering-strain-like data.
order – array-like, optional [[0, 1, 2, 3, 4, 5]] The order of in_array. The order should be [11, 22, 33, 12, 23, 31] order.
- Returns:
- numpy.ndarray
(n, 6, 6) symmetric matrix.
- Return type:
symmetrc_matrix
- femio.functions.convert_symmetric_matrix2array(in_matrix, *, to_engineering=False, order=None)
Convert (n, 3, 3) shaped symmetric matrices to (n, 6) array.
- Parameters:
in_matrix – numpy.ndarray (n, 6, 6) symmetric matrix.
to_engineering – bool, optional [False] If True, the out_array will be converted to engineering-strain-like data.
order – array-like, optional [[0, 1, 2, 3, 4, 5]] The order of out_array. The order should be [11, 22, 33, 12, 23, 31] order.
- Returns:
- numpy.ndarray
(n, 6) shaped array.
- Return type:
out_array
- femio.functions.invert_strain(strain, is_engineering=False)
- femio.functions.normalize(array, keep_zeros=False)
Normalizes input array.
- Parameters:
array (numpy.ndarray) – 2-dimensional input array
keep_zeros (bool, optional) – If True, keep zero vectors as is. The default is False.
- Returns:
Normalized array
- Return type:
numpy.ndarray
- femio.functions.remove_duplicates(connectivities, return_index=False, return_inverse=False, end=None)
Remove duplicating elements.
- Parameters:
connectivities (numpy.ndarray[int]) – Element connectivities.
return_index (bool, optional) – If True, return also indices of unique.
return_inverse (bool, optional) – If True, return also the inverse_indice
end (int, optional) – If fed, use only first end elements to detect duplication.
- Returns:
connectivities_wo_duplications – Element connectivities without duplications.
- Return type:
numpy.ndarray[int]
femio.geometry_processor module
- class femio.geometry_processor.GeometryProcessorMixin
Bases:
object
- calculate_all_element_normals(facet_data=None)
Calculate normal vectors of each elements. If the elements are solid, then multiple normal vectors per solid will be generated.
- Returns:
normals (numpy.ndarray) – (n_element, n_faces_per_element, 3)-shaped array.
facet_data (femio.FEMData) – FEMData object of facet data.
- calculate_angles()
Calculate angles of each element. Calculated angles are returned and also stored in the fem_data.elemental_data dict with key = ‘angles’ .
- Returns:
numpy.ndarray
- Return type:
angles
- calculate_edge_lengths()
Calculate edge lengths of each element. Calculated lengths are returned and also stored in the fem_data.elemental_data dict with key = ‘edge_lengths’ .
- Returns:
numpy.ndarray
- Return type:
edge_lengths
- calculate_element_areas(*, mode='centroid', raise_negative_area=False, return_abs_area=True, elements=None, element_type=None, update=True)
Calculate areas of each element assuming that the geometry of higher order elements is the same as that of order 1 elements. Calculated areas are returned and also stored in the fem_data.elemental_data dict with key = ‘area’ .
- Parameters:
mode (str, optional ["centroid"]) – If “gaussian”, areas are calculated by gaussian integral. If “linear”, areas are calculated under the assumption that all elements is linear, and it runs a bit faster. If “centroid”, areas are calculated by decomposing it into triangles at centroid. Therefore, the result doesn’t depend on the node labels.
raise_negative_area (bool, optional [False]) – If True, raise ValueError when negative area exists.
return_abs_area (bool, optional [True]) – If True, return absolute area instead of signed area.
elements (femio.FEMAttribute) – If fed, compute volumes for the fed one.
- Returns:
areas
- Return type:
numpy.ndarray
- calculate_element_centroids(element_type=None, elements=None)
Calculate centroid of each element.
- Parameters:
element_type (str, optional) – Element type of the element.
elements (femio.FEMAttribute, optional) – If fed, compute centroids for the fed one.
- Returns:
centroid – [n_elemnt, 3] shaped array of centroid coordinates.
- Return type:
numpy.ndarray[float]
- calculate_element_metrics(*, raise_negative_metric=True, return_abs_metric=False, elements=None, element_type=None, update=True)
Calculate metric (area or volume depending on the mesh dimension) of each element assuming that the geometry of higher order elements is the same as that of order 1 elements. Calculated metrics are returned and also stored in the fem_data.elemental_data dict with key = ‘metric’.
- Parameters:
raise_negative_metric (bool, optional [True]) – If True, raise ValueError when negative metric exists.
return_abs_metric (bool, optional [False]) – If True, return absolute volume instead of signed metric.
elements (femio.FEMAttribute) – If fed, compute volumes for the fed one.
- Returns:
metrics
- Return type:
numpy.ndarray
- calculate_element_normals(mode='centroid', elements=None, element_type=None, update=True)
Calculate normal vectors of each shell elements. Please note that the calculated normal may not be aligned with neighbor elements. To make vector field smooth, use femio.extract_direction_feature() method.
Args: mode: str, optional [“centroid”]
If “centroid”, normal vectors are calculated by decomposing it into triangles at centroid. Therefore, the result doesn’t depend on the node labels.
- Returns:
- numpy.ndarray
(n_element, 3)-shaped array.
- Return type:
normals
- calculate_element_volumes(*, mode='centroid', raise_negative_volume=True, return_abs_volume=False, elements=None, element_type=None, faces=None, update=True)
Calculate volume of each element assuming that the geometry of higher order elements is the same as that of order 1 elements. Calculated volumes are returned and also stored in the fem_data.elemental_data dict with key = ‘volume’ .
- Parameters:
mode (str, optional ["centroid"]) – If “gaussian”, volumes are calculated by gaussian integral. If “linear”, volumes are calculated under the assumption that all elements are linear, and it runs a bit faster. If “centroid”, volumes are calculated by decomposing their surfaces into triangles at centroid. Therefore, the result doesn’t depend on the node labels.
raise_negative_volume (bool, optional [True]) – If True, raise ValueError when negative volume exists.
return_abs_volume (bool, optional [False]) – If True, return absolute volume instead of signed volume.
elements (femio.FEMAttribute) – If fed, compute volumes for the fed one.
- Returns:
volumes
- Return type:
numpy.ndarray
- calculate_jacobians()
Calculate jacobians of each element. Calculated jacobians are returned and also stored in the fem_data.elemental_data dict with key = ‘jacobians’ .
- Returns:
numpy.ndarray
- Return type:
jacobians
- calculate_normal_incidence_matrix()
Calculate incidence matrix based on the normal vector which point outside of each element.
- Returns:
facet_fem_data (femio.FEMData)
signed_incidence_matrix (scipy.sparse.csr_matrix[int]) – Positive if the direction of the facet’s normal vector is in outside direction. Negative otherwise.
facet_normal_vectors (numpy.ndarray[float]) – [n_facet, 3]-shaped array represents normal vectors of facets.
- calculate_surface_normals(mode='mean')
Calculate nodal normal vectors of the surface of a solid mesh. If an node is not on the surface, the vector will be zero.
- Parameters:
mode – str, optional If ‘mean’, use mean metric to weight. If ‘effective’, use effective metric to weight. The default is ‘mean’.
- Returns:
- numpy.ndarray
(n_node, 3)-shaped array.
- Return type:
normals
- extract_direction_feature(vectors, *, skip_normalization=False)
Extract direction feature, which take into account v ~ -v symmetricity. The resultant vectors will not have the same directions as originals’, but the vector field will be smoother.
- Parameters:
vectors – numpy.ndarray (n, 3) shaped input vectors.
skip_normalization – bool, optional [False] If True, skip normalization of vector.
- integrate_node_attribute_over_surface(attr_name)
Integrate a node attribute over surface areas.
- Parameters:
attr_name (str) – The name of node attribute.
- Returns:
integrated_value
- Return type:
float number
- make_elements_positive()
Perfmute element connectivity order when it has negative volume.
- rotation(vx, vy, vz, theta)
Rotate the nodes, around straight line which throw (0,0,0) and (vx,vy,vz).
- Parameters:
vx (float) – The axis of the rotation.
vy (float) – The axis of the rotation.
vz (float) – The axis of the rotation.
theta (float) – Rotation angle.
- translation(vx, vy, vz)
Translate the nodes. If nodal_data or elemental_data exists, NotImplementedError is raised.
- Parameters:
vx (float) – Coordinates of the translation vector.
vy (float) – Coordinates of the translation vector.
vz (float) – Coordinates of the translation vector.
femio.graph_processor module
- class femio.graph_processor.GraphProcessorMixin
Bases:
object
- static build_octree_element(triangles, boundingbox)
- static build_octree_node(points, boundingbox)
- calculate_adjacency_matrix(*, mode='elemental', order1_only=False)
Calculate graph adjacency matrix.
- Parameters:
mode (str, optional (['elemental'], 'nodal')) – If ‘elemental’, generate (n_element, n_element) shaped adjacency matrix where edges are defined by node shearing. If ‘nodal’, generate (n_node, n_node) shaped adjacency matrix with edges are defined by element shearing.
order1_only (bool, optional [True]) – If True, consider only order 1 nodes. Effective only when mode == ‘nodal’.
- Returns:
adj – Adjacency matrix in CSR expression.
- Return type:
scipy.sparse.csr_matrix
- calculate_adjacency_matrix_element(order1_only=False)
Calculate graph adjacency matrix regarding elements sharing the same node as connected.
- Returns:
adj – Adjacency matrix in CSR expression.
- Return type:
scipy.sparse.csr_matrix
- calculate_adjacency_matrix_node(order1_only=False)
Calculate graph adjacency matrix regarding nodes connected with edges. Edges are defined by element shearing.
- Parameters:
order1_only (bool, optional [True]) – If True, consider only order 1 nodes.
- Returns:
adj – Adjacency matrix in CSR expression.
- Return type:
scipy.sparse.csr_matrix
- calculate_e2v_matrix(mode='elemental', include_self_loop=False)
Calculate aggregation matrix from elemental data to vertex data ( in terms of either elemental or nodal graph).
- Parameters:
mode (str, optional) – Mode of graph, which is either ‘elemental’ or ‘nodal’. Defaults to ‘elemental’.
include_self_loop (bool, optional) – If True, include self loop to the operation. Defaults to False.
- Returns:
e2v_matrix – Aggregation matrix in COO format.
- Return type:
scipy.sparse.coo_matrix
- calculate_edge_gradient_matrix(mode='nodal', order1_only=False)
Calculate edge-based graph gradient matrix, which is (n_edge, n_vertex)-shaped matrix with bool. n_vertex can be either n_node or n_element, depending on the mode option.
- Parameters:
mode (str, optional, ['nodal', 'elemental'])
order1_only (bool, optional) – If True, generate incidence matrix based on only order-one nodes.
- Returns:
gradient_matrix – (n_edge, n_node)-shaped sparse matrix.
- Return type:
scipy.sparse.csr_matrix
- calculate_element_degree()
Calculated degrees of the graph of elements. Edges of the graph are defined by node shearing. Calculated degrees are returned and also stored in the fem_data.elemental_data dict with key = ‘degree’ .
- Returns:
degrees
- Return type:
numpy.ndarray
- calculate_euclidean_hop_graph(r, *, mode='elemental')
Calculate the adjacency matrix of graph G defined as follows.
If mode is ‘nodal’, G is a nodal graph and node v, v’ is adjacent in G if there exists a sequence of nodes (v_0, v_1, …, v_n) satisfying
v_0 = v, v_n = w
dist(v, v_i) < r, for all i
v_i and v_{i+1} shares some element.
If mode is ‘elemental’, G is a elemental graph and element e, e’ is adjacent in G if there exists a sequence of elements (e_0, e_1, …, e_n) satisfying
e_0 = e, e_n = e’
dist(e, e_i) < r, for all i
e_i and e_{i+1} shares some node.
In elemental case, the distance of elements is defined by Euclidean distance between its vertex sets.
In both cases, self-loops are excluded.
- Parameters:
r (float) – radius of the ball.
mode (str, optional (['elemental'], 'nodal')) – If ‘elemental’, generate (n_element, n_element) shaped adjacenty martix of the euclidean hop graph. If ‘nodal’, generate (n_node, n_node) shaped adjacenty martix of the euclidean hop graph.
- Returns:
adj – Adjacency matrix in CSR expression.
- Return type:
scipy.sparse.csr_matrix
- calculate_filter_by_ids(all_ids, extracting_ids)
- calculate_hausdorff_distance_elements(target_fem_data, directed=False)
Calculate Hausdorff distance from this fem_data to target_fem_data.
- Directed Hausdorff distance from X to Y is difined by:
HD(X to Y) := sup_{x} inf_{y} |x-y|.
- (Bidirected) Hausdorff distance is defined by
min(HD(X to Y), HD(Y to X)).
Here, X and Y are point could (i.e. only nodes are considered).
- Parameters:
target_fem_data (FEMData Object.)
directed (bool) – If True, calculate directed Hausdorff distance.
- Returns:
dist – Calculated Hausdorff distance.
- Return type:
float
- calculate_hausdorff_distance_nodes(target_fem_data, directed=False)
Calculate Hausdorff distance from this fem_data to target_fem_data.
- Directed Hausdorff distance from X to Y is difined by:
HD(X to Y) := sup_{x} inf_{y} |x-y|.
- (Bidirected) Hausdorff distance is defined by
min(HD(X to Y), HD(Y to X)).
Here, X and Y are point could (i.e. only nodes are considered).
- Parameters:
target_fem_data (FEMData Object.)
directed (bool) – If True, calculate directed Hausdorff distance.
- Returns:
dist – Calculated Hausdorff distance.
- Return type:
float
- calculate_incidence_matrix(order1_only=False)
Calculate graph incidence matrix, which is (n_node, n_element)-shaped matrix with bool.
- Parameters:
order1_only (bool, optional) – If True, generate incidence matrix based on only order-one nodes.
- Returns:
incidence_matrix – (n_node, n_element)-shaped sparse matrix.
- Return type:
scipy.sparse.csr_matrix
- calculate_laplacian_matrix(mode='nodal', order1_only=False)
Calculate edge-based graph incidence matrix, which is (n_edge, n_node)-shaped matrix with bool.
- Parameters:
mode (str, optional, ['nodal', 'elemental'])
order1_only (bool, optional) – If True, generate incidence matrix based on only order-one nodes.
- Returns:
incidence_matrix – (n_edge, n_node)-shaped sparse matrix.
- Return type:
scipy.sparse.csr_matrix
- calculate_n_hop_adj(mode='elemental', n_hop=1, include_self_loop=True, order1_only=False)
- calculate_relative_incidence_metrix_element(other_fem_data, minimum_n_sharing=None)
Calculate incidence matrix from other_fem_data to self based on elements, i.e., the resultant incidence matrix being of the shape (n_self_element, n_other_element).
- Parameters:
other_fem_data (femio.FEMData) – Other FEMData object.
minimum_n_sharing (int) – The minimum number of sharing node ids to define edge connectivity.
- Returns:
incidence_matrix – Incidence matrix in CSR expression.
- Return type:
scipy.sparse.csr_matrix
- collect_element_data_by_ids(node_ids)
- collect_element_indices_by_ids(node_ids)
- collect_node_indices_by_ids(node_ids)
- collect_node_positions_by_ids(node_ids)
- convert_element_data_to_indices(elements)
- convert_id_elements_to_index_elements(element_ids=None)
- extract_facets(elements=None, element_type=None, remove_duplicates=False, method=None)
Extract facets.
- Parameters:
elements (str, optional) – If fed, extract facets of the specified elements.
elements – If not fed, infer element type from the number of nodes per element.
method (callable) – A method to aggregate facet features. If not fed, numpy.concatenate is used.
- Returns:
facets
- Return type:
dict[tuple(numpy.ndarray)]
- extract_surface(elements=None, element_type=None)
Extract surface from solid mesh.
- Returns:
surface_indices – indices of nodes (not IDs).
surface_positions – Positions of each nodes on the surface.
- extract_surface_fistr()
Extract surface from solid mesh.
- Returns:
surface_data – row data correspond to (element_id, surface_id) of surface.
- Return type:
2D array of int.
- filter_first_order_nodes()
Obtain filter to get first order nodes.
- Returns:
filter
- Return type:
np.array() of bool
- nearest_neighbor_search_from_elements_to_elements(k, distance_upper_bound=inf, target_fem_data=None)
Compute 1-st to k-th nearest nodes in target_fem_data from each nodes in this fem_data.
- Parameters:
k (int) – The number of nodes to search.
distance_upper_bound (float) – Search only neighbors within this distance.
target_fem_data (FEMData Object)
- Returns:
nbd_indices (np.ndarray) – 2D array of shape (N, k) containing int data where N is the number of nodes. If the number of points found is less than k, corresponding value are set to be -1.
dists (np.ndarray) – 2D array of shape (N, k) containing float data. Distances from the elements to nearest points. If the number of points found is less than k, corresponding values are filled by np.inf.
- nearest_neighbor_search_from_elements_to_nodes(k, distance_upper_bound=inf, target_fem_data=None)
Compute 1-st to k-th nearest nodes in target_fem_data from each nodes in this fem_data.
- Parameters:
k (int) – The number of nodes to search.
distance_upper_bound (float) – Search only neighbors within this distance.
target_fem_data (FEMData Object)
- Returns:
nbd_indices (np.ndarray) – 2D array of shape (N, k) containing int data where N is the number of nodes. If the number of points found is less than k, corresponding value are set to be -1.
vectors (np.ndarray) – 3D array of shape (N, k, 3) containing float data. The vector from input point to neighbors. If the number of points found is less than k, corresponding values are filled by np.inf.
dists (np.ndarray) – 2D array of shape (N, k) containing float data. The length of vectors.
- nearest_neighbor_search_from_nodes_to_elements(k, distance_upper_bound=inf, target_fem_data=None)
Compute 1-st to k-th nearest nodes in target_fem_data from each nodes in this fem_data.
- Parameters:
k (int) – The number of nodes to search.
distance_upper_bound (float) – Search only neighbors within this distance.
target_fem_data (FEMData Object)
- Returns:
nbd_indices (np.ndarray) – 2D array of shape (N, k) containing int data where N is the number of nodes. If the number of points found is less than k, corresponding value are set to be -1.
vectors (np.ndarray) – 3D array of shape (N, k, 3) containing float data. The vector from input point to neighbors. If the number of points found is less than k, corresponding values are filled by np.inf.
dists (np.ndarray) – 2D array of shape (N, k) containing float data. The length of vectors.
- nearest_neighbor_search_from_nodes_to_nodes(k, distance_upper_bound=inf, target_fem_data=None)
Compute 1-st to k-th nearest nodes in target_fem_data from each nodes in this fem_data.
- Parameters:
k (int) – The number of nodes to search.
distance_upper_bound (float) – Search only neighbors within this distance.
target_fem_data (FEMData Object)
- Returns:
nbd_indices (np.ndarray) – 2D array of shape (N, k) containing int data where N is the number of nodes. If the number of points found is less than k, corresponding value are set to be -1.
vectors (np.ndarray) – 3D array of shape (N, k, 3) containing float data. The vector from input point to neighbors. If the number of points found is less than k, corresponding values are filled by np.inf.
dists (np.ndarray) – 2D array of shape (N, k) containing float data. The length of vectors.
- separate()
Separate the FEMData object into parts in terms of connected subgraphs.
- Returns:
list_fem_data – Connected subgraphs of the FEMData object. The components are in the order of the smallest node ids.
- Return type:
List[femio.FEMData]
femio.io module
- femio.io.convert_to_2d_if_needed(x)
- femio.io.convert_vtk_unstructured_to_femio(mesh)
Convert vtk unstructured grid to femio.FEMData object.
- Parameters:
mesh (tvtk.tvtk_classes.unstructured_grid.UnstructuredGrid) – Input UnstructuredGrid object.
- Return type:
femio.FEMData
- femio.io.read_directory(*args, **kwargs)
Initialize FEMData object from directory.
See FEMData.read_directory for more detail.
- femio.io.read_files(*args, **kwargs)
Initialize FEMData object from files.
See FEMData.read_files for more detail.
- femio.io.read_npy_directory(*args, **kwargs)
Initialize FEMData object from directory that contains femio npy data.
See FEMData.read_npy_directory for more detail.
- femio.io.stack_if_needed(type_id, data)
- femio.io.update_voxel2hex_if_needed(elements_data)
femio.mesh_compressor module
- class femio.mesh_compressor.MeshCompressor(*, fem_data)
Bases:
object
- calculate_compressed_fem_data()
Calculate the compressed FEMData. Before running this method, you need to run compress method.
- Returns:
FEMData Object
- Return type:
output_fem_data
- calculate_conversion_matrix_elemental(knn)
Calculate the conversion matrix of element_data. Let N be the number of the original FEMData, and M be the number of the original FEMData. Then create a sparse (M, N) matrix.
We can convert elemental_data between original FEMData and compressed FEMData by using this matrix. We can also convert them by using compress_elemental_data_data and decompress_elemental_data_data method.
- Parameters:
knn – int The number of elements related to a element in original fem_data. In other words, the number of nonzero entry in each columns in the calculated matrix.
- Returns:
- csr_matrix (bool)
The conversion matrix of elemental_data. Its shape is (M, N).
- Return type:
mat
- calculate_conversion_matrix_nodal(knn)
Calculate the conversion matrix of nodal_data. Let N be the number of the original FEMData, and M be the number of the original FEMData. Then create a sparse (M, N) matrix.
We can convert nodal_data between original FEMData and compressed FEMData by using this matrix. We can also convert them by using compress_nodal_data and decompress_nodal_data method.
- Parameters:
knn – int The number of nodes related to a node in original fem_data. In other words, the number of nonzero entry in each columns in the calculated matrix.
- Returns:
- csr_matrix (bool)
The conversion matrix of nodal_data. Its shape is (M, N).
- Return type:
mat
- compress(*, elem_num, cos_thresh, dist_thresh)
Compress the input FEMData. After running this method, you can calculate the compressed FEMData by calculate_compressed_fem_data method.
- Parameters:
elem_num – int The number of elements of output FEMData. This param is just an estimate. Typically, the number of output FEMData will be 1.0x ~ 2.0x, where x = elem_num.
cos_thresh – Two faces, edges are merged if cos of its angle is greater than cos_thresh. Therefore, if cos_thresh is near 1.0 then the overall shape of the FEMData tends to be preserved.
dist_thresh – The nodes connected by a edge is merged if distance between them is shorter than dist_thresh. Therefore, if dist_thresh is near 0.0 then the overall shape of the FEMData tends to be preserved.
- compress_elemental_data(*, name_1, name_2, kind, knn)
Convert elemental_data in original FEMData to compressed FEMData. Converted elemental_data is automatically attached to the compressed FEMData.
- Parameters:
name_1 – str Name of the elemental_data in original FEMData.
name_2 – str Name of the elemental_data in compressed FEMData which will be created.
kind – str, “sum” or “mean” If kind == “mean”, new data is computed as simple average of original data related to it. If kind == “sum”, new data is computed as weighted sum of original data related to it, and the sum of data of all elements is preserved.
knn – int The number of elements related to a element in original fem_data.
- compress_nodal_data(*, name_1, name_2, kind, knn)
Convert nodal_data in original FEMData to compressed FEMData. Converted nodal_data is automatically attached to the compressed FEMData.
- Parameters:
name_1 – str Name of the nodal_data in original FEMData.
name_2 – str Name of the nodal_data in compressed FEMData which will be created.
kind – str, “sum” or “mean” If kind == “mean”, new data is computed as simple average of original data related to it. If kind == “sum”, new data is computed as weighted sum of original data related to it, and the sum of data of all nodes is preserved.
knn – int The number of nodes related to a node in original fem_data.
- decompress_elemental_data(*, name_1, name_2, kind, knn)
Convert elemental_data in compressed FEMData to original FEMData. Converted elemental_data is automatically attached to the original FEMData.
- Parameters:
name_1 – str Name of the elemental_data in compressed FEMData.
name_2 – str Name of the elemental_data in original FEMData which will be created.
kind – str, “sum” or “mean” If kind == “mean”, new data is computed as simple average of original data related to it. If kind == “sum”, new data is computed as weighted sum of original data related to it, and the sum of data of all elements is preserved.
knn – int The number of elements related to a element in original fem_data.
- decompress_nodal_data(*, name_1, name_2, kind, knn)
Convert nodal_data in compressed FEMData to original FEMData. Converted nodal_data is automatically attached to the original FEMData.
- Parameters:
name_1 – str Name of the nodal_data in compressed FEMData.
name_2 – str Name of the nodal_data in original FEMData which will be created.
kind – str, “sum” or “mean” If kind == “mean”, new data is computed as simple average of original data related to it. If kind == “sum”, new data is computed as weighted sum of original data related to it, and the sum of data of all nodes is preserved.
knn – int The number of nodes related to a node in original fem_data.
- femio.mesh_compressor.calc_centers(face_data_csr, node_pos)
- femio.mesh_compressor.calculate_elemental_knn(csr_raw, csr_after, node_conv, node_pos, knn)
- femio.mesh_compressor.calculate_nodal_knn(csr, node_conv, node_pos, knn)
- femio.mesh_compressor.check_polyhedron(poly)
- femio.mesh_compressor.collect_vertex(poly)
- femio.mesh_compressor.merge_elements(face_data_csr, node_pos, elem_conv, K)
- femio.mesh_compressor.merge_polyhedrons(face_data_csr, IDS, elem_conv, nxt_idx)
- femio.mesh_compressor.merge_vertices(face_data_csr, node_pos, elem_conv, node_conv, THRESH)
- femio.mesh_compressor.print_stat(csr)
- femio.mesh_compressor.recalc_node_pos(node_pos, node_conv)
- femio.mesh_compressor.reindex(csr, node_conv)
- femio.mesh_compressor.remove_edges(face_data_csr, node_pos, elem_conv, THRESH=0.99)
- femio.mesh_compressor.remove_one_edge_from_polyhedron(poly, A, B)
- femio.mesh_compressor.remove_one_vertex_from_polyhedron(poly, rm_v)
- femio.mesh_compressor.remove_vertices(face_data_csr, node_pos, elem_conv, THRESH=0.99)
- femio.mesh_compressor.remove_vertices_2(face_data_csr, node_pos, elem_conv)
- femio.mesh_compressor.shrink(polyhedrons, elem_conv)
femio.nodal_data module
- class femio.nodal_data.NodalData(nodal_data)
Bases:
object
femio.signal_processor module
- class femio.signal_processor.SignalProcessorMixin
Bases:
object
- add_principal_vectors(name_variable)
- aggregate_edges_to_vertices(edges_data, mode='elemental', include_self_loop=False)
Aggregate edge data to vertices (in terms of either elemental of nodal graph).
- Parameters:
edges_data (numpy.ndarray) – Edge data, which should be either (n_edge, n_feature) or (n_edge, n_feature1, n_feature2) -shaped array.
mode (str, optional) – Mode of graph, which is either ‘elemental’ or ‘nodal’. Defaults to ‘elemental’.
include_self_loop (bool, optional) – If True, include self loop to the operation. Defaults to False.
- Returns:
aggregated_vertice_data – Either (n_vertex, n_feature) or (n_vertes, n_feature1, n_feature2) -shaped array of aggregated vertex data.
- Return type:
numpy.ndarray
- calculate_data_adjs(adj, data)
- calculate_data_diff_adjs(adj, data)
- calculate_diffusion_elemental_data(elemental_data, *, hops=1, weight=0.0001)
Perform diffusion of elemental data according with graph Laplacian.
- Parameters:
elemental_data – numpy.ndarray Elemental data to be moiving-averaged.
hops – int, optional [1] The number of hops to make moving averaging.
weight – float, optional [1e-4] Weight to be used in diffusion (= diffusion coeff).
- Returns:
- numpy.ndarray
The results of diffusion.
- Return type:
diffused_elemental_data
- calculate_distance_kernel_adj(kernel, distance_adj, **kwargs)
- calculate_distance_kernel_adj_chisquare_data(adj_data, k=1)
- calculate_distance_kernel_adj_exp_data(adj_data, alpha=1.0)
- calculate_distance_kernel_adj_gauss_data(adj_data, alpha=1.0)
- calculate_edge_differences(data, *, mode='elemental', include_self_loop=False)
Calculate difference between data which are connected with edges (in terms of either elemental or nodal graph).
- Parameters:
data (numpy.ndarray) – data to be subtracted. It shoud be (n_vertex, 2, n_feature)-shaped array which [:, 0, :] contains reference vertex and [:, 1, :] contains opposed vertex.
mode (str, optional) – Mode of graph, which is either ‘elemental’ or ‘nodal’. Defaults to ‘elemental’.
include_self_loop (bool, optional) – If True, include self loop to the operation. Defaults to False.
- Returns:
differentiated_data – (n_vertex, n_feature)-shaped array after subtraction.
- Return type:
numpy.ndarray
- calculate_elemental_spatial_gradients(elemental_data, n_hop=1, kernel=None, normals=None, **kwargs)
Calculate spatial gradient (not graph gradient) w.r.t elemental data.
- Parameters:
elemental_data (numpy.ndarray) – Data to calculate gradient over. It should be (n_element, n_feature)-shaped array.
normals (bool or numpy.ndarray, optional [False]) – If True, take into account surface normal vectors to consider Neumann boundary condition. If numpy.ndarray is fed, use them as normal vectors.
- Returns:
gradients – (n_element, 3, n_feature)-shaped array of grad. 3 means dimension of the space.
- Return type:
numpy.ndarray
- calculate_frame_expansion_adjs(data, mode='nodal', n_hop=1, order1_only=False, **kwargs)
Calculate frame expansion adjacency matrices.
- Parameters:
data (numpy.ndarray) –
- (n_node, dimension, dimension, …) shaped array to be expanded.
k repetitions for rank k tensor
mode (['nodal', 'elemental'], optional) – If ‘nodal’, deal with nodal data. If ‘elemental’, deal with elemental data. The default is ‘nodal’.
n_hop (int, optional) – The number of hops to be considered. The default is 1.
order1_only (bool, optional) – If True, take into account only order 1 nodes. The default is True.
- Returns:
frame_expansion_matric –
- List of shape (dimension, dimension, …) which contains
k repetitions for rank k tensor
(n_node, n_node) shaped sparse matrices.
- Return type:
List[scipy.sparse.csr_matrix]
- calculate_frame_tensor_adjs(mode='elemental', n_hop=1, order1_only=False, tensor_rank=1)
Calculate frame adjacency matrices F s.t. phi = F phi, based on frame which are set of relative vectors coming from mesh topology.
- Parameters:
mode (['nodal', 'elemental'], optional) – If ‘nodal’, deal with nodal data. If ‘elemental’, deal with elemental data. The default is ‘nodal’.
n_hop (int, optional) – The number of hops to be considered. The default is 1.
order1_only (bool, optional) – If True, take into account only order 1 nodes. The default is True.
tensor_rank (int, optional) – Tensor rank for the generated frame.
- Returns:
frame_tensor_adjs (List[scipy.sparse.csr_matrix]) –
- List of shape (dimension, dimension, …) which contains
k repetitions for rank k tensor
(n_node, n_node) shaped sparse matrices.
scaled_tensor_adjs (List[scipy.sparse.csr_matrix]) –
- List of shape (dimension, dimension, …) which contains
k*2 repetitions for rank k tensor
(n_node, n_node) shaped sparse matrices.
- calculate_median_filter(data, *, mode='elemental', hops=1, order1_only=False)
Perform median filter according with adjacency of the mesh.
- Parameters:
data – numpy.ndarray Data to be filtered.
hops – int, optional [1] The number of hops to make filtering.
mode – str, optional, ([‘elemental’], ‘nodal’)
order1_only – bool, optional [True] If True, nordal data should be associated with order 1 nodes.
- Returns:
- numpy.ndarray
The results of filtering.
- Return type:
moving_averaged_nodal_data
- calculate_moving_average_elemental_data(elemental_data, *, hops=1, weight=0.1)
Perform moving average according with adjacency of the mesh.
- Parameters:
elemental_data – numpy.ndarray Elemental data to be moiving-averaged.
hops – int, optional [1] The number of hops to make moving averaging.
weight – float, optional [.1] Weight to be used in moving averaging.
- Returns:
- numpy.ndarray
The results of moving averaging.
- Return type:
moving_averaged_elemental_data
- calculate_moving_average_nodal_data(nodal_data, *, hops=1, weight=0.1, order1_only=False)
Perform moving average according with adjacency of the mesh.
- Parameters:
nordal_data – numpy.ndarray Nodal data to be moiving-averaged.
hops – int, optional [1] The number of hops to make moving averaging.
weight – float, optional [.1] Weight to be used in moving averaging.
order1_only – bool, optional [True] If True, nordal data should be associated with order 1 nodes.
- Returns:
- numpy.ndarray
The results of moving averaging.
- Return type:
moving_averaged_nodal_data
- calculate_nodal_spatial_gradients(nodal_data, n_hop=1, kernel=None, order1_only=False, normals=None, **kwargs)
Calculate spatial gradient (not graph gradient) w.r.t nodal data.
- Parameters:
nodal_data (numpy.ndarray) – Data to calculate gradient over. It should be (n_node, n_feature)-shaped array.
n_hop (int, optional [1]) – The number of hops to be considered.
kernel (str, optional [None]) – Kernel function type.
order1_only (bool, optional [True]) – If True, consider only order 1 nodes.
normals (bool or numpy.ndarray, optional [False]) – If True, take into account surface normal vectors to consider Neumann boundary condition. If numpy.ndarray is fed, use them as normal vectors.
- Returns:
gradients – (n_node, 3, n_feature)-shaped array of grad. 3 means dimension of the space.
- Return type:
numpy.ndarray
- calculate_norm_adj(adjs, p=2)
- calculate_spatial_gradient_adjacency_matrices(mode='elemental', n_hop=1, kernel=None, order1_only=False, use_effective_volume=True, moment_matrix=False, consider_volume=True, normals=None, normal_weight=1.0, normal_weight_factor=None, adj=None, **kwargs)
Calculate spatial gradient (not graph gradient) matrix.
- Parameters:
nodal_data (numpy.ndarray) – Data to calculate gradient over. It should be (n_node, n_feature)-shaped array.
n_hop (int, optional [1]) – The number of hops to be considered.
kernel (str, optional [None]) – Kernel function type.
order1_only (bool, optional [True]) – If True, consider only order 1 nodes.
moment_matrix (bool, optional [False]) – If True, scale the matrix with moment matrices, which are tensor products of relative position tensors.
consider_volume (bool, optional [True]) – If True, consider effective volume of each vertex.
normals (bool or numpy.ndarray, optional [False]) – If True, take into account surface normal vectors to consider Neumann boundary condition. If numpy.ndarray is fed, use them as normal vectors.
normal_weight (float, optional [1.]) – Weight of the normal vector.
normal_weight_factor (float, optional [False]) – If fed, weight the normal vector. The weight is calculated with normal_weight_factor * sum_i volume_i, where the index i runs overt the graph neighbor including the self loop.
adj (scipy.sparse [None]) – If fed, used as a adjacency matrix.
- Returns:
gradients – (n_node, 3, n_feature)-shaped array of grad. 3 means dimension of the space.
- Return type:
numpy.ndarray
- calculate_spatial_gradient_incidence_matrix(mode='nodal', order1_only=False, moment_matrix=True, normals=None, normal_weight=1.0, **kwargs)
Calculate spatial gradient (not graph gradient) incidence matrix.
- Parameters:
mode (str, optional ['nodal', 'elemental'])
order1_only (bool, optional [True]) – If True, consider only order 1 nodes.
moment_matrix (bool, optional [True]) – If True, scale the matrix with moment matrices, which are tensor products of relative position tensors.
normals (bool or numpy.ndarray, optional [False]) – If True, take into account surface normal vectors to consider Neumann boundary condition. If numpy.ndarray is fed, use them as normal vectors.
normal_weight (float, optional [1.]) – Weight of the normal vector.
- Returns:
spatial_gradient_matrix (list[scipy.sparse.csr_matrix]) – Three spatial gradient matrix with [n_edge, n_vertex] shape.
edge_incidence_matrix (scipy.sparse.csr_matrix) – Sparse matrices whose shapes are [n_vertex, n_edge].
- calculate_tensor_power(x, power, is_sparse=None)
Calculate tensor power of x.
- Parameters:
x – numpy.ndarray or List[scipy.sparse] In case of dense, R^{n * d^k}, in case of sparse, R^{d^k * n * n}, where n is the number of node, k is the rank.
power – int
- Returns:
numpy.ndarray or List[scipy.sparse]
- Return type:
tensor_power_x
- convert_elemental2nodal(elemental_data, mode='mean', order1_only=False, raise_negative_volume=True, weight=None, incidence=None)
Convert elemental data to nodal data.
- Parameters:
elemental_data – numpy.ndarray Elemental data to be converted.
mode – str, optional The way haw to convert. ‘effective’ means weighted integration which results in consistent volume. ‘mean’ means weighted mean which results in smoother field at the boundary but not necessarily consistent volume. The default is ‘mean’.
order1_only – bool, optional [True] If True, convert data only for order 1 nodes.
raise_negative_volume – bool, optional [True] If True, raise ValueError when negative volume found.
weight – numpy.ndarray Weight to be used in ‘mean’ mode. False means equal weight.
incidence – scipy.sparse.csr_matrix (n_node, n_element)-shaped incidence matrix.
- Returns:
numpy.ndarray
- Return type:
converted_data
- convert_lte_global2local()
Convert linear thermal expansion coefficient from global to local point of view.
- convert_lte_local2global()
Convert linear thermal expansion coefficient from local to global point of view.
- convert_nodal2elemental(data, *, calc_average=False, ravel=False)
Convert nodal data to elemental data.
- Parameters:
data – String or numpy.ndarray Name of nodal data or nodal data itself.
calc_average – Bool, optional [False] If True, output is averaged element by element.
ravel – Bool, optional [False] If True, output is raveled to make 2D array.
- Returns:
numpy.ndarray
- Return type:
elemental_data
- convert_vertices_to_edges(data, mode='elemental', include_self_loop=False)
Convert vertex values to edge values (in terms of either elemental or nodal graph).
- Parameters:
data (numpy.ndarray) – Vertex data, which should be (n_vertex, n_feature)-shaped.
mode (str, optional) – Mode of graph, which is either ‘elemental’ or ‘nodal’. Defaults to ‘elemental’.
include_self_loop (bool, optional) – If True, include self loop to the operation. Defaults to False.
- Returns:
edge_values – (n_element, 2, n_feature)-shaped array of edge data. [:, 0, :] contains reference vertex and [:, 1, :] contains opposed vertex.
- Return type:
numpy.ndarray
- integrate(nodal_data)
Integrate nodal data over element volumes.
Args: nodal_data: np.ndarray
Nodal data with (n_nodes, n_features) shape.
Returns: integrated_elements: np.ndarray
Integrated elements data with (n_features,) shape.
- integrate_elements(nodal_data)
Integrate nodal data with element volumes.
Args: nodal_data: np.ndarray
Nodal data with (n_nodes, n_features) shape.
Returns: integrated_elements: np.ndarray
Integrated elements data with (n_elements, n_features) shape.
- multiply_sparse_tensors(a, b)
Perform multiplication of sparse tensors.
- Parameters:
a (List[scipy.sparse] or scipy.sparse)
b (List[scipy.sparse] or scipy.sparse)
- Returns:
c
- Return type:
List[scipy.sparse] or scipy.sparse
femio.time_series_dataframe module
- class femio.time_series_dataframe.TimeSeriesArray(time_series_data_frame, method)
Bases:
object
Module contents
FEM I/O tool