libMesh
Functions | Variables
adjoints_ex3.C File Reference

Go to the source code of this file.

Functions

std::string numbered_filename (unsigned int t_step, unsigned int a_step, std::string solution_type, std::string type, std::string extension, FEMParameters &param)
 
void write_output (EquationSystems &es, unsigned int t_step, unsigned int a_step, std::string solution_type, FEMParameters &param)
 
void write_output_headers (FEMParameters &param)
 
void write_output_solvedata (EquationSystems &es, unsigned int a_step, unsigned int newton_steps, unsigned int krylov_steps, unsigned int tv_sec, unsigned int tv_usec)
 
void write_output_footers (FEMParameters &param)
 
void write_error (EquationSystems &es, ErrorVector &error, unsigned int t_number, unsigned int a_number, FEMParameters &param, std::string error_type) void write_error(EquationSystems &
 

Variables

void ErrorVector unsigned int
 

Function Documentation

std::string numbered_filename ( unsigned int  t_step,
unsigned int  a_step,
std::string  solution_type,
std::string  type,
std::string  extension,
FEMParameters param 
)

Definition at line 119 of file adjoints_ex3.C.

References FEMParameters::output_bz2, and FEMParameters::output_gz.

Referenced by write_output().

125 {
126  std::ostringstream file_name;
127  file_name << solution_type
128  << ".out."
129  << type
130  << '.'
131  << std::setw(3)
132  << std::setfill('0')
133  << std::right
134  << t_step
135  << '.'
136  << std::setw(2)
137  << std::setfill('0')
138  << std::right
139  << a_step
140  << '.'
141  << extension;
142 
143  if (param.output_bz2)
144  file_name << ".bz2";
145  else if (param.output_gz)
146  file_name << ".gz";
147  return file_name.str();
148 }
void write_error ( EquationSystems es,
ErrorVector error,
unsigned int  t_number,
unsigned int  a_number,
FEMParameters param,
std::string  error_type 
)

Referenced by write_output_footers().

void write_output ( EquationSystems es,
unsigned int  t_step,
unsigned int  a_step,
std::string  solution_type,
FEMParameters param 
)

Definition at line 151 of file adjoints_ex3.C.

References libMesh::EquationSystems::get_mesh(), mesh, numbered_filename(), FEMParameters::output_exodus, FEMParameters::output_gmv, FEMParameters::output_tecplot, FEMParameters::output_xda, FEMParameters::output_xdr, libMesh::MeshBase::renumber_nodes_and_elements(), libMesh::WRITE, libMesh::EquationSystems::write(), libMesh::MeshBase::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, libMesh::EquationSystems::WRITE_DATA, libMesh::MeshOutput< MT >::write_equation_systems(), and libMesh::ExodusII_IO::write_timestep().

156 {
157  MeshBase & mesh = es.get_mesh();
158 
159 #ifdef LIBMESH_HAVE_GMV
160  if (param.output_gmv)
161  {
162  std::ostringstream file_name_gmv;
163  file_name_gmv << solution_type
164  << ".out.gmv."
165  << std::setw(3)
166  << std::setfill('0')
167  << std::right
168  << t_step
169  << '.'
170  << std::setw(2)
171  << std::setfill('0')
172  << std::right
173  << a_step;
174 
176  (file_name_gmv.str(), es);
177  }
178 #endif
179 
180 #ifdef LIBMESH_HAVE_TECPLOT_API
181  if (param.output_tecplot)
182  {
183  std::ostringstream file_name_tecplot;
184  file_name_tecplot << solution_type
185  << ".out."
186  << std::setw(3)
187  << std::setfill('0')
188  << std::right
189  << t_step
190  << '.'
191  << std::setw(2)
192  << std::setfill('0')
193  << std::right
194  << a_step
195  << ".plt";
196 
198  (file_name_tecplot.str(), es);
199  }
200 #endif
201 
202  if (param.output_xda || param.output_xdr)
204  if (param.output_xda)
205  {
206  mesh.write(numbered_filename(t_step, a_step, solution_type, "mesh", "xda", param));
207  es.write(numbered_filename(t_step, a_step, solution_type, "soln", "xda", param),
208  WRITE, EquationSystems::WRITE_DATA |
209  EquationSystems::WRITE_ADDITIONAL_DATA);
210  }
211  if (param.output_xdr)
212  {
213  mesh.write(numbered_filename(t_step, a_step, solution_type, "mesh", "xdr", param));
214  es.write(numbered_filename(t_step, a_step, solution_type, "soln", "xdr", param),
215  WRITE, EquationSystems::WRITE_DATA |
216  EquationSystems::WRITE_ADDITIONAL_DATA);
217  }
218 
219 #ifdef LIBMESH_HAVE_EXODUS_API
220  if (param.output_exodus)
221  {
222  // We write out one file per adaptive step. The files are named in
223  // the following way:
224  // foo.e
225  // foo.e-s002
226  // foo.e-s003
227  // ...
228  // so that, if you open the first one with Paraview, it actually
229  // opens the entire sequence of adapted files.
230  std::ostringstream file_name_exodus;
231 
232  file_name_exodus << solution_type << ".e";
233  if (a_step > 0)
234  file_name_exodus << "-s"
235  << std::setw(3)
236  << std::setfill('0')
237  << std::right
238  << a_step + 1;
239 
240  // We write each adaptive step as a pseudo "time" step, where the
241  // time simply matches the (1-based) adaptive step we are on.
242  ExodusII_IO(mesh).write_timestep(file_name_exodus.str(),
243  es,
244  1,
245  /*time=*/a_step + 1);
246  }
247 #endif
248 }
void write(const std::string &name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
void write_timestep(const std::string &fname, const EquationSystems &es, const int timestep, const Real time)
Writes out the solution at a specific timestep.
Definition: exodusII_io.C:773
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
MeshBase & mesh
std::string numbered_filename(unsigned int t_step, unsigned int a_step, std::string solution_type, std::string type, std::string extension, FEMParameters &param)
Definition: adjoints_ex3.C:119
This class implements writing meshes in the GMV format.
Definition: gmv_io.h:46
This is the MeshBase class.
Definition: mesh_base.h:68
virtual void write(const std::string &name)=0
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
const MeshBase & get_mesh() const
This class implements writing meshes in the Tecplot format.
Definition: tecplot_io.h:43
virtual void renumber_nodes_and_elements()=0
After partitioning a mesh it is useful to renumber the nodes and elements so that they lie in contigu...
void write_output_footers ( FEMParameters param)

Definition at line 309 of file adjoints_ex3.C.

References libMesh::global_processor_id(), libMesh::out, FEMParameters::run_simulation, FEMParameters::steadystate_tolerance, FEMParameters::timesolver_tolerance, and write_error().

310 {
311  // Write footers on output .m files
312  if (libMesh::global_processor_id() == 0)
313  {
314  std::ofstream clocktime ("out_clocktime.m",
315  std::ios_base::app | std::ios_base::out);
316  clocktime << "];" << std::endl;
317 
318  if (param.run_simulation)
319  {
320  std::ofstream activemesh ("out_activemesh.m",
321  std::ios_base::app | std::ios_base::out);
322  activemesh << "];" << std::endl;
323 
324  std::ofstream solvesteps ("out_solvesteps.m",
325  std::ios_base::app | std::ios_base::out);
326  solvesteps << "];" << std::endl;
327 
328  if (param.timesolver_tolerance)
329  {
330  std::ofstream times ("out_time.m",
331  std::ios_base::app | std::ios_base::out);
332  times << "];" << std::endl;
333  std::ofstream timesteps ("out_timesteps.m",
334  std::ios_base::app | std::ios_base::out);
335  timesteps << "];" << std::endl;
336  }
337  if (param.steadystate_tolerance)
338  {
339  std::ofstream changerate ("out_changerate.m",
340  std::ios_base::app | std::ios_base::out);
341  changerate << "];" << std::endl;
342  }
343  }
344 
345  // We're done, so write out a file (for e.g. Make to check)
346  std::ofstream complete ("complete");
347  complete << "complete" << std::endl;
348  }
349 }
libMesh::Real timesolver_tolerance
Definition: femparameters.h:38
OStreamProxy out
processor_id_type global_processor_id()
Definition: libmesh_base.h:114
libMesh::Real steadystate_tolerance
Definition: femparameters.h:38
void write_output_headers ( FEMParameters param)

Definition at line 250 of file adjoints_ex3.C.

References libMesh::global_processor_id(), FEMParameters::initial_timestep, FEMParameters::run_simulation, start_output(), FEMParameters::steadystate_tolerance, and FEMParameters::timesolver_tolerance.

251 {
252  // Only one processor needs to take care of headers.
253  if (libMesh::global_processor_id() != 0)
254  return;
255 
256  start_output(param.initial_timestep, "out_clocktime.m", "vector_clocktime");
257 
258  if (param.run_simulation)
259  {
260  start_output(param.initial_timestep, "out_activemesh.m", "table_activemesh");
261  start_output(param.initial_timestep, "out_solvesteps.m", "table_solvesteps");
262 
263  if (param.timesolver_tolerance)
264  {
265  start_output(param.initial_timestep, "out_time.m", "vector_time");
266  start_output(param.initial_timestep, "out_timesteps.m", "vector_timesteps");
267  }
268  if (param.steadystate_tolerance)
269  start_output(param.initial_timestep, "out_changerate.m", "vector_changerate");
270  }
271 }
void start_output(unsigned int timesteps, std::string filename, std::string varname)
Definition: output.C:11
unsigned int initial_timestep
Definition: femparameters.h:34
libMesh::Real timesolver_tolerance
Definition: femparameters.h:38
processor_id_type global_processor_id()
Definition: libmesh_base.h:114
libMesh::Real steadystate_tolerance
Definition: femparameters.h:38
void write_output_solvedata ( EquationSystems es,
unsigned int  a_step,
unsigned int  newton_steps,
unsigned int  krylov_steps,
unsigned int  tv_sec,
unsigned int  tv_usec 
)

Definition at line 273 of file adjoints_ex3.C.

References libMesh::EquationSystems::get_mesh(), mesh, libMesh::EquationSystems::n_active_dofs(), libMesh::MeshBase::n_active_elem(), libMesh::out, and libMesh::ParallelObject::processor_id().

279 {
280  MeshBase & mesh = es.get_mesh();
281  unsigned int n_active_elem = mesh.n_active_elem();
282  unsigned int n_active_dofs = es.n_active_dofs();
283 
284  if (mesh.processor_id() == 0)
285  {
286  // Write out the number of elements/dofs used
287  std::ofstream activemesh ("out_activemesh.m",
288  std::ios_base::app | std::ios_base::out);
289  activemesh.precision(17);
290  activemesh << (a_step + 1) << ' '
291  << n_active_elem << ' '
292  << n_active_dofs << std::endl;
293 
294  // Write out the number of solver steps used
295  std::ofstream solvesteps ("out_solvesteps.m",
296  std::ios_base::app | std::ios_base::out);
297  solvesteps.precision(17);
298  solvesteps << newton_steps << ' '
299  << krylov_steps << std::endl;
300 
301  // Write out the clock time
302  std::ofstream clocktime ("out_clocktime.m",
303  std::ios_base::app | std::ios_base::out);
304  clocktime.precision(17);
305  clocktime << tv_sec << '.' << tv_usec << std::endl;
306  }
307 }
virtual dof_id_type n_active_elem() const =0
MeshBase & mesh
This is the MeshBase class.
Definition: mesh_base.h:68
OStreamProxy out
const MeshBase & get_mesh() const
std::size_t n_active_dofs() const
processor_id_type processor_id() const

Variable Documentation

void ErrorVector unsigned unsigned int