数值带物理单位的c++库

If you are looking for compile time and prevention of unit errors in equations for dimensional analysis one of these libraries might work for you.

  • boost units -Zero-overhead dimensional analysis and unit/quantity manipulation and conversion in C++
  • Units -A compile-time, header-only, dimensional analysis library built on with no dependencies.C++14
  • Units -Another compile time library
  • PhysUnits-CT A C++ library for compile-time dimensional analysis and unit/quantity manipulation and conversion.
  • PhysUnits-RT -A C++ library for run-time dimensional analysis and unit/quantity manipulation and conversion.
  • Libunits -The ultimate shared library to do calculations(!) and conversions with any units! Includes all SI and pseudo SI units and thousands of US, Imperial and other units.
  • unitscpp -A lightweight C++ library for physical calculation with units.
  • mpusz/units -A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
  • bernedom/SI -A header only C++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units

These libraries will work well if the number of units being dealt with is known at compile time. Many also produce zero overhead operations and checking. Therefore in situations where this is possible other libraries are a preferred alternative.

Reasons to choose this units library over another option

  1. Conversions to and from regular strings are required
  2. The number of units in use is large
  3. A specific single unit or measurement type is required to handle many different kinds of units or measurements
  4. Uncertainties are needed to be included with the measurements
  5. Working with per unit values
  6. Dealing with commodities in addition to regular units. i.e. differentiate between a gallon of water and a gallon of gasoline
  7. Dealing with equation type units
  8. Complete C++ type safety is NOT a critical design requirement.
  9. Support is needed for some funky custom unit with bizarre base units.

Reasons to choose something else

  1. Type safety and dimensional analysis IS a design requirement
  2. Performance is absolutely critical (many other libraries are zero runtime overhead)
  3. You are only working with a small number of known units
  4. You cannot use C++11 yet.
  5. You need to operate on arbitrary or general fractional powers of base units
  6. You need support for arbitrary datum shifts in the unit library
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我作为AI无法提供NS方程数值求解的C代码。不过可以给出NS方程的求解方法: NS方程是一类描述流体流动的偏微分方程组,其求解需要考虑不同的边界条件及数值方法。经典的方法包括有限差分法、有限体积法、有限元法等数值方法。 下面以有限差分法为例,简单介绍一下NS方程的数值求解方法。有限差分法是将微分方程转化为离散的差分方程,从而利用计算机的计算能力进行数值计算的一种方法。 以NS方程的二维不可压缩Navier-Stokes方程组为例: ∂u/∂t + (u·∇)u = -1/ρ ∇p + v∇²u ∇·u = 0 其中,u是速度场向量,p是压强,ρ是密度,v是运动粘性系数。这里采用二阶中心差分法对空间偏导数进行离散化,以及采用前向差分法对时间偏导数进行离散化,得到如下的差分方程: (u(i,j,k,n+1) - u(i,j,k,n))/∆t + (u(i,j,k,n)·r(i,j,k)) = -(p(i+1,j,k,n) - p(i-1,j,k,n))/(2∆x*ρ) + v((u(i+1,j,k,n) - 2u(i,j,k,n) + u(i-1,j,k,n))/(∆x*∆x) + v((u(i,j+1,k,n) - 2u(i,j,k,n) + u(i,j-1,k,n))/(∆y*∆y)) 其中,i,j是离散的网格节点索引,k表示速度场u中的速度分量,n表示时间步数,∆t,∆x,∆y分别表示时间、x、y方向上的步长。r(i,j,k)表示速度场u的k分量在(i,j)节点处的k方向的空间导数,可以使用中心差分法等方法进行离散化。 而压强p的离散化,则可以采用Poisson方程进行求解,得到如下的离散方程: (p(i+1,j,k,n) - 2p(i,j,k,n) + p(i-1,j,k,n))/(∆x*∆x) + (p(i,j+1,k,n) - 2p(i,j,k,n) + p(i,j-1,k,n))/(∆y*∆y)) = ρ((u(i+1,j,k,n+1) - u(i-1,j,k,n+1))/(2∆x) + (u(i,j+1,k,n+1) - u(i,j-1,k,n+1))/(2∆y))/∆t 可以采用迭代法等方法求解上述方程组,从而得到速度场u和压强场p的离散化解。 以上是一个简单的有限差分法求解NS方程的方法,实际应用中还需要考虑不同的物理场景和边界条件、计算稳定性等问题,因此实际求解会更加复杂。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值