📄 stencilops.h
字号:
const int x = firstDim, y = secondDim, z = thirdDim; return TinyVector<_bz_typename T::T_numtype,3>( central12(vz,y)-central12(vy,z), central12(vx,z)-central12(vz,x), central12(vy,x)-central12(vx,y));}// Normalized O(h^2) curl, using central differencetemplate<typename T>inline TinyVector<_bz_typename T::T_numtype,3>curln(T& vx, T& vy, T& vz) { const int x = firstDim, y = secondDim, z = thirdDim; return TinyVector<_bz_typename T::T_numtype,3>( (central12(vz,y)-central12(vy,z)) * recip_2, (central12(vx,z)-central12(vz,x)) * recip_2, (central12(vy,x)-central12(vx,y)) * recip_2);}// Multicomponent curltemplate<typename T>inline _bz_typename T::T_numtype curl(T& A) { const int x = firstDim, y = secondDim, z = thirdDim; return _bz_typename T::T_numtype( central12(A,z,y)-central12(A,y,z), central12(A,x,z)-central12(A,z,x), central12(A,y,x)-central12(A,x,y));}// Normalized multicomponent curltemplate<typename T>inline _bz_typename T::T_numtype curln(T& A) { const int x = firstDim, y = secondDim, z = thirdDim; return _bz_typename T::T_numtype( (central12(A,z,y)-central12(A,y,z)) * recip_2, (central12(A,x,z)-central12(A,z,x)) * recip_2, (central12(A,y,x)-central12(A,x,y)) * recip_2);}// O(h^4) curl, using 4th order central differencetemplate<typename T>inline TinyVector<_bz_typename T::T_numtype,3>curl4(T& vx, T& vy, T& vz) { const int x = firstDim, y = secondDim, z = thirdDim; return TinyVector<_bz_typename T::T_numtype,3>( central14(vz,y)-central14(vy,z), central14(vx,z)-central14(vz,x), central14(vy,x)-central14(vx,y));}// O(h^4) curl, using 4th order central difference (multicomponent version)template<typename T>inline _bz_typename T::T_numtypecurl4(T& A) { const int x = firstDim, y = secondDim, z = thirdDim; return _bz_typename T::T_numtype( central14(A,z,y)-central14(A,y,z), central14(A,x,z)-central14(A,z,x), central14(A,y,x)-central14(A,x,y));}// Normalized O(h^4) curl, using 4th order central differencetemplate<typename T>inline TinyVector<_bz_typename T::T_numtype,3>curl4n(T& vx, T& vy, T& vz) { const int x = firstDim, y = secondDim, z = thirdDim; return TinyVector<_bz_typename T::T_numtype,3>( (central14(vz,y)-central14(vy,z)) * recip_2, (central14(vx,z)-central14(vz,x)) * recip_2, (central14(vy,x)-central14(vx,y)) * recip_2);}// O(h^4) curl, using 4th order central difference (normalized multicomponent)template<typename T>inline _bz_typename T::T_numtypecurl4n(T& A) { const int x = firstDim, y = secondDim, z = thirdDim; return _bz_typename T::T_numtype( (central14(A,z,y)-central14(A,y,z)) * recip_2, (central14(A,x,z)-central14(A,z,x)) * recip_2, (central14(A,y,x)-central14(A,x,y)) * recip_2);}// Two-dimensional curltemplate<typename T>inline _bz_typename T::T_numtypecurl(T& vx, T& vy) { const int x = firstDim, y = secondDim; return central12(vy,x)-central12(vx,y);}template<typename T>inline _bz_typename T::T_numtypecurln(T& vx, T& vy) { const int x = firstDim, y = secondDim; return (central12(vy,x)-central12(vx,y)) * recip_2;}// Multicomponent curltemplate<typename T>inline _bz_typename T::T_numtype::T_numtype curl2D(T& A) { const int x = firstDim, y = secondDim; return central12(A,y,x)-central12(A,x,y);}template<typename T>inline _bz_typename T::T_numtype::T_numtype curl2Dn(T& A) { const int x = firstDim, y = secondDim; return (central12(A,y,x)-central12(A,x,y)) * recip_2;}// 4th order versionstemplate<typename T>inline _bz_typename T::T_numtypecurl4(T& vx, T& vy) { const int x = firstDim, y = secondDim; return central14(vy,x)-central14(vx,y);}template<typename T>inline _bz_typename T::T_numtypecurl4n(T& vx, T& vy) { const int x = firstDim, y = secondDim; return (central14(vy,x)-central14(vx,y)) * recip_12;}// Multicomponent curltemplate<typename T>inline _bz_typename T::T_numtype::T_numtype curl2D4(T& A) { const int x = firstDim, y = secondDim; return central14(A,y,x)-central14(A,x,y);}template<typename T>inline _bz_typename T::T_numtype::T_numtype curl2D4n(T& A) { const int x = firstDim, y = secondDim; return (central14(A,y,x)-central14(A,x,y)) * recip_12;}/**************************************************************************** * Divergence ****************************************************************************/BZ_DECLARE_STENCIL_OPERATOR2(div,vx,vy) return central12(vx,firstDim) + central12(vy,secondDim);BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR2(divn,vx,vy) return (central12(vx,firstDim) + central12(vy,secondDim)) * recip_2;BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR2(div4,vx,vy) return central14(vx,firstDim) + central14(vy,secondDim);BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR2(div4n,vx,vy) return (central14(vx,firstDim) + central14(vy,secondDim)) * recip_12;BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR3(div,vx,vy,vz) return central12(vx,firstDim) + central12(vy,secondDim) + central12(vz,thirdDim);BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR3(divn,vx,vy,vz) return (central12(vx,firstDim) + central12(vy,secondDim) + central12(vz,thirdDim)) * recip_2;BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR3(div4,vx,vy,vz) return central14(vx,firstDim) + central14(vy,secondDim) + central14(vz,thirdDim);BZ_END_STENCIL_OPERATORBZ_DECLARE_STENCIL_OPERATOR3(div4n,vx,vy,vz) return (central14(vx,firstDim) + central14(vy,secondDim) + central14(vz,thirdDim)) * recip_12;BZ_END_STENCIL_OPERATORtemplate<typename T>inline _bz_typename T::T_numtype::T_numtypediv2D(T& A){ const int x = firstDim, y = secondDim; return central12(A,x,x) + central12(A,y,y);}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv2D4(T& A){ const int x = firstDim, y = secondDim; return central14(A,x,x) + central14(A,y,y);}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv2Dn(T& A){ const int x = firstDim, y = secondDim; return (central12(A,x,x) + central12(A,y,y)) * recip_2;}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv2D4n(T& A){ const int x = firstDim, y = secondDim; return (central14(A,x,x) + central14(A,y,y)) * recip_12;}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv3D(T& A){ const int x = firstDim, y = secondDim, z = thirdDim; return central12(A,x,x) + central12(A,y,y) + central12(A,z,z);}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv3D4(T& A){ const int x = firstDim, y = secondDim, z = thirdDim; return central14(A,x,x) + central14(A,y,y) + central14(A,z,z);}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv3Dn(T& A){ const int x = firstDim, y = secondDim, z = thirdDim; return (central12(A,x,x) + central12(A,y,y) + central12(A,z,z)) * recip_2;}template<typename T>inline _bz_typename T::T_numtype::T_numtypediv3D4n(T& A){ const int x = firstDim, y = secondDim, z = thirdDim; return (central14(A,x,x) + central14(A,y,y) + central14(A,z,z)) * recip_12;}/**************************************************************************** * Mixed Partial derivatives ****************************************************************************/template<typename T>inline _bz_typename T::T_numtypemixed22(T& A, int x, int y){ return A.shift(-1,x,-1,y) - A.shift(-1,x,1,y) - A.shift(1,x,-1,y) + A.shift(1,x,1,y);}template<typename T>inline _bz_typename T::T_numtypemixed22n(T& A, int x, int y){ return mixed22(A,x,y) * recip_4;}template<typename T>inline _bz_typename T::T_numtypemixed24(T& A, int x, int y){ return 64.0 * (A.shift(-1,x,-1,y) - A.shift(-1,x,1,y) - A.shift(1,x,-1,y) + A.shift(1,x,1,y)) + (A.shift(-2,x,1,y) - A.shift(-1,x,2,y) - A.shift(1,x,2,y) - A.shift(2,x,1,y) + A.shift(2,x,-1,y) + A.shift(1,x,-2,y) - A.shift(-1,x,-2,y) + A.shift(-2,x,-1,y)) + 8.0 * (A.shift(-1,x,1,y) + A.shift(-1,x,2,y) - A.shift(2,x,-2,y) + A.shift(2,x,2,y));}template<typename T>inline _bz_typename T::T_numtypemixed24n(T& A, int x, int y){ return mixed24(A,x,y) * recip_144;}/**************************************************************************** * Smoothers ****************************************************************************/// NEEDS_WORK-- put other stencil operators here:// Average5pt2D// Average7pt3D// etc./**************************************************************************** * Stencil operators with geometry (experimental) ****************************************************************************/template<typename T>inline _bz_typename multicomponent_traits<_bz_typename T::T_numtype>::T_element div3DVec4(T& A, const UniformCubicGeometry<3>& geom){ const int x = 0, y = 1, z = 2; return (central14(A, x, firstDim) + central14(A, y, secondDim) + central14(A, z, thirdDim)) * recip_12 * geom.recipSpatialStep();}template<typename T>inline _bz_typename T::T_numtype Laplacian3D4(T& A, const UniformCubicGeometry<3>& geom){ return Laplacian3D4n(A) * geom.recipSpatialStepPow2();}template<typename T>inline _bz_typename T::T_numtype Laplacian3DVec4(T& A, const UniformCubicGeometry<3>& geom){ typedef _bz_typename T::T_numtype vector3d; typedef _bz_typename multicomponent_traits<vector3d>::T_element T_element; const int u = 0, v = 1, w = 2; const int x = 0, y = 1, z = 2; // central24 is a 5-point stencil // This is a 9*5 = 45 point stencil T_element t1 = (central24(A,u,x) + central24(A,u,y) + central24(A,u,z)) * recip_12 * geom.recipSpatialStepPow2(); T_element t2 = (central24(A,v,x) + central24(A,v,y) + central24(A,v,z)) * recip_12 * geom.recipSpatialStepPow2(); T_element t3 = (central24(A,w,x) + central24(A,w,y) + central24(A,w,z)) * recip_12 * geom.recipSpatialStepPow2(); return vector3d(t1,t2,t3);}template<typename T>inline TinyMatrix<_bz_typename multicomponent_traits<_bz_typename T::T_numtype>::T_element, 3, 3>grad3DVec4(T& A, const UniformCubicGeometry<3>& geom){ const int x=0, y=1, z=2; const int u=0, v=1, w=2; TinyMatrix<_bz_typename multicomponent_traits<_bz_typename T::T_numtype>::T_element, 3, 3> grad; // This is a 9*4 = 36 point stencil grad(u,x) = central14n(A,u,x) * geom.recipSpatialStep(); grad(u,y) = central14n(A,u,y) * geom.recipSpatialStep(); grad(u,z) = central14n(A,u,z) * geom.recipSpatialStep(); grad(v,x) = central14n(A,v,x) * geom.recipSpatialStep(); grad(v,y) = central14n(A,v,y) * geom.recipSpatialStep(); grad(v,z) = central14n(A,v,z) * geom.recipSpatialStep(); grad(w,x) = central14n(A,w,x) * geom.recipSpatialStep(); grad(w,y) = central14n(A,w,y) * geom.recipSpatialStep(); grad(w,z) = central14n(A,w,z) * geom.recipSpatialStep(); return grad;}template<typename T>inline TinyVector<_bz_typename T::T_numtype,3> grad3D4(T& A, const UniformCubicGeometry<3>& geom) { return TinyVector<_bz_typename T::T_numtype,3>( central14(A,firstDim) * recip_12 * geom.recipSpatialStep(), central14(A,secondDim) * recip_12 * geom.recipSpatialStep(), central14(A,thirdDim) * recip_12 * geom.recipSpatialStep());}BZ_NAMESPACE_END#endif // BZ_ARRAYSTENCILOPS_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -