Ejemplo n.º 1
0
    def ExecuteBeforeSolutionLoop(self):

        data = {}
        data["TIME"] = []
        count = 0

        # Material points values
        for mp in self.sub_model_part.Elements:
            compute = self.__check_flag(mp)

            if (compute == True):
                if (self.resultant_solution == False):
                    data["PARTICLE_" + str(mp.Id)] = {}
                else:
                    data["RESULTANT"] = {}

                for i in range(self.params["gauss_points_output_variables"].size()):
                    out = self.params["gauss_points_output_variables"][i]
                    variable_name = out.GetString()
                    variable = KratosMultiphysics.KratosGlobals.GetVariable(variable_name)
                    variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(variable_name)

                    if (variable_type == "Double" or variable_type == "Component"):
                        if (self.resultant_solution == False):
                            data["PARTICLE_" + str(mp.Id)][variable_name] = []
                        else:
                            if (count == 0):
                                data["RESULTANT"][variable_name] = []
                    elif variable_type == "Array":
                        if (KratosMultiphysics.KratosGlobals.GetVariableType(variable_name + "_X") == "Component"):
                            if (self.resultant_solution == False):
                                data["PARTICLE_" + str(mp.Id)][variable_name + "_X"] = []
                                data["PARTICLE_" + str(mp.Id)][variable_name + "_Y"] = []
                                data["PARTICLE_" + str(mp.Id)][variable_name + "_Z"] = []
                            else:
                                if (count == 0):
                                    data["RESULTANT"][variable_name + "_X"] = []
                                    data["RESULTANT"][variable_name + "_Y"] = []
                                    data["RESULTANT"][variable_name + "_Z"] = []
                        else:
                            if (self.resultant_solution == False):
                                data["PARTICLE_" + str(mp.Id)][variable_name] = []
                            else:
                                if (count == 0):
                                    data["RESULTANT"][variable_name] = []
                    elif variable_type == "Vector":
                        if (self.resultant_solution == False):
                            data["PARTICLE_" + str(mp.Id)][variable_name] = []
                        else:
                            if (count == 0):
                                data["RESULTANT"][variable_name] = []

                count += 1

        write_external_json(self.output_file_name, data)
    def ExecuteFinalizeSolutionStep(self):

        data = read_external_json(self.output_file_name)

        time = self.sub_model_part.ProcessInfo.GetValue(
            KratosMultiphysics.TIME)
        dt = self.sub_model_part.ProcessInfo.GetValue(
            KratosMultiphysics.DELTA_TIME)
        self.time_counter += dt
        if self.time_counter > self.frequency:
            self.time_counter = 0.0
            data["TIME"].append(time)
            count = 0

            # Material points values
            for mp in self.sub_model_part.Elements:
                compute = self.__check_flag(mp)

                if (compute == True):
                    for i in range(
                            self.params["gauss_points_output_variables"].size(
                            )):
                        out = self.params["gauss_points_output_variables"][i]
                        variable_name = out.GetString()
                        variable = KratosMultiphysics.KratosGlobals.GetVariable(
                            variable_name)
                        variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(
                            variable_name)
                        values_vector = mp.CalculateOnIntegrationPoints(
                            variable, self.sub_model_part.ProcessInfo)
                        value = values_vector[0]

                        if (variable_type == "Double"
                                or variable_type == "Integer"
                                or variable_type == "Component"):
                            if (self.resultant_solution == False):
                                data["PARTICLE_" +
                                     str(mp.Id)][variable_name].append(value)
                            else:
                                if (count == 0):
                                    data["RESULTANT"][variable_name].append(
                                        value)
                                else:
                                    data["RESULTANT"][variable_name][
                                        -1] += value
                        elif variable_type == "Array":
                            if (KratosMultiphysics.KratosGlobals.
                                    GetVariableType(variable_name +
                                                    "_X") == "Double"):
                                if (self.resultant_solution == False):
                                    data["PARTICLE_" +
                                         str(mp.Id)][variable_name +
                                                     "_X"].append(value[0])
                                    data["PARTICLE_" +
                                         str(mp.Id)][variable_name +
                                                     "_Y"].append(value[1])
                                    data["PARTICLE_" +
                                         str(mp.Id)][variable_name +
                                                     "_Z"].append(value[2])
                                else:
                                    if (count == 0):
                                        data["RESULTANT"][variable_name +
                                                          "_X"].append(
                                                              value[0])
                                        data["RESULTANT"][variable_name +
                                                          "_Y"].append(
                                                              value[1])
                                        data["RESULTANT"][variable_name +
                                                          "_Z"].append(
                                                              value[2])
                                    else:
                                        data["RESULTANT"][variable_name +
                                                          "_X"][-1] += value[0]
                                        data["RESULTANT"][variable_name +
                                                          "_Y"][-1] += value[1]
                                        data["RESULTANT"][variable_name +
                                                          "_Z"][-1] += value[2]
                            else:
                                if (self.resultant_solution == False):
                                    list = self.__kratos_vector_to__python_list(
                                        value)
                                    data["PARTICLE_" +
                                         str(mp.Id)][variable_name].append(
                                             list)
                                else:
                                    aux = 0.0
                                    for index in range(len(value)):
                                        aux += value[index]
                                    if (count == 0):
                                        data["RESULTANT"][
                                            variable_name].append(aux)
                                    else:
                                        data["RESULTANT"][variable_name][
                                            -1] += aux
                        elif variable_type == "Vector":
                            if (self.resultant_solution == False):
                                list = self.__kratos_vector_to__python_list(
                                    value)
                                data["PARTICLE_" +
                                     str(mp.Id)][variable_name].append(list)
                            else:
                                if (count == 0):
                                    list = self.__kratos_vector_to__python_list(
                                        value)
                                    data["RESULTANT"][variable_name][
                                        -1] += list

                count += 1

        write_external_json(self.output_file_name, data)
Ejemplo n.º 3
0
    def ExecuteFinalizeSolutionStep(self):
        """ This method is executed in order to finalize the current step

        Here the dictionary containing the solution is filled

        Keyword arguments:
        self -- It signifies an instance of a class.
        """

        data = read_external_json(self.output_file_name)

        time = self.sub_model_part.ProcessInfo.GetValue(
            KratosMultiphysics.TIME)
        dt = self.sub_model_part.ProcessInfo.GetValue(
            KratosMultiphysics.DELTA_TIME)
        self.time_counter += dt
        if self.time_counter > self.frequency:
            self.time_counter = 0.0
            data["TIME"].append(time)
            count = 0

            # Nodal values
            for node in self.sub_model_part.Nodes:
                compute = self.__check_flag(node)

                if compute:
                    node_identifier = "NODE_" + self.__get_node_identifier(
                        node)

                    for i in range(self.params["output_variables"].size()):
                        out = self.params["output_variables"][i]
                        variable_name = out.GetString()
                        variable = KratosMultiphysics.KratosGlobals.GetVariable(
                            variable_name)
                        variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(
                            variable_name)
                        if self.historical_value:
                            value = node.GetSolutionStepValue(variable, 0)
                        else:
                            value = node.GetValue(variable)

                        if variable_type == "Double":
                            if not self.resultant_solution:
                                data[node_identifier][variable_name].append(
                                    value)
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name].append(
                                        value)
                                else:
                                    data["RESULTANT"][variable_name][
                                        -1] += value
                        elif variable_type == "Array":
                            if KratosMultiphysics.KratosGlobals.GetVariableType(
                                    variable_name + "_X") == "Double":
                                if not self.resultant_solution:
                                    data[node_identifier][variable_name +
                                                          "_X"].append(
                                                              value[0])
                                    data[node_identifier][variable_name +
                                                          "_Y"].append(
                                                              value[1])
                                    data[node_identifier][variable_name +
                                                          "_Z"].append(
                                                              value[2])
                                else:
                                    if count == 0:
                                        data["RESULTANT"][variable_name +
                                                          "_X"].append(
                                                              value[0])
                                        data["RESULTANT"][variable_name +
                                                          "_Y"].append(
                                                              value[1])
                                        data["RESULTANT"][variable_name +
                                                          "_Z"].append(
                                                              value[2])
                                    else:
                                        data["RESULTANT"][variable_name +
                                                          "_X"][-1] += value[0]
                                        data["RESULTANT"][variable_name +
                                                          "_Y"][-1] += value[1]
                                        data["RESULTANT"][variable_name +
                                                          "_Z"][-1] += value[2]
                            else:
                                if not self.resultant_solution:
                                    list = self.__kratos_vector_to__python_list(
                                        value)
                                    data[node_identifier][
                                        variable_name].append(list)
                                else:
                                    aux = 0.0
                                    for index in range(len(value)):
                                        aux += value[index]
                                    if count == 0:
                                        data["RESULTANT"][
                                            variable_name].append(aux)
                                    else:
                                        data["RESULTANT"][variable_name][
                                            -1] += aux
                        elif variable_type == "Vector":
                            if not self.resultant_solution:
                                data[node_identifier][variable_name].append(
                                    value)
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name].append(
                                        value)
                                else:
                                    data["RESULTANT"][variable_name][
                                        -1] += value

                        # TODO: Add pending classes
                    count += 1

            count = 0
            # Gauss points values
            for elem in self.sub_model_part.Elements:
                compute = self.__check_flag(elem)

                if compute:
                    for i in range(
                            self.params["gauss_points_output_variables"].size(
                            )):
                        out = self.params["gauss_points_output_variables"][i]
                        variable_name = out.GetString()
                        variable = KratosMultiphysics.KratosGlobals.GetVariable(
                            variable_name)
                        variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(
                            variable_name)
                        value = elem.CalculateOnIntegrationPoints(
                            variable, self.sub_model_part.ProcessInfo)

                        gauss_point_number = len(value)

                        if variable_type == "Double":
                            if not self.resultant_solution:
                                for gp in range(gauss_point_number):
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name][str(
                                             gp)].append(value[gp])
                            else:
                                if count == 0:
                                    for gp in range(gauss_point_number):
                                        data["RESULTANT"][variable_name][str(
                                            gp)].append(value[gp])
                                else:
                                    for gp in range(gauss_point_number):
                                        data["RESULTANT"][variable_name][str(
                                            gp)][-1] += value[gp]
                        elif variable_type == "Array":
                            if KratosMultiphysics.KratosGlobals.GetVariableType(
                                    variable_name + "_X") == "Double":
                                if not self.resultant_solution:
                                    for gp in range(gauss_point_number):
                                        data["ELEMENT_" + str(elem.Id)][
                                            variable_name +
                                            "_X"][str(gp)].append(value[gp][0])
                                        data["ELEMENT_" + str(elem.Id)][
                                            variable_name +
                                            "_Y"][str(gp)].append(value[gp][1])
                                        data["ELEMENT_" + str(elem.Id)][
                                            variable_name +
                                            "_Z"][str(gp)].append(value[gp][2])
                                else:
                                    if count == 0:
                                        for gp in range(gauss_point_number):
                                            data["RESULTANT"][
                                                variable_name +
                                                "_X"][str(gp)].append(
                                                    value[gp][0])
                                            data["RESULTANT"][
                                                variable_name +
                                                "_Y"][str(gp)].append(
                                                    value[gp][1])
                                            data["RESULTANT"][
                                                variable_name +
                                                "_Z"][str(gp)].append(
                                                    value[gp][2])
                                    else:
                                        for gp in range(gauss_point_number):
                                            data["RESULTANT"][
                                                variable_name + "_X"][str(
                                                    gp)][-1] += value[gp][0]
                                            data["RESULTANT"][
                                                variable_name + "_Y"][str(
                                                    gp)][-1] += value[gp][1]
                                            data["RESULTANT"][
                                                variable_name + "_Z"][str(
                                                    gp)][-1] += value[gp][2]
                            else:
                                if not self.resultant_solution:
                                    list = self.__kratos_vector_to__python_list(
                                        value)
                                    for gp in range(gauss_point_number):
                                        data["ELEMENT_" +
                                             str(elem.Id)][variable_name][str(
                                                 gp)].append(list)
                                else:
                                    if count == 0:
                                        for gp in range(gauss_point_number):
                                            aux = 0.0
                                            for index in range(len(value[gp])):
                                                aux += value[index]
                                            data["RESULTANT"][variable_name][
                                                str(gp)].append(aux)
                                    else:
                                        for gp in range(gauss_point_number):
                                            aux = 0.0
                                            for index in range(len(value[gp])):
                                                aux += value[index]
                                            data["RESULTANT"][variable_name][
                                                str(gp)][-1] += aux
                        elif variable_type == "Vector":
                            if not self.resultant_solution:
                                for gp in range(gauss_point_number):
                                    list = self.__kratos_vector_to__python_list(
                                        value[gp])
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name][str(
                                             gp)].append(list)
                            else:
                                if count == 0:
                                    for gp in range(gauss_point_number):
                                        list = self.__kratos_vector_to__python_list(
                                            value[gp])
                                        data["RESULTANT"][variable_name][str(
                                            gp)][-1] += list

                            # TODO: Add pending classes
                count += 1

        write_external_json(self.output_file_name, data)
Ejemplo n.º 4
0
    def ExecuteBeforeSolutionLoop(self):
        """ This method is executed before starting the time loop

        This step generates the structure of the dictionary

        Keyword arguments:
        self -- It signifies an instance of a class.
        """

        data = {}
        data["TIME"] = []
        count = 0
        for node in self.sub_model_part.Nodes:
            compute = self.__check_flag(node)

            if compute:
                node_identifier = "NODE_" + self.__get_node_identifier(node)

                if not self.resultant_solution:
                    data[node_identifier] = {}
                else:
                    if count == 0:
                        data["RESULTANT"] = {}

                for i in range(self.params["output_variables"].size()):
                    out = self.params["output_variables"][i]
                    variable_name = out.GetString()
                    variable = KratosMultiphysics.KratosGlobals.GetVariable(
                        variable_name)
                    variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(
                        variable_name)
                    if self.historical_value:
                        value = node.GetSolutionStepValue(variable, 0)
                    else:
                        value = node.GetValue(variable)

                    if variable_type == "Double":
                        if not self.resultant_solution:
                            data[node_identifier][variable_name] = []
                        else:
                            if count == 0:
                                data["RESULTANT"][variable_name] = []
                    elif variable_type == "Array":
                        if KratosMultiphysics.KratosGlobals.GetVariableType(
                                variable_name + "_X") == "Double":
                            if not self.resultant_solution:
                                data[node_identifier][variable_name +
                                                      "_X"] = []
                                data[node_identifier][variable_name +
                                                      "_Y"] = []
                                data[node_identifier][variable_name +
                                                      "_Z"] = []
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name +
                                                      "_X"] = []
                                    data["RESULTANT"][variable_name +
                                                      "_Y"] = []
                                    data["RESULTANT"][variable_name +
                                                      "_Z"] = []
                        else:
                            if not self.resultant_solution:
                                data[node_identifier][variable_name] = []
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name] = []
                    elif variable_type == "Vector":
                        if not self.resultant_solution:
                            data[node_identifier][variable_name] = []
                        else:
                            if count == 0:
                                data["RESULTANT"][variable_name] = []
                    # TODO: Add pending classes
                count += 1

        count = 0
        # Gauss points values
        for elem in self.sub_model_part.Elements:
            compute = self.__check_flag(elem)

            if compute:
                if not self.resultant_solution:
                    data["ELEMENT_" + str(elem.Id)] = {}
                else:
                    data["RESULTANT"] = {}

                for i in range(
                        self.params["gauss_points_output_variables"].size()):
                    out = self.params["gauss_points_output_variables"][i]
                    variable_name = out.GetString()
                    variable = KratosMultiphysics.KratosGlobals.GetVariable(
                        variable_name)
                    variable_type = KratosMultiphysics.KratosGlobals.GetVariableType(
                        variable_name)

                    value = elem.CalculateOnIntegrationPoints(
                        variable, self.sub_model_part.ProcessInfo)

                    gauss_point_number = len(value)

                    if variable_type == "Double":
                        if not self.resultant_solution:
                            data["ELEMENT_" + str(elem.Id)][variable_name] = {}
                            for gp in range(gauss_point_number):
                                data["ELEMENT_" + str(elem.Id)][variable_name][
                                    str(gp)] = []
                        else:
                            if count == 0:
                                data["RESULTANT"][variable_name] = {}
                                for gp in range(gauss_point_number):
                                    data["RESULTANT"][variable_name][str(
                                        gp)] = []
                    elif variable_type == "Array":
                        if KratosMultiphysics.KratosGlobals.GetVariableType(
                                variable_name + "_X") == "Double":
                            if not self.resultant_solution:
                                data["ELEMENT_" + str(elem.Id)][variable_name +
                                                                "_X"] = {}
                                data["ELEMENT_" + str(elem.Id)][variable_name +
                                                                "_Y"] = {}
                                data["ELEMENT_" + str(elem.Id)][variable_name +
                                                                "_Z"] = {}
                                for gp in range(gauss_point_number):
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name +
                                                       "_X"][str(gp)] = []
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name +
                                                       "_Y"][str(gp)] = []
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name +
                                                       "_Z"][str(gp)] = []
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name +
                                                      "_X"] = {}
                                    data["RESULTANT"][variable_name +
                                                      "_Y"] = {}
                                    data["RESULTANT"][variable_name +
                                                      "_Z"] = {}
                                    for gp in range(gauss_point_number):
                                        data["RESULTANT"][variable_name +
                                                          "_X"][str(gp)] = []
                        else:
                            if not self.resultant_solution:
                                data["ELEMENT_" +
                                     str(elem.Id)][variable_name] = {}
                                for gp in range(gauss_point_number):
                                    data["ELEMENT_" +
                                         str(elem.Id)][variable_name][str(
                                             gp)] = []
                            else:
                                if count == 0:
                                    data["RESULTANT"][variable_name] = {}
                    elif variable_type == "Vector":
                        if not self.resultant_solution:
                            data["ELEMENT_" + str(elem.Id)][variable_name] = {}
                            for gp in range(gauss_point_number):
                                data["ELEMENT_" + str(elem.Id)][variable_name][
                                    str(gp)] = []
                        else:
                            if count == 0:
                                data["RESULTANT"][variable_name] = {}
                                for gp in range(gauss_point_number):
                                    data["RESULTANT"][variable_name][str(
                                        gp)] = []
                    # TODO: Add pending classes
                count += 1

        write_external_json(self.output_file_name, data)