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

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file meshavg.C.

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

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],
49  EquationSystems::READ_HEADER |
50  EquationSystems::READ_DATA |
51  EquationSystems::READ_BASIC_ONLY);
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],
71  EquationSystems::READ_HEADER |
72  EquationSystems::READ_DATA |
73  EquationSystems::READ_BASIC_ONLY);
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
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.
OStreamProxy out
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

Variable Documentation

unsigned char dim = 2

Definition at line 31 of file meshavg.C.

Referenced by main().