首页 > 其他分享 >OFtutorial09_runtimePostprocessingUtility解析

OFtutorial09_runtimePostprocessingUtility解析

时间:2024-08-20 21:05:03浏览次数:11  
标签:pipeCalc const runtimePostprocessingUtility Foam virtual file faces 解析 OFtutoria

组成

pipeCalc.H

源码

头文件

#ifndef pipeCalc_H
#define pipeCalc_H

#include "volFieldsFwd.H"
#include "Switch.H"
#include "fvc.H"
#include "fvMeshFunctionObject.H"
#include "logFiles.H"
#include "addToRunTimeSelectionTable.H"

命名空间

namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
                          Class pipeCalc Declaration
\*---------------------------------------------------------------------------*/

class pipeCalc
:
    // NOTE: derive from the base fvMeshFunctionObject and logFiles in order to
    // provide a ready interface for dealing with output files
    public fvMeshFunctionObject,//继承的父类
    public logFiles//继承的父类
{
private:
    // Private data

        //- Name of this set of pipeCalc objects
        word name_;

        //- On/off switch
        bool active_;

        //- Name of velocity field, default is "U"
        word UName_;

        // NOTE: these fields hold the information about the faceZone
        // Name of the face zone
        word faceZoneName_;

        // index of the face zone in the mesh container
        label faceZoneLabel_;

        // indices of the faces of the CS in the mesh - keep as reference, should be faster for large sets
        const labelList& faces_;

    // Private Member Functions

        //- Disallow default bitwise copy construct
        pipeCalc(const pipeCalc&);

        //- Disallow default bitwise assignment
        void operator=(const pipeCalc&);

protected:
    // NOTE: define a list of files this object writes to; the underlying logFiles
    // object will handle output to correct streams automatically.
    enum fileID//定义了一个名为fileID的枚举类型。
    {
        MAIN_FILE = 0
    };

    // NOTE: Create file names for each of the output files
    wordList createFileNames(const dictionary& dict) const;

    // NOTE: this first gets declared in the baseline object and gets used to
    // write the header in the output file.
    virtual void writeFileHeader(const label i);

public:

    //- Runtime type information
    TypeName("pipeCalc");

    // Constructors

        //- Construct for given Time and dictionary.
        pipeCalc
        (
            const word& name,
            const Time& runTime,
            const dictionary& dict
        );

    //- Destructor
    virtual ~pipeCalc();

    // Member Functions

    //- Return name of the set of pipeCalc
    virtual const word& name() const { return name_; }

    //- Read the pipeCalc data
    virtual bool read(const dictionary&);

    //- Execute, currently does nothing
    virtual bool execute();

    //- Execute at the final time-loop, currently does nothing
    virtual bool end();

    //- Called when time was set at the end of the Time::operator++
    virtual void timeSet();

    // NOTE: Key method which implements the object's actual functionality
    virtual bool write();

    //- Update for changes of mesh
    virtual void updateMesh(const mapPolyMesh&) {}

    //- Update for changes of mesh
    virtual void movePoints(const polyMesh&) {}
};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace functionObjectFile
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

pipeCalc.C

#include "pipeCalc.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(pipeCalc, 0);
    addToRunTimeSelectionTable(functionObject, pipeCalc, dictionary);
}
}
// * * * * * * * * * * * * * * * * Protected members  * * * * * * * * * * * * * * //

// NOTE: this returns a list of file names which match indices of the enum
// defined in the header of this class. These names are used to create matching
// files by the logFiles object.
Foam::wordList Foam::functionObjects::pipeCalc::createFileNames
(
    const dictionary& dict
) const
{
    DynamicList<word> names(1);// 初始化一个动态列表,预设大小为1 

    // use type of the utility as specified in the dict as the top-level dir name
    const word objectType(dict.lookup("type"));

    // Name for file(MAIN_FILE=0)
    names.append(objectType);

    return names;
}

// NOTE: this method first gets declared in logFiles.H, from which this
// class is derived. This method gets called automatically when the base object's
// write() function gets called too.
// The purpose of the function is to add the header to the output data file.
void Foam::functionObjects::pipeCalc::writeFileHeader(const label i)
{
    // Find the correct file to write to from the enum defined in the header.
    switch (fileID(i))
    {
        case MAIN_FILE:
        {
            writeHeader(file(i), "Flow rate through face zone");
            writeHeaderValue(file(i), "Face zone name", faceZoneName_);
            writeCommented(file(i), "Time [s] | Flow rate [m3s-1]");
            file() << endl;
            break; // exit the case structure
        }
        default:
        {
            FatalErrorInFunction
                << "Unhandled file index: " << i
                << abort(FatalError);
        }
    }
}

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
Foam::functionObjects::pipeCalc::pipeCalc
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    // NOTE: call the base class constructor
    fvMeshFunctionObject(name, runTime, dict),
    logFiles(obr_, name),

    name_(name),
    active_(true),
    UName_("U"),
    // NOTE: Read the face zone to integrate over. Get its name from the dict, find
    // it in the mesh, and get a reference to the list of its faces.
    faceZoneName_(dict.lookup("faceZoneName")),
    faceZoneLabel_( mesh_.faceZones().findZoneID(faceZoneName_) ),
    faces_( mesh_.faceZones()[faceZoneLabel_] )
{
    // NOTE: calls the separate .read() method to import the controls from the dict.
    // dict reference is passed automatically by the OpenFOAM runtime object manager.
    read(dict);

    // built-in logFiles method for creating file streams.
    resetNames(createFileNames(dict));

    if (active_)
    {
        // Any extra initialisation goes here, if necessary

        // NOTE: type() returns the typeName, as defined in the header file. Name
        // is the individual identifier of this instance, as specified in the dict
        Info << "Finished initialising " << type() << ": " << name_ << nl << endl;
    }
}

// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::functionObjects::pipeCalc::~pipeCalc()
{}

// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

bool Foam::functionObjects::pipeCalc::read(const dictionary& dict)
{
    if (active_)
    {
        UName_ = dict.lookupOrDefault<word>("UName", "U");
    }
    return true;
}

bool Foam::functionObjects::pipeCalc::execute()
{
    if (active_)
    {
        // This gets called before write, should put things on which other
        // function objects might depend on here (for instance field calculations)
    }
    return true;
}

bool Foam::functionObjects::pipeCalc::end()
{
    if (active_)
    {
        execute();
    }
    return true;
}

void Foam::functionObjects::pipeCalc::timeSet()
{}

bool Foam::functionObjects::pipeCalc::write()
{
    if (active_)
    {
        // NOTE: this is the main part of the function object and implements the
        // actual functionality.

        // Retrieve a reference to the velocity field
        const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);

        // itnerpolate onto the faces
        surfaceVectorField Uface = fvc::interpolate(U);

        // Go over each face zone face and compute the flow rate normal to the
        // face zone faces.
        // This assumes none of the face zone faces are on processor boundaries.
        // If they are, a seg fault will occur as faces_[faceI] will exceed the
        // internal field dimensions. A check could be made by using:
        // if ((faces_[faceI] > mesh_.owner().size()) || (mesh_.owner().size() == 0))
        // and the boundary values could be used instead. This is not done here
        // for simplicity.
        scalar flowRate(0.);

        forAll(faces_, faceI)
            // Flow rate = dot product of velocity and surface area vector; in Latex terms,
            // Q = \mathbf{U} \cdot \mathbf{\hat{n}} A
            flowRate += Uface[faces_[faceI]] & mesh_.Sf()[faces_[faceI]];

        // reduce for parallel running
        reduce(flowRate, sumOp<scalar>());

        Info << "Total flow rate " << flowRate << " through "
             << returnReduce(faces_.size(), sumOp<label>()) << " faces" << nl << endl;

        // Output to file - only execute on the master thread to avoid the file
        // getting written into from a few processors at the same time
        if (Pstream::master())
        {
            // Call the base class method which checks if the output file exists
            // and creates it, if necessary. That also calls the .writeFileHeader()
            // method of the derived class.
            logFiles::write();

            // Add the entry for this time step that has just been computed.
            file(MAIN_FILE) << obr_.time().value() << tab << flowRate << endl;
        }
    }
    return true;
}

标签:pipeCalc,const,runtimePostprocessingUtility,Foam,virtual,file,faces,解析,OFtutoria
From: https://www.cnblogs.com/ouqiyo/p/18360850

相关文章

  • 汇编语言的神秘面纱:指令前缀的深度解析
    标题:汇编语言的神秘面纱:指令前缀的深度解析在计算机编程的底层世界中,汇编语言以其接近硬件的特性,扮演着至关重要的角色。指令前缀是汇编语言中一个关键的概念,它为指令提供了额外的信息,使得程序能够执行更加复杂和灵活的操作。本文将深入探讨指令前缀的作用、类型以及如何在......
  • 深入解析CDN(内容分发网络):架构、优势与实现
    摘要内容分发网络(CDN)是一种通过在多个地理位置部署服务器节点来提高网站加载速度和数据传输效率的网络技术。随着互联网内容的日益丰富和用户对访问速度的高要求,CDN已经成为现代网站和应用不可或缺的一部分。本文将详细介绍CDN的基本概念、工作原理、优势以及如何在Web开发......
  • 网络丢包深度解析:影响、原因及优化策略
    摘要网络丢包是数据在传输过程中未能成功到达目的地的现象,它对网络通信的性能有着显著的影响。本文将深入探讨网络丢包的定义、原因、对性能的影响,以及如何通过技术手段进行检测和优化。1.网络丢包的定义网络丢包发生在数据包在源和目的地之间的传输过程中,由于各种原因......
  • 全面解析:IP池大小对国外代理IP选择的影响
    代理IP是跨境人不可或缺的工具,广泛应用于广告验证、数据获取和账号矩阵管理等方面。而在选择代理IP时,IP池的大小往往是一个至关重要的考量因素。本文将深入解析IP池大小对代理IP选择的影响,帮助大家更好地理解这一关键决策点。一、IP池的定义及其重要性IP池,作为代理服务提供......
  • 汇编语言的构建大师:宏(Macro)的深度解析
    标题:汇编语言的构建大师:宏(Macro)的深度解析在汇编语言的世界里,宏(Macro)是一种强大的工具,它允许开发者定义一段可重用的代码片段,这些片段可以在程序中多次调用,从而提高编程效率和代码的可读性。本文将深入探讨宏的概念、作用以及如何在汇编语言中使用宏,并通过代码示例展示其应......
  • Swift中的强大构建块:自定义运算符全解析
    标题:Swift中的强大构建块:自定义运算符全解析在Swift编程语言中,运算符是执行操作的一种快捷方式,它们可以用于简单的数学计算,也可以用于复杂的逻辑处理。Swift不仅提供了丰富的内置运算符,还允许开发者定义自己的运算符,以适应特定的编程需求。本文将深入探讨如何在Swift中实现......
  • Swift编译器代码生成策略全解析:优化你的性能与效率
    标题:Swift编译器代码生成策略全解析:优化你的性能与效率在Swift编程的高性能世界里,编译器的代码生成选项扮演着至关重要的角色。它们不仅影响应用的性能,还决定了最终代码的效率和大小。本文将深入探讨Swift编译器提供的代码生成选项,并通过实际代码示例,指导你如何利用这些选......
  • PyTorch中的随机采样秘籍:SubsetRandomSampler全解析
    标题:PyTorch中的随机采样秘籍:SubsetRandomSampler全解析在深度学习的世界里,数据是模型训练的基石。而如何高效、合理地采样数据,直接影响到模型训练的效果和效率。PyTorch作为当前流行的深度学习框架,提供了一个强大的工具torch.utils.data.SubsetRandomSampler,它允许开发者......
  • TXT 记录解析怎么做?
    在当今数字化的时代,网络技术的应用越来越广泛,而域名系统(DNS)则是网络通信中至关重要的一部分。TXT记录作为DNS中的一种记录类型,有着特定的用途和解析方法。那么,TXT记录解析究竟该怎么做呢?一、了解TXT记录的概念TXT记录,即文本记录,是一种可以存储任意文本信息的DNS记录类......
  • svnhook---用户提交后,解析用户的提交信息,发送到企业微信机器人
    一:第一篇写到了在用户提交时做检测,不允许不填写提交日志和特定的信息,感兴趣的可以查看  https://www.cnblogs.com/a565810497/p/18369876二:现在来写一个用户成功提交后,我们拿到svn的提交日志,通过企业微信机器人发送到群组里三:下面是具体操作先复制一个脚本,去掉tmpl后缀,并且......