【Velocity】关于#foreach的累加

博主遇到遍历后累计相加的需求,初用vm进行开发,经过无数次尝试,最终成功实现随手记账单小程序,期待大家的反馈。

今天遇到了一个需求 遍历出来后累计相加 vm才接触 就想用这个给它整出来

  $sun = 0
  #foreach($!result in $!map.page.list)
    $sum += $result.num)
  #end

不行……

  $sun = 0
  #foreach($!result in $!map.page.list)
    $sum = $sum + $result.num)
  #end

漂亮……不行

  #foreach($!result in $!map.page.list)
    #set($sum = $sum + $result.num))
  #end

哔了狗了

经过了无数次的尝试 列举了以上几种不行的 终于给它整出来了 初用vm 垃圾小白 大神路过就好 感谢

  #set($sum = 0)
  #foreach($!result in $!map.page.list)
    #set($sum = $sum + $result.num)
  #end
  $sum

随手记账单小程序 期待大家的反馈

微信图片_20200907143529.jpg

Surface force and vorticity We first define a function which computes ∇u⋅n∇u⋅n while taking the boundary conditions on the embedded surface into account. static inline coord embed_gradient (Point point, vector u, coord p, coord n) { coord dudn; foreach_dimension() { bool dirichlet = false; double vb = u.x.boundary[embed] (point, point, u.x, &dirichlet); if (dirichlet) { double val; dudn.x = dirichlet_gradient (point, u.x, cs, n, p, vb, &val); } else // Neumann dudn.x = vb; if (dudn.x == nodata) dudn.x = 0.; } return dudn; } The force exerted by the fluid on the solid can be written FΓ=−∫∂Γ(−pI+2μD)⋅nd∂ΓFΓ​=−∫∂Γ​(−pI+2μD)⋅nd∂Γ with ΓΓ the solid boundary. It can be further decomposed into a pressure (i.e. “form”) drag Fp=∫∂Γpnd∂ΓFp​=∫∂Γ​pnd∂Γ and a viscous drag Fμ=−∫∂Γ2μD⋅nd∂ΓFμ​=−∫∂Γ​2μD⋅nd∂Γ These two vectors are computed by the embed_force() function. trace void embed_force (scalar p, vector u, face vector mu, coord * Fp, coord * Fmu) { coord Fps = {0}, Fmus = {0}; foreach (reduction(+:Fps) reduction(+:Fmus), nowarning) if (cs[] > 0. && cs[] < 1.) { To compute the pressure force, we first get the coordinates of the barycentre of the embedded fragment, its area and normal, and then interpolate the pressure field on the surface. coord n, b; double area = embed_geometry (point, &b, &n); area *= pow (Delta, dimension - 1); double Fn = area*embed_interpolate (point, p, b); foreach_dimension() Fps.x += Fn*n.x; To compute the viscous force, we first need to retrieve the local value of the viscosity (ideally at the barycentre of the embedded fragment). This is not completely trivial since it is defined on the faces of the cell. We use a surface-fraction-weighted average value. if (constant(mu.x) != 0.) { double mua = 0., fa = 0.; foreach_dimension() { mua += mu.x[] + mu.x[1]; fa += fm.x[] + fm.x[1]; } mua /= fa; To compute the viscous force, we need to take into account the (Dirichlet) boundary conditions for the velocity on the surface. We only know how to do this when computing the normal gradient ∇u⋅n∇u⋅n using the embed_gradient() function. We thus need to re-express the viscous force using only normal derivatives of the velocity field. If we assume that uu is constant on the boundary, then ∇u⋅t=0∇u⋅t=0 with tt the unit tangent vector to the boundary. We thus have the relations ∇u=(∇u⋅n)n+(∇u⋅t)t=(∇u⋅n)n∇u=(∇u⋅n)n+(∇u⋅t)t=(∇u⋅n)n D=12(∇u+∇Tu)=12(2(∇u⋅n)nx(∇u⋅n)ny+(∇v⋅n)nx(∇u⋅n)ny+(∇v⋅n)nx2(∇v⋅n)ny)D=21​(∇u+∇Tu)=21​(2(∇u⋅n)nx​(∇u⋅n)ny​+(∇v⋅n)nx​​(∇u⋅n)ny​+(∇v⋅n)nx​2(∇v⋅n)ny​​) Fμ=−∫Γ([2μ(∇u⋅n)nx]nx+μ[(∇u⋅n)ny+(∇v⋅n)nx]ny[2μ(∇v⋅n)ny]ny+μ[(∇u⋅n)ny+(∇v⋅n)nx]nx)Fμ​=−∫Γ​([2μ(∇u⋅n)nx​]nx​+μ[(∇u⋅n)ny​+(∇v⋅n)nx​]ny​[2μ(∇v⋅n)ny​]ny​+μ[(∇u⋅n)ny​+(∇v⋅n)nx​]nx​​) Fμ=−∫Γ(μ[(∇u⋅n)(nx2+1)+(∇v⋅n)nxny]μ[(∇v⋅n)(ny2+1)+(∇u⋅n)nxny])Fμ​=−∫Γ​(μ[(∇u⋅n)(nx2​+1)+(∇v⋅n)nx​ny​]μ[(∇v⋅n)(ny2​+1)+(∇u⋅n)nx​ny​]​) assert (dimension == 2); coord dudn = embed_gradient (point, u, b, n); foreach_dimension() Fmus.x -= area*mua*(dudn.x*(sq(n.x) + 1.) + dudn.y*n.x*n.y); } } *Fp = Fps; *Fmu = Fmus; } In two dimensions, embed_vorticity() returns the vorticity of velocity field u, on the surface of the embedded boundary contained in the cell. p is the relative position of the barycentre of the embedded fragment and n its normal. #if dimension == 2 double embed_vorticity (Point point, vector u, coord p, coord n) { We compute ∇u⋅n∇u⋅n, taking the boundary conditions into account. coord dudn = embed_gradient (point, u, p, n); The vorticity is then obtained using the relations ω=∂xv−∂yu=(∇v⋅n)nx−(∇u⋅n)nyω=∂x​v−∂y​u=(∇v⋅n)nx​−(∇u⋅n)ny​ return dudn.y*n.x - dudn.x*n.y; } #endif // dimension == 2 将以上官网的代码中穿插的解释翻印并总结,并总结其中的所有代码
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值