<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000'>Hello,<br>I added a build with cgns on the buildbot<br>http://gnep.mcs.anl.gov:8010/builders/moab-cgns<br>Buildbot still runs on ubuntu 10.04, on gnep;<br>this build uses a gnep-built cgns library, which is located here:<br>/homes/fathom/3rdparty/cgns/cgns314<br><br>On my machine (ubuntu 12.04), I have tested with this cgns<br>/homes/fathom/3rdparty/cgns<br><br>It works for me, but not for Rajeev. There are still some quirks related to hdf5 library not linked correctly.<br><br>So far, all these cgns builds are static. This reader/writer works in serial, and it is a work done by Carlos Breviglieri and Junior Junqueira. Thank you!<br><br>Best regards,<br>Iulian <br><br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>commits-noreply@bitbucket.org<br><b>To: </b>moab-dev@mcs.anl.gov<br><b>Sent: </b>Wednesday, November 20, 2013 10:40:20 AM<br><b>Subject: </b>[MOAB-dev] commit/MOAB: iulian07: first pass at CGNS reader / writer<br><br>1 new commit in MOAB:<br><br>https://bitbucket.org/fathomteam/moab/commits/6cccf6afd097/<br>Changeset: 6cccf6afd097<br>Branch: master<br>User: iulian07<br>Date: 2013-11-20 17:39:28<br>Summary: first pass at CGNS reader / writer<br><br>integrate contributions from Carlos Breviglieri and Junior<br>Junqueira<br><br>Affected #: 14 files<br><br>diff --git a/Makefile.am b/Makefile.am<br>index 1c91622..b8c3c9e 100644<br>--- a/Makefile.am<br>+++ b/Makefile.am<br>@@ -48,7 +48,7 @@ install-data-hook:<br> echo -n "SET(MOAB_LIBRARIES \"" >> $(DESTDIR)$(cfgdir)/MOABConfig.cmake<br> # next line: get the post-substitution set of link commands, then filter out leading<br> # and trailing spaces, then terminate with close-quote and close-paren<br>- echo -n "@EXPORT_LDFLAGS@ -L$(MOAB_LIBDIR) -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@" | \<br>+ echo -n "@EXPORT_LDFLAGS@ -L$(libdir) -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @CGNS_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@" | \<br> sed -e 's/^ *//;s/ *$$/\")\n/' >> $(DESTDIR)$(cfgdir)/MOABConfig.cmake<br> <br> # Generate a file to be installed in $libdir containing the configuration<br><br>diff --git a/MeshFiles/unittest/io/2d_naca0012.cgns b/MeshFiles/unittest/io/2d_naca0012.cgns<br>new file mode 100644<br>index 0000000..4ce0452<br>Binary files /dev/null and b/MeshFiles/unittest/io/2d_naca0012.cgns differ<br><br>diff --git a/MeshFiles/unittest/io/Makefile.am b/MeshFiles/unittest/io/Makefile.am<br>index fb8a265..b4077d0 100644<br>--- a/MeshFiles/unittest/io/Makefile.am<br>+++ b/MeshFiles/unittest/io/Makefile.am<br>@@ -19,6 +19,7 @@ EXTRA_DIST = HommeMapping.nc \<br> test.unv \<br> sample.stl \<br> three.smf \<br>- mpasx1.642.t.2.nc<br>+ mpasx1.642.t.2.nc \<br>+ 2d_naca0012.cgns<br> <br> <br><br>diff --git a/config/cgns.m4 b/config/cgns.m4<br>new file mode 100644<br>index 0000000..16b19e3<br>--- /dev/null<br>+++ b/config/cgns.m4<br>@@ -0,0 +1,92 @@<br>+#######################################################################################<br>+# Check for CGNS library<br>+# Sets HAVE_CGNS to 'yes' or 'no'<br>+# If HAVE_CGNS == yes, then exports:<br>+# CGNS_CPPFLAGS<br>+# CGNS_LDFLAGS<br>+# CGNS_LIBS<br>+#######################################################################################<br>+AC_DEFUN([FATHOM_CHECK_CGNS],[<br>+<br>+AC_MSG_CHECKING([if CGNS support is enabled])<br>+AC_ARG_WITH(cgns, <br>+[AC_HELP_STRING([--with-cgns<:@=DIR@:>@], [Specify CGNS library to use for CGNS file format])<br>+AC_HELP_STRING([--without-cgns], [Disable support for CGNS file format])],<br>+[CGNS_ARG=$withval<br>+DISTCHECK_CONFIGURE_FLAGS="$DISTCHECK_CONFIGURE_FLAGS --with-cgns=\"${withval}\""<br>+]<br>+, [CGNS_ARG=])<br>+if test "xno" != "x$CGNS_ARG"; then<br>+ AC_MSG_RESULT([yes])<br>+else<br>+ AC_MSG_RESULT([no])<br>+fi<br>+<br>+ # if CGNS support is not disabled<br>+HAVE_CGNS=no<br>+if test "xno" != "x$CGNS_ARG"; then<br>+ HAVE_CGNS=yes<br>+ <br>+ # if a path is specified, update LIBS and INCLUDES accordingly<br>+ if test "xyes" != "x$CGNS_ARG" && test "x" != "x$CGNS_ARG"; then<br>+ if test -d "${CGNS_ARG}/lib"; then<br>+ CGNS_LDFLAGS="-L${CGNS_ARG}/lib"<br>+ elif test -d "${CGNS_ARG}"; then<br>+ CGNS_LDFLAGS="-L${CGNS_ARG}"<br>+ else<br>+ AC_MSG_ERROR("$CGNS_ARG is not a directory.")<br>+ fi<br>+ if test -d "${CGNS_ARG}/include"; then<br>+ CGNS_CPPFLAGS="-I${CGNS_ARG}/include"<br>+ elif test -d "${CGNS_ARG}/inc"; then<br>+ CGNS_CPPFLAGS="-I${CGNS_ARG}/inc"<br>+ else<br>+ CGNS_CPPFLAGS="-I${CGNS_ARG}"<br>+ fi<br>+ fi<br>+ <br>+ old_CPPFLAGS="$CPPFLAGS"<br>+ CPPFLAGS="$CGNS_CPPFLAGS $CPPFLAGS"<br>+ old_LDFLAGS="$LDFLAGS"<br>+ LDFLAGS="$CGNS_LDFLAGS $HDF5_LDFLAGS $LDFLAGS"<br>+ <br>+ # Check for C library<br>+ AC_LANG_PUSH([C])<br>+<br>+ AC_CHECK_HEADER([cgnslib.h], [],<br>+ [AC_MSG_WARN([[CGNS header not found.]]); HAVE_CGNS=no] )<br>+<br>+ # Check if cgns is usable by itself<br>+ AC_CHECK_LIB( [cgns], [cg_open], [CGNS_LIBS="-lcgns"], [<br>+ # Check if cgns is usable with HDF5<br>+ unset ac_cv_lib_cgns<br>+ unset ac_cv_lib_cgns_cg_open<br>+ # If we haven't already looked for HDF5 libraries, again now incase<br>+ # they're in the CGNS lib directory.<br>+ FATHOM_DETECT_HDF5_LIBS<br>+ LDFLAGS="$LDFLAGS $HDF5_LDFLAGS"<br>+ AC_CHECK_LIB( [cgns], [cg_open], [CGNS_LIBS="-lcgns -lhdf5_hl"], [<br>+ # Try one more time with HDF5 and libcurl<br>+ unset ac_cv_lib_cgns<br>+ unset ac_cv_lib_cgns_cg_open<br>+ AC_CHECK_LIB( [cgns], [cg_open], [CGNS_LIBS="-lcgns -lhdf5_hl -lcurl"], <br>+ [HAVE_CGNS=no], [-lhdf5_hl $HDF5_LIBS -lcurl] )],<br>+ [-lhdf5_hl $HDF5_LIBS] )],<br>+ )<br>+ <br>+ CPPFLAGS="$old_CPPFLAGS"<br>+ LDFLAGS="$old_LDFLAGS"<br>+ AC_LANG_POP([C])<br>+<br>+ if test "x$HAVE_CGNS" = "xno"; then<br>+ if test "x$CGNS_ARG" != "x"; then <br>+ AC_MSG_ERROR("CGNS not found or not working")<br>+ else<br>+ AC_MSG_WARN("CGNS support disabled")<br>+ fi<br>+ CGNS_CPPFLAGS=<br>+ CGNS_LDFLAGS=<br>+ fi<br>+fi<br>+<br>+]) # FATHOM_HAVE_CGNS<br><br>diff --git a/configure.ac b/configure.ac<br>index bdc225b..ea22a5e 100644<br>--- a/configure.ac<br>+++ b/configure.ac<br>@@ -446,6 +446,22 @@ AM_CPPFLAGS="$PNETCDF_CPPFLAGS $AM_CPPFLAGS"<br> EXPORT_LDFLAGS="$PNETCDF_LDFLAGS $EXPORT_LDFLAGS"<br> AC_SUBST(PNETCDF_LIBS)<br> <br>+################################################################################<br>+# CGNS OPTIONS<br>+################################################################################<br>+<br>+old_LDFLAGS="$LDFLAGS"<br>+LDFLAGS="$LDFLAGS $HDF5_LDFLAGS"<br>+FATHOM_CHECK_CGNS<br>+LDFLAGS="$old_LDFLAGS"<br>+if test "xno" != "x$HAVE_CGNS"; then<br>+ AM_CPPFLAGS="$AM_CPPFLAGS -DCGNS_FILE"<br>+fi<br>+AM_CONDITIONAL(CGNS_FILE, [test "xno" != "x$HAVE_CGNS"])<br>+AM_CPPFLAGS="$CGNS_CPPFLAGS $AM_CPPFLAGS"<br>+EXPORT_LDFLAGS="$CGNS_LDFLAGS $EXPORT_LDFLAGS"<br>+AC_SUBST(CGNS_LIBS)<br>+<br> <br> #################################################################################<br> # Documentation<br><br>diff --git a/moab.make.in b/moab.make.in<br>index 45f80de..4519175 100644<br>--- a/moab.make.in<br>+++ b/moab.make.in<br>@@ -16,7 +16,7 @@ MOAB_FFLAGS = @FFLAGS@<br> MOAB_FCFLAGS = @FCFLAGS@<br> MOAB_LDFLAGS = @EXPORT_LDFLAGS@<br> <br>-MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@ @ZOLTAN_LIBS@ <br>+MOAB_LIBS_LINK = ${MOAB_LDFLAGS} -L${MOAB_LIBDIR} -lMOAB @LIBS@ @PNETCDF_LIBS@ @NETCDF_LIBS@ @CGNS_LIBS@ @HDF5_LIBS@ @CCMIO_LIBS@ @CGM_LIBS@ @ZOLTAN_LIBS@ <br> <br> MOAB_CXX = @CXX@<br> MOAB_CC = @CC@<br><br>diff --git a/src/ReaderWriterSet.cpp b/src/ReaderWriterSet.cpp<br>index 8185b34..5015a7f 100644<br>--- a/src/ReaderWriterSet.cpp<br>+++ b/src/ReaderWriterSet.cpp<br>@@ -1,16 +1,16 @@<br> /**<br> * MOAB, a Mesh-Oriented datABase, is a software component for creating,<br> * storing and accessing finite element mesh data.<br>- * <br>+ *<br> * Copyright 2004 Sandia Corporation. Under the terms of Contract<br> * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government<br> * retains certain rights in this software.<br>- * <br>+ *<br> * This library is free software; you can redistribute it and/or<br> * modify it under the terms of the GNU Lesser General Public<br> * License as published by the Free Software Foundation; either<br> * version 2.1 of the License, or (at your option) any later version.<br>- * <br>+ *<br> */<br> <br> #include "moab/Core.hpp"<br>@@ -54,11 +54,16 @@<br> #endif<br> <br> // 2nd include of ReadNC in case we have pnetcdf and not netcdf<br>-#ifdef PNETCDF_FILE <br>+#ifdef PNETCDF_FILE<br> # include "ReadNC.hpp"<br> # include "ReadGCRM.hpp"<br> #endif<br> <br>+#ifdef CGNS_FILE<br>+# include "ReadCGNS.hpp"<br>+# include "WriteCGNS.hpp"<br>+#endif<br>+<br> #ifdef CCMIO_FILE<br> # include "ReadCCMIO.hpp"<br> # include "WriteCCMIO.hpp"<br>@@ -83,15 +88,15 @@<br> namespace moab {<br> <br> ReaderWriterSet::ReaderWriterSet( Core* mdb, Error* handler )<br>- : mbCore( mdb ), mbError( handler ) <br>+ : mbCore( mdb ), mbError( handler )<br> {<br> #ifdef HDF5_FILE<br> const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };<br> #ifdef HDF5_PARALLEL<br>- register_factory( ReadHDF5::factory, WriteHDF5Parallel::factory, <br>+ register_factory( ReadHDF5::factory, WriteHDF5Parallel::factory,<br> "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );<br> #else<br>- register_factory( ReadHDF5::factory, WriteHDF5::factory, <br>+ register_factory( ReadHDF5::factory, WriteHDF5::factory,<br> "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );<br> #endif<br> #endif<br>@@ -103,21 +108,26 @@ ReaderWriterSet::ReaderWriterSet( Core* mdb, Error* handler )<br> register_factory( ReadNC::factory, NULL, "Climate NC", "nc", "NC" );<br> #endif<br> <br>+#ifdef CGNS_FILE<br>+ const char* cgns_sufxs[] = { "cgns", NULL };<br>+ register_factory( ReadCGNS::factory, WriteCGNS::factory, "CGNS", cgns_sufxs, "CGNS" );<br>+#endif<br>+<br> register_factory( ReadIDEAS::factory, NULL, "IDEAS format", "unv", "UNV" );<br>- <br>+<br> register_factory( ReadMCNP5::factory, NULL, "MCNP5 format", "meshtal", "MESHTAL" );<br>- <br>+<br> const char* nastran_sufxs[] = { "nas", "bdf", NULL };<br> register_factory( ReadNASTRAN::factory, NULL, "NASTRAN format", nastran_sufxs, "NAS" );<br> <br> register_factory( ReadABAQUS::factory, NULL, "ABAQUS INP mesh format", "abq", "Abaqus mesh" );<br>- <br>+<br> register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );<br>- <br>+<br> register_factory( ReadSms::factory, NULL, "RPI SMS", "sms", "SMS" );<br>- <br>+<br> register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );<br>- <br>+<br> register_factory( ReadSmf::factory, WriteSmf::factory , "QSlim format", "smf", "SMF");<br> <br> #ifdef CGM<br>@@ -131,27 +141,27 @@ ReaderWriterSet::ReaderWriterSet( Core* mdb, Error* handler )<br> register_factory( ReadCGM::factory, NULL, "IGES B-Rep exchange", iges_sufxs, "IGES");<br> #endif<br> <br>-#ifdef NETCDF_FILE <br>+#ifdef NETCDF_FILE<br> register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );<br> #endif<br> <br>-#ifdef CCMIO_FILE <br>+#ifdef CCMIO_FILE<br> const char* ccmio_sufxs[] = { "ccm", "ccmg", NULL };<br> register_factory( ReadCCMIO::factory, WriteCCMIO::factory, "CCMIO files", ccmio_sufxs, "CCMIO");<br> #endif<br> <br>-#ifdef DAMSEL_FILE <br>+#ifdef DAMSEL_FILE<br> const char* damsel_sufxs[] = { "h5", NULL };<br> register_factory( ReadDamsel::factory, WriteDamsel::factory, "Damsel files", damsel_sufxs, "DAMSEL");<br> #endif<br> <br> register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );<br>- <br>+<br> register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );<br>- <br>+<br> const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };<br> register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );<br>- <br>+<br> register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );<br> <br> const char* tetgen_sufxs[] = { "node", "ele", "face", "edge", NULL };<br>@@ -178,7 +188,7 @@ ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,<br> {<br> if (!reader && !writer)<br> return MB_FAILURE;<br>- <br>+<br> // check for duplicate names<br> iterator h = handler_by_name( name );<br> if (h != end()) {<br>@@ -186,7 +196,7 @@ ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,<br> name );<br> return MB_FAILURE;<br> }<br>- <br>+<br> // count extensions and check for duplicates<br> const char* const* iter;<br> for (iter = extensions; *iter; ++iter)<br>@@ -206,7 +216,7 @@ ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,<br> }<br> handlerList.push_back( Handler(reader, writer, name, description, extensions, iter - extensions) );<br> return MB_SUCCESS;<br>-} <br>+}<br> <br> ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,<br> writer_factory_t writer,<br>@@ -218,8 +228,8 @@ ErrorCode ReaderWriterSet::register_factory( reader_factory_t reader,<br> return register_factory( reader, writer, description, extensions, name );<br> }<br> <br>- <br>-ReaderIface* ReaderWriterSet::get_file_extension_reader( <br>+<br>+ReaderIface* ReaderWriterSet::get_file_extension_reader(<br> const std::string& filename ) const<br> {<br> std::string ext = extension_from_filename( filename );<br>@@ -227,7 +237,7 @@ ReaderIface* ReaderWriterSet::get_file_extension_reader(<br> return handler == end() ? NULL : handler->make_reader(mbCore);<br> }<br> <br>-WriterIface* ReaderWriterSet::get_file_extension_writer( <br>+WriterIface* ReaderWriterSet::get_file_extension_writer(<br> const std::string& filename ) const<br> {<br> std::string ext = extension_from_filename( filename );<br>@@ -235,7 +245,7 @@ WriterIface* ReaderWriterSet::get_file_extension_writer(<br> return handler == end() ? NULL : handler->make_writer(mbCore);<br> }<br> <br>-std::string ReaderWriterSet::extension_from_filename( <br>+std::string ReaderWriterSet::extension_from_filename(<br> const std::string& filename )<br> {<br> std::string::size_type idx = filename.find_last_of( "." );<br>@@ -245,11 +255,11 @@ std::string ReaderWriterSet::extension_from_filename(<br> return filename.substr( idx + 1 );<br> }<br> <br>-ReaderWriterSet::Handler::Handler( reader_factory_t read_f, <br>+ReaderWriterSet::Handler::Handler( reader_factory_t read_f,<br> writer_factory_t write_f,<br> const char* nm,<br>- const char* desc, <br>- const char* const* ext, <br>+ const char* desc,<br>+ const char* const* ext,<br> int num_ext )<br> : mReader(read_f), mWriter(write_f), mName(nm), mDescription(desc), mExtensions(num_ext)<br> {<br>@@ -261,45 +271,45 @@ ReaderWriterSet::Handler::Handler( reader_factory_t read_f,<br> #define strcasecmp(A,B) _stricmp( A, B )<br> #endif<br> <br>-ReaderWriterSet::iterator <br>+ReaderWriterSet::iterator<br> ReaderWriterSet::handler_from_extension( const std::string& ext,<br> bool with_reader,<br> bool with_writer ) const<br> {<br> iterator iter;<br> std::vector<std::string>::const_iterator siter;<br>- <br>+<br> // try case-sensitive compare<br> for (iter = begin(); iter != end(); ++iter)<br> {<br> if ((with_reader && !iter->have_reader()) ||<br> (with_writer && !iter->have_writer()))<br> continue;<br>- <br>+<br> for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)<br> if (*siter == ext)<br> return iter;<br> }<br>- <br>+<br> // try case-insensitive compare<br> for (iter = begin(); iter != end(); ++iter)<br> {<br> if ((with_reader && !iter->have_reader()) ||<br> (with_writer && !iter->have_writer()))<br> continue;<br>- <br>+<br> for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)<br> if (0 == strcasecmp( siter->c_str(), ext.c_str() ))<br> return iter;<br> }<br>- <br>+<br> return end();<br> }<br> <br>-bool ReaderWriterSet::Handler::reads_extension(const char *ext) const <br>+bool ReaderWriterSet::Handler::reads_extension(const char *ext) const<br> {<br> if (!have_reader()) return false;<br>- <br>+<br> std::vector<std::string>::const_iterator siter;<br> for (siter = mExtensions.begin(); siter != mExtensions.end(); ++siter)<br> if (!(*siter).compare(ext)) return true;<br>@@ -308,10 +318,10 @@ bool ReaderWriterSet::Handler::reads_extension(const char *ext) const<br> return false;<br> }<br> <br>-bool ReaderWriterSet::Handler::writes_extension(const char *ext) const <br>+bool ReaderWriterSet::Handler::writes_extension(const char *ext) const<br> {<br> if (!have_writer()) return false;<br>- <br>+<br> std::vector<std::string>::const_iterator siter;<br> for (siter = mExtensions.begin(); siter != mExtensions.end(); ++siter)<br> if (!(*siter).compare(ext)) return true;<br>@@ -335,7 +345,7 @@ bool ReaderWriterSet::Handler::operator==( const char* nm ) const<br> return false;<br> return *nm == '\0';<br> }<br>- <br>+<br> } // namespace moab<br> <br> <br><br>diff --git a/src/io/Makefile.am b/src/io/Makefile.am<br>index 60caa48..09fe3d3 100644<br>--- a/src/io/Makefile.am<br>+++ b/src/io/Makefile.am<br>@@ -7,7 +7,7 @@ endif<br> <br> # Things to build<br> noinst_LTLIBRARIES = libmoabio.la <br>-libmoabio_la_LIBADD = $(NETCDF_LIBS) $(PNETCDF_LIBS) $(HDF5_LIBS) <br>+libmoabio_la_LIBADD = $(NETCDF_LIBS) $(PNETCDF_LIBS) $(CGNS_LIBS) $(HDF5_LIBS) <br> <br> AM_CPPFLAGS += -DIS_BUILDING_MB \<br> -I.. -I$(srcdir)/.. -I$(srcdir)/../parallel<br>@@ -43,6 +43,13 @@ if ENABLE_mbzoltan<br> AM_CPPFLAGS += -I$(srcdir)/../../tools/mbzoltan $(ZOLTAN_INC_FLAGS) <br> endif<br> <br>+if CGNS_FILE<br>+ MOAB_CGNS_SRCS = ReadCGNS.cpp ReadCGNS.hpp \<br>+ WriteCGNS.cpp WriteCGNS.hpp<br>+else<br>+ MOAB_CGNS_SRCS =<br>+endif<br>+<br> if HDF5_FILE<br> libmoabio_la_LIBADD += mhdf/libmhdf.la<br> MOAB_HDF5_SRCS = HDF5Common.cpp \<br>@@ -139,6 +146,7 @@ libmoabio_la_SOURCES = \<br> WriteVtk.cpp \<br> WriteVtk.hpp \<br> $(MOAB_NETCDF_SRCS) \<br>+ $(MOAB_CGNS_SRCS) \<br> $(MOAB_HDF5_SRCS) \<br> $(MOAB_CCMIO_SRCS) \<br> $(MOAB_DAMSEL_SRCS) \<br><br>diff --git a/src/io/ReadCGNS.cpp b/src/io/ReadCGNS.cpp<br>new file mode 100644<br>index 0000000..d8f77e8<br>--- /dev/null<br>+++ b/src/io/ReadCGNS.cpp<br>@@ -0,0 +1,613 @@<br>+/**<br>+ * \class ReadCGNS<br>+ * \brief Template for writing a new reader in MOAB<br>+ *<br>+ */<br>+<br>+#include "ReadCGNS.hpp"<br>+#include "Internals.hpp"<br>+#include "moab/Interface.hpp"<br>+#include "moab/ReadUtilIface.hpp"<br>+#include "moab/Range.hpp"<br>+#include "moab/FileOptions.hpp"<br>+#include "MBTagConventions.hpp"<br>+#include "MBParallelConventions.h"<br>+#include "moab/CN.hpp"<br>+<br>+#include <cstdio><br>+#include <assert.h><br>+#include <errno.h><br>+#include <map><br>+#include <set><br>+<br>+#include <iostream><br>+#include <cmath><br>+<br>+namespace moab<br>+{<br>+<br>+ReaderIface* ReadCGNS::factory(Interface* iface)<br>+{<br>+ return new ReadCGNS(iface);<br>+}<br>+<br>+ReadCGNS::ReadCGNS(Interface* impl)<br>+ : mbImpl(impl)<br>+{<br>+ mbImpl->query_interface(readMeshIface);<br>+}<br>+<br>+ReadCGNS::~ReadCGNS()<br>+{<br>+ if (readMeshIface) {<br>+ mbImpl->release_interface(readMeshIface);<br>+ readMeshIface = 0;<br>+ }<br>+}<br>+<br>+<br>+ErrorCode ReadCGNS::read_tag_values(const char* /* file_name */,<br>+ const char* /* tag_name */,<br>+ const FileOptions& /* opts */,<br>+ std::vector<int>& /* tag_values_out */,<br>+ const SubsetList* /* subset_list */)<br>+{<br>+ return MB_NOT_IMPLEMENTED;<br>+}<br>+<br>+<br>+ErrorCode ReadCGNS::load_file(const char* filename,<br>+ const EntityHandle * /*file_set*/,<br>+ const FileOptions& opts,<br>+ const ReaderIface::SubsetList* subset_list,<br>+ const Tag* file_id_tag)<br>+{<br>+<br>+ int num_material_sets = 0;<br>+ const int* material_set_list = 0;<br>+<br>+ if (subset_list) {<br>+ if (subset_list->tag_list_length > 1 &&<br>+ !strcmp(subset_list->tag_list[0].tag_name, MATERIAL_SET_TAG_NAME)) {<br>+ readMeshIface->report_error("CGNS supports subset read only by material ID.");<br>+ return MB_UNSUPPORTED_OPERATION;<br>+ }<br>+ material_set_list = subset_list->tag_list[0].tag_values;<br>+ num_material_sets = subset_list->tag_list[0].num_tag_values;<br>+ }<br>+<br>+<br>+ ErrorCode result;<br>+<br>+ geomSets.clear();<br>+ result = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER,<br>+ globalId, MB_TAG_DENSE | MB_TAG_CREAT, 0);<br>+ if (MB_SUCCESS != result)<br>+ return result;<br>+<br>+ // Create set for more convienient check for material set ids<br>+ std::set<int> blocks;<br>+ for (const int* mat_set_end = material_set_list + num_material_sets;<br>+ material_set_list != mat_set_end; ++material_set_list)<br>+ blocks.insert(*material_set_list);<br>+<br>+ // Map of ID->handle for nodes<br>+ std::map<long, EntityHandle> node_id_map;<br>+<br>+<br>+ // save filename to member variable so we don't need to pass as an argument<br>+ // to called functions<br>+ fileName = filename;<br>+<br>+ // process options; see src/FileOptions.hpp for API for FileOptions class, and doc/metadata_info.doc for<br>+ // a description of various options used by some of the readers in MOAB<br>+ result = process_options(opts);<br>+ if (MB_SUCCESS != result) {<br>+ readMeshIface->report_error("%s: problem reading options\n", fileName);<br>+ return result;<br>+ }<br>+<br>+ // Open file<br>+ int filePtr = 0;<br>+<br>+ cg_open(filename, CG_MODE_READ, &filePtr);<br>+<br>+ if (filePtr <= 0) {<br>+ readMeshIface->report_error("%s: fopen returned error.\n", fileName);<br>+ return MB_FILE_DOES_NOT_EXIST;<br>+ }<br>+<br>+ // read number of verts, elements, sets<br>+ long num_verts = 0, num_elems = 0, num_sets = 0;<br>+ int num_bases = 0, num_zones = 0, num_sections = 0;<br>+<br>+ char zoneName[128];<br>+ cgsize_t size[3];<br>+<br>+ mesh_dim = 3; // default to 3D<br>+<br>+ // Read number of bases;<br>+ cg_nbases(filePtr, &num_bases);<br>+<br>+ if (num_bases > 1) {<br>+ readMeshIface->report_error("%s: support for number of bases > 1 not implemented.\n", fileName);<br>+ return MB_NOT_IMPLEMENTED;<br>+ }<br>+<br>+ for (int indexBase = 1; indexBase <= num_bases; ++indexBase) {<br>+<br>+ // Get the number of zones/blocks in current base.<br>+ cg_nzones(filePtr, indexBase, &num_zones);<br>+<br>+ if (num_zones > 1) {<br>+ readMeshIface->report_error("%s: support for number of zones > 1 not implemented.\n", fileName);<br>+ return MB_NOT_IMPLEMENTED;<br>+ }<br>+<br>+ for (int indexZone = 1; indexZone <= num_zones; ++indexZone) {<br>+<br>+ // get zone name and size.<br>+ cg_zone_read(filePtr, indexBase, indexZone, zoneName, size);<br>+<br>+ // Read number of sections/Parts in current zone.<br>+ cg_nsections(filePtr, indexBase, indexZone, &num_sections);<br>+<br>+ num_verts = size[0];<br>+ num_elems = size[1];<br>+ num_sets = num_sections;<br>+<br>+<br>+ std::cout << "\nnumber of nodes = " << num_verts;<br>+ std::cout << "\nnumber of elems = " << num_elems;<br>+ std::cout << "\nnumber of parts = " << num_sets << std::endl;<br>+<br>+<br>+<br>+ // //////////////////////////////////<br>+ // Read Nodes<br>+<br>+ // allocate nodes; these are allocated in one shot, get contiguous handles starting with start_handle,<br>+ // and the reader is passed back double*'s pointing to MOAB's native storage for vertex coordinates<br>+ // for those verts<br>+ std::vector<double*> coord_arrays;<br>+ EntityHandle handle = 0;<br>+ result = readMeshIface->get_node_coords(3, num_verts, MB_START_ID, handle, coord_arrays);<br>+ if (MB_SUCCESS != result) {<br>+ readMeshIface->report_error("%s: Trouble reading vertices\n", fileName);<br>+ return result;<br>+ }<br>+<br>+<br>+ // fill in vertex coordinate arrays<br>+ cgsize_t beginPos = 1, endPos = num_verts;<br>+<br>+<br>+ // Read nodes coordinates.<br>+ cg_coord_read(filePtr, indexBase, indexZone, "CoordinateX",<br>+ RealDouble, &beginPos, &endPos, coord_arrays[0]);<br>+ cg_coord_read(filePtr, indexBase, indexZone, "CoordinateY",<br>+ RealDouble, &beginPos, &endPos, coord_arrays[1]);<br>+ cg_coord_read(filePtr, indexBase, indexZone, "CoordinateZ",<br>+ RealDouble, &beginPos, &endPos, coord_arrays[2]);<br>+<br>+ // CGNS seems to always include the Z component, even if the mesh is 2D.<br>+ // Check if Z is zero and determine mesh dimension.<br>+ // Also create the node_id_map data.<br>+ double sumZcoord = 0.0;<br>+ double eps = 1.0e-12;<br>+ for (long i = 0; i < num_verts; ++i, ++handle) {<br>+<br>+ int index = i + 1;<br>+<br>+ node_id_map.insert(std::pair<long, EntityHandle>(index, handle)).second;<br>+<br>+ sumZcoord += *(coord_arrays[2] + i);<br>+ }<br>+ if (std::abs(sumZcoord) <= eps) mesh_dim = 2;<br>+<br>+<br>+ // create reverse map from handle to id<br>+ std::vector<int> ids(num_verts);<br>+ std::vector<int>::iterator id_iter = ids.begin();<br>+ std::vector<EntityHandle> handles(num_verts);<br>+ std::vector<EntityHandle>::iterator h_iter = handles.begin();<br>+ for (std::map<long, EntityHandle>::iterator i = node_id_map.begin();<br>+ i != node_id_map.end(); ++i, ++id_iter, ++h_iter) {<br>+ *id_iter = i->first;<br>+ * h_iter = i->second;<br>+ }<br>+ // store IDs in tags<br>+ result = mbImpl->tag_set_data(globalId, &handles[0], num_verts, &ids[0]);<br>+ if (MB_SUCCESS != result)<br>+ return result;<br>+ if (file_id_tag) {<br>+ result = mbImpl->tag_set_data(*file_id_tag, &handles[0], num_verts, &ids[0]);<br>+ if (MB_SUCCESS != result)<br>+ return result;<br>+ }<br>+ ids.clear();<br>+ handles.clear();<br>+<br>+<br>+<br>+ // //////////////////////////////////<br>+ // Read elements data<br>+<br>+ EntityType ent_type;<br>+<br>+ long section_offset = 0;<br>+<br>+ // Define which mesh parts are volume families.<br>+ // mesh parts with volumeID[X] = 0 are boundary parts.<br>+ std::vector<int> volumeID(num_sections, 0);<br>+<br>+<br>+ for (int section = 0; section < num_sections; ++section) {<br>+<br>+ ElementType_t elemsType;<br>+ int iparent_flag, nbndry;<br>+ char sectionName[128];<br>+ int verts_per_elem;<br>+<br>+ int cgSection = section + 1;<br>+<br>+ cg_section_read(filePtr, indexBase, indexZone, cgSection, sectionName,<br>+ &elemsType, &beginPos, &endPos, &nbndry, &iparent_flag);<br>+<br>+ size_t section_size = endPos - beginPos + 1;<br>+<br>+<br>+ // Read element description in current section<br>+<br>+ switch (elemsType) {<br>+ case BAR_2:<br>+ ent_type = MBEDGE;<br>+ verts_per_elem = 2;<br>+ break;<br>+ case TRI_3:<br>+ ent_type = MBTRI;<br>+ verts_per_elem = 3;<br>+ if (mesh_dim == 2) volumeID[section] = 1;<br>+ break;<br>+ case QUAD_4:<br>+ ent_type = MBQUAD;<br>+ verts_per_elem = 4;<br>+ if (mesh_dim == 2) volumeID[section] = 1;<br>+ break;<br>+ case TETRA_4:<br>+ ent_type = MBTET;<br>+ verts_per_elem = 4;<br>+ if (mesh_dim == 3) volumeID[section] = 1;<br>+ break;<br>+ case PYRA_5:<br>+ ent_type = MBPYRAMID;<br>+ verts_per_elem = 5;<br>+ if (mesh_dim == 3) volumeID[section] = 1;<br>+ break;<br>+ case PENTA_6:<br>+ ent_type = MBPRISM;<br>+ verts_per_elem = 6;<br>+ if (mesh_dim == 3) volumeID[section] = 1;<br>+ break;<br>+ case HEXA_8:<br>+ ent_type = MBHEX;<br>+ verts_per_elem = 8;<br>+ if (mesh_dim == 3) volumeID[section] = 1;<br>+ break;<br>+ case MIXED:<br>+ ent_type = MBMAXTYPE;<br>+ verts_per_elem = 0;<br>+ break;<br>+ default:<br>+ readMeshIface->report_error("%s: Trouble determining element type.\n", fileName);<br>+ return MB_INDEX_OUT_OF_RANGE;<br>+ break;<br>+ }<br>+<br>+ if (elemsType == TETRA_4 || elemsType == PYRA_5 || elemsType == PENTA_6 || elemsType == HEXA_8 ||<br>+ elemsType == TRI_3 || elemsType == QUAD_4 || ((elemsType == BAR_2) && mesh_dim == 2)) {<br>+<br>+ // read connectivity into conn_array directly<br>+<br>+ cgsize_t iparentdata;<br>+ cgsize_t connDataSize;<br>+<br>+ // get number of entries on the connectivity list for this section<br>+ cg_ElementDataSize(filePtr, indexBase, indexZone, cgSection, &connDataSize);<br>+<br>+ // need a temporary vector to later cast to conn_array.<br>+ std::vector<cgsize_t> elemNodes(connDataSize);<br>+<br>+ cg_elements_read(filePtr, indexBase, indexZone, cgSection, &elemNodes[0], &iparentdata);<br>+<br>+ // //////////////////////////////////<br>+ // Create elements, sets and tags<br>+<br>+ create_elements(sectionName, file_id_tag,<br>+ ent_type, verts_per_elem, section_offset, section_size , elemNodes);<br>+<br>+<br>+ } // homogeneous mesh type<br>+<br>+ else if (elemsType == MIXED) {<br>+<br>+ // We must first sort all elements connectivities into continuous vectors<br>+<br>+ cgsize_t connDataSize;<br>+ cgsize_t iparentdata;<br>+<br>+ cg_ElementDataSize(filePtr, indexBase, indexZone, cgSection, &connDataSize);<br>+<br>+ std::vector< cgsize_t > elemNodes(connDataSize);<br>+<br>+ cg_elements_read(filePtr, indexBase, indexZone, cgSection, &elemNodes[0], &iparentdata);<br>+<br>+ std::vector<cgsize_t> elemsConn_EDGE;<br>+ std::vector<cgsize_t> elemsConn_TRI, elemsConn_QUAD;<br>+ std::vector<cgsize_t> elemsConn_TET, elemsConn_PYRA, elemsConn_PRISM, elemsConn_HEX;<br>+ cgsize_t count_EDGE, count_TRI, count_QUAD;<br>+ cgsize_t count_TET, count_PYRA, count_PRISM, count_HEX;<br>+<br>+<br>+ // First, get elements count for current section<br>+<br>+ count_EDGE = count_TRI = count_QUAD = 0;<br>+ count_TET = count_PYRA = count_PRISM = count_HEX = 0;<br>+<br>+ int connIndex = 0;<br>+ for (int i = beginPos; i <= endPos; i++) {<br>+<br>+ elemsType = ElementType_t(elemNodes[connIndex]);<br>+<br>+ // get current cell node count.<br>+ cg_npe(elemsType, &verts_per_elem);<br>+<br>+ switch (elemsType) {<br>+ case BAR_2:<br>+ count_EDGE += 1;<br>+ break;<br>+ case TRI_3:<br>+ count_TRI += 1;<br>+ break;<br>+ case QUAD_4:<br>+ count_QUAD += 1;<br>+ break;<br>+ case TETRA_4:<br>+ count_TET += 1;<br>+ break;<br>+ case PYRA_5:<br>+ count_PYRA += 1;<br>+ break;<br>+ case PENTA_6:<br>+ count_PRISM += 1;<br>+ break;<br>+ case HEXA_8:<br>+ count_HEX += 1;<br>+ break;<br>+ default:<br>+ readMeshIface->report_error("%s: Trouble determining element type.\n", fileName);<br>+ return MB_INDEX_OUT_OF_RANGE;<br>+ break;<br>+ }<br>+<br>+ connIndex += (verts_per_elem + 1); // add one to skip next element descriptor<br>+<br>+ }<br>+<br>+ if (count_EDGE > 0) elemsConn_EDGE.resize(count_EDGE * 2);<br>+ if (count_TRI > 0) elemsConn_TRI.resize(count_TRI * 3);<br>+ if (count_QUAD > 0) elemsConn_QUAD.resize(count_QUAD * 4);<br>+ if (count_TET > 0) elemsConn_TET.resize(count_TET * 4);<br>+ if (count_PYRA > 0) elemsConn_PYRA.resize(count_PYRA * 5);<br>+ if (count_PRISM > 0) elemsConn_PRISM.resize(count_PRISM * 6);<br>+ if (count_HEX > 0) elemsConn_HEX.resize(count_HEX * 8);<br>+<br>+ // grab mixed section elements connectivity<br>+<br>+ int idx_edge, idx_tri, idx_quad;<br>+ int idx_tet, idx_pyra, idx_prism, idx_hex;<br>+ idx_edge = idx_tri = idx_quad = 0;<br>+ idx_tet = idx_pyra = idx_prism = idx_hex = 0;<br>+<br>+<br>+ connIndex = 0;<br>+ for (int i = beginPos; i <= endPos; i++) {<br>+<br>+ elemsType = ElementType_t(elemNodes[connIndex]);<br>+<br>+ // get current cell node count.<br>+ cg_npe(elemsType, &verts_per_elem);<br>+<br>+ switch (elemsType) {<br>+ case BAR_2:<br>+ for (int j = 0; j < 2; ++j) elemsConn_EDGE[idx_edge + j] = elemNodes[connIndex + j + 1];<br>+ idx_edge += 2;<br>+ break;<br>+ case TRI_3:<br>+ for (int j = 0; j < 3; ++j) elemsConn_TRI[idx_tri + j] = elemNodes[connIndex + j + 1];<br>+ idx_tri += 3;<br>+ break;<br>+ case QUAD_4:<br>+ for (int j = 0; j < 4; ++j) elemsConn_QUAD[idx_quad + j] = elemNodes[connIndex + j + 1];<br>+ idx_quad += 4;<br>+ break;<br>+ case TETRA_4:<br>+ for (int j = 0; j < 4; ++j) elemsConn_TET[idx_tet + j] = elemNodes[connIndex + j + 1];<br>+ idx_tet += 4;<br>+ break;<br>+ case PYRA_5:<br>+ for (int j = 0; j < 5; ++j) elemsConn_PYRA[idx_pyra + j] = elemNodes[connIndex + j + 1];<br>+ idx_pyra += 5;<br>+ break;<br>+ case PENTA_6:<br>+ for (int j = 0; j < 6; ++j) elemsConn_PRISM[idx_prism + j] = elemNodes[connIndex + j + 1];<br>+ idx_prism += 6;<br>+ break;<br>+ case HEXA_8:<br>+ for (int j = 0; j < 8; ++j) elemsConn_HEX[idx_hex + j] = elemNodes[connIndex + j + 1];<br>+ idx_hex += 8;<br>+ break;<br>+ default:<br>+ readMeshIface->report_error("%s: Trouble determining element type.\n", fileName);<br>+ return MB_INDEX_OUT_OF_RANGE;<br>+ break;<br>+ }<br>+<br>+ connIndex += (verts_per_elem + 1); // add one to skip next element descriptor<br>+<br>+ }<br>+<br>+<br>+ // //////////////////////////////////<br>+ // Create elements, sets and tags<br>+<br>+ if (count_EDGE > 0)<br>+ create_elements(sectionName, file_id_tag, MBEDGE, 2, section_offset, count_EDGE, elemsConn_EDGE);<br>+<br>+ if (count_TRI > 0)<br>+ create_elements(sectionName, file_id_tag, MBTRI, 3, section_offset, count_TRI, elemsConn_TRI);<br>+<br>+ if (count_QUAD > 0)<br>+ create_elements(sectionName, file_id_tag, MBQUAD, 4, section_offset, count_QUAD, elemsConn_QUAD);<br>+<br>+ if (count_TET > 0)<br>+ create_elements(sectionName, file_id_tag, MBTET, 4, section_offset, count_TET, elemsConn_TET);<br>+<br>+ if (count_PYRA > 0)<br>+ create_elements(sectionName, file_id_tag, MBPYRAMID, 5, section_offset, count_PYRA, elemsConn_PYRA);<br>+<br>+ if (count_PRISM > 0)<br>+ create_elements(sectionName, file_id_tag, MBPRISM, 6, section_offset, count_PRISM, elemsConn_PRISM);<br>+<br>+ if (count_HEX > 0)<br>+ create_elements(sectionName, file_id_tag, MBHEX, 8, section_offset, count_HEX, elemsConn_HEX);<br>+<br>+ } // mixed mesh type<br>+<br>+ } // num_sections<br>+<br>+ cg_close(filePtr);<br>+<br>+ return result;<br>+<br>+ } // indexZone for<br>+<br>+ } // indexBase for<br>+<br>+ return MB_SUCCESS;<br>+<br>+}<br>+<br>+ErrorCode ReadCGNS::create_elements(char *sectionName,<br>+ const Tag *file_id_tag,<br>+ const EntityType &ent_type,<br>+ const int& verts_per_elem,<br>+ long §ion_offset,<br>+ int elems_count,<br>+ const std::vector<cgsize_t>& elemsConn)<br>+{<br>+<br>+ ErrorCode result;<br>+<br>+ // Create the element sequence; passes back a pointer to the internal storage for connectivity and the<br>+ // starting entity handle<br>+ EntityHandle* conn_array;<br>+ EntityHandle handle = 0;<br>+<br>+ result = readMeshIface->get_element_connect(elems_count, verts_per_elem, ent_type, 1, handle, conn_array);<br>+<br>+ if (MB_SUCCESS != result) {<br>+ readMeshIface->report_error("%s: Trouble reading elements\n", fileName);<br>+ return result;<br>+ }<br>+<br>+ memcpy(conn_array, &elemsConn[0], elemsConn.size() * sizeof(EntityHandle));<br>+<br>+ // notify MOAB of the new elements<br>+ result = readMeshIface->update_adjacencies(handle, elems_count, verts_per_elem, conn_array);<br>+ if (MB_SUCCESS != result) return result;<br>+<br>+<br>+ // //////////////////////////////////<br>+ // Create sets and tags<br>+<br>+ Range elements(handle, handle + elems_count - 1);<br>+<br>+ // Store element IDs<br>+<br>+ std::vector<int> id_list(elems_count);<br>+<br>+ // add 1 to offset id to 1-based numbering<br>+ for (cgsize_t i = 0; i < elems_count; ++i) id_list[i] = i + 1 + section_offset;<br>+ section_offset += elems_count;<br>+<br>+ create_sets(sectionName, file_id_tag, ent_type, elements, id_list, 0);<br>+<br>+ return MB_SUCCESS;<br>+<br>+}<br>+<br>+<br>+ErrorCode ReadCGNS::create_sets(char *sectionName,<br>+ const Tag *file_id_tag,<br>+ EntityType /*element_type*/,<br>+ const Range& elements,<br>+ const std::vector<int>& set_ids,<br>+ int /*set_type*/)<br>+{<br>+<br>+ ErrorCode result;<br>+<br>+ result = mbImpl->tag_set_data(globalId, elements, &set_ids[0]);<br>+ if (MB_SUCCESS != result) return result;<br>+<br>+ if (file_id_tag) {<br>+ result = mbImpl->tag_set_data(*file_id_tag, elements, &set_ids[0]);<br>+ if (MB_SUCCESS != result) return result;<br>+ }<br>+<br>+ result = MB_SUCCESS;<br>+ EntityHandle set_handle;<br>+<br>+ Tag tag_handle;<br>+<br>+ const char* setName = sectionName;<br>+<br>+ mbImpl->tag_get_handle(setName, 1, MB_TYPE_INTEGER, tag_handle, MB_TAG_SPARSE | MB_TAG_CREAT);<br>+<br>+ // create set<br>+ result = mbImpl->create_meshset(MESHSET_SET, set_handle);<br>+ if (MB_SUCCESS != result) {<br>+ readMeshIface->report_error("%s: Trouble creating set.\n", fileName);<br>+ return result;<br>+ }<br>+<br>+// // add dummy values to current set<br>+// std::vector<int> tags(set_ids.size(), 1);<br>+// result = mbImpl->tag_set_data(tag_handle, elements, &tags[0]);<br>+// if (MB_SUCCESS != result) return result;<br>+<br>+ // add them to the set<br>+ result = mbImpl->add_entities(set_handle, elements);<br>+ if (MB_SUCCESS != result) {<br>+ readMeshIface->report_error("%s: Trouble putting entities in set.\n", fileName);<br>+ return result;<br>+ }<br>+<br>+ return MB_SUCCESS;<br>+<br>+}<br>+<br>+<br>+ErrorCode ReadCGNS::process_options(const FileOptions & opts)<br>+{<br>+ // mark all options seen, to avoid compile warning on unused variable<br>+ opts.mark_all_seen();<br>+<br>+ return MB_SUCCESS;<br>+}<br>+<br>+<br>+} // namespace moab<br>+<br>+<br><br>diff --git a/src/io/ReadCGNS.hpp b/src/io/ReadCGNS.hpp<br>new file mode 100644<br>index 0000000..c0e25c6<br>--- /dev/null<br>+++ b/src/io/ReadCGNS.hpp<br>@@ -0,0 +1,88 @@<br>+#ifndef READ_CGNS_HPP<br>+#define READ_CGNS_HPP<br>+<br>+#include "moab/ReaderIface.hpp"<br>+#include "moab/Range.hpp"<br>+<br>+#include "cgnslib.h"<br>+<br>+namespace moab<br>+{<br>+<br>+class ReadUtilIface;<br>+class Interface;<br>+<br>+/**<br>+ * \brief Export CGNS files.<br>+ * \author Carlos Breviglieri, Carlos Junqueira Junior<br>+ */<br>+<br>+class ReadCGNS : public ReaderIface<br>+{<br>+<br>+public:<br>+<br>+ //! factory method<br>+ static ReaderIface* factory(Interface*);<br>+<br>+ ErrorCode load_file(const char* file_name,<br>+ const EntityHandle* file_set,<br>+ const FileOptions& opts,<br>+ const SubsetList* subset_list = 0,<br>+ const Tag* file_id_tag = 0);<br>+<br>+ ErrorCode read_tag_values(const char* file_name,<br>+ const char* tag_name,<br>+ const FileOptions& opts,<br>+ std::vector<int>& tag_values_out,<br>+ const SubsetList* subset_list = 0);<br>+<br>+ //! Constructor<br>+ ReadCGNS(Interface* impl = NULL);<br>+<br>+ //! Destructor<br>+ virtual ~ReadCGNS();<br>+<br>+private:<br>+<br>+ ErrorCode create_elements(char *sectionName,<br>+ const Tag* file_id_tag,<br>+ const EntityType& ent_type,<br>+ const int& verts_per_elem,<br>+ long& section_offset,<br>+ int elems_count,<br>+ const std::vector<cgsize_t>& elemsConn);<br>+<br>+ ErrorCode create_sets(char* sectionName,<br>+ const Tag* file_id_tag,<br>+ EntityType element_type,<br>+ const Range& elements,<br>+ const std::vector<int>& set_ids,<br>+ int set_type);<br>+<br>+ ErrorCode create_geometric_topology();<br>+<br>+ /** \brief Process options passed into the reader<br>+ * \param opts Options passed into this read<br>+ */<br>+ ErrorCode process_options(const FileOptions &opts);<br>+<br>+ const char *fileName;<br>+<br>+ short mesh_dim;<br>+<br>+ ReadUtilIface* readMeshIface;<br>+<br>+ //! interface instance<br>+ Interface* mbImpl;<br>+<br>+ Tag globalId;<br>+ Tag boundary;<br>+ Range geomSets;<br>+<br>+};<br>+<br>+} // namespace moab<br>+<br>+#endif<br>+<br><br>diff --git a/src/io/WriteCGNS.cpp b/src/io/WriteCGNS.cpp<br>new file mode 100644<br>index 0000000..5e6cfe4<br>--- /dev/null<br>+++ b/src/io/WriteCGNS.cpp<br>@@ -0,0 +1,715 @@<br>+#include "WriteCGNS.hpp"<br>+#include "moab/CN.hpp"<br>+#include "MBTagConventions.hpp"<br>+#include "MBParallelConventions.h"<br>+#include "moab/Interface.hpp"<br>+#include "moab/Range.hpp"<br>+#include "moab/WriteUtilIface.hpp"<br>+#include "moab/FileOptions.hpp"<br>+#include "GmshUtil.hpp"<br>+<br>+#include <fstream><br>+#include <map><br>+#include <set><br>+<br>+#include <iostream><br>+<br>+namespace moab {<br>+<br>+WriterIface *WriteCGNS::factory( Interface* iface )<br>+ { return new WriteCGNS( iface ); }<br>+<br>+WriteCGNS::WriteCGNS(Interface *impl)<br>+ : mbImpl(impl), VrtSize(0), EdgeSize(0), FaceSize(0), CellSize(0)<br>+{<br>+ impl->query_interface(mWriteIface);<br>+}<br>+<br>+WriteCGNS::~WriteCGNS()<br>+{<br>+ mbImpl->release_interface(mWriteIface);<br>+}<br>+<br>+//! writes out a file<br>+ErrorCode WriteCGNS::write_file(const char *file_name,<br>+ const bool overwrite,<br>+ const FileOptions& /*options*/,<br>+ const EntityHandle */*output_list*/,<br>+ const int /*num_sets*/,<br>+ const std::vector<std::string>&,<br>+ const Tag*,<br>+ int,<br>+ int )<br>+{<br>+ ErrorCode rval;<br>+<br>+ if (!overwrite){<br>+ rval = mWriteIface->check_doesnt_exist( file_name );<br>+ if (MB_SUCCESS != rval)<br>+ return rval;<br>+ }<br>+ std::cout << "THE CGNS CONVERSION ONLY WORKS FOR ENTITIES CITED BELOW:";<br>+ std::cout << "\n -MBVERTEX\n -MBEDGE\n -MBTRI\n -MBQUAD";<br>+ std::cout << "\n -MBTET\n -MBPYRAMID\n -MBHEX\n";<br>+<br>+ // Get entities to write<br>+ // Get and count vertex entities<br>+ rval = get_vertex_entities ( VrtSize, Nodes );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+ // Get and count edge entities<br>+ rval = get_edge_entities( EdgeSize, Edges );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+ // Get and count face entities<br>+ rval = get_face_entities( FaceSize, Faces );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+ // Get and count cell entities<br>+ rval = get_cell_entities( CellSize, Cells );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+ std::cout << "\nThe Number of Vertex is " << VrtSize << ".\n";<br>+ std::cout << "The Number of Edges is " << EdgeSize << ".\n";<br>+ std::cout << "The Number of Faces is " << FaceSize << ".\n";<br>+ std::cout << "The Number of Cells is " << CellSize << ".\n\n";<br>+<br>+ // save filename to member variable so we don't need to pass as an argument<br>+ // to called functions<br>+ fileName = file_name;<br>+ std::cout << fileName << " file is a " << physdim << "-D mesh.\n";<br>+<br>+ // Open file<br>+ IndexFile = 0;<br>+<br>+ // open the cgns file<br>+ // filename: (input) Name of the CGNS file, including path name if necessary. There is no limit on the <br>+ // length of this character variable. <br>+ // CG_MODE_WRITE: (input) Mode used for opening the file. The modes currently supported are CG_MODE_READ, <br>+ // CG_MODE_WRITE, and CG_MODE_MODIFY.<br>+ // filePtr: (output) CGNS file index number.<br>+ if ( cg_open(fileName, CG_MODE_WRITE, &IndexFile) ){<br>+ std::cout << "Error opening file\n";<br>+ cg_error_exit();<br>+ }<br>+ // Give a base name<br>+ BaseName = "Cgns Base";<br>+ if ( cg_base_write(IndexFile,BaseName,celldim,physdim,&IndexBase) ){<br>+ std::cout << "Error creating CGNS base";<br>+ }<br>+ // Give a zone name<br>+ ZoneName = "Cgns Zone";<br>+ // isize array contains the total vertex size, cell size, and boundary <br>+ // vertex size for the zone<br>+ // Note that for unstructured zones, the index dimension is always 1<br>+ isize[0] = VrtSize; // isize[0] contains the total vertex size<br>+ isize[1] = CellSize; // isize[1] contains the total cell size<br>+ isize[2] = 0; // isize[2] = 0 for unsorted elements <br>+ // Create zone */<br>+ // ZoneType_t: Unstructured<br>+ if ( cg_zone_write(IndexFile,IndexBase,ZoneName,isize,Unstructured,&IndexZone) ){<br>+ std::cout << "Error creating CGNS zone\n";<br>+ cg_error_exit();<br>+ } <br>+ // Write the vertex coordinates<br>+ rval = write_coord_cgns( Nodes );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+<br>+ // Create a vector to hold the Tags<br>+ std::vector<moab::Tag> TagHandles;<br>+ // Get Tags<br>+ rval = mbImpl->tag_get_tags( TagHandles );<br>+ if (rval != MB_SUCCESS){<br>+ return rval;<br>+ }<br>+ // Get the number of Tags in the mesh<br>+ int NbTags = TagHandles.size();<br>+ std:: cout << "\nThe mesh has " << NbTags << " Tags.\n";<br>+<br>+ // Create a vector of size NbTags<br>+ // Sets have informations about the entity set<br>+ std::vector<SetStruct> Sets;<br>+ Sets.reserve(NbTags);<br>+ // Fill Sets with all information needed<br>+ rval = set_tag_values( TagHandles, Edges, Faces, Cells, Sets );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to set tag values\n";<br>+ return rval;<br>+ }<br>+<br>+ // Create a matrix to hold connectivity<br>+ std::vector < std::vector<cgsize_t> > ConnTable;<br>+ ConnTable.resize(NbTags);<br>+<br>+ std::vector< int > Begin ( NbTags , 0 );<br>+ std::vector< int > End ( NbTags , 0 );<br>+<br>+ // Take the connectivity of higher dimension entities<br>+ cgsize_t BeginSetsIndex = 1;<br>+ cgsize_t EndSetsIndex;<br>+ switch ( physdim ){<br>+ case 1:<br>+ rval = get_conn_table( Edges, Begin, End, TagHandles, Sets, ConnTable );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to fill the connectivity table for 1-D entities\n";<br>+ return rval;<br>+ }<br>+ for (int i = 0; i < NbTags; ++i) {<br>+ if ( Sets[i].IdSet != -1 ){<br>+ const char * SectionName = Sets[i].TagName.c_str();<br>+ EndSetsIndex = BeginSetsIndex + Sets[i].NbEdges - 1;<br>+ // Write the section in CGNS file<br>+ if ( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType,<br>+ BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0],&IndexSection) ){<br>+ std::cout << "Issue on writing connectivity - 3-D\n"; <br>+ cg_error_exit();<br>+ }<br>+ BeginSetsIndex = EndSetsIndex+1;<br>+ }<br>+ }<br>+ break;<br>+ case 2:<br>+ rval = get_conn_table( Edges, Begin, End, TagHandles, Sets, ConnTable );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to fill the connectivity table for 1-D entities\n";<br>+ return rval;<br>+ }<br>+ rval = get_conn_table( Faces, Begin, End, TagHandles, Sets, ConnTable );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to fill the connectivity table for 2-D entities\n";<br>+ return rval;<br>+ }<br>+ for (int i = 0; i < NbTags; ++i) {<br>+ if ( Sets[i].IdSet != -1 ){<br>+ const char * SectionName = Sets[i].TagName.c_str();<br>+ EndSetsIndex = BeginSetsIndex + Sets[i].NbEdges + Sets[i].NbFaces - 1;<br>+ // Write the section in CGNS file<br>+ if ( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType, <br>+ BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0],&IndexSection) ){<br>+ std::cout << "Issue on writing connectivity -- 2-D\n"; <br>+ cg_error_exit();<br>+ }<br>+ BeginSetsIndex = EndSetsIndex+1;<br>+ }<br>+ }<br>+ break;<br>+ case 3:<br>+ rval = get_conn_table( Faces, Begin, End, TagHandles, Sets, ConnTable );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to fill the connectivity table for 2-D entities\n";<br>+ return rval;<br>+ }<br>+ rval = get_conn_table( Cells, Begin, End, TagHandles, Sets, ConnTable );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to fill the connectivity table for 3-D entities\n";<br>+ return rval;<br>+ }<br>+ for (int i = 0; i < NbTags; ++i) {<br>+ if ( Sets[i].IdSet != -1 ){<br>+ const char * SectionName = Sets[i].TagName.c_str();<br>+ EndSetsIndex = BeginSetsIndex + Sets[i].NbFaces + Sets[i].NbCells - 1;<br>+ std::cout << "BeginSetsIndex = " << BeginSetsIndex << "\tEndSetsIndex = " << EndSetsIndex << "\n";<br>+ // Write the section in CGNS file<br>+ if ( cg_section_write( IndexFile, IndexBase, IndexBase, SectionName, Sets[i].CGNSType,<br>+ BeginSetsIndex, EndSetsIndex, 0, &ConnTable[i][0],&IndexSection) ){<br>+ std::cout << "Issue on writing connectivity -- 3-D\n"; <br>+ cg_error_exit();<br>+ }<br>+ BeginSetsIndex = EndSetsIndex+1;<br>+ }<br>+ }<br>+ break;<br>+ default:<br>+ std::cout << "Issue on Physical dimension\n"; <br>+ return MB_FAILURE;<br>+ }<br>+<br>+ // Close the CGNS mesh file<br>+ if ( cg_close(IndexFile) ){<br>+ std::cout << "Error closing file\n";<br>+ cg_error_exit();<br>+ }<br>+ // done<br>+ return MB_SUCCESS;<br>+}<br>+<br>+// Get and count vertex entities<br>+ErrorCode WriteCGNS::get_vertex_entities ( cgsize_t &VrtSize_, std::vector< moab::EntityHandle > &Nodes_)<br>+{<br>+ ErrorCode rval;<br>+ // Get vertex entities<br>+ // The first input is 0 because one queries the entire mesh.<br>+ // Retrieves all entities of dimension = 0 in "Nodes"<br>+ rval = mbImpl->get_entities_by_dimension( 0, 0, Nodes_, false );<br>+ if ( Nodes.size() > 0 ){<br>+ celldim=0;<br>+ physdim=0;<br>+ // get the amout of vertex<br>+ VrtSize_ = Nodes_.size();<br>+ }<br>+ else { std::cout << "The mesh has not node points.\n"; }<br>+ // done<br>+ return rval;<br>+}<br>+<br>+// Get and count edge entities<br>+ErrorCode WriteCGNS::get_edge_entities(cgsize_t &EdgeSize_, std::vector< moab::EntityHandle > &Edges_)<br>+{<br>+ ErrorCode rval;<br>+ // The first input is 0 because one queries the entire mesh.<br>+ // Get all entities of dimension = 1 in Edges<br>+ rval = mbImpl->get_entities_by_dimension( 0, 1, Edges_, false );<br>+ if ( Edges_.size() > 0 ){<br>+ celldim=1;<br>+ physdim=1;<br>+ // get the amout of edges<br>+ EdgeSize_ = Edges_.size();<br>+ }<br>+ // done<br>+ return rval;<br>+}<br>+<br>+// Get and count face entities<br>+ErrorCode WriteCGNS::get_face_entities(cgsize_t &FaceSize_, std::vector< moab::EntityHandle > &Faces_)<br>+{<br>+ ErrorCode rval;<br>+ // The first input is 0 because one queries the entire mesh.<br>+ // Get all entities of dimension = 2 in Faces<br>+ rval = mbImpl->get_entities_by_dimension( 0, 2, Faces_, false );<br>+ if ( Faces_.size() ){<br>+ celldim=2;<br>+ physdim=2;<br>+ // get the amout of faces<br>+ FaceSize_ = Faces_.size();<br>+ }<br>+ // done<br>+ return rval;<br>+}<br>+<br>+// Get and count cell entities<br>+ErrorCode WriteCGNS::get_cell_entities(cgsize_t &CellSize_, std::vector< moab::EntityHandle > &Cells_)<br>+{<br>+ ErrorCode rval;<br>+ // The first input is 0 because one queries the entire mesh.<br>+ // Get all entities of dimension = 3 in Cell<br>+ rval = mbImpl->get_entities_by_dimension( 0, 3, Cells_, false );<br>+ if ( Cells_.size() ){<br>+ celldim=3;<br>+ physdim=3;<br>+ // get the amout of volumes<br>+ CellSize_ = Cells_.size();<br>+ }<br>+ // done<br>+ return rval;<br>+}<br>+<br>+ErrorCode WriteCGNS::write_coord_cgns(std::vector< moab::EntityHandle > &Nodes_)<br>+{<br>+ ErrorCode rval;<br>+ <br>+ const int num_entities = (int)Nodes_.size();<br>+ <br>+ // Moab works with one vector for the threee coordinates<br>+ std::vector<double> Coords ( 3*num_entities );<br>+ std::vector<double>::iterator c = Coords.begin();<br>+<br>+ // CGNS uses one vector for each coordinate<br>+ std::vector<double> CoordX;<br>+ std::vector<double> CoordY;<br>+ std::vector<double> CoordZ;<br>+<br>+ // Summ the values of all coordinates to be sure if it is not zero <br>+ double SumX=0;<br>+ double SumY=0;<br>+ double SumZ=0;<br>+ <br>+ // Get the moab coordinates - Coords is the output<br>+ rval = mbImpl->get_coords( &Nodes_[0], num_entities, &Coords[0] );<br>+ if (MB_SUCCESS != rval){<br>+ std::cout << "Error getting coordinates from nodes.\n";<br>+ return rval;<br>+ }<br>+<br>+ // Reserve the size of nodes<br>+ CoordX.reserve( Nodes_.size() );<br>+ CoordY.reserve( Nodes_.size() );<br>+ CoordZ.reserve( Nodes_.size() );<br>+<br>+ for (std::vector<moab::EntityHandle>::iterator i=Nodes_.begin(); i != Nodes_.end(); ++i){<br>+ CoordX.push_back(*c); // Put the X coordinate in CoordX vector<br>+ SumX += abs(*c); // Sum all X coordinates<br>+ ++c; // Move to Y coordinate<br>+ CoordY.push_back(*c); // Put the Y coordinate in CoordY vector<br>+ SumY += abs(*c); // Sum all Y coordinates<br>+ ++c; // Move to Z coordinate<br>+ CoordZ.push_back(*c); // Put the Z coordinate in CoordZ vector<br>+ SumZ += abs(*c); // Sum all Z coordinates<br>+ ++c; // Move to X coordinate<br>+ } <br>+<br>+ // If X coordinate is not empty then write CoordX (user must use SIDS-standard names here)<br>+ if ( SumX != 0 ){<br>+ if ( cg_coord_write(IndexFile,IndexBase,IndexZone,RealDouble,"CoordinateX",&CoordX[0],&IndexCoord[0]) ){<br>+ std::cout << " Error writing X coordinates.\n";<br>+ cg_error_exit();<br>+ }<br>+ }<br>+ // If Y coordinate is not empty then write CoordY (user must use SIDS-standard names here)<br>+ if ( SumY != 0 ){<br>+ if ( cg_coord_write(IndexFile,IndexBase,IndexZone,RealDouble,"CoordinateY",&CoordY[0],&IndexCoord[1]) ){<br>+ std::cout << " Error writing Y coordinates.\n";<br>+ cg_error_exit();<br>+ }<br>+ }<br>+ // If Z coordinate is not empty then write CoordZ (user must use SIDS-standard names here)<br>+ if ( SumZ != 0 ){<br>+ if ( cg_coord_write(IndexFile,IndexBase,IndexZone,RealDouble,"CoordinateZ",&CoordZ[0],&IndexCoord[2]) ){<br>+ std::cout << " Error writing Z coordinates.\n";<br>+ cg_error_exit();<br>+ }<br>+ }<br>+<br>+ // Clear vectors<br>+ Coords.clear();<br>+ CoordX.clear();<br>+ CoordY.clear();<br>+ CoordZ.clear();<br>+ <br>+ // done<br>+ return MB_SUCCESS; <br>+}<br>+<br>+ErrorCode WriteCGNS::set_tag_values( std::vector< Tag >& TagHandles,<br>+ std::vector< moab::EntityHandle > &Edges_,<br>+ std::vector< moab::EntityHandle > &Faces_,<br>+ std::vector< moab::EntityHandle > &Cells_,<br>+ std::vector< WriteCGNS::SetStruct >& Sets )<br>+{<br>+ ErrorCode rval;<br>+<br>+ // Get the number of Tags in the mesh<br>+ int NbTags = TagHandles.size();<br>+<br>+ // Loop over all Tags<br>+ for (int i = 0; i < NbTags; ++i) {<br>+<br>+ // Allocate another position in the vector of SetStruct using a default constructor<br>+ Sets.push_back( SetStruct() );<br>+<br>+ // Get the Tag name<br>+ rval = mbImpl->tag_get_name( TagHandles[i], Sets[i].TagName );<br>+ if (rval != MB_SUCCESS){<br>+ std::cout << "Problem to get Tag Name\n";<br>+ return rval;<br>+ }<br>+ std::cout << "Tag name= " << Sets[i].TagName << "\n";<br>+<br>+ // Count all entities by type and put in Sets[i].NbEntities vector<br>+ rval = get_set_entities( i, TagHandles, Sets);<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get Set entities\n";<br>+ return rval;<br>+ }<br>+<br>+ // Get the CGNSTYpe of the Set<br>+ rval = get_cgns_type ( i, Sets );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get CGNSType\n";<br>+ return rval;<br>+ }<br>+ std::cout << "\tSets[" << i << "].CGNSType= " << Sets[i].CGNSType << "\n";<br>+<br>+ //int Number;<br>+<br>+ // Set a data index for Edges and TagHandles[i]<br>+ if ( Sets[i].CGNSType == BAR_2 || Sets[i].CGNSType == TRI_3 || Sets[i].CGNSType == QUAD_4 ||<br>+ Sets[i].CGNSType == TETRA_4 || Sets[i].CGNSType == PYRA_5 || Sets[i].CGNSType == PENTA_6 ||<br>+ Sets[i].CGNSType == HEXA_8 || Sets[i].CGNSType == MIXED ){<br>+<br>+ if ( Sets[i].NbEdges > 0 && physdim < 3 ){<br>+ // Set a data index for Edges and TagHandles[i]<br>+ const std::vector< int > tag_values ( Edges_.size(), i );<br>+ rval = mbImpl-> tag_set_data ( TagHandles[i], &Edges_[0], Edges_.size(), &tag_values[0] );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to set data for 1-D entities\n";<br>+ return rval;<br>+ }<br>+ }<br>+ if ( Sets[i].NbFaces > 0 && physdim > 1 ){<br>+ // Set a data index for Faces and TagHandles[i]<br>+ const std::vector< int > tag_values ( Faces.size(), i );<br>+ rval = mbImpl-> tag_set_data ( TagHandles[i], &Faces_[0], Faces_.size(), &tag_values[0] );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to set data for 2-D entities\n";<br>+ return rval;<br>+ }<br>+ }<br>+ if ( Sets[i].NbCells > 0 && physdim > 2 ){<br>+ // Set a data index for Cells and TagHandles[i]<br>+ const std::vector< int > tag_values ( Cells.size(), i );<br>+ rval = mbImpl-> tag_set_data ( TagHandles[i], &Cells_[0], Cells_.size(), &tag_values[0] );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to set data for 3-D entities\n";<br>+ return rval;<br>+ }<br>+ }<br>+ // IdSet gets the Set Index indicating that it is not empty<br>+ Sets[i].IdSet = i;<br>+ }<br>+ std::cout << "\tSets[" << i << "].IdSet = " << Sets[i].IdSet << "\n\n";<br>+ }<br>+ return MB_SUCCESS;<br>+}<br>+<br>+// Get Entities in the set<br>+ErrorCode WriteCGNS::get_set_entities(int i, std::vector< Tag >& TagHandles, <br>+ std::vector< WriteCGNS::SetStruct >& Sets)<br>+{<br>+ ErrorCode rval;<br>+ <br>+ // Get the number of MBEDGE entities<br>+ // NbEntities[0] holds the number of MBEDGE in the "Sets"<br>+ int Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBEDGE, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBEDGE == Sets[i].NbEntities[0]<br>+ Sets[i].NbEdges += Number;<br>+ std::cout << "\tNumber of MBEDGE = " << Number << "\n";<br>+<br>+ // Get the number of MBTRI entities<br>+ // NbEntities[1] holds the number of MBTRI in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBTRI, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBTRI == Sets[i].NbEntities[1]<br>+ Sets[i].NbFaces += Number;<br>+ std::cout << "\tNumber of MBTRI = " << Number << "\n";<br>+<br>+ // Get the number of MBQUAD entities<br>+ // NbEntities[2] holds the number of MBQUAD in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBQUAD, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBQUAD == Sets[i].NbEntities[2]<br>+ Sets[i].NbFaces += Number;<br>+ std::cout << "\tNumber of MBQUAD = " << Number << "\n";<br>+<br>+ // Get the number of MBTET entities<br>+ // NbEntities[3] holds the number of MBTET in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBTET, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBTET == Sets[i].NbEntities[3]<br>+ Sets[i].NbCells += Number;<br>+ std::cout << "\tNumber of MBTET = " << Number << "\n";<br>+<br>+ // Get the number of MBPYRAMID entities<br>+ // NbEntities[4] holds the number of MBPYRAMID in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBPYRAMID, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBPYRAMID == Sets[i].NbEntities[4]<br>+ Sets[i].NbCells += Number;<br>+ std::cout << "\tNumber of MBPYRAMID = " << Number << "\n";<br>+<br>+ // Get the number of MBPRISM entities - MBPRISM == PENTA_6<br>+ // NbEntities[5] holds the number of MBPRISM in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBPRISM, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBPRISM == Sets[i].NbEntities[5]<br>+ Sets[i].NbCells += Number;<br>+ std::cout << "\tNumber of MBPRISM = " << Number << "\n";<br>+<br>+ // Get the number of MBHEX entities<br>+ // NbEntities[6] holds the number of MBHEX in the "Sets"<br>+ Number=0;<br>+ rval = mbImpl->get_number_entities_by_type_and_tag( 0, MBHEX, &TagHandles[i], 0, 1, Number );<br>+ if (rval != MB_SUCCESS ){<br>+ std::cout << "Problem to get the number of entities by type and tag\n";<br>+ return rval;<br>+ }<br>+ Sets[i].NbEntities.push_back(Number); // MBHEX == Sets[i].NbEntities[6]<br>+ Sets[i].NbCells += Number;<br>+ std::cout << "\tNumber of MBHEX = " << Number << "\n";<br>+ <br>+ std::cout << "\tTotal number of Edges = " << Sets[i].NbEdges << "\n";<br>+ std::cout << "\tTotal number of Faces = " << Sets[i].NbFaces << "\n";<br>+ std::cout << "\tTotal number of Cells = " << Sets[i].NbCells << "\n";<br>+ <br>+ return MB_SUCCESS;<br>+}<br>+<br>+// Get CGNSType<br>+ErrorCode WriteCGNS::get_cgns_type ( int i, std::vector<WriteCGNS::SetStruct> &Sets )<br>+{<br>+ std::vector<int> Test;<br>+ int Sum=0;<br>+<br>+ // NbEntities is a vector which has the number of entities of each type<br>+ // 0-MBEDGE | 1-MBTRI | 2-MBQUAD | 3-MBTET | 4-MBPYRAMID | 5-MBPRISM | 6-MBHEX<br>+ // if NbEntities[i]>0 then Test[i]=1<br>+ // else then Test[i]=0<br>+ for ( int j=0; j< (int)Sets[i].NbEntities.size(); ++j){<br>+ if ( Sets[i].NbEntities[j] > 0 ){ <br>+ Test.push_back(1);<br>+ Sum++;<br>+ }<br>+ else { Test.push_back(0); }<br>+ }<br>+<br>+ // Test the Sum<br>+ // if Sum > 1 then the Set is MIXED<br>+ // if Sum = 0 then the Set is Homogeneous<br>+ // else then the Set is empty<br>+ if ( Sum>1 ){ Sets[i].CGNSType = MIXED; }<br>+ else if ( Sum==1 ){ <br>+ int j=0;<br>+ std::cout << "Homogeneous Type\n";<br>+ while ( Sets[i].NbEntities[j] != 1 && j<(int)Sets[i].NbEntities.size() ){ ++j; }<br>+ switch ( j ){<br>+ case 0 :<br>+ Sets[i].CGNSType = BAR_2;<br>+ break;<br>+ case 1 :<br>+ Sets[i].CGNSType = TRI_3;<br>+ break;<br>+ case 2 :<br>+ Sets[i].CGNSType = QUAD_4;<br>+ break;<br>+ case 3 :<br>+ Sets[i].CGNSType = TETRA_4;<br>+ break;<br>+ case 4 :<br>+ Sets[i].CGNSType = PYRA_5;<br>+ break;<br>+ case 5 :<br>+ Sets[i].CGNSType = PENTA_6;<br>+ break;<br>+ case 6 :<br>+ Sets[i].CGNSType = HEXA_8;<br>+ break;<br>+ default :<br>+ std::cout << "It was not possible to identify the CGNSType\n";<br>+ return MB_FAILURE;<br>+ }<br>+ }<br>+ else { Sets[i].CGNSType = ElementTypeNull; } // NOT SURE IF THAT'S THE RIGHT WAY....... <br>+<br>+ // Clear the test vector<br>+ Test.clear();<br>+<br>+ return MB_SUCCESS; <br>+ <br>+}<br>+<br>+// Fill the connectivity table<br>+ErrorCode WriteCGNS::get_conn_table( std::vector< moab::EntityHandle > &Elements,<br>+ std::vector< int > &Begin,<br>+ std::vector< int > &End,<br>+ std::vector<moab::Tag> &TagHandles,<br>+ std::vector<WriteCGNS::SetStruct> &Sets,<br>+ std::vector < std::vector<cgsize_t> > &ConnTable )<br>+{<br>+ ErrorCode rval;<br>+ <br>+// int Begin = 0; // GOT TO WORK ON THIS<br>+// int End;<br>+<br>+ // Get the number of Tags in the mesh<br>+ int NbTags = TagHandles.size();<br>+<br>+ // Test all Elements, get their ids and connectivity <br>+ // to fill ConnTable<br>+ for (std::vector<moab::EntityHandle>::iterator i=Elements.begin(); i != Elements.end(); ++i){<br>+ int id;<br>+ // Test all Tags<br>+ for ( int j = 0; j < NbTags; ++j ){<br>+ // Test if the Tag has data<br>+ if ( Sets[j].IdSet != -1 ){<br>+ // Try to get data from entity<br>+ rval = mbImpl->tag_get_data( TagHandles[j], &*i, 1, &id );<br>+ if (MB_SUCCESS != rval){<br>+ return rval;<br>+ }<br>+ // If successful id==j<br>+ if ( id == j ){<br>+ // Get the entity type of the EntityHandle wich points to Cells<br>+ int num_vtx; // Number of MeshVertices in array connectivity.<br>+ const EntityHandle* conn; // Array in which connectivity of entity_handle is returned.<br>+ // Gets a pointer to constant connectivity data of entity_handle<br>+ rval = mbImpl->get_connectivity( *i, conn, num_vtx );<br>+ if (MB_SUCCESS != rval){<br>+ return rval;<br>+ }<br>+ // If the Set is MIXED type<br>+ // push CGNS ENUM type of the entity<br>+ // before the connectivity<br>+ if ( Sets[j].CGNSType == MIXED ){<br>+ ConnTable[j].push_back( moab_cgns_conv(*i) ); // moab_cgns_conv return an int which <br>+ // represents the CGNS type<br>+ Begin[j]++;<br>+ }<br>+ End[j] = Begin[j] + num_vtx;<br>+ // Push conn in ConnTable in which "j" is the Set Index<br>+ for (int k=Begin[j]; k<End[j]; ++k){<br>+ ConnTable[j].push_back( (cgsize_t)conn[k-Begin[j]] );<br>+ }<br>+ Begin[j] = End[j];<br>+ }<br>+ }<br>+ }<br>+ }<br>+ return MB_SUCCESS;<br>+}<br>+<br>+// Read the Moab type and return CGNS type<br>+int WriteCGNS::moab_cgns_conv(const EntityHandle handle)<br>+{<br>+ EntityType MoabType = mbImpl->type_from_handle( handle );<br>+ switch ( MoabType ){<br>+ case MBEDGE : /**< Mesh Edge */<br>+ return BAR_2;<br>+ case MBTRI : /**< Triangular element (including shells) */<br>+ return TRI_3;<br>+ case MBQUAD : /**< Quadrilateral element (including shells) */<br>+ return QUAD_4;<br>+ case MBTET : /**< Tetrahedral element */<br>+ return TETRA_4;<br>+ case MBPYRAMID : /**< Pyramid element */<br>+ return PYRA_5;<br>+ case MBPRISM : /**< Wedge element */<br>+ return PENTA_6;<br>+ case MBHEX : /**< Hexahedral element */<br>+ return HEXA_8;<br>+ default :<br>+ std::cout << "It was not possible to identify the CGNSType\n";<br>+ return 0;<br>+ }<br>+}<br>+<br>+} //namespace moab<br><br>This diff is so big that we needed to truncate the remainder.<br><br>Repository URL: https://bitbucket.org/fathomteam/moab/<br><br>--<br><br>This is a commit notification from bitbucket.org. You are receiving<br>this because you have the service enabled, addressing the recipient of<br>this email.<br></div><br></div></body></html>