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