Skip to content

bmartins95/MSHtoCGNS

 
 

Repository files navigation

MSHtoCGNS

Master: Build Status Develop: Build Status

Generate a msh grid using gmsh 3.0.6

gmsh

Convert it to the CGNS format and open it with paraview

paraview

This project currently supports

MSH IO

CGNS IO

  • cgns 3.10 - 3.4.0
  • HDF mothernode
  • read/write unstructured grids composed of linear elements
  • write simulation results


Dependencies

To build, it is necessary

In Arch Linux/Manjaro, all dependencies may be installed through LibraryInstaller. Just set the following options in Settings.py

libraries = {
    "openmpi"  : {"version" : "4.0.2" , "install" : True},

    "boost"    : {"version" : "1.72.0", "install" : True},

    "metis"    : {"version" : "5.1.0" , "install" : False},
    "petsc"    : {"version" : "3.12.2", "install" : False},

    "hdf5"     : {"version" : "1.10.5", "install" : True},
    "cgns"     : {"version" : "4.1.1" , "install" : True},
    "mshtocgns": {"version" : "4.0.0" , "install" : True},

    "dei"      : {"version" : "1.0.0" , "install" : False},

    "muparser" : {"version" : "2.2.6" , "install" : False},

    "triangle" : {"version" : "1.6.0" , "install" : False},
    "tetgen"   : {"version" : "1.5.1" , "install" : False}
}

In Ubuntu 18.04, once the first four dependencies have been installed, you may install Boost and CGNS by executing setup.sh. This script will install shared libraries in release variant.

Build

Simply execute

$ mkdir build
$ cd build
$ cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=TRUE
$ make
$ make test

If you would like to install

$ make install

Convert

The file MSHtoCGNS.json, located in Zeta/, specifies the paths to the msh files (inputs) and the path where the directory containing the CGNS files will be created (output). Thus, once you have set this, you may execute

$ ./MSHtoCGNS

Simulate

Simulation input files are read through the CgnsReader.

CgnsReader cgnsReader(std::string filePath);
boost::shared_ptr<GridData> gridData{cgnsReader.gridData};

The GridData, in turn, holds vertices coordinates, elements connectivity and the sections they belong to.

struct GridData {
    int dimension;

    std::vector<std::array<double, 3>> coordinates;

    std::vector<std::vector<int>> connectivities;

    std::vector<SectionData> sections;

    int numberOfLocalVertices;
};

Note that the element type is in the connectivity std::vector front, and the element index is at the connectivity std::vector back. As in a CGNS file, the sections hold a contiguous partition of elements -- its information is stored in the SectionData.

struct SectionData {
    SectionData() = default;

    SectionData(std::string name, int dimension, int begin, int end, std::vector<int> vertices) :
        name(name), dimension(dimension), begin(begin), end(end), vertices(vertices) {}

    std::string name;
    int dimension;
    int begin;
    int end;
    std::vector<int> vertices;
};

It is necessary to remark that: boundaries are sections where the boundary conditions are applied, regions are employed to define different physical properties throughout the domain, and wells may be associated to source terms.

Finally, the CgnsWriter is used to write the simulation results in the output file.

class CgnsWriter : public CgnsOpener {
    public:
        CgnsWriter() = default;
        CgnsWriter(std::string filePath, std::string gridLocation);

        void writeSolution(std::string name);
        void writeSolution(double timeValue);

        void writeField(std::string name, const std::vector<double>& values);
        void writeField(std::string name, const std::vector<int>& values);

        void finalizeTransient();

        ...
    }

Easily visualised results with paraview.

gmsh gmsh

gmsh gmsh


Import

MSHtoCGNS may be easily imported to any project using CMake, just make sure FindMSHtoCGNS.cmake is on your CMAKE_MODULE_PATH. Hence, you may use this snippet

set (MSHTOCGNS_DIR $ENV{MSHTOCGNS_DIR}/${BUILD_TYPE}/${LIBRARY_TYPE})
find_package (MSHtoCGNS REQUIRED)
if (MSHTOCGNS_FOUND)
    include_directories (${MSHTOCGNS_INCLUDE_DIR})
endif ()

...

target_link_libraries (${_target} ${MSHTOCGNS_LIBRARIES})

Usually,

$ENV{MSHTOCGNS_DIR} is set to a directory such as /home/felipe/Libraries/mshtocgns-0.16.0

${BUILD_TYPE} is the lower case ${CMAKE_BUILD_TYPE} - release OR debug

${LIBRARY_TYPE} is the lower case library type - shared OR static

You may also set ${MSHTOCGNS_DIR} (on your project's CMakeLists.txt) to the installation directory of MSHtoCGNS.


Note

For MSH file format version 4.1, geometrical entities may be associated to none or a single physical entity. Otherwise, the MSH reader may not work properly.

About

An Interface to Numerical Simulation I/O

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C++ 61.9%
  • CMake 37.4%
  • Shell 0.7%