00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "SundanceL2Projector.hpp"
00032 #include "TSFAztecSolver.hpp"
00033 #include "SundanceOut.hpp"
00034 #include "SundanceTabs.hpp"
00035
00036 #include "SundanceDerivative.hpp"
00037 #include "SundanceTestFunction.hpp"
00038 #include "SundanceUnknownFunction.hpp"
00039 #include "SundanceEssentialBC.hpp"
00040 #include "SundanceIntegral.hpp"
00041 #include "SundanceGaussianQuadrature.hpp"
00042
00043 #include "SundanceCellFilter.hpp"
00044 #include "SundanceMaximalCellFilter.hpp"
00045
00046 using namespace Sundance;
00047 using namespace Sundance;
00048 using namespace Sundance;
00049 using namespace Sundance;
00050 using namespace Teuchos;
00051 using namespace TSFExtended;
00052 using namespace Thyra;
00053
00054
00055 L2Projector::L2Projector(const DiscreteSpace& space,
00056 const Expr& expr,
00057 const LinearSolver<double>& solver)
00058 : prob_(), solver_()
00059 {
00060 CoordinateSystem cs = new CartesianCoordinateSystem();
00061 init(space, cs, expr, solver);
00062 }
00063
00064
00065 L2Projector::L2Projector(const DiscreteSpace& space,
00066 const CoordinateSystem& cs,
00067 const Expr& expr,
00068 const LinearSolver<double>& solver)
00069 : prob_(), solver_()
00070 {
00071 init(space, cs, expr, solver);
00072 }
00073
00074 L2Projector::L2Projector(const DiscreteSpace& space,
00075 const Expr& expr)
00076 : prob_(), solver_()
00077 {
00078 CoordinateSystem cs = new CartesianCoordinateSystem();
00079
00080
00081 std::map<int,int> azOptions;
00082 std::map<int,double> azParams;
00083
00084 azOptions[AZ_solver] = AZ_cg;
00085 azOptions[AZ_precond] = AZ_dom_decomp;
00086 azOptions[AZ_subdomain_solve] = AZ_icc;
00087 azOptions[AZ_graph_fill] = 1;
00088 azOptions[AZ_max_iter] = 1000;
00089 azOptions[AZ_output] = AZ_none;
00090 azParams[AZ_tol] = 1.0e-13;
00091
00092 LinearSolver<double> solver = new AztecSolver(azOptions,azParams);
00093
00094 init(space, cs, expr, solver);
00095 }
00096
00097
00098 L2Projector::L2Projector(const DiscreteSpace& space,
00099 const CoordinateSystem& cs,
00100 const Expr& expr)
00101 : prob_(), solver_()
00102 {
00103
00104 std::map<int,int> azOptions;
00105 std::map<int,double> azParams;
00106
00107 azOptions[AZ_solver] = AZ_cg;
00108 azOptions[AZ_precond] = AZ_dom_decomp;
00109 azOptions[AZ_subdomain_solve] = AZ_icc;
00110 azOptions[AZ_graph_fill] = 1;
00111 azOptions[AZ_max_iter] = 1000;
00112 azOptions[AZ_output] = AZ_none;
00113 azParams[AZ_tol] = 1.0e-13;
00114
00115 LinearSolver<double> solver = new AztecSolver(azOptions,azParams);
00116
00117 init(space, cs, expr, solver);
00118 }
00119
00120
00121
00122
00123 void L2Projector::init(const DiscreteSpace& space,
00124 const CoordinateSystem& coordSys,
00125 const Expr& expr,
00126 const LinearSolver<double>& solver)
00127 {
00128 TEST_FOR_EXCEPTION(space.basis().size() != expr.size(),
00129 RuntimeError,
00130 "mismatched vector structure between basis and expr");
00131
00132 TEST_FOR_EXCEPTION(space.basis().size() == 0,
00133 RuntimeError,
00134 "Empty basis?");
00135
00136 Expr v = new TestFunction(space.basis()[0], "dummy_v[0]");
00137 Expr u = new UnknownFunction(space.basis()[0], "dummy_u[0]");
00138
00139 for (int i=1; i<space.basis().size(); i++)
00140 {
00141 v.append(new TestFunction(space.basis()[i], "dummy_v["
00142 + Teuchos::toString(i)+"]"));
00143 u.append(new UnknownFunction(space.basis()[i], "dummy_u["
00144 + Teuchos::toString(i)+"]"));
00145 }
00146
00147 CellFilter interior = new MaximalCellFilter();
00148
00149 Expr eqn = 0.0;
00150 Expr J = coordSys.jacobian();
00151
00152 for (int i=0; i<space.basis().size(); i++)
00153 {
00154 eqn = eqn + Integral(space.cellFilters(i),
00155 J*v[i]*(u[i]-expr[i]),
00156 new GaussianQuadrature(4));
00157 }
00158 Expr bc;
00159
00160 prob_ = LinearProblem(space.mesh(), eqn, bc, v, u, space.vecType());
00161 solver_ = solver;
00162 }
00163
00164
00165