bluemira.materials.cache

Classes and methods to load, store, and retrieve materials.

Attributes

vacuum_void

Classes

MaterialCache

A helper class for loading and caching materials.

Functions

establish_material_cache(materials_package)

Load the material data from the provided json files into the global material cache

get_cached_material(→ matproplib.material.Material | None)

Get the named material from the MaterialCache.

Module Contents

bluemira.materials.cache.vacuum_void
class bluemira.materials.cache.MaterialCache

A helper class for loading and caching materials.

Notes

Extend the available_classes attribute to load custom classes.

_instance: MaterialCache | None = None
classmethod get_instance() MaterialCache

Get the singleton instance of the MaterialCache.

Returns:

The singleton instance of the MaterialCache.

Return type:

MaterialCache

__getattr__(value: str)

Allow attribute access to cached materials

Returns:

The requested Material

Raises:

AttributeError – No attribute found

Parameters:

value (str)

load_from_package(package)

Load material package

_get_material(name)
get_material(name: str, *, clone: bool = True)

Get the named material from the material dictionary

Parameters:
  • name (str) – The name of the material to retrieve from the dictionary

  • clone (bool) – If True, get a clone (deepcopy) of the material, else get the actual material as stored in the material dictionary. By default True.

Return type:

The requested material.

bluemira.materials.cache.establish_material_cache(materials_package: str | object)

Load the material data from the provided json files into the global material cache instance.

This instance can be accessed using the MaterialCache.get_instance() function.

Parameters:

materials_package (str | object) – A list of paths to the data files to load into the material cache.

Return type:

The material cache.

bluemira.materials.cache.get_cached_material(material_name: str, cache: MaterialCache | None = None) matproplib.material.Material | None

Get the named material from the MaterialCache.

If cache is None, the global cache instance is used.

Parameters:
  • material_name (str) – The name of the material to retrieve from the dictionary

  • cache (MaterialCache | None) – The material cache to retrieve the material from. By default the global cache.

Returns:

The requested material.

Raises:

MaterialsError – If the material name is not a string.

Return type:

matproplib.material.Material | None