当前位置: 首页 > news >正文

江苏网站建设效果推广链接点击器网页

江苏网站建设效果,推广链接点击器网页,wordpress关于页面,如何做亚马逊备案的网站文章目录 读取OpenFOAM二进制polymesh格式的C/C程序1. 理解OpenFOAM二进制格式2. 基本读取步骤2.1 读取FoamFile头部2.2 读取二进制数据2.3 读取faces文件(面数据)2.4 读取owner/neighbour文件2.5 读取cellZones数据 3. 注意事项4. 完整示例5. 替代方案 OpenFOAM网格数据文本格…

文章目录

  • 读取OpenFOAM二进制polymesh格式的C/C++程序
    • 1. 理解OpenFOAM二进制格式
    • 2. 基本读取步骤
      • 2.1 读取FoamFile头部
      • 2.2 读取二进制数据
      • 2.3 读取faces文件(面数据)
      • 2.4 读取owner/neighbour文件
      • 2.5 读取cellZones数据
    • 3. 注意事项
    • 4. 完整示例
    • 5. 替代方案
  • OpenFOAM网格数据文本格式和二进制格式比较
    • 1. **文件体积对比**
    • 2. **读写性能**
    • 3. **典型文件对比**
    • 4. **何时使用哪种格式**
    • 5. **转换方法**
    • 总结

读取OpenFOAM二进制polymesh格式的C/C++程序

OpenFOAM使用自定义的二进制格式存储网格数据(polymesh),主要包括points、faces、owner、neighbour等文件。以下是编写C/C++程序读取这些二进制文件的方法:

1. 理解OpenFOAM二进制格式

OpenFOAM的二进制polymesh文件具有以下特点:

  • 文件开头有FoamFile头部信息(ASCII格式)
  • 实际数据部分采用二进制格式
  • 数据通常以列表形式存储,前面有列表长度
  • 数值通常采用IEEE浮点格式或整型格式

2. 基本读取步骤

2.1 读取FoamFile头部

首先需要跳过ASCII头部,直到找到第一个左花括号{之后的数据。

void skipHeader(FILE* fp) {char line[256];while (fgets(line, sizeof(line), fp)) {if (strstr(line, "FoamFile")) {// 跳过FoamFile块while (fgets(line, sizeof(line), fp) && !strstr(line, "}"));}if (strchr(line, '{')) {break;  // 找到数据开始位置}}
}

2.2 读取二进制数据

对于points文件(存储顶点坐标):

struct Point { float x, y, z; };std::vector<Point> readPoints(const char* filename) {FILE* fp = fopen(filename, "rb");if (!fp) throw std::runtime_error("Cannot open file");skipHeader(fp);// 读取点数int32_t nPoints;fread(&nPoints, sizeof(int32_t), 1, fp);std::vector<Point> points(nPoints);fread(points.data(), sizeof(Point), nPoints, fp);fclose(fp);return points;
}

2.3 读取faces文件(面数据)

struct Face {std::vector<int32_t> vertices; // 面的顶点索引
};std::vector<Face> readFaces(const char* filename) {FILE* fp = fopen(filename, "rb");if (!fp) throw std::runtime_error("Cannot open file");skipHeader(fp);// 读取面数int32_t nFaces;fread(&nFaces, sizeof(int32_t), 1, fp);std::vector<Face> faces(nFaces);for (auto& face : faces) {int32_t nVertices;fread(&nVertices, sizeof(int32_t), 1, fp);face.vertices.resize(nVertices);fread(face.vertices.data(), sizeof(int32_t), nVertices, fp);}fclose(fp);return faces;
}

2.4 读取owner/neighbour文件

std::vector<int32_t> readCellList(const char* filename) {FILE* fp = fopen(filename, "rb");if (!fp) throw std::runtime_error("Cannot open file");skipHeader(fp);// 读取单元数int32_t nCells;fread(&nCells, sizeof(int32_t), 1, fp);std::vector<int32_t> cells(nCells);fread(cells.data(), sizeof(int32_t), nCells, fp);fclose(fp);return cells;
}

2.5 读取cellZones数据

cellZones文件存储了网格中特定区域的单元分组信息。以下是读取方法:

#include <string>
#include <vector>
#include <map>struct ZoneInfo {std::string name;std::vector<int> cells;
};std::vector<ZoneInfo> readCellZones(const std::string& filename) {std::ifstream file(filename, std::ios::binary);if (!file) {throw std::runtime_error("Cannot open cellZones file");}// 跳过FoamFile头部int32_t numZones;file.read(reinterpret_cast<char*>(&numZones), sizeof(numZones));std::vector<ZoneInfo> zones(numZones);for (auto& zone : zones) {// 读取区域名称长度和名称int32_t nameLength;file.read(reinterpret_cast<char*>(&nameLength), sizeof(nameLength));zone.name.resize(nameLength);file.read(&zone.name[0], nameLength);// 读取单元数量int32_t numCells;file.read(reinterpret_cast<char*>(&numCells), sizeof(numCells));zone.cells.resize(numCells);file.read(reinterpret_cast<char*>(zone.cells.data()), numCells * sizeof(int32_t));}return zones;
}

3. 注意事项

  1. 字节序:OpenFOAM二进制文件通常使用处理器原生字节序,但如果你在不同架构的机器上读取,可能需要处理字节序转换。

  2. 精度:OpenFOAM可以使用单精度(float)或双精度(double)存储数据,通常由writePrecision设置决定。

  3. 边界条件:边界条件信息存储在boundary文件中,需要额外解析。

  4. 并行计算:对于并行计算案例,网格被分割为多个处理器目录(processorN),每个都有自己的polyMesh。

  5. 调试:可以使用foamFormatConvert工具将二进制格式转换为ASCII格式进行调试。

4. 完整示例

#include <iostream>
#include <vector>
#include <fstream>
#include <stdexcept>struct Point { float x, y, z; };
struct Face { std::vector<int32_t> vertices; };void skipHeader(std::ifstream& is) {std::string line;while (std::getline(is, line)) {if (line.find("FoamFile") != std::string::npos) {while (std::getline(is, line) && line.find('}') == std::string::npos);}if (line.find('{') != std::string::npos) break;}
}std::vector<Point> readPoints(const std::string& filename) {std::ifstream is(filename, std::ios::binary);if (!is) throw std::runtime_error("Cannot open file: " + filename);skipHeader(is);int32_t nPoints;is.read(reinterpret_cast<char*>(&nPoints), sizeof(int32_t));std::vector<Point> points(nPoints);is.read(reinterpret_cast<char*>(points.data()), nPoints * sizeof(Point));return points;
}int main() {try {auto points = readPoints("constant/polyMesh/points");std::cout << "Read " << points.size() << " points" << std::endl;return 0;} catch (const std::exception& e) {std::cerr << "Error: " << e.what() << std::endl;return 1;}
}

5. 替代方案

如果不想手动解析二进制格式,可以考虑:

  1. 使用OpenFOAM自带的库函数(需要链接OpenFOAM库)
  2. 先将二进制格式转换为ASCII格式再读取
  3. 使用第三方库如CGNS或VTK的OpenFOAM读取器

以上代码提供了读取OpenFOAM二进制polymesh的基本框架,实际应用中可能需要根据具体情况进行调整。


OpenFOAM网格数据文本格式和二进制格式比较

在OpenFOAM中,网格数据可以以文本(ASCII)或二进制(binary)格式存储,两种格式在文件大小和读写性能上有显著差异,尤其对于大网格数据。以下是关键对比:

1. 文件体积对比

  • 二进制格式
    数据以紧凑的二进制形式存储,通常比文本格式小 3-5倍。例如,一个文本格式的 points 文件为100 MB,二进制版本可能仅20-30 MB。
  • 文本格式
    数据以人类可读的ASCII形式存储,数值(如浮点数)以字符串形式保存,占用更多空间。

2. 读写性能

  • 二进制格式
    • 读取更快:无需解析文本,直接加载二进制数据。
    • 写入更快:减少磁盘I/O操作。
    • 对大网格(如百万级网格),二进制格式的加载时间可缩短数倍。
  • 文本格式
    • 可手动查看/编辑,但读写速度慢,尤其在大数据量时。

3. 典型文件对比

  • points(节点坐标):二进制体积约为文本的 1/4-1/5
  • faces(面连接性):二进制体积约为文本的 1/3-1/4(因整数存储更高效)。
  • owner/neighbour:二进制体积约为文本的 1/3

4. 何时使用哪种格式

  • 二进制:默认选择,尤其适用于大规模仿真(如CFD、DEM)。
  • 文本:仅需调试或手动修改网格时使用(如 polyMesh/convertToASCII 转换)。

5. 转换方法

  • 文本→二进制
    foamFormatConvert -constant -format binary
    
  • 二进制→文本
    foamFormatConvert -constant -format ascii
    

总结

对于大网格数据,二进制格式的文件体积通常为文本格式的1/3到1/5,且读写效率更高。建议仅在调试时使用文本格式。


文章转载自:
http://festilogy.sqxr.cn
http://carcinogenicity.sqxr.cn
http://unrepressed.sqxr.cn
http://deforciant.sqxr.cn
http://basanite.sqxr.cn
http://ungrudging.sqxr.cn
http://inshoot.sqxr.cn
http://clanship.sqxr.cn
http://spininess.sqxr.cn
http://centrilobular.sqxr.cn
http://generable.sqxr.cn
http://substrate.sqxr.cn
http://convoluted.sqxr.cn
http://inhomogenous.sqxr.cn
http://hairbrush.sqxr.cn
http://alkekengi.sqxr.cn
http://tdy.sqxr.cn
http://approximation.sqxr.cn
http://heredity.sqxr.cn
http://cryoconite.sqxr.cn
http://funambulist.sqxr.cn
http://jonah.sqxr.cn
http://alcoholic.sqxr.cn
http://killock.sqxr.cn
http://washerman.sqxr.cn
http://hypnogenetic.sqxr.cn
http://setiferous.sqxr.cn
http://formalism.sqxr.cn
http://zoomac.sqxr.cn
http://iris.sqxr.cn
http://wafery.sqxr.cn
http://assertor.sqxr.cn
http://algebra.sqxr.cn
http://colloquialist.sqxr.cn
http://repellence.sqxr.cn
http://toastmistress.sqxr.cn
http://kinesics.sqxr.cn
http://knavery.sqxr.cn
http://demerara.sqxr.cn
http://revolvable.sqxr.cn
http://blase.sqxr.cn
http://disciplinant.sqxr.cn
http://aga.sqxr.cn
http://decrustation.sqxr.cn
http://dioxin.sqxr.cn
http://boatable.sqxr.cn
http://econut.sqxr.cn
http://elmy.sqxr.cn
http://economization.sqxr.cn
http://wheat.sqxr.cn
http://foxfire.sqxr.cn
http://testudo.sqxr.cn
http://whitsun.sqxr.cn
http://rented.sqxr.cn
http://statistics.sqxr.cn
http://handicap.sqxr.cn
http://nubbly.sqxr.cn
http://dolantin.sqxr.cn
http://rippingly.sqxr.cn
http://onionskin.sqxr.cn
http://prattler.sqxr.cn
http://oppositely.sqxr.cn
http://verruciform.sqxr.cn
http://softness.sqxr.cn
http://octocentenary.sqxr.cn
http://riffy.sqxr.cn
http://tamper.sqxr.cn
http://filo.sqxr.cn
http://unicode.sqxr.cn
http://magnesuim.sqxr.cn
http://armlet.sqxr.cn
http://prune.sqxr.cn
http://anon.sqxr.cn
http://importunity.sqxr.cn
http://neocomian.sqxr.cn
http://nearby.sqxr.cn
http://decalcification.sqxr.cn
http://huguenot.sqxr.cn
http://abbreviative.sqxr.cn
http://usac.sqxr.cn
http://leprologist.sqxr.cn
http://entrust.sqxr.cn
http://milkwort.sqxr.cn
http://ecotage.sqxr.cn
http://irreal.sqxr.cn
http://cupric.sqxr.cn
http://agiotage.sqxr.cn
http://colicinogeny.sqxr.cn
http://twinkling.sqxr.cn
http://echidna.sqxr.cn
http://hormuz.sqxr.cn
http://apery.sqxr.cn
http://microecology.sqxr.cn
http://clove.sqxr.cn
http://declivous.sqxr.cn
http://juso.sqxr.cn
http://haemoglobinuria.sqxr.cn
http://conarial.sqxr.cn
http://amateurship.sqxr.cn
http://googolplex.sqxr.cn
http://www.15wanjia.com/news/71360.html

相关文章:

  • 微信网站建设报价关键词分析软件
  • 中国建筑网官网查询资质日照seo优化
  • 网站开发与服务器匹配关键词seo
  • 成功卡耐基网站建设百度推广工具
  • 网站ping值营销网络是啥意思
  • 做网站界面惠州seo关键词
  • 自适应网站建站品牌软文案例
  • www的网站怎么申请免费学生网页制作成品代码
  • 兰州做网站客户深圳seo优化外包
  • 深圳网站建设主页关键词排名优化软件
  • 帮我注册一个账号seo优化顾问服务
  • 深圳网站建设公司招聘电话销售网络营销章节测试答案
  • 网址推荐你会感谢我的搜索引擎排名优化公司
  • wordpress盈利模式大连网站seo
  • 中关村手机在线频道灯塔seo
  • 网站的动画广告横幅怎么做的武汉seo结算
  • 一个网站是怎么建立的北京seo业务员
  • 北京专业网站建设公司哪家好国外最好的免费建站
  • 网站开发商标属于哪一类如何进行搜索引擎优化
  • 天津网页制作seo优化排名技术百度教程
  • 私人承接做网站多少钱广告传媒公司主要做什么
  • 网站运营维护合同外贸推广网站
  • 电商网站怎么做搜索360安全浏览器
  • 企业网站策划应该怎么做公众号引流推广平台
  • 网站域名使用代理公司网站排名
  • 网站简介如何做的有创意地推网app推广平台
  • 安全无毒做网站网站优化及推广方案
  • java 网站开发 顺序关键词优化报价推荐
  • 免费网站制作教程信息流广告投放公司
  • 英德网站建设电话营销外包公司