def _set_level_set_convection_process(self): # Construct the level set convection process if self._bfecc_convection: if have_conv_diff: if self.main_model_part.ProcessInfo[ KratosMultiphysics.DOMAIN_SIZE] == 2: locator = KratosMultiphysics.BinBasedFastPointLocator2D( self.main_model_part).UpdateSearchDatabase() level_set_convection_process = KratosConvDiff.BFECCConvection2D( locator) else: locator = KratosMultiphysics.BinBasedFastPointLocator3D( self.main_model_part).UpdateSearchDatabase() level_set_convection_process = KratosConvDiff.BFECCConvection3D( locator) else: raise Exception( "The BFECC level set convection requires the Kratos ConvectionDiffusionApplication compilation." ) else: if self.main_model_part.ProcessInfo[ KratosMultiphysics.DOMAIN_SIZE] == 2: level_set_convection_process = KratosMultiphysics.LevelSetConvectionProcess2D( KratosMultiphysics.DISTANCE, self.main_model_part, self.linear_solver) else: level_set_convection_process = KratosMultiphysics.LevelSetConvectionProcess3D( KratosMultiphysics.DISTANCE, self.main_model_part, self.linear_solver) return level_set_convection_process
def ExecuteBeforeSolutionLoop(self): dimension = self.model_part.ProcessInfo[KM.DOMAIN_SIZE] num_of_avg_elems = 10 num_of_avg_nodes = 10 neighbor_search = KM.FindNodalNeighboursProcess(self.model_part) neighbor_search.Execute() neighbor_elements_search = KM.FindElementalNeighboursProcess( self.model_part, dimension, num_of_avg_elems) neighbor_elements_search.Execute() settings = self.model_part.ProcessInfo[ KM.CONVECTION_DIFFUSION_SETTINGS] self.unknown_var = settings.GetUnknownVariable() self.projection_var = settings.GetProjectionVariable() self.velocity_var = settings.GetVelocityVariable() self.mesh_velocity_var = settings.GetMeshVelocityVariable() max_num_of_particles = 8 * dimension if dimension == 2: self.moveparticles = CDA.MoveParticleUtilityScalarTransport2D( self.model_part, max_num_of_particles) else: self.moveparticles = CDA.MoveParticleUtilityScalarTransport3D( self.model_part, max_num_of_particles) self.moveparticles.MountBin()
def _CreateLevelSetConvectionProcess(self): # Construct the level set convection process domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] computing_model_part = self.GetComputingModelPart() if self._bfecc_convection: if have_conv_diff: if domain_size == 2: locator = KratosMultiphysics.BinBasedFastPointLocator2D(computing_model_part) locator.UpdateSearchDatabase() level_set_convection_process = KratosConvDiff.BFECCConvection2D(locator) else: locator = KratosMultiphysics.BinBasedFastPointLocator3D(computing_model_part) locator.UpdateSearchDatabase() level_set_convection_process = KratosConvDiff.BFECCConvection3D(locator) else: raise Exception("The BFECC level set convection requires the Kratos ConvectionDiffusionApplication compilation.") else: linear_solver = self._GetLinearSolver() if domain_size == 2: level_set_convection_process = KratosMultiphysics.LevelSetConvectionProcess2D( KratosMultiphysics.DISTANCE, computing_model_part, linear_solver) else: level_set_convection_process = KratosMultiphysics.LevelSetConvectionProcess3D( KratosMultiphysics.DISTANCE, computing_model_part, linear_solver) return level_set_convection_process
def _CreateBFECCConvection(self): # Create the locator for the BFECC convector domain_size = self.GetComputingModelPart().ProcessInfo[ KratosMultiphysics.DOMAIN_SIZE] if domain_size == 2: point_locator = KratosMultiphysics.BinBasedFastPointLocator2D( self.GetComputingModelPart()) elif domain_size == 3: point_locator = KratosMultiphysics.BinBasedFastPointLocator3D( self.GetComputingModelPart()) else: err_msg = "Wrong domain size: {0}".format(domain_size) raise Exception(err_msg) # Initialize the locator search database point_locator.UpdateSearchDatabase() # Create the BFECC convection utility if domain_size == 2: bfecc_utility = ConvectionDiffusionApplication.BFECCConvection2D( point_locator) else: bfecc_utility = ConvectionDiffusionApplication.BFECCConvection3D( point_locator) return bfecc_utility
def _create_runge_kutta_4_strategy(self): computing_model_part = self.GetComputingModelPart() explicit_builder_and_solver = self.get_builder_and_solver() rebuild_level = 0 return ConvectionDiffusionApplication.ExplicitSolvingStrategyRungeKutta4ConvectionDiffusion( computing_model_part, explicit_builder_and_solver, self.settings["move_mesh_flag"].GetBool(), rebuild_level, )
def Initialize(self): if self.settings["response_function_settings"][ "response_type"].GetString() == "point_temperature": self.response_function = convdiff.LocalTemperatureAverageResponseFunction( self.settings["response_function_settings"]["custom_settings"], self.model_part) else: raise Exception("invalid response_type: " + self.settings["response_function_settings"] ["response_type"].GetString()) self.sensitivity_builder = kratos.SensitivityBuilder( self.settings["sensitivity_settings"], self.model_part, self.response_function) import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory self.linear_solver = linear_solver_factory.ConstructSolver( self.settings["linear_solver_settings"]) self.time_scheme = kratos.ResidualBasedAdjointStaticScheme( self.response_function) builder_and_solver = kratos.ResidualBasedBlockBuilderAndSolver( self.linear_solver) self.solver = kratos.ResidualBasedLinearStrategy( self.model_part, self.time_scheme, builder_and_solver, False, False, False, False) self.solver.SetEchoLevel(self.settings["echo_level"].GetInt()) self.solver.Initialize() self.response_function.Initialize() self.sensitivity_builder.Initialize() kratos.Logger.PrintInfo(self.__class__.__name__, "Solver initialization finished.")
def runTest(self): with UnitTest.WorkFolderScope(self.work_folder, __file__): # Create the test model part self.model = KratosMultiphysics.Model() self.main_model_part = self.model.CreateModelPart("MainModelPart") self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VELOCITY) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.TEMPERATURE) # Generate the problem domain problem_domain = KratosMultiphysics.Quadrilateral2D4( KratosMultiphysics.Node(1, 0.0, 0.0, 0.0), KratosMultiphysics.Node(2, 0.0, 1.0, 0.0), KratosMultiphysics.Node(3, 1.0, 1.0, 0.0), KratosMultiphysics.Node(4, 1.0, 0.0, 0.0)) mesh_parameters = KratosMultiphysics.Parameters("{}") mesh_parameters.AddEmptyValue("element_name").SetString("Element2D3N") mesh_parameters.AddEmptyValue("condition_name").SetString("LineCondition2D2N") mesh_parameters.AddEmptyValue("create_skin_sub_model_part").SetBool(False) mesh_parameters.AddEmptyValue("number_of_divisions").SetInt(self.mesh_divisions) KratosMultiphysics.StructuredMeshGeneratorProcess(problem_domain, self.main_model_part, mesh_parameters).Execute() # Set buffer size self.main_model_part.SetBufferSize(2) # Set the convection velocity and the initial temperature fields x_c = 0.2 y_c = 0.2 for node in self.main_model_part.Nodes: x_local = node.X - 0.5 y_local = node.Y - 0.5 r = math.sqrt(x_local**2 + y_local**2) if(r < 0.45): aux_temp = math.sqrt((x_local - x_c)**2 + (y_local - y_c)**2) - 0.1 node.SetSolutionStepValue(KratosMultiphysics.TEMPERATURE, 0, aux_temp) node.SetSolutionStepValue(KratosMultiphysics.VELOCITY, 0, [-y_local, x_local, 0.0]) # If the limiter is used, set some initial overshoots # if self.has_limiter: # if aux_temp <= 0.0: # node.SetSolutionStepValue(KratosMultiphysics.TEMPERATURE, 0, 1.0) # else: # node.SetSolutionStepValue(KratosMultiphysics.TEMPERATURE, 0, 0.0) # Create the search structure locator = KratosMultiphysics.BinBasedFastPointLocator2D(self.main_model_part) locator.UpdateSearchDatabase() # Construct the BFECC utility if self.has_limiter: bfecc_utility = ConvectionDiffusionApplication.BFECCConvection2D(locator) else: bfecc_utility = ConvectionDiffusionApplication.BFECCLimiterConvection2D(locator) self.main_model_part.CloneTimeStep(0.0) # Set output if (self.print_output): gid_mode = KratosMultiphysics.GiDPostMode.GiD_PostBinary multifile = KratosMultiphysics.MultiFileFlag.SingleFile deformed_mesh_flag = KratosMultiphysics.WriteDeformedMeshFlag.WriteUndeformed write_conditions = KratosMultiphysics.WriteConditionsFlag.WriteElementsOnly gid_io = KratosMultiphysics.GidIO(self.reference_file, gid_mode, multifile, deformed_mesh_flag, write_conditions) mesh_name = 0.0 gid_io.InitializeMesh(mesh_name) gid_io.WriteMesh(self.main_model_part.GetMesh()) gid_io.FinalizeMesh() gid_io.InitializeResults(mesh_name,(self.main_model_part).GetMesh()) # Advance in time and convect t = 0.0 while(t < self.end_time): t += self.dt self.main_model_part.CloneTimeStep(t) bfecc_utility.BFECCconvect( self.main_model_part, KratosMultiphysics.TEMPERATURE, KratosMultiphysics.VELOCITY, self.bfecc_substeps) if (self.print_output): gid_io.WriteNodalResults(KratosMultiphysics.VELOCITY, self.main_model_part.Nodes, t, 0) gid_io.WriteNodalResults(KratosMultiphysics.TEMPERATURE, self.main_model_part.Nodes, t, 0) if (self.print_output): gid_io.FinalizeResults()
def testBFECCNodalLimiterConvection(self): current_model = KratosMultiphysics.Model() model_part = current_model.CreateModelPart("Main") model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DISTANCE) model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VELOCITY) KratosMultiphysics.ModelPartIO(GetFilePath("BFECCConvectionTest/Semi1D_1x02_50")).ReadModelPart(model_part) model_part.SetBufferSize(2) model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, 2) model_part.ProcessInfo.SetValue(KratosMultiphysics.TIME, 0.0) model_part.ProcessInfo.SetValue(KratosMultiphysics.DELTA_TIME, 0.05) # Create the search structure locator = KratosMultiphysics.BinBasedFastPointLocator2D(model_part) locator.UpdateSearchDatabase() bfecc_utility = ConvectionDiffusionApplication.BFECCConvection2D( locator, False, # No partial dt (splitting) True) # Activating nodal limiter for node in model_part.Nodes: node.SetSolutionStepValue(KratosMultiphysics.DISTANCE, BaseJumpedDistance(node.X,node.Y,node.Z)) node.SetSolutionStepValue(KratosMultiphysics.VELOCITY, ConvectionVelocity(node.X,node.Y,node.Z)) node.SetSolutionStepValue(KratosMultiphysics.VELOCITY, 1, ConvectionVelocity(node.X,node.Y,node.Z)) for node in model_part.Nodes: if node.X < 0.001: node.Fix(KratosMultiphysics.DISTANCE) kratos_comm = KratosMultiphysics.DataCommunicator.GetDefault() KratosMultiphysics.FindGlobalNodalNeighboursProcess( kratos_comm, model_part).Execute() KratosMultiphysics.ComputeNonHistoricalNodalGradientProcess( model_part, KratosMultiphysics.DISTANCE, KratosMultiphysics.DISTANCE_GRADIENT, KratosMultiphysics.NODAL_AREA).Execute() for i in range(12): bfecc_utility.CopyScalarVarToPreviousTimeStep( model_part, KratosMultiphysics.DISTANCE) bfecc_utility.BFECCconvect( model_part, KratosMultiphysics.DISTANCE, KratosMultiphysics.VELOCITY, 5) # substeps dt = model_part.ProcessInfo.GetValue(KratosMultiphysics.DELTA_TIME) model_part.ProcessInfo.SetValue(KratosMultiphysics.TIME, float(i)*dt) max_distance = -1.0 min_distance = +1.0 for node in model_part.Nodes: d = node.GetSolutionStepValue(KratosMultiphysics.DISTANCE) max_distance = max(max_distance, d) min_distance = min(min_distance, d) # gid_output = GiDOutputProcess(model_part, # "BFECCConvection_test_2D", # KratosMultiphysics.Parameters(""" # { # "result_file_configuration" : { # "gidpost_flags": { # "GiDPostMode": "GiD_PostBinary", # "WriteDeformedMeshFlag": "WriteUndeformed", # "WriteConditionsFlag": "WriteConditions", # "MultiFileFlag": "SingleFile" # }, # "nodal_results" : ["DISTANCE","VELOCITY"] # } # } # """) # ) # gid_output.ExecuteInitialize() # gid_output.ExecuteBeforeSolutionLoop() # gid_output.ExecuteInitializeSolutionStep() # gid_output.PrintOutput() # gid_output.ExecuteFinalizeSolutionStep() # gid_output.ExecuteFinalize() self.assertAlmostEqual(max_distance, 1.0000000000000013) self.assertAlmostEqual(min_distance, 0.0)