Skip to content

Commit

Permalink
Merge pull request #11419 from KratosMultiphysics/med-application
Browse files Browse the repository at this point in the history
MedApplication
  • Loading branch information
philbucher authored Sep 21, 2023
2 parents 1125a16 + b42fdbd commit 635c2c0
Show file tree
Hide file tree
Showing 33 changed files with 2,602 additions and 0 deletions.
83 changes: 83 additions & 0 deletions applications/MedApplication/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)

message("**** configuring KratosMedApplication ****")

################### PYBIND11
include(pybind11Tools)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) # for FindMED
find_package(MED REQUIRED)

# MED uses HDF
# TODO check interoperability with the HDFapp, both in serial and parallel
if (NOT HDF5_FOUND)
find_package(HDF5 REQUIRED COMPONENTS C)
endif()

include_directories(${MED_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS})

include_directories( ${KRATOS_SOURCE_DIR}/kratos )

## Med Core sources
file(GLOB_RECURSE KRATOS_MED_APPLICATION_CORE
${CMAKE_CURRENT_SOURCE_DIR}/med_application.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_io/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_utilities/*.cpp
)

## Med testing sources
if(${KRATOS_BUILD_TESTING} MATCHES ON)
file(GLOB_RECURSE KRATOS_MED_APPLICATION_TESTING_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
endif(${KRATOS_BUILD_TESTING} MATCHES ON)

## Med python interface sources
file(GLOB_RECURSE KRATOS_MED_APPLICATION_PYTHON_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/custom_python/*.cpp)

add_library(KratosMedCore SHARED ${KRATOS_MED_APPLICATION_CORE} ${KRATOS_MED_APPLICATION_TESTING_SOURCES})
target_link_libraries(KratosMedCore PUBLIC KratosCore ${MED_LIBRARIES} ${HDF5_C_LIBRARIES})
set_target_properties(KratosMedCore PROPERTIES COMPILE_DEFINITIONS "MED_APPLICATION=EXPORT,API")
target_include_directories(KratosMedCore SYSTEM PRIVATE hdf5::hdf5)


###############################################################
## define library Kratos which defines the basic python interface
pybind11_add_module(KratosMedApplication MODULE THIN_LTO ${KRATOS_MED_APPLICATION_PYTHON_INTERFACE})
target_link_libraries(KratosMedApplication PRIVATE KratosMedCore)
set_target_properties(KratosMedApplication PROPERTIES PREFIX "")

# changing the .dll suffix to .pyd (Windows)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_target_properties(KratosMedApplication PROPERTIES SUFFIX .pyd)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

# changing the .dylib suffix to .so (OS X)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(KratosMedApplication PROPERTIES SUFFIX .so)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

# Add to the KratosMultiphisics Python module
kratos_python_install(${INSTALL_PYTHON_USING_LINKS} ${CMAKE_CURRENT_SOURCE_DIR}/MedApplication.py KratosMultiphysics/MedApplication/__init__.py )

# Install python files
get_filename_component (CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
kratos_python_install_directory(${INSTALL_PYTHON_USING_LINKS} ${CMAKE_CURRENT_SOURCE_DIR}/python_scripts KratosMultiphysics/${CURRENT_DIR_NAME} )

# Kratos Testing. Install everything except sources to ensure that reference and configuration files are copied.
if(${INSTALL_TESTING_FILES} MATCHES ON )
get_filename_component (CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests DESTINATION applications/${CURRENT_DIR_NAME}
PATTERN "*.git" EXCLUDE
PATTERN "*.c" EXCLUDE
PATTERN "*.h" EXCLUDE
PATTERN "*.cpp" EXCLUDE
PATTERN "*.hpp" EXCLUDE
)
endif(${INSTALL_TESTING_FILES} MATCHES ON)

# Install targets
install(TARGETS KratosMedCore DESTINATION libs )
install(TARGETS KratosMedApplication DESTINATION libs )

# Define custom targets
set(KRATOS_KERNEL "${KRATOS_KERNEL};KratosMedCore" PARENT_SCOPE)
set(KRATOS_PYTHON_INTERFACE "${KRATOS_PYTHON_INTERFACE};KratosMedApplication" PARENT_SCOPE)
38 changes: 38 additions & 0 deletions applications/MedApplication/FindMED.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# include(FindPackageHandleStandardArgs)
# find_package_handle_standard_args






# Find the MED includes and libraries
#
# MED_INCLUDE_DIR - where to find autopack.h
# MED_LIBRARIES - List of fully qualified libraries to link against.
# MED_FOUND - Do not attempt to use if "no" or undefined.

FIND_PATH(MED_INCLUDE_DIR "med.h"
PATHS
"${MED_ROOT}/include"
/usr/local/include
/usr/include
)

FIND_LIBRARY(MED_LIBRARY medC
PATHS
"${MED_ROOT}/lib"
/usr/local/lib/*
/usr/lib/*
)

IF(MED_INCLUDE_DIR AND MED_LIBRARY)
SET( MED_LIBRARIES ${MED_LIBRARY})
SET( MED_FOUND "YES" )
message(STATUS "MED found!")
message(STATUS "MED includes: ${MED_INCLUDE_DIR}")
message(STATUS "MED libraries: ${MED_LIBRARY}")
else()
message(WARNING "finding MED failed, please try to set the var MED_ROOT")
ENDIF()
7 changes: 7 additions & 0 deletions applications/MedApplication/MedApplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Application dependent names and paths
from KratosMultiphysics import _ImportApplication
from KratosMedApplication import *
application = KratosMedApplication()
application_name = "KratosMedApplication"

_ImportApplication(application, application_name)
12 changes: 12 additions & 0 deletions applications/MedApplication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# MedApplication

The Med Application an interface to the MED-library. This library writes med-files, which contain mesh, field results and other data, and is based on [HDF5](https://www.hdfgroup.org/solutions/hdf5/). This format is used by [Salome](https://www.salome-platform.org/) and [Code_Aster](https://code-aster.org).

## Installation
The MED-library is an external library, which must be installed before the application can be compiled

On Ubuntu, it can be installed with `sudo apt-get install libmedc-dev`. This installs all required dependencies, including HDF5

The source code is available on the Salome website for a manual installation. In this case also HDF5 needs to be installed separately.

Use `MED_ROOT` to specify the path to the MED installation in the CMake of Kratos.
Loading

0 comments on commit 635c2c0

Please sign in to comment.