libMesh
Public Member Functions | List of all members
WriteSidesetData Class Reference
Inheritance diagram for WriteSidesetData:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (WriteSidesetData)
 This test ensures you can write both vector and scalar variables. More...
 
 CPPUNIT_TEST (testWrite)
 
 CPPUNIT_TEST_SUITE_END ()
 
void testWrite ()
 

Detailed Description

Definition at line 17 of file write_sideset_data.C.

Member Function Documentation

◆ CPPUNIT_TEST()

WriteSidesetData::CPPUNIT_TEST ( testWrite  )

◆ CPPUNIT_TEST_SUITE()

WriteSidesetData::CPPUNIT_TEST_SUITE ( WriteSidesetData  )

This test ensures you can write both vector and scalar variables.

◆ CPPUNIT_TEST_SUITE_END()

WriteSidesetData::CPPUNIT_TEST_SUITE_END ( )

◆ testWrite()

void WriteSidesetData::testWrite ( )
inline

Definition at line 31 of file write_sideset_data.C.

32  {
34 
35  // We set our initial conditions based on build_square node ids
36  mesh.allow_renumbering(false);
37 
39  /*nx=*/5, /*ny=*/5,
40  -1., 1.,
41  -1., 1.,
42  QUAD4);
43 
44  // Get list of all (elem, side, id) tuples
45  std::vector<BoundaryInfo::BCTuple> all_bc_tuples =
47 
48  // Data structures to be passed to ExodusII_IO::write_sideset_data
49  std::vector<std::string> var_names = {"var1", "var2"};
50  std::vector<std::set<boundary_id_type>> side_ids =
51  {
52  {0, 2}, // var1 is defined on sidesets 0 and 2
53  {1, 3} // var2 is defined on sidesets 1 and 3
54  };
55 
56  // Data structure mapping (elem, side, id) tuples to Real values that
57  // will be passed to Exodus.
58  std::vector<std::map<BoundaryInfo::BCTuple, Real>> bc_vals(var_names.size());
59 
60  // For each var_names[i], construct bc_vals[i]
61  for (unsigned int i=0; i<var_names.size(); ++i)
62  {
63  // const auto & var_name = var_names[i];
64  auto & vals = bc_vals[i];
65 
66  for (const auto & t : all_bc_tuples)
67  {
68  // dof_id_type elem_id = std::get<0>(t);
69  // unsigned int side_id = std::get<1>(t);
70  boundary_id_type b_id = std::get<2>(t);
71 
72  if (side_ids[i].count(b_id))
73  {
74  // Compute a value. This could in theory depend on
75  // var_name, elem_id, side_id, and/or b_id.
76  Real val = static_cast<Real>(b_id);
77 
78  // Insert into the vals map.
79  vals.insert(std::make_pair(t, val));
80  }
81  }
82 
83  // If we have a distributed mesh, write_sideset_data wants our
84  // ghost data too; we'll just serialize everything here.
85  if (!mesh.is_serial())
86  TestCommWorld->set_union(vals);
87 
88  } // done constructing bc_vals
89 
90 #ifdef LIBMESH_HAVE_EXODUS_API
91 
92  // We write the file in the ExodusII format.
93  {
94  ExodusII_IO writer(mesh);
95  writer.write("write_sideset_data.e");
96  writer.write_sideset_data (/*timestep=*/1, var_names, side_ids, bc_vals);
97  }
98 
99  // Make sure that the writing is done before the reading starts.
100  TestCommWorld->barrier();
101 
102  // Now read it back in
103  Mesh read_mesh(*TestCommWorld);
104  ExodusII_IO reader(read_mesh);
105  reader.read("write_sideset_data.e");
106 
107  std::vector<std::string> read_in_var_names;
108  std::vector<std::set<boundary_id_type>> read_in_side_ids;
109  std::vector<std::map<BoundaryInfo::BCTuple, Real>> read_in_bc_vals;
110  reader.read_sideset_data
111  (/*timestep=*/1, read_in_var_names, read_in_side_ids, read_in_bc_vals);
112 
113  // Assert that we got back out what we put in.
114  CPPUNIT_ASSERT(read_in_var_names == var_names);
115  CPPUNIT_ASSERT(read_in_side_ids == side_ids);
116  CPPUNIT_ASSERT(read_in_bc_vals == bc_vals);
117 
118 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
119  }

References libMesh::MeshBase::allow_renumbering(), libMesh::BoundaryInfo::build_side_list(), libMesh::MeshTools::Generation::build_square(), libMesh::MeshBase::get_boundary_info(), libMesh::MeshBase::is_serial(), mesh, libMesh::QUAD4, libMesh::ExodusII_IO::read(), libMesh::ExodusII_IO::read_sideset_data(), libMesh::Real, TestCommWorld, libMesh::ExodusII_IO::write(), and libMesh::ExodusII_IO::write_sideset_data().


The documentation for this class was generated from the following file:
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::MeshBase::get_boundary_info
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:132
libMesh::MeshBase::is_serial
virtual bool is_serial() const
Definition: mesh_base.h:159
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::boundary_id_type
int8_t boundary_id_type
Definition: id_types.h:51
libMesh::BoundaryInfo::build_side_list
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
Creates a list of element numbers, sides, and ids for those sides.
Definition: boundary_info.C:1976
libMesh::MeshTools::Generation::build_square
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
Definition: mesh_generation.C:1501
libMesh::QUAD4
Definition: enum_elem_type.h:41
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::MeshBase::allow_renumbering
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
Definition: mesh_base.h:1025
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121