-
Notifications
You must be signed in to change notification settings - Fork 247
How to do Mapping between nonmatching meshes
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:
- Compilation
- Setting up a JSON file for the mapper
- Importing the Application in Python
- Initializing the mapper
- Mapping
An example is provided at the end of this page.
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)
The settings for a mapper are saved under mapper_settings
in a list.
The following setting is MANDATORY for a mapper:
-
mapper_type [string] Name of the mapper (Currently available options:
NearestNeighbor
andNearestElement
)
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)
- Mute every output
- Print Timing Information
- Warnings are printed
- Basic Information, recommended for standard debugging
- Very detailed output (recommended for developing only)
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
Import the Application by using:
import KratosMultiphysics.MappingApplication as KratosMapping
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)
The mapper has three functions, with some optional arguments.
- 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.
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)
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()
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API