Skip to content

How to do Mapping between nonmatching meshes

Philipp Bucher edited this page Jan 5, 2018 · 17 revisions

WARNING Interface changes in PR #1244!

This guide explains how to use the MappingApplication for exchanging Variable Data on an interface of nonmatching grids.

The data is exchanged between an origin and a destination SubModelPart. These SubModelParts can, but don't have to, be in separate ModelParts.

The Application works in serial as well as fully MPI-parallel. The usage does not change if executed in parallel.

The Application works in 1D (edges), 2D (surfaces) and 3D (volumes).

Currently the following mappers are implemented:

  • Nearest Neighbor: Each node in the destination gets the value of the closest node in the origin
  • Nearest Element: Each node in the destination gets an interpolated value from the origin. (more accurate)

In order to use the Application, the following steps have to be performed:

An example is provided at the end of this page.

Compiling

To compile the MappingApplication, set the MAPPING_APPLICATION flag by adding the line -DMAPPING_APPLICATION=ON to the CMake configuration script (by default, configure in the cmake_build folder)

Settings in the JSON file

The settings for a mapper are saved under mapper_settings in a list.

Basic Usage

The following setting is MANDATORY for a mapper:

  • mapper_type [string] Name of the mapper (Currently available options: NearestNeighbor and NearestElement)

Extended Settings

You can use the main ModelPart or a SubModelPart to build the Mapper. If you want to use a SubModelPart, use one of the following settings. If you don't specify interface_submodel_part*, the main Modelpart is used.

  • interface_submodel_part_origin [string] Name of the interface submodelpart in the origin modelpart
  • interface_submodel_part_destination [string] Name of the interface submodelpart in the destination modelpart
  • echo_level [integer] specifies how much information the mapper prints (Description can also be found in the class description of the MapperCommunicator)
  1. Mute every output
  2. Print Timing Information
  3. Warnings are printed
  4. Basic Information, recommended for standard debugging
  5. Very detailed output (recommended for developing only)

Extended functionalities

These settings are for advanced users. It is recommended to not interfere with the search parameters.

  • search_radius [double] (default: automatic computation) search radius for the neighbor search
  • search_iterations [double] (default: 3) number of search iterations for the neighbor search, usually not needed
  • approximation_tolerance [double] needed for element-based mapper if the the projection fails

The default values are saved in the m_default_settings in the MapperCommunicator

Importing

Import the Application by using:

import KratosMultiphysics.MappingApplication as KratosMapping

Initializing the mapper

The mapper takes the main ModelPart of origin and destination as well as some parameters from a JSON file as input (if you want to use a SubModelPart, take a look at the JSON file ).

mapper = KratosMapping.MapperFactory(model_part_origin, 
				     model_part_destination, 
				     project_parameters_mapper_1)

Using the mapping functions

The mapper has three functions, with some optional arguments.

Basic Usage

  • Map (variable_origin, variable_destination, options): This function maps from the origin side of the interface to the destination side of the interface
  • InverseMap (variable_origin, variable_destination, options): This function maps from the destination side of the interface to the origin side of the interface
  • UpdateInterface (search_radius): This function updates the interface in case of relative motion (e.g. sliding), it recomputes the neighboring pairs.

Extended functionalities

Besides the basic functionality of the mapper, extended functionalities are implemented to increase the usability.

Extended functionalities are provided through the usage of specific flags. These flags are the Flags-Objects implemented by Kratos and require a certain usage which is explained in this section.

Currently the following flags are implemented, for the respective functions:

  • Map/InverseMap ADD_VALUES: Instead of overwriting the nodal values with the mapped values, the mapped values are added to the existing ones (useful if for example several loads act on the interface, not only the mapped loads)
  • Map/InverseMap SWAP_SIGN: The sign of the mapped values is swapped

The flags have to be used with referring to their namespace:
KratosMapping.MapperFactory.FLAGNAME

To set multiple flags at the same time, combine them using the bitwise or operator (vertical bar |) i.e. (ADD_VALUES | SWAP_SIGN)

Example

JSON file

{
"mapper_settings": [
		{
		"mapper_type": "NearestNeighbor",
		"interface_submodel_part_origin": "Interface_Fluid"
		},
		{
		"mapper_type": "NearestElement",
		"interface_submodel_part_destination": "SubModelPart_Interface_2",
		"search_radius" : 1.34,
		"search_iterations" : 10,
		"approximation_tolerance" : 1.77,
		"echo_level" : 3
		}
	]
}

In this example, the first mapper uses a SubModelPart (with name "Interface_Fluid") for the origin side, whereas the main ModelPart is used for the destination. The second mapper uses the main Modelpart for the origin and a SubModelpart (with name "SubModelPart_Interface_2") for the destination.

Usage in MainKratos.py

import KratosMultiphysics.MappingApplication as KratosMapping

nearest_neighbor_mapper = KratosMapping.MapperFactory(
					main_modelpart_1,
					main_modelpart_2,
					["mapper_settings"][0])
													  
nearest_element_mapper = KratosMapping.MapperFactory(
					main_modelpart_3,
					main_modelpart_4,
					["mapper_settings"][1])
					
nearest_neighbor_mapper.Map(PRESSURE, PRESSURE)

nearest_element_mapper.InverseMap(VELOCITY, VELOCITY, KratosMapping.MapperFactory.ADD_VALUES)

nearest_element_mapper.Map(REACTION, POINT_LOAD, 
                           KratosMapping.MapperFactory.ADD_VALUES | KratosMapping.MapperFactory.SWAP_SIGN)

nearest_neighbor_mapper.UpdateInterface()

Project information

Getting Started

Tutorials

Developers

Kratos structure

Conventions

Solvers

Debugging, profiling and testing

HOW TOs

Utilities

Kratos API

Kratos Structural Mechanics API

Clone this wiki locally