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

◆ numbered_filename()

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 117 of file adjoints_ex3.C.

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

Referenced by write_output().

123 {
124  std::ostringstream file_name;
125  file_name << solution_type
126  << ".out."
127  << type
128  << '.'
129  << std::setw(3)
130  << std::setfill('0')
131  << std::right
132  << t_step
133  << '.'
134  << std::setw(2)
135  << std::setfill('0')
136  << std::right
137  << a_step
138  << '.'
139  << extension;
140 
141  if (param.output_bz2)
142  file_name << ".bz2";
143  else if (param.output_gz)
144  file_name << ".gz";
145  return file_name.str();
146 }

◆ write_error()

void write_error ( EquationSystems es,
ErrorVector error,
unsigned int  t_number,
unsigned int  a_number,
FEMParameters param,
std::string  error_type 
) &

◆ write_output()

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

Definition at line 149 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().

154 {
155  MeshBase & mesh = es.get_mesh();
156 
157 #ifdef LIBMESH_HAVE_GMV
158  if (param.output_gmv)
159  {
160  std::ostringstream file_name_gmv;
161  file_name_gmv << solution_type
162  << ".out.gmv."
163  << std::setw(3)
164  << std::setfill('0')
165  << std::right
166  << t_step
167  << '.'
168  << std::setw(2)
169  << std::setfill('0')
170  << std::right
171  << a_step;
172 
174  (file_name_gmv.str(), es);
175  }
176 #endif
177 
178 #ifdef LIBMESH_HAVE_TECPLOT_API
179  if (param.output_tecplot)
180  {
181  std::ostringstream file_name_tecplot;
182  file_name_tecplot << solution_type
183  << ".out."
184  << std::setw(3)
185  << std::setfill('0')
186  << std::right
187  << t_step
188  << '.'
189  << std::setw(2)
190  << std::setfill('0')
191  << std::right
192  << a_step
193  << ".plt";
194 
196  (file_name_tecplot.str(), es);
197  }
198 #endif
199 
200  if (param.output_xda || param.output_xdr)
202  if (param.output_xda)
203  {
204  mesh.write(numbered_filename(t_step, a_step, solution_type, "mesh", "xda", param));
205  es.write(numbered_filename(t_step, a_step, solution_type, "soln", "xda", param),
206  WRITE, EquationSystems::WRITE_DATA |
207  EquationSystems::WRITE_ADDITIONAL_DATA);
208  }
209  if (param.output_xdr)
210  {
211  mesh.write(numbered_filename(t_step, a_step, solution_type, "mesh", "xdr", param));
212  es.write(numbered_filename(t_step, a_step, solution_type, "soln", "xdr", param),
213  WRITE, EquationSystems::WRITE_DATA |
214  EquationSystems::WRITE_ADDITIONAL_DATA);
215  }
216 
217 #ifdef LIBMESH_HAVE_EXODUS_API
218  if (param.output_exodus)
219  {
220  // We write out one file per adaptive step. The files are named in
221  // the following way:
222  // foo.e
223  // foo.e-s002
224  // foo.e-s003
225  // ...
226  // so that, if you open the first one with Paraview, it actually
227  // opens the entire sequence of adapted files.
228  std::ostringstream file_name_exodus;
229 
230  file_name_exodus << solution_type << ".e";
231  if (a_step > 0)
232  file_name_exodus << "-s"
233  << std::setw(3)
234  << std::setfill('0')
235  << std::right
236  << a_step + 1;
237 
238  // We write each adaptive step as a pseudo "time" step, where the
239  // time simply matches the (1-based) adaptive step we are on.
240  ExodusII_IO(mesh).write_timestep(file_name_exodus.str(),
241  es,
242  1,
243  /*time=*/a_step + 1);
244  }
245 #endif
246 }
void write(std::string_view 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.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=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
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:117
This class implements writing meshes in the GMV format.
Definition: gmv_io.h:46
This is the MeshBase class.
Definition: mesh_base.h:75
virtual void write(const std::string &name) const =0
void write_timestep(const std::string &fname, const EquationSystems &es, const int timestep, const Real time, const std::set< std::string > *system_names=nullptr)
Writes out the solution at a specific timestep.
Definition: exodusII_io.C:2017
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...

◆ write_output_footers()

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, and FEMParameters::timesolver_tolerance.

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:39
OStreamProxy out
processor_id_type global_processor_id()
Definition: libmesh_base.h:85
libMesh::Real steadystate_tolerance
Definition: femparameters.h:39

◆ write_output_headers()

void write_output_headers ( FEMParameters param)

Definition at line 248 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.

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

◆ write_output_solvedata()

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 271 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().

277 {
278  MeshBase & mesh = es.get_mesh();
279 
280  // Query parallel_object_only() methods *outside* if(pid==0)
281  const std::size_t n_active_elem = mesh.n_active_elem();
282  const std::size_t 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:75
OStreamProxy out
const MeshBase & get_mesh() const
std::size_t n_active_dofs() const
processor_id_type processor_id() const

Variable Documentation

◆ int

void ErrorVector unsigned unsigned int