1 Star 1 Fork 0

xjtu-forge/mantaflow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vortexpart.cpp 2.75 KB
一键复制 编辑 原始数据 按行查看 历史
Nils Thuerey 提交于 7年前 . license update
/******************************************************************************
*
* MantaFlow fluid solver framework
* Copyright 2011 Tobias Pfaff, Nils Thuerey
*
* This program is free software, distributed under the terms of the
* Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Vortex particles
* (warning, the vortex methods are currently experimental, and not fully supported!)
*
******************************************************************************/
#include "vortexpart.h"
#include "integrator.h"
#include "mesh.h"
using namespace std;
namespace Manta {
// vortex particle effect: (cyl coord around wp)
// u = -|wp|*rho*exp( (-rho^2-z^2)/(2sigma^2) ) e_phi
inline Vec3 VortexKernel(const Vec3& p, const vector<VortexParticleData>& vp, Real scale) {
Vec3 u(0.0);
for (size_t i=0; i<vp.size(); i++) {
if (vp[i].flag & ParticleBase::PDELETE) continue;
// cutoff radius
const Vec3 r = p - vp[i].pos;
const Real rlen2 = normSquare(r);
const Real sigma2 = square(vp[i].sigma);
if (rlen2 > 6.0 * sigma2 || rlen2 < 1e-8) continue;
// split vortex strength
Vec3 vortNorm = vp[i].vorticity;
Real strength = normalize(vortNorm) * scale;
// transform in cylinder coordinate system
const Real rlen = sqrt(rlen2);
const Real z = dot(r, vortNorm);
const Vec3 ePhi = cross(r, vortNorm) / rlen;
const Real rho2 = rlen2 - z*z;
Real vortex = 0;
if (rho2 > 1e-10) {
// evaluate Kernel
vortex = strength * sqrt(rho2) * exp (rlen2 * -0.5/sigma2);
}
u += vortex * ePhi;
}
return u;
}
KERNEL(pts) returns(vector<Vec3> u(size))
vector<Vec3> KnVpAdvectMesh(vector<Node>& nodes, const vector<VortexParticleData>& vp, Real scale) {
if (nodes[idx].flags & Mesh::NfFixed)
u[idx] = 0.0;
else
u[idx] = VortexKernel(nodes[idx].pos, vp, scale);
}
KERNEL(pts) returns(vector<Vec3> u(size))
vector<Vec3> KnVpAdvectSelf(vector<VortexParticleData>& vp, Real scale) {
if (vp[idx].flag & ParticleBase::PDELETE)
u[idx] = 0.0;
else
u[idx] = VortexKernel(vp[idx].pos, vp, scale);
}
VortexParticleSystem::VortexParticleSystem(FluidSolver* parent) :
ParticleSystem<VortexParticleData>(parent)
{
}
void VortexParticleSystem::advectSelf(Real scale, int integrationMode) {
KnVpAdvectSelf kernel(mData, scale* getParent()->getDt());
integratePointSet( kernel, integrationMode);
}
void VortexParticleSystem::applyToMesh(Mesh& mesh, Real scale, int integrationMode) {
KnVpAdvectMesh kernel(mesh.getNodeData(), mData, scale* getParent()->getDt());
integratePointSet( kernel, integrationMode);
}
ParticleBase* VortexParticleSystem::clone() {
VortexParticleSystem* nm = new VortexParticleSystem(getParent());
compress();
nm->mData = mData;
nm->setName(getName());
return nm;
}
} // namespace
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xjtu-forge/mantaflow.git
git@gitee.com:xjtu-forge/mantaflow.git
xjtu-forge
mantaflow
mantaflow
master

搜索帮助