• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/export/development/ViennaFEM/viennafem/io/vtk_writer.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAFEM_IO_VTKWRITER_HPP
00002 #define VIENNAFEM_IO_VTKWRITER_HPP
00003 
00004 /* =========================================================================
00005    Copyright (c) 2012, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008                              -----------------
00009                ViennaFEM - The Vienna Finite Element Method Library
00010                              -----------------
00011 
00012    Author:     Karl Rupp                          rupp@iue.tuwien.ac.at
00013 
00014    License:    MIT (X11), see file LICENSE in the ViennaFEM base directory
00015 ============================================================================ */
00016 
00017 
00018 // include necessary system headers
00019 #include <iostream>
00020 
00021 #include "viennafem/forwards.h"
00022 
00023 // ViennaGrid includes:
00024 #include "viennagrid/domain.hpp"
00025 #include "viennagrid/iterators.hpp"
00026 #include "viennagrid/io/vtk_writer.hpp"
00027 
00028 // ViennaData includes:
00029 #include "viennadata/api.hpp"
00030 
00035 namespace viennafem
00036 {
00037   namespace io
00038   {
00039 
00047     template <typename VectorType,
00048               typename DomainType>
00049     void write_solution_to_VTK_file(VectorType const & result,
00050                                     std::string filename,
00051                                     DomainType const & domain,
00052                                     long id)
00053     {
00054       typedef typename DomainType::config_type                                              ConfigType;
00055       typedef typename viennagrid::result_of::ncell<ConfigType, 0>::type               VertexType;
00056       typedef typename viennagrid::result_of::const_ncell_range<DomainType, 0>::type    VertexContainer;
00057       typedef typename viennagrid::result_of::iterator<VertexContainer>::type               VertexIterator;
00058       
00059       typedef viennafem::mapping_key          MappingKeyType;
00060       typedef viennafem::boundary_key         BoundaryKeyType;
00061       
00062       MappingKeyType map_key(id);
00063       BoundaryKeyType bnd_key(id);
00064       
00065       
00066       std::cout << "* write_solution_to_VTK_file(): Writing result on mesh for later export" << std::endl;
00067       VertexContainer vertices = viennagrid::ncells<0>(domain);
00068       for (VertexIterator vit = vertices.begin();
00069           vit != vertices.end();
00070           ++vit)
00071       {
00072         long cur_index = viennadata::access<MappingKeyType, long>(map_key)(*vit);
00073         if (cur_index > -1)
00074           viennadata::access<std::string, double>("vtk_data")(*vit) = result[cur_index];
00075         else //use Dirichlet boundary data:
00076           viennadata::access<std::string, double>("vtk_data")(*vit) = 
00077             viennadata::access<BoundaryKeyType, double>(bnd_key)(*vit);
00078       }
00079 
00080       std::cout << "* write_solution_to_VTK_file(): Writing data to '"
00081                 << filename
00082                 << "' (can be viewed with e.g. Paraview)" << std::endl;
00083 
00084       viennagrid::io::vtk_writer<DomainType> my_vtk_writer;
00085       viennagrid::io::add_scalar_data_on_vertices<std::string, double>(my_vtk_writer, "vtk_data", "fem_result");
00086       my_vtk_writer(domain, filename);  
00087     }
00088 
00089 
00090   }
00091 }
00092 #endif
00093 

Generated on Wed Feb 29 2012 21:51:05 for ViennaFEM - The Vienna Finite Element Method Library by  doxygen 1.7.1