SundanceUnknownFunctionStub.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 "SundanceUnknownFunctionStub.hpp"
00032 #include "SundanceUnknownFuncElement.hpp"
00033 #include "SundanceSpectralBasis.hpp"
00034 #include "SundanceSpectralExpr.hpp"
00035 
00036 
00037 using namespace Sundance;
00038 using namespace Sundance;
00039 
00040 using namespace Sundance;
00041 using namespace Teuchos;
00042 
00043 
00044 
00045 UnknownFunctionStub::UnknownFunctionStub(const std::string& name, 
00046   int tensorOrder,
00047   int dim, 
00048   const RCP<const UnknownFuncDataStub>& data)
00049   : SymbolicFunc(makeFuncID(tensorOrder), 
00050     rcp_dynamic_cast<const CommonFuncDataStub>(data)), data_(data)
00051 {
00052   FunctionIdentifier myFid = fid();
00053   if (tensorOrder==0)
00054   {
00055     Expr u = new UnknownFuncElement(data, name, "", myFid);
00056     append(u);
00057   }
00058   else if (tensorOrder==1)
00059   {
00060     for (int d=0; d<dim; d++)
00061     {
00062       std::string suffix="[" + Teuchos::toString(d) + "]";
00063       FunctionIdentifier fid = myFid.createComponent(d);
00064       append(new UnknownFuncElement(data, name, suffix, fid));
00065     }
00066   }
00067   else 
00068   {
00069     TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "tensor order = " << tensorOrder
00070       << " not supported");
00071   }
00072 }
00073 
00074 
00075 
00076 UnknownFunctionStub::UnknownFunctionStub(const std::string& name, 
00077   const SpectralBasis& sbasis, int tensorOrder, int dim,
00078   const RCP<const UnknownFuncDataStub>& data)
00079   : SymbolicFunc(FunctionIdentifier(),
00080     rcp_dynamic_cast<const CommonFuncDataStub>(data)), data_(data)
00081 {
00082   Array<FunctionIdentifier> cFid(sbasis.nterms());
00083 
00084   for (int n=0; n<sbasis.nterms(); n++)
00085   {
00086     cFid[n] = makeFuncID(tensorOrder);
00087   }
00088   
00089   if (tensorOrder==0 || dim==1)
00090   {
00091     Array<Expr> coeffs(sbasis.nterms());
00092     for (int n=0; n<sbasis.nterms(); n++)
00093     {
00094       std::string suffix="";
00095       if (sbasis.nterms()>1) suffix = "[" + Teuchos::toString(n) + "]";
00096       coeffs[n] = new UnknownFuncElement(data, name, suffix, cFid[n]);
00097     }
00098     append(new SpectralExpr(sbasis, coeffs));
00099   }
00100   else if (tensorOrder==1)
00101   {
00102     for (int d=0; d<dim; d++)
00103     {
00104       std::string suffix="[" + Teuchos::toString(d) + "]";
00105       Array<Expr> coeffs(sbasis.nterms());
00106       for (int n=0; n<sbasis.nterms(); n++)
00107       {
00108         FunctionIdentifier fid = cFid[n].createComponent(d);
00109         if (sbasis.nterms()>1) suffix += "[" + Teuchos::toString(n) + "]";
00110         coeffs[n]= new UnknownFuncElement(data, name, suffix, fid);
00111       }
00112       append(new SpectralExpr(sbasis, coeffs));
00113     }
00114   }
00115   else 
00116   {
00117     TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "tensor order = " << tensorOrder
00118       << " not supported");
00119   }
00120 }
00121 
00122 

Site Contact