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
00043
00044 #ifndef SUNDANCE_SYMBPREPROCESSOR_H
00045 #define SUNDANCE_SYMBPREPROCESSOR_H
00046
00047 #include "SundanceExpr.hpp"
00048 #include "SundanceEvaluatableExpr.hpp"
00049 #include "SundanceZeroExpr.hpp"
00050 #include "SundanceDiscreteFuncElement.hpp"
00051 #include "SundanceComputationType.hpp"
00052
00053
00054
00055 namespace Sundance
00056 {
00057 using namespace Sundance;
00058 using namespace Teuchos;
00059
00060
00061
00062
00063 class Parameter;
00064
00065
00066
00067 class SymbPreprocessor
00068 {
00069 public:
00070
00071
00072 static DerivSet setupVariations(const Expr& expr,
00073 const Expr& vars,
00074 const Expr& varEvalPts,
00075 const Expr& unks,
00076 const Expr& unkEvalPts,
00077 const Expr& unkParams,
00078 const Expr& unkParamEvalPts,
00079 const Expr& fixedFields,
00080 const Expr& fixedFieldEvalPts,
00081 const Expr& fixedParams,
00082 const Expr& fixedParamEvalPts,
00083 const EvalContext& context,
00084 const ComputationType& compType);
00085
00086
00087 static DerivSet setupFunctional(const Expr& expr,
00088 const Expr& fixedParams,
00089 const Expr& fixedParamEvalPts,
00090 const Expr& fixedFields,
00091 const Expr& fixedFieldEvalPts,
00092 const EvalContext& context,
00093 const ComputationType& compType);
00094
00095
00096 static DerivSet setupGradient(const Expr& expr,
00097 const Expr& vars,
00098 const Expr& varEvalPts,
00099 const Expr& fixedParams,
00100 const Expr& fixedParamEvalPts,
00101 const Expr& fixedFields,
00102 const Expr& fixedFieldEvalPts,
00103 const EvalContext& contex,
00104 const ComputationType& compType);
00105
00106
00107 static DerivSet setupSensitivities(const Expr& expr,
00108 const Expr& tests,
00109 const Expr& unks,
00110 const Expr& unkEvalPts,
00111 const Expr& unkParams,
00112 const Expr& unkParamEvalPts,
00113 const Expr& fixedParams,
00114 const Expr& fixedParamEvalPts,
00115 const Expr& fixedFields,
00116 const Expr& fixedFieldEvalPts,
00117 const EvalContext& context,
00118 const ComputationType& compType);
00119
00120
00121 static DerivSet setupFwdProblem(const Expr& expr,
00122 const Expr& tests,
00123 const Expr& unks,
00124 const Expr& unkEvalPts,
00125 const Expr& unkParams,
00126 const Expr& unkParamEvalPts,
00127 const Expr& fixedParams,
00128 const Expr& fixedParamEvalPts,
00129 const Expr& fixedFields,
00130 const Expr& fixedFieldEvalPts,
00131 const EvalContext& context,
00132 const ComputationType& compType);
00133
00134
00135
00136
00137
00138 template <class T>
00139 static Set<int> processInputFuncs(const Expr& u, const Expr& u0)
00140 {
00141 Set<int> idSet;
00142
00143 for (int i=0; i<u.size(); i++)
00144 {
00145
00146 const T* uPtr = dynamic_cast<const T*>(u[i].ptr().get());
00147 TEUCHOS_TEST_FOR_EXCEPTION(uPtr==0, std::runtime_error,
00148 "Unexpected function type error: function " << u[i].toString()
00149 << " is of type=" << typeid(u).name()
00150 << ", but we expected type=" << typeid(T).name());
00151
00152
00153
00154 int fid = uPtr->fid().dofID();
00155 TEUCHOS_TEST_FOR_EXCEPTION(idSet.contains(fid), std::runtime_error,
00156 "duplicate function in input list " << u.toString());
00157 idSet.put(fid);
00158
00159
00160
00161
00162 RCP<DiscreteFuncElement> u0Ptr
00163 = rcp_dynamic_cast<DiscreteFuncElement>(u0[i].ptr());
00164 RCP<ZeroExpr> u0ZeroPtr
00165 = rcp_dynamic_cast<ZeroExpr>(u0[i].ptr());
00166 TEUCHOS_TEST_FOR_EXCEPTION(u0Ptr.get()==NULL && u0ZeroPtr.get()==NULL,
00167 std::runtime_error,
00168 "evaluation point " << u0[i].toString() << " for func=" << u[i]
00169 << " is neither a discrete function nor a zero expr");
00170
00171
00172 if (u0Ptr.get()==NULL)
00173 {
00174 uPtr->substituteZero();
00175 }
00176 else
00177 {
00178 uPtr->substituteFunction(u0Ptr);
00179 }
00180 }
00181
00182 return idSet;
00183 }
00184
00185
00186
00187
00188
00189 template <class T>
00190 static Set<int> processInputParams(const Expr& alpha, const Expr& alpha0)
00191 {
00192 Set<int> paramID;
00193
00194 for (int i=0; i<alpha.size(); i++)
00195 {
00196
00197 const T* aPtr = dynamic_cast<const T*>(alpha[i].ptr().get());
00198 TEUCHOS_TEST_FOR_EXCEPTION(aPtr==0, std::runtime_error,
00199 "list of purported parameters "
00200 "contains a function that is not an unknown parameter:"
00201 << alpha[i].toString());
00202
00203 int fid = aPtr->fid().dofID();
00204 TEUCHOS_TEST_FOR_EXCEPTION(paramID.contains(fid), std::runtime_error,
00205 "duplicate input parameter in list "
00206 << alpha.toString());
00207 paramID.put(fid);
00208
00209 RCP<Parameter> a0Ptr
00210 = rcp_dynamic_cast<Parameter>(alpha0[i].ptr());
00211 TEUCHOS_TEST_FOR_EXCEPTION(a0Ptr.get()==NULL,
00212 std::runtime_error,
00213 "parameter evaluation point " << alpha0[i].toString()
00214 << " is not a parameter");
00215 aPtr->substituteFunction(a0Ptr);
00216 }
00217 return paramID;
00218 }
00219
00220
00221
00222 TEUCHOS_TIMER(preprocTimer, "symbolic preprocessing");
00223 };
00224
00225
00226 Expr makeZeros(const Expr& e);
00227
00228
00229 }
00230
00231 #endif