deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
grid_in.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1999 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_grid_in_h
14#define dealii_grid_in_h
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_GMSH_WITH_API
20# include <deal.II/base/mpi.h>
21
23
24# include <gmsh.h>
25#endif
26
29#include <deal.II/base/point.h>
30
31#include <deal.II/lac/vector.h>
32
33#include <iostream>
34#include <map>
35#include <string>
36#include <vector>
37
39
40// Forward declarations
41#ifndef DOXYGEN
42template <int dim, int spacedim>
44class Triangulation;
45template <int dim>
46struct CellData;
47#endif
48
201template <int dim, int spacedim = dim>
203{
204public:
238
242 GridIn();
243
248
252 void
254
259 void
260 read(std::istream &in, Format format = Default);
261
266 void
267 read(const std::string &in, Format format = Default);
268
315 void
316 read_vtk(std::istream &in);
317
332 void
333 read_vtu(std::istream &in);
334
368 void
369 read_unv(std::istream &in);
370
410 void
411 read_ucd(std::istream &in,
412 const bool apply_all_indicators_to_manifolds = false);
413
453 void
454 read_abaqus(std::istream &in,
455 const bool apply_all_indicators_to_manifolds = false);
456
467 void
468 read_dbmesh(std::istream &in);
469
478 void
479 read_xda(std::istream &in);
480
500 void
501 read_msh(std::istream &in);
502
561 void
562 read_msh(const std::string &filename);
563
624 void
625 read_partitioned_msh(const std::string &file_prefix,
626 const std::string &file_suffix = "msh");
627
664 void
665 read_comsol_mphtxt(std::istream &in);
666
677 void
678 read_tecplot(std::istream &in);
679
714 void
715 read_assimp(const std::string &filename,
716 const unsigned int mesh_index = numbers::invalid_unsigned_int,
717 const bool remove_duplicates = true,
718 const double tol = 1e-12,
719 const bool ignore_unsupported_element_types = true);
720
729 void
730 read_ugrid(std::istream &in);
731
741 {
746 std::vector<std::vector<int>> id_to_sideset_ids;
747 };
748
806 read_exodusii(const std::string &filename,
807 const bool apply_all_indicators_to_manifolds = false);
808
812 static std::string
813 default_suffix(const Format format);
814
818 static Format
819 parse_format(const std::string &format_name);
820
826 static std::string
828
845 const std::map<std::string, Vector<double>> &
846 get_cell_data() const;
847
852 int,
853 << "The section type <" << arg1 << "> in an UNV "
854 << "input file is not implemented.");
855
860 int,
861 << "The element type <" << arg1 << "> in an UNV "
862 << "input file is not implemented.");
863
868 std::string,
869 << "The identifier <" << arg1 << "> as name of a "
870 << "part in an UCD input file is unknown or the "
871 << "respective input routine is not implemented. "
872 << "(Maybe the space dimension of triangulation and "
873 << "input file do not match?");
878 "No Triangulation has been attached to this GridIn object "
879 "so that nothing can be filled during any read function "
880 "calls. Please pass a reference to the Triangulation tria "
881 "to be filled in the constructor GridIn(tria) or attach "
882 "it with the function call GridIn::attach_triangulation().");
888 int,
889 int,
890 << "While creating cell " << arg1
891 << ", you are referencing a vertex with index " << arg2
892 << " but no vertex with this index has been described in the input file.");
898 int,
899 int,
900 int,
901 << "While creating cell " << arg1 << " (which is numbered as " << arg2
902 << " in the input file), you are referencing a vertex with index " << arg3
903 << " but no vertex with this index has been described in the input file.");
912 std::string,
913 << "The string <" << arg1
914 << "> is not recognized at the present"
915 << " position of a DB Mesh file.");
916
922 int,
923 << "The specified dimension " << arg1
924 << " is not the same as that of the triangulation to be created.");
925
927 std::string,
928 << "The string <" << arg1
929 << "> is not recognized at the present"
930 << " position of a Gmsh Mesh file.");
931
933 int,
934 << "The Element Identifier <" << arg1 << "> is not "
935 << "supported in the deal.II library when "
936 << "reading meshes in " << dim << " dimensions.\n"
937 << "Supported elements are: \n"
938 << "ELM-TYPE\n"
939 << "1 Line (2 nodes, 1 edge).\n"
940 << "2 Triangle (3 nodes, 3 edges).\n"
941 << "3 Quadrilateral (4 nodes, 4 edges).\n"
942 << "4 Tetrahedron (4 nodes, 6 edges, 4 faces) when in 3d.\n"
943 << "5 Hexahedron (8 nodes, 12 edges, 6 faces) when in 3d.\n"
944 << "15 Point (1 node, ignored when read).");
945
946
949 unsigned int,
950 unsigned int,
951 "While reading a gmsh file, the reader function did not find "
952 "any cells. This sometimes happens if the file only contains a "
953 "surface mesh, but not a volume mesh."
954 "\n\n"
955 "The reader function did find " +
956 std::to_string(arg1) + " lines and " + std::to_string(arg2) +
957 " facets (surface triangles or quadrilaterals).");
958
959protected:
964
985 static void
986 debug_output_grid(const std::vector<CellData<dim>> &cells,
987 const std::vector<Point<spacedim>> &vertices,
988 std::ostream &out);
989
990private:
995 static void
996 skip_empty_lines(std::istream &in);
997
1005 static void
1006 skip_comment_lines(std::istream &in, const char comment_start);
1007
1015 static void
1016 parse_tecplot_header(std::string &header,
1017 std::vector<unsigned int> &tecplot2deal,
1018 unsigned int &n_vars,
1019 unsigned int &n_vertices,
1020 unsigned int &n_cells,
1021 std::vector<unsigned int> &IJK,
1022 bool &structured,
1023 bool &blocked);
1024
1029
1039 std::map<std::string, Vector<double>> cell_data;
1040};
1041
1042/* -------------- declaration of explicit specializations ------------- */
1043
1044#ifndef DOXYGEN
1045
1046template <>
1047void
1048GridIn<2>::debug_output_grid(const std::vector<CellData<2>> &cells,
1049 const std::vector<Point<2>> &vertices,
1050 std::ostream &out);
1051
1052
1053template <>
1054void
1055GridIn<2, 3>::debug_output_grid(const std::vector<CellData<2>> &cells,
1056 const std::vector<Point<3>> &vertices,
1057 std::ostream &out);
1058template <>
1059void
1060GridIn<3>::debug_output_grid(const std::vector<CellData<3>> &cells,
1061 const std::vector<Point<3>> &vertices,
1062 std::ostream &out);
1063#endif // DOXYGEN
1064
1066
1067#endif
@ Default
Use GridIn::default_format stored in this object.
Definition grid_in.h:212
@ vtu
Use read_vtu()
Definition grid_in.h:230
@ xda
Use read_xda()
Definition grid_in.h:222
@ tecplot
Use read_tecplot()
Definition grid_in.h:226
@ ugrid
Use read_ugrid()
Definition grid_in.h:236
@ msh
Use read_msh()
Definition grid_in.h:224
@ ucd
Use read_ucd()
Definition grid_in.h:216
@ dbmesh
Use read_dbmesh()
Definition grid_in.h:220
@ abaqus
Use read_abaqus()
Definition grid_in.h:218
@ assimp
Use read_assimp()
Definition grid_in.h:232
@ unv
Use read_unv()
Definition grid_in.h:214
@ exodusii
Use read_exodusii()
Definition grid_in.h:234
@ vtk
Use read_vtk()
Definition grid_in.h:228
void read_vtk(std::istream &in)
Definition grid_in.cc:164
GridIn()
Definition grid_in.cc:138
static void skip_empty_lines(std::istream &in)
Definition grid_in.cc:4814
void read_partitioned_msh(const std::string &file_prefix, const std::string &file_suffix="msh")
Definition grid_in.cc:3175
void read_assimp(const std::string &filename, const unsigned int mesh_index=numbers::invalid_unsigned_int, const bool remove_duplicates=true, const double tol=1e-12, const bool ignore_unsupported_element_types=true)
Definition grid_in.cc:4028
void read_ugrid(std::istream &in)
Definition grid_in.cc:4183
std::map< std::string, Vector< double > > cell_data
Definition grid_in.h:1039
void read_abaqus(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
Definition grid_in.cc:1354
static std::string default_suffix(const Format format)
Definition grid_in.cc:5122
void read_xda(std::istream &in)
Definition grid_in.cc:1571
void read_comsol_mphtxt(std::istream &in)
Definition grid_in.cc:1635
static void skip_comment_lines(std::istream &in, const char comment_start)
Definition grid_in.cc:4844
void attach_triangulation(Triangulation< dim, spacedim > &tria)
Definition grid_in.cc:155
const std::map< std::string, Vector< double > > & get_cell_data() const
Definition grid_in.cc:766
void read_msh(std::istream &in)
Definition grid_in.cc:2199
static Format parse_format(const std::string &format_name)
Definition grid_in.cc:5159
void read_vtu(std::istream &in)
Definition grid_in.cc:773
void read_tecplot(std::istream &in)
Definition grid_in.cc:4019
Format default_format
Definition grid_in.h:1028
ExodusIIData read_exodusii(const std::string &filename, const bool apply_all_indicators_to_manifolds=false)
Definition grid_in.cc:4649
void read_dbmesh(std::istream &in)
Definition grid_in.cc:1410
void read_ucd(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
Definition grid_in.cc:1100
ObserverPointer< Triangulation< dim, spacedim >, GridIn< dim, spacedim > > tria
Definition grid_in.h:963
void read(std::istream &in, Format format=Default)
Definition grid_in.cc:5051
static void debug_output_grid(const std::vector< CellData< dim > > &cells, const std::vector< Point< spacedim > > &vertices, std::ostream &out)
Definition grid_in.cc:4870
static std::string get_format_names()
Definition grid_in.cc:5219
void read_unv(std::istream &in)
Definition grid_in.cc:800
static void parse_tecplot_header(std::string &header, std::vector< unsigned int > &tecplot2deal, unsigned int &n_vars, unsigned int &n_vertices, unsigned int &n_cells, std::vector< unsigned int > &IJK, bool &structured, bool &blocked)
Definition grid_in.cc:3551
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DeclException0(Exception0)
static ::ExceptionBase & ExcInvalidDBMeshFormat()
static ::ExceptionBase & ExcUnknownIdentifier(std::string arg1)
static ::ExceptionBase & ExcInvalidGMSHInput(std::string arg1)
static ::ExceptionBase & ExcInvalidDBMESHInput(std::string arg1)
static ::ExceptionBase & ExcDBMESHWrongDimension(int arg1)
static ::ExceptionBase & ExcInvalidVertexIndex(int arg1, int arg2)
static ::ExceptionBase & ExcNoTriangulationSelected()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcUnknownElementType(int arg1)
static ::ExceptionBase & ExcGmshNoCellInformation(unsigned int arg1, unsigned int arg2)
static ::ExceptionBase & ExcInvalidVertexIndexGmsh(int arg1, int arg2, int arg3)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcUnknownSectionType(int arg1)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcGmshUnsupportedGeometry(int arg1)
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
std::vector< std::vector< int > > id_to_sideset_ids
Definition grid_in.h:746