libMesh
Functions | Variables
meshavg.C File Reference

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

unsigned char dim = 2
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file meshavg.C.

References dim, libMesh::index_range(), libMesh::TriangleWrapper::init(), libMesh::out, libMesh::EquationSystems::READ_BASIC_ONLY, libMesh::EquationSystems::READ_DATA, libMesh::EquationSystems::READ_HEADER, and libMesh::NameBasedIO::write_equation_systems().

33 {
34  LibMeshInit init(argc, argv);
35 
36  Mesh mesh1(init.comm(), dim);
37  EquationSystems es1(mesh1);
38 
39  libMesh::out << "Usage: " << argv[0]
40  << " outputsolution mesh firstsolution [secondsolution ...]" << std::endl;
41 
42  mesh1.read(argv[2]);
43  libMesh::out << "Loaded mesh " << argv[2] << std::endl;
44 
45  mesh1.print_info();
46 
47  es1.read(argv[3],
48  EquationSystems::READ_HEADER |
49  EquationSystems::READ_DATA |
50  EquationSystems::READ_BASIC_ONLY);
51  libMesh::out << "Loaded first solution " << argv[3] << std::endl;
52 
53  es1.print_info();
54 
55  std::vector<std::string> sysnames;
56  std::vector<std::unique_ptr<NumericVector<libMesh::Number>>> summed_solutions;
57 
58  for (unsigned int s = 0; s != es1.n_systems(); ++s)
59  {
60  sysnames.push_back(es1.get_system(s).name());
61  summed_solutions.emplace_back(es1.get_system(s).solution->clone());
62  }
63 
64  for (int i=4; i < argc; ++i)
65  {
66  Mesh mesh2(init.comm(), dim);
67  EquationSystems es2(mesh2);
68  mesh2.read(argv[2]);
69  es2.read(argv[i],
70  EquationSystems::READ_HEADER |
71  EquationSystems::READ_DATA |
72  EquationSystems::READ_BASIC_ONLY);
73  libMesh::out << "Loaded next solution " << argv[i] << std::endl;
74 
75  for (auto s : index_range(sysnames))
76  {
77  libmesh_error_msg_if(!es2.has_system(sysnames[s]),
78  "EquationSystems object does not have " << sysnames[s]);
79 
80  (*summed_solutions[s]) += *es2.get_system(s).solution;
81  }
82  }
83 
84  int n_solutions = argc - 3;
85 
86  for (auto s : index_range(sysnames))
87  {
88  (*summed_solutions[s]) /= n_solutions;
89  es1.get_system(s).solution->swap(*summed_solutions[s]);
90  es1.get_system(s).solution->close();
91  }
92 
93  NameBasedIO(mesh1).write_equation_systems (argv[1], es1);
94 
95  return 0;
96 }
This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of...
Definition: namebased_io.h:44
virtual void write_equation_systems(const std::string &filename, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: namebased_io.C:533
This is the EquationSystems class.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
unsigned char dim
Definition: meshavg.C:30
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
OStreamProxy out
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

Variable Documentation

◆ dim

unsigned char dim = 2

Definition at line 30 of file meshavg.C.

Referenced by main().