int main () {

	//===============================================================//
	//========= PROBLEM SETUP  =======================//
	//===============================================================//
	
    int d   = 2;
    int d_  = 2;
    int j0  = 2;

    //getchar();

    /// Basis initialization
    TrialBasis_Time      basis_per(d,d_,j0);
    TestBasis_Time       basis_int(d,d_,j0);
    Basis_Space 		 basis_intbc(d,0);
    basis_intbc.enforceBoundaryCondition<DirichletBC>();

    Basis2D_Trial basis2d_trial(basis_per,basis_intbc);
    Basis2D_Test  basis2d_test(basis_int,basis_intbc);

    /// Initialization of operators
    DenseVectorT no_singPts;

    // Bilinear Forms
    Convection1D_Time			ConvectionBil_t(basis_per, basis_int);
    Identity1D_Time 		    IdentityBil_t(basis_per, basis_int);
    Identity1D_Space 	        IdentityBil_x(basis_intbc, basis_intbc);
    Laplace1D_Space 	        LaplaceBil_x(basis_intbc, basis_intbc);
    Convection1D_Space 	        ConvectionBil_x(basis_intbc, basis_intbc);


    RefConvection1D_Time 		RefConvectionBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefIdentity1D_Time 		    RefIdentityBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefIdentity1D_Space 	    RefIdentityBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefLaplace1D_Space 	        RefLaplaceBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefConvection1D_Space 	    RefConvectionBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);

    // Transposed Bilinear Forms
    TranspConvection1D_Time 	TranspConvectionBil_t(basis_per, basis_int);
    TranspIdentity1D_Time 		TranspIdentityBil_t(basis_per, basis_int);
    TranspIdentity1D_Space 	    TranspIdentityBil_x(basis_intbc, basis_intbc);
    TranspLaplace1D_Space 	    TranspLaplaceBil_x(basis_intbc, basis_intbc);
    TranspConvection1D_Space 	TranspConvectionBil_x(basis_intbc, basis_intbc);
    
    RefTranspConvection1D_Time 	RefTranspConvectionBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefTranspIdentity1D_Time 	RefTranspIdentityBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefTranspIdentity1D_Space 	RefTranspIdentityBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefTranspLaplace1D_Space 	RefTranspLaplaceBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefTranspConvection1D_Space RefTranspConvectionBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);

    /// Initialization of local operator
    LOp_Conv1D_Time			lOp_Conv1D_t	(basis_int, basis_per, RefConvectionBil_t, ConvectionBil_t);
    LOp_Id1D_Time			lOp_Id1D_t  	(basis_int, basis_per, RefIdentityBil_t, IdentityBil_t);
    LOp_Id1D_Space			lOp_Id1D_x  	(basis_intbc, basis_intbc, RefIdentityBil_x, IdentityBil_x);
    LOp_Lapl1D_Space		lOp_Lapl1D_x	(basis_intbc, basis_intbc, RefLaplaceBil_x, LaplaceBil_x);
    LOp_Conv1D_Space		lOp_Conv1D_x	(basis_intbc, basis_intbc, RefConvectionBil_x, ConvectionBil_x);
    
    LOpT_Conv1D_Time		lOpT_Conv1D_t(basis_per, basis_int, RefTranspConvectionBil_t, TranspConvectionBil_t);
    LOpT_Id1D_Time			lOpT_Id1D_t  (basis_per, basis_int, RefTranspIdentityBil_t, TranspIdentityBil_t);
    LOpT_Id1D_Space			lOpT_Id1D_x  (basis_intbc, basis_intbc, RefTranspIdentityBil_x, TranspIdentityBil_x);
    LOpT_Lapl1D_Space		lOpT_Lapl1D_x(basis_intbc, basis_intbc, RefTranspLaplaceBil_x, TranspLaplaceBil_x);
    LOpT_Conv1D_Space		lOpT_Conv1D_x(basis_intbc, basis_intbc, RefTranspConvectionBil_x, TranspConvectionBil_x);

    LOp_Conv_Id_2D			localConvectionIdentityOp2D		(lOp_Conv1D_t, 		lOp_Id1D_x);
    LOp_Id_Id_2D			localIdentityIdentityOp2D		(lOp_Id1D_t, 		lOp_Id1D_x);
    LOp_Id_Lapl_2D			localIdentityLaplaceOp2D		(lOp_Id1D_t, 		lOp_Lapl1D_x);
    LOp_Id_Conv_2D			localIdentityConvectionOp2D		(lOp_Id1D_t, 		lOp_Conv1D_x);

    LOpT_Conv_Id_2D		transpLocalConvectionIdentityOp2D	(lOpT_Conv1D_t, lOpT_Id1D_x);
    LOpT_Id_Id_2D		transpLocalIdentityIdentityOp2D		(lOpT_Id1D_t, 	lOpT_Id1D_x);
    LOpT_Id_Lapl_2D		transpLocalIdentityLaplaceOp2D		(lOpT_Id1D_t, 	lOpT_Lapl1D_x);
    LOpT_Id_Conv_2D		transpLocalIdentityConvectionOp2D	(lOpT_Id1D_t, 	lOpT_Conv1D_x);

    localConvectionIdentityOp2D.setJ(9);
    localIdentityIdentityOp2D.setJ(9);
    localIdentityLaplaceOp2D.setJ(9);
    localIdentityConvectionOp2D.setJ(9);
    transpLocalConvectionIdentityOp2D.setJ(9);
    transpLocalIdentityIdentityOp2D.setJ(9);
    transpLocalIdentityLaplaceOp2D.setJ(9);
    transpLocalIdentityConvectionOp2D.setJ(9);

    // Affine Decompositions:
    // 	Left Hand Side -> mu's are _NOT_ evaluated (only global consts!!)
    vector<ThetaStructure<ParamType>::ThetaFct>	lhs_theta_fcts;
    lhs_theta_fcts.push_back(no_theta);
    lhs_theta_fcts.push_back(theta_lapl);
    lhs_theta_fcts.push_back(theta_conv);
    lhs_theta_fcts.push_back(theta_reac);
    ThetaStructure<ParamType> lhs_theta(lhs_theta_fcts);

    vector<AbstractLocalOperator2D<T>* > lhs_ops, lhs_opsT;
    lhs_ops.push_back(&localConvectionIdentityOp2D);
    lhs_ops.push_back(&localIdentityLaplaceOp2D);
    lhs_ops.push_back(&localIdentityConvectionOp2D);
    lhs_ops.push_back(&localIdentityIdentityOp2D);
    lhs_opsT.push_back(&transpLocalConvectionIdentityOp2D);
    lhs_opsT.push_back(&transpLocalIdentityLaplaceOp2D);
    lhs_opsT.push_back(&transpLocalIdentityConvectionOp2D);
    lhs_opsT.push_back(&transpLocalIdentityIdentityOp2D);

    Affine_Op_2D affine_lhs(lhs_theta, lhs_ops);
    Affine_Op_2D affine_lhs_T(lhs_theta, lhs_opsT);


    /// Initialization of preconditioner
    LeftPrec2D leftPrec(basis2d_test);
    RightPrec2D rightPrec(basis2d_trial);

    NoPrec2D noPrec;

    /// Initialization of rhs

    /// Right Hand Side:
    ///     No Singular Supports in both dimensions
    int n = 20;
    DenseVectorT sing_support_t(n+1), sing_support_x(n+1);
    int i0 = sing_support_t.firstIndex();
    for(int i = 0; i <= n; ++i){
    	sing_support_t(i0 + i) = i/(double)n;
    	sing_support_x(i0 + i) = i/(double)n;
    }

    ///      Forcing Functions
    Function2D<T> 			F_fct(curve, sing_support_t, sing_support_x);
    RhsIntegral2D			rhs(basis2d_test, F_fct, 10);
    AdaptiveRhs2D           F(rhs,noPrec);

	//===============================================================//
	//===============  AWGM =========================================//
	//===============================================================//


    /* AWGM PG Parameters Default Values
    double tol = 5e-03;
	double alpha = 0.7;
	size_t max_its = 100;
	size_t max_basissize = 400000;
	bool reset_res = false;
	StableExpansionVersion stable_exp_u = FullExpansion;
	StableExpansionVersion stable_exp_res = FullExpansion;
	ResidualConstruction res_construction = SimpleStableExpansion;
	bool print_info = true;
	bool verbose = true;
	bool plot_solution = false;
	bool verbose_extra = false; //(print added wavelet indizes)
	size_t hashmapsize_trial = 10;
	size_t hashmapsize_test = 10;
	std::string info_filename = "awgm_cgls_conv_info.txt";
	std::string plot_filename = "awgm_cgls_u_plot";
	bool write_intermediary_solutions = false;
    std::string intermediary_solutions_filename = "awgm_cgls_u";
	*/

    /* IS Parameters Default Values
	bool adaptive_tol = true;
	size_t max_its = 100;
	double init_tol = 0.001;
	double res_reduction = 0.01;
	double absolute_tol = 1e-8;
	bool verbose = true;
	*/

    // MultitreeAWGM with default values
    //MT_AWGM multitree_awgm(basis2d_trial, basis2d_test, localOperator2D, transLocalOperator2D,
    //    						F, rightPrec, leftPrec);


    // If you want other parameters
    AWGM_PG_Parameters awgm_parameters;
    IS_Parameters cgls_parameters;
    // .... set them here:
    awgm_parameters.tol = 0.0001;
    awgm_parameters.stable_exp_u = OnlyTemporalHWExpansion; //WoMixedHWExpansion;
    awgm_parameters.stable_exp_res = OnlyTemporalHWExpansion;
    awgm_parameters.res_construction = DoubleStableExpansion; // ParallelMTCones
    awgm_parameters.plot_solution = false;
    awgm_parameters.verbose_extra = true;
    awgm_parameters.info_filename = "awgm_ExCDRCurve_mw_DoubleExp_conv_info.txt";
    awgm_parameters.plot_filename = "awgm_ExCDRCurve_mw_DoubleExp_u_plot";
    awgm_parameters.write_intermediary_solutions = true;
    awgm_parameters.intermediary_solutions_filename = "awgm_ExCDRCurve_mw_DoubleExp_u_Iteration";
    
    cgls_parameters.adaptive_tol = true;
    cgls_parameters.init_tol = 1e-4;
    cgls_parameters.res_reduction = 0.01;
    cgls_parameters.max_its = 700;

//    MT_AWGM multitree_awgm(basis2d_trial, basis2d_test, localOperator2D, transpLocalOperator2D,
//    						F, rightPrec, leftPrec, awgm_parameters, cgls_parameters);

    MT_AWGM multitree_awgm(basis2d_trial, basis2d_test, affine_lhs, affine_lhs_T,
        				F, rightPrec, leftPrec, awgm_parameters, cgls_parameters);

    // Parameter is ignored anyway!!
    ParamType mu = {{0., -9.}};
    lhs_theta.set_param(mu);

    multitree_awgm.awgm_params.print();
    multitree_awgm.is_params.print();

    multitree_awgm.set_sol(dummy);

    /// Initialization of solution vector and initial index sets
    Coefficients<Lexicographical,T,Index2D> u;

    T gamma = 0.2;
    IndexSet<Index2D> LambdaTrial, LambdaTest;
    getSparseGridIndexSet(basis2d_trial,LambdaTrial,2,0,gamma);
    getSparseGridIndexSet(basis2d_test ,LambdaTest ,2,1,gamma);

    Timer time;
    time.start();
    multitree_awgm.solve(u, LambdaTrial, LambdaTest);
    time.stop();
    cout << "Solution took " << time.elapsed() << " seconds" << endl;

    saveCoeffVector2D(u, basis2d_trial, "awgm_ExCDRCurve_mw_DoubleExp_u.txt");
    return 0;
}
int main (int argc, char* argv[]) {

	if(argc != 2){
		cerr << "USAGE: " << argv[0] << " Jmax (= max. level of sparse grid)" << endl;
		exit(1);
	}

	//===============================================================//
	//========= PROBLEM SETUP  =======================//
	//===============================================================//
	
    int d   = 2;
    int d_  = 2;
    int j0  = 2;
    size_t Jmax = atoi(argv[1]);

    //getchar();

    /// Basis initialization
    TrialBasis_Time      basis_per(d,d_,j0);
    TestBasis_Time       basis_int(d,d_,j0);
    Basis_Space 		 basis_intbc(d,0);
    basis_intbc.enforceBoundaryCondition<DirichletBC>();

    Basis2D_Trial basis2d_trial(basis_per,basis_intbc);
    Basis2D_Test  basis2d_test(basis_int,basis_intbc);

    /// Initialization of operator

    // Bilinear Forms
    Convection1D_Time			ConvectionBil_t(basis_per, basis_int);
    Identity1D_Time 		    IdentityBil_t(basis_per, basis_int);
    Identity1D_Space 	        IdentityBil_x(basis_intbc, basis_intbc);
    Laplace1D_Space 	        LaplaceBil_x(basis_intbc, basis_intbc);
    
    RefConvection1D_Time 		RefConvectionBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefIdentity1D_Time 		    RefIdentityBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefIdentity1D_Space 	    RefIdentityBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefLaplace1D_Space 	        RefLaplaceBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);

    // Transposed Bilinear Forms
    TranspConvection1D_Time 	TranspConvectionBil_t(basis_per, basis_int);
    TranspIdentity1D_Time 		TranspIdentityBil_t(basis_per, basis_int);
    TranspIdentity1D_Space 	    TranspIdentityBil_x(basis_intbc, basis_intbc);
    TranspLaplace1D_Space 	    TranspLaplaceBil_x(basis_intbc, basis_intbc);
    
    RefTranspConvection1D_Time 	RefTranspConvectionBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefTranspIdentity1D_Time 	RefTranspIdentityBil_t(basis_per.refinementbasis, basis_int.refinementbasis);
    RefTranspIdentity1D_Space 	RefTranspIdentityBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);
    RefTranspLaplace1D_Space 	RefTranspLaplaceBil_x(basis_intbc.refinementbasis, basis_intbc.refinementbasis);

    /// Initialization of local operator
    LOp_Conv1D_Time		lOp_Conv1D_t(basis_int, basis_per, RefConvectionBil_t, ConvectionBil_t);
    LOp_Id1D_Time		lOp_Id1D_t  (basis_int, basis_per, RefIdentityBil_t, IdentityBil_t);
    LOp_Id1D_Space		lOp_Id1D_x  (basis_intbc, basis_intbc, RefIdentityBil_x, IdentityBil_x);
    LOp_Lapl1D_Space	lOp_Lapl1D_x(basis_intbc, basis_intbc, RefLaplaceBil_x, LaplaceBil_x);
    
    LOpT_Conv1D_Time	lOpT_Conv1D_t(basis_per, basis_int, RefTranspConvectionBil_t, TranspConvectionBil_t);
    LOpT_Id1D_Time		lOpT_Id1D_t  (basis_per, basis_int, RefTranspIdentityBil_t, TranspIdentityBil_t);
    LOpT_Id1D_Space		lOpT_Id1D_x  (basis_intbc, basis_intbc, RefTranspIdentityBil_x, TranspIdentityBil_x);
    LOpT_Lapl1D_Space	lOpT_Lapl1D_x(basis_intbc, basis_intbc, RefTranspLaplaceBil_x, TranspLaplaceBil_x);

    LOp_Conv_Id_2D		localConvectionIdentityOp2D(lOp_Conv1D_t, lOp_Id1D_x);
    LOp_Id_Lapl_2D		localIdentityLaplaceOp2D(lOp_Id1D_t, lOp_Lapl1D_x);
    
    LOpT_Conv_Id_2D		transpLocalConvectionIdentityOp2D(lOpT_Conv1D_t, lOpT_Id1D_x);
    LOpT_Id_Lapl_2D		transpLocalIdentityLaplaceOp2D(lOpT_Id1D_t, lOpT_Lapl1D_x);

    localConvectionIdentityOp2D.setJ(9);
    localIdentityLaplaceOp2D.setJ(9);
    transpLocalConvectionIdentityOp2D.setJ(9);
    transpLocalIdentityLaplaceOp2D.setJ(9);

    // Use CompoundLocalOperator2D
    COp_Heat            localOperator2D(localConvectionIdentityOp2D,localIdentityLaplaceOp2D);
    COpT_Heat           transpLocalOperator2D(transpLocalConvectionIdentityOp2D,transpLocalIdentityLaplaceOp2D);

    // Use FlexibleCompoundLocalOperator2D
//    vector<AbstractLocalOperator2D<T>* > localOperatorVec, transpLocalOperatorVec;
//    localOperatorVec.push_back(&localConvectionIdentityOp2D);
//    localOperatorVec.push_back(&localIdentityLaplaceOp2D);
//    transpLocalOperatorVec.push_back(&transpLocalConvectionIdentityOp2D);
//    transpLocalOperatorVec.push_back(&transpLocalIdentityLaplaceOp2D);
//    FlexibleCompoundLocalOperator2D       localOperator2D(localOperatorVec);
//    FlexibleCompoundLocalOperator2D  	    transpLocalOperator2D(transpLocalOperatorVec);

    /// Initialization of preconditioner
    LeftPrec2D leftPrec(basis2d_test);
    RightPrec2D rightPrec(basis2d_trial);

    NoPrec2D noPrec;

    /// Initialization of rhs

    /// Right Hand Side:
    ///     No Singular Supports in both dimensions
    DenseVectorT sing_support_x;
    DenseVectorT sing_support_t(n+1);
    for(size_t i = 0; i <= n; ++i){
    	sing_support_t(i+1) = i*l;
    }
    ///      Forcing Functions
    SeparableFunction2D<T> F_fct(f_t, sing_support_t, f_x, sing_support_x);
    ///     Peaks: points and corresponding coefficients
    ///             (heights of jumps in derivatives)
    FullColMatrixT nodeltas;
    SeparableRhsIntegral2D			rhs(basis2d_test, F_fct, nodeltas, nodeltas, 20);
    SeparableRhs           			F(rhs,noPrec);

	//===============================================================//
	//===============  AWGM =========================================//
	//===============================================================//


    /* AWGM PG Parameters Default Values
    double tol = 5e-03;
	double alpha = 0.7;
	size_t max_its = 100;
	size_t max_basissize = 400000;
	bool reset_res = false;
	bool print_info = true;
	bool verbose = true;
	bool plot_solution = false;
	bool verbose_extra = false; //(print added wavelet indizes)
	size_t hashmapsize_trial = 10;
	size_t hashmapsize_test = 10;
	std::string info_filename = "awgm_cgls_conv_info.txt";
	std::string plot_filename = "awgm_cgls_u_plot";
	bool write_intermediary_solutions = false;
    std::string intermediary_solutions_filename = "awgm_cgls_u";
	*/

    /* IS Parameters Default Values
	bool adaptive_tol = true;
	size_t max_its = 100;
	double init_tol = 0.001;
	double res_reduction = 0.01;
	double absolute_tol = 1e-8;
	bool verbose = true;
	*/

    // MultitreeAWGM with default values
    //MT_AWGM multitree_awgm(basis2d_trial, basis2d_test, localOperator2D, transLocalOperator2D,
    //    						F, rightPrec, leftPrec);


    // If you want other parameters
    AWGM_PG_Parameters awgm_parameters;
    IS_Parameters cgls_parameters;
    // .... set them here:
    awgm_parameters.max_its = 0;
    awgm_parameters.tol = 1e-04;
    awgm_parameters.plot_solution = false;
    awgm_parameters.verbose_extra = false;
    awgm_parameters.info_filename = "awgm_ExSaw_SG_mv_conv_info.txt";
    awgm_parameters.plot_filename = "awgm_ExSaw_SG_mv_u_plot";
    awgm_parameters.write_intermediary_solutions = true;
    awgm_parameters.max_basissize = 1000000;

    cgls_parameters.adaptive_tol = true;
    cgls_parameters.init_tol = 1e-4;
    cgls_parameters.res_reduction = 0.01;
    cgls_parameters.max_its = 700;

    MT_AWGM multitree_awgm(basis2d_trial, basis2d_test, localOperator2D, transpLocalOperator2D,
    						F, rightPrec, leftPrec, awgm_parameters, cgls_parameters);


    multitree_awgm.awgm_params.print();
    multitree_awgm.is_params.print();

    multitree_awgm.set_sol(dummy);

    for(size_t J = 2; J < Jmax; ++J){

        stringstream filename;
        filename << "awgm_ExSaw_SG_mv_u_J_" << J;
        multitree_awgm.awgm_params.intermediary_solutions_filename = filename.str();

        /// Initialization of solution vector and initial index sets
        Coefficients<Lexicographical,T,Index2D> u;

        T gamma = 0.2;
        IndexSet<Index2D> LambdaTrial, LambdaTest;
        getSparseGridIndexSet(basis2d_trial,LambdaTrial,J,0,gamma);
        getSparseGridIndexSet(basis2d_test ,LambdaTest ,J,1,gamma);

        Timer time;
        time.start();
        multitree_awgm.solve(u, LambdaTrial, LambdaTest);
        time.stop();
        cout << "Solution took " << time.elapsed() << " seconds" << endl;
    }


    return 0;
}
Exemple #3
0
int main () {

	//===============================================================//
	//========= PROBLEM SETUP  =======================//
	//===============================================================//

    int d   = 4;
    int j0  = 2;
    cout << "Wavelets: d = " << d <<  ", j0 = " << j0 << endl << endl; 


    /// Basis initialization
    _Basis     basis(d, j0);
    Basis2D    basis2d(basis, basis);


/*
    for (int i = 1; i<= 6; ++i) {
        DataType        u;

        std::string     snapshot;
        std::string     plot;
        snapshot = "training_data_toy/snap/snap_";
        plot     = "plot_";
        snapshot += std::to_string(i);
        plot     += std::to_string(i);
        snapshot += ".txt";

        std::cout << "Reading snapshot from file " << snapshot << std::endl;
        std::cout << "Printing plot to file " << plot << std::endl;
        readCoeffVector2D(u, snapshot.c_str());
        precon _p;
        plot2D(basis2d, u, _p,
                                 zero,
                                 0., 1.,
                                 0., 1.,
                                 1e-02,
                                 plot.c_str());
    }
    exit(0);
*/


    /// Initialization of operators
    DenseVectorT no_singPts;
    Function<T> zero_Fct(zero_fct,no_singPts);

    // Bilinear Forms
    Identity1D 		    IdentityBil(basis);
    Laplace1D 	        LaplaceBil(basis);

    RefIdentity1D 		    RefIdentityBil(basis.refinementbasis);
    RefLaplace1D 	        RefLaplaceBil(basis.refinementbasis);

    /// Initialization of local operator
    LOp_Id1D              lOp_Id1D      (basis, basis, RefIdentityBil, IdentityBil);
    LOp_Lapl1D            lOp_Lapl1D    (basis, basis, RefLaplaceBil,  LaplaceBil);

    LOp_Id_Id_2D			localIdentityIdentityOp2D		(lOp_Id1D, 		lOp_Id1D);
    LOp_Id_Lapl_2D			localIdentityLaplaceOp2D		(lOp_Id1D, 		lOp_Lapl1D);
    LOp_Lapl_Id_2D			localLaplaceIdentityOp2D		(lOp_Lapl1D, 		lOp_Id1D);

    localIdentityIdentityOp2D.setJ(9);
    localIdentityLaplaceOp2D.setJ(9);
    localLaplaceIdentityOp2D.setJ(9);

    /// Initialization of preconditioner
    Prec2D prec(basis2d);
    NoPrec2D noPrec;

    /// Initialization of rhs

    /// Right Hand Side:
    ///     No Singular Supports in both dimensions
    DenseVectorT sing_support;
    ///      Forcing Functions
    Function2D<T> F1_Fct(f1, sing_support, sing_support);
    Function2D<T> F2_Fct(f2, sing_support, sing_support);
    Function2D<T> F3_Fct(f3, sing_support, sing_support);
    Function2D<T> F4_Fct(f4, sing_support, sing_support);
    Function2D<T> F5_Fct(f5, sing_support, sing_support);
    Function2D<T> F6_Fct(f6, sing_support, sing_support);
    Function2D<T> F7_Fct(f7, sing_support, sing_support);
    Function2D<T> F8_Fct(f8, sing_support, sing_support);
    Function2D<T> F9_Fct(f9, sing_support, sing_support);
    Function2D<T> F10_Fct(f10, sing_support, sing_support);
    Function2D<T> F11_Fct(f11, sing_support, sing_support);
    Function2D<T> F12_Fct(f12, sing_support, sing_support);
    Function2D<T> F13_Fct(f13, sing_support, sing_support);
    Function2D<T> F14_Fct(f14, sing_support, sing_support);
    Function2D<T> F15_Fct(f15, sing_support, sing_support);
    Function2D<T> F16_Fct(f16, sing_support, sing_support);
    Function2D<T> F17_Fct(f17, sing_support, sing_support);
    Function2D<T> F18_Fct(f18, sing_support, sing_support);
    Function2D<T> F19_Fct(f19, sing_support, sing_support);
    Function2D<T> F20_Fct(f20, sing_support, sing_support);
    Function2D<T> F21_Fct(f21, sing_support, sing_support);
    Function2D<T> F22_Fct(f22, sing_support, sing_support);
    Function2D<T> F23_Fct(f23, sing_support, sing_support);
    Function2D<T> F24_Fct(f24, sing_support, sing_support);
    Function2D<T> F25_Fct(f25, sing_support, sing_support);
    Function2D<T> F26_Fct(f26, sing_support, sing_support);
    Function2D<T> F27_Fct(f27, sing_support, sing_support);
    Function2D<T> F28_Fct(f28, sing_support, sing_support);
    Function2D<T> F29_Fct(f29, sing_support, sing_support);
    Function2D<T> F30_Fct(f30, sing_support, sing_support);
    Function2D<T> F31_Fct(f31, sing_support, sing_support);
    Function2D<T> F32_Fct(f32, sing_support, sing_support);
    Function2D<T> F33_Fct(f33, sing_support, sing_support);
    Function2D<T> F34_Fct(f34, sing_support, sing_support);
    Function2D<T> F35_Fct(f35, sing_support, sing_support);
    Function2D<T> F36_Fct(f36, sing_support, sing_support);
    Function2D<T> F37_Fct(f37, sing_support, sing_support);
    Function2D<T> F38_Fct(f38, sing_support, sing_support);
    Function2D<T> F39_Fct(f39, sing_support, sing_support);
    Function2D<T> F40_Fct(f40, sing_support, sing_support);
    Function2D<T> F41_Fct(f41, sing_support, sing_support);
    Function2D<T> F42_Fct(f42, sing_support, sing_support);
    Function2D<T> F43_Fct(f43, sing_support, sing_support);
    Function2D<T> F44_Fct(f44, sing_support, sing_support);
    Function2D<T> F45_Fct(f45, sing_support, sing_support);
    Function2D<T> F46_Fct(f46, sing_support, sing_support);
    Function2D<T> F47_Fct(f47, sing_support, sing_support);
    Function2D<T> F48_Fct(f48, sing_support, sing_support);
    Function2D<T> F49_Fct(f49, sing_support, sing_support);

    RhsIntegral2D			rhs_1(basis2d, F1_Fct,  100);
    RhsIntegral2D			rhs_2(basis2d, F2_Fct,  100);
    RhsIntegral2D			rhs_3(basis2d, F3_Fct,  100);
    RhsIntegral2D			rhs_4(basis2d, F4_Fct,  100);
    RhsIntegral2D			rhs_5(basis2d, F5_Fct,  100);
    RhsIntegral2D			rhs_6(basis2d, F6_Fct,  100);
    RhsIntegral2D			rhs_7(basis2d, F7_Fct,  100);
    RhsIntegral2D			rhs_8(basis2d, F8_Fct,  100);
    RhsIntegral2D			rhs_9(basis2d, F9_Fct,  100);
    RhsIntegral2D			rhs_10(basis2d, F10_Fct,  100);
    RhsIntegral2D			rhs_11(basis2d, F11_Fct,  100);
    RhsIntegral2D			rhs_12(basis2d, F12_Fct,  100);
    RhsIntegral2D			rhs_13(basis2d, F13_Fct,  100);
    RhsIntegral2D			rhs_14(basis2d, F14_Fct,  100);
    RhsIntegral2D			rhs_15(basis2d, F15_Fct,  100);
    RhsIntegral2D			rhs_16(basis2d, F16_Fct,  100);
    RhsIntegral2D			rhs_17(basis2d, F17_Fct,  100);
    RhsIntegral2D			rhs_18(basis2d, F18_Fct,  100);
    RhsIntegral2D			rhs_19(basis2d, F19_Fct,  100);
    RhsIntegral2D			rhs_20(basis2d, F20_Fct,  100);
    RhsIntegral2D			rhs_21(basis2d, F21_Fct,  100);
    RhsIntegral2D			rhs_22(basis2d, F22_Fct,  100);
    RhsIntegral2D			rhs_23(basis2d, F23_Fct,  100);
    RhsIntegral2D			rhs_24(basis2d, F24_Fct,  100);
    RhsIntegral2D			rhs_25(basis2d, F25_Fct,  100);
    RhsIntegral2D			rhs_26(basis2d, F26_Fct,  100);
    RhsIntegral2D			rhs_27(basis2d, F27_Fct,  100);
    RhsIntegral2D			rhs_28(basis2d, F28_Fct,  100);
    RhsIntegral2D			rhs_29(basis2d, F29_Fct,  100);
    RhsIntegral2D			rhs_30(basis2d, F30_Fct,  100);
    RhsIntegral2D			rhs_31(basis2d, F31_Fct,  100);
    RhsIntegral2D			rhs_32(basis2d, F32_Fct,  100);
    RhsIntegral2D			rhs_33(basis2d, F33_Fct,  100);
    RhsIntegral2D			rhs_34(basis2d, F34_Fct,  100);
    RhsIntegral2D			rhs_35(basis2d, F35_Fct,  100);
    RhsIntegral2D			rhs_36(basis2d, F36_Fct,  100);
    RhsIntegral2D			rhs_37(basis2d, F37_Fct,  100);
    RhsIntegral2D			rhs_38(basis2d, F38_Fct,  100);
    RhsIntegral2D			rhs_39(basis2d, F39_Fct,  100);
    RhsIntegral2D			rhs_40(basis2d, F40_Fct,  100);
    RhsIntegral2D			rhs_41(basis2d, F41_Fct,  100);
    RhsIntegral2D			rhs_42(basis2d, F42_Fct,  100);
    RhsIntegral2D			rhs_43(basis2d, F43_Fct,  100);
    RhsIntegral2D			rhs_44(basis2d, F44_Fct,  100);
    RhsIntegral2D			rhs_45(basis2d, F45_Fct,  100);
    RhsIntegral2D			rhs_46(basis2d, F46_Fct,  100);
    RhsIntegral2D			rhs_47(basis2d, F47_Fct,  100);
    RhsIntegral2D			rhs_48(basis2d, F48_Fct,  100);
    RhsIntegral2D			rhs_49(basis2d, F49_Fct,  100);
    Rhs           			F1(rhs_1,noPrec);
    Rhs           			F2(rhs_2,noPrec);
    Rhs           			F3(rhs_3,noPrec);
    Rhs           			F4(rhs_4,noPrec);
    Rhs           			F5(rhs_5,noPrec);
    Rhs           			F6(rhs_6,noPrec);
    Rhs           			F7(rhs_7,noPrec);
    Rhs           			F8(rhs_8,noPrec);
    Rhs           			F9(rhs_9,noPrec);
    Rhs           			F10(rhs_10,noPrec);
    Rhs           			F11(rhs_11,noPrec);
    Rhs           			F12(rhs_12,noPrec);
    Rhs           			F13(rhs_13,noPrec);
    Rhs           			F14(rhs_14,noPrec);
    Rhs           			F15(rhs_15,noPrec);
    Rhs           			F16(rhs_16,noPrec);
    Rhs           			F17(rhs_17,noPrec);
    Rhs           			F18(rhs_18,noPrec);
    Rhs           			F19(rhs_19,noPrec);
    Rhs           			F20(rhs_20,noPrec);
    Rhs           			F21(rhs_21,noPrec);
    Rhs           			F22(rhs_22,noPrec);
    Rhs           			F23(rhs_23,noPrec);
    Rhs           			F24(rhs_24,noPrec);
    Rhs           			F25(rhs_25,noPrec);
    Rhs           			F26(rhs_26,noPrec);
    Rhs           			F27(rhs_27,noPrec);
    Rhs           			F28(rhs_28,noPrec);
    Rhs           			F29(rhs_29,noPrec);
    Rhs           			F30(rhs_30,noPrec);
    Rhs           			F31(rhs_31,noPrec);
    Rhs           			F32(rhs_32,noPrec);
    Rhs           			F33(rhs_33,noPrec);
    Rhs           			F34(rhs_34,noPrec);
    Rhs           			F35(rhs_35,noPrec);
    Rhs           			F36(rhs_36,noPrec);
    Rhs           			F37(rhs_37,noPrec);
    Rhs           			F38(rhs_38,noPrec);
    Rhs           			F39(rhs_39,noPrec);
    Rhs           			F40(rhs_40,noPrec);
    Rhs           			F41(rhs_41,noPrec);
    Rhs           			F42(rhs_42,noPrec);
    Rhs           			F43(rhs_43,noPrec);
    Rhs           			F44(rhs_44,noPrec);
    Rhs           			F45(rhs_45,noPrec);
    Rhs           			F46(rhs_46,noPrec);
    Rhs           			F47(rhs_47,noPrec);
    Rhs           			F48(rhs_48,noPrec);
    Rhs           			F49(rhs_49,noPrec);

	//===============================================================//
	//===============  RB SETUP =====================================//
	//===============================================================//

    // Affine Decompositions:
    // 	Left Hand Side
    vector<ThetaStructure<ParamType>::ThetaFct>	lhs_theta_fcts;
    lhs_theta_fcts.push_back(no_theta);
    ThetaStructure<ParamType> lhs_theta(lhs_theta_fcts);

    vector<AbstractLocalOperator2D<T>* > lhs_ops;
    lhs_ops.push_back(&localLaplaceIdentityOp2D);
    lhs_ops.push_back(&localIdentityLaplaceOp2D);
    Flex_COp_2D                       A(lhs_ops);
    vector<Flex_COp_2D*>                 ops_vec;
    ops_vec.push_back(&A);

    Affine_Op_2D affine_lhs(lhs_theta, ops_vec);

    H1_InnProd_2D innprod(localIdentityIdentityOp2D, localLaplaceIdentityOp2D, localIdentityLaplaceOp2D);

    // Right Hand Side
    vector<ThetaStructure<ParamType>::ThetaFct> rhs_theta_fcts;
    rhs_theta_fcts.push_back(theta_chi_1);
    rhs_theta_fcts.push_back(theta_chi_2);
    rhs_theta_fcts.push_back(theta_chi_3);
    rhs_theta_fcts.push_back(theta_chi_4);
    rhs_theta_fcts.push_back(theta_chi_5);
    rhs_theta_fcts.push_back(theta_chi_6);
    rhs_theta_fcts.push_back(theta_chi_7);
    rhs_theta_fcts.push_back(theta_chi_8);
    rhs_theta_fcts.push_back(theta_chi_9);
    rhs_theta_fcts.push_back(theta_chi_10);
    rhs_theta_fcts.push_back(theta_chi_11);
    rhs_theta_fcts.push_back(theta_chi_12);
    rhs_theta_fcts.push_back(theta_chi_13);
    rhs_theta_fcts.push_back(theta_chi_14);
    rhs_theta_fcts.push_back(theta_chi_15);
    rhs_theta_fcts.push_back(theta_chi_16);
    rhs_theta_fcts.push_back(theta_chi_17);
    rhs_theta_fcts.push_back(theta_chi_18);
    rhs_theta_fcts.push_back(theta_chi_19);
    rhs_theta_fcts.push_back(theta_chi_20);
    rhs_theta_fcts.push_back(theta_chi_21);
    rhs_theta_fcts.push_back(theta_chi_22);
    rhs_theta_fcts.push_back(theta_chi_23);
    rhs_theta_fcts.push_back(theta_chi_24);
    rhs_theta_fcts.push_back(theta_chi_25);
    rhs_theta_fcts.push_back(theta_chi_26);
    rhs_theta_fcts.push_back(theta_chi_27);
    rhs_theta_fcts.push_back(theta_chi_28);
    rhs_theta_fcts.push_back(theta_chi_29);
    rhs_theta_fcts.push_back(theta_chi_30);
    rhs_theta_fcts.push_back(theta_chi_31);
    rhs_theta_fcts.push_back(theta_chi_32);
    rhs_theta_fcts.push_back(theta_chi_33);
    rhs_theta_fcts.push_back(theta_chi_34);
    rhs_theta_fcts.push_back(theta_chi_35);
    rhs_theta_fcts.push_back(theta_chi_36);
    rhs_theta_fcts.push_back(theta_chi_37);
    rhs_theta_fcts.push_back(theta_chi_38);
    rhs_theta_fcts.push_back(theta_chi_39);
    rhs_theta_fcts.push_back(theta_chi_40);
    rhs_theta_fcts.push_back(theta_chi_41);
    rhs_theta_fcts.push_back(theta_chi_42);
    rhs_theta_fcts.push_back(theta_chi_43);
    rhs_theta_fcts.push_back(theta_chi_44);
    rhs_theta_fcts.push_back(theta_chi_45);
    rhs_theta_fcts.push_back(theta_chi_46);
    rhs_theta_fcts.push_back(theta_chi_47);
    rhs_theta_fcts.push_back(theta_chi_48);
    rhs_theta_fcts.push_back(theta_chi_49);
    ThetaStructure<ParamType> rhs_theta(rhs_theta_fcts);
    vector<Rhs*> rhs_fcts;
    rhs_fcts.push_back(&F1);
    rhs_fcts.push_back(&F2);
    rhs_fcts.push_back(&F3);
    rhs_fcts.push_back(&F4);
    rhs_fcts.push_back(&F5);
    rhs_fcts.push_back(&F6);
    rhs_fcts.push_back(&F7);
    rhs_fcts.push_back(&F8);
    rhs_fcts.push_back(&F9);
    rhs_fcts.push_back(&F10);
    rhs_fcts.push_back(&F11);
    rhs_fcts.push_back(&F12);
    rhs_fcts.push_back(&F13);
    rhs_fcts.push_back(&F14);
    rhs_fcts.push_back(&F15);
    rhs_fcts.push_back(&F16);
    rhs_fcts.push_back(&F17);
    rhs_fcts.push_back(&F18);
    rhs_fcts.push_back(&F19);
    rhs_fcts.push_back(&F20);
    rhs_fcts.push_back(&F21);
    rhs_fcts.push_back(&F22);
    rhs_fcts.push_back(&F23);
    rhs_fcts.push_back(&F24);
    rhs_fcts.push_back(&F25);
    rhs_fcts.push_back(&F26);
    rhs_fcts.push_back(&F27);
    rhs_fcts.push_back(&F28);
    rhs_fcts.push_back(&F29);
    rhs_fcts.push_back(&F30);
    rhs_fcts.push_back(&F31);
    rhs_fcts.push_back(&F32);
    rhs_fcts.push_back(&F33);
    rhs_fcts.push_back(&F34);
    rhs_fcts.push_back(&F35);
    rhs_fcts.push_back(&F36);
    rhs_fcts.push_back(&F37);
    rhs_fcts.push_back(&F38);
    rhs_fcts.push_back(&F39);
    rhs_fcts.push_back(&F40);
    rhs_fcts.push_back(&F41);
    rhs_fcts.push_back(&F42);
    rhs_fcts.push_back(&F43);
    rhs_fcts.push_back(&F44);
    rhs_fcts.push_back(&F45);
    rhs_fcts.push_back(&F46);
    rhs_fcts.push_back(&F47);
    rhs_fcts.push_back(&F48);
    rhs_fcts.push_back(&F49);

    Affine_Rhs_2D affine_rhs(rhs_theta, rhs_fcts);
    RieszF_Rhs_2D rieszF_rhs(rhs_fcts);
    RieszA_Rhs_2D rieszA_rhs(ops_vec);

    // Right Hand Sides for direct Riesz Representor
    AffineA_Rhs_2D	 	affineA_rhs(lhs_theta, lhs_ops);
    RieszRes_Rhs_2D		rieszRes_rhs(affineA_rhs, affine_rhs);

	//===============================================================//
	//===============  AWGM =========================================//
	//===============================================================//

    IS_Parameters is_parameters;
    AWGM_Parameters awgm_truth_parameters, awgm_riesz_f_parameters, awgm_riesz_a_parameters, awgm_riesz_res_parameters;
    awgm_truth_parameters.max_its = 1e+03;

    is_parameters.adaptive_tol = true;
    is_parameters.init_tol = 0.0001;
    is_parameters.res_reduction = 0.01;

    //----------- Solver ---------------- //

    T gamma = 0.2;
    IndexSet<Index2D> Lambda;
    getSparseGridIndexSet(basis2d, Lambda, 1, 0, gamma);

    MT_AWGM_Truth awgm_u(basis2d, affine_lhs, affine_rhs, prec, awgm_truth_parameters, is_parameters);
    awgm_u.set_sol(dummy);
    awgm_u.awgm_params.tol = 1e-04;
    awgm_u.awgm_params.max_basissize = 1e+06;
    awgm_u.set_initial_indexset(Lambda);

    MT_AWGM_Riesz_F awgm_rieszF(basis2d, innprod, rieszF_rhs, prec, awgm_riesz_f_parameters, is_parameters);
    awgm_rieszF.set_sol(dummy);
    awgm_rieszF.set_initial_indexset(Lambda);
    awgm_rieszF.awgm_params.tol = 5e-04;
    awgm_rieszF.awgm_params.info_filename = "stempel_rieszF_conv_info.txt";

    MT_AWGM_Riesz_A awgm_rieszA(basis2d, innprod, rieszA_rhs, prec, awgm_riesz_a_parameters, is_parameters);
    awgm_rieszA.set_sol(dummy);
    awgm_rieszA.set_initial_indexset(Lambda);
    awgm_rieszA.awgm_params.tol = 5e-04;
    awgm_rieszA.awgm_params.info_filename = "stempel_rieszA_conv_info.txt";

    MT_AWGM_Riesz_Res awgm_rieszRes(basis2d, innprod, rieszRes_rhs, prec, awgm_riesz_res_parameters, is_parameters);
    awgm_rieszRes.set_sol(dummy);
    awgm_rieszRes.set_initial_indexset(Lambda);
    awgm_rieszRes.awgm_params.tol = 5e-04;
    awgm_rieszRes.awgm_params.print_info = false;

    MTTruthSolver rb_truth(awgm_u, awgm_rieszF, awgm_rieszA, &awgm_rieszRes, innprod, affine_lhs, rieszF_rhs);

    //----------- RB System ---------------- //

    RB_Model rb_system(lhs_theta, rhs_theta);

    rb_system.rb_params.ref_param = {{1.}};
    rb_system.rb_params.call = call_cg;

    //----------- RB Base ---------------- //

    RB_BaseModel rb_base(rb_system, rb_truth, Lambda);

    ParamType mu_min = {{0}};
    ParamType mu_max = {{1}};

    rb_base.greedy_params.training_type = weak;
    rb_base.greedy_params.tol = 1e-05;
    rb_base.greedy_params.min_param = mu_min;
    rb_base.greedy_params.max_param = mu_max;
    rb_base.greedy_params.Nmax =    6;
    rb_base.greedy_params.nb_training_params = {{nb_stempel}};
    rb_base.greedy_params.log_scaling = {{0}};
    rb_base.greedy_params.print_file = "toy_greedy_info.txt";
    rb_base.greedy_params.trainingdata_folder = "training_data_toy";
    rb_base.greedy_params.print_paramset = true;
    rb_base.greedy_params.erase_snapshot_params = false;
    rb_base.greedy_params.orthonormalize_bfs = true;
    rb_base.greedy_params.tighten_tol = true;
    rb_base.greedy_params.snapshot_tol_red_crit = repeated_param;
    rb_base.greedy_params.tighten_tol_rieszA = false;
    rb_base.greedy_params.tighten_tol_rieszF = false;
    rb_base.greedy_params.tighten_tol_reduction = 0.1,
    rb_base.greedy_params.update_snapshot = true;
    rb_base.greedy_params.update_rieszF = false;
    rb_base.greedy_params.update_rieszA = false;
    rb_base.greedy_params.test_estimator_equivalence = false;
    rb_base.greedy_params.write_direct_representors = false;
    rb_base.greedy_params.riesz_constant_X = 5.6;
    rb_base.greedy_params.riesz_constant_Y = 2;

    cout << "Parameters Training: " << std::endl << std::endl;
    rb_base.greedy_params.print();
    rb_system.rb_params.print();

    cout << "Parameters Truth Solver: " << std::endl << std::endl;
    awgm_u.awgm_params.print();

    awgm_u.is_params.print();

    cout << "Parameters Riesz Solver F : " << std::endl << std::endl;
    awgm_rieszF.awgm_params.print();

    cout << "Parameters Riesz Solver A : " << std::endl << std::endl;
    awgm_rieszA.awgm_params.print();

    cout << "Parameters Riesz Solver Res : " << std::endl << std::endl;
    awgm_rieszRes.awgm_params.print();

    //rb_system.read_rb_data("training_data_toy");
    //rb_base.read_basisfunctions("training_data_toy/bf");
    /*for (int i=0; i<rb_base.n_bf(); ++i) {
        std::cout << " i = " << i+1 << std::endl;
        std::cout << rb_base.rb_basisfunctions[i].size() << std::endl;
    }*/
    //rb_base.read_rieszrepresentors("training_data_toy/representors");
    //rb_base.calculate_Riesz_RHS_information(true);
    //rb_base.calc_rb_data();
    //rb_system.write_rb_data("training_data_toy");
    rb_base.train_Greedy();

    std::cout << "toy_offline exited normally\n";
    return 0;
}