Ejemplo n.º 1
0
    def Initialize(self):
        Say('Initializing simulation...\n')
        self.run_code = self.GetRunCode()

        # Moving to the recently created folder
        os.chdir(self.main_path)
        if self.do_print_results:
            [self.post_path, data_and_results, self.graphs_path, MPI_results] = \
            self.procedures.CreateDirectories(str(self.main_path),
                                            str(self.project_parameters["problem_data"]["problem_name"].GetString()),
                                            self.run_code)
            SDP.CopyInputFilesIntoFolder(self.main_path, self.post_path)
            self.MPI_results = MPI_results

        self.FluidInitialize()

        self.DispersePhaseInitialize()

        self.SetAllModelParts()

        if self.project_parameters.Has(
                'sdem_output_processes') and self.do_print_results:
            gid_output_options = self.project_parameters[
                "sdem_output_processes"]["gid_output"][0]["Parameters"]
            result_file_configuration = gid_output_options[
                "postprocess_parameters"]["result_file_configuration"]
            write_conditions_option = result_file_configuration[
                "gidpost_flags"]["WriteConditionsFlag"].GetString(
                ) == "WriteConditions"
            deformed_mesh_option = result_file_configuration["gidpost_flags"][
                "WriteDeformedMeshFlag"].GetString() == "WriteDeformed"
            old_gid_output_post_options_dict = {
                'GiD_PostAscii': 'Ascii',
                'GiD_PostBinary': 'Binary',
                'GiD_PostAsciiZipped': 'AsciiZipped'
            }
            old_gid_output_multiple_file_option_dict = {
                'SingleFile': 'Single',
                'MultipleFiles': 'Multiples'
            }
            post_mode_key = result_file_configuration["gidpost_flags"][
                "GiDPostMode"].GetString()
            multiple_files_option_key = result_file_configuration[
                "gidpost_flags"]["MultiFileFlag"].GetString()

            self.swimming_DEM_gid_io = \
            swimming_DEM_gid_output.SwimmingDEMGiDOutput(
                file_name = self.project_parameters["problem_data"]["problem_name"].GetString(),
                vol_output = result_file_configuration["body_output"].GetBool(),
                post_mode = old_gid_output_post_options_dict[post_mode_key],
                multifile = old_gid_output_multiple_file_option_dict[multiple_files_option_key],
                deformed_mesh = deformed_mesh_option,
                write_conditions = write_conditions_option)

            self.swimming_DEM_gid_io.initialize_swimming_DEM_results(
                self.spheres_model_part, self.cluster_model_part,
                self.rigid_face_model_part, self.mixed_model_part)

        self.SetPointGraphPrinter()

        self.AssignKinematicViscosityFromDynamicViscosity()

        super(SwimmingDEMAnalysis, self).Initialize()

        # coarse-graining: applying changes to the physical properties of the model to adjust for
        # the similarity transformation if required (fluid effects only).
        SDP.ApplySimilarityTransformations(
            self.fluid_model_part, self.project_parameters["similarity"]
            ["similarity_transformation_type"].GetInt(),
            self.project_parameters["similarity"]
            ["model_over_real_diameter_factor"].GetDouble())

        if self.do_print_results:
            self.SetPostUtils()

        # creating an IOTools object to perform other printing tasks
        self.io_tools = SDP.IOTools(self.project_parameters)

        dem_physics_calculator = DEM.SphericElementGlobalPhysicsCalculator(
            self.spheres_model_part)

        if self.project_parameters["coupling"]["coupling_level_type"].GetInt():
            default_meso_scale_length_needed = (
                self.project_parameters["coupling"]["backward_coupling"]
                ["meso_scale_length"].GetDouble() <= 0.0
                and self.spheres_model_part.NumberOfElements(0) > 0)

            if default_meso_scale_length_needed:
                biggest_size = (
                    2 * dem_physics_calculator.CalculateMaxNodalVariable(
                        self.spheres_model_part, Kratos.RADIUS))
                self.project_parameters["coupling"]["backward_coupling"][
                    "meso_scale_length"].SetDouble(20 * biggest_size)

            elif self.spheres_model_part.NumberOfElements(0) == 0:
                self.project_parameters["coupling"]["backward_coupling"][
                    "meso_scale_length"].SetDouble(1.0)

        # creating a custom functions calculator for the implementation of
        # additional custom functions
        fluid_domain_dimension = self.project_parameters["fluid_parameters"][
            "solver_settings"]["domain_size"].GetInt()
        self.custom_functions_tool = SDP.FunctionsCalculator(
            fluid_domain_dimension)

        # creating a debug tool
        self.dem_volume_tool = self.GetVolumeDebugTool()

        #self.SetEmbeddedTools()

        Say('Initialization Complete\n')

        if self.project_parameters["custom_fluid"][
                "flow_in_porous_DEM_medium_option"].GetBool():
            SDP.FixModelPart(self.spheres_model_part)

        ##################################################

        #    I N I T I A L I Z I N G    T I M E    L O O P

        ##################################################
        self.step = 0
        self.time = self.fluid_parameters["problem_data"][
            "start_time"].GetDouble()
        self.fluid_time_step = self._GetFluidAnalysis()._GetSolver(
        )._ComputeDeltaTime()
        self.time_step = self.spheres_model_part.ProcessInfo.GetValue(
            Kratos.DELTA_TIME)
        self.rigid_face_model_part.ProcessInfo[
            Kratos.DELTA_TIME] = self.time_step
        self.cluster_model_part.ProcessInfo[Kratos.DELTA_TIME] = self.time_step
        self.stationarity = False

        # setting up loop counters:
        self.DEM_to_fluid_counter = self.GetBackwardCouplingCounter()
        self.stationarity_counter = self.GetStationarityCounter()
        self.print_counter = self.GetPrintCounter()
        self.debug_info_counter = self.GetDebugInfo()
        self.particles_results_counter = self.GetParticlesResultsCounter()
        self.quadrature_counter = self.GetHistoryForceQuadratureCounter()
        # Phantom
        self._GetDEMAnalysis(
        ).analytic_data_counter = self.ProcessAnalyticDataCounter()
        self.mat_deriv_averager = SDP.Averager(1, 3)
        self.laplacian_averager = SDP.Averager(1, 3)

        self.report.total_steps_expected = int(self.end_time / self.time_step)

        Say(self.report.BeginReport(self.timer))

        # creating a Post Utils object that executes several post-related tasks
        self.post_utils_DEM = DP.PostUtils(
            self.project_parameters['dem_parameters'], self.spheres_model_part)

        # otherwise variables are set to 0 by default:
        SDP.InitializeVariablesWithNonZeroValues(self.project_parameters,
                                                 self.fluid_model_part,
                                                 self.spheres_model_part)

        if self.do_print_results:
            self.SetUpResultsDatabase()

        # ANALYTICS BEGIN
        self.project_parameters.AddEmptyValue(
            "perform_analytics_option").SetBool(False)

        if self.project_parameters["perform_analytics_option"].GetBool():
            import KratosMultiphysics.SwimmingDEMApplication.analytics as analytics
            variables_to_measure = [Kratos.PRESSURE]
            steps_between_measurements = 100
            gauge = analytics.Gauge(self.fluid_model_part,
                                    self.fluid_time_step, self.end_time,
                                    variables_to_measure,
                                    steps_between_measurements)
            point_coors = [0.0, 0.0, 0.01]
            target_node = SDP.FindClosestNode(self.fluid_model_part,
                                              point_coors)
            target_id = target_node.Id
            Say(target_node.X, target_node.Y, target_node.Z)
            Say(target_id)

            def condition(node):
                return node.Id == target_id

            gauge.ConstructArrayOfNodes(condition)
            Say(gauge.variables)
        # ANALYTICS END

        self.FillHistoryForcePrecalculatedVectors()

        self.PerformZeroStepInitializations()

        if self.do_print_results:
            self._Print()
Ejemplo n.º 2
0
 def InitializeVariablesWithNonZeroValues(self):
     SDP.InitializeVariablesWithNonZeroValues(self.project_parameters,
                                              self.fluid_model_part,
                                              self.spheres_model_part)