示例#1
0
    def FluidSolve(self, time='None', solve_system=True):
        Say('Solving Fluid... (', self.fluid_model_part.NumberOfElements(0), 'elements )\n')

        if solve_system:
            self.fluid_solution.fluid_solver.Solve()
        else:
            Say("Skipping solving system...\n")
    def Rotate(self, model_part, time):
        Say('Starting mesh movement...')

        sin = math.sin(self.omega * time)
        cos = math.cos(self.omega * time)

        # Rotation matrix
        R = cos * self.I + sin * self.Ux + (1.0 - cos) * self.UU

        # Rotation matrix' (derivative of R with respect to time)
        Rp = - self.omega * sin * self.I + self.omega * cos * self.Ux + self.omega * sin * self.UU

        for node in model_part.Nodes:
            P0 = np.array([node.X0, node.Y0, node.Z0])

            P = self.a_init + R.dot(P0 - self.a_init)

            Displacement = P - P0
            Velocity = Rp.dot(P0 - self.a_init)

            node.X, node.Y, node.Z = P[0], P[1], P[2]

            node.SetSolutionStepValue(DISPLACEMENT, Vector(list(Displacement)))
            node.SetSolutionStepValue(MESH_VELOCITY, Vector(list(Velocity)))

        Say('Mesh movement finshed.')
示例#3
0
    def FinishAndSayEndMessage(self, message_start):
        if self.n_simulations:
            message_start += ' out of ' + str(self.n_simulations) + '...\n'
        else:
            message_start += '...\n'

        message_start += '=' * self.print_line_length + '\n'
        message_start += ('\n' + ' ' * int(self.print_line_length / 2) +
                          '*') * self.number_of_trailing_dots
        Say(message_start)
示例#4
0
    def SetDragOutput(self):
        # define the drag computation list
        self.drag_list = define_output.DefineDragList()
        self.drag_file_output_list = []
        for it in self.drag_list:
            f = open(it[1], 'w')
            self.drag_file_output_list.append(f)
            tmp = "#Drag for group " + it[1] + "\n"
            f.write(tmp)
            tmp = "time RX RY RZ"
            f.write(tmp)
            f.flush()

        Say(self.drag_file_output_list)
示例#5
0
    def LoadFluid(self, fluid_time):
        Say('\nLoading fluid from hdf5 file...')
        # getting time indices and weights (identifying the two fluid time steps surrounding the current DEM step and assigning correspnding weights)
        time_index_past, alpha_past, time_index_future, alpha_future = self.GetTimeIndicesAndWeights(fluid_time)
        future_step_dataset_name = self.GetDatasetName(time_index_future)
        must_load_from_database = self.time_index_past != time_index_past or self.time_index_future != time_index_future# old and future time steps must be updated

        if must_load_from_database: # the current time is not between the two already loaded time steps
            # the old future becomes the new past
            self.data_array_past, self.data_array_future = self.data_array_future, self.data_array_past

        index = Index()
        self.UpdateFluidVariable(future_step_dataset_name + '/vx', Kratos.VELOCITY_X, next(index), must_load_from_database, alpha_past, alpha_future)
        self.UpdateFluidVariable(future_step_dataset_name + '/vy', Kratos.VELOCITY_Y, next(index), must_load_from_database, alpha_past, alpha_future)
        self.UpdateFluidVariable(future_step_dataset_name + '/vz', Kratos.VELOCITY_Z, next(index), must_load_from_database, alpha_past, alpha_future)

        if self.store_pressure:
            self.UpdateFluidVariable(future_step_dataset_name + '/p', Kratos.PRESSURE, next(index), must_load_from_database, alpha_past, alpha_future)

        if self.load_derivatives:
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxx', Kratos.VELOCITY_X_GRADIENT_X, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxy', Kratos.VELOCITY_X_GRADIENT_Y, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxz', Kratos.VELOCITY_X_GRADIENT_Z, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyx', Kratos.VELOCITY_Y_GRADIENT_X, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyy', Kratos.VELOCITY_Y_GRADIENT_Y, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyz', Kratos.VELOCITY_Y_GRADIENT_Z, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzx', Kratos.VELOCITY_Z_GRADIENT_X, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzy', Kratos.VELOCITY_Z_GRADIENT_Y, next(index), must_load_from_database, alpha_past, alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzz', Kratos.VELOCITY_Z_GRADIENT_Z, next(index), must_load_from_database, alpha_past, alpha_future)

        if self.time_index_past == - 1: # it is the first upload
            self.data_array_past[:] = self.data_array_future[:]

        self.time_index_past = time_index_past
        self.time_index_future = time_index_future

        Say('Finished loading fluid from hdf5 file.\n')
示例#6
0
    def SayStartMessage(self):
        message_start = '\n' + '=' * self.print_line_length
        message_start += '\n\nRunning simulation number ' + str(
            self.simulation_id)
        if self.n_simulations:
            message_start += ' out of ' + str(self.n_simulations) + '...\n'
        else:
            message_start += '...\n'

        if self.identification_text:
            message_start += self.identification_text

        message_start += '_' * self.print_line_length + '\n'

        Say(message_start)
示例#7
0
 def TellFinalSummary(self, time, step, DEM_step):
     Say('*************************************************************')
     Say('CALCULATIONS FINISHED. THE SIMULATION ENDED SUCCESSFULLY.')
     simulation_elapsed_time = self.timer.time(
     ) - self.simulation_start_time
     Say('Elapsed time: ' + '%.5f' % (simulation_elapsed_time) + ' s ')
     Say('per fluid time step: ' + '%.5f' %
         (simulation_elapsed_time / step) + ' s ')
     Say('per DEM time step: ' + '%.5f' %
         (simulation_elapsed_time / DEM_step) + ' s ')
     Say('*************************************************************\n')
示例#8
0
    def TellFinalSummary(self, time, step, DEM_step):
        simulation_elapsed_time = self.timer.time() - self.simulation_start_time
        if simulation_elapsed_time and step and DEM_step:
            elapsed_time_per_unit_fluid_step = simulation_elapsed_time / step
            elapsed_time_per_unit_DEM_step = simulation_elapsed_time / DEM_step
        else:
            elapsed_time_per_unit_fluid_step = 0.0
            elapsed_time_per_unit_DEM_step = 0.0
        Say('*************************************************************')
        Say('CALCULATIONS FINISHED. THE SIMULATION ENDED SUCCESSFULLY.')

        Say('Elapsed time: ' + '%.5f'%(simulation_elapsed_time) + ' s ')
        Say('per fluid time step: ' + '%.5f'%(elapsed_time_per_unit_fluid_step) + ' s ')
        Say('per DEM time step: ' + '%.5f'%(elapsed_time_per_unit_DEM_step) + ' s ')
        Say('*************************************************************\n')
示例#9
0
    def RunCase(self, parameters, simulation_id, identification_text=''):
        self.simulation_id = simulation_id
        self.identification_text = identification_text

        self.SayStartMessage()

        try:
            with script.Solution(self.algorithm, parameters) as test:
                test.Run()
            error = None
            message_start = 'Successfully finished running simulation number ' + str(
                simulation_id)
            self.FinishAndSayEndMessage(message_start)
        except Exception:
            error = sys.exc_info()
            message_start = 'Finished running simulation number ' + str(
                simulation_id)
            self.FinishAndSayEndMessage(message_start)
            Say('The simulation crashed.')

        os.chdir(self.main_path)

        return error
示例#10
0
    def LoadFluid(self, DEM_time):
        Say('\nLoading fluid from hdf5 file...')
        # getting time indices and weights (identifyint the two fluid time steps surrounding the current DEM step and assigning correspnding weights)
        old_time_index, alpha_old, future_time_index, alpha_future = self.GetOldTimeIndicesAndWeights(
            DEM_time, self.times, self.dt)
        old_step_dataset_name = self.times_str[old_time_index]
        future_step_dataset_name = self.times_str[future_time_index]
        must_load_from_database = not self.old_time_index == old_time_index  # old and future time steps must be updated

        if must_load_from_database:
            # new old becomes old future
            self.old_data_array, self.future_data_array = self.future_data_array, self.old_data_array

        indices = Index()
        self.UpdateFluidVariable(future_step_dataset_name + '/vx', VELOCITY_X,
                                 next(indices), must_load_from_database,
                                 alpha_old, alpha_future)
        self.UpdateFluidVariable(future_step_dataset_name + '/vy', VELOCITY_Y,
                                 next(indices), must_load_from_database,
                                 alpha_old, alpha_future)
        self.UpdateFluidVariable(future_step_dataset_name + '/vz', VELOCITY_Z,
                                 next(indices), must_load_from_database,
                                 alpha_old, alpha_future)

        if self.store_pressure:
            self.UpdateFluidVariable(future_step_dataset_name + '/p', PRESSURE,
                                     next(indices), must_load_from_database,
                                     alpha_old, alpha_future)

        if self.load_derivatives:
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxx',
                                     VELOCITY_X_GRADIENT_X, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxy',
                                     VELOCITY_X_GRADIENT_Y, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvxz',
                                     VELOCITY_X_GRADIENT_Z, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyx',
                                     VELOCITY_Y_GRADIENT_X, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyy',
                                     VELOCITY_Y_GRADIENT_Y, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvyz',
                                     VELOCITY_Y_GRADIENT_Z, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzx',
                                     VELOCITY_Z_GRADIENT_X, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzy',
                                     VELOCITY_Z_GRADIENT_Y, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
            self.UpdateFluidVariable(future_step_dataset_name + '/dvzz',
                                     VELOCITY_Z_GRADIENT_Z, next(indices),
                                     must_load_from_database, alpha_old,
                                     alpha_future)
        Say('Finished loading fluid from hdf5 file.\n')
示例#11
0
 def TellTime(self, time):
     Say('\nTIME = ', time)
     Say('ELAPSED TIME = ',
         self.timer.time() - self.simulation_start_time, '\n')
示例#12
0
 def AssessStationarity(self):
     Say("Assessing Stationarity...\n")
     self.stationarity = self.stationarity_tool.Assess(
         self.fluid_model_part)
     self.stationarity_counter.Deactivate(self.stationarity)
示例#13
0
    def RunMainTemporalLoop(self):
        coupling_level_type = self.pp.CFD_DEM["coupling_level_type"].GetInt()
        project_at_every_substep_option = self.pp.CFD_DEM[
            "project_at_every_substep_option"].GetBool()
        coupling_scheme_type = self.pp.CFD_DEM[
            "coupling_scheme_type"].GetString()
        integration_scheme = self.pp.CFD_DEM[
            "TranslationalIntegrationScheme"].GetString()
        dem_inlet_option = self.pp.CFD_DEM["dem_inlet_option"].GetBool()
        interaction_start_time = self.pp.CFD_DEM[
            "interaction_start_time"].GetDouble()

        while self.TheSimulationMustGoOn():

            self.time = self.time + self.Dt
            self.step += 1
            self.CloneTimeStep()
            self.TellTime(self.time)

            if coupling_scheme_type == "UpdatedDEM":
                time_final_DEM_substepping = self.time + self.Dt

            else:
                time_final_DEM_substepping = self.time

            #self.PerformEmbeddedOperations() TO-DO: it's crashing

            self.UpdateALEMeshMovement(self.time)

            # solving the fluid part
            if self.step >= self.GetFirstStepForFluidComputation():
                self.FluidSolve(self.time,
                                solve_system=self.fluid_solve_counter.Tick()
                                and not self.stationarity)

                # assessing stationarity
                if self.stationarity_counter.Tick():
                    self.AssessStationarity()

            # printing if required

            if self.particles_results_counter.Tick():
                self.io_tools.PrintParticlesResults(
                    self.pp.variables_to_print_in_file, self.time,
                    self.spheres_model_part)

                self.PrintDrag(self.drag_list, self.drag_file_output_list,
                               self.fluid_model_part, self.time)

            if self.print_counter_updated_DEM.Tick():

                if coupling_level_type:
                    self.projection_module.ComputePostProcessResults(
                        self.spheres_model_part.ProcessInfo)

                self.post_utils.Writeresults(self.time_dem)

            # solving the DEM part

            self.derivative_recovery_counter.Activate(
                self.time > interaction_start_time)

            if self.derivative_recovery_counter.Tick():
                self.RecoverDerivatives()

            Say('Solving DEM... (',
                self.spheres_model_part.NumberOfElements(0), 'elements )')
            first_dem_iter = True

            for self.time_dem in self.yield_DEM_time(
                    self.time_dem, time_final_DEM_substepping, self.Dt_DEM):
                self.DEM_step += 1
                self.spheres_model_part.ProcessInfo[TIME_STEPS] = self.DEM_step
                self.rigid_face_model_part.ProcessInfo[
                    TIME_STEPS] = self.DEM_step
                self.cluster_model_part.ProcessInfo[TIME_STEPS] = self.DEM_step

                self.PerformInitialDEMStepOperations(self.time_dem)

                it_is_time_to_forward_couple = (
                    self.time >= interaction_start_time and coupling_level_type
                    and (project_at_every_substep_option or first_dem_iter))

                if it_is_time_to_forward_couple:

                    if coupling_scheme_type == "UpdatedDEM":
                        self.ApplyForwardCoupling()

                    else:
                        alpha = 1.0 - (time_final_DEM_substepping -
                                       self.time_dem) / self.Dt
                        self.ApplyForwardCoupling(alpha)

                        if self.quadrature_counter.Tick():
                            self.AppendValuesForTheHistoryForce()

                        if integration_scheme in {
                                'Hybrid_Bashforth', 'TerminalVelocityScheme'
                        }:
                            # Advance in space only
                            self.DEMSolve(self.time_dem)
                            self.ApplyForwardCouplingOfVelocityToSlipVelocityOnly(
                                self.time_dem)

                # performing the time integration of the DEM part

                self.spheres_model_part.ProcessInfo[TIME] = self.time_dem
                self.rigid_face_model_part.ProcessInfo[TIME] = self.time_dem
                self.cluster_model_part.ProcessInfo[TIME] = self.time_dem

                if self.do_solve_dem:
                    self.DEMSolve(self.time_dem)

                self.disperse_phase_solution.DEMFEMProcedures.MoveAllMeshes(
                    self.all_model_parts, self.time_dem, self.Dt_DEM)

                #### TIME CONTROL ##################################

                # adding DEM elements by the inlet:
                if dem_inlet_option:
                    # After solving, to make sure that neighbours are already set.
                    self.disperse_phase_solution.DEM_inlet.CreateElementsFromInletMesh(
                        self.spheres_model_part, self.cluster_model_part,
                        self.disperse_phase_solution.creator_destructor)

                if self.print_counter_updated_fluid.Tick():

                    if coupling_level_type:
                        self.projection_module.ComputePostProcessResults(
                            self.spheres_model_part.ProcessInfo)

                    self.post_utils.Writeresults(self.time_dem)

                first_dem_iter = False

                # applying DEM-to-fluid coupling

                if self.DEM_to_fluid_counter.Tick(
                ) and self.time >= interaction_start_time:
                    self.projection_module.ProjectFromParticles()

            #### PRINTING GRAPHS ####
            os.chdir(self.graphs_path)
            # measuring mean velocities in a certain control volume (the 'velocity trap')
            if self.pp.CFD_DEM["VelocityTrapOption"].GetBool():
                self.post_utils_DEM.ComputeMeanVelocitiesinTrap(
                    "Average_Velocity.txt", self.time)

            os.chdir(self.post_path)

            # coupling checks (debugging)
            if self.debug_info_counter.Tick():
                self.dem_volume_tool.UpdateDataAndPrint(
                    self.pp.CFD_DEM["fluid_domain_volume"].GetDouble())

            # printing if required

            if self.particles_results_counter.Tick():
                self.io_tools.PrintParticlesResults(
                    self.pp.variables_to_print_in_file, self.time,
                    self.spheres_model_part)

                self.PrintDrag(self.drag_list, self.drag_file_output_list,
                               self.fluid_model_part, self.time)
示例#14
0
    def Initialize(self):
        Say('\nInitializing 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.problem_name,
            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()

        # 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.n_particles_in_depth = 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 = 20 * biggest_size

            elif self.spheres_model_part.NumberOfElements(0) == 0:
                self.pp.CFD_DEM.meso_scale_length = 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()
        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.perform_analytics_option = False

        if self.pp.CFD_DEM.perform_analytics_option:
            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)
示例#15
0
    import define_output  # MA: some GUI write this file, some others not!
except ImportError:
    pass

# Import MPI modules if needed. This way to do this is only valid when using OpenMPI.
# For other implementations of MPI it will not work.
if "OMPI_COMM_WORLD_SIZE" in os.environ:
    # Kratos MPI
    from KratosMultiphysics.MetisApplication import *
    from KratosMultiphysics.MPISearchApplication import *
    from KratosMultiphysics.mpi import *

    # DEM Application MPI
    import DEM_procedures_mpi as DEM_procedures
    import DEM_material_test_script_mpi as DEM_material_test_script
    Say('Running under MPI...........\n')
else:
    # DEM Application
    import DEM_procedures
    import DEM_material_test_script
    Say('Running under OpenMP........\n')

sys.path.insert(0, '')


class Logger(object):
    def __init__(self):
        self.terminal = sys.stdout
        self.console_output_file_name = 'console_output.txt'
        self.path_to_console_out_file = os.getcwd()
        self.path_to_console_out_file += '/' + self.console_output_file_name
示例#16
0
                simulation_id += 1
                varying_parameters[
                    'material_acceleration_calculation_type'] = derivatives_type
                varying_parameters[
                    'laplacian_calculation_type'] = derivatives_type
                parameters = Parameters(json.dumps(varying_parameters))
                identification_text = 'mesh size: ' + str(
                    size) + '\nrecovery type: ' + str(derivatives_type) + '\n'
                error = runner.RunCase(parameters,
                                       simulation_id,
                                       identification_text=identification_text)
                if error:
                    errors.append(error)
                    combinations_that_failed.append({
                        'size': size,
                        'type': derivatives_type
                    })
Say()
Say('****************************************')

if combinations_that_failed:
    Say('The following combinations produced an error:')
    Say('combinations_that_failed', combinations_that_failed)
    for combination, error in zip(combinations_that_failed, errors):
        Say(combination)
        Say(error[1:2])
        Say(traceback.print_tb(error[2]))
else:
    Say('All combinations run without errors')
Say('****************************************')
示例#17
0
    def SetBetaParameters(
        self
    ):  # These are input parameters that have not yet been transferred to the interface
        # import the configuration data as read from the GiD
        ##############################################################################
        #                                                                            #
        #    INITIALIZE                                                              #
        #                                                                            #
        ##############################################################################

        #G
        self.pp.CFD_DEM.AddEmptyValue("do_solve_dem").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue("fluid_already_calculated").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue("recovery_echo_level").SetInt(1)
        self.pp.CFD_DEM.AddEmptyValue("gradient_calculation_type").SetInt(1)
        self.pp.CFD_DEM.AddEmptyValue("pressure_grad_recovery_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("fluid_fraction_grad_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("store_full_gradient_option").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue("store_fluid_pressure_option").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue("laplacian_calculation_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("do_search_neighbours").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue("faxen_terms_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue(
            "material_acceleration_calculation_type").SetInt(1)
        self.pp.CFD_DEM.AddEmptyValue("faxen_force_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("vorticity_calculation_type").SetInt(5)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_FLUID_VEL_PROJECTED_RATE_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_MATERIAL_FLUID_ACCEL_PROJECTED_option").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue("basset_force_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("print_BASSET_FORCE_option").SetBool(
            True)
        self.pp.CFD_DEM.AddEmptyValue("basset_force_integration_type").SetInt(
            2)
        self.pp.CFD_DEM.AddEmptyValue("n_init_basset_steps").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("time_steps_per_quadrature_step").SetInt(
            1)
        self.pp.CFD_DEM.AddEmptyValue("delta_time_quadrature").SetDouble(
            self.pp.CFD_DEM["time_steps_per_quadrature_step"].GetInt() *
            self.pp.CFD_DEM["MaxTimeStep"].GetDouble())
        self.pp.CFD_DEM.AddEmptyValue("quadrature_order").SetInt(2)
        self.pp.CFD_DEM.AddEmptyValue("time_window").SetDouble(0.8)
        self.pp.CFD_DEM.AddEmptyValue("number_of_exponentials").SetInt(2)
        self.pp.CFD_DEM.AddEmptyValue(
            "number_of_quadrature_steps_in_window").SetInt(
                int(self.pp.CFD_DEM["time_window"].GetDouble() /
                    self.pp.CFD_DEM["delta_time_quadrature"].GetDouble()))
        self.pp.CFD_DEM.AddEmptyValue(
            "do_impose_flow_from_field_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_MATERIAL_ACCELERATION_option").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_FLUID_ACCEL_FOLLOWING_PARTICLE_PROJECTED_option").SetBool(
                False)
        self.pp.CFD_DEM.AddEmptyValue("print_VORTICITY_option").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_MATERIAL_ACCELERATION_option").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_VELOCITY_GRADIENT_option").SetBool(True)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_DISPERSE_FRACTION_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_FLUID_FRACTION_GRADIENT_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "print_FLUID_FRACTION_GRADIENT_PROJECTED_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue("calculate_diffusivity_option").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue("print_CONDUCTIVITY_option").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue("filter_velocity_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue("print_PARTICLE_VEL_option").SetBool(
            False)
        self.pp.CFD_DEM.AddEmptyValue(
            "apply_time_filter_to_fluid_fraction_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "full_particle_history_watcher").SetString("Empty")
        self.pp.CFD_DEM.AddEmptyValue("prerun_fluid_file_name").SetString("")
        self.pp.CFD_DEM.AddEmptyValue("frame_of_reference_type").SetInt(0)
        self.pp.CFD_DEM.AddEmptyValue("angular_velocity_of_frame_X").SetDouble(
            0.0)
        self.pp.CFD_DEM.AddEmptyValue("angular_velocity_of_frame_Y").SetDouble(
            0.0)
        self.pp.CFD_DEM.AddEmptyValue("angular_velocity_of_frame_Z").SetDouble(
            0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_velocity_of_frame_old_X").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_velocity_of_frame_old_Y").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_velocity_of_frame_old_Z").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "acceleration_of_frame_origin_X").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "acceleration_of_frame_origin_Y").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "acceleration_of_frame_origin_Z").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_acceleration_of_frame_X").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_acceleration_of_frame_Y").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue(
            "angular_acceleration_of_frame_Z").SetDouble(0.0)
        self.pp.CFD_DEM.AddEmptyValue("ALE_option").SetBool(False)
        self.pp.CFD_DEM.AddEmptyValue(
            "frame_rotation_axis_initial_point").SetVector(Vector([0., 0.,
                                                                   0.]))
        self.pp.CFD_DEM.AddEmptyValue(
            "frame_rotation_axis_final_point").SetVector(Vector([0., 0., 1.]))
        self.pp.CFD_DEM.AddEmptyValue("angular_velocity_magnitude").SetDouble(
            1.0)
        self.pp.CFD_DEM.print_DISPERSE_FRACTION_option = False
        self.pp.CFD_DEM.print_steps_per_plot_step = 1
        self.pp.CFD_DEM.PostCationConcentration = False
        # Making the fluid step an exact multiple of the DEM step
        self.pp.Dt = int(self.pp.Dt / self.pp.CFD_DEM["MaxTimeStep"].GetDouble(
        )) * self.pp.CFD_DEM["MaxTimeStep"].GetDouble()
        self.output_time = int(self.pp.CFD_DEM["OutputTimeStep"].GetDouble() /
                               self.pp.CFD_DEM["MaxTimeStep"].GetDouble()
                               ) * self.pp.CFD_DEM["MaxTimeStep"].GetDouble()
        Say('Dt_DEM', self.pp.CFD_DEM["MaxTimeStep"].GetDouble())
        Say('self.pp.Dt', self.pp.Dt)
        Say('self.output_time', self.output_time)
        self.pp.viscosity_modification_type = 0.0
        self.domain_size = 3
        self.pp.type_of_inlet = 'VelocityImposed'  # 'VelocityImposed' or 'ForceImposed'
        self.pp.force = Vector(3)
        self.pp.force[0] = 0
        self.pp.force[1] = 0
        self.pp.force[2] = 1e-10

        # defining and adding imposed porosity fields
        self.pp.fluid_fraction_fields = []
        field1 = SDP.FluidFractionFieldUtility.LinearField(
            0.0, [0.0, 0.0, 0.0], [-1.0, -1.0, 0.15], [1.0, 1.0, 0.3])
        from math import pi
        self.pp.CFD_DEM.AddEmptyValue("fluid_domain_volume").SetDouble(
            0.5**2 * 2 * pi)  # write down the volume you know it has

        self.pp.fluid_fraction_fields.append(field1)
示例#18
0
    def RunMainTemporalLoop(self):

        while self.TheSimulationMustGoON():

            self.time = self.time + self.Dt
            self.step += 1
            self.TransferTimeToFluidSolver()
            self.CloneTimeStep()
            self.TellTime(self.time)

            if self.pp.CFD_DEM["coupling_scheme_type"].GetString(
            ) == "UpdatedDEM":
                time_final_DEM_substepping = self.time + self.Dt

            else:
                time_final_DEM_substepping = self.time

            #self.PerformEmbeddedOperations() #TODO: it's crashing

            # solving the fluid part

            if self.step >= self.GetFirstStepForFluidComputation():
                self.FluidSolve(self.time,
                                solve_system=self.fluid_solve_counter.Tick()
                                and not self.stationarity)

                # assessing stationarity

                if self.stationarity_counter.Tick():
                    Say("Assessing Stationarity...\n")
                    self.stationarity = self.stationarity_tool.Assess(
                        self.fluid_model_part)
                    self.stationarity_counter.Deactivate(self.stationarity)

            # printing if required

            if self.particles_results_counter.Tick():
                # eliminating remote balls

                #if self.pp.dem.BoundingBoxOption == "ON":
                #    self.creator_destructor.DestroyParticlesOutsideBoundingBox(self.disperse_phase_algorithm.spheres_model_part)

                self.io_tools.PrintParticlesResults(
                    self.pp.variables_to_print_in_file, self.time,
                    self.disperse_phase_algorithm.spheres_model_part)
                #self.graph_printer.PrintGraphs(self.time) #MA: commented out because the constructor was already commented out
                self.PrintDrag(self.drag_list, self.drag_file_output_list,
                               self.fluid_model_part, self.time)

            if self.output_time <= self.out and self.pp.CFD_DEM[
                    "coupling_scheme_type"].GetString() == "UpdatedDEM":

                if self.pp.CFD_DEM["coupling_level_type"].GetInt() > 0:
                    self.projection_module.ComputePostProcessResults(
                        self.disperse_phase_algorithm.spheres_model_part.
                        ProcessInfo)

                self.post_utils.Writeresults(self.time)
                self.out = 0

            # solving the DEM part
            self.derivative_recovery_counter.Activate(
                self.time >
                self.pp.CFD_DEM["interaction_start_time"].GetDouble())

            if self.derivative_recovery_counter.Tick():
                self.recovery.Recover()

            Say(
                'Solving DEM... (',
                self.disperse_phase_algorithm.spheres_model_part.
                NumberOfElements(0), 'elements )')
            first_dem_iter = True

            interaction_start_time = self.pp.CFD_DEM[
                "interaction_start_time"].GetDouble()
            coupling_level_type = self.pp.CFD_DEM[
                "coupling_level_type"].GetInt()
            project_at_every_substep_option = self.pp.CFD_DEM[
                "project_at_every_substep_option"].GetBool()
            coupling_scheme_type = self.pp.CFD_DEM[
                "coupling_scheme_type"].GetString()
            integration_scheme = self.pp.CFD_DEM[
                "IntegrationScheme"].GetString()
            basset_force_type = self.pp.CFD_DEM["basset_force_type"].GetInt()
            dem_inlet_option = self.pp.CFD_DEM["dem_inlet_option"].GetBool()

            for self.time_dem in self.yield_DEM_time(
                    self.time_dem, time_final_DEM_substepping, self.Dt_DEM):
                self.DEM_step += 1  # this variable is necessary to get a good random insertion of particles
                self.disperse_phase_algorithm.spheres_model_part.ProcessInfo[
                    TIME_STEPS] = self.DEM_step
                self.disperse_phase_algorithm.rigid_face_model_part.ProcessInfo[
                    TIME_STEPS] = self.DEM_step
                self.disperse_phase_algorithm.cluster_model_part.ProcessInfo[
                    TIME_STEPS] = self.DEM_step

                self.PerformInitialDEMStepOperations(self.time_dem)

                if self.time >= interaction_start_time and coupling_level_type and (
                        project_at_every_substep_option or first_dem_iter):

                    if coupling_scheme_type == "UpdatedDEM":
                        self.ApplyForwardCoupling()

                    else:
                        self.ApplyForwardCoupling(
                            (time_final_DEM_substepping - self.time_dem) /
                            self.Dt)

                        if integration_scheme in {
                                'Hybrid_Bashforth', 'TerminalVelocityScheme'
                        }:
                            self.DEMSolve(self.time_dem)
                            self.ApplyForwardCouplingOfVelocityOnly(
                                self.time_dem)
                        else:
                            if basset_force_type > 0:
                                node.SetSolutionStepValue(SLIP_VELOCITY_X, vx)
                                node.SetSolutionStepValue(SLIP_VELOCITY_Y, vy)

                        if self.quadrature_counter.Tick():
                            self.AppendValuesForTheHistoryForce()

                # performing the time integration of the DEM part

                self.disperse_phase_algorithm.spheres_model_part.ProcessInfo[
                    TIME] = self.time_dem
                self.disperse_phase_algorithm.rigid_face_model_part.ProcessInfo[
                    TIME] = self.time_dem
                self.disperse_phase_algorithm.cluster_model_part.ProcessInfo[
                    TIME] = self.time_dem

                if self.pp.do_solve_dem:
                    self.DEMSolve(self.time_dem)

                self.disperse_phase_algorithm.DEMFEMProcedures.MoveAllMeshes(
                    self.all_model_parts, self.time_dem, self.Dt_DEM)

                #### TIME CONTROL ##################################

                # adding DEM elements by the inlet:
                if dem_inlet_option:
                    self.disperse_phase_algorithm.DEM_inlet.CreateElementsFromInletMesh(
                        self.disperse_phase_algorithm.spheres_model_part,
                        self.disperse_phase_algorithm.cluster_model_part,
                        self.disperse_phase_algorithm.creator_destructor
                    )  # After solving, to make sure that neighbours are already set.

                if self.output_time <= self.out and coupling_scheme_type == "UpdatedFluid":

                    if coupling_level_type:
                        self.projection_module.ComputePostProcessResults(
                            self.disperse_phase_algorithm.spheres_model_part.
                            ProcessInfo)

                    self.post_utils.Writeresults(self.time_dem)
                    self.out = 0

                self.out = self.out + self.Dt_DEM
                first_dem_iter = False

                # applying DEM-to-fluid coupling

                if self.DEM_to_fluid_counter.Tick(
                ) and self.time >= interaction_start_time:
                    self.projection_module.ProjectFromParticles()

            #### PRINTING GRAPHS ####
            os.chdir(self.graphs_path)
            # measuring mean velocities in a certain control volume (the 'velocity trap')
            if self.pp.CFD_DEM["VelocityTrapOption"].GetBool():
                self.post_utils_DEM.ComputeMeanVelocitiesinTrap(
                    "Average_Velocity.txt", self.time)

            os.chdir(self.post_path)

            # coupling checks (debugging)
            if self.debug_info_counter.Tick():
                self.dem_volume_tool.UpdateDataAndPrint(
                    self.pp.CFD_DEM["fluid_domain_volume"].GetDouble())

            # printing if required

            if self.particles_results_counter.Tick():
                self.io_tools.PrintParticlesResults(
                    self.pp.variables_to_print_in_file, self.time,
                    self.disperse_phase_algorithm.spheres_model_part)
                #self.graph_printer.PrintGraphs(self.time) #MA: commented out because the constructor was already commented out
                self.PrintDrag(self.drag_list, self.drag_file_output_list,
                               self.fluid_model_part, self.time)