首页 > 其他分享 >OFtutorial03_understandingTheMesh解析

OFtutorial03_understandingTheMesh解析

时间:2024-08-12 11:16:07浏览次数:8  
标签:classes 解析 Cf cell mesh OFtutorial03 understandingTheMesh include

OFtutorial3.C

#include "fvCFD.H"

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

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

	// runTime and mesh are instances of objects (or classes).
	// If you are not familiar with what a class or object is, it is HIGHLY RECOMMENDED you visit this
	// website and only come back once you've read everything about classes, inheritance and polymorphism:
	// http://www.cplusplus.com/doc/tutorial/classes/
	// Note how the next lines call functions .timeName(), .C() and .Cf() implemented in the objects.
	// It is also important to realise that mesh.C() and .Cf() return vector fields denoting centres of each
    // cell and internal face.
	// Calling the mesh.C().size() method therefore yields the total size of the mesh.
#mesh.C()返回表示cell中心的向量场,mesh.Cf()返回表示internel face中心的向量场
	Info << "Hello there, the most recent time folder found is " << runTime.timeName() << nl
		 << "The mesh has " << mesh.C().size() << " cells and " << mesh.Cf().size()
         << " internal faces in it. Wubalubadubdub!" << nl << endl;

    // It's possible to iterate over every cell in a standard C++ for loop.
#遍历cells,获取cell的中心坐标
    for (label cellI = 0; cellI < mesh.C().size(); cellI++)
        if (cellI%20 == 0) // only show every twentieth cell not to spam the screen too much
            Info << "Cell " << cellI << " with centre at " << mesh.C()[cellI] << endl;
    Info << endl; // spacer

    // Each cell is constructed of faces - these may either be internal or constitute a
    // boundary, or a patch in OpenFOAM terms; internal faces have an owner cell
    // and a neighbour.
#mesh.owner() 返回 internal face 的主体(cell);mesh.neighbour() 返回 internal face 主体(cell)的相邻主体(cell),该处用于遍历faces
    for (label faceI = 0; faceI < mesh.owner().size(); faceI++)
        if (faceI%40 == 0)
            Info << "Internal face " << faceI << " with centre at " << mesh.Cf()[faceI]
                 << " with owner cell " << mesh.owner()[faceI]
                 << " and neighbour " << mesh.neighbour()[faceI] << endl;
    Info << endl;

    // Boundary conditions may be accessed through the boundaryMesh object.
    // In reality, each boundary face is also included in the constant/polyMesh/faces
    // description. But, in that file, the internal faces are defined first.
    // In addition, the constant/polyMesh/boundary file defines the starting faceI
    // indices from which boundary face definitions start.
    // OpenFOAM also provides a macro definition for for loops over all entries
    // in a field or a list, which saves up on the amount of typing.
#输出边界类型及对应面上faces的数量
    forAll(mesh.boundaryMesh(), patchI)
        Info << "Patch " << patchI << ": " << mesh.boundary()[patchI].name() << " with "
             << mesh.boundary()[patchI].Cf().size() << " faces. Starts at total face "
             << mesh.boundary()[patchI].start() << endl;
    Info << endl;

    // Faces adjacent to boundaries may be accessed as follows.
    // Also, a useful thing to know about a face is its normal vector and face area.
#输出各边界上的face(0)所在的cell及其方向
    label patchFaceI(0);
    forAll(mesh.boundaryMesh(), patchI)
        Info << "Patch " << patchI << " has its face " << patchFaceI << " adjacent to cell "
             << mesh.boundary()[patchI].patch().faceCells()[patchFaceI]
             << ". It has normal vector " << mesh.boundary()[patchI].Sf()[patchFaceI]
             << " and surface area " << mag(mesh.boundary()[patchI].Sf()[patchFaceI])
             << endl;
    Info << endl;

    // For internal faces, method .Sf() can be called directly on the mesh instance.
    // Moreover, there is a shorthand method .magSf() which returns the surface area
    // as a scalar.
    // For internal faces, the normal vector points from the owner to the neighbour
    // and the owner has a smaller cellI index than the neighbour. For boundary faces,
    // the normals always point outside of the domain (they have "imaginary" neighbours
    // which do not exist).

    // It is possible to look at the points making up each face in more detail.
    // First, we define a few shorthands by getting references to the respective
    // objects in the mesh. These are defined as constants since we do not aim to
    // alter the mesh in any way.
    // NOTE: these lists refer to the physical definition of the mesh and thus
    // include boundary faces. Use can be made of the mesh.boundary()[patchI].Cf().size()
    // and mesh.boundary()[patchI].start() methods to check whether the face is internal
    // or lies on a boundary.
    const faceList& fcs = mesh.faces();
    const List<point>& pts = mesh.points();
    const List<point>& cents = mesh.faceCentres();

    forAll(fcs,faceI)
        if (faceI%80==0)
        {
            if (faceI<mesh.Cf().size())#找出内部面
                Info << "Internal face ";
            else
            {
                forAll(mesh.boundary(),patchI)#找出边界面
                    if ((mesh.boundary()[patchI].start()<= faceI) &&
                        (faceI < mesh.boundary()[patchI].start()+mesh.boundary()[patchI].Cf().size()))
                    {
                        Info << "Face on patch " << patchI << ", faceI ";
                        break; // exit the forAll loop prematurely
                    }
            }

            Info << faceI << " with centre at " << cents[faceI]
                 << " has " << fcs[faceI].size() << " vertices:";输出面的位置(内部或边界)、索引、中心点坐标和顶点数量
            forAll(fcs[faceI],vertexI)#遍历当前面的所有顶点
                // Note how fcs[faceI] holds the indices of points whose coordinates
                // are stored in the pts list.
                Info << " " << pts[fcs[faceI][vertexI]];#输出当前顶点的坐标
            Info << endl;
        }
    Info << endl;

    // In the original cavity tutorial, on which the test case is based,
    // the frontAndBack boundary is defined as and "empty" type. This is a special
    // BC case which may cause unexpected behaviour as its .Cf() field has size of 0.
    // Type of a patch may be checked to avoid running into this problem if there
    // is a substantial risk that an empty patch type will appear
#检查empty Patch
    label patchID(0);
    const polyPatch& pp = mesh.boundaryMesh()[patchID];
    if (isA<emptyPolyPatch>(pp))
    {
        // patch patchID is of type "empty".
        Info << "You will not see this." << endl;
    }

    // Patches may also be retrieved from the mesh using their name. This could be
    // useful if the user were to refer to a particular patch from a dictionary
    // (like when you do when calculating forces on a particular patch).
#以名称检索Patch
    word patchName("movingWall");
    patchID = mesh.boundaryMesh().findPatchID(patchName);
    Info << "Retrieved patch " << patchName << " at index " << patchID << " using its name only." << nl << endl;

    Info<< "End\n" << endl;

    return 0;
}

Allwclean、Allwmake、Make、testcase

与前章类似,不做赘述

标签:classes,解析,Cf,cell,mesh,OFtutorial03,understandingTheMesh,include
From: https://www.cnblogs.com/ouqiyo/p/18353626

相关文章

  • 中药配方颗粒行业报告:市场规模、趋势与机遇解析
    一、行业简述(一)行业概念中药配方颗粒,是指将传统中药饮片通过现代制药技术,经水提取、浓缩、干燥、制粒等步骤制成的颗粒状制剂。这种制剂保持了中药饮片的性味归经和主治功效,同时具有安全、有效、方便、质量稳定可控等优点。中药配方颗粒无需像传统饮片一样煎煮,可直接冲泡服......
  • 0218-地址解析协议
    环境Time2022-11-20VirtualBox7.0.2Rust1.65.0pnet0.31.0CentOS7前言说明参考:https://docs.rs/pnet_packet/latest/pnet_packet/index.html目标使用两台虚拟机,通过IP地址,获取到目标主机的MAC地址。日常使用的时候,都是使用IP连接服务器,需要使用地址解析协......
  • PrimeFaces SelectOneMenu 与 Ajax 集成实例解析
    ======在现代Web开发中,用户界面的交互性是至关重要的。PrimeFaces作为JavaServerFaces(JSF)的一个流行UI组件库,提供了丰富的组件来增强用户界面。本文将通过一个具体实例,详细介绍如何使用PrimeFaces的SelectOneMenu组件与Ajax技术相结合,实现在选择事件时通过Ajax提交数据。......
  • Java动态代理与方法拦截实战解析
    Java动态代理与方法拦截实战解析在Java编程中,动态代理是一种强大的技术,它允许我们在运行时创建接口的代理实例,并且可以拦截方法调用。本文将通过一个具体的实例,详细解析如何使用JDK的动态代理机制来实现方法拦截,以及如何编写通用的方法拦截器。实现InvocationHandler首先......
  • 深入解析@JsonValue注解在Java序列化中的应用
    深入解析@JsonValue注解在Java序列化中的应用在Java开发中,对象序列化是一个常见的需求,尤其是在进行网络通信或者数据持久化时。Jackson库作为Java领域内一个非常流行的JSON处理库,提供了强大的序列化和反序列化功能。在Jackson2.9版本之后,@JsonValue注解的引入,为开发者提供......
  • Python数据科学的秘密武器:Pandas库的深度解析
    标题:Python数据科学的秘密武器:Pandas库的深度解析Python作为数据科学领域的宠儿,其强大的数据处理能力离不开Pandas库的加持。Pandas是一个开源的数据分析和操作库,它提供了快速、灵活和表达力强的数据结构,旨在使数据清洗和分析工作变得更加简单易行。本文将深入探讨Pandas库......
  • 云中韧性:Spring Cloud服务调用重试机制深度解析
    标题:云中韧性:SpringCloud服务调用重试机制深度解析在微服务架构中,服务间的调用可能会因为网络问题、服务不可达、资源竞争等原因失败。SpringCloud作为微服务架构的主流实现框架,提供了一套完整的服务调用重试机制,以增强系统的健壮性和可靠性。本文将详细探讨SpringCloud......
  • LangChain 安全特性全解析与实践指南
    LangChain安全特性全解析与实践指南引言在人工智能的浪潮中,LangChain以其卓越的能力,成为开发大型语言模型(LLM)应用程序的佼佼者。然而,随着技术的发展,安全问题逐渐浮出水面。本文将深入探讨LangChain的安全特性,并提供详细的代码示例和最佳实践,以确保开发者能够在保障安全......
  • 解密AI的未来:决策式AI与生成式AI的深度解析
    在当今科技飞速发展的时代,人工智能(AI)已成为各行各业的热议话题。尤其是决策式AI和生成式AI,这两种技术各具特色,却又相辅相成。本文将深入探讨这两种AI的定义、应用及其未来发展趋势,带你一探究竟!一、什么是决策式AI?决策式AI是指能够通过分析数据和信息,帮助用户做出明智决策的人......
  • 微服务的多面手:Spring Cloud 多数据中心支持全解析
    标题:微服务的多面手:SpringCloud多数据中心支持全解析在微服务架构中,服务的高可用性和弹性伸缩是设计的核心。随着业务的全球化发展,企业经常需要在多个数据中心部署应用以满足不同地区的用户需求,确保服务的快速响应和数据的低延迟访问。SpringCloud作为微服务架构的佼佼......