Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 8564f12b authored by MAUNOURY Matthieu's avatar MAUNOURY Matthieu
Browse files

Read cgns and write meshb working

parent 0fe9a309
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@ objects/
.qmake.stash
.DS_Store
build
*.meshb
......@@ -6,7 +6,7 @@
cmake_minimum_required (VERSION 3.0.1)
project(gmf2CGNS C CXX Fortran)
project(cgns2meshb C CXX Fortran)
if (WIN32)
set (CMAKE_C_FLAGS -DWIN32)
......@@ -42,12 +42,19 @@ find_package(HDF5 REQUIRED)
if(HDF5_FOUND)
message("HDF5 has been found")
message("HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
# include_directories (${HDF5_INCLUDE_DIRS})
message("HDF5_INCLUDE_DIR: ${HDF5_INCLUDE_DIR}")
message("HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
set (HDF5_TOOLS_DIR ${HDF5_SOURCE_DIR}/tools)
set (LINK_LIBS ${LINK_LIBS} ${HDF5_LIBRARIES})
message (STATUS "HDF5-${HDF5_VERSION_STRING} found: INC=${HDF5_INCLUDE_DIR} TOOLS=${HDF5_TOOLS_DIR} HDF5_BUILD_SHARED_LIBS=${HDF5_BUILD_SHARED_LIBS}")
include_directories (${HDF5_INCLUDE_DIR})
set (HDF5_LIBRARY ${LINK_LIBS})
message (STATUS "HDF5 link libs: ${LINK_LIBS}")
else()
message (WARNING "
HDF5 could not be found.")
endif()
include_directories (${PROJECT_SOURCE_DIR}/sources)
add_subdirectory (sources)
# Prerequisite: install CGNS with hdf5 (following help markdown of https://github.com/CGNS/CGNS)
Go to a directory where to install CGNS\
git clone -b master https://github.com/CGNS/CGNS.git \
cd cgns\
mkdir build\
cd build\
cmake ..\
ccmake .\
=> it opens an interactive menu:
- switch CGNS_ENABLE_HDF5 to ON
- press "c"
- if needed press "e" to quit opened help
- repress "c"
- if needed press "e" to quit opened help
- press "g"
- if needed press "e" to quit opened help
=> a Makefile should have been generated with HDF5 binding\
sudo make\
sudo make install
# Build for *Linux* or *macOS*
Simply follow these steps:
- Clone the repo
......@@ -7,3 +29,8 @@ Simply follow these steps:
- `cmake ..`
- `make`
- `make install`
# How to use
The format is: cgns2meshb xxx.cgns yyy.cgns zzz.cgns (-ascii)
- several cgns files can be provided
- -ascii is optional to define ascii output (binary by default otherwise)
......@@ -3,12 +3,11 @@
# BUILD UTILITIES
#################
#message("add add_executable")
#message("libMeshb_LIBRARIES: ${libMeshb_LIBRARIES}")
#message("VTK_LIBRARIES: ${VTK_LIBRARIES}")
#message("VTK_INCLUDE_DIRS: ${VTK_INCLUDE_DIRS}")
message("libMeshb_LIBRARIES: ${libMeshb_LIBRARIES}")
message("LINK_LIBRARIES: ${LINK_LIBRARIES}")
message("HDF5_LIBRARY: ${HDF5_LIBRARY}")
message("HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
add_executable(cgns2meshb cgns2meshb.cpp msh.c)
target_link_libraries(cgns2meshb ${libMeshb_LIBRARIES} ${LINK_LIBRARIES} ${VTK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(cgns2meshb ${libMeshb_LIBRARIES} ${LINK_LIBRARIES} ${HDF5_LIBRARY} ${LINK_LIBS} /usr/local/lib/libcgns.dylib ${CMAKE_THREAD_LIBS_INIT})
install (TARGETS cgns2meshb DESTINATION bin COMPONENT applications)
......@@ -14,81 +14,100 @@ extern "C"
#include "libmeshb7.h"
static inline int isParameter(char *str)
{
if (str == NULL)
return 0;
if (str[0] == '-')
return 0;
return 1;
}
int main(int argc, char **argv)
{
printf(" \n");
printf(" ----------------------------------------------------------------------- \n");
printf("| |\n");
printf("| CGNS2MESHB |\n");
printf("| cgns2meshb |\n");
printf("| |\n");
printf(" -----------------------------------------------------------------------\n");
printf(" \n");
VizObject *iObj = NULL;
int i;
char InpMshNam[1024], noMshNam[1024], noSolNam[1024], OutMshNam[1024], OutSolNam[1024];
int ierro;
bool ascii = false;
VizObject *Obj_surf = NULL;
VizIntStatus status;
int ierro, ierrsol, dim;
int ithSol, nbrSol, nbrtmp, SolAtEntTyp, iter, deg, nbrNod, nbrNodSol;
double tim;
double *sol = NULL;
char OutMshNam[1024], OutSolNam[1024], bufNam[1024], noMshNam[1024];
int i, iin = 0, isol = 0, iout = 0;
double t0 = GetWallClock();
if (argc < 3)
if (argc < 2)
{
cout << " ERROR: missing arguments" << endl;
goto errormessage;
errormessage: //-- error message
printf("\n");
cout << " The format is: cgns2meshb -in xxx.mesh[b] -sol xxx.sol[b] -out xxx" << endl;
cout << " where -in is required to define the input mesh files" << endl;
cout << " -sol is optional to define the input solution files" << endl;
cout << " -out is optional to define the output mesh/sol files" << endl;
cout << " The format is: cgns2meshb xxx.cgns yyy.cgns zzz.cgns (-ascii)" << endl;
cout << " several cgns files can be provided" << endl;
cout << " -ascii is optional to define ascii output (binary by default otherwise)" << endl;
return 0;
}
//-- read parameters
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-in") == 0)
iin = i + 1;
if (strcmp(argv[i], "-sol") == 0)
isol = i + 1;
if (strcmp(argv[i], "-out") == 0)
iout = i + 1;
if (strcmp(argv[i], "-ascii") == 0)
ascii = true;
}
if (iin == 0)
{
cout << " ERROR: -in is missing" << endl;
return 0;
}
if (isol == 0)
isol = iin; //-- no solution file given
ierro = viz_NewInterface(&iObj);
if (ierro != 0)
for (i = 1; i < argc; i++)
{
printf(" viz_NewInterface status %d \n", ierro);
if ((isParameter(argv[i]) == 1))
{
sprintf(InpMshNam, "%s", argv[i]);
sprintf(noMshNam, "%s", InpMshNam);
if (strstr(InpMshNam, ".cgns") != NULL)
{
//-- cgns file found
printf("Case of cgns file: %s\n", argv[i]);
noMshNam[strstr(InpMshNam, ".cgns") - InpMshNam] = '\0'; // check if it has the extension .cgns[b] and remove it if it is the case
sprintf(OutMshNam, "%s", noMshNam);
sprintf(OutSolNam, "%s", noMshNam);
if (ascii)
strcat(OutMshNam, ".mesh");
else
strcat(OutMshNam, ".meshb");
if (ascii)
strcat(OutSolNam, ".sol");
else
strcat(OutSolNam, ".solb");
ierro = viz_NewInterface(&Obj_surf);
if (ierro != 0)
printf(" viz_NewInterface status %d \n", ierro);
ierro = viz_OpenMesh(Obj_surf, InpMshNam, &status);
if (ierro != VIZINT_SUCCESS)
printf(" viz_OpenMesh failed error %3d : %s\n", ierro, status.ErrMsg);
else
printf(" %%%% %s OPENED\n", status.InfoMsg);
viz_PrintMeshInfo(Obj_surf, &status);
ierro = viz_WriteMesh(Obj_surf, OutMshNam, &status);
if (ierro != VIZINT_SUCCESS)
printf(" viz_WriteMesh failed error %3d : %s\n", ierro, status.ErrMsg);
else
printf(" %%%% Mesh written in %s\n", status.InfoMsg);
}
}
}
double t1 = GetWallClock();
ierro = viz_OpenMesh(iObj, argv[iin], &status);
double t2 = GetWallClock();
printf(" cpu time to open the mesh %lg (s) \n", t2 - t1);
if (ierro != VIZINT_SUCCESS)
printf(" viz_OpenMesh failed error %3d : %s\n", ierro, status.ErrMsg);
else
printf(" %%%% %s OPENED\n", status.InfoMsg);
viz_PrintMeshInfo(iObj, &status);
viz_GetDimension(iObj, &dim, &status);
t2 = GetWallClock();
printf(" Total cpu time %lg (s) \n", t2 - t0);
cout << "\n Thank you for using cgns2meshb" << endl;
......
This diff is collapsed.
......@@ -9,6 +9,7 @@
#include <string.h>
#include "numbering.h"
#include "cgnslib.h"
typedef float float3[3];
typedef double double2[2];
......@@ -267,4 +268,35 @@ int1 *viz_GetIndicesArray(VizObject *Obj, int Typ, int1 *nbrEnt, int1 *sizEnt, V
double GetWallClock();
typedef long long int lint;
/* reallocate a sequence of arrays */
static inline void *viz_reallocate(lint size, void *pcur)
{
if (pcur != NULL)
{
free(pcur);
pcur = NULL;
}
//printf(" size %d \n",size);
return malloc(size);
}
int viz_WriteMesh(VizObject *iObj, const char *MshFile, VizIntStatus *status); //--- writes the current mesh stored in the VizObject
int viz_WriteMeshLibMeshb(VizObject *iObj, const char *MshFile, VizIntStatus *status); //--- writes the current mesh stored in the VizObject
int viz_OpenMeshCGNS(VizObject *iObj, const char *MshFile, VizIntStatus *status);
int viz_setMeshArraysFromCGNSFile(int Mode, const char *MshNam, int1 *Dim, int1 *NbrVer, int1 *NbrCor, int1 *NbrEdg, int1 *NbrTri, int1 *NbrQua, int1 *NbrTet, int1 *NbrPyr, int1 *NbrPri, int1 *NbrHex,
int1 *NbrP2Tri, int1 *NbrQ2Qua, int1 *NbrP2Tet, int1 *NbrP2Pyr, int1 *NbrP2Pri, int1 *NbrQ2Hex,
int1 *NbrP3Tri, int1 *NbrQ3Qua, int1 *NbrP3Tet, int1 *NbrP3Pyr, int1 *NbrP3Pri, int1 *NbrQ3Hex,
int1 *NbrP4Tri, int1 *NbrQ4Qua, int1 *NbrP4Tet, int1 *NbrP4Pyr, int1 *NbrP4Pri, int1 *NbrQ4Hex,
double3 *Crd, int1 *Cor, int2 *Edg, int1 *EdgRef, int4 *Qua, int1 *QuaRef, int3 *Tri, int1 *TriRef, int4 *Tet, int1 *TetRef, int5 *Pyr, int1 *PyrRef, int6 *Pri, int1 *PriRef, int8 *Hex, int1 *HexRef,
int6 *P2Tri, int1 *P2TriRef, int9 *Q2Qua, int1 *Q2QuaRef, int10 *P2Tet, int1 *P2TetRef, int14 *P2Pyr, int1 *P2PyrRef, int18 *P2Pri, int1 *P2PriRef, int27 *Q2Hex, int1 *Q2HexRef,
int10 *P3Tri, int1 *P3TriRef, int16 *Q3Qua, int1 *Q3QuaRef, int20 *P3Tet, int1 *P3TetRef, int30 *P3Pyr, int1 *P3PyrRef, int40 *P3Pri, int1 *P3PriRef, int64 *Q3Hex, int1 *Q3HexRef,
int15 *P4Tri, int1 *P4TriRef, int25 *Q4Qua, int1 *Q4QuaRef, int35 *P4Tet, int1 *P4TetRef, int55 *P4Pyr, int1 *P4PyrRef, int75 *P4Pri, int1 *P4PriRef, int125 *Q4Hex, int1 *Q4HexRef,
VizIntStatus *status);
int viz_writeCGNSFileFromMeshArrays(const char *MshNam, int1 NbrVer, int1 NbrTri, int1 NbrQua, int1 NbrTet, int1 NbrPyr, int1 NbrPri, int1 NbrHex,
double3 *Crd, int4 *Qua, int1 *QuaRef, int3 *Tri, int1 *TriRef, int4 *Tet, int5 *Pyr, int6 *Pri, int8 *Hex, VizIntStatus *status);
int viz_OpenSolutionCGNS(VizObject *iObj, const char *SolFile, VizIntStatus *status);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment