Tonatiuh-实际案例

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();

应用建议

  1. 初学者:使用定日镜场向导快速创建系统
  2. 研究人员:结合脚本进行参数化研究和优化
  3. 工程师:使用脚本实现复杂的自动化建模流程

进一步学习

  1. 建议将脚本保存为 .tnhs 文件,便于管理和重用
  2. 确保所有文件路径设置正确,特别是仿真结果的导出路径
  3. 从简单场景开始,逐步增加复杂度来掌握各种功能
  4. 可参考ECMAScript规范文档了解更多语法特性
相关推荐
zhangfeng113330 分钟前
平替 Claude Code 类似的开源项目 — GitHub Star 前十排名
开源·github·claude code
DogDaoDao41 分钟前
【GitHub】Warp 终端深度解析:Rust + GPU 加速的 AI 原生终端开源架构
人工智能·程序员·rust·开源·github·ai编程·warp
kyriewen12 小时前
奥特曼借GPT-5.5干杯,而你的Copilot正按Token收钱
前端·github·openai
jinanwuhuaguo14 小时前
(第三十三篇)五月的文明奠基:OpenClaw 2026.5.2版本的文明级解读
android·java·开发语言·人工智能·github·拓扑学·openclaw
DogDaoDao15 小时前
【GitHub】andrej-karpathy-skills:让 AI 编程助手告别三大通病
人工智能·深度学习·程序员·大模型·github·ai编程·andrej-karpathy
Shin_chan17 小时前
Linux 内核史诗级提权漏洞:CVE-2026-31431 复现与分析
github
CoderJia程序员甲19 小时前
GitHub 热榜项目 - 日榜(2026-05-03)
ai·大模型·llm·github·ai教程
yyuuuzz20 小时前
aws 基础认知与实践注意点
运维·服务器·网络·云计算·github·aws
weixin_5142531821 小时前
430-github-aguvis tmux
github
阿里嘎多学长1 天前
2026-05-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管