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
crbapp.hpp
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 __OpusEadsCrbApp_H
30 #define __OpusEadsCrbApp_H 1
31 
32 #include <feel/feelcrb/crb.hpp>
34 
35 
36 namespace Feel
37 {
44 template<typename ModelType>
45 class CRBApp : public Application
46 {
47  typedef Application super;
48 public:
49 
51  typedef boost::shared_ptr<crbmodel_type> crbmodel_ptrtype;
53  typedef boost::shared_ptr<crb_type> crb_ptrtype;
54 
55  CRBApp( AboutData const& ad, po::options_description const& od )
56  :
57  super( ad, crbOptions().add( od ) )
58  {
59  this->init();
60  }
61 
62  CRBApp( int argc, char** argv, AboutData const& ad, po::options_description const& od )
63  :
64  super( argc, argv, ad, crbOptions().add( od ) )
65  {
66  this->init();
67  }
68  void init()
69  {
70  std::srand( static_cast<unsigned>( std::time( 0 ) ) );
71  std::cerr << "[CRBApp] constructor " << this->about().appName() << std::endl;
72 
73  if ( this->vm().count( "crb.output-index" ) )
74  this->changeRepository( boost::format( "%1%/h_%2%/s_%3%" )
75  % this->about().appName()
76  % this->vm()["hsize"].template as<double>()
77  % this->vm()["crb.output-index"].template as<int>()
78  );
79 
80  else
81  this->changeRepository( boost::format( "%1%/h_%2%/" )
82  % this->about().appName()
83  % this->vm()["hsize"].template as<double>()
84  );
85 
86  std::cerr << "[CRBApp] ch repo" << std::endl;
87  this->setLogs();
88  std::cerr << "[CRBApp] set Logs" << std::endl;
89  opus = crbmodel_ptrtype( new crbmodel_type( this->vm() ) );
90  std::cerr << "[CRBApp] get model done" << std::endl;
91  crb = crb_ptrtype( new crb_type( this->about().appName(),
92  this->vm() ) );
93 
94  std::cerr << "[CRBApp] get crb done" << std::endl;
95  crb->setTruthModel( opus );
96  std::cerr << "[CRBApp] constructor done" << std::endl;
97 
98  }
99  void setOutput( int i = 0, CRBErrorType error_type = ( int )CRB_RESIDUAL , int maxiter = 10 )
100  {
101  auto ckconv = crb->offline();
102 
103  if ( ckconv.size() )
104  {
105 #if 0
106  double max_ei=0;
107  double min_ei=0;
108  crb->computeErrorEstimationEfficiencyIndicator ( opus->parameterSpace(), max_ei, min_ei,10 );
109 #endif
110 
111  for ( auto it = ckconv.left.begin(); it != ckconv.left.end(); ++it )
112  {
113  LOG(INFO) << "ckconv[" << it->first <<"]=" << it->second << "\n";
114  }
115  }
116  }
117  void run()
118  {
119  if ( this->vm().count( "help" ) )
120  {
121  std::cout << this->optionsDescription() << "\n";
122  return;
123  }
124 
125  if ( !crb->isDBLoaded() )
126  {
127  std::cout << "No DB available, do offline computations first...\n";
128  crb->offline();
129  }
130 
131  typename crb_type::sampling_ptrtype Sampling( new typename crb_type::sampling_type( opus->parameterSpace() ) );
132  Sampling->randomize( 10 );
133  int crb_error_type = crb->errorType();
134  int output_index = crb->outputIndex();
135  BOOST_FOREACH( auto mu, *Sampling )
136  {
137  double sfem = opus->output( output_index, mu );
138  int size = mu.size();
139  std::cout << "------------------------------------------------------------\n";
140  std::cout << "tolerance : " << this->vm()["crb.online-tolerance"].template as<double>() << "\n";
141  std::cout << "mu = [ ";
142 
143  for ( int i=0; i<size-1; i++ ) std::cout<< mu[i] <<" , ";
144 
145  std::cout<< mu[size-1]<<" ] \n";
146  auto o = crb->run( mu, this->vm()["crb.online-tolerance"].template as<double>() );
147 
148  if ( crb_error_type==2 )
149  {
150  std::cout << "output=" << o.get<0>() << " with " << o.get<2>() << " basis functions\n";
151  std::cout << "output obtained using FEM : "<<sfem<<std::endl;
152  }
153 
154  else
155  {
156  std::cout << "output=" << o.get<0>() << " with " << o.get<2>() << " basis functions (error estimation on this output : " << o.get<1>()<<") \n";
157  std::cout << "output obtained using FEM : "<<sfem<<std::endl;
158  }
159 
160  std::cout << "------------------------------------------------------------\n";
161  }
162  }
163  void run( const double * X, unsigned long N,
164  double * Y, unsigned long P )
165  {
166  crb->run( X, N, Y, P );
167  }
168 
169  crbmodel_ptrtype opus;
170  crb_ptrtype crb;
171 }; // CRBApp
172 } // Feel
173 
174 #endif /* __CrbApp_H */

Generated on Sun Oct 20 2013 08:24:55 for Feel++ by doxygen 1.8.4