Ejemplo n.º 1
0
    def __init__(self, model, parameters=Parameters("{}")):
        sys.stdout = SDEMLogger()
        self.StartTimer()
        self.model = model
        self.main_path = os.getcwd()

        self.SetProjectParameters(parameters)

        self.vars_man = variables_management.VariablesManager(
            self.project_parameters)

        self._GetDEMAnalysis().coupling_analysis = weakref.proxy(self)

        self._GetFluidAnalysis().coupling_analysis = weakref.proxy(self)

        self.procedures = weakref.proxy(self._GetDEMAnalysis().procedures)

        self.report = DP.Report()

        self._GetDEMAnalysis().SetAnalyticFaceWatcher()

        # defining member variables for the model_parts (for convenience)
        self.fluid_model_part = self._GetFluidAnalysis().fluid_model_part
        self.spheres_model_part = self._GetDEMAnalysis().spheres_model_part
        self.cluster_model_part = self._GetDEMAnalysis().cluster_model_part
        self.rigid_face_model_part = self._GetDEMAnalysis(
        ).rigid_face_model_part
        self.dem_inlet_model_part = self._GetDEMAnalysis().dem_inlet_model_part
        self.vars_man.ConstructListsOfVariables(self.project_parameters)

        super(SwimmingDEMAnalysis, self).__init__(model,
                                                  self.project_parameters)
Ejemplo n.º 2
0
    def Initialize(self):
        self.PrepareTests()
        self.PrepareTestTriaxialHydro()
        self.PrepareTestOedometric()

        domain_volume = math.pi * 0.5 * 0.5 * self.diameter * self.diameter * self.height
        DEM_procedures.GranulometryUtils(domain_volume, self.spheres_model_part)
Ejemplo n.º 3
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.º 4
0
    def UpdateDataAndPrint(self, domain_volume, is_time_to_print=True):
        self.granul_utils = DP.GranulometryUtils(domain_volume,
                                                 self.balls_model_part)
        self.domain_volume = domain_volume
        self.number_of_balls = self.balls_model_part.NumberOfElements(0)
        self.discr_domain_volume = self.custom_utils.CalculateDomainVolume(
            self.fluid_model_part)
        self.proj_fluid_volume = self.custom_utils.CalculateGlobalFluidVolume(
            self.fluid_model_part)
        self.solid_volume = self.granul_utils.solid_volume
        self.balls_per_area = self.granul_utils.spheres_per_area
        self.fluid_volume = domain_volume - self.solid_volume
        self.discr_fluid_volume = self.discr_domain_volume - self.solid_volume
        self.proj_solid_volume = self.discr_domain_volume - self.proj_fluid_volume
        self.global_fluid_fraction = self.fluid_volume / self.domain_volume
        self.global_solid_fraction = 1.0 - self.global_fluid_fraction
        self.fluid_on_balls_total_force = Array3()
        self.proj_balls_on_fluid_total_force = Array3()
        self.mean_proj_balls_on_fluid_total_force = Array3()
        self.custom_utils.CalculateTotalHydrodynamicForceOnParticles(
            self.balls_model_part, self.fluid_on_balls_total_force)
        self.custom_utils.CalculateTotalHydrodynamicForceOnFluid(
            self.fluid_model_part, self.proj_balls_on_fluid_total_force,
            self.mean_proj_balls_on_fluid_total_force)

        if not is_time_to_print:
            return

        # printing

        tot_len = 38  # total length of each line, including spaces
        Logger.PrintInfo("SwimmingDEM", )
        Logger.PrintInfo("SwimmingDEM", "Projection-related measurements")
        Logger.PrintInfo("SwimmingDEM", tot_len * "**")
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("number_of_balls", tot_len) + '=',
                         self.number_of_balls)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("domain_volume", tot_len) + '=',
                         self.domain_volume)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("fluid_volume", tot_len) + '=',
                         self.fluid_volume)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("solid_volume", tot_len) + '=',
                         self.solid_volume)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("discr_domain_volume", tot_len) + '=',
            self.discr_domain_volume)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("discr_fluid_volume", tot_len) + '=',
            self.discr_fluid_volume)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("proj_fluid_volume", tot_len) + '=',
                         self.proj_fluid_volume)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("proj_solid_volume", tot_len) + '=',
                         self.proj_solid_volume)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("global_fluid_fraction", tot_len) + '=',
            self.global_fluid_fraction)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("global_solid_fraction", tot_len) + '=',
            self.global_solid_fraction)
        Logger.PrintInfo("SwimmingDEM",
                         GetWordWithSpaces("balls_per_area", tot_len) + '=',
                         self.balls_per_area)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("fluid_on_balls_total_force", tot_len) + '=',
            self.fluid_on_balls_total_force)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("proj_balls_on_fluid_total_force", tot_len) +
            '=', self.proj_balls_on_fluid_total_force)
        Logger.PrintInfo(
            "SwimmingDEM",
            GetWordWithSpaces("mean_proj_balls_on_fluid_total_force", tot_len)
            + '=', self.mean_proj_balls_on_fluid_total_force)
        Logger.PrintInfo("SwimmingDEM", tot_len * "**")
        Logger.PrintInfo("SwimmingDEM", )
        Logger.Flush()