/// <summary> /// returns <paramref name="a"/>*<paramref name="alpha"/> /// </summary> /// <param name="a">a vector field</param> /// <param name="alpha">scalar</param> /// <returns></returns> static public VectorField <T> operator *(VectorField <T> a, double alpha) { VectorField <T> ret = (VectorField <T>)a.Clone(); ret.Scale(alpha); return(ret); }
/// <summary> /// adding two vector fields /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static public VectorField <T> operator +(VectorField <T> a, VectorField <T> b) { VectorField <T> ret = (VectorField <T>)b.Clone(); ret.Acc(1.0, a); return(ret); }
/// <summary> /// accumulates the curl of a 2D DG vector field <paramref name="vec"/> /// times <paramref name="alpha"/> /// to this vector field, i.e. <br/> /// this = this + <paramref name="alpha"/>* Curl(<paramref name="vec"/>) /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <param name="em"> /// An optional restriction to the domain in which the derivative is /// computed (it may, e.g. be only required in boundary cells, so a /// computation over the whole domain would be a waste of computational /// power. A proper execution mask for this case would be e.g. /// <see cref="BoSSS.Foundation.Grid.GridData.BoundaryCells"/>.)<br/> /// if null, the computation is carried out in the whole domain /// </param> /// <remarks> /// This method is based on /// <see cref="DGField.Derivative(double,DGField,int)"/>, i.e. it /// calculates derivatives by analytic cell-by-cell derivation of the /// DG polynomials; /// </remarks> /// <seealso cref="VectorField{T}.Curl3D(double, VectorField{T}, CellMask)"/> public void Curl2D <T>(double alpha, VectorField <T> vec, CellMask em) where T : DGField { using (new FuncTrace()) { if (vec.Dim != 2) { throw new ArgumentException("vector field must be 2-dim.", "vec"); } this.Derivative(alpha, vec[1], 0, em); this.Derivative(-alpha, vec[0], 1, em); } }
/// <summary> /// copies the values of <paramref name="other"/> to this object /// (non-shallow) if possible /// </summary> /// <param name="other"></param> public void CopyFrom(VectorField <T> other) { if (this.Dim != other.Dim) { throw new ApplicationException("unable to copy from other vector field - dimension mismatch."); } for (int d = 0; d < m_Components.Length; d++) { this[d].CopyFrom(other[d]); } }
/// <summary> /// 'lax' accumulation (see /// <see cref="DGField.AccLaidBack(double, DGField, CellMask)"/>) of an /// other vector field /// <paramref name="a"/>*<paramref name="mult"/> to this field; /// </summary> public void AccLaidBack(double mult, VectorField <T> a, CellMask m = null) { if (a.Dim != this.Dim) { throw new ArgumentException("a is of another dimension", "a"); } for (int d = 0; d < m_Components.Length; d++) { m_Components[d].AccLaidBack(mult, a.m_Components[d], m); } }
/// <summary> /// The inner product of vector fields <paramref name="a"/> and <paramref name="b"/>; /// </summary> static public double InnerProduct(VectorField <T> a, VectorField <T> b) { if (a.Dim != b.Dim) { throw new ArgumentException("mismatch in dimension"); } double acc = 0; for (int d = 0; d < a.Dim; d++) { acc += DGField.InnerProduct(a[d], b[d]); } return(acc); }
/// <summary> /// accumulates the curl of 2D DG vector field <paramref name="vec"/> /// times <paramref name="alpha"/> /// to this vector field, i.e. <br/> /// this = this + <paramref name="alpha"/>* Curl(<paramref name="vec"/>) /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <param name="optionalSubGrid"> /// An optional restriction to the domain in which the derivative is /// computed (it may, e.g. be only required in boundary cells, so a /// computation over the whole domain would be a waste of computational /// power. A proper execution mask would be see e.g. /// <see cref="GridData.BoundaryCells"/>.) /// <br/> /// if null, the computation is carried out in the whole domain. /// </param> /// <remarks> /// This method is based on <see cref="DGField.DerivativeByFlux"/>, i.e. /// it calculates derivatives by central-difference fluxes; /// </remarks> /// <seealso cref="VectorField{T}.Curl3DByFlux"/> /// <param name="bndMode"></param> public void Curl2DByFlux <T>(double alpha, VectorField <T> vec, SubGrid optionalSubGrid = null, SubGridBoundaryModes bndMode = SubGridBoundaryModes.OpenBoundary) where T : DGField { //diff(v(x, y), x)-(diff(u(x, y), y)) using (new FuncTrace()) { if (vec.Dim != 2) { throw new ArgumentException("vector field must be 2-dim.", "vec"); } this.DerivativeByFlux(alpha, vec[1], 0, optionalSubGrid, bndMode); this.DerivativeByFlux(-alpha, vec[0], 1, optionalSubGrid, bndMode); } }
/// <summary> /// accumulates the divergence of vector field <paramref name="vec"/> /// times <paramref name="alpha"/> /// to this field. /// </summary> /// <remarks> /// This method is based on <see cref="DerivativeByFlux"/>; /// </remarks> public void DivergenceByFlux <T>(double alpha, VectorField <T> vec, SubGrid optionalSubGrid = null, SubGridBoundaryModes bndMode = SubGridBoundaryModes.OpenBoundary) where T : DGField { using (new FuncTrace()) { if (vec.Dim != GridDat.SpatialDimension) { throw new ArgumentException("wrong number of components in vector field.", "vec"); } int D = GridDat.SpatialDimension; for (int d = 0; d < D; d++) { this.DerivativeByFlux(alpha, vec[d], d, optionalSubGrid, bndMode); } } }
/// <summary> /// accumulates the divergence of vector field <paramref name="vec"/> /// times <paramref name="alpha"/> to this field. /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <param name="em"></param> /// <remarks> /// This method is based on <see cref="Derivative(double,DGField,int,CellMask)"/>; /// </remarks> public void Divergence <T>(double alpha, VectorField <T> vec, CellMask em = null) where T : DGField { using (new FuncTrace()) { if (vec.Dim != GridDat.SpatialDimension) { throw new ArgumentException( "wrong number of components in vector field.", "vec"); } int D = GridDat.SpatialDimension; for (int d = 0; d < D; d++) { this.Derivative(alpha, vec[d], d, em); } } }
/// <summary> /// accumulates the curl of a 3D DG vector field <paramref name="vec"/> /// times <paramref name="alpha"/> to this vector field, i.e. <br/> /// this = this + <paramref name="alpha"/>* Curl(<paramref name="vec"/>) /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <param name="em"> /// An optional restriction to the domain in which the derivative is /// computed (it may, e.g. be only required in boundary cells, so a /// computation over the whole domain would be a waste of /// computational power. A proper execution mask for this case would be /// e.g. <see cref="BoSSS.Foundation.Grid.GridData.BoundaryCells"/>.) /// <br/>if null, the computation is carried out in the whole domain /// </param> /// <remarks> /// This method is based on /// <see cref="DGField.Derivative(double,DGField,int)"/>, i.e. it /// calculates derivatives by analytic cell-by-cell derivation of the /// DG polynomials; /// </remarks> /* <seealso cref="DGField.Curl2D{T}(double, VectorField{T}, CellMask)"/> */ public void Curl3D(double alpha, VectorField <T> vec, CellMask em = null) { if (vec.Dim != 3) { throw new ArgumentException("this method works only for 3-dimensional vector fields.", "vec"); } if (this.Dim != 3) { throw new ApplicationException("this vector field must be 3-dimensional."); } this.m_Components[0].Derivative(alpha, vec.m_Components[2], 1, em); this.m_Components[0].Derivative(-alpha, vec.m_Components[1], 2, em); this.m_Components[1].Derivative(alpha, vec.m_Components[0], 2, em); this.m_Components[1].Derivative(-alpha, vec.m_Components[2], 0, em); this.m_Components[2].Derivative(alpha, vec.m_Components[1], 0, em); this.m_Components[2].Derivative(-alpha, vec.m_Components[0], 1, em); }
/// <summary> /// accumulates the curl of 3D DG vector field <paramref name="vec"/> /// times <paramref name="alpha"/> /// to this vector field, i.e. <br/> /// this = this + <paramref name="alpha"/>* Curl(<paramref name="vec"/>) /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <param name="optionalSubGrid"> /// An optional restriction to the domain in which the derivative is /// computed (it may, e.g. be only required in boundary cells, so a /// computation over the whole domain would be a waste of computational /// power. A proper execution mask would be see e.g. /// <see cref="Grid.GridData.BoundaryCells"/>.) /// <br/> if null, the computation is carried out in the whole domain. /// </param> /// <param name="bndMode"></param> /// <remarks> /// This method is based on /// <see cref="DGField.DerivativeByFlux(double,DGField,int,SubGrid,SpatialOperator.SubGridBoundaryModes)"/>, /// i.e. it calculates derivatives by central-difference fluxes; /// </remarks> /* <seealso cref="DGField.Curl2DByFlux{T}"/> */ public void Curl3DByFlux(double alpha, VectorField <T> vec, SubGrid optionalSubGrid = null, SpatialOperator.SubGridBoundaryModes bndMode = SpatialOperator.SubGridBoundaryModes.OpenBoundary) { if (vec.Dim != 3) { throw new ArgumentException("this method works only for 3-dimensional vector fields.", "vec"); } if (this.Dim != 3) { throw new ApplicationException("this vector field must be 3-dimensional."); } this.m_Components[0].DerivativeByFlux(alpha, vec.m_Components[2], 1, optionalSubGrid, bndMode); this.m_Components[0].DerivativeByFlux(-alpha, vec.m_Components[1], 2, optionalSubGrid, bndMode); this.m_Components[1].DerivativeByFlux(alpha, vec.m_Components[0], 2, optionalSubGrid, bndMode); this.m_Components[1].DerivativeByFlux(-alpha, vec.m_Components[2], 0, optionalSubGrid, bndMode); this.m_Components[2].DerivativeByFlux(alpha, vec.m_Components[1], 0, optionalSubGrid, bndMode); this.m_Components[2].DerivativeByFlux(-alpha, vec.m_Components[0], 1, optionalSubGrid, bndMode); }
/// <summary> /// see <see cref="ProjectAbs(double,CellMask, DGField[])"/>; /// </summary> virtual public void ProjectAbs <T>(double alpha, VectorField <T> vec) where T : DGField { ProjectAbs(alpha, null, vec.ToArray()); }
/// <summary> /// accumulates the curl of 2D DG vector field <paramref name="vec"/> /// times <paramref name="alpha"/> /// to this vector field, i.e. <br/> /// this = this + <paramref name="alpha"/>* Curl(<paramref name="vec"/>) /// </summary> /// <param name="alpha"></param> /// <param name="vec"></param> /// <remarks> /// This method is based on /// <see cref="DGField.Derivative(double,DGField,int)"/>, i.e. it /// calculates derivatives by analytic cell-by-cell derivation of the /// DG polynomials; /// </remarks> /// <seealso cref="VectorField{T}.Curl3D"/> public void Curl2D <T>(double alpha, VectorField <T> vec) where T : DGField { Curl2D <T>(alpha, vec, null); }