SundanceL2Projector.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
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   /* Create an Aztec solver for solving the linear subproblems */
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   /* Create an Aztec solver for solving the linear subproblems */
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 

Site Contact