def Initialize(self):

        self.computing_model_part = self.GetComputingModelPart()

        domain_size = self.main_model_part.ProcessInfo[
            KratosMultiphysics.DOMAIN_SIZE]

        if self.settings["response_function_settings"][
                "response_type"].GetString() == "drag":
            if (domain_size == 2):
                self.response_function = KratosAdjoint.DragResponseFunction2D(
                    self.main_model_part,
                    self.settings["response_function_settings"])
            elif (domain_size == 3):
                self.response_function = KratosAdjoint.DragResponseFunction3D(
                    self.main_model_part,
                    self.settings["response_function_settings"])
            else:
                raise Exception("Invalid DOMAIN_SIZE: " + str(domain_size))
        else:
            raise Exception("invalid response_type: " +
                            self.settings["response_function_settings"]
                            ["response_type"].GetString())

        if self.settings["scheme_settings"]["scheme_type"].GetString(
        ) == "bossak":
            self.time_scheme = KratosAdjoint.AdjointBossakScheme(
                self.settings["scheme_settings"], self.response_function)
        elif self.settings["scheme_settings"]["scheme_type"].GetString(
        ) == "steady":
            self.time_scheme = KratosAdjoint.AdjointSteadyVelocityPressureScheme(
                self.settings["scheme_settings"], self.response_function)
        else:
            raise Exception(
                "invalid scheme_type: " +
                self.settings["scheme_settings"]["scheme_type"].GetString())

        builder_and_solver = KratosMultiphysics.ResidualBasedBlockBuilderAndSolver(
            self.linear_solver)

        self.solver = KratosMultiphysics.ResidualBasedLinearStrategy(
            self.main_model_part, self.time_scheme, self.linear_solver,
            builder_and_solver, False, False, False, False)

        (self.solver).SetEchoLevel(self.settings["echo_level"].GetInt())

        (self.solver).Initialize()

        (self.solver).Check()

        self.main_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DYNAMIC_TAU,
            self.settings["dynamic_tau"].GetDouble())
        self.main_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.OSS_SWITCH,
            self.settings["oss_switch"].GetInt())

        KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__,
                                            "Solver initialization finished.")
Ejemplo n.º 2
0
    def Initialize(self):

        ## Construct the communicator
        self.EpetraCommunicator = TrilinosApplication.CreateCommunicator()

        ## Get the computing model part
        self.computing_model_part = self.GetComputingModelPart()

        domain_size = self.main_model_part.ProcessInfo[
            KratosMultiphysics.DOMAIN_SIZE]
        if self.settings["response_function_settings"][
                "response_type"].GetString() == "drag":
            if (domain_size == 2):
                self.response_function = AdjointFluidApplication.DragResponseFunction2D(
                    self.main_model_part,
                    self.settings["response_function_settings"])
            elif (domain_size == 3):
                self.response_function = AdjointFluidApplication.DragResponseFunction3D(
                    self.main_model_part,
                    self.settings["response_function_settings"])
            else:
                raise Exception("Invalid DOMAIN_SIZE: " + str(domain_size))
        else:
            raise Exception("invalid response_type: " +
                            self.settings["response_function_settings"]
                            ["response_type"].GetString())

        if self.settings["scheme_settings"]["scheme_type"].GetString(
        ) == "bossak":
            self.time_scheme = TrilinosApplication.TrilinosAdjointBossakScheme(
                self.settings["scheme_settings"], self.response_function)
        elif self.settings["scheme_settings"]["scheme_type"].GetString(
        ) == "steady":
            self.time_scheme = TrilinosApplication.TrilinosAdjointSteadyScheme(
                self.settings["scheme_settings"], self.response_function)
        else:
            raise Exception(
                "invalid scheme_type: " +
                self.settings["scheme_settings"]["scheme_type"].GetString())

        if self.main_model_part.ProcessInfo[
                KratosMultiphysics.DOMAIN_SIZE] == 3:
            guess_row_size = 20 * 4
        elif self.main_model_part.ProcessInfo[
                KratosMultiphysics.DOMAIN_SIZE] == 2:
            guess_row_size = 10 * 3

        self.builder_and_solver = TrilinosApplication.TrilinosBlockBuilderAndSolver(
            self.EpetraCommunicator, guess_row_size,
            self.trilinos_linear_solver)

        self.solver = TrilinosApplication.TrilinosLinearStrategy(
            self.main_model_part, self.time_scheme,
            self.trilinos_linear_solver, self.builder_and_solver, False, False,
            False, False)

        (self.solver).SetEchoLevel(self.settings["echo_level"].GetInt())

        (self.solver).Initialize()

        (self.solver).Check()

        self.main_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DYNAMIC_TAU,
            self.settings["dynamic_tau"].GetDouble())
        self.main_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.OSS_SWITCH,
            self.settings["oss_switch"].GetInt())

        if self._IsPrintingRank():
            KratosMultiphysics.Logger.PrintInfo(
                self.__class__.__name__,
                "Monolithic MPI solver initialization finished.")