Exemple #1
0
 def __init__(self):
     self.build_order = []
     self.parts = {}  # dict of parts in this geometry
     self.xsecs = {}  # dict of cross-sections in this geometry
     self.serial_fcdoc = None  # serialized FreeCAD document for this geometry
     self.mesh_verts = None  # numpy array corresponding to the mesh vertices
     self.mesh_tets = None  # numpy array; each row contains the vertex indices in one tet
     self.mesh_regions = None  # 1D array; each entry is the region ID of the corresponding tet
     self.mesh_id_dict = None  # dictionary with part name keys mapping to region IDs
     self.virtual_mesh_regions = None  # Dict with 1D arrays; each entry specifies what tets belong to virtual region
     self.materials_database = Materials()
Exemple #2
0
 def __init__(self):
     """
     Class for a 3D geometry specification. It holds:
         - parts is a dict of Part3D objects, keyed by the label of each Part3D object.
         - build_order is a list of strings indicating the construction order.
     """
     self.build_order = []
     self.parts = {}  # dict of parts in this geometry
     self.serial_fcdoc = None  # serialized FreeCAD document for this geometry
     self.mesh_verts = None  # numpy array corresponding to the mesh vertices
     self.mesh_tets = None  # numpy array; each row contains the vertex indices in one tet
     self.mesh_regions = None  # 1D array; each entry is the region ID of the corresponding tet
     self.mesh_id_dict = None  # dictionary with part name keys mapping to region IDs
     self.materials_database = Materials()
Exemple #3
0
def build_materials(
    geo_data: Union[Geo2DData, Geo3DData],
    materials_mapping: Dict[str, str],
    materials: Optional[Materials] = None,
) -> MatData:
    """Build a MatData object.

    Parameters
    ----------
    geo_data : Union[Geo2DData, Geo3DData]
        A 2D or 3D geometry class.
    materials_mapping : dict
        A mapping of parts to materials.
    materials : Materials
        A Materials class, representing a materials library. If you want to override
        properties, use make_materials.
    Returns
    -------
    MatData
       Built object with materials information.
    Raises
    ------
    ValueError
        If materials_mapping does not contain a key for a part in geo_data.
    """
    if materials is None:
        materials = Materials()

    # We keep a copy of materials_mapping around, but also set the material property
    # on all the parts
    new_mapping = {}
    for name, part in geo_data.parts.items():
        if ":" in name:
            old_name, _ = name.split(":")
            new_mapping[name] = materials_mapping[old_name]
            continue

        if (name not in materials_mapping and not part.virtual
                and not isinstance(part, LineString)):
            raise ValueError(
                f"materials_mapping does not contain material for part {name}")
        mat = materials_mapping.get(name)
        if mat is not None:
            new_mapping[name] = mat
    extra_materials = set(new_mapping.keys()) - set(geo_data.parts.keys())
    if extra_materials:
        warnings.warn(
            f"{extra_materials} are provided in materials_mapping but not found in "
            "geometry parts")
    return MatData(materials, new_mapping)
Exemple #4
0
 def __init__(self):
     """
     Class for a 3D geometry specification. It holds:
         - parts is a dict of Part3D objects, keyed by the label of each Part3D object.
         - build_order is a list of strings indicating the construction order.
     """
     self.build_order = []
     self.parts = {}  # dict of parts in this geometry
     self.serial_fcdoc = None  # serialized FreeCAD document for this geometry
     self.serial_mesh = None  # Holding container for the serialized xml of the meshed geometry
     self.serial_region_marker = None  # Holding container for the serialized xml of the region
     # marker function
     self.fenics_ids = None  # dictionary with part name keys mapping to fenics ids.
     self.materials_database = Materials()
Exemple #5
0
def test_materials_property_map():
    int_map = DummyPartMap([0, 1])
    str_map = DummyPartMap(["part1", "part2"])
    part_materials1 = {0: "InAs", 1: "GaSb"}
    part_materials2 = {"part1": "InAs", "part2": "Al"}
    mat_lib = Materials(matDict={})
    mat_lib.add_material(
        "InAs",
        "semi",
        electronMass=0.026,
        directBandGap=417.0,
        valenceBandOffset=-590.0,
    )
    mat_lib.add_material("GaSb",
                         "semi",
                         electronMass=0.039,
                         directBandGap=812.0,
                         valenceBandOffset=-30.0)
    mat_lib.add_material("Al", "metal", workFunction=4280.0)

    prop_map1 = MaterialPropertyMap(int_map, part_materials1, mat_lib,
                                    "electronMass")
    assert prop_map1.get_part((1.0, 2.0)) == 1
    assert np.all(prop_map1.get_part(-np.ones((2, 3))) == 0)
    assert prop_map1((1.0, 2.0)) == mat_lib["GaSb"]["electronMass"]
    assert np.all(
        prop_map1(-np.ones((2, 3))) == mat_lib["InAs"]["electronMass"])

    prop_map2 = MaterialPropertyMap(str_map,
                                    part_materials2,
                                    mat_lib,
                                    "directBandGap",
                                    eunit="eV",
                                    fill_value=0.0)
    assert prop_map2.get_part((1.0, 2.0)) == "part2"
    assert np.all(prop_map2.get_part(-np.ones((2, 3))) == "part1")
    assert prop_map2((1.0, 2.0)) == 0.0
    assert np.all(
        prop_map2(-np.ones((2, 3))) == mat_lib.find("InAs", "eV")
        ["directBandGap"])
Exemple #6
0
def test_materials_property_map():
    int_map = DummyPartMap([0, 1])
    str_map = DummyPartMap(['part1', 'part2'])
    part_materials1 = {0: 'InAs', 1: 'GaSb'}
    part_materials2 = {'part1': 'InAs', 'part2': 'Al'}
    mat_lib = Materials(matDict={})
    mat_lib.add_material('InAs', 'semi', electronMass=0.026, directBandGap=417.,
                         valenceBandOffset=-590.)
    mat_lib.add_material('GaSb', 'semi', electronMass=.039, directBandGap=812.,
                         valenceBandOffset=-30.)
    mat_lib.add_material('Al', 'metal', workFunction=4280.)

    prop_map1 = MaterialPropertyMap(int_map, part_materials1, mat_lib, 'electronMass')
    assert prop_map1.get_part((1., 2.)) == 1
    assert np.all(prop_map1.get_part(-np.ones((2, 3))) == 0)
    assert prop_map1((1., 2.)) == mat_lib['GaSb']['electronMass']
    assert np.all(prop_map1(-np.ones((2, 3))) == mat_lib['InAs']['electronMass'])

    prop_map2 = MaterialPropertyMap(str_map, part_materials2, mat_lib, 'directBandGap', eunit='eV',
                                    fill_value=0.)
    assert prop_map2.get_part((1., 2.)) == 'part2'
    assert np.all(prop_map2.get_part(-np.ones((2, 3))) == 'part1')
    assert prop_map2((1., 2.)) == 0.
    assert np.all(prop_map2(-np.ones((2, 3))) == mat_lib.find('InAs', 'eV')['directBandGap'])
Exemple #7
0
def make_materials_library(material_properties: Dict[str, Dict]) -> Materials:
    """Make a Materials class instance with physical constants overridden by an input dictionary.

    Parameters
    ----------
    material_properties: dict
        Override specific material properties by specifying
        {'material':{'material_attribute':override_value}.
    Returns
    -------
    The materials library with overriden properties.
    """
    mat_lib = Materials()
    if material_properties:
        for material in material_properties:
            mat_obj = mat_lib[material]
            for attribute in material_properties[material]:
                mat_obj[attribute] = material_properties[material][attribute]
            mat_lib[material] = mat_obj
    return mat_lib
Exemple #8
0
def build_materials(
    geo_data: Union[Geo2DData, Geo3DData],
    materials_mapping: Dict[str, str],
    materials: Materials = None,
) -> MatData:
    """Build a MatData object.

    Parameters
    ----------
    geo_data : Union[Geo2DData, Geo3DData]
        A 2D or 3D geometry class.
    materials_mapping : dict
        A mapping of parts to materials.
    materials : Materials
        A Materials class, representing a materials library. If you want to override
        properties, use make_materials.
    Returns
    -------
    MatData
       Built object with materials information.
    Raises
    ------
    ValueError
        If materials_mapping does not contain a key for a part in geo_data.
    """
    if materials is None:
        materials = Materials()

    # We keep a copy of materials_mapping around, but also set the material property
    # on all the parts
    for name, part in geo_data.parts.items():
        if name not in materials_mapping and not part.virtual:
            raise ValueError(
                f"materials_mapping does not contain material for part {name}")
    extra_materials = set(materials_mapping.keys()) - set(
        geo_data.parts.keys())
    if extra_materials:
        warnings.warn(
            f"{extra_materials} are provided in materials_mapping but not found in "
            "geometry parts")
    return MatData(materials, materials_mapping)