Example #1
0
    def _generate_particle_element_and_check(self, current_model):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)

        dimension = 3

        # Initialize model part
        ## Material model part definition
        material_point_model_part = current_model.CreateModelPart("dummy_name")
        material_point_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        self.process_info = material_point_model_part.ProcessInfo

        ## Initial material model part definition
        initial_mesh_model_part = current_model.CreateModelPart("Initial_dummy_name")
        initial_mesh_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        # Create element and nodes
        sub_mp = initial_mesh_model_part.CreateSubModelPart("test")
        sub_mp.GetProperties()[1].SetValue(KratosParticle.PARTICLES_PER_ELEMENT, 4)
        self._create_nodes(sub_mp)
        self._create_elements(sub_mp)

        # Create background element and nodes
        background_sub_mp = grid_model_part.CreateSubModelPart("test2")
        self._create_nodes(background_sub_mp)
        self._create_elements(background_sub_mp)
        self._create_conditions(background_sub_mp)

        # Generate MP Elements and Conditions
        KratosParticle.GenerateMaterialPointElement(grid_model_part, initial_mesh_model_part, material_point_model_part, False)
        KratosParticle.GenerateMaterialPointCondition(grid_model_part, initial_mesh_model_part, material_point_model_part)
Example #2
0
    def test_ParticleEraseBySearch(self):
        current_model = KratosMultiphysics.Model()
        self._generate_particle_element_and_check(current_model)

        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")

        # Check initial total number of element
        particle_counter = material_point_model_part.NumberOfElements()
        self.assertEqual(particle_counter, 8)

        # Move particle
        for mpm in material_point_model_part.Elements:
            new_coordinate = mpm.GetValue(
                KratosParticle.MP_COORD) + [0.3, 0.23, 0.22]
            mpm.SetValue(KratosParticle.MP_COORD, new_coordinate)

        # Call Search
        self._search_element(current_model)

        # Initiate process
        process = KratosParticle.ParticleEraseProcess(
            material_point_model_part)

        # Execute
        process.Execute()

        # Check total number of element
        particle_counter = material_point_model_part.NumberOfElements()
        self.assertEqual(particle_counter, 1)
        expected_id = 9
        for mpm in material_point_model_part.Elements:
            self.assertEqual(mpm.Id, expected_id)
Example #3
0
    def test_ParticleEraseOutsideGivenDomain(self):
        current_model = KratosMultiphysics.Model()
        self._generate_particle_element_and_check(current_model)

        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")

        # Check initial total number of element
        particle_counter = material_point_model_part.NumberOfElements()
        self.assertEqual(particle_counter, 8)

        # Move particle
        for mpm in material_point_model_part.Elements:
            new_coordinates = mpm.CalculateOnIntegrationPoints(KratosParticle.MP_COORD, self.process_info)
            new_coordinates[0] += [0.3, 0.23, 0.22]
            mpm.SetValuesOnIntegrationPoints(KratosParticle.MP_COORD, new_coordinates, self.process_info)

        # Check outside given domain
        for mpm in material_point_model_part.Elements:
            new_coordinate = mpm.CalculateOnIntegrationPoints(KratosParticle.MP_COORD, self.process_info)[0]
            if(new_coordinate[0] < -0.5 or new_coordinate[0] > 0.5 or new_coordinate[1] < -0.5 or new_coordinate[1] > 0.5 or new_coordinate[2] < 0.0 or new_coordinate[2] > 1.0 ):
                mpm.Set(KratosMultiphysics.TO_ERASE, True)

        # Initiate process
        process = KratosParticle.ParticleEraseProcess(material_point_model_part)

        # Execute
        process.Execute()

        # Check total number of element
        particle_counter = material_point_model_part.NumberOfElements()
        self.assertEqual(particle_counter, 1)
        expected_id = 9
        for mpm in material_point_model_part.Elements:
            self.assertEqual(mpm.Id, expected_id)
Example #4
0
    def test_ParticleConditionEraseBySearch(self):
        current_model = KratosMultiphysics.Model()
        self._generate_particle_element_and_check(current_model)

        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")

        # Check initial number of condition
        particle_counter = material_point_model_part.NumberOfConditions()
        self.assertEqual(particle_counter, 4)

        # Move particle
        for mpc in material_point_model_part.Conditions:
            new_coordinate = mpc.GetValue(
                KratosParticle.MPC_COORD) + [-0.5, 0.5, 0.5]
            mpc.SetValue(KratosParticle.MPC_COORD, new_coordinate)

        # Call Search
        self._search_element(current_model)

        # Initiate process
        process = KratosParticle.ParticleEraseProcess(
            material_point_model_part)

        # Execute
        process.Execute()

        # Check total number of condition
        particle_counter = material_point_model_part.NumberOfConditions()
        self.assertEqual(particle_counter, 1)
        expected_id = 11
        for mpc in material_point_model_part.Conditions:
            self.assertEqual(mpc.Id, expected_id)
Example #5
0
    def test_ParticleEraseOutsideGivenDomain(self):
        current_model = KratosMultiphysics.Model()
        self._generate_particle_element_and_check(current_model)

        # Get model part
        material_model_part = current_model.GetModelPart("dummy_name")

        # Move particle
        for mpm in material_model_part.Elements:
            new_coordinate = mpm.GetValue(KratosParticle.MP_COORD) + [0.3, 0.23, 0.22]
            mpm.SetValue(KratosParticle.MP_COORD, new_coordinate)

        # Check outside given domain
        for mpm in material_model_part.Elements:
            new_coordinate = mpm.GetValue(KratosParticle.MP_COORD)
            if(new_coordinate[0] < -0.5 or new_coordinate[0] > 0.5 or new_coordinate[1] < -0.5 or new_coordinate[1] > 0.5 or new_coordinate[2] < -0.5 or new_coordinate[2] > 0.5 ):
                mpm.Set(KratosMultiphysics.TO_ERASE, True)

        # Initiate process
        process = KratosParticle.ParticleEraseProcess(material_model_part)

        # Execute
        process.Execute()

        # Check total number of element
        particle_counter = len(material_model_part.Elements)
        self.assertEqual(particle_counter, 1)
        expected_id = 3
        for mpm in material_model_part.Elements:
            self.assertEqual(mpm.Id, expected_id)
Example #6
0
    def _generate_particle_elements(self, current_model, dimension,
                                    geometry_element, num_particle,
                                    is_mixed_formulation):
        # Create element and nodes for background grids
        if self.grid_model_part.HasSubModelPart("Sub_Background_Grid"):
            sub_background = self.grid_model_part.GetSubModelPart(
                "Sub_Background_Grid")
        else:
            sub_background = self.grid_model_part.CreateSubModelPart(
                "Sub_Background_Grid")

        self._create_nodes(sub_background, dimension, geometry_element)
        self._create_elements(sub_background, dimension, geometry_element)

        # Create element and nodes for initial meshes
        if self.initial_mesh_model_part.HasSubModelPart("Elements"):
            sub_initial = self.initial_mesh_model_part.GetSubModelPart(
                "Elements")
        else:
            sub_initial = self.initial_mesh_model_part.CreateSubModelPart(
                "Elements")
            sub_initial.GetProperties()[1].SetValue(
                KratosParticle.PARTICLES_PER_ELEMENT, num_particle)
            sub_initial.GetProperties()[1].SetValue(KratosMultiphysics.DENSITY,
                                                    1000.0)

        self._create_nodes(sub_initial, dimension, geometry_element)
        self._create_elements(sub_initial, dimension, geometry_element)

        # Generate MP Elements
        KratosParticle.GenerateMaterialPointElement(
            self.grid_model_part, self.initial_mesh_model_part,
            self.material_point_model_part, is_mixed_formulation)
    def _CreateSolutionScheme(self):
        grid_model_part = self.GetGridModelPart()
        domain_size = self._GetDomainSize()
        block_size = domain_size
        if (self.settings["pressure_dofs"].GetBool()):
            block_size += 1

        # Setting the time integration schemes
        scheme_type = self.settings["scheme_type"].GetString()
        if (scheme_type == "newmark"):
            damp_factor_m = 0.0
            newmark_beta = self.settings["newmark_beta"].GetDouble()
        elif (scheme_type == "bossak"):
            damp_factor_m = self.settings["damp_factor_m"].GetDouble()
            newmark_beta = self.settings["newmark_beta"].GetDouble()
        else:
            err_msg = "The requested scheme type \"" + scheme_type + "\" is not available!\n"
            err_msg += "Available options are: \"newmark\", \"bossak\""
            raise Exception(err_msg)

        is_dynamic = self._IsDynamic()

        return KratosParticle.MPMResidualBasedBossakScheme(
            grid_model_part, domain_size, block_size, damp_factor_m,
            newmark_beta, is_dynamic)
Example #8
0
    def _GenerateMaterialPoint(self):
        pressure_dofs = self.settings["pressure_dofs"].GetBool()
        axis_symmetric_flag = self.settings["axis_symmetric_flag"].GetBool()

        # Assigning extra information to the main model part
        self.material_point_model_part.SetNodes(
            self.grid_model_part.GetNodes())
        self.material_point_model_part.ProcessInfo = self.grid_model_part.ProcessInfo
        self.material_point_model_part.SetBufferSize(
            self.grid_model_part.GetBufferSize())

        # Generate MP Element and Condition
        KratosParticle.GenerateMaterialPointElement(
            self.grid_model_part, self.initial_mesh_model_part,
            self.material_point_model_part, axis_symmetric_flag, pressure_dofs)
        KratosParticle.GenerateMaterialPointCondition(
            self.grid_model_part, self.initial_mesh_model_part,
            self.material_point_model_part)
 def _CreateLinearStrategy(self):
     computing_model_part = self.GetComputingModelPart()
     solution_scheme = self._GetSolutionScheme()
     reform_dofs_at_each_step = False  ## hard-coded, but can be changed upon implementation
     move_mesh_flag = self.settings["move_mesh_flag"].GetBool()
     move_mesh_flag = False  ## hard-coded
     return KratosParticle.MPMExplicitStrategy(
         computing_model_part, solution_scheme,
         self.settings["compute_reactions"].GetBool(),
         reform_dofs_at_each_step, move_mesh_flag)
Example #10
0
    def _move_and_search_condition(self, current_model, new_coordinate, max_num_results = 1000, specific_tolerance = 1.e-5):
        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")
        grid_model_part           = current_model.GetModelPart("Background_Grid")

        # Apply before search
        for mpc in material_point_model_part.Conditions:
            mpc.SetValuesOnIntegrationPoints(KratosParticle.MPC_COORD, [new_coordinate], self.process_info)

        # Search element
        KratosParticle.SearchElement(grid_model_part, material_point_model_part, max_num_results, specific_tolerance)
Example #11
0
    def _search_element(self, current_model):
        # Default
        max_num_results = 1000
        specific_tolerance = 1.e-5

        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")
        grid_model_part           = current_model.GetModelPart("Background_Grid")

        # Search element
        KratosParticle.SearchElement(grid_model_part, material_point_model_part, max_num_results, specific_tolerance)
    def _generate_particle_element_and_check(self, current_model):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)

        dimension = 3

        # Initialize model part
        ## Material model part definition
        material_model_part = current_model.CreateModelPart("dummy_name")
        material_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Initial material model part definition
        initial_material_model_part = current_model.CreateModelPart("Initial_dummy_name")
        initial_material_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        # Create element and nodes
        sub_mp = initial_material_model_part.CreateSubModelPart("test")
        sub_mp.GetProperties()[1].SetValue(KratosParticle.PARTICLES_PER_ELEMENT, 4)
        self._create_nodes(sub_mp)
        self._create_elements(sub_mp)

        # Create background element and nodes
        background_sub_mp = grid_model_part.CreateSubModelPart("test2")
        self._create_nodes(background_sub_mp)
        self._create_elements(background_sub_mp)
        self._create_conditions(background_sub_mp)

        # Initialize linear_solver
        linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver()

        # Initialize element
        new_element = KratosParticle.CreateUpdatedLagragian3D8N()

        # Initialize solver
        self.solver = KratosParticle.MPM3D(grid_model_part, initial_material_model_part, material_model_part, linear_solver, new_element, "static", 20, False, False, False, False)
Example #13
0
 def _CreateNewtonRaphsonStrategy(self):
     computing_model_part = self.GetComputingModelPart()
     solution_scheme = self._GetSolutionScheme()
     linear_solver = self._GetLinearSolver()
     convergence_criterion = self._GetConvergenceCriteria()
     builder_and_solver = self._GetBuilderAndSolver()
     reform_dofs_at_each_step = False  ## hard-coded, but can be changed upon implementation
     return KratosParticle.MPMResidualBasedNewtonRaphsonStrategy(
         computing_model_part, solution_scheme, linear_solver,
         convergence_criterion, builder_and_solver,
         self.settings["max_iteration"].GetInt(),
         self.settings["compute_reactions"].GetBool(),
         reform_dofs_at_each_step,
         self.settings["move_mesh_flag"].GetBool())
Example #14
0
    def _generate_particle_element_and_check_mp_volume(self, current_model,
                                                       dimension,
                                                       geometry_element,
                                                       num_particle,
                                                       expected_mp_volume):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(
            KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_point_model_part = current_model.CreateModelPart("dummy_name")
        material_point_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Initial material model part definition
        initial_mesh_model_part = current_model.CreateModelPart(
            "Initial_dummy_name")
        initial_mesh_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
                                             dimension)

        # Create element and nodes for background grids
        sub_background = grid_model_part.CreateSubModelPart("test_background")
        self._create_nodes(sub_background, dimension, geometry_element)
        self._create_elements(sub_background, dimension, geometry_element)

        # Create element and nodes for initial meshes
        sub_mp = initial_mesh_model_part.CreateSubModelPart("test")
        sub_mp.GetProperties()[1].SetValue(
            KratosParticle.PARTICLES_PER_ELEMENT, num_particle)
        self._create_nodes(sub_mp, dimension, geometry_element)
        self._create_elements(sub_mp, dimension, geometry_element)

        # Generate MP Elements
        KratosParticle.GenerateMaterialPointElement(grid_model_part,
                                                    initial_mesh_model_part,
                                                    material_point_model_part,
                                                    False)

        # Check volume of first material point
        for mp in material_point_model_part.Elements:
            mp_volume = mp.CalculateOnIntegrationPoints(
                KratosParticle.MP_VOLUME, grid_model_part.ProcessInfo)[0]
            self.assertEqual(expected_mp_volume, mp_volume)
            break
    def _move_and_search_element(self,
                                 current_model,
                                 new_coordinate,
                                 max_num_results=1000,
                                 specific_tolerance=1.e-5):
        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")
        grid_model_part = current_model.GetModelPart("Background_Grid")

        # Apply  before search
        for mpm in material_point_model_part.Elements:
            mpm.SetValue(KratosParticle.MP_COORD, new_coordinate)

        # Search element
        KratosParticle.SearchElement(grid_model_part,
                                     material_point_model_part,
                                     max_num_results, specific_tolerance)
Example #16
0
 def _SearchElement(self):
     searching_alg_type = self.settings["element_search_settings"][
         "search_algorithm_type"].GetString()
     max_number_of_search_results = self.settings[
         "element_search_settings"]["max_number_of_results"].GetInt()
     searching_tolerance = self.settings["element_search_settings"][
         "searching_tolerance"].GetDouble()
     if (searching_alg_type == "bin_based"):
         KratosParticle.SearchElement(self.grid_model_part,
                                      self.material_point_model_part,
                                      max_number_of_search_results,
                                      searching_tolerance)
     else:
         err_msg = "The requested searching algorithm \"" + searching_alg_type
         err_msg += "\" is not available for ParticleMechanicsApplication!\n"
         err_msg += "Available options are: \"bin_based\""
         raise Exception(err_msg)
Example #17
0
    def _generate_particle_condition_and_check(self, current_model, dimension,
                                               geometry_element, num_particle,
                                               expected_num_particle):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(
            KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_point_model_part = current_model.CreateModelPart("dummy_name")
        material_point_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Initial material model part definition
        initial_mesh_model_part = current_model.CreateModelPart(
            "Initial_dummy_name")
        initial_mesh_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
                                             dimension)

        # Create element and nodes for background grids
        sub_background = grid_model_part.CreateSubModelPart("test_background")
        self._create_nodes(sub_background, dimension, geometry_element)
        self._create_elements(sub_background, dimension, geometry_element)
        self._create_condition(sub_background, dimension, geometry_element)
        for condition in grid_model_part.Conditions:
            condition.SetValue(KratosParticle.PARTICLES_PER_CONDITION,
                               num_particle)

        # Create element and nodes for initial meshes
        sub_mp = initial_mesh_model_part.CreateSubModelPart("test")
        sub_mp.GetProperties()[1].SetValue(
            KratosParticle.PARTICLES_PER_ELEMENT, 4)

        # Generate MP Conditions
        KratosParticle.GenerateMaterialPointCondition(
            grid_model_part, initial_mesh_model_part,
            material_point_model_part)

        # Check total number of element
        particle_counter = material_point_model_part.NumberOfConditions()
        self.assertEqual(expected_num_particle, particle_counter)
Example #18
0
    def _CreateSolutionScheme(self):
        grid_model_part = self.GetGridModelPart()
        domain_size = self._GetDomainSize()
        block_size  = domain_size
        if (self.settings["pressure_dofs"].GetBool()):
            block_size += 1

        # Check whether compressibility is considered
        is_compressible = self.settings["compressible"].GetBool()
        grid_model_part.ProcessInfo.SetValue(KratosParticle.IS_COMPRESSIBLE, is_compressible)

        # Check if we are fixing MPs that lie directly on the edge of grid elements
        is_fix_explicit_mp_on_grid_edge = self.settings["is_fix_explicit_mp_on_grid_edge"].GetBool()
        grid_model_part.ProcessInfo.SetValue(KratosParticle.IS_FIX_EXPLICIT_MP_ON_GRID_EDGE, is_fix_explicit_mp_on_grid_edge)

        # Setting the time integration schemes
        scheme_type = self.settings["scheme_type"].GetString()

        if scheme_type == "forward_euler":
            stress_update_option = 10
            stress_update = self.settings["stress_update"].GetString() #0 = USF, 1 = USL, 2 = MUSL
            if stress_update == "usf":
                stress_update_option = 0
            elif stress_update == "usl":
                stress_update_option = 1
            elif stress_update == "musl":
                stress_update_option = 2
            else:
                err_msg = "The requested stress update \"" + stress_update + "\" is not available!\n"
                err_msg += "Available options are: \"usf\", \"usl\",\"musl\""
            grid_model_part.ProcessInfo.SetValue(KratosParticle.EXPLICIT_STRESS_UPDATE_OPTION, stress_update_option)
            grid_model_part.ProcessInfo.SetValue(KratosParticle.IS_EXPLICIT_CENTRAL_DIFFERENCE, False)
        elif scheme_type == "central_difference":
            grid_model_part.ProcessInfo.SetValue(KratosParticle.EXPLICIT_STRESS_UPDATE_OPTION, 0)
            grid_model_part.ProcessInfo.SetValue(KratosParticle.IS_EXPLICIT_CENTRAL_DIFFERENCE, True)
        else:
            err_msg = "The requested scheme type \"" + scheme_type + "\" is not available!\n"
            err_msg += "Available options are: \"forward_euler\", \"central_difference\""
            raise Exception(err_msg)

        return KratosParticle.MPMExplicitScheme( grid_model_part)
Example #19
0
    def _generate_particle_element(self, current_model, dimension, geometry_element, is_structured, is_fine=False):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_point_model_part = current_model.CreateModelPart("dummy_name")
        material_point_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)
        self.process_info = material_point_model_part.ProcessInfo

        ## Initial material model part definition
        initial_mesh_model_part = current_model.CreateModelPart("Initial_dummy_name")
        initial_mesh_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        # Create Background Grid
        sub_background = grid_model_part.CreateSubModelPart("test")
        if is_structured:
            self._create_background_nodes_structured(sub_background, dimension, geometry_element)
        else:
            self._create_background_nodes_unstructured(sub_background, dimension, geometry_element, is_fine)

        self._create_background_elements(sub_background,dimension, geometry_element, is_structured)

        # Create element and nodes
        sub_mp = initial_mesh_model_part.CreateSubModelPart("test")
        sub_mp.GetProperties()[1].SetValue(KratosParticle.PARTICLES_PER_ELEMENT, 1)
        if is_structured:
            self._create_nodes_structured(sub_mp, dimension, geometry_element)
        else:
            self._create_nodes_unstructured(sub_mp, dimension, geometry_element, is_fine)

        self._create_elements(sub_mp,dimension, geometry_element)

        # Set active
        KratosMultiphysics.VariableUtils().SetFlag(KratosMultiphysics.ACTIVE, True, initial_mesh_model_part.Elements)

        # Generate MP Elements
        KratosParticle.GenerateMaterialPointElement(grid_model_part, initial_mesh_model_part, material_point_model_part, False, False)
Example #20
0
    def test_ParticleConditionEraseOutsideGivenDomain(self):
        current_model = KratosMultiphysics.Model()
        self._generate_particle_element_and_check(current_model)

        # Get model part
        material_point_model_part = current_model.GetModelPart("dummy_name")

        # Check initial number of condition
        particle_counter = material_point_model_part.NumberOfConditions()
        self.assertEqual(particle_counter, 4)

        # Move particle
        for mpc in material_point_model_part.Conditions:
            new_coordinate = mpc.GetValue(
                KratosParticle.MPC_COORD) + [-0.5, 0.5, 0.5]
            mpc.SetValue(KratosParticle.MPC_COORD, new_coordinate)

        # Check outside given domain
        for mpc in material_point_model_part.Conditions:
            new_coordinate = mpc.GetValue(KratosParticle.MPC_COORD)
            if (new_coordinate[0] < -0.5 or new_coordinate[0] > 0.5
                    or new_coordinate[1] < -0.5 or new_coordinate[1] > 0.5
                    or new_coordinate[2] < -0.5 or new_coordinate[2] > 0.5):
                mpc.Set(KratosMultiphysics.TO_ERASE, True)

        # Initiate process
        process = KratosParticle.ParticleEraseProcess(
            material_point_model_part)

        # Execute
        process.Execute()

        # Check total number of condition
        particle_counter = material_point_model_part.NumberOfConditions()
        self.assertEqual(particle_counter, 1)
        expected_id = 11
        for mpc in material_point_model_part.Conditions:
            self.assertEqual(mpc.Id, expected_id)
    def _generate_particle_element_and_check(self, current_model, dimension, geometry_element, num_particle, expected_num_particle):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_model_part = current_model.CreateModelPart("dummy_name")
        material_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Initial material model part definition
        initial_material_model_part = current_model.CreateModelPart("Initial_dummy_name")
        initial_material_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        # Create element and nodes
        sub_mp = initial_material_model_part.CreateSubModelPart("test")
        self._create_nodes(sub_mp, dimension, geometry_element)
        self._create_elements(sub_mp,dimension, geometry_element)

        # Initialize linear_solver
        linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver()

        # Initialize element
        if geometry_element == "Triangle":
            if (dimension == 2):
                new_element = KratosParticle.CreateUpdatedLagragian2D3N()
            else:
                new_element = KratosParticle.CreateUpdatedLagragian3D4N()
        elif geometry_element == "Quadrilateral":
            if (dimension == 2):
                new_element = KratosParticle.CreateUpdatedLagragian2D4N()
            else:
                new_element = KratosParticle.CreateUpdatedLagragian3D8N()

        # Initialize solver
        if(dimension==2):
            self.solver = KratosParticle.MPM2D(grid_model_part, initial_material_model_part, material_model_part, linear_solver, new_element, False, "static", geometry_element, num_particle, False, False)
        else:
            self.solver = KratosParticle.MPM3D(grid_model_part, initial_material_model_part, material_model_part, linear_solver, new_element, False, "static", geometry_element, num_particle, False, False)

        # Check total number of element
        particle_counter = len(material_model_part.Elements)
        self.assertEqual(expected_num_particle,particle_counter)
Example #22
0
    def _generate_particle_condition(self, current_model, dimension, geometry_element):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_point_model_part = current_model.CreateModelPart("dummy_name")
        material_point_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)
        self.process_info = material_point_model_part.ProcessInfo

        ## Initial material model part definition
        initial_mesh_model_part = current_model.CreateModelPart("Initial_dummy_name")
        initial_mesh_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, dimension)

        # Create Background Grid
        sub_background = grid_model_part.CreateSubModelPart("test")
        self._create_background_nodes(sub_background, dimension, geometry_element)

        self._create_background_elements(sub_background,dimension, geometry_element)

        self._create_nodes(sub_background, dimension)

        self._create_conditions(sub_background,dimension)
        for condition in grid_model_part.Conditions:
            condition.SetValue(KratosParticle.PARTICLES_PER_CONDITION, 1)
            condition.SetValue(KratosParticle.MPC_IS_NEUMANN, True)
            condition.SetValue(KratosParticle.POINT_LOAD, [1.0, 0.0, 0.0])

        # Set active
        KratosMultiphysics.VariableUtils().SetFlag(KratosMultiphysics.ACTIVE, True, initial_mesh_model_part.Elements)

        # Generate MP Conditions
        KratosParticle.GenerateMaterialPointCondition(grid_model_part, initial_mesh_model_part, material_point_model_part)
Example #23
0
    def Initialize(self):
        #TODO: implement solver_settings and change the input of the constructor in MPM_strategy.h

        # Set definition of the convergence criteria
        self.convergence_criterion_type = self.settings[
            "convergence_criterion"].GetString()
        self.rel_disp_tol = self.settings[
            "displacement_relative_tolerance"].GetDouble()
        self.abs_disp_tol = self.settings[
            "displacement_absolute_tolerance"].GetDouble()
        self.rel_res_tol = self.settings[
            "residual_relative_tolerance"].GetDouble()
        self.abs_res_tol = self.settings[
            "residual_absolute_tolerance"].GetDouble()
        self.max_iteration = self.settings["max_iteration"].GetInt()

        # Set definition of the global solver type
        self.solver_type = self.settings["solver_type"].GetString()

        # Set definition of the solver parameters
        self.compute_reactions = self.settings["compute_reactions"].GetBool()
        self.pressure_dofs = self.settings["pressure_dofs"].GetBool()
        self.axis_symmetric_flag = self.settings[
            "axis_symmetric_flag"].GetBool()
        self.move_mesh_flag = self.settings["move_mesh_flag"].GetBool()

        # Set definition of search element
        self.max_number_of_search_results = self.settings[
            "element_search_settings"]["max_number_of_results"].GetInt()
        self.searching_tolerance = self.settings["element_search_settings"][
            "searching_tolerance"].GetDouble()

        # Identify geometry type
        self._identify_geometry_type()

        # Set default solver_settings parameters
        if self.geometry_element == "Triangle":
            if (self.domain_size == 2):
                if (self.pressure_dofs):
                    self.new_element = KratosParticle.CreateUpdatedLagragianUP2D3N(
                    )
                else:
                    if (self.axis_symmetric_flag):
                        self.new_element = KratosParticle.CreateUpdatedLagragianAxis2D3N(
                        )
                    else:
                        self.new_element = KratosParticle.CreateUpdatedLagragian2D3N(
                        )
            else:
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 3D for Tetrahedral Element is not yet implemented."
                    )
                else:
                    self.new_element = KratosParticle.CreateUpdatedLagragian3D4N(
                    )
        elif self.geometry_element == "Quadrilateral":
            if (self.domain_size == 2):
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 2D for Quadrilateral Element is not yet implemented."
                    )
                else:
                    if (self.axis_symmetric_flag):
                        self.new_element = KratosParticle.CreateUpdatedLagragianAxis2D4N(
                        )
                    else:
                        self.new_element = KratosParticle.CreateUpdatedLagragian2D4N(
                        )
            else:
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 3D for Hexahedral Element is not yet implemented."
                    )
                else:
                    self.new_element = KratosParticle.CreateUpdatedLagragian3D8N(
                    )

        # Initialize solver
        if (self.domain_size == 2):
            self.solver = KratosParticle.MPM2D(
                self.grid_model_part, self.initial_material_model_part,
                self.material_model_part, self.linear_solver, self.new_element,
                self.solver_type, self.max_iteration, self.compute_reactions,
                self.block_builder, self.pressure_dofs, self.move_mesh_flag)
        else:
            self.solver = KratosParticle.MPM3D(
                self.grid_model_part, self.initial_material_model_part,
                self.material_model_part, self.linear_solver, self.new_element,
                self.solver_type, self.max_iteration, self.compute_reactions,
                self.block_builder, self.pressure_dofs, self.move_mesh_flag)

        # Set echo level
        self._set_echo_level()

        # Check if everything is assigned correctly
        self._check()

        KratosMultiphysics.Logger.PrintInfo(
            "::[ParticleMPMSolver]:: ", "Solver is initialized correctly.")
    def _generate_particle_element(self,
                                   current_model,
                                   dimension,
                                   geometry_element,
                                   is_structured,
                                   is_fine=False):
        KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(
            KratosMultiphysics.Logger.Severity.WARNING)

        # Initialize model part
        ## Material model part definition
        material_model_part = current_model.CreateModelPart("dummy_name")
        material_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Initial material model part definition
        initial_material_model_part = current_model.CreateModelPart(
            "Initial_dummy_name")
        initial_material_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE, dimension)

        ## Grid model part definition
        grid_model_part = current_model.CreateModelPart("Background_Grid")
        grid_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
                                             dimension)

        # Create Background Grid
        sub_background = grid_model_part.CreateSubModelPart("test")
        if is_structured:
            self._create_background_nodes_structured(sub_background, dimension,
                                                     geometry_element)
        else:
            self._create_background_nodes_unstructured(sub_background,
                                                       dimension,
                                                       geometry_element,
                                                       is_fine)

        self._create_background_elements(sub_background, dimension,
                                         geometry_element, is_structured)

        # Create element and nodes
        sub_mp = initial_material_model_part.CreateSubModelPart("test")
        if is_structured:
            self._create_nodes_structured(sub_mp, dimension, geometry_element)
        else:
            self._create_nodes_unstructured(sub_mp, dimension,
                                            geometry_element, is_fine)

        self._create_elements(sub_mp, dimension, geometry_element)

        # Set active
        KratosMultiphysics.VariableUtils().SetFlag(
            KratosMultiphysics.ACTIVE, True,
            initial_material_model_part.Elements)

        # Initialize linear_solver
        linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver()

        # Initialize element
        if geometry_element == "Triangle":
            if (dimension == 2):
                new_element = KratosParticle.CreateUpdatedLagragian2D3N()
            else:
                new_element = KratosParticle.CreateUpdatedLagragian3D4N()
        elif geometry_element == "Quadrilateral":
            if (dimension == 2):
                new_element = KratosParticle.CreateUpdatedLagragian2D4N()
            else:
                new_element = KratosParticle.CreateUpdatedLagragian3D8N()

        # Initialize solver
        if (dimension == 2):
            self.solver = KratosParticle.MPM2D(
                grid_model_part, initial_material_model_part,
                material_model_part, linear_solver, new_element, False,
                "static", geometry_element, 1, False, False)
        else:
            self.solver = KratosParticle.MPM3D(
                grid_model_part, initial_material_model_part,
                material_model_part, linear_solver, new_element, False,
                "static", geometry_element, 1, False, False)
Example #25
0
    def Initialize(self):
        #TODO: implement solver_settings and change the input of the constructor in MPM_strategy.h

        # Set definition of the convergence criteria
        self.convergence_criterion_type = self.settings[
            "convergence_criterion"].GetString()
        self.rel_disp_tol = self.settings[
            "displacement_relative_tolerance"].GetDouble()
        self.abs_disp_tol = self.settings[
            "displacement_absolute_tolerance"].GetDouble()
        self.rel_res_tol = self.settings[
            "residual_relative_tolerance"].GetDouble()
        self.abs_res_tol = self.settings[
            "residual_absolute_tolerance"].GetDouble()
        self.max_iters = self.settings["max_iteration"].GetInt()

        # Set definition of the global solver type
        self.solver_type = self.settings["solver_type"].GetString()
        self.scheme_type = self.settings["scheme_type"].GetString()
        self.time_integration_method = self.settings[
            "time_integration_method"].GetString()

        # Set definition of the solver parameters
        self.compute_reactions = self.settings["compute_reactions"].GetBool()
        self.compute_contact_forces = self.settings[
            "compute_contact_forces"].GetBool()
        self.rotation_dofs = self.settings["rotation_dofs"].GetBool()
        self.pressure_dofs = self.settings["pressure_dofs"].GetBool()
        self.line_search = self.settings["line_search"].GetBool()
        self.implex = self.settings["implex"].GetBool()
        self.move_mesh_flag = self.settings["move_mesh_flag"].GetBool()

        # Set explicit scheme definitions
        if self.scheme_type == "Explicit":
            self.explicit_integration_scheme = self.settings[
                "explicit_integration_scheme"].GetString()
            self.rayleigh_damping = self.settings["rayleigh_damping"].GetBool()
            self.max_delta_time = self.settings["max_delta_time"].GetDouble()

            value = 0
            if (self.settings["time_step_prediction_level"].GetString() ==
                    "Automatic"):
                value = 1
            elif (self.settings["time_step_prediction_level"].GetString() ==
                  "RefreshEveryTimeStep"):
                value = 2
            self.time_step_prediction_level = value

        # Set definition of the echo level
        self.echo_level = self.settings["echo_level"].GetInt()

        # Set default solver_settings parameters
        self.geometry_element = self.settings["geometry_element"].GetString()
        self.number_particle = self.settings["particle_per_element"].GetInt()
        if self.geometry_element == "Triangle":
            if (self.domain_size == 2):
                if (self.pressure_dofs):
                    self.new_element = KratosParticle.CreateUpdatedLagragianUP2D3N(
                    )
                else:
                    self.new_element = KratosParticle.CreateUpdatedLagragian2D3N(
                    )
            else:
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 3D for Tetrahedral Element is not yet implemented."
                    )
                else:
                    self.new_element = KratosParticle.CreateUpdatedLagragian3D4N(
                    )
        elif self.geometry_element == "Quadrilateral":
            if (self.domain_size == 2):
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 2D for Quadrilateral Element is not yet implemented."
                    )
                else:
                    self.new_element = KratosParticle.CreateUpdatedLagragian2D4N(
                    )
            else:
                if (self.pressure_dofs):
                    raise Exception(
                        "Element for mixed U-P formulation in 3D for Hexahedral Element is not yet implemented."
                    )
                else:
                    raise Exception(
                        "Element in 3D for Hexahedral Element is not yet implemented. Please use Tetrahedral instead."
                    )

        # Initialize solver
        if (self.domain_size == 2):
            self.solver = KratosParticle.MPM2D(
                self.model_part1, self.model_part2, self.model_part3,
                self.linear_solver, self.new_element, self.move_mesh_flag,
                self.solver_type, self.geometry_element, self.number_particle,
                self.block_builder, self.pressure_dofs)
        else:
            self.solver = KratosParticle.MPM3D(
                self.model_part1, self.model_part2, self.model_part3,
                self.linear_solver, self.new_element, self.move_mesh_flag,
                self.solver_type, self.geometry_element, self.number_particle,
                self.block_builder, self.pressure_dofs)

        # Set echo level
        self._set_echo_level()

        # Check if everything is assigned correctly
        self._check()

        if self._is_printing_rank():
            KratosMultiphysics.Logger.PrintInfo(
                "ParticleMPMSolver", "Solver is initialized correctly.")