libMesh
meshnorm.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // Open the mesh and solution file named on standard input, find all
21 // variables therein, and output their norms and seminorms.
22 #include "libmesh/libmesh.h"
23 #include "libmesh/mesh.h"
24 #include "libmesh/equation_systems.h"
25 #include "libmesh/enum_norm_type.h"
26 
27 using namespace libMesh;
28 
29 void output_norms(const System & sys, const NumericVector<Number> & vec, const std::string & vecname)
30 {
31  for (unsigned int k = 0; k != sys.n_vars(); ++k)
32  {
33  libMesh::out << "Norms in system " << sys.name() <<
34  ", vector " << vecname <<
35  ", variable " << sys.variable_name(k) << ":" << std::endl;
36  Real l1_vecnorm = sys.calculate_norm(vec, k, DISCRETE_L1);
37  libMesh::out << "l1 norm: " << l1_vecnorm << std::endl;
38  if (l1_vecnorm)
39  {
40  libMesh::out << "l2 norm: " << sys.calculate_norm(vec, k, DISCRETE_L2) << std::endl;
41  libMesh::out << "linf norm: " << sys.calculate_norm(vec, k, DISCRETE_L_INF) << std::endl;
42  libMesh::out << "H1 norm: " << sys.calculate_norm(vec, k, H1) << std::endl;
43  libMesh::out << "L1 norm: " << sys.calculate_norm(vec, k, L1) << std::endl;
44  libMesh::out << "L2 norm: " << sys.calculate_norm(vec, k, L2) << std::endl;
45  libMesh::out << "Linf norm: " << sys.calculate_norm(vec, k, L_INF) << std::endl;
46  libMesh::out << "H1 seminorm: " << sys.calculate_norm(vec, k, H1_SEMINORM) << std::endl;
47  libMesh::out << "H1 norm: " << sys.calculate_norm(vec, k, H1) << std::endl;
48  }
49  }
50 }
51 
52 int main(int argc, char ** argv)
53 {
54  LibMeshInit init (argc, argv);
55 
56  Mesh mesh(init.comm());
58 
59  libMesh::out << "Usage: " << argv[0]
60  << " mesh solution" << std::endl;
61 
62  libMesh::out << "Loading..." << std::endl;
63 
64  mesh.read(argv[1]);
65  libMesh::out << "Loaded mesh " << argv[1] << std::endl;
66  mesh.print_info();
67 
68  es.read(argv[2], EquationSystems::READ_HEADER |
72  libMesh::out << "Loaded solution " << argv[2] << std::endl;
73  es.print_info();
74 
76 
77  for (unsigned int i = 0; i != es.n_systems(); ++i)
78  {
79  System & sys = es.get_system(i);
80 
81  output_norms(sys, *sys.solution, std::string("solution"));
82  for (unsigned int j = 0; j != sys.n_vectors(); ++j)
83  output_norms(sys, sys.get_vector(j), sys.vector_name(j));
84  }
85 }
libMesh::DISCRETE_L_INF
Definition: enum_norm_type.h:54
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::System::n_vars
unsigned int n_vars() const
Definition: system.h:2155
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::MeshBase::read
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
libMesh::EquationSystems::READ_ADDITIONAL_DATA
Definition: equation_systems.h:85
libMesh::L_INF
Definition: enum_norm_type.h:42
libMesh::DISCRETE_L2
Definition: enum_norm_type.h:53
libMesh::System::variable_name
const std::string & variable_name(const unsigned int i) const
Definition: system.h:2203
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::L1
Definition: enum_norm_type.h:41
libMesh::System::n_vectors
unsigned int n_vectors() const
Definition: system.h:2283
libMesh::H1_SEMINORM
Definition: enum_norm_type.h:43
main
int main(int argc, char **argv)
Definition: meshnorm.C:52
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::System::vector_name
const std::string & vector_name(const unsigned int vec_num) const
Definition: system.C:820
libMesh::NumericVector< Number >
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
output_norms
void output_norms(const System &sys, const NumericVector< Number > &vec, const std::string &vecname)
Definition: meshnorm.C:29
libMesh::EquationSystems::READ_DATA
Definition: equation_systems.h:84
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::DISCRETE_L1
Definition: enum_norm_type.h:52
libMesh::System::name
const std::string & name() const
Definition: system.h:2067
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
libMesh::BasicOStreamProxy::precision
std::streamsize precision() const
Get the associated write precision.
Definition: ostream_proxy.h:189
libMesh::L2
Definition: enum_norm_type.h:36
libMesh::System::calculate_norm
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition: system.C:1356
libMesh::H1
Definition: enum_norm_type.h:37
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
libMesh::System::get_vector
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774
libMesh::EquationSystems::READ_HEADER
Definition: equation_systems.h:83
libMesh::EquationSystems::READ_BASIC_ONLY
Definition: equation_systems.h:88