Skip to content

Commit

Permalink
Merge pull request #11580 from KratosMultiphysics/med/fixes
Browse files Browse the repository at this point in the history
[MEDApp] Minor Fixes
  • Loading branch information
matekelemen authored Sep 23, 2023
2 parents f69333d + ca10692 commit 54f69c8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
9 changes: 9 additions & 0 deletions applications/MedApplication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ The Med Application an interface to the MED-library. This library writes med-fil
## Installation
The MED-library is an external library, which must be installed before the application can be compiled

### Ubuntu

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.

### Arch / Manjaro

Packages related to *Salome* and *MED* for arch-based distros can be installed from the [AUR](https://en.wikipedia.org/wiki/Arch_Linux#Arch_User_Repository_(AUR)). The MedApplication requires [med-serial](https://aur.archlinux.org/packages/med-serial) (for non-MPI builds) or [med-openmpi](https://archlinux.org/packages/extra/x86_64/med-openmpi/) (for MPI builds with OpenMPI).
```
sudo pacman -S med-serial med-openmpi
```
31 changes: 20 additions & 11 deletions applications/MedApplication/custom_io/med_model_part_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ std::function<void(std::vector<T>&)> GetReorderFunction(const med_geometry_type
};

case MED_TRIA6:
KRATOS_ERROR << "MED_TRIA6 is not implemented!" << std::endl;
return [](auto& rConnectivities) -> void {
CheckConnectivitiesSize(6, rConnectivities);
std::swap(rConnectivities[1], rConnectivities[2]);
std::swap(rConnectivities[3], rConnectivities[5]);
};

case MED_QUAD4:
return [](auto& Connectivities){
Expand All @@ -100,6 +104,14 @@ std::function<void(std::vector<T>&)> GetReorderFunction(const med_geometry_type
case MED_QUAD9: // should be same as MED_QUAD8
KRATOS_ERROR << "MED_QUAD9 is not implemented!" << std::endl;

case MED_TETRA10:
return [](auto& rConnectivities) -> void {
CheckConnectivitiesSize(10, rConnectivities);
std::swap(rConnectivities[1], rConnectivities[2]);
std::swap(rConnectivities[4], rConnectivities[6]);
std::swap(rConnectivities[8], rConnectivities[9]);
};

case MED_PYRA5:
KRATOS_ERROR << "MED_PYRA5 is not implemented!" << std::endl;

Expand Down Expand Up @@ -311,11 +323,7 @@ class MedModelPartIO::MedFileHandler

~MedFileHandler()
{
KRATOS_TRY

KRATOS_WARNING_IF("MedModelPartIO", MEDfileClose(mFileHandle) < 0) << "Closing of file " << mFileName << " failed!" << std::endl;

KRATOS_CATCH("")
}

private:
Expand All @@ -340,8 +348,6 @@ void MedModelPartIO::ReadModelPart(ModelPart& rThisModelPart)
{
KRATOS_TRY

using NodePointerType = ModelPart::NodeType::Pointer;

KRATOS_ERROR_IF_NOT(mpFileHandler->IsReadMode()) << "MedModelPartIO needs to be created in read mode to read a ModelPart!" << std::endl;

// reading nodes
Expand Down Expand Up @@ -430,16 +436,19 @@ void MedModelPartIO::ReadModelPart(ModelPart& rThisModelPart)

std::vector<IndexType> geom_node_ids(num_nodes_geo_type);

for (std::size_t i=0; i<num_geometries; ++i) {
for (std::size_t i=0; i<static_cast<std::size_t>(num_geometries); ++i) {
for (int j=0; j<num_nodes_geo_type; ++j) {
const int node_idx = i*num_nodes_geo_type + j;
geom_node_ids[j] = connectivity[node_idx];
}
reorder_fct(geom_node_ids);
rThisModelPart.CreateNewGeometry(kratos_geo_name, geom_node_ids);
}

num_geometries_total += num_geometries;
KRATOS_ERROR_IF(std::numeric_limits<decltype(num_geometries_total)>::max() == num_geometries_total)
<< "number of geometries read (" << num_geometries_total << ") exceeds the capacity of the index type";
rThisModelPart.CreateNewGeometry(kratos_geo_name,
num_geometries_total++,
geom_node_ids);
}

KRATOS_INFO("MedModelPartIO") << "Read " << num_geometries << " geometries of type " << kratos_geo_name << std::endl;
}
Expand Down
2 changes: 2 additions & 0 deletions applications/MedApplication/med_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

// Those dummy structs are necessary when the MED-library is compiled with MPI support.
// Then the header also contains functions which use those MPI-types
#ifndef KRATOS_USING_MPI
struct MPI_Comm;
struct MPI_Info;
#endif

// External includes
#include "med.h"
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ namespace Kratos::Testing {
KRATOS_TEST_CASE_IN_SUITE(MedModelpartIO_NonExistingFile_read, KratosMedFastSuite)
{
const std::filesystem::path file_path(this->Name() + ".txt");
KRATOS_CHECK_IS_FALSE(std::filesystem::exists(file_path)); // make sure there are no leftovers
KRATOS_EXPECT_FALSE(std::filesystem::exists(file_path)); // make sure there are no leftovers

KRATOS_CHECK_EXCEPTION_IS_THROWN(
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
MedModelPartIO dummy(file_path),
"File \""+file_path.string()+"\" does not exist!");

KRATOS_CHECK_IS_FALSE(std::filesystem::exists(file_path));
KRATOS_EXPECT_FALSE(std::filesystem::exists(file_path));
}

KRATOS_TEST_CASE_IN_SUITE(MedModelpartIO_NonExistingFile_write, KratosMedFastSuite)
{
const std::filesystem::path file_path(this->Name() + ".txt");
KRATOS_CHECK_IS_FALSE(std::filesystem::exists(file_path)); // make sure there are no leftovers
KRATOS_EXPECT_FALSE(std::filesystem::exists(file_path)); // make sure there are no leftovers

MedModelPartIO(file_path, IO::WRITE);
KRATOS_CHECK(std::filesystem::exists(file_path));
KRATOS_EXPECT_TRUE(std::filesystem::exists(file_path));

std::filesystem::remove(file_path); // clean leftover
}
Expand All @@ -48,7 +48,7 @@ KRATOS_TEST_CASE_IN_SUITE(MedModelpartIO_TextFile, KratosMedFastSuite)
const std::filesystem::path file_path(this->Name() + ".txt");
std::ofstream output(file_path); // create a dummy file (that is not a hdf file)

KRATOS_CHECK_EXCEPTION_IS_THROWN(
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
MedModelPartIO dummy(file_path),
"A problem with HDF occured while trying to open file \""+file_path.string()+"\"!");

Expand Down

0 comments on commit 54f69c8

Please sign in to comment.