首页 > 其他分享 >OFtutorial01_inputOutput解析

OFtutorial01_inputOutput解析

时间:2024-08-09 14:05:41浏览次数:6  
标签:someBool customDict someScalar dictionary inputOutput OFtutorial01 customPropert

OFtutorial1.C

源码解析

#include "fvCFD.H"

int main(int argc, char *argv[])
{
    // Initialise OF case
    #include "setRootCase.H"

    // These two create the time system (instance called runTime) and fvMesh (instance called mesh).
    #include "createTime.H"<details>
    #include "createMesh.H"

    // ---
    // Get access to a custom dictionary
    dictionary customDict;
    const word dictName("customProperties");#定义一个word对象dictName,用来存放customProperties文件名称
    // Create and input-output object - this holds the path to the dict and its name
    IOobject dictIO
    (
        dictName, // name of the file
        mesh.time().constant(), // path to where the file is
        mesh, // reference to the mesh needed by the constructor
        IOobject::MUST_READ // indicate that reading this dictionary is compulsory
    );

    // Check the if the dictionary is present and follows the OF format
    if (!dictIO.typeHeaderOk<dictionary>(true))
        FatalErrorIn(args.executable()) << "Cannot open specified refinement dictionary "
            << dictName << exit(FatalError);

    // Initialise the dictionary object
    customDict = IOdictionary(dictIO);

    // ---
    // Read various pieces of information from the main part of the dictionary

    // Lookup which does not need to be told what type of variable we're looking for and
    // uses the standard C++ stringstream syntax
    word someWord;
    customDict.lookup("someWord") >> someWord;

    // This template method needs to know the type of the variable and can provide
    // a default value if the entry is not found in the dictionary
    scalar someScalar( customDict.lookupOrDefault<scalar>("someScalar", 1.0) );#定义一个scalar类对象someScalar, 这个字典对象customDict的lookup函数找到这个对象customDict的关键词"someScalar"的值,然后放入someScalar中去。如果没有,默认为1.

    // A switch is a neat feature allowing boolean values to be read from a dict,
    // it supports the OpenFOAM yes/on/true/1 and no/off/false/0 values automatically.
    bool someBool ( customDict.lookupOrDefault<Switch>("someBool",true) );#定义一个bool类对象someBool,这个对象someBool通过字典对象customDict的lookup函数找到这个对象customDict的关键词" someBool "的值,然后放入someBool中去。

    // Lists of values may also be read in the same way
    List<scalar> someList ( customDict.lookup("someList") );

    // This type of container is particularly interesting - it associates entries with
    // given key values (here of word type but can be anything); useful when
    // associating things by indices in a list is less handy
    HashTable<vector,word> someHashTable ( customDict.lookup("someHashTable") );

    // Summarise what's been read and print in the console
    Info << nl << "Read the following:" << nl << nl
         << "someWord " << someWord << nl << nl
         << "someScalar " << someScalar << nl << nl
         << "someList " << someList << nl << nl
         << "someHashTable " << someHashTable << nl << nl
         << "someBool " << someBool << nl << nl
         << endl;

    // ---
    // Create a custom directory and write an output file

    // Create the output path directory
    fileName outputDir = mesh.time().path()/"postProcessing";
    // Creathe the directory
    mkDir(outputDir);

    // File pointer to direct the output to
	autoPtr<OFstream> outputFilePtr;
    // Open the file in the newly created directory
    outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat"));

    // Write stuff
    outputFilePtr() << "# This is a header" << endl;
    outputFilePtr() << "0 1 2 3 4 5" << endl;

    // Append to the imported hash table and wirte it too
    someHashTable.insert("newKey", vector(1., 0., 0.));
    outputFilePtr() << someHashTable << endl;

    Info<< "End\n" << endl;
    return 0;
}

小结

该求解器读取customProperties文件中的内容并将需要的内容输出到customOutputFile.dat中

Make、Allwclean、Allwmake

这三个文件(目录)与上期OFtutorial00_helloWorld解析类似,此处不做赘述

testcase

组成如图所示

与OFtutorial00相同,没有调用system、constant(除customProperties外)中的文件,其内容可以忽略

标签:someBool,customDict,someScalar,dictionary,inputOutput,OFtutorial01,customPropert
From: https://www.cnblogs.com/ouqiyo/p/18350642

相关文章

  • 探秘华为桌面云:架构解析与核心优势
    一、华为桌面云深度解读1.华为桌面云概念解析华为云FusionAccess桌面云,作为一种创新的虚拟桌面解决方案,借助云平台在硬件层面的部署,实现了用户通过瘦客户端或其他联网设备访问跨平台应用程序及完整虚拟桌面的可能。2.华为桌面云的价值体现数据安全上移,保障信息安全高效......
  • Linux:Linux权限解析
    一、Linux下的用户分类 在Linux下,有两种用户,一种是超级用户,一种是普通用户超级用户:可以再linux系统下做任何事情,不受权限限制(制定规则,但不需要遵守规则)普通用户:在linux下做有限的事情。(必须遵守相应的规则)超级用户的命令提示符是“#”,普通用户的命令提示符是“$”1、......
  • vue中methods、mounted等的使用方法解析
    created:html加载完成之前,执行。执行顺序:父组件-子组件mounted:html加载完成后执行。执行顺序:子组件-父组件methods:事件方法执行watch:去监听一个值的变化,然后执行相对应的函数computed:computed是计算属性,也就是依赖其它的属性计算所得出最后的值 vue中localstorage用法......
  • SVG之Path路径详解(二),全面解析贝塞尔曲线
    前言如果没看过上一篇文章,可以点击链接前往观看,循序渐进,体验更佳在进入正题前,先温习一下svg的坐标系,x轴为水平向右,y轴为垂直向下在前一篇文章中,我们已经了解了d属性的M、L、H、V、A命令,接下来,将继续了解剩下命令d属性详解主要定义了路径的路径数据,由描述路径的一系列命令数......
  • SVG之path详解(一),全面解析椭圆弧命令A
    简述SVG中的<path>元素用于创建路径,它是SVG中最强大和最灵活的基本形状之一使用<path>元素可以绘制直线、曲线、弧线等各种复杂的图形,并且可以通过设置路径命令来控制路径的形状和样式在进入正题前,先温习一下svg的坐标系,x轴为水平向右,y轴为垂直向下基本语法<path......
  • win7一键修复所有dll缺失详细方法,7个dll修复方法深度解析(2024)
    dll文件是一种包含函数和其他关键信息的文件,供Windows应用程序使用。虽然大多数普通用户对.dll文件的具体工作原理并不熟悉,但这些文件对于系统应用来说是至关重要的。通常情况下,人们在遇到因DLL文件缺失或损坏而导致的错误时,才会接触到它们。对于非专业用户来说,理解这些错......
  • 反向代理的工作原理解析
     在当今数字化时代,网络通讯扮演着重要的角色,而代理技术为网络通讯提供了更多的灵活性和安全性。作为两种重要的代理技术,代理服务器和反向代理的运行原理和用途各有不同。本文将重点介绍反向代理的运行原理,深入探讨其在网络通讯中的作用和优势。1.代理服务器和反向代理之间......
  • OFtutorial00_helloWorld解析
    组成如图OFtutorial0.CfvCFD.H在OpenFOAM中,所有代码都以注释段开头,使用有限体积的CFD类型文件都包括头文件fvCFD.H,该文件包含类或函数的定义,函数的内容会在运行时以动态形式调用。在fvCFD.H中,为了避免被多次引用,定义了如下宏变量#ifndeffvCFD_H#definefvCFD_H…......
  • 【第九节】python中xml解析和json编解码
    目录一、PythonXML解析1.1什么是XML1.2Python对XML的解析方法1.3SAX解析xml1.4xml.dom解析xml1.6ElementTree解析XML二、Python编解码json2.1什么是json2.2使用json库2.3使用第三方库Demjson一、PythonXML解析1.1什么是XML        XML,......
  • 工程项目综合管理系统解析:哪一款适合你的企业?
    国内外主流的10款工程项目综合管理系统对比:PingCode、Worktile、广联达、明源云、中望软件、OraclePrimavera、Asana、Wrike、ZohoProjects、Basecamp。在处理复杂的工程项目时,选择合适的综合管理系统可能是一个令人头痛的问题。项目延误、成本超支和资源管理不当等问题常常......