public SecondDerivativeOp(int direction, FdmMesher mesher) : base(direction, mesher) { FdmLinearOpLayout layout = mesher.layout(); FdmLinearOpIterator endIter = layout.end(); for (FdmLinearOpIterator iter = layout.begin(); iter != endIter; ++iter) { int i = iter.index(); double?hm = mesher.dminus(iter, direction_); double?hp = mesher.dplus(iter, direction_); double?zetam1 = hm * (hm + hp); double?zeta0 = hm * hp; double?zetap1 = hp * (hm + hp); int co = iter.coordinates()[direction_]; if (co == 0 || co == layout.dim()[direction] - 1) { lower_[i] = diag_[i] = upper_[i] = 0.0; } else { lower_[i] = 2.0 / zetam1.Value; diag_[i] = -2.0 / zeta0.Value; upper_[i] = 2.0 / zetap1.Value; } } }
public FirstDerivativeOp(int direction, FdmMesher mesher) : base(direction, mesher) { FdmLinearOpLayout layout = mesher.layout(); FdmLinearOpIterator endIter = layout.end(); for (FdmLinearOpIterator iter = layout.begin(); iter != endIter; ++iter) { int i = iter.index(); double?hm = mesher.dminus(iter, direction_); double?hp = mesher.dplus(iter, direction_); double?zetam1 = hm * (hm + hp); double?zeta0 = hm * hp; double?zetap1 = hp * (hm + hp); if (iter.coordinates()[direction_] == 0) { //upwinding scheme lower_[i] = 0.0; diag_[i] = -(upper_[i] = 1 / hp.Value); } else if (iter.coordinates()[direction_] == layout.dim()[direction] - 1) { // downwinding scheme lower_[i] = -(diag_[i] = 1 / hm.Value); upper_[i] = 0.0; } else { lower_[i] = -hp.Value / zetam1.Value; diag_[i] = (hp.Value - hm.Value) / zeta0.Value; upper_[i] = hm.Value / zetap1.Value; } } }
public SecondOrderMixedDerivativeOp(int d0, int d1, FdmMesher mesher) : base(d0, d1, mesher) { FdmLinearOpLayout layout = mesher.layout(); FdmLinearOpIterator endIter = layout.end(); for (FdmLinearOpIterator iter = layout.begin(); iter != endIter; ++iter) { int i = iter.index(); double?hm_d0 = mesher.dminus(iter, d0_); double?hp_d0 = mesher.dplus(iter, d0_); double?hm_d1 = mesher.dminus(iter, d1_); double?hp_d1 = mesher.dplus(iter, d1_); double?zetam1 = hm_d0 * (hm_d0 + hp_d0); double?zeta0 = hm_d0 * hp_d0; double?zetap1 = hp_d0 * (hm_d0 + hp_d0); double?phim1 = hm_d1 * (hm_d1 + hp_d1); double?phi0 = hm_d1 * hp_d1; double?phip1 = hp_d1 * (hm_d1 + hp_d1); int c0 = iter.coordinates()[d0_]; int c1 = iter.coordinates()[d1_]; if (c0 == 0 && c1 == 0) { // lower left corner a00_[i] = a01_[i] = a02_[i] = a10_[i] = a20_[i] = 0.0; a11_[i] = a22_[i] = 1.0 / (hp_d0.Value * hp_d1.Value); a21_[i] = a12_[i] = -a11_[i]; } else if (c0 == layout.dim()[d0_] - 1 && c1 == 0) { // upper left corner a22_[i] = a21_[i] = a20_[i] = a10_[i] = a00_[i] = 0.0; a01_[i] = a12_[i] = 1.0 / (hm_d0.Value * hp_d1.Value); a11_[i] = a02_[i] = -a01_[i]; } else if (c0 == 0 && c1 == layout.dim()[d1_] - 1) { // lower right corner a00_[i] = a01_[i] = a02_[i] = a12_[i] = a22_[i] = 0.0; a10_[i] = a21_[i] = 1.0 / (hp_d0.Value * hm_d1.Value); a20_[i] = a11_[i] = -a10_[i]; } else if (c0 == layout.dim()[d0_] - 1 && c1 == layout.dim()[d1_] - 1) { // upper right corner a20_[i] = a21_[i] = a22_[i] = a12_[i] = a02_[i] = 0.0; a00_[i] = a11_[i] = 1.0 / (hm_d0.Value * hm_d1.Value); a10_[i] = a01_[i] = -a00_[i]; } else if (c0 == 0) { // lower side a00_[i] = a01_[i] = a02_[i] = 0.0; a10_[i] = hp_d1.Value / (hp_d0.Value * phim1.Value); a20_[i] = -a10_[i]; a21_[i] = (hp_d1.Value - hm_d1.Value) / (hp_d0.Value * phi0.Value); a11_[i] = -a21_[i]; a22_[i] = hm_d1.Value / (hp_d0.Value * phip1.Value); a12_[i] = -a22_[i]; } else if (c0 == layout.dim()[d0_] - 1) { // upper side a20_[i] = a21_[i] = a22_[i] = 0.0; a00_[i] = hp_d1.Value / (hm_d0.Value * phim1.Value); a10_[i] = -a00_[i]; a11_[i] = (hp_d1.Value - hm_d1.Value) / (hm_d0.Value * phi0.Value); a01_[i] = -a11_[i]; a12_[i] = hm_d1.Value / (hm_d0.Value * phip1.Value); a02_[i] = -a12_[i]; } else if (c1 == 0) { // left side a00_[i] = a10_[i] = a20_[i] = 0.0; a01_[i] = hp_d0.Value / (zetam1.Value * hp_d1.Value); a02_[i] = -a01_[i]; a12_[i] = (hp_d0.Value - hm_d0.Value) / (zeta0.Value * hp_d1.Value); a11_[i] = -a12_[i]; a22_[i] = hm_d0.Value / (zetap1.Value * hp_d1.Value); a21_[i] = -a22_[i]; } else if (c1 == layout.dim()[d1_] - 1) { // right side a22_[i] = a12_[i] = a02_[i] = 0.0; a00_[i] = hp_d0.Value / (zetam1.Value * hm_d1.Value); a01_[i] = -a00_[i]; a11_[i] = (hp_d0.Value - hm_d0.Value) / (zeta0.Value * hm_d1.Value); a10_[i] = -a11_[i]; a21_[i] = hm_d0.Value / (zetap1.Value * hm_d1.Value); a20_[i] = -a21_[i]; } else { a00_[i] = hp_d0.Value * hp_d1.Value / (zetam1.Value * phim1.Value); a10_[i] = -(hp_d0.Value - hm_d0.Value) * hp_d1.Value / (zeta0.Value * phim1.Value); a20_[i] = -hm_d0.Value * hp_d1.Value / (zetap1.Value * phim1.Value); a01_[i] = -hp_d0.Value * (hp_d1.Value - hm_d1.Value) / (zetam1.Value * phi0.Value); a11_[i] = (hp_d0.Value - hm_d0.Value) * (hp_d1.Value - hm_d1.Value) / (zeta0.Value * phi0.Value); a21_[i] = hm_d0.Value * (hp_d1.Value - hm_d1.Value) / (zetap1.Value * phi0.Value); a02_[i] = -hp_d0.Value * hm_d1.Value / (zetam1.Value * phip1.Value); a12_[i] = hm_d1.Value * (hp_d0.Value - hm_d0.Value) / (zeta0.Value * phip1.Value); a22_[i] = hm_d0.Value * hm_d1.Value / (zetap1.Value * phip1.Value); } } }