SundanceFunctional.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 "SundanceFunctional.hpp"
00043 #include "SundanceOut.hpp"
00044 #include "PlayaTabs.hpp"
00045 #include "SundanceTestFunction.hpp"
00046 #include "SundanceUnknownFunction.hpp"
00047 #include "SundanceEssentialBC.hpp"
00048 #include "SundanceIntegral.hpp"
00049 #include "SundanceListExpr.hpp"
00050 #include "SundanceZeroExpr.hpp"
00051 #include "SundanceEquationSet.hpp"
00052 #include "SundanceAssembler.hpp"
00053 
00054 
00055 using namespace Sundance;
00056 using namespace Teuchos;
00057 using namespace Playa;
00058 
00059 
00060 Functional::Functional(const Mesh& mesh, const Expr& integral, 
00061   const Playa::VectorType<double>& vecType)
00062   : mesh_(mesh),
00063     integral_(integral),
00064     bc_(),
00065     vecType_(vecType)
00066 {
00067   
00068 }
00069 
00070 Functional::Functional(
00071   const Mesh& mesh, 
00072   const Expr& integral,  
00073   const Expr& essentialBC,
00074   const Playa::VectorType<double>& vecType)
00075   : mesh_(mesh),
00076     integral_(integral),
00077     bc_(essentialBC),
00078     vecType_(vecType)
00079 {
00080   
00081 }
00082 
00083 
00084 LinearProblem Functional::linearVariationalProb(
00085   const Expr& var,
00086   const Expr& varEvalPts,
00087   const Expr& unk,
00088   const Expr& fixed,
00089   const Expr& fixedEvalPts) const 
00090 {
00091 
00092   Array<Expr> zero(unk.size());
00093   for (int i=0; i<unk.size(); i++) 
00094     {
00095       Expr z = new ZeroExpr();
00096       zero[i] = z;
00097     }
00098 
00099   Expr unkEvalPts = new ListExpr(zero);
00100 
00101   Expr unkParams;
00102   Expr fixedParams;
00103   Expr unkParamValues;
00104   Expr fixedParamValues;
00105 
00106   RCP<EquationSet> eqn 
00107     = rcp(new EquationSet(integral_, bc_, 
00108                           tuple(var), tuple(varEvalPts),
00109                           tuple(unk), tuple(unkEvalPts), 
00110                           unkParams, unkParamValues,
00111                           tuple(fixed), tuple(fixedEvalPts)));
00112 
00113   RCP<Assembler> assembler 
00114     = rcp(new Assembler(mesh_, eqn, tuple(vecType_), tuple(vecType_), false));
00115 
00116   return LinearProblem(assembler);
00117 }
00118 
00119 NonlinearProblem Functional
00120 ::nonlinearVariationalProb(const Expr& var,
00121                            const Expr& varEvalPts,
00122                            const Expr& unk,
00123                            const Expr& unkEvalPts,
00124                            const Expr& fixed,
00125                            const Expr& fixedEvalPts) const
00126 {
00127 
00128   Expr unkParams;
00129   Expr fixedParams;
00130   Expr unkParamValues;
00131   Expr fixedParamValues;
00132 
00133   RCP<EquationSet> eqn 
00134     = rcp(new EquationSet(integral_, bc_, 
00135                           tuple(var), tuple(varEvalPts),
00136                           tuple(unk), tuple(unkEvalPts), 
00137                           fixedParams, fixedParamValues,
00138                           tuple(fixed), tuple(fixedEvalPts)));
00139 
00140   RCP<Assembler> assembler 
00141     = rcp(new Assembler(mesh_, eqn, tuple(vecType_), tuple(vecType_), false));
00142 
00143   return NonlinearProblem(assembler, unkEvalPts);
00144 }
00145 
00146 FunctionalEvaluator Functional::evaluator(const Expr& var,
00147                                           const Expr& varEvalPts,
00148                                           const Expr& fixed,
00149                                           const Expr& fixedEvalPts) const 
00150 {
00151 
00152   Expr unkParams;
00153   Expr fixedParams;
00154   Expr unkParamValues;
00155   Expr fixedParamValues;
00156 
00157   return FunctionalEvaluator(mesh_, integral_, bc_,
00158                              var, 
00159                              varEvalPts, 
00160                              fixed, fixedEvalPts,
00161                              vecType_);
00162 }
00163 
00164 
00165 FunctionalEvaluator Functional::evaluator(const Expr& var,
00166                                           const Expr& varEvalPts) const 
00167 {
00168   return FunctionalEvaluator(mesh_, integral_, bc_,
00169                              var, 
00170                              varEvalPts,
00171                              vecType_);
00172 }
00173 
00174 
00175 namespace Sundance
00176 {
00177 
00178 double L2Norm(const Mesh& mesh, const CellFilter& domain,
00179   const Expr& f, const QuadratureFamily& quad,
00180   const WatchFlag& watch)
00181 {
00182   Expr I2 = Integral(domain, f*f, quad, watch);
00183 
00184   return sqrt(evaluateIntegral(mesh, I2));
00185 }
00186 
00187 
00188 double H1Seminorm(
00189   const Mesh& mesh,
00190   const CellFilter& filter,
00191   const Expr& f,
00192   const QuadratureFamily& quad,
00193   const WatchFlag& watch)
00194 {
00195   Expr grad = gradient(mesh.spatialDim());
00196   return L2Norm(mesh, filter, grad*f, quad, watch);
00197 }
00198   
00199 double H1Norm(
00200   const Mesh& mesh,
00201   const CellFilter& filter,
00202   const Expr& f,
00203   const QuadratureFamily& quad,
00204   const WatchFlag& watch)
00205 {
00206   Expr grad = gradient(mesh.spatialDim());
00207   Expr g = grad*f;
00208   Expr I2 = Integral(filter, f*f + g*g, quad, watch);
00209 
00210   return sqrt(evaluateIntegral(mesh, I2));  
00211 }
00212 }

Site Contact