9 实际案例:创建小型定日镜塔系统
第一步:建模塔架
节点结构:
scss
SunNode/RootNode/
└── Tower (分组节点)
└── Base (分组节点,设置位置)
└── TowerBaseSurface (表面节点)
└── Cone (形状节点)
javascript
ruby
// 从空系统开始
tonatiuh.New();
// 选择根节点并创建塔架结构
tonatiuh.SelectNode("//SunNode/RootNode");
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode("//SunNode/RootNode/TSeparatorKit1");
tonatiuh.SetNodeName("Tower");
// 创建塔基
tonatiuh.SelectNode("//SunNode/RootNode/Tower");
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode("//SunNode/RootNode/Tower/TSeparatorKit1");
tonatiuh.SetNodeName("Base");
// 设置塔基位置和创建表面
tonatiuh.SetValue("//SunNode/RootNode/Tower/Base","translation","0 0 76.35");
tonatiuh.CreateSurfaceNode();
tonatiuh.SelectNode("//SunNode/RootNode/Tower/Base/TShapeKit1");
tonatiuh.SetNodeName("TowerBaseSurface");
// 创建圆锥形状
tonatiuh.CreateShape("Cone");
var baseSurfaceNode = "//SunNode/RootNode/Tower/Base/TowerBaseSurface/Cone";
tonatiuh.SetValue(baseSurfaceNode, "baseRadius", "3");
tonatiuh.SetValue(baseSurfaceNode, "topRadius", "2");
tonatiuh.SetValue(baseSurfaceNode, "height", "135");
第二步:建模接收器
javascript
ruby
// 创建接收器结构
tonatiuh.SelectNode("//SunNode/RootNode/Tower");
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode("//SunNode/RootNode/Tower/TSeparatorKit1");
tonatiuh.SetNodeName("Target");
// 设置位置和旋转
tonatiuh.SetValue("//SunNode/RootNode/Tower/Target","translation","0 130 74.25");
tonatiuh.SetValue("//SunNode/RootNode/Tower/Target","rotation","-1 0 0 1.5707964");
// 创建旋转节点和表面
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode("//SunNode/RootNode/Tower/Target/TSeparatorKit1");
tonatiuh.SetNodeName("TargetRotationNode");
tonatiuh.SetValue("//SunNode/RootNode/Tower/Target/TargetRotationNode","rotation","0 1 0 3.1415927");
// 创建接收器表面
tonatiuh.CreateSurfaceNode();
tonatiuh.SelectNode("//SunNode/RootNode/Tower/Target/TargetRotationNode/TShapeKit1");
tonatiuh.SetNodeName("TargetSurface");
tonatiuh.CreateShape("Flat_Rectangle");
tonatiuh.CreateMaterial("Specular_Standard_Material");
var targetShapeNode = "//SunNode/RootNode/Tower/Target/TargetRotationNode/TargetSurface/Flat_Rectangle";
tonatiuh.SetValue(targetShapeNode, "width", "10");
tonatiuh.SetValue(targetShapeNode, "height", "10");
第三步:建模定日镜场
javascript
ini
// 创建20行x25列定日镜场
var rootnode = "//SunNode/RootNode";
tonatiuh.SelectNode(rootnode);
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode(rootnode.concat("/TSeparatorKit1"));
tonatiuh.SetNodeName("HeliostatField");
var fieldPath = rootnode.concat("/HeliostatField");
var zCoord = -52.3;
var rGap = 5.5;
for(r = 1; r <= 20; ++r){
tonatiuh.SelectNode(fieldPath);
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode(fieldPath.concat("/TSeparatorKit1"));
var rowName = "Row".concat(r);
tonatiuh.SetNodeName(rowName);
var rowPath = fieldPath.concat("/", rowName);
var rowZ = zCoord + (r - 1) * rGap;
tonatiuh.SetValue(rowPath, "translation", "0 0".concat(" ", rowZ));
var xCoord = -66;
var hGap = 5.5;
for(h = 1; h <= 25; ++h){
tonatiuh.SelectNode(rowPath);
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode(rowPath.concat("/TSeparatorKit1"));
var heliostatName = "Heliostat".concat(h);
var heliostatPath = rowPath.concat("/", heliostatName);
tonatiuh.SetNodeName(heliostatName);
var heliostatX = xCoord + (h - 1) * hGap;
tonatiuh.SetValue(heliostatPath, "translation", heliostatX.toString().concat(" 0 0"));
tonatiuh.CreateGroupNode();
tonatiuh.SelectNode(heliostatPath.concat("/TSeparatorKit1"));
tonatiuh.SetNodeName("HeliostatTrackerNode");
var heliostatTrackerPath = heliostatPath.concat("/HeliostatTrackerNode");
tonatiuh.SelectNode(heliostatTrackerPath);
tonatiuh.CreateTracker("Heliostat_tracker");
tonatiuh.SetValue(heliostatTrackerPath.concat("/Heliostat_tracker"), "aimingPoint", "0 130 74.25");
if(r == 1 && h == 1){
tonatiuh.CreateSurfaceNode();
tonatiuh.SelectNode(heliostatTrackerPath.concat("/TShapeKit1"));
tonatiuh.SetNodeName("HeliostatSurface");
var heliostatSurfacePath = heliostatTrackerPath.concat("/HeliostatSurface");
tonatiuh.CreateShape("Spherical_rectangle");
tonatiuh.SetValue(heliostatSurfacePath.concat("/Spherical_rectangle"), "radius", "300");
tonatiuh.SetValue(heliostatSurfacePath.concat("/Spherical_rectangle"), "widthX", "5");
tonatiuh.SetValue(heliostatSurfacePath.concat("/Spherical_rectangle"), "widthZ", "5");
tonatiuh.SetValue(heliostatSurfacePath.concat("/Spherical_rectangle"), "activeSide", "INSIDE");
tonatiuh.CreateMaterial("Specular_Standard_Material");
tonatiuh.SetValue(heliostatSurfacePath.concat("/Specular_Standard_Material"), "m_reflectivity", "1");
tonatiuh.Copy();
}
else{
tonatiuh.PasteLink();
}
}
}
第四步:完整仿真配置和运行
javascript
csharp
// === 环境配置 ===
tonatiuh.ChangeSunPosition(0, 90);
tonatiuh.SetSunshape("Pillbox_Sunshape");
tonatiuh.SetSunshapeParameter("irradiance", "920");
tonatiuh.SetSunshapeParameter("thetaMax", "0.00465");
tonatiuh.SetTransmissivity("Ballestrin Transmissivity");
// === 光线追踪配置 ===
tonatiuh.SetRaysPerIteration(2000000);
tonatiuh.SetRandomDeviateType("Mersenne Twister");
tonatiuh.SetRayCastingGrid(300, 300);
tonatiuh.SetRaysDrawingOptions(false, false);
tonatiuh.SetPhotonMapBufferSize(5000000);
tonatiuh.SetIncreasePhotonMap(false);
// === 数据导出配置 ===
tonatiuh.SetExportPhotonMapType("Binary_file");
tonatiuh.SetExportCoordinates(true, false);
tonatiuh.SetExportIntersectionSurface(false);
tonatiuh.SetExportIntersectionSurfaceSide(true);
tonatiuh.SetExportPreviousNextPhotonID(false);
var targetSurface = "//SunNode/RootNode/Tower/Target/TargetRotationNode/TargetSurface";
tonatiuh.AddExportSurfaceURL(targetSurface);
var exportDir = "C:/SimulationResults";
tonatiuh.SetExportTypeParameterValue("ExportDirectory", exportDir);
tonatiuh.SetExportTypeParameterValue("ExportFile", "TargetData");
tonatiuh.SetExportTypeParameterValue("FileSize", "-1");
// === 运行仿真 ===
tonatiuh.Run();
应用建议
- 初学者:使用定日镜场向导快速创建系统
- 研究人员:结合脚本进行参数化研究和优化
- 工程师:使用脚本实现复杂的自动化建模流程
进一步学习
- 建议将脚本保存为
.tnhs
文件,便于管理和重用 - 确保所有文件路径设置正确,特别是仿真结果的导出路径
- 从简单场景开始,逐步增加复杂度来掌握各种功能
- 可参考ECMAScript规范文档了解更多语法特性