Exemplo n.º 1
0
    def __read_material(self):
        material_list = []
        read_material = False
        read_elastic = False
        read_conductivity = False
        i_file = open(self.__filename, "r")
        first_material = True
        for line in i_file:
            line = line[0:-1]
            # Coments and line does not exist
            if len(line) == 0:
                continue
            elif len(line) >= 2:
                if line[0:1] == "**":
                    continue

            # Stop reading
            if line[0] == "*":
                read_material = False
                read_elastic = False
                read_conductivity = False

            if read_elastic:
                words = line.split(",")
                if len(words) <= 2:
                    young_module = FEM.YoungModule(float(words[0]), 0)
                    poisson_ratio = FEM.PoissonRatio(float(words[1]), 0)
                else:
                    young_module = FEM.YoungModule(float(words[0]), words[2])
                    poisson_ratio = FEM.PoissonRatio(float(words[1]), words[2])
                mat.add_young_module(young_module)
                mat.add_poisson_ratio(poisson_ratio)

            if read_conductivity:
                words = line.split(",")
                if len(words) <= 1:
                    conductivity = FEM.Conductivity(float(words[0]), 0)
                else:
                    conductivity = FEM.Conductivity(float(words[0]), words[1])
                mat.add_conductivity(conductivity)

            # Check if node key is found and not *NODE PRINT ...
            if "*MATERIAL" in line.upper():

                words = line.split(",")
                for word in words:
                    new_word = word.split(" ")
                    for word_no_space in new_word:
                        if word_no_space.upper() == "*MATERIAL":
                            read_material = True

                if read_material:
                    if not first_material:
                        material_list.append(mat)
                    first_material = False
                    words = line.split(", ")
                    material_name = ""
                    for word in words:
                        if "NAME" in word.upper():
                            word_no_equal = word.split("=")
                            material_name = word_no_equal[1]
                    mat = FEM.Material(material_name)

            if "*ELASTIC" in line.upper():
                read_elastic = True
            if "*CONDUCTIVITY" in line.upper():
                read_conductivity = True

        material_list.append(mat)
        return material_list