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
pfemapp.hpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2010-03-22
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 #ifndef PFEMAPP_HPP
30 #define PFEMAPP_HPP
31 
32 #include <feel/feelcore/feel.hpp>
34 #include <feel/options.hpp>
35 
36 
38 #include <feel/feelcrb/pfemapp.hpp>
39 
40 
41 namespace Feel
42 {
43 po::options_description pfemapp_options( std::string const& prefix );
44 std::string _o( std::string const& prefix, std::string const& opt )
45 {
46  std::string o = prefix;
47 
48  if ( !o.empty() )
49  o += "-";
50 
51  return o + opt;
52 }
59 template<typename ModelType>
60 class PFemApp : public Application
61 {
62  typedef Application super;
63 public:
64 
66  typedef boost::shared_ptr<crbmodel_type> crbmodel_ptrtype;
67 
68 
69  PFemApp( AboutData const& ad, po::options_description const& od )
70  :
71  super( ad, pfemapp_options( ad.appName() ).add( od ) )
72  {
73  this->init();
74  }
75 
76  PFemApp( int argc, char** argv, AboutData const& ad, po::options_description const& od )
77  :
78  super( argc, argv, ad, pfemapp_options( ad.appName() ).add( od ) )
79  {
80  this->init();
81  }
82  void init()
83  {
84  std::srand( static_cast<unsigned>( std::time( 0 ) ) );
85  this->setLogs();
86  this->changeRepository( boost::format( "%1%/h_%2%/" )
87  % this->about().appName()
88  % this->vm()["hsize"].template as<double>()
89  );
90  std::cout << "[PFemApp] build model " << this->about().appName() << "\n";
91  model = crbmodel_ptrtype( new crbmodel_type( this->vm() ) );
92 
93  std::cout << "build model " << this->about().appName() << " done\n";
94  }
95  void run()
96  {
97  if ( this->vm().count( "help" ) )
98  {
99  std::cout << this->optionsDescription() << "\n";
100  return;
101  }
102 
103  typename crbmodel_type::parameter_type mu( model->parameterSpace() );
104  int mutype = this->vm()[_o( this->about().appName(),"mu-type" )].template as<int>();
105 
106  if ( mutype <= 0 )
107  {
108  bool broadcast = true;
109  mu = crbmodel_type::parameterspace_type::logRandom( model->parameterSpace(), broadcast );
110  }
111 
112  else if ( mutype == 1 )
113  {
114  mu = model->parameterSpace()->min();
115  }
116 
117  else if ( mutype == 2 )
118  {
119  //mu = model->parameterSpace()->middle();
120  mu = model->parameterSpace()->max();
121  }
122 
123  else
124  {
125  mu = model->parameterSpace()->max();
126  }
127 
128  std::cout << "[PFemApp] running " << this->about().appName() << " with mu = [";
129  int size = mu.size();
130 
131  for ( int i=0; i<size-1; i++ ) std::cout<<mu( i )<<" , ";
132 
133  std::cout<< mu( size-1 )<<"] "<<std::endl;
134 
135  model->solve( mu );
136 
137  auto Xh = model->functionSpace();
138  auto u = Xh->element();
139  bool need_to_solve=true;
140 
141  for ( int l =0; l < model->Nl(); ++l )
142  {
143  double o = model->output( l,mu , u , need_to_solve );
144  std::cout << "[PFemApp] output " << l << " of " << this->about().appName() << " = " << o << "\n";
145  }
146  }
147 
148  void run( const double * X, unsigned long N,
149  double * Y, unsigned long P )
150  {
151 
152  model->run( X, N, Y, P );
153 
154  }
155 
156  crbmodel_ptrtype model;
157 
158 
159 }; // Opus
160 
161 
162 
163 } // Feel
164 
165 #endif

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