GRINS-0.8.0
visualization.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // This class
27 #include "grins/visualization.h"
28 
29 // GRINS
30 #include "grins/grins_enums.h"
31 #include "grins/multiphysics_sys.h"
32 
33 // libMesh
34 #include "libmesh/getpot.h"
35 #include "libmesh/gmv_io.h"
36 #include "libmesh/exodusII_io.h"
37 #include "libmesh/mesh.h"
38 #include "libmesh/nemesis_io.h"
39 #include "libmesh/tecplot_io.h"
40 #include "libmesh/vtk_io.h"
41 
42 // POSIX
43 #include <sys/errno.h>
44 #include <sys/stat.h>
45 #include <sys/types.h>
46 
47 namespace GRINS
48 {
49 
50  Visualization::Visualization( const GetPot& input,
51  const libMesh::Parallel::Communicator &comm )
52  : _vis_output_file_prefix( input("vis-options/vis_output_file_prefix", "unknown" ) )
53  {
54  unsigned int num_formats = input.vector_variable_size("vis-options/output_format");
55 
56  // If no format specified, default to ExodusII only
57  if( num_formats == 0 )
58  {
59  // Were we specifically asked to use a ParallelMesh or SerialMesh?
60  std::string mesh_class = input("mesh-options/mesh_class", "default");
61 
62  if (mesh_class == "parallel")
63  _output_format.push_back("Nemesis");
64  else if (mesh_class == "serial")
65  _output_format.push_back("ExodusII");
66  else if (mesh_class == "default")
67  {
68  // Is our default Mesh distributable?
69  libMesh::Mesh testdefault(comm);
70  testdefault.delete_remote_elements();
71  if (testdefault.is_serial())
72  _output_format.push_back("ExodusII");
73  else
74  _output_format.push_back("Nemesis");
75  }
76  else
77  {
78  std::cerr << " Visualization::Visualization:"
79  << " mesh-options/mesh_class had invalid value " << mesh_class
80  << std::endl;
81  libmesh_error();
82  }
83  }
84 
85  for( unsigned int i = 0; i < num_formats; i++ )
86  {
87  _output_format.push_back( input("vis-options/output_format", "DIE", i ) );
88  }
89 
90  return;
91  }
92 
94  {
95  return;
96  }
97 
98  void Visualization::output( SharedPtr<libMesh::EquationSystems> equation_system )
99  {
100  this->dump_visualization( equation_system, _vis_output_file_prefix, 0.0 );
101 
102  return;
103  }
104 
106  ( SharedPtr<libMesh::EquationSystems> equation_system,
107  const unsigned int time_step,
108  const libMesh::Real time )
109  {
110  std::stringstream suffix;
111 
112  suffix << time_step;
113 
114  std::string filename = this->_vis_output_file_prefix;
115  filename+="."+suffix.str();
116 
117  this->dump_visualization( equation_system, filename, time );
118 
119  return;
120  }
121 
122  void Visualization::output_residual( SharedPtr<libMesh::EquationSystems> equation_system,
123  MultiphysicsSystem* system )
124  {
125  this->output_residual( equation_system, system, 0, 0.0 );
126  return;
127  }
128 
130  (SharedPtr<libMesh::EquationSystems> equation_system,
131  MultiphysicsSystem* system,
132  const libMesh::ParameterVector & params)
133  {
134  this->output_residual_sensitivities
135  ( equation_system, system, params, 0, 0.0 );
136  }
137 
138  void Visualization::output_adjoint( SharedPtr<libMesh::EquationSystems> equation_system,
139  MultiphysicsSystem* system )
140  {
141  this->output_adjoint( equation_system, system, 0, 0.0 );
142  }
143 
145  (SharedPtr<libMesh::EquationSystems> equation_system,
146  MultiphysicsSystem* system,
147  const libMesh::ParameterVector & params)
148  {
149  this->output_solution_sensitivities
150  ( equation_system, system, params, 0, 0.0 );
151  }
152 
154  ( SharedPtr<libMesh::EquationSystems> equation_system,
155  const std::string& filename_prefix,
156  const libMesh::Real time )
157  {
158  libMesh::MeshBase& mesh = equation_system->get_mesh();
159 
160  if( this->_vis_output_file_prefix == "unknown" )
161  {
162  // TODO: Need consisent way to print warning messages.
163  std::cout << " WARNING in Visualization::dump_visualization :"
164  << " using 'unknown' as file prefix since it was not set "
165  << std::endl;
166  }
167 
168  // If we're asked to put files in a subdirectory, let's make sure
169  // it exists
170  if (!mesh.comm().rank())
171  for (std::size_t pos = this->_vis_output_file_prefix.find('/');
172  pos != std::string::npos;
173  pos = this->_vis_output_file_prefix.find('/',++pos))
174  if (mkdir(this->_vis_output_file_prefix.substr(0,pos).c_str(),
175  0777) != 0 && errno != EEXIST)
176  libmesh_file_error(this->_vis_output_file_prefix.substr(0,pos));
177 
178  for( std::vector<std::string>::const_iterator format = _output_format.begin();
179  format != _output_format.end();
180  format ++ )
181  {
182  // The following is a modifed copy from the FIN-S code.
183  if ((*format) == "tecplot" ||
184  (*format) == "dat")
185  {
186  std::string filename = filename_prefix+".dat";
187  libMesh::TecplotIO(mesh,false).write_equation_systems( filename,
188  *equation_system );
189  }
190  else if ((*format) == "tecplot_binary" ||
191  (*format) == "plt")
192  {
193  std::string filename = filename_prefix+".plt";
194  libMesh::TecplotIO(mesh,true).write_equation_systems( filename,
195  *equation_system );
196  }
197  else if ((*format) == "gmv")
198  {
199  std::string filename = filename_prefix+".gmv";
200  libMesh::GMVIO(mesh).write_equation_systems( filename,
201  *equation_system );
202  }
203  else if ((*format) == "pvtu")
204  {
205  std::string filename = filename_prefix+".pvtu";
206  libMesh::VTKIO(mesh).write_equation_systems( filename,
207  *equation_system );
208  }
209  else if ((*format) == "ExodusII")
210  {
211  std::string filename = filename_prefix+".exo";
212 
213  // The "1" is hardcoded for the number of time steps because the ExodusII manual states that
214  // it should be the number of timesteps within the file. Here, we are explicitly only doing
215  // one timestep per file.
216  libMesh::ExodusII_IO(mesh).write_timestep
217  ( filename, *equation_system, 1, time );
218  }
219  else if ((*format) == "Nemesis")
220  {
221  std::string filename = filename_prefix+".nem";
222 
223  // The "1" is hardcoded for the number of time steps because the ExodusII manual states that
224  // it should be the number of timesteps within the file. Here, we are explicitly only doing
225  // one timestep per file.
226  libMesh::Nemesis_IO(mesh).write_timestep
227  ( filename, *equation_system, 1, time );
228  }
229  else if ((*format).find("xda") != std::string::npos ||
230  (*format).find("xdr") != std::string::npos)
231  {
232  std::string filename = filename_prefix+"."+(*format);
233  const bool binary = ((*format).find("xdr") != std::string::npos);
234  equation_system->write( filename,
235  binary ? GRINSEnums::ENCODE : GRINSEnums::WRITE,
236  libMesh::EquationSystems::WRITE_DATA |
237  libMesh::EquationSystems::WRITE_ADDITIONAL_DATA );
238  }
239  else if ((*format) == "mesh_only" )
240  {
241  std::string filename = filename_prefix+"_mesh.xda";
242  equation_system->get_mesh().write( filename );
243  }
244  else
245  {
246  // TODO: Do we want to use this to error throughout the code?
247  // TODO: (at least need to pass/print some message/string) - sahni
248  libmesh_error();
249  }
250  } // End loop over formats
251 
252  return;
253  }
254 
255 } // namespace GRINS
void output_residual(SharedPtr< libMesh::EquationSystems > equation_system, GRINS::MultiphysicsSystem *system)
void dump_visualization(SharedPtr< libMesh::EquationSystems > equation_system, const std::string &filename_prefix, const libMesh::Real time)
void output_adjoint(SharedPtr< libMesh::EquationSystems > equation_system, GRINS::MultiphysicsSystem *system)
void output_residual_sensitivities(SharedPtr< libMesh::EquationSystems > equation_system, GRINS::MultiphysicsSystem *system, const libMesh::ParameterVector &params)
std::vector< std::string > _output_format
std::string _vis_output_file_prefix
virtual ~Visualization()
Definition: visualization.C:93
GRINS namespace.
Visualization(const GetPot &input, const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Definition: visualization.C:50
Interface with libMesh for solving Multiphysics problems.
void output(SharedPtr< libMesh::EquationSystems > equation_system)
Definition: visualization.C:98
void output_solution_sensitivities(SharedPtr< libMesh::EquationSystems > equation_system, GRINS::MultiphysicsSystem *system, const libMesh::ParameterVector &params)

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1