Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exporterimpl.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2010-04-21
7 
8  Copyright (C) 2010 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #include <boost/tokenizer.hpp>
30 #include <boost/token_functions.hpp>
31 #include <boost/algorithm/string/split.hpp>
32 #include <boost/algorithm/string/classification.hpp>
33 
34 #include <feel/feelcore/feel.hpp>
37 
38 #include <feel/feelfilters/exportergmsh.hpp>
39 #include <feel/feelfilters/exporterensight.hpp>
40 #include <feel/feelfilters/exporterensightgold.hpp>
42 
43 namespace Feel
44 {
45 template<typename MeshType, int N> class ExporterEnsight;
46 template<typename MeshType, int N> class ExporterEnsightGold;
47 template<typename MeshType, int N> class ExporterGmsh;
48 
49 template<typename MeshType, int N>
50 Exporter<MeshType, N>::Exporter( WorldComm const& worldComm )
51  :
52  super1(),
53  super2(),
54  M_worldComm( worldComm ),
55  M_do_export( true ),
56  M_type(),
57  M_prefix( Environment::about().appName() ),
58  M_freq( 1 ),
59  M_cptOfSave( 0 ),
60  M_ft( ASCII ),
61  M_path( "." ),
62  M_ex_geometry( EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY )
63 {
64  VLOG(1) << "[exporter::exporter] do export = " << doExport() << "\n";
65 }
66 
67 template<typename MeshType, int N>
68 Exporter<MeshType, N>::Exporter( std::string const& __type, std::string const& __prefix, int __freq, WorldComm const& worldComm )
69  :
70  super1(),
71  super2(),
72  M_worldComm( worldComm ),
73  M_do_export( true ),
74  M_type( __type ),
75  M_prefix( __prefix ),
76  M_freq( __freq ),
77  M_cptOfSave( 0 ),
78  M_ft( ASCII ),
79  M_path( "." ),
80  M_ex_geometry( EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY )
81 {
82 
83 }
84 
85 template<typename MeshType, int N>
86 Exporter<MeshType, N>::Exporter( po::variables_map const& vm, std::string const& exp_prefix, WorldComm const& worldComm )
87  :
88  super1(),
89  super2(),
90  M_worldComm( worldComm ),
91  M_do_export( true ),
92  M_type(),
93  M_prefix( exp_prefix ),
94  M_freq( 1 ),
95  M_cptOfSave( 0 ),
96  M_ft( ASCII ),
97  M_path( "." ),
98  M_ex_geometry( EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY )
99 {
100  VLOG(1) << "[exporter::exporter] do export = " << doExport() << "\n";
101 }
102 
103 template<typename MeshType, int N>
105  :
106  super1(),
107  super2(),
108  M_worldComm( __ex.M_worldComm ),
109  M_do_export( __ex.M_do_export ),
110  M_type( __ex.M_type ),
111  M_prefix( __ex.M_prefix ),
112  M_freq( __ex.M_freq ),
113  M_cptOfSave( __ex.M_cptOfSave ),
114  M_ft( __ex.M_ft ),
115  M_path( __ex.M_path ),
116  M_ex_geometry( EXPORTER_GEOMETRY_CHANGE_COORDS_ONLY )
117 {
118 
119 }
120 
121 template<typename MeshType, int N>
123 {}
124 
125 template<typename MeshType, int N>
126 boost::shared_ptr<Exporter<MeshType, N> >
127 Exporter<MeshType, N>::New( std::string const& exportername, std::string prefix, WorldComm const& worldComm )
128 {
129  Exporter<MeshType, N>* exporter = 0;//Factory::type::instance().createObject( exportername );
130 
131  if ( N == 1 && ( exportername == "ensight" ) )
132  exporter = new ExporterEnsight<MeshType, N>( worldComm );
133  else if ( N == 1 && ( exportername == "ensightgold" ) )
134  exporter = new ExporterEnsightGold<MeshType, N>( worldComm );
135  else if ( N == 1 && ( exportername == "exodus" ) )
136  exporter = new ExporterExodus<MeshType, N>( worldComm );
137  else if ( N > 1 || ( exportername == "gmsh" ) )
138  exporter = new ExporterGmsh<MeshType,N>;
139  else // fallback
140  exporter = new ExporterEnsight<MeshType, N>( worldComm );
141 
142  exporter->addTimeSet( timeset_ptrtype( new timeset_type( prefix ) ) );
143  exporter->setPrefix( prefix );
144  return boost::shared_ptr<Exporter<MeshType, N> >(exporter);
145 }
146 
147 template<typename MeshType, int N>
148 boost::shared_ptr<Exporter<MeshType, N> >
149 Exporter<MeshType, N>::New( po::variables_map const& vm, std::string prefix, WorldComm const& worldComm )
150 {
151  std::string estr = vm["exporter.format"].template as<std::string>();
152  Exporter<MeshType, N>* exporter = 0;//Factory::type::instance().createObject( estr );
153 
154  if ( N == 1 && ( estr == "ensight" ) )
155  exporter = new ExporterEnsight<MeshType, N>( worldComm );
156  else if ( N == 1 && ( estr == "ensightgold" ) )
157  exporter = new ExporterEnsightGold<MeshType, N>( worldComm );
158  else if ( N == 1 && ( estr == "exodus" ) )
159  exporter = new ExporterExodus<MeshType, N>( worldComm );
160  else if ( N > 1 || estr == "gmsh" )
161  exporter = new ExporterGmsh<MeshType,N>;
162  else // fallback
163  exporter = new ExporterEnsight<MeshType, N>( worldComm );
164 
165 
166  exporter->setOptions();
167  //std::cout << "[exporter::New] do export = " << exporter->doExport() << std::endl;
168  exporter->addTimeSet( timeset_ptrtype( new timeset_type( prefix ) ) );
169  exporter->setPrefix( prefix );
170  return boost::shared_ptr<Exporter<MeshType, N> >( exporter );
171 }
172 
173 template<typename MeshType, int N>
175 Exporter<MeshType, N>::setOptions( std::string const& exp_prefix )
176 {
177  //M_do_export = Environment::vm(_prefix+"export"].template as<bool>();
178  M_do_export = Environment::vm(_name="exporter.export",_prefix=exp_prefix).template as<bool>();
179  M_type = Environment::vm(_name="exporter.format",_prefix=exp_prefix).template as<std::string>();
180 
181  std::string p = exp_prefix;
182  if ( !p.empty() )
183  p += ".";
184  if ( Environment::vm().count( p+"exporter.prefix" ) )
185  M_prefix = Environment::vm(_name="exporter.prefix",_prefix=exp_prefix).template as<std::string>();
186 
187  M_freq = Environment::vm(_name="exporter.freq",_prefix=exp_prefix).template as<int>();
188  M_ft = file_type( Environment::vm(_name="exporter.file-type",_prefix=exp_prefix).template as<int>() );
189 
190  VLOG(1) << "[Exporter] type: " << M_type << "\n";
191  VLOG(1) << "[Exporter] prefix: " << M_prefix << "\n";
192  VLOG(1) << "[Exporter] freq: " << M_freq << "\n";
193  VLOG(1) << "[Exporter] ft: " << M_ft << "\n";
194  return this;
195 }
196 
197 template<typename MeshType, int N>
199 Exporter<MeshType, N>::addPath( boost::format fmt )
200 {
201  fs::path rep_path = ".";
202  typedef std::vector< std::string > split_vector_type;
203 
204  split_vector_type dirs; // #2: Search for tokens
205  std::string fmtstr = fmt.str();
206  boost::split( dirs, fmtstr, boost::is_any_of( "/" ) );
207 
208  BOOST_FOREACH( std::string const& dir, dirs )
209  {
210  //DVLOG(2) << "[Application::Application] option: " << s << "\n";
211  rep_path = rep_path / dir;
212 
213  if ( !fs::exists( rep_path ) )
214  fs::create_directory( rep_path );
215  }
216 
217  M_path = rep_path.string();
218 
219  return this;
220 }
221 
222 
223 }

Generated on Fri Oct 25 2013 14:24:09 for Feel++ by doxygen 1.8.4