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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceL2Projector.hpp"
00043 #include "PlayaAztecSolver.hpp"
00044 #include "SundanceOut.hpp"
00045 #include "PlayaTabs.hpp"
00046
00047 #include "SundanceDerivative.hpp"
00048 #include "SundanceTestFunction.hpp"
00049 #include "SundanceUnknownFunction.hpp"
00050 #include "SundanceEssentialBC.hpp"
00051 #include "SundanceIntegral.hpp"
00052 #include "SundanceGaussianQuadrature.hpp"
00053
00054 #include "SundanceCellFilter.hpp"
00055 #include "SundanceMaximalCellFilter.hpp"
00056
00057 using namespace Sundance;
00058 using namespace Teuchos;
00059 using namespace Playa;
00060
00061
00062 L2Projector::L2Projector(const DiscreteSpace& space,
00063 const Expr& expr,
00064 const LinearSolver<double>& solver)
00065 : prob_(), solver_()
00066 {
00067 CoordinateSystem cs = new CartesianCoordinateSystem();
00068 init(space, cs, expr, solver, new GaussianQuadrature(4));
00069 }
00070
00071
00072 L2Projector::L2Projector(const DiscreteSpace& space,
00073 const CoordinateSystem& cs,
00074 const Expr& expr,
00075 const LinearSolver<double>& solver)
00076 : prob_(), solver_()
00077 {
00078 init(space, cs, expr, solver, new GaussianQuadrature(4));
00079 }
00080
00081
00082 L2Projector::L2Projector(const DiscreteSpace& space,
00083 const Expr& expr,
00084 const LinearSolver<double>& solver,
00085 const QuadratureFamily& quad)
00086 : prob_(), solver_()
00087 {
00088 CoordinateSystem cs = new CartesianCoordinateSystem();
00089 init(space, cs, expr, solver, quad);
00090 }
00091
00092 L2Projector::L2Projector(const DiscreteSpace& space,
00093 const Expr& expr)
00094 : prob_(), solver_()
00095 {
00096 CoordinateSystem cs = new CartesianCoordinateSystem();
00097
00098
00099 std::map<int,int> azOptions;
00100 std::map<int,double> azParams;
00101
00102 azOptions[AZ_solver] = AZ_cg;
00103 azOptions[AZ_precond] = AZ_dom_decomp;
00104 azOptions[AZ_subdomain_solve] = AZ_icc;
00105 azOptions[AZ_graph_fill] = 1;
00106 azOptions[AZ_max_iter] = 1000;
00107 azOptions[AZ_output] = AZ_none;
00108 azParams[AZ_tol] = 1.0e-13;
00109
00110 LinearSolver<double> solver = new AztecSolver(azOptions,azParams);
00111
00112 init(space, cs, expr, solver, new GaussianQuadrature(4));
00113 }
00114
00115 L2Projector::L2Projector(const DiscreteSpace& space,
00116 const Expr& expr,
00117 const QuadratureFamily& quad)
00118 : prob_(), solver_()
00119 {
00120 CoordinateSystem cs = new CartesianCoordinateSystem();
00121
00122
00123 std::map<int,int> azOptions;
00124 std::map<int,double> azParams;
00125
00126 azOptions[AZ_solver] = AZ_cg;
00127 azOptions[AZ_precond] = AZ_dom_decomp;
00128 azOptions[AZ_subdomain_solve] = AZ_icc;
00129 azOptions[AZ_graph_fill] = 1;
00130 azOptions[AZ_max_iter] = 1000;
00131 azOptions[AZ_output] = AZ_none;
00132 azParams[AZ_tol] = 1.0e-13;
00133
00134 LinearSolver<double> solver = new AztecSolver(azOptions,azParams);
00135
00136 init(space, cs, expr, solver, quad);
00137 }
00138
00139
00140 L2Projector::L2Projector(const DiscreteSpace& space,
00141 const CoordinateSystem& cs,
00142 const Expr& expr)
00143 : prob_(), solver_()
00144 {
00145
00146 std::map<int,int> azOptions;
00147 std::map<int,double> azParams;
00148
00149 azOptions[AZ_solver] = AZ_cg;
00150 azOptions[AZ_precond] = AZ_dom_decomp;
00151 azOptions[AZ_subdomain_solve] = AZ_icc;
00152 azOptions[AZ_graph_fill] = 1;
00153 azOptions[AZ_max_iter] = 1000;
00154 azOptions[AZ_output] = AZ_none;
00155 azParams[AZ_tol] = 1.0e-13;
00156
00157 LinearSolver<double> solver = new AztecSolver(azOptions,azParams);
00158
00159 init(space, cs, expr, solver, new GaussianQuadrature(4));
00160 }
00161
00162
00163
00164
00165 void L2Projector::init(const DiscreteSpace& space,
00166 const CoordinateSystem& coordSys,
00167 const Expr& expr,
00168 const LinearSolver<double>& solver,
00169 const QuadratureFamily& quad)
00170 {
00171 TEUCHOS_TEST_FOR_EXCEPTION(space.basis().size() != expr.size(),
00172 std::runtime_error,
00173 "mismatched vector structure between basis and expr");
00174
00175 TEUCHOS_TEST_FOR_EXCEPTION(space.basis().size() == 0,
00176 std::runtime_error,
00177 "Empty basis?");
00178
00179 Expr v = new TestFunction(space.basis()[0], "dummy_v[0]");
00180 Expr u = new UnknownFunction(space.basis()[0], "dummy_u[0]");
00181
00182 for (int i=1; i<space.basis().size(); i++)
00183 {
00184 v.append(new TestFunction(space.basis()[i], "dummy_v["
00185 + Teuchos::toString(i)+"]"));
00186 u.append(new UnknownFunction(space.basis()[i], "dummy_u["
00187 + Teuchos::toString(i)+"]"));
00188 }
00189
00190 CellFilter interior = new MaximalCellFilter();
00191
00192 Expr eqn = 0.0;
00193 Expr J = coordSys.jacobian();
00194
00195 for (int i=0; i<space.basis().size(); i++)
00196 {
00197 eqn = eqn + Integral(space.cellFilters(i),
00198 J*v[i]*(u[i]-expr[i]),
00199 quad);
00200 }
00201 Expr bc;
00202
00203 prob_ = LinearProblem(space.mesh(), eqn, bc, v, u, space.vecType());
00204 solver_ = solver;
00205 }
00206
00207
00208