libMesh
meshavg.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 // Open the solution files named on standard input, take the average
20 // of their fields' values, and output to a new solution file.
21 
22 #include "libmesh/libmesh.h"
23 
24 #include "libmesh/equation_systems.h"
25 #include "libmesh/mesh.h"
26 #include "libmesh/namebased_io.h"
27 #include "libmesh/numeric_vector.h"
28 
29 using namespace libMesh;
30 
31 unsigned char dim = 2; // This gets overridden by most mesh formats
32 
33 int main(int argc, char ** argv)
34 {
35  LibMeshInit init(argc, argv);
36 
37  Mesh mesh1(init.comm(), dim);
38  EquationSystems es1(mesh1);
39 
40  libMesh::out << "Usage: " << argv[0]
41  << " outputsolution mesh firstsolution [secondsolution ...]" << std::endl;
42 
43  mesh1.read(argv[2]);
44  libMesh::out << "Loaded mesh " << argv[2] << std::endl;
45 
46  mesh1.print_info();
47 
48  es1.read(argv[3],
52  libMesh::out << "Loaded first solution " << argv[3] << std::endl;
53 
54  es1.print_info();
55 
56  std::vector<std::string> sysnames;
57  std::vector<NumericVector<libMesh::Number> *> summed_solutions;
58 
59  for (unsigned int s = 0; s != es1.n_systems(); ++s)
60  {
61  sysnames.push_back(es1.get_system(s).name());
62  summed_solutions.push_back(es1.get_system(s).solution->clone().release());
63  }
64 
65  for (int i=4; i < argc; ++i)
66  {
67  Mesh mesh2(init.comm(), dim);
68  EquationSystems es2(mesh2);
69  mesh2.read(argv[2]);
70  es2.read(argv[i],
74  libMesh::out << "Loaded next solution " << argv[i] << std::endl;
75 
76  for (std::size_t s = 0; s != sysnames.size(); ++s)
77  {
78  if (!es2.has_system(sysnames[s]))
79  libmesh_error_msg("EquationSystems object does not have " << sysnames[s]);
80 
81  (*summed_solutions[s]) += *es2.get_system(s).solution;
82  }
83  }
84 
85  int n_solutions = argc - 3;
86 
87  for (std::size_t s = 0; s != sysnames.size(); ++s)
88  {
89  (*summed_solutions[s]) /= n_solutions;
90  es1.get_system(s).solution->swap(*summed_solutions[s]);
91  es1.get_system(s).solution->close();
92 
93  delete summed_solutions[s];
94  }
95 
96  NameBasedIO(mesh1).write_equation_systems (argv[1], es1);
97 
98  return 0;
99 }
This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of...
Definition: namebased_io.h:44
This is the EquationSystems class.
int main(int argc, char **argv)
Definition: meshavg.C:33
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
The libMesh namespace provides an interface to certain functionality in the library.
unsigned char dim
Definition: meshavg.C:31
virtual void write_equation_systems(const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=libmesh_nullptr) libmesh_override
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: namebased_io.C:490
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
const Parallel::Communicator & comm() const
Definition: libmesh.h:81
OStreamProxy out
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50