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

Public Member Functions

 CPPUNIT_TEST_SUITE (MeshInputTest)
 
 CPPUNIT_TEST (testExodusCopyElementSolution)
 
 CPPUNIT_TEST (testExodusWriteElementDataFromDiscontinuousNodalData)
 
 CPPUNIT_TEST (testDynaReadElem)
 
 CPPUNIT_TEST (testDynaReadPatch)
 
 CPPUNIT_TEST (testMeshMoveConstructor)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testExodusCopyElementSolution ()
 
void testExodusWriteElementDataFromDiscontinuousNodalData ()
 
void testDynaReadElem ()
 
void testDynaReadPatch ()
 
void testMeshMoveConstructor ()
 

Detailed Description

Definition at line 31 of file mesh_input.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/5]

MeshInputTest::CPPUNIT_TEST ( testDynaReadElem  )

◆ CPPUNIT_TEST() [2/5]

MeshInputTest::CPPUNIT_TEST ( testDynaReadPatch  )

◆ CPPUNIT_TEST() [3/5]

MeshInputTest::CPPUNIT_TEST ( testExodusCopyElementSolution  )

◆ CPPUNIT_TEST() [4/5]

MeshInputTest::CPPUNIT_TEST ( testExodusWriteElementDataFromDiscontinuousNodalData  )

◆ CPPUNIT_TEST() [5/5]

MeshInputTest::CPPUNIT_TEST ( testMeshMoveConstructor  )

◆ CPPUNIT_TEST_SUITE()

MeshInputTest::CPPUNIT_TEST_SUITE ( MeshInputTest  )

◆ CPPUNIT_TEST_SUITE_END()

MeshInputTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void MeshInputTest::setUp ( )
inline

Definition at line 54 of file mesh_input.C.

55  {}

◆ tearDown()

void MeshInputTest::tearDown ( )
inline

Definition at line 57 of file mesh_input.C.

58  {}

◆ testDynaReadElem()

void MeshInputTest::testDynaReadElem ( )
inline

Definition at line 214 of file mesh_input.C.

215  {
217 
218  DynaIO dyna(mesh);
219 
220  // Make DynaIO::add_spline_constraints work on DistributedMesh
221  mesh.allow_renumbering(false);
223 
224  if (mesh.processor_id() == 0)
225  dyna.read("1_quad.dyn");
227 
229 
230  // We have 1 QUAD9 finite element, attached via a trivial map to 9
231  // spline Node+NodeElem objects
232  CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), dof_id_type(10));
233  CPPUNIT_ASSERT_EQUAL(mesh.n_nodes(), dof_id_type(18));
234 
235  CPPUNIT_ASSERT_EQUAL(mesh.default_mapping_type(),
237 
238  unsigned char weight_index = mesh.default_mapping_data();
239 
240  for (auto & elem : mesh.element_ptr_range())
241  {
242  if (elem->type() == NODEELEM)
243  continue;
244 
245  CPPUNIT_ASSERT_EQUAL(elem->type(), QUAD9);
246  for (unsigned int n=0; n != 9; ++n)
247  CPPUNIT_ASSERT_EQUAL
248  (elem->node_ref(n).get_extra_datum<Real>(weight_index),
249  Real(0.75));
250 
251  CPPUNIT_ASSERT_EQUAL(elem->point(0)(0), Real(0.5));
252  CPPUNIT_ASSERT_EQUAL(elem->point(0)(1), Real(0.5));
253  CPPUNIT_ASSERT_EQUAL(elem->point(1)(0), Real(1.5));
254  CPPUNIT_ASSERT_EQUAL(elem->point(1)(1), Real(0.5));
255  CPPUNIT_ASSERT_EQUAL(elem->point(2)(0), Real(1.5));
256  CPPUNIT_ASSERT_EQUAL(elem->point(2)(1), Real(1.5));
257  CPPUNIT_ASSERT_EQUAL(elem->point(3)(0), Real(0.5));
258  CPPUNIT_ASSERT_EQUAL(elem->point(3)(1), Real(1.5));
259  CPPUNIT_ASSERT(elem->has_affine_map());
260 #if LIBMESH_DIM > 2
261  for (unsigned int v=0; v != 4; ++v)
262  CPPUNIT_ASSERT_EQUAL(elem->point(v)(2), Real(0));
263 #endif
264  }
265  }

References libMesh::MeshBase::allow_remote_element_removal(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshCommunication::broadcast(), libMesh::MeshBase::default_mapping_data(), libMesh::MeshBase::default_mapping_type(), libMesh::MeshBase::element_ptr_range(), mesh, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::NODEELEM, libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::QUAD9, libMesh::RATIONAL_BERNSTEIN_MAP, libMesh::DynaIO::read(), libMesh::Real, and TestCommWorld.

◆ testDynaReadPatch()

void MeshInputTest::testDynaReadPatch ( )
inline

Definition at line 268 of file mesh_input.C.

269  {
271 
272  // Make DynaIO::add_spline_constraints work on DistributedMesh
273  mesh.allow_renumbering(false);
275 
276  DynaIO dyna(mesh);
277  if (mesh.processor_id() == 0)
278  dyna.read("25_quad.bxt");
280 
282 
283  // We have 5^2 QUAD9 elements, with 11^2 nodes,
284  // tied to 49 Node/NodeElem spline nodes
285  CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), dof_id_type(25+49));
286  CPPUNIT_ASSERT_EQUAL(mesh.n_nodes(), dof_id_type(121+49));
287 
288  CPPUNIT_ASSERT_EQUAL(mesh.default_mapping_type(),
290 
291  unsigned char weight_index = mesh.default_mapping_data();
292 
293  for (const auto & elem : mesh.active_element_ptr_range())
294  {
295  if (elem->type() == NODEELEM)
296  continue;
297  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(0.04), elem->volume(), TOLERANCE);
298 
299  for (unsigned int n=0; n != 9; ++n)
300  CPPUNIT_ASSERT_EQUAL
301  (elem->node_ref(n).get_extra_datum<Real>(weight_index),
302  Real(1.0));
303 
304  unsigned int n_neighbors = 0, n_neighbors_expected = 2;
305  for (unsigned int side=0; side != 4; ++side)
306  if (elem->neighbor_ptr(side))
307  n_neighbors++;
308  Point c = elem->centroid();
309 
310  if (c(0) > 0.2 && c(0) < 0.8)
311  n_neighbors_expected++;
312  if (c(1) > 0.2 && c(1) < 0.8)
313  n_neighbors_expected++;
314 
315  CPPUNIT_ASSERT_EQUAL(n_neighbors, n_neighbors_expected);
316  }
317 
318 #ifdef LIBMESH_ENABLE_CONSTRAINTS
319  // Now test whether we can assign the desired constraint equations
320  EquationSystems es(mesh);
321  ImplicitSystem & sys = es.add_system<ImplicitSystem>("test");
322  sys.add_variable("u", SECOND); // to match QUAD9
323  es.init();
324  dyna.add_spline_constraints(sys.get_dof_map(), 0, 0);
325 
326  // We should have a constraint on every FE dof
327  CPPUNIT_ASSERT_EQUAL(sys.get_dof_map().n_constrained_dofs(), dof_id_type(121));
328 #endif // LIBMESH_ENABLE_CONSTRAINTS
329  }

References libMesh::MeshBase::active_element_ptr_range(), libMesh::DynaIO::add_spline_constraints(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_remote_element_removal(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshCommunication::broadcast(), libMesh::MeshBase::default_mapping_data(), libMesh::MeshBase::default_mapping_type(), libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::libmesh_real(), mesh, libMesh::DofMap::n_constrained_dofs(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::NODEELEM, libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::RATIONAL_BERNSTEIN_MAP, libMesh::DynaIO::read(), libMesh::Real, libMesh::SECOND, TestCommWorld, and libMesh::TOLERANCE.

◆ testExodusCopyElementSolution()

void MeshInputTest::testExodusCopyElementSolution ( )
inline

Definition at line 61 of file mesh_input.C.

62  {
63  {
65 
67  System &sys = es.add_system<System> ("SimpleSystem");
68  sys.add_variable("e", CONSTANT, MONOMIAL);
69 
71  3, 3,
72  0., 1., 0., 1.);
73 
74  es.init();
75  sys.project_solution(x_plus_y, nullptr, es.parameters);
76 
77  ExodusII_IO exii(mesh);
78 
79  // Don't try to write element data as nodal data
80  std::set<std::string> sys_list;
81  exii.write_equation_systems("mesh_with_soln.e", es, &sys_list);
82 
83  // Just write it as element data
84  exii.write_element_data(es);
85  }
86 
87  // copy_elemental_solution currently requires ReplicatedMesh
88  {
90 
92  System &sys = es.add_system<System> ("SimpleSystem");
93  sys.add_variable("teste", CONSTANT, MONOMIAL);
94 
95  ExodusII_IO exii(mesh);
96 
97  if (mesh.processor_id() == 0)
98  exii.read("mesh_with_soln.e");
101 
102  es.init();
103 
104  // Read the solution e into variable teste.
105  //
106  // With complex numbers, we'll only bother reading the real
107  // part.
108 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
109  exii.copy_elemental_solution(sys, "teste", "r_e");
110 #else
111  exii.copy_elemental_solution(sys, "teste", "e");
112 #endif
113 
114  // Exodus only handles double precision
115  Real exotol = std::max(TOLERANCE*TOLERANCE, Real(1e-12));
116 
117  for (Real x = Real(1.L/6.L); x < 1; x += Real(1.L/3.L))
118  for (Real y = Real(1.L/6.L); y < 1; y += Real(1.L/3.L))
119  {
120  Point p(x,y);
121  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(sys.point_value(0,p)),
122  libmesh_real(x+y),
123  exotol);
124  }
125  }
126  }

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshCommunication::broadcast(), libMesh::MeshTools::Generation::build_square(), libMesh::CONSTANT, libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::EquationSystems::init(), libMesh::libmesh_real(), mesh, libMesh::MONOMIAL, libMesh::EquationSystems::parameters, libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::System::project_solution(), libMesh::ExodusII_IO::read(), libMesh::Real, TestCommWorld, libMesh::TOLERANCE, libMesh::ExodusII_IO::write_element_data(), libMesh::MeshOutput< MT >::write_equation_systems(), and x_plus_y().

◆ testExodusWriteElementDataFromDiscontinuousNodalData()

void MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData ( )
inline

Definition at line 130 of file mesh_input.C.

131  {
132  // first scope: write file
133  {
135 
136  EquationSystems es(mesh);
137  System & sys = es.add_system<System> ("SimpleSystem");
138  sys.add_variable("u", FIRST, L2_LAGRANGE);
139 
141  (mesh, 2, 2, 2, 0., 1., 0., 1., 0., 1., HEX8);
142 
143  es.init();
144 
145  // Set solution u^e_i = i, for the ith vertex of a given element e.
146  const DofMap & dof_map = sys.get_dof_map();
147  std::vector<dof_id_type> dof_indices;
148  for (const auto & elem : mesh.element_ptr_range())
149  {
150  dof_map.dof_indices(elem, dof_indices, /*var_id=*/0);
151  for (unsigned int i=0; i<dof_indices.size(); ++i)
152  sys.solution->set(dof_indices[i], i);
153  }
154  sys.solution->close();
155 
156  // Now write to file.
157  ExodusII_IO exii(mesh);
158 
159  // Don't try to write element data as averaged nodal data.
160  std::set<std::string> sys_list;
161  exii.write_equation_systems("elemental_from_nodal.e", es, &sys_list);
162 
163  // Write one elemental data field per vertex value.
164  sys_list = {"SimpleSystem"};
165 
166  exii.write_element_data_from_discontinuous_nodal_data
167  (es, &sys_list, /*var_suffix=*/"_elem_corner_");
168  } // end first scope
169 
170  // second scope: read values back in, verify they are correct.
171  {
172  std::vector<std::string> file_var_names =
173  {"u_elem_corner_0",
174  "u_elem_corner_1",
175  "u_elem_corner_2",
176  "u_elem_corner_3"};
177  std::vector<Real> expected_values = {0., 1., 2., 3.};
178 
179  // copy_elemental_solution currently requires ReplicatedMesh
181 
182  EquationSystems es(mesh);
183  System & sys = es.add_system<System> ("SimpleSystem");
184  for (auto i : index_range(file_var_names))
185  sys.add_variable(file_var_names[i], CONSTANT, MONOMIAL);
186 
187  ExodusII_IO exii(mesh);
188 
189  if (mesh.processor_id() == 0)
190  exii.read("elemental_from_nodal.e");
193 
194  es.init();
195 
196  for (auto i : index_range(file_var_names))
197  exii.copy_elemental_solution
198  (sys, sys.variable_name(i), file_var_names[i]);
199 
200  // Check that the values we read back in are as expected.
201  for (const auto & elem : mesh.active_element_ptr_range())
202  for (auto i : index_range(file_var_names))
203  {
204  Real read_val = sys.point_value(i, elem->centroid());
205  LIBMESH_ASSERT_FP_EQUAL
206  (read_val, expected_values[i], TOLERANCE*TOLERANCE);
207  }
208  } // end second scope
209  } // end testExodusWriteElementDataFromDiscontinuousNodalData

References libMesh::MeshBase::active_element_ptr_range(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshCommunication::broadcast(), libMesh::MeshTools::Generation::build_cube(), libMesh::CONSTANT, libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::DofMap::dof_indices(), libMesh::MeshBase::element_ptr_range(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::HEX8, libMesh::index_range(), libMesh::EquationSystems::init(), libMesh::L2_LAGRANGE, mesh, libMesh::MONOMIAL, libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::ExodusII_IO::read(), libMesh::Real, libMesh::System::solution, TestCommWorld, libMesh::TOLERANCE, libMesh::System::variable_name(), libMesh::ExodusII_IO::write_element_data_from_discontinuous_nodal_data(), and libMesh::MeshOutput< MT >::write_equation_systems().

◆ testMeshMoveConstructor()

void MeshInputTest::testMeshMoveConstructor ( )
inline

Definition at line 332 of file mesh_input.C.

333  {
336  3, 3,
337  0., 1., 0., 1.);
338 
339  // Construct mesh2, stealing the resources of the original.
340  Mesh mesh2(std::move(mesh));
341 
342  // Make sure mesh2 now has the 9 elements.
343  CPPUNIT_ASSERT_EQUAL(mesh2.n_elem(),
344  static_cast<dof_id_type>(9));
345 
346  // Verify that the moved-from mesh's Partitioner and BoundaryInfo
347  // objects were successfully stolen. Note: moved-from unique_ptrs
348  // are guaranteed to compare equal to nullptr, see e.g. Section
349  // 20.8.1/4 of the standard.
350  // https://stackoverflow.com/questions/24061767/is-unique-ptr-guaranteed-to-store-nullptr-after-move
351  CPPUNIT_ASSERT(!mesh.partitioner());
352  CPPUNIT_ASSERT(!mesh.boundary_info);
353  }

References libMesh::MeshBase::boundary_info, libMesh::MeshTools::Generation::build_square(), mesh, libMesh::DistributedMesh::n_elem(), libMesh::MeshBase::partitioner(), and TestCommWorld.


The documentation for this class was generated from the following file:
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::MeshBase::default_mapping_type
ElemMappingType default_mapping_type() const
Returns the default master space to physical space mapping basis functions to be used on newly added ...
Definition: mesh_base.h:708
libMesh::ImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
Definition: implicit_system.h:57
libMesh::DofMap::dof_indices
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1967
libMesh::DofMap::n_constrained_dofs
dof_id_type n_constrained_dofs() const
Definition: dof_map_constraints.C:1184
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
x_plus_y
Number x_plus_y(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: mesh_input.C:19
libMesh::MeshBase::active_element_ptr_range
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
libMesh::MeshBase::n_elem
virtual dof_id_type n_elem() const =0
libMesh::System::variable_name
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2203
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::MeshTools::Generation::build_cube
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Definition: mesh_generation.C:298
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
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::SECOND
Definition: enum_order.h:43
libMesh::RATIONAL_BERNSTEIN_MAP
Definition: enum_elem_type.h:84
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::MeshBase::element_ptr_range
virtual SimpleRange< element_iterator > element_ptr_range()=0
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::MeshCommunication::broadcast
void broadcast(MeshBase &) const
Definition: mesh_communication.C:1084
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::System::add_variable
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1069
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::CONSTANT
Definition: enum_order.h:41
libMesh::DynaIO
Reading and writing meshes in (a subset of) LS-DYNA format.
Definition: dyna_io.h:52
libMesh::MONOMIAL
Definition: enum_fe_family.h:39
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshBase::n_nodes
virtual dof_id_type n_nodes() const =0
libMesh::MeshBase::boundary_info
std::unique_ptr< BoundaryInfo > boundary_info
This class holds the boundary information.
Definition: mesh_base.h:1659
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::System::point_value
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:1971
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::NODEELEM
Definition: enum_elem_type.h:66
libMesh::L2_LAGRANGE
Definition: enum_fe_family.h:41
libMesh::MeshBase::allow_remote_element_removal
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition: mesh_base.h:1034
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::MeshBase::default_mapping_data
unsigned char default_mapping_data() const
Returns any default data value used by the master space to physical space mapping.
Definition: mesh_base.h:724
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
libMesh::MeshBase::prepare_for_use
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:318
libMesh::MeshCommunication
This is the MeshCommunication class.
Definition: mesh_communication.h:50
libMesh::System::project_solution
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Definition: system_projection.C:950
libMesh::FIRST
Definition: enum_order.h:42
libMesh::MeshBase::partitioner
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each prepare_for_use()
Definition: mesh_base.h:127