2#include "libmesh/distributed_mesh.h"
3#include "libmesh/equation_systems.h"
4#include "libmesh/exodusII_io.h"
5#include "libmesh/explicit_system.h"
6#include "libmesh/mesh_generation.h"
7#include "libmesh/nemesis_io.h"
8#include "libmesh/node.h"
9#include "libmesh/numeric_vector.h"
10#include "libmesh/replicated_mesh.h"
11#include "libmesh/string_to_enum.h"
29#if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
48 Utility::string_to_enum<ElemType>(
"TRI6"));
55 equation_systems.
init();
59 std::vector<Real> initial_vector({10, 0, 12, 8, 4, 2, 16, 6, 14});
62 for (
const auto & node :
mesh.node_ptr_range())
65 if (node->n_comp(0,0))
67 dof_id = node->dof_number(0,0,0);
71 CPPUNIT_ASSERT(node->n_comp(0,1));
72 dof_id = node->dof_number(0,1,0);
74 if (dof_id >= sys_solution.first_local_index() &&
75 dof_id < sys_solution.last_local_index())
76 sys_solution.set(dof_id, initial_vector[node->id()]);
78 CPPUNIT_ASSERT_EQUAL(initial_vector[node->id()], dof_id*
Real(2));
90 const std::vector<Real> gold_vector = {-1, 3, 10,
105 const std::vector<dof_id_type>
106 node_reordering({0, 3, 1, 8, 5, 4, 6, 7, 2});
110 for (
const auto & node : read_mesh.node_ptr_range())
117#ifdef LIBMESH_USE_COMPLEX_NUMBERS
118 const unsigned int v2 = 3;
120 const unsigned int v2 = 1;
122 CPPUNIT_ASSERT_EQUAL(node->n_vars(0), 3*v2);
127 const auto grid_index =
128 cast_int<dof_id_type>(std::lround((*node)(0)) + 1 +
129 3*(std::lround((*node)(1)) + 1));
131 CPPUNIT_ASSERT_LESS(node_reordering.size(), std::size_t(grid_index));
132 const dof_id_type gold_i_ux = node_reordering[grid_index] * 3;
135 CPPUNIT_ASSERT_LESS(gold_vector.size(), std::size_t(gold_i_v));
137 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,0,0)),
138 gold_vector[gold_i_ux], tol);
139 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,v2,0)),
140 gold_vector[gold_i_uy], tol);
141 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,2*v2,0)),
142 gold_vector[gold_i_v], tol);
145#ifdef LIBMESH_USE_COMPLEX_NUMBERS
146 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,1,0)),
148 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,2,0)),
149 std::abs(gold_vector[gold_i_ux]), tol);
150 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,4,0)),
152 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,5,0)),
153 std::abs(gold_vector[gold_i_uy]), tol);
154 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,7,0)),
156 LIBMESH_ASSERT_NUMBERS_EQUAL(sys2_soln(node->dof_number(0,8,0)),
157 std::abs(gold_vector[gold_i_v]), tol);
163#ifdef LIBMESH_HAVE_EXODUS_API
164 template <
typename MeshType>
183 read_mesh.allow_renumbering(
false);
187 read_mesh.prepare_for_use();
193 for (
const auto & var_name : nodal_vars)
198 for (
const auto & var_name : nodal_vars)
209#ifdef LIBMESH_HAVE_NEMESIS_API
210 template <
typename MeshType>
229 read_mesh.allow_renumbering(
false);
231 nemio.
read(filename);
233 read_mesh.prepare_for_use();
239 for (
const auto & var_name : nodal_vars)
244 for (
const auto & var_name : nodal_vars)
void testSolution(const MeshBase &read_mesh, const System &sys2)
void setupTests(UnstructuredMesh &mesh, EquationSystems &equation_systems)
void testWriteExodus(const std::string &filename)
void testWriteNemesis(const std::string &filename)
void testWriteExodusDistributed()
CPPUNIT_TEST(testWriteExodusReplicated)
CPPUNIT_TEST(testWriteExodusDistributed)
LIBMESH_CPPUNIT_TEST_SUITE(WriteVecAndScalar)
This test ensures you can write both vector and scalar variables.
CPPUNIT_TEST(testWriteNemesisDistributed)
CPPUNIT_TEST(testWriteNemesisReplicated)
void testWriteExodusReplicated()
void testWriteNemesisReplicated()
void testWriteNemesisDistributed()
This is the EquationSystems class.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
void copy_nodal_solution(System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution in...
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
This is the MeshBase class.
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
virtual void read(const std::string &base_filename) override
Implements reading the mesh from several different files.
void copy_nodal_solution(System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution in...
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
processor_id_type processor_id() const
processor_id_type n_processors() const
Manages consistently variables, degrees of freedom, and coefficient vectors.
unsigned int add_variable(std::string_view 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.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
The UnstructuredMesh class is derived from the MeshBase class.
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CPPUNIT_TEST_SUITE_REGISTRATION(WriteVecAndScalar)