Beispiel #1
0
    def __init__(self, model, parameters = Parameters("{}")):
        sys.stdout = SDEMLogger()
        self.pp = python_parameters()
        self.StartTimer()
        self.model = model
        self.main_path = os.getcwd()
        self.dem_json_path = os.getcwd() + '/ProjectParametersDEM.json'
        self.fluid_json_path = os.getcwd() + '/ProjectParameters.json'
        self.project_parameters = parameters

        if parameters.Has('dem_json_path'):
            self.dem_json_path = parameters['dem_json_path'].GetString()
        if parameters.Has('fluid_json_path'):
            self.fluid_json_path = parameters['fluid_json_path'].GetString()

        self.SetCouplingParameters(parameters)

        self.SetFluidParameters()

        self.ModifyInputParametersForCoherence()

        self.SetDispersePhaseAlgorithm()

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

        self.SetFluidAlgorithm()
        self.fluid_solution.coupling_analysis = weakref.proxy(self)

        self.procedures = weakref.proxy(self.disperse_phase_solution.procedures)
        self.report = DEM_procedures.Report()

        # creating a basset_force tool to perform the operations associated
        # with the calculation of this force along the path of each particle
        self.disperse_phase_solution.SetAnalyticFaceWatcher()

        # defining member variables for the model_parts (for convenience)
        self.fluid_model_part = self.fluid_solution.fluid_model_part
        self.spheres_model_part = self.disperse_phase_solution.spheres_model_part
        self.cluster_model_part = self.disperse_phase_solution.cluster_model_part
        self.rigid_face_model_part = self.disperse_phase_solution.rigid_face_model_part
        self.DEM_inlet_model_part = self.disperse_phase_solution.DEM_inlet_model_part
        vars_man.ConstructListsOfVariables(self.pp)
        super(SwimmingDEMAnalysis, self).__init__(model, self.pp.CFD_DEM) # TODO: The DEM jason is now interpreted as the coupling json. This must be changed
    def AddExtraVariables(self):
        spheres_model_part = self.all_model_parts.Get('SpheresPart')
        fluid_model_part = self.all_model_parts.Get('FluidPart')

        # building lists of variables for which memory is to be allocated
        # TEMPORARY, HORRIBLE !!!
        import variables_management as vars_man

        vars_man.ConstructListsOfVariables(self.pp)
        fluid_model_part = self.all_model_parts.Get('FluidPart')

        if "REACTION" in self.pp.nodal_results:
            fluid_model_part.AddNodalSolutionStepVariable(REACTION)
        if "DISTANCE" in self.pp.nodal_results:
            fluid_model_part.AddNodalSolutionStepVariable(DISTANCE)

        # importing the solvers needed
        SolverSettings = self.pp.FluidSolverConfiguration
        self.solver_module = import_solver(SolverSettings)

        # caution with breaking up this block (memory allocation)! {
        self.solver_module.AddVariables(fluid_model_part, SolverSettings)
        vars_man.AddNodalVariables(fluid_model_part,
                                   self.pp.fluid_vars)  #     MOD.
        # }
        # self.ReadFluidModelPart()
        # Creating necessary directories
        [post_path, data_and_results, graphs_path,
         MPI_results] = self.procedures.CreateDirectories(
             str(self.main_path), str(self.pp.CFD_DEM.problem_name))

        vars_man.AddNodalVariables(spheres_model_part, self.pp.dem_vars)
        vars_man.AddNodalVariables(self.rigid_face_model_part,
                                   self.pp.rigid_faces_vars)
        vars_man.AddNodalVariables(self.DEM_inlet_model_part,
                                   self.pp.inlet_vars)
        # adding extra process info variables
        vars_man.AddingExtraProcessInfoVariables(self.pp, fluid_model_part,
                                                 spheres_model_part)
Beispiel #3
0
DEM_inlet_model_part  = ModelPart("DEMInletPart")
mapping_model_part    = ModelPart("Mappingmodel_part")

# defining and adding imposed porosity fields
pp.fluid_fraction_fields = []
field1 = swim_proc.FluidFractionFieldUtility.LinearField(0.0,
                                                         [0.0, 0.0, 0.0],
                                                         [-1.0, -1.0, 0.15],
                                                         [1.0, 1.0, 0.3])
pp.fluid_fraction_fields.append(field1)

# building lists of variables for which memory is to be allocated
# TEMPORARY, HORRIBLE !!!
pp.viscosity_modification_type = 0.0

vars_man.ConstructListsOfVariables(pp)
#_____________________________________________________________________________________________________________________________________
#
#                               F L U I D    B L O C K    B E G I N S
#_____________________________________________________________________________________________________________________________________

# defining variables to be used
# GID IO IS NOT USING THIS NOW. TO BE REMOVED ONCE THE "PRINT IN POINTS"
# CODE IS NOT USING IT

variables_dictionary = {"PRESSURE"   : PRESSURE,
                        "VELOCITY"   : VELOCITY,
                        "MU"         : MU,         #    MOD.
                        "BUOYANCY"   : BUOYANCY,   #    MOD.
                        "DRAG_FORCE" : DRAG_FORCE,  #    MOD.
                        "LIFT_FORCE" : LIFT_FORCE} #    MOD.
Beispiel #4
0
ProjectParameters.drag_law_slope = 0.0  # problemtype option
ProjectParameters.power_law_tol = 0.0
ProjectParameters.model_over_real_diameter_factor = 1.0  # not active if similarity_transformation_type = 0
ProjectParameters.max_pressure_variation_rate_tol = 1e-3  # for stationary problems, criterion to stop the fluid calculations
ProjectParameters.time_steps_per_stationarity_step = 15  # number of fluid time steps between consecutive assessment of stationarity steps
ProjectParameters.meso_scale_length = -1  # the radius of the support of the averaging function for homogenization (<=0 for automatic calculation)
ProjectParameters.shape_factor = 1.0  # the density function's maximum over its support's radius (only relevant if coupling_weighing_type == 3)

# defining and adding imposed porosity fields
ProjectParameters.fluid_fraction_fields = []
field1 = swim_proc.FluidFractionFieldUtility.LinearField(
    0.0, [0.0, 0.0, 0.0], [-1.0, -1.0, 0.15], [1.0, 1.0, 0.3])
ProjectParameters.fluid_fraction_fields.append(field1)

# building lists of variables for which memory is to be allocated
vars_man.ConstructListsOfVariables(ProjectParameters)

#_____________________________________________________________________________________________________________________________________
#
#                               F L U I D    B L O C K    B E G I N S
#_____________________________________________________________________________________________________________________________________

# defining variables to be used
# GID IO IS NOT USING THIS NOW. TO BE REMOVED ONCE THE "PRINT IN POINTS"
# CODE IS NOT USING IT

variables_dictionary = {
    "PRESSURE": PRESSURE,
    "VELOCITY": VELOCITY,
    "MU": MU,  #    MOD.
    "BUOYANCY": BUOYANCY,  #    MOD.
Beispiel #5
0
    def Initialize(self):
        Say('Initializing Problem...\n')

        self.run_code = self.GetRunCode()

        # Moving to the recently created folder
        os.chdir(self.main_path)
        [self.post_path, data_and_results, self.graphs_path, MPI_results] = \
        self.procedures.CreateDirectories(str(self.main_path),
                                          str(self.pp.CFD_DEM["problem_name"].GetString()),
                                          self.run_code)
        SDP.CopyInputFilesIntoFolder(self.main_path, self.post_path)
        self.MPI_results = MPI_results
        #self.mixed_model_part = self.all_model_parts.Get('MixedPart')

        vars_man.ConstructListsOfVariables(self.pp)

        self.FluidInitialize()
        self.DispersePhaseInitialize()

        self.SetAllModelParts()

        self.SetCutsOutput()

        self.swimming_DEM_gid_io = \
        swimming_DEM_gid_output.SwimmingDEMGiDOutput(
            self.pp.CFD_DEM["problem_name"].GetString(),
            self.pp.VolumeOutput,
            self.pp.GiDPostMode,
            self.pp.GiDMultiFileFlag,
            self.pp.GiDWriteMeshFlag,
            self.pp.GiDWriteConditionsFlag
            )

        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.SetDragOutput()

        self.SetPointGraphPrinter()

        self.TransferGravityFromDisperseToFluid()

        self.AssignKinematicViscosityFromDynamicViscosity()

        # 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.pp.CFD_DEM["similarity_transformation_type"].GetInt(),
            self.pp.CFD_DEM["model_over_real_diameter_factor"].GetDouble())

        self.SetPostUtils()

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

        # creating a projection module for the fluid-DEM coupling
        self.h_min = 0.01
        n_balls = 1
        fluid_volume = 10
        # the variable n_particles_in_depth is only relevant in 2D problems
        self.pp.CFD_DEM.AddEmptyValue("n_particles_in_depth").SetInt(
            int(math.sqrt(n_balls / fluid_volume)))
        # creating a physical calculations module to analyse the DEM model_part

        dem_physics_calculator = SphericElementGlobalPhysicsCalculator(
            self.spheres_model_part)

        if self.pp.CFD_DEM["coupling_level_type"].GetInt():
            default_meso_scale_length_needed = (
                self.pp.CFD_DEM["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, RADIUS))
                self.pp.CFD_DEM["meso_scale_length"].SetDouble(20 *
                                                               biggest_size)

            elif self.spheres_model_part.NumberOfElements(0) == 0:
                self.pp.CFD_DEM["meso_scale_length"].SetDouble(1.0)

            self.projection_module = CFD_DEM_coupling.ProjectionModule(
                self.fluid_model_part,
                self.spheres_model_part,
                self.rigid_face_model_part,
                self.pp,
                flow_field=self.GetFieldUtility())

            self.projection_module.UpdateDatabase(self.h_min)

        # creating a custom functions calculator for the implementation of
        # additional custom functions
        self.custom_functions_tool = SDP.FunctionsCalculator(self.pp)

        # creating a stationarity assessment tool
        self.stationarity_tool = SDP.StationarityAssessmentTool(
            self.pp.CFD_DEM["max_pressure_variation_rate_tol"].GetDouble(),
            self.custom_functions_tool)

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

        #self.SetEmbeddedTools()

        Say('Initialization Complete\n')

        self.report.Prepare(self.timer,
                            self.pp.CFD_DEM["ControlTime"].GetDouble())

        #first_print = True; index_5 = 1; index_10 = 1; index_50 = 1; control = 0.0

        if self.pp.CFD_DEM["ModelDataInfo"].GetBool():
            os.chdir(data_and_results)
            if self.pp.CFD_DEM.ContactMeshOption == "ON":
                coordination_number = self.procedures.ModelData(
                    self.spheres_model_part, self.solver)
                Say('Coordination Number: ' + str(coordination_number) + '\n')
                os.chdir(self.main_path)
            else:
                Say('Activate Contact Mesh for ModelData information\n')

        if self.pp.CFD_DEM["flow_in_porous_medium_option"].GetBool():
            fluid_frac_util = SDP.FluidFractionFieldUtility(
                self.fluid_model_part, self.pp.CFD_DEM.min_fluid_fraction)

            for field in self.pp.fluid_fraction_fields:
                fluid_frac_util.AppendLinearField(field)

            fluid_frac_util.AddFluidFractionField()

        if self.pp.CFD_DEM["flow_in_porous_DEM_medium_option"].GetBool():
            SDP.FixModelPart(self.spheres_model_part)

        # choosing the directory in which we want to work (print to)

        os.chdir(self.post_path)

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

        #    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.pp.Start_time
        self.Dt = self.pp.Dt
        self.final_time = self.pp.CFD_DEM["FinalTime"].GetDouble()
        self.DEM_step = 0
        self.time_dem = 0.0
        self.Dt_DEM = self.spheres_model_part.ProcessInfo.GetValue(DELTA_TIME)
        self.rigid_face_model_part.ProcessInfo[DELTA_TIME] = self.Dt_DEM
        self.cluster_model_part.ProcessInfo[DELTA_TIME] = self.Dt_DEM
        self.stationarity = False

        # setting up loop counters:
        self.fluid_solve_counter = self.GetFluidSolveCounter()
        self.DEM_to_fluid_counter = self.GetBackwardCouplingCounter()
        self.derivative_recovery_counter = self.GetRecoveryCounter()
        self.stationarity_counter = self.GetStationarityCounter()
        self.print_counter_updated_DEM = self.GetPrintCounterUpdatedDEM()
        self.print_counter_updated_fluid = self.GetPrintCounterUpdatedFluid()
        self.debug_info_counter = self.GetDebugInfo()
        self.particles_results_counter = self.GetParticlesResultsCounter()
        self.quadrature_counter = self.GetHistoryForceQuadratureCounter()
        #Phantom
        self.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.final_time / self.Dt_DEM)

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

        # creating a Post Utils object that executes several post-related tasks
        self.post_utils_DEM = DEM_procedures.PostUtils(self.pp.CFD_DEM,
                                                       self.spheres_model_part)

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

        self.SetUpResultsDatabase()

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

        if self.pp.CFD_DEM["perform_analytics_option"].GetBool():
            import analytics
            variables_to_measure = [PRESSURE]
            steps_between_measurements = 100
            gauge = analytics.Gauge(self.fluid_model_part, self.Dt,
                                    self.final_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

        import derivative_recovery.derivative_recovery_strategy as derivative_recoverer

        self.recovery = derivative_recoverer.DerivativeRecoveryStrategy(
            self.pp, self.fluid_model_part, self.custom_functions_tool)

        self.FillHistoryForcePrecalculatedVectors()

        self.PerformZeroStepInitializations()

        self.post_utils.Writeresults(self.time)
Beispiel #6
0
    def AddExtraVariables(self):
        spheres_model_part = self.all_model_parts.Get('SpheresPart')
        fluid_model_part = self.all_model_parts.Get('FluidPart')

        # building lists of variables for which memory is to be allocated
        # TEMPORARY, HORRIBLE !!!
        import variables_management as vars_man

        vars_man.ConstructListsOfVariables(self.pp)
        #_____________________________________________________________________________________________________________________________________
        #
        #                               F L U I D    B L O C K    B E G I N S
        #_____________________________________________________________________________________________________________________________________

        # defining variables to be used
        # GID IO IS NOT USING THIS NOW. TO BE REMOVED ONCE THE "PRINT IN POINTS"
        # CODE IS NOT USING IT

        variables_dictionary = {
            "PRESSURE": PRESSURE,
            "VELOCITY": VELOCITY,
            "MU": MU,  #    MOD.
            "BUOYANCY": BUOYANCY,  #    MOD.
            "DRAG_FORCE": DRAG_FORCE,  #    MOD.
            "LIFT_FORCE": LIFT_FORCE
        }  #    MOD.

        fluid_model_part = self.all_model_parts.Get('FluidPart')

        if "REACTION" in self.pp.nodal_results:
            fluid_model_part.AddNodalSolutionStepVariable(REACTION)
        if "DISTANCE" in self.pp.nodal_results:
            fluid_model_part.AddNodalSolutionStepVariable(DISTANCE)

        # importing the solvers needed
        SolverSettings = self.pp.FluidSolverConfiguration
        self.solver_module = import_solver(SolverSettings)

        # caution with breaking up this block (memory allocation)! {
        self.solver_module.AddVariables(fluid_model_part, SolverSettings)
        vars_man.AddNodalVariables(fluid_model_part,
                                   self.pp.fluid_vars)  #     MOD.
        # }
        # self.ReadFluidModelPart()
        # Creating necessary directories
        [post_path, data_and_results, graphs_path,
         MPI_results] = self.procedures.CreateDirectories(
             str(self.main_path), str(self.pp.CFD_DEM.problem_name))

        #_____________________________________________________________________________________________________________________________________
        #
        #                               F L U I D    B L O C K    E N D S
        #_____________________________________________________________________________________________________________________________________

        # Add variables

        vars_man.AddNodalVariables(spheres_model_part, self.pp.dem_vars)
        vars_man.AddNodalVariables(self.rigid_face_model_part,
                                   self.pp.rigid_faces_vars)
        vars_man.AddNodalVariables(self.DEM_inlet_model_part,
                                   self.pp.inlet_vars)
        # adding extra process info variables
        vars_man.AddingExtraProcessInfoVariables(self.pp, fluid_model_part,
                                                 spheres_model_part)