Example #1
0
def CreateMapper(origin_model_part, destination_model_part, mapper_settings):
    default_settings = KM.Parameters("""
    {
        "filter_function_type"       : "linear",
        "filter_radius"              : 0.000000000001,
        "max_nodes_in_filter_radius" : 10000,
        "matrix_free_filtering"      : false,
        "consistent_mapping"         : false,
        "improved_integration"       : false,
        "integration_method"         : "gauss_integration",
        "number_of_gauss_points"     : 5,
        "in_plane_morphing"                   : false,
        "in_plane_morphing_settings"          : {}
    }""")

    mapper_settings.ValidateAndAssignDefaults(default_settings)

    if mapper_settings["in_plane_morphing"].GetBool():
        return in_plane_vertex_morphing_mapper.InPlaneVertexMorphingMapper(origin_model_part, destination_model_part, mapper_settings)
    elif mapper_settings["matrix_free_filtering"].GetBool():
        if mapper_settings["consistent_mapping"].GetBool():
             raise ValueError ("Matrix free mapper has no option to map consistently yet!")
        if mapper_settings["improved_integration"].GetBool():
             raise ValueError ("Matrix free mapper does not yet allow for an improved integration!")
        else:
            return KSO.MapperVertexMorphingMatrixFree(origin_model_part, destination_model_part, mapper_settings)
    else:
        if mapper_settings["improved_integration"].GetBool():
            return KSO.MapperVertexMorphingImprovedIntegration(origin_model_part, destination_model_part, mapper_settings)
        else:
            return KSO.MapperVertexMorphing(origin_model_part, destination_model_part, mapper_settings)

# ==============================================================================
        kratos_response_settings["response_type"].GetString(),
        kratos_response_settings, model)
    model_part = model.GetModelPart(model_part_name)
    model_part.AddNodalSolutionStepVariable(KSO.DF1DX)
    model_part.AddNodalSolutionStepVariable(KSO.DF1DX_MAPPED)
    response.Initialize()
    response.InitializeSolutionStep()
    response.CalculateValue()
    response.CalculateGradient()
    response.FinalizeSolutionStep()
    response.Finalize()

    # Perform mapping
    WriteDictionaryDataOnNodalVariable(response.GetShapeGradient(), model_part,
                                       KSO.DF1DX)
    vm_mapper = KSO.MapperVertexMorphingMatrixFree(model_part, model_part,
                                                   mapper_settings)
    vm_mapper.InverseMap(KSO.DF1DX, KSO.DF1DX_MAPPED)

    # Output to verify mapping
    OutputModelPart(model_part, "reference_part", ["DF1DX", "DF1DX_MAPPED"])

    # Get results
    reference_value = response.GetValue()
    reference_gradient = model_part.Nodes[move_node_id].GetSolutionStepValue(
        KSO.DF1DX_MAPPED)

    # Initialize results file
    with open(results_filename, 'a') as open_file:
        open_file.write(
            "-----------------------------------------------------------------------\n"
        )