首页 > 其他分享 >OFtutorial07_customLibraries解析

OFtutorial07_customLibraries解析

时间:2024-08-13 16:28:27浏览次数:4  
标签:解析 const customLibrary volScalarField 编译 OFtutorial07 mesh include customLibrari

关于编译库和编译类的:编译是将函数文件编译成动态链接,另一个求解器/应用程序/类可以调用该链接后再编译,若编译成动态链接后在对文件直接修改将不会影响链接,需要重新编译。因此,编译类和编译库的区别就在编译库之后可以直接使用库链接

组成

如图

customLibrary

组成

customLibrary.H

#include "fvCFD.H"

// This method simply implements the calculation of the distance of each
// cell centre from x0; it accepts the volScalarField r as a reference to avoid
// passing large amounts of information by value, as this is expensive.
// It returns the maximum value found.
scalar computeR(const fvMesh& mesh, volScalarField& r, dimensionedVector x0);//声明computeR函数

// This computes the velocity field. The reference to the pressure is obtained
// through the mesh object, using the name of the p field only. This assmes a
// default value which may be redefined, if necessary.
void computeU(const fvMesh& mesh, volVectorField& U, word pName = "p");//声明computeU函数

customLibrary.C

#include "customLibrary.H"

scalar computeR(const fvMesh& mesh, volScalarField& r, dimensionedVector x0)//定义computeR函数
{
    r = mag(mesh.C()-x0);//mag()用于求矢量的模
    //reduce()函数的作用主要是在并行计算环境中将分布在多个处理器(或计算节点)上的数据“聚合”或“减少”到一个单一的值。其中第一个参数表示从当前处理器取值,这里取了r的最大值,第二个参数是对全局的已取值筛选条件,这里是取最大值。
    return returnReduce(max(r).value(), maxOp<scalar>());
}

void computeU(const fvMesh& mesh, volVectorField& U, word pName)//定义computeU函数
{
    // This allows a reference to a field to be obtained through the mesh object
    // alone by just knowing the name of the field.
    //通过网格对象和字段名称查找压力场 
    const volScalarField& pField = mesh.lookupObject<volScalarField>(pName);

    // Do the usual
    U = fvc::grad(pField)*dimensionedScalar("tmp", dimTime, 1.);
}

Make

与此前章节介绍类似,不做赘述

OFtutorial7.C

#include "fvCFD.H"

// Include the headers for the custom library.
// The library can implement anything from a simple function to several different
// classes. The main advantage of libraries is that they allow the same code to be
// compiled once and used by many other pieces of code later on.
// NOTE: check how the Make/options changed to make sure the additional code gets
// linked to the current utility.
#include "customLibrary.H"

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    //dimLength给定物理维度,它指定了向量的每个分量都是长度单位
    const dimensionedVector originVector("x0", dimLength, vector(0.05, 0.05, 0.005));
    scalar f (1.);
    // NOTE: initialise the radius field with zero values and dimensions
    volScalarField r
    (
        IOobject
        (
            "r",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        mesh,
        dimensionedScalar("r0", dimLength, 0.)
    );
    // NOTE: use the method implemented in the library to calculate r and rFarCell
    const scalar rFarCell = computeR(mesh, r, originVector);

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        p = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value())
            / (r/rFarCell + dimensionedScalar("small", dimLength, 1e-12))
            * dimensionedScalar("tmp", dimensionSet(0, 3, -2, 0, 0), 1.);
        p.correctBoundaryConditions();

        // NOTE: call the library method to calculate U
        computeU(mesh, U);

        runTime.write();
    }

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

    return 0;
}

Make

options

EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -IcustomLibrary/包含customLibrary目录

EXE_LIBS = \
    -lfiniteVolume \
    -lmeshTools \
    -L$(FOAM_USER_LIBBIN) -lcustomLibrary//链接customLibrary库

files

不做赘述

Allwmake

wmake libso customLibrary//编译customLibrary库
wmake

Allwclean

wclean libso customLibrary//解构customLibrary库
wclean

testcase

不做赘述

标签:解析,const,customLibrary,volScalarField,编译,OFtutorial07,mesh,include,customLibrari
From: https://www.cnblogs.com/ouqiyo/p/18357220

相关文章

  • 汇率波动下的企业生存之道:汇率风险管理策略解析
    在全球化经济的浪潮中,企业如同航行在波涛汹涌的大海上的船只,不仅要面对市场的竞争,还要应对汇率波动带来的风险。汇率风险,一个在国际贸易中不可忽视的挑战,对跨境交易的企业尤为关键。本文将带您深入了解汇率风险的种类及其对企业的影响,并探讨企业如何有效应对这一挑战。汇率风险:企......
  • 【华为云MySQL技术专栏】MySQL 8.0事务提交原理解析!
    摘要:当多个引擎/节点同时访问和修改数据时,如何保证数据在各个引擎/节点之间的一致性成为了一项挑战。本文将深入探讨MySQL集群在保持数据一致性的解决方案。本文分享自华为云社区《【华为云MySQL技术专栏】MySQL8.0事务提交原理解析!》,作者:GaussDB数据库。 1.概述MySQL是一......
  • Flink1.19 JobSubmitHandler源码解析
    文章目录概要整体架构流程概要JobGraph在客户端生成后,需要发送到服务端,首先会被JobSubmitHandler(WebMonitor内处理http请求的处理类)接收处理,然后会发送到Dispatcher进一步处理整体架构流程首先会进入JobSubmitHandler对象的handleRequest方法有两个参数:request:封......
  • # Android开发 - FileWriter 类写入文件解析
    FileWriter是什么FileWriter是一个用于将字符数据写入文件中的类。在Java中,它使得文件的写入操作变得简单直观FileWriter继承自OutputStreamWriter类,进一步继承自WriterFileWriter构造方法FileWriter(StringfileName):创建一个FileWriter对象,用于写入指定文件......
  • Android开发 - File类文件操作解析
    File是什么File类用于处理文件和目录。它允许你创建、删除、读取和写入文件。你可以用它来获取文件路径、检查文件是否存在、获取文件大小等。例如,Filefile=newFile(context.getFilesDir(),"example.txt");可以用来在应用的私有目录中创建一个名为example.txt的文件......
  • 【图像去噪】论文复现:新手入门必看!DnCNN的Pytorch源码训练测试全流程解析!为源码做详细
    第一次来请先看【专栏介绍文章】:源码只提供了noiselevel为25的DnCNN-S模型文件。本文末尾有完整代码和训练好的σ=15,25,50的DnCNN-S、σ∈[0,55]的DnCNN-B和CDnCNN-B、DnCNN-3共6个模型文件!读者可以自行下载!本文亮点:以官方Pytorch源代码为基础,在DnCNN-S的基础上,增添Dn......
  • OFtutorial06_customClasses 解析
    组成如图customClass.H#include"fvCFD.H"classcustomClass{private:labelmyInt_;public:customClass();~customClass();//Accessoperators-allowtheinternalvaluetobesetorretrieved.//Definedasinlinetomake......
  • 深入解析Node.js中的fs.watch:options与listener详解
    在Node.js中,fs.watch方法是一个功能强大的文件系统监控工具,它允许我们对文件或目录进行实时监控,并在文件或目录发生变化时触发相应的操作。在使用fs.watch时,两个关键的部分是options对象和listener回调函数。本文将详细讲解这两个部分,帮助读者更好地理解和使用fs.watch。一......
  • 如何解决因内存不足导致的 iPhone 白苹果问题:原因解析与修复教程
    引言在使用iPhone的过程中,许多用户可能遇到过“白苹果”现象,即设备启动时只显示白色的Apple标志,却无法进入系统。这种情况通常让人感到困惑和担忧,尤其是当重要数据似乎无法访问时。本文将探讨内存不足导致iPhone白苹果的原因,并提供详细的修复教程,帮助你恢复设备正常运行......
  • 全面解析Gerapy分布式部署:从环境搭建到定时任务,避开Crawlab的坑
    Gerapy分布式部署搭建远程服务器的环境装好带docker服务的系统Docker:容器可生成镜像,也可拉去镜像生成容器示例:将一个环境打包上传到云端(远程服务器),其他8个服务器需要这个环境直接向云端拉取镜像生成容器,进而使用该环境,比如有MYSQL的镜像、Redis的镜像备注:Linux系统下......