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 #include "SundanceDiscreteFunctionStub.hpp"
00032 #include "SundanceDiscreteFuncElement.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 DiscreteFunctionStub::DiscreteFunctionStub(const std::string& name, 
00046   int tensorOrder,
00047   int dim, 
00048   const RCP<DiscreteFuncDataStub>& data,
00049   int listIndex)
00050   : ListExpr(), data_(data)
00051 {
00052   initTensor(name, tensorOrder, dim, data,  listIndex);
00053 }
00054 
00055 void DiscreteFunctionStub::initTensor(const std::string& name, 
00056   int tensorOrder,
00057   int dim, 
00058   const RCP<DiscreteFuncDataStub>& data,
00059   int listIndex)
00060 {
00061   FunctionIdentifier myFid = makeFuncID(tensorOrder);
00062   if (tensorOrder==0)
00063   {
00064     append(new DiscreteFuncElement(data, name, "", myFid, listIndex));
00065   }
00066   else if (tensorOrder==1)
00067   {
00068     for (int d=0; d<dim; d++)
00069     {
00070       std::string suffix="[" + Teuchos::toString(d) + "]";
00071       FunctionIdentifier fid = myFid.createComponent(d);
00072       append(new DiscreteFuncElement(data, name, suffix, fid, listIndex));
00073     }
00074   }
00075   else 
00076   {
00077     TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "tensor order = " << tensorOrder
00078       << " not supported");
00079   }
00080 }
00081 
00082 
00083 void DiscreteFunctionStub::initTensorSpectral(const std::string& name, 
00084   const SpectralBasis& sbasis, 
00085   int tensorOrder,
00086   int dim, 
00087   const RCP<DiscreteFuncDataStub>& data,
00088   int listIndexOffset)
00089 {
00090   Array<FunctionIdentifier> cFid(sbasis.nterms());
00091   Array<int> listIndex(sbasis.nterms());
00092 
00093   for (int n=0; n<sbasis.nterms(); n++)
00094   {
00095     cFid[n] = makeFuncID(tensorOrder);
00096     listIndex[n] = listIndexOffset + n;
00097   }
00098   
00099   if (tensorOrder==0 || dim==1)
00100   {
00101     Array<Expr> coeffs(sbasis.nterms());
00102     for (int n=0; n<sbasis.nterms(); n++)
00103     {
00104       std::string suffix="";
00105       if (sbasis.nterms()>1) suffix = "[" + Teuchos::toString(n) + "]";
00106       coeffs[n] = new DiscreteFuncElement(data, name, suffix, cFid[n], listIndex[n]);
00107     }
00108     append(new SpectralExpr(sbasis, coeffs));
00109   }
00110   else if (tensorOrder==1)
00111   {
00112     for (int d=0; d<dim; d++)
00113     {
00114       std::string suffix="[" + Teuchos::toString(d) + "]";
00115       Array<Expr> coeffs(sbasis.nterms());
00116       for (int n=0; n<sbasis.nterms(); n++)
00117       {
00118         FunctionIdentifier fid = cFid[n].createComponent(d);
00119         if (sbasis.nterms()>1) suffix += "[" + Teuchos::toString(n) + "]";
00120         coeffs[n]= new DiscreteFuncElement(data, name, suffix, fid, listIndex[n]);
00121       }
00122       append(new SpectralExpr(sbasis, coeffs));
00123     }
00124   }
00125   else 
00126   {
00127     TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "tensor order = " << tensorOrder
00128       << " not supported");
00129   }
00130 }
00131 
00132 
00133 
00134 
00135 DiscreteFunctionStub::DiscreteFunctionStub(const Array<string>& name, 
00136   const Array<std::pair<int,int> >& tensorStructure,
00137   const RCP<DiscreteFuncDataStub>& data)
00138   : ListExpr(), data_(data)
00139 {
00140   TEUCHOS_TEST_FOR_EXCEPT(name.size() != tensorStructure.size() && name.size()!=1);
00141 
00142   if (tensorStructure.size()==1)
00143   {
00144     int tensorOrder = tensorStructure[0].first;
00145     int dim = tensorStructure[0].second;
00146     initTensor(name[0], tensorOrder, dim, data, 0);
00147   }
00148   else
00149   {
00150     for (int i=0; i<tensorStructure.size(); i++)
00151     {
00152       std::string nm;
00153       if (name.size()==1) nm = name[0] + "[" + Teuchos::toString(i) + "]";
00154       else nm = name[i];
00155       append(new DiscreteFunctionStub(
00156                nm,
00157                tensorStructure[i].first,
00158                tensorStructure[i].second,
00159                data, i));
00160     }
00161   }
00162 }
00163 
00164 
00165 
00166 DiscreteFunctionStub::DiscreteFunctionStub(const std::string& name, 
00167   const SpectralBasis& sbasis, int tensorOrder, int dim,
00168   const RCP<DiscreteFuncDataStub>& data,
00169   int listIndex)
00170   : ListExpr(), data_(data)
00171 {
00172   initTensorSpectral(name, sbasis, tensorOrder, dim, data, listIndex);
00173 }
00174 
00175 
00176 
00177 DiscreteFunctionStub::DiscreteFunctionStub(const Array<string>& name, 
00178   const SpectralBasis& sbasis,  
00179   const Array<std::pair<int,int> >& tensorStructure,
00180   const RCP<DiscreteFuncDataStub>& data)
00181   : ListExpr(), data_(data)
00182 {
00183   TEUCHOS_TEST_FOR_EXCEPT(name.size() != tensorStructure.size());
00184    if (tensorStructure.size()==1)
00185   {
00186     int tensorOrder = tensorStructure[0].first;
00187     int dim = tensorStructure[0].second;
00188     initTensorSpectral(name[0], sbasis, tensorOrder, dim, data, 0);
00189   }
00190   else
00191   {
00192     for (int i=0; i<tensorStructure.size(); i++)
00193     {
00194       std::string nm;
00195       if (name.size()==1) nm = name[0] + "[" + Teuchos::toString(i) + "]";
00196       else nm = name[i];
00197       append(new DiscreteFunctionStub(
00198                nm,
00199                sbasis,
00200                tensorStructure[i].first,
00201                tensorStructure[i].second,
00202                data, i*sbasis.nterms()));
00203     }
00204   }
00205 }
00206 
00207