29 #ifndef ModelCrbBase_H
30 #define ModelCrbBase_H 1
32 #include <feel/feel.hpp>
40 class ParameterDefinitionBase
43 typedef ParameterSpace<1> parameterspace_type ;
46 class FunctionSpaceDefinitionBase
50 typedef Simplex<1> entity_type ;
51 typedef Mesh<entity_type > mesh_type ;
54 typedef Lagrange<1,Scalar> basis_type ;
57 typedef FunctionSpace<mesh_type , basis_type > space_type ;
60 template <
typename ParameterDefinition,
typename FunctionSpaceDefinition>
61 class EimDefinitionBase
69 typedef EIMFunctionBase<space_type , space_type , parameterspace_type > fun_type ;
70 typedef EIMFunctionBase<space_type , space_type , parameterspace_type > fund_type ;
76 template <
typename ParameterDefinition,
typename FunctionSpaceDefinition,
typename EimDefinition = EimDefinitionBase<ParameterDefinition,FunctionSpaceDefinition> >
77 class ModelCrbBase :
public ModelCrbBaseBase
81 typedef typename EimDefinition::fun_type fun_type;
82 typedef typename EimDefinition::fund_type fund_type;
85 typedef typename parameterspace_type::element_type parameter_type;
89 typedef boost::shared_ptr<fun_type> fun_ptrtype;
90 typedef std::vector<fun_ptrtype> funs_type;
92 typedef boost::shared_ptr<fund_type> fund_ptrtype;
93 typedef std::vector<fund_ptrtype> funsd_type;
95 typedef Eigen::VectorXd vectorN_type;
97 typedef std::vector< std::vector< double > > beta_vector_type;
99 typedef OperatorLinear< space_type , space_type > operator_type;
100 typedef boost::shared_ptr<operator_type> operator_ptrtype;
102 typedef OperatorLinearComposite< space_type , space_type > operatorcomposite_type;
103 typedef boost::shared_ptr<operatorcomposite_type> operatorcomposite_ptrtype;
105 typedef FsFunctionalLinearComposite< space_type > functionalcomposite_type;
106 typedef boost::shared_ptr<functionalcomposite_type> functionalcomposite_ptrtype;
108 typedef FsFunctionalLinear< space_type > functional_type;
109 typedef boost::shared_ptr<functional_type> functional_ptrtype;
111 typedef backend_type::vector_type vector_type;
112 typedef backend_type::vector_ptrtype vector_ptrtype;
114 typedef backend_type::sparse_matrix_type sparse_matrix_type;
115 typedef backend_type::sparse_matrix_ptrtype sparse_matrix_ptrtype;
119 M_is_initialized( false )
123 void setInitialized(
const bool & b )
125 M_is_initialized = b ;
130 return M_is_initialized;
133 virtual funs_type scalarContinuousEim ()
const
138 virtual funsd_type scalarDiscontinuousEim ()
const
143 virtual void initModel() = 0;
145 virtual operatorcomposite_ptrtype operatorCompositeA()
149 virtual operatorcomposite_ptrtype operatorCompositeM()
153 virtual std::vector< functionalcomposite_ptrtype > functionalCompositeF()
170 virtual bool constructOperatorCompositeM()
182 virtual int QInitialGuess()
const
187 virtual int mMaxInitialGuess(
int q )
const
192 throw std::logic_error(
"[ModelCrbBase::mMaxInitialGuess(q)] ERROR wrong index q, should be 0" );
195 virtual beta_vector_type computeBetaInitialGuess( parameter_type
const& mu )
197 beta_vector_type beta;
211 virtual double scalarProductForMassMatrix( vector_ptrtype
const& X, vector_ptrtype
const& Y )
213 throw std::logic_error(
"Your model is time-dependant so you MUST implement scalarProductForMassMatrix function");
216 virtual double scalarProductForMassMatrix( vector_type
const& x, vector_type
const& y )
218 throw std::logic_error(
"Your model is time-dependant so you MUST implement scalarProductForMassMatrix function");
226 virtual sparse_matrix_ptrtype
const& innerProductForMassMatrix ()
const
228 throw std::logic_error(
"Your model is time-dependant so you MUST implement innerProductForMassMatrix function");
231 virtual sparse_matrix_ptrtype innerProductForMassMatrix ()
233 throw std::logic_error(
"Your model is time-dependant so you MUST implement innerProductForMassMatrix function");
242 vectorN_type computeStatistics( Eigen::VectorXd vector , std::string name )
244 double min=0,max=0,mean=0,mean1=0,mean2=0,standard_deviation=0,variance=0;
245 Eigen::MatrixXf::Index index;
246 Eigen::VectorXd square;
248 if( vector.size() > 0 )
250 bool force = option(
"eim.use-dimension-max-functions").template as<bool>();
253 Neim = option(
"eim.dimension-max").template as<int>();
255 int N = vector.size();
258 LOG( INFO ) <<
" statistics for "<<name<<
" ( was called "<< N <<
" times with "<<Neim<<
" basis functions )";
260 LOG( INFO ) <<
" statistics for "<<name<<
" ( was called "<< N <<
" times )";
262 min = vector.minCoeff(&index);
263 max = vector.maxCoeff(&index);
264 mean = vector.mean();
266 square = vector.array().pow(2);
267 mean2 = square.mean();
268 standard_deviation = math::sqrt( mean2 - mean1 );
269 LOG(INFO)<<
"min : "<<min<<
" - max : "<<max<<
" mean : "<<mean<<
" standard deviation : "<<standard_deviation;
271 vectorN_type result(4);
275 result(3)=standard_deviation;
284 bool M_is_initialized;
286 sparse_matrix_ptrtype M;
288 operatorcomposite_ptrtype M_compositeA;
289 operatorcomposite_ptrtype M_compositeM;
290 std::vector< functionalcomposite_ptrtype > M_compositeF;
Definition: functionspace.hpp:1374
Parameter space class.
Definition: parameterspace.hpp:58