00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <PDEOperatorExpression.hpp>
00021 #include <PDEOperator.hpp>
00022
00023 #include <FunctionExpressionUnaryMinus.hpp>
00024 #include <ScalarFunctionBase.hpp>
00025
00026 #include <DivMuGrad.hpp>
00027 #include <SecondOrderOperator.hpp>
00028
00029 #include <FirstOrderOperator.hpp>
00030
00031 #include <MassOperator.hpp>
00032
00033 PDEOperatorExpression::
00034 PDEOperatorExpression(const PDEOperatorExpression& e)
00035 : Expression(e),
00036 __pdeOperatorType(e.__pdeOperatorType)
00037 {
00038 ;
00039 }
00040
00041 PDEOperatorExpression::
00042 PDEOperatorExpression(PDEOperatorType t)
00043 : Expression(Expression::pdeOperator),
00044 __pdeOperatorType(t)
00045 {
00046 ;
00047 }
00048
00049 PDEOperatorExpression::~PDEOperatorExpression()
00050 {
00051 ;
00052 }
00053
00054 void PDEOperatorExpression::execute()
00055 {
00056 this->__execute();
00057 if (this->__checkBoundaryExpression()) {
00058 throw ErrorHandler(__FILE__, __LINE__,
00059 "cannot evaluate the expression \""
00060 +stringify(*this)+
00061 "\" in the volume",
00062 ErrorHandler::normal);
00063 }
00064 }
00065
00066 ReferenceCounting<PDEOperator>
00067 PDEScalarOperatorExpression::pdeOperator()
00068 {
00069 return __pdeOperator;
00070 }
00071
00072 PDEScalarOperatorExpression::PDEScalarOperatorExpression(const PDEScalarOperatorExpression& e)
00073 : PDEOperatorExpression(e),
00074 __unknownName(e.__unknownName),
00075 __pdeOperator(e.__pdeOperator),
00076 __pdeScalarOperatorType(e.__pdeScalarOperatorType)
00077 {
00078 ;
00079 }
00080
00081 PDEScalarOperatorExpression::
00082 PDEScalarOperatorExpression(const std::string& unknownName,
00083 PDEScalarOperatorType t)
00084 : PDEOperatorExpression(PDEOperatorExpression::scalar),
00085 __unknownName(unknownName),
00086 __pdeScalarOperatorType(t)
00087 {
00088 ;
00089 }
00090
00091 PDEScalarOperatorExpression::~PDEScalarOperatorExpression()
00092 {
00093 ;
00094 }
00095
00096
00097 bool PDEScalarOperatorExpressionDivMuGrad::__checkBoundaryExpression() const
00098 {
00099 return __mu->hasBoundaryExpression();
00100 }
00101
00102 void PDEScalarOperatorExpressionDivMuGrad::__execute()
00103 {
00104 __mu->execute();
00105 ScalarFunctionBuilder functionBuilder;
00106 functionBuilder.setFunction(__mu->function());
00107 functionBuilder.setUnaryMinus();
00108
00109 __pdeOperator = new DivMuGrad(functionBuilder.getBuiltFunction());
00110 }
00111
00112 bool PDEScalarOperatorExpressionOrderZero::__checkBoundaryExpression() const
00113 {
00114 return __Alpha->hasBoundaryExpression();
00115 }
00116
00117 void PDEScalarOperatorExpressionOrderZero::__execute()
00118 {
00119 __Alpha->execute();
00120 __pdeOperator = new MassOperator(__Alpha->function());
00121 }
00122
00123 bool PDEScalarOperatorExpressionOrderOne::__checkBoundaryExpression() const
00124 {
00125 for (size_t i=0; i<3; ++i) {
00126 if(__nu[i] != 0) {
00127 if (__nu[i]->hasBoundaryExpression()) {
00128 return true;
00129 }
00130 }
00131 }
00132 return false;
00133 }
00134
00135 void PDEScalarOperatorExpressionOrderOne::__execute()
00136 {
00137 this->preexec();
00138
00139 ReferenceCounting<TinyVector<3, ConstReferenceCounting<ScalarFunctionBase> > > nu
00140 = new TinyVector<3, ConstReferenceCounting<ScalarFunctionBase> >;
00141
00142 for (size_t i=0; i<3; ++i) {
00143 if(__nu[i] != 0) {
00144 (*nu)[i] = __nu[i]->function();
00145 } else {
00146 (*nu)[i] = 0;
00147 }
00148 }
00149
00150 __pdeOperator = new FirstOrderOperator(nu);
00151 }
00152
00153
00154 PDEVectorialOperatorExpression::
00155 PDEVectorialOperatorExpression(const PDEVectorialOperatorExpression::
00156 PDEScalarOperatorType& t)
00157 : PDEOperatorExpression(PDEOperatorExpression::vectorial),
00158 __pdeOperatorType(t)
00159 {
00160 ;
00161 }
00162
00163 PDEVectorialOperatorExpression::
00164 PDEVectorialOperatorExpression(const PDEVectorialOperatorExpression& e)
00165 : PDEOperatorExpression(e),
00166 __pdeOperatorList(e.__pdeOperatorList),
00167 __pdeOperatorType(e.__pdeOperatorType)
00168 {
00169 ;
00170 }
00171
00172 PDEVectorialOperatorExpression::
00173 ~PDEVectorialOperatorExpression()
00174 {
00175 ;
00176 }
00177
00178 bool PDEVectorialOperatorExpressionOrderOne::
00179 __checkBoundaryExpression() const
00180 {
00181 for(FirstOrderSum::const_iterator i = __sum.begin();
00182 i != __sum.end(); ++i) {
00183 if ((*(*i).second).__checkBoundaryExpression()) {
00184 return true;
00185 }
00186 }
00187 for(FirstOrderSum::const_iterator i = __diff.begin();
00188 i != __diff.end(); ++i) {
00189 if ((*(*i).second).__checkBoundaryExpression()) {
00190 return true;
00191 }
00192 }
00193 return false;
00194 }
00195
00196 bool PDEVectorialOperatorExpressionOrderTwo::
00197 __checkBoundaryExpression() const
00198 {
00199 typedef
00200 TinyMatrix<3,3,ReferenceCounting<FunctionExpression> >
00201 FunctionMatrix;
00202
00203 typedef
00204 std::map<FunctionVariable*,FunctionMatrix >
00205 FunctionMatrixSet;
00206 FunctionMatrixSet matrixSet;
00207
00208 typedef
00209 PDEVectorialOperatorExpressionOrderOne::FirstOrderSum::const_iterator
00210 PDEVectorialOperatorIterator;
00211
00212 for (FirstOperatorList::const_iterator i = __firstOrderOp.begin();
00213 i != __firstOrderOp.end(); ++i) {
00214 const PDEVectorialOperatorExpressionOrderOne& pdeOpOrderOne
00215 = (*(*i).second);
00216
00217 if (pdeOpOrderOne.__checkBoundaryExpression()) {
00218 return true;
00219 }
00220 }
00221
00222 return false;
00223 }
00224
00225 void PDEVectorialOperatorExpressionOrderTwo::__execute()
00226 {
00227 typedef
00228 TinyMatrix<3,3,ReferenceCounting<FunctionExpression> >
00229 FunctionMatrix;
00230
00231 typedef
00232 std::map<std::string,FunctionMatrix >
00233 FunctionMatrixSet;
00234 FunctionMatrixSet matrixSet;
00235
00236 typedef
00237 PDEVectorialOperatorExpressionOrderOne::FirstOrderSum::iterator
00238 PDEVectorialOperatorIterator;
00239
00240 for (FirstOperatorList::iterator i = __firstOrderOp.begin();
00241 i != __firstOrderOp.end(); ++i) {
00242 int I = (*i).first;
00243 PDEVectorialOperatorExpressionOrderOne& pdeOpOrderOne
00244 = (*(*i).second);
00245 pdeOpOrderOne.preexec();
00246
00247 for (PDEVectorialOperatorIterator j = pdeOpOrderOne.__sum.begin();
00248 j != pdeOpOrderOne.__sum.end(); ++j) {
00249 PDEScalarOperatorExpressionOrderOne& operatorOrderOne = *j->second;
00250
00251 FunctionMatrix& A = matrixSet[(*j).first];
00252
00253 for (size_t J=0; J<3; ++J) {
00254 if (operatorOrderOne.nu(J) != 0) {
00255 if (A(I,J) == 0) {
00256 A(I,J) = operatorOrderOne.nu(J);
00257 } else {
00258 A(I,J)
00259 = new FunctionExpressionBinaryOperation(BinaryOperation::sum,A(I,J),operatorOrderOne.nu(J));
00260 }
00261 }
00262 }
00263 }
00264
00265 for (PDEVectorialOperatorIterator j = pdeOpOrderOne.__diff.begin();
00266 j != pdeOpOrderOne.__diff.end(); ++j) {
00267 PDEScalarOperatorExpressionOrderOne& operatorOrderOne = (*(*j).second);
00268
00269 FunctionMatrix& A = matrixSet[(*j).first];
00270
00271 for (size_t J=0; J<3; ++J) {
00272 if (operatorOrderOne.nu(J) != 0) {
00273 if (A(I,J) == 0) {
00274 A(I,J) = new FunctionExpressionUnaryMinus(operatorOrderOne.nu(J));
00275 } else {
00276 A(I,J)
00277 = new FunctionExpressionBinaryOperation(BinaryOperation::difference, A(I,J),operatorOrderOne.nu(J));
00278 }
00279 }
00280 }
00281 }
00282 }
00283 for (FunctionMatrixSet::iterator i = matrixSet.begin();
00284 i != matrixSet.end(); ++i) {
00285 FunctionMatrix& a = (*i).second;
00286 ReferenceCounting<SecondOrderOperator::Matrix> A
00287 = new SecondOrderOperator::Matrix;
00288 for (size_t m=0; m<3; ++m)
00289 for (size_t n=0; n<3; ++n) {
00290 if (a(m,n) != 0) {
00291 ScalarFunctionBuilder functionBuilder;
00292 functionBuilder.setFunction(a(m,n)->function());
00293 functionBuilder.setUnaryMinus();
00294 (*A)(m,n) = functionBuilder.getBuiltFunction();
00295 }
00296 }
00297 SecondOrderOperator* secondOrderOp = new SecondOrderOperator(A);
00298 __pdeOperatorList.insert(std::make_pair(i->first,secondOrderOp));
00299 }
00300 }
00301
00302 PDEVectorialOperatorExpressionOrderTwo::
00303 PDEVectorialOperatorExpressionOrderTwo()
00304 : PDEVectorialOperatorExpression(PDEVectorialOperatorExpression::
00305 secondOrder)
00306 {
00307 ;
00308 }
00309
00310 PDEVectorialOperatorExpressionOrderTwo::
00311 ~PDEVectorialOperatorExpressionOrderTwo()
00312 {
00313 ;
00314 }