libMesh
vtk_io.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // C++ includes
20 #include <fstream>
21 
22 // Local includes
23 #include "libmesh/libmesh_config.h"
24 #include "libmesh/vtk_io.h"
25 #include "libmesh/mesh_base.h"
26 #include "libmesh/equation_systems.h"
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/system.h"
29 #include "libmesh/node.h"
30 #include "libmesh/elem.h"
31 #include "libmesh/enum_io_package.h"
32 
33 #ifdef LIBMESH_HAVE_VTK
34 
35 // I get a lot of "warning: extra ';' inside a class [-Wextra-semi]" from clang
36 // on VTK header files.
37 #include "libmesh/ignore_warnings.h"
38 
39 #include "vtkXMLUnstructuredGridReader.h"
40 #include "vtkXMLUnstructuredGridWriter.h"
41 #include "vtkXMLPUnstructuredGridWriter.h"
42 #include "vtkUnstructuredGrid.h"
43 #include "vtkIntArray.h"
44 #include "vtkCellArray.h"
45 #include "vtkCellData.h"
46 #include "vtkConfigure.h"
47 #include "vtkDoubleArray.h"
48 #include "vtkGenericCell.h"
49 #include "vtkPointData.h"
50 #include "vtkPoints.h"
51 #include "vtkSmartPointer.h"
52 
53 #ifdef LIBMESH_HAVE_MPI
54 #include "vtkMPI.h"
55 #include "vtkMPICommunicator.h"
56 #include "vtkMPIController.h"
57 #endif
58 
59 #include "libmesh/restore_warnings.h"
60 
61 // A convenient macro for comparing VTK versions. Returns 1 if the
62 // current VTK version is < major.minor.subminor and zero otherwise.
63 //
64 // It relies on the VTK version numbers detected during configure. Note that if
65 // LIBMESH_HAVE_VTK is not defined, none of the LIBMESH_DETECTED_VTK_VERSION_* variables will
66 // be defined either.
67 #define VTK_VERSION_LESS_THAN(major,minor,subminor) \
68  ((LIBMESH_DETECTED_VTK_VERSION_MAJOR < (major) || \
69  (LIBMESH_DETECTED_VTK_VERSION_MAJOR == (major) && (LIBMESH_DETECTED_VTK_VERSION_MINOR < (minor) || \
70  (LIBMESH_DETECTED_VTK_VERSION_MINOR == (minor) && \
71  LIBMESH_DETECTED_VTK_VERSION_SUBMINOR < (subminor))))) ? 1 : 0)
72 
73 #endif // LIBMESH_HAVE_VTK
74 
75 
76 
77 namespace libMesh
78 {
79 
80 // Constructor for reading
82  MeshInput<MeshBase> (mesh, /*is_parallel_format=*/true),
83  MeshOutput<MeshBase>(mesh, /*is_parallel_format=*/true)
84 #ifdef LIBMESH_HAVE_VTK
85  ,_compress(false)
86 #endif
87 {
88 }
89 
90 
91 
92 // Constructor for writing
93 VTKIO::VTKIO (const MeshBase & mesh) :
94  MeshOutput<MeshBase>(mesh, /*is_parallel_format=*/true)
95 #ifdef LIBMESH_HAVE_VTK
96  ,_compress(false)
97 #endif
98 {
99 }
100 
101 
102 
103 // Output the mesh without solutions to a .pvtu file
104 void VTKIO::write (const std::string & name)
105 {
106  std::vector<Number> soln;
107  std::vector<std::string> names;
108  this->write_nodal_data(name, soln, names);
109 }
110 
111 
112 
113 // The rest of the file is wrapped in ifdef LIBMESH_HAVE_VTK except for
114 // a couple of "stub" functions at the bottom.
115 #ifdef LIBMESH_HAVE_VTK
116 
117 // Initialize the static _element_maps struct.
118 VTKIO::ElementMaps VTKIO::_element_maps = VTKIO::build_element_maps();
119 
120 // Static function which constructs the ElementMaps object.
122 {
123  // Object to be filled up
124  ElementMaps em;
125 
126  em.associate(EDGE2, VTK_LINE);
127  em.associate(EDGE3, VTK_QUADRATIC_EDGE);
128  em.associate(TRI3, VTK_TRIANGLE);
129  em.associate(TRI6, VTK_QUADRATIC_TRIANGLE);
130  em.associate(QUAD4, VTK_QUAD);
131  em.associate(QUAD8, VTK_QUADRATIC_QUAD);
132  em.associate(TET4, VTK_TETRA);
133  em.associate(TET10, VTK_QUADRATIC_TETRA);
134  em.associate(HEX8, VTK_HEXAHEDRON);
135  em.associate(HEX20, VTK_QUADRATIC_HEXAHEDRON);
136  em.associate(HEX27, VTK_TRIQUADRATIC_HEXAHEDRON);
137  em.associate(PRISM6, VTK_WEDGE);
138  em.associate(PRISM15, VTK_QUADRATIC_WEDGE);
139  em.associate(PRISM18, VTK_BIQUADRATIC_QUADRATIC_WEDGE);
140  em.associate(PYRAMID5, VTK_PYRAMID);
141 
142  // VTK_BIQUADRATIC_QUAD has been around since VTK 5.0
143 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION > 0)
144  em.associate(QUAD9, VTK_BIQUADRATIC_QUAD);
145 #endif
146 
147  // TRI3SUBDIVISION is for writing only
148  em.writing_map[TRI3SUBDIVISION] = VTK_TRIANGLE;
149 
150  return em;
151 }
152 
153 
154 
155 void VTKIO::read (const std::string & name)
156 {
157  // This is a serial-only process for now;
158  // the Mesh should be read on processor 0 and
159  // broadcast later
160  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0);
161 
162  // Keep track of what kinds of elements this file contains
163  elems_of_dimension.clear();
164  elems_of_dimension.resize(4, false);
165 
166  // Use a typedef, because these names are just crazy
167  typedef vtkSmartPointer<vtkXMLUnstructuredGridReader> MyReader;
168  MyReader reader = MyReader::New();
169 
170  // Pass the filename along to the reader
171  reader->SetFileName(name.c_str());
172 
173  // Force reading
174  reader->Update();
175 
176  // read in the grid
177  _vtk_grid = reader->GetOutput();
178 
179  // Get a reference to the mesh
181 
182  // Clear out any pre-existing data from the Mesh
183  mesh.clear();
184 
185  // Get the number of points from the _vtk_grid object
186  const unsigned int vtk_num_points = static_cast<unsigned int>(_vtk_grid->GetNumberOfPoints());
187 
188  // always numbered nicely so we can loop like this
189  for (unsigned int i=0; i<vtk_num_points; ++i)
190  {
191  // add to the id map
192  // and add the actual point
193  double pnt[3];
194  _vtk_grid->GetPoint(static_cast<vtkIdType>(i), pnt);
195  Point xyz(pnt[0], pnt[1], pnt[2]);
196  mesh.add_point(xyz, i);
197  }
198 
199  // Get the number of cells from the _vtk_grid object
200  const unsigned int vtk_num_cells = static_cast<unsigned int>(_vtk_grid->GetNumberOfCells());
201 
202  vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
203  for (unsigned int i=0; i<vtk_num_cells; ++i)
204  {
205  _vtk_grid->GetCell(i, cell);
206 
207  // Get the libMesh element type corresponding to this VTK element type.
208  ElemType libmesh_elem_type = _element_maps.find(cell->GetCellType());
209  Elem * elem = Elem::build(libmesh_elem_type).release();
210 
211  // get the straightforward numbering from the VTK cells
212  for (auto j : elem->node_index_range())
213  elem->set_node(j) =
214  mesh.node_ptr(cast_int<dof_id_type>(cell->GetPointId(j)));
215 
216  // then get the connectivity
217  std::vector<dof_id_type> conn;
218  elem->connectivity(0, VTK, conn);
219 
220  // then reshuffle the nodes according to the connectivity, this
221  // two-time-assign would evade the definition of the vtk_mapping
222  for (unsigned int j=0,
223  n_conn = cast_int<unsigned int>(conn.size());
224  j != n_conn; ++j)
225  elem->set_node(j) = mesh.node_ptr(conn[j]);
226 
227  elem->set_id(i);
228 
229  elems_of_dimension[elem->dim()] = true;
230 
231  mesh.add_elem(elem);
232  } // end loop over VTK cells
233 
234  // Set the mesh dimension to the largest encountered for an element
235  for (unsigned char i=0; i!=4; ++i)
236  if (elems_of_dimension[i])
238 
239 #if LIBMESH_DIM < 3
240  if (mesh.mesh_dimension() > LIBMESH_DIM)
241  libmesh_error_msg("Cannot open dimension " \
242  << mesh.mesh_dimension() \
243  << " mesh file when configured without " \
244  << mesh.mesh_dimension() \
245  << "D support.");
246 #endif // LIBMESH_DIM < 3
247 }
248 
249 
250 
251 void VTKIO::write_nodal_data (const std::string & fname,
252  const std::vector<Number> & soln,
253  const std::vector<std::string> & names)
254 {
255  // Warn that the .pvtu file extension should be used. Paraview
256  // recognizes this, and it works in both serial and parallel. Only
257  // warn about this once.
258  if (fname.substr(fname.rfind("."), fname.size()) != ".pvtu")
259  libmesh_do_once(libMesh::err << "The .pvtu extension should be used when writing VTK files in libMesh.");
260 
261  // If there are variable names being written, the solution vector
262  // should not be empty, it should have been broadcast to all
263  // processors by the MeshOutput base class, since VTK is a parallel
264  // format. Verify this before going further.
265  if (!names.empty() && soln.empty())
266  libmesh_error_msg("Empty soln vector in VTKIO::write_nodal_data().");
267 
268  // Get a reference to the mesh
270 
271  // we only use Unstructured grids
272  _vtk_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
273  vtkSmartPointer<vtkXMLPUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLPUnstructuredGridWriter>::New();
274 #ifdef LIBMESH_HAVE_MPI
275  // Set VTK to the same communicator as libMesh
276  vtkSmartPointer<vtkMPICommunicator> vtk_comm = vtkSmartPointer<vtkMPICommunicator>::New();
277  MPI_Comm mpi_comm = mesh.comm().get();
278  vtkMPICommunicatorOpaqueComm vtk_opaque_comm(&mpi_comm);
279  vtk_comm->InitializeExternal(&vtk_opaque_comm);
280 
281  vtkSmartPointer<vtkMPIController> vtk_mpi_ctrl = vtkSmartPointer<vtkMPIController>::New();
282  vtk_mpi_ctrl->SetCommunicator(vtk_comm);
283 
284  writer->SetController(vtk_mpi_ctrl);
285 #endif
286 
287  // add nodes to the grid and update _local_node_map
288  _local_node_map.clear();
289  this->nodes_to_vtk();
290 
291  // add cells to the grid
292  this->cells_to_vtk();
293 
294  // add nodal solutions to the grid, if solutions are given
295  if (names.size() > 0)
296  {
297  std::size_t num_vars = names.size();
298  std::vector<Number> local_values;
299 
300 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
301  std::vector<Real> local_real_values;
302 #endif
303 
304  for (std::size_t variable=0; variable<num_vars; ++variable)
305  {
306  get_local_node_values(local_values, variable, soln, names);
307 
308 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
309  // write real part
310  local_real_values.resize(local_values.size());
311  std::transform(local_values.begin(), local_values.end(),
312  local_real_values.begin(),
313  [](Number x) { return x.real(); });
314  node_values_to_vtk(names[variable] + "_real", local_real_values);
315 
316  // write imaginary part
317  local_real_values.resize(local_values.size());
318  std::transform(local_values.begin(), local_values.end(),
319  local_real_values.begin(),
320  [](Number x) { return x.imag(); });
321  node_values_to_vtk(names[variable] + "_imag", local_real_values);
322 #else
323  node_values_to_vtk(names[variable], local_values);
324 #endif
325  }
326  }
327 
328  // Tell the writer how many partitions exist and on which processor
329  // we are currently
330  writer->SetNumberOfPieces(mesh.n_processors());
331  writer->SetStartPiece(mesh.processor_id());
332  writer->SetEndPiece(mesh.processor_id());
333 
334  // partitions overlap by one node
335  // FIXME: According to this document
336  // http://paraview.org/Wiki/images/5/51/SC07_tut107_ParaView_Handouts.pdf
337  // the ghosts are cells rather than nodes.
338  writer->SetGhostLevel(1);
339 
340  // VTK 6 replaces SetInput() with SetInputData(). See
341  // http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput
342  // for the full explanation.
343 #if VTK_VERSION_LESS_THAN(6,0,0)
344  writer->SetInput(_vtk_grid);
345 #else
346  writer->SetInputData(_vtk_grid);
347 #endif
348 
349  writer->SetFileName(fname.c_str());
350  writer->SetDataModeToAscii();
351 
352  // compress the output, if desired (switches also to binary)
353  if (this->_compress)
354  {
355 #if !VTK_VERSION_LESS_THAN(5,6,0)
356  writer->SetCompressorTypeToZLib();
357 #else
358  libmesh_do_once(libMesh::err << "Compression not implemented with old VTK libs!" << std::endl;);
359 #endif
360  }
361 
362  writer->Write();
363 
364 }
365 
366 
367 
368 vtkUnstructuredGrid * VTKIO::get_vtk_grid()
369 {
370  return _vtk_grid;
371 }
372 
373 
374 
376 {
377  this->_compress = b;
378 }
379 
380 
381 
383 {
385 
386  // containers for points and coordinates of points
387  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
388  vtkSmartPointer<vtkDoubleArray> pcoords = vtkSmartPointer<vtkDoubleArray>::New();
389  // if this grid is to be used in VTK then the dimension of the points should be 3
390  pcoords->SetNumberOfComponents(LIBMESH_DIM);
391  pcoords->Allocate(3*mesh.n_local_nodes());
392  points->SetNumberOfPoints(mesh.n_local_nodes()); // it seems that it needs this to prevent a segfault
393 
394  unsigned int local_node_counter = 0;
395 
396  for (const auto & node_ptr : mesh.local_node_ptr_range())
397  {
398  const Node & node = *node_ptr;
399 
400  double pnt[3] = {0, 0, 0};
401  for (unsigned int i=0; i<LIBMESH_DIM; ++i)
402  pnt[i] = node(i);
403 
404  // Fill mapping between global and local node numbers
405  _local_node_map[node.id()] = local_node_counter;
406 
407  // add point
408 #if VTK_VERSION_LESS_THAN(7,1,0)
409  pcoords->InsertNextTupleValue(pnt);
410 #else
411  pcoords->InsertNextTuple(pnt);
412 #endif
413  ++local_node_counter;
414  }
415 
416  // add coordinates to points
417  points->SetData(pcoords);
418 
419  // add points to grid
420  _vtk_grid->SetPoints(points);
421 }
422 
423 
424 
426 {
428 
429  vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
430  vtkSmartPointer<vtkIdList> pts = vtkSmartPointer<vtkIdList>::New();
431 
432  std::vector<int> types(mesh.n_active_local_elem());
433 
434  vtkSmartPointer<vtkIntArray> elem_id = vtkSmartPointer<vtkIntArray>::New();
435  elem_id->SetName("libmesh_elem_id");
436  elem_id->SetNumberOfComponents(1);
437 
438  vtkSmartPointer<vtkIntArray> subdomain_id = vtkSmartPointer<vtkIntArray>::New();
439  subdomain_id->SetName("subdomain_id");
440  subdomain_id->SetNumberOfComponents(1);
441 
442  vtkSmartPointer<vtkIntArray> elem_proc_id = vtkSmartPointer<vtkIntArray>::New();
443  elem_proc_id->SetName("processor_id");
444  elem_proc_id->SetNumberOfComponents(1);
445 
446  unsigned active_element_counter = 0;
447  for (const auto & elem : mesh.active_local_element_ptr_range())
448  {
449  pts->SetNumberOfIds(elem->n_nodes());
450 
451  // get the connectivity for this element
452  std::vector<dof_id_type> conn;
453  elem->connectivity(0, VTK, conn);
454 
455  for (unsigned int i=0,
456  n_conn = cast_int<unsigned int>(conn.size());
457  i != n_conn; ++i)
458  {
459  // If the node ID is not found in the _local_node_map, we'll
460  // add it to the _vtk_grid. NOTE[JWP]: none of the examples
461  // I have actually enters this section of code...
462  if (_local_node_map.find(conn[i]) == _local_node_map.end())
463  {
464  dof_id_type global_node_id = elem->node_id(i);
465 
466  const Point & the_node = mesh.point(global_node_id);
467 
468  // InsertNextPoint accepts either a double or float array of length 3.
469  double pt[3] = {0., 0., 0.};
470  for (unsigned int d=0; d<LIBMESH_DIM; ++d)
471  pt[d] = the_node(d);
472 
473  // Insert the point into the _vtk_grid
474  vtkIdType local = _vtk_grid->GetPoints()->InsertNextPoint(pt);
475 
476  // Update the _local_node_map with the ID returned by VTK
477  _local_node_map[global_node_id] =
478  cast_int<dof_id_type>(local);
479  }
480 
481  // Otherwise, the node ID was found in the _local_node_map, so
482  // insert it into the vtkIdList.
483  pts->InsertId(i, _local_node_map[conn[i]]);
484  }
485 
486  vtkIdType vtkcellid = cells->InsertNextCell(pts);
487  types[active_element_counter] = cast_int<int>(_element_maps.find(elem->type()));
488 
489  elem_id->InsertTuple1(vtkcellid, elem->id());
490  subdomain_id->InsertTuple1(vtkcellid, elem->subdomain_id());
491  elem_proc_id->InsertTuple1(vtkcellid, elem->processor_id());
492  ++active_element_counter;
493  } // end loop over active elements
494 
495  _vtk_grid->SetCells(types.data(), cells);
496  _vtk_grid->GetCellData()->AddArray(elem_id);
497  _vtk_grid->GetCellData()->AddArray(subdomain_id);
498  _vtk_grid->GetCellData()->AddArray(elem_proc_id);
499 }
500 
501 void VTKIO::node_values_to_vtk(const std::string & name,
502  const std::vector<Real> & local_values)
503 {
504  vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
505  data->SetName(name.c_str());
506 
507  libmesh_assert_equal_to(_local_node_map.size(), local_values.size());
508 
509  // number of local and ghost nodes
510  data->SetNumberOfValues(_local_node_map.size());
511 
512  // copy values into vtk
513  for (auto i : index_range(local_values)) {
514  data->SetValue(i, local_values[i]);
515  }
516 
517  _vtk_grid->GetPointData()->AddArray(data);
518 }
519 
520 void VTKIO::get_local_node_values(std::vector<Number> & local_values,
521  std::size_t variable,
522  const std::vector<Number> & soln,
523  const std::vector<std::string> & names)
524 {
526  std::size_t num_vars = names.size();
527  dof_id_type num_nodes = mesh.n_nodes();
528 
529  local_values.clear();
530  local_values.resize(_local_node_map.size(), 0.0);
531 
532  // loop over all nodes and get the solution for the current
533  // variable, if the node is in the current partition
534  for (dof_id_type k=0; k<num_nodes; ++k)
535  {
536  std::map<dof_id_type, dof_id_type>::iterator local_node_it = _local_node_map.find(k);
537  if (local_node_it == _local_node_map.end())
538  continue; // not a local node
539 
540  local_values[local_node_it->second] = soln[k*num_vars + variable];
541  }
542 }
543 
544 
545 
553 // void VTKIO::system_vectors_to_vtk(const EquationSystems & es,
554 // vtkUnstructuredGrid *& grid)
555 // {
556 // if (MeshOutput<MeshBase>::mesh().processor_id() == 0)
557 // {
558 // std::map<std::string, std::vector<Number>> vecs;
559 // for (unsigned int i=0; i<es.n_systems(); ++i)
560 // {
561 // const System & sys = es.get_system(i);
562 // System::const_vectors_iterator v_end = sys.vectors_end();
563 // System::const_vectors_iterator it = sys.vectors_begin();
564 // for (; it!= v_end; ++it)
565 // {
566 // // for all vectors on this system
567 // std::vector<Number> values;
568 // // libMesh::out<<"it "<<it->first<<std::endl;
569 //
570 // it->second->localize_to_one(values, 0);
571 // // libMesh::out<<"finish localize"<<std::endl;
572 // vecs[it->first] = values;
573 // }
574 // }
575 //
576 // std::map<std::string, std::vector<Number>>::iterator it = vecs.begin();
577 //
578 // for (; it!=vecs.end(); ++it)
579 // {
580 // vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
581 // data->SetName(it->first.c_str());
582 // libmesh_assert_equal_to (it->second.size(), es.get_mesh().n_nodes());
583 // data->SetNumberOfValues(it->second.size());
584 //
585 // for (auto i : index_range(it->second))
586 // {
587 // #ifdef LIBMESH_USE_COMPLEX_NUMBERS
588 // libmesh_do_once (libMesh::err << "Only writing the real part for complex numbers!\n"
589 // << "if you need this support contact " << LIBMESH_PACKAGE_BUGREPORT
590 // << std::endl);
591 // data->SetValue(i, it->second[i].real());
592 // #else
593 // data->SetValue(i, it->second[i]);
594 // #endif
595 //
596 // }
597 // grid->GetPointData()->AddArray(data);
598 // }
599 // }
600 // }
601 
602 
603 
604 #else // !LIBMESH_HAVE_VTK
605 
606 void VTKIO::read (const std::string & name)
607 {
608  libmesh_error_msg("Cannot read VTK file: " << name \
609  << "\nYou must have VTK installed and correctly configured to read VTK meshes.");
610 }
611 
612 
613 
614 void VTKIO::write_nodal_data (const std::string & fname,
615  const std::vector<Number> &,
616  const std::vector<std::string> &)
617 {
618  libmesh_error_msg("Cannot write VTK file: " << fname \
619  << "\nYou must have VTK installed and correctly configured to read VTK meshes.");
620 }
621 
622 
623 #endif // LIBMESH_HAVE_VTK
624 
625 
626 
627 } // namespace libMesh
libMesh::VTKIO::read
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in VTK format.
Definition: vtk_io.C:155
libMesh::HEX20
Definition: enum_elem_type.h:48
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::PRISM6
Definition: enum_elem_type.h:50
libMesh::VTKIO::cells_to_vtk
void cells_to_vtk()
write the cells from the mesh into a vtkUnstructuredGrid
Definition: vtk_io.C:425
libMesh::VTKIO::VTKIO
VTKIO(MeshBase &mesh)
Constructor.
Definition: vtk_io.C:81
libMesh::VTKIO::nodes_to_vtk
void nodes_to_vtk()
write the nodes from the mesh into a vtkUnstructuredGrid and update the local_node_map.
Definition: vtk_io.C:382
libMesh::VTKIO::ElementMaps::writing_map
std::map< ElemType, vtkIdType > writing_map
Definition: vtk_io.h:207
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::MeshBase::point
virtual const Point & point(const dof_id_type i) const =0
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::DofObject::set_id
dof_id_type & set_id()
Definition: dof_object.h:776
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Elem::dim
virtual unsigned short dim() const =0
libMesh::TET10
Definition: enum_elem_type.h:46
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::VTKIO::get_vtk_grid
vtkUnstructuredGrid * get_vtk_grid()
Get a pointer to the VTK unstructured grid data structure.
Definition: vtk_io.C:368
libMesh::Elem::node_index_range
IntRange< unsigned short > node_index_range() const
Definition: elem.h:2170
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::node_ptr
virtual const Node * node_ptr(const dof_id_type i) const =0
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
libMesh::TET4
Definition: enum_elem_type.h:45
libMesh::PRISM15
Definition: enum_elem_type.h:51
libMesh::Elem::connectivity
virtual void connectivity(const unsigned int sc, const IOPackage iop, std::vector< dof_id_type > &conn) const =0
libMesh::MeshBase::n_local_nodes
dof_id_type n_local_nodes() const
Definition: mesh_base.h:303
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::HEX27
Definition: enum_elem_type.h:49
libMesh::ParallelObject::n_processors
processor_id_type n_processors() const
Definition: parallel_object.h:100
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::VTKIO::_vtk_grid
vtkSmartPointer< vtkUnstructuredGrid > _vtk_grid
Write the system vectors to vtk.
Definition: vtk_io.h:169
libMesh::MeshBase::local_node_ptr_range
virtual SimpleRange< node_iterator > local_node_ptr_range()=0
libMesh::QUAD4
Definition: enum_elem_type.h:41
libMesh::VTKIO::_compress
bool _compress
Flag to indicate whether the output should be compressed.
Definition: vtk_io.h:174
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::TRI3
Definition: enum_elem_type.h:39
libMesh::VTKIO::get_local_node_values
void get_local_node_values(std::vector< Number > &local_values, std::size_t variable, const std::vector< Number > &soln, const std::vector< std::string > &names)
Extract the values of soln that correspond to the nodes.
Definition: vtk_io.C:520
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::VTKIO::ElementMaps::associate
void associate(ElemType libmesh_type, vtkIdType vtk_type)
Definition: vtk_io.h:189
libMesh::Elem::set_node
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2059
libMesh::MeshBase::n_nodes
virtual dof_id_type n_nodes() const =0
libMesh::TRI6
Definition: enum_elem_type.h:40
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::VTKIO::set_compression
void set_compression(bool b)
Setter for compression flag.
Definition: vtk_io.C:375
libMesh::MeshOutput::mesh
const MT & mesh() const
Definition: mesh_output.h:247
libMesh::MeshBase::add_elem
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
libMesh::PYRAMID5
Definition: enum_elem_type.h:53
libMesh::DofObject::id
dof_id_type id() const
Definition: dof_object.h:767
libMesh::VTKIO::node_values_to_vtk
void node_values_to_vtk(const std::string &name, const std::vector< Real > &local_values)
write the nodal values of soln to a vtkUnstructuredGrid
Definition: vtk_io.C:501
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::VTKIO::ElementMaps
Helper object that holds a map from VTK to libMesh element types and vice-versa.
Definition: vtk_io.h:186
libMesh::MeshBase::n_active_local_elem
dof_id_type n_active_local_elem() const
Definition: mesh_base.h:420
libMesh::VTKIO::_local_node_map
std::map< dof_id_type, dof_id_type > _local_node_map
maps global node id to node id of partition
Definition: vtk_io.h:179
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::VTKIO::build_element_maps
static ElementMaps build_element_maps()
Static function used to construct the _element_maps struct.
Definition: vtk_io.C:121
libMesh::VTK
Definition: enum_io_package.h:42
libMesh::VTKIO::ElementMaps::find
vtkIdType find(ElemType libmesh_type)
Definition: vtk_io.h:196
data
IterBase * data
Ideally this private member data should have protected access.
Definition: variant_filter_iterator.h:337
libMesh::VTKIO::write_nodal_data
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: vtk_io.C:251
libMesh::MeshInput< MeshBase >::mesh
MeshBase & mesh()
Definition: mesh_input.h:169
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::MeshBase::add_point
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
libMesh::err
OStreamProxy err
libMesh::VTKIO::write
virtual void write(const std::string &) override
Output the mesh without solutions to a .pvtu file.
libMesh::TRI3SUBDIVISION
Definition: enum_elem_type.h:69
libMesh::MeshBase::clear
virtual void clear()
Deletes all the element and node data that is currently stored.
Definition: mesh_base.C:429
libMesh::MeshBase::set_mesh_dimension
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
Definition: mesh_base.h:218
libMesh::PRISM18
Definition: enum_elem_type.h:52
libMesh::Elem::build
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:246
libMesh::VTKIO::_element_maps
static ElementMaps _element_maps
ElementMaps object that is built statically and used by all instances of this class.
Definition: vtk_io.h:215
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::MeshInput
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
libMesh::EDGE2
Definition: enum_elem_type.h:35
libMesh::MeshInput< MeshBase >::elems_of_dimension
std::vector< bool > elems_of_dimension
A vector of bools describing what dimension elements have been encountered when reading a mesh.
Definition: mesh_input.h:97
libMesh::QUAD8
Definition: enum_elem_type.h:42
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33