当前位置:网站首页>[splishsplash] custom exporter
[splishsplash] custom exporter
2022-06-12 19:42:00 【beidou111】
#include "ParticleExporter_xyz.h"
#include <Utilities/Logger.h>
#include <Utilities/FileSystem.h>
#include "SPlisHSPlasH/Simulation.h"
#include <limits>
using namespace SPH;
using namespace Utilities;
using namespace std;
ParticleExporter_xyz::ParticleExporter_xyz(SimulatorBase* base) :
ExporterBase(base)
{
m_outfile = nullptr;
}
ParticleExporter_xyz::~ParticleExporter_xyz(void)
{
}
void ParticleExporter_xyz::init(const std::string& outputPath)
{
// define output path for the data
m_exportPath = FileSystem::normalizePath(outputPath + "/xyz");
}
void ParticleExporter_xyz::step(const unsigned int frame)
{
// check if the exporter is active
if (!m_active)
return;
Simulation* sim = Simulation::getCurrent();
for (unsigned int i = 0; i < sim->numberOfFluidModels(); i++)
{
FluidModel* model = sim->getFluidModel(i);
//define the exportFileName
std::string fileName = "Fluid";
fileName = fileName + "_" + std::to_string(frame);
std::string exportFileName = FileSystem::normalizePath(m_exportPath + "/" + fileName + ".in");
// Define the fstream object m_outfile. Open the file
m_outfile = new std::ofstream(exportFileName, std::ios_base::trunc);
if (!m_outfile->is_open())
{
LOG_WARN << "Cannot open a file to save VTK particles.";
return;
}
//output particle number
const unsigned int numParticles = model->numActiveParticles();
*m_outfile << numParticles << std::endl;
//output particle radius
*m_outfile << sim->getParticleRadius() << std::endl;
//output positions
for(unsigned int i = 0; i < numParticles; i++)
{
Vector3f pos = model->getPosition(i);
*m_outfile << pos.x() <<" " <<pos.y() <<" "<<pos.z() << std::endl;
}
}
m_outfile->close();
delete m_outfile;
m_outfile = nullptr;
}
void ParticleExporter_xyz::reset()
{
}
void ParticleExporter_xyz::setActive(const bool active)
{
ExporterBase::setActive(active);
// create output folder
if (m_active)
FileSystem::makeDirs(m_exportPath);
}
#ifndef __ParticleExporter_xyz_h__
#define __ParticleExporter_xyz_h__
#include "ExporterBase.h"
#include <fstream>
#include "SPlisHSPlasH/FluidModel.h"
namespace SPH
{
/** \brief particle exporter, output the positions(xyz) of the particles * line1: particle number * line2: particle radius * line3: bounding box(minimum positions of all particles) * line3: bounding box(maximum positions of all particles) * after: particle positions * */
class ParticleExporter_xyz : public ExporterBase
{
protected:
std::string m_exportPath;
std::ofstream *m_outfile;
public:
ParticleExporter_xyz(SimulatorBase* base);
ParticleExporter_xyz(const ParticleExporter_xyz&) = delete;
ParticleExporter_xyz& operator=(const ParticleExporter_xyz&) = delete;
virtual ~ParticleExporter_xyz(void);
virtual void init(const std::string& outputPath);
virtual void step(const unsigned int frame);
virtual void reset();
virtual void setActive(const bool active);
};
}
#endif
边栏推荐
- 系统 日志
- Shell arrays and functions
- Demand and business model analysis -6- five topics
- DACOM G150 dual-mode earphones make sound for love and protect the healthy growth of children's hearing
- Equipment management - borrowing and returning module 1
- Using / developing private plug-ins in traifik proxy 2.5 (traifik official blog)
- Theory + practice will help you master the dynamic programming method
- system()
- Reading small program based on wechat e-book graduation design (4) opening report
- RT-Thread 模拟器 simulator 搭建 LVGL 的开发调试环境
猜你喜欢

Leetcodesql: count the number of students in each major

Interpreter Files

“即服务”,未来已来,始于现在 | IT消费新模式,FOD按需计费

First build green, then build city

The component style set by uniapp takes effect in H5 and app, but does not take effect in wechat applet. The problem is solved

基于微信电子书阅读小程序毕业设计毕设作品(7)中期检查报告

IO流基础知识详解--文件及IO流原理

PostgreSQL database replication - background first-class citizen process walreceiver PG_ stat_ wal_ Receiver view

New product launch

Microsoft Word 教程,如何在 Word 中插入页眉或页脚?
随机推荐
unity websockt一些知识:
PostgreSQL数据库复制——后台一等公民进程WalReceiver pg_stat_wal_receiver视图
模塊八作業
5G R17标准冻结,主要讲了些啥?
Software usage of Tencent cloud TDP virt viewer win client
基于微信电子书阅读小程序毕业设计毕设作品(1)开发概要
系统 日志
基于微信电子书阅读小程序毕业设计毕设作品(5)任务书
开源深度学习框架PlaidML安装及测试
Promise to solve hell function calls can be used infinitely
[SQL] MySQL query statement execution sequence analysis
3GPP RAN第一次F2F会议,都干了些啥?
Hardware test - why not use grounding clip for ripple test
Interpreter Files
Business opportunities with an annual increase of 3billion - non cage eggs or a new blue ocean for export to ASEAN
设备管理-借还模块界面代码
Jenkins中pipeline对接CMDB接口获取主机列表的发布实践原创
5g R17 standard is frozen. What does it say?
Ctfshow-web265 (deserialization)
基于微信电子书阅读小程序毕业设计毕设作品(2)小程序功能