SundanceL2Projector.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
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   /* Create an Aztec solver for solving the linear subproblems */
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   /* Create an Aztec solver for solving the linear subproblems */
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   /* Create an Aztec solver for solving the linear subproblems */
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 

Site Contact