上海交通大学船舶海洋与建筑工程学院谢彬Numerical TESTs for PDEs解答1.2.2

adv122Foam.C

/*---------------------------------------------------------------------------*\
	Changed from scalarTransportFoam to adv121Foam

Application
    adv122Foam

Description
    Solves training examples 1.2.2 problem.

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
#include "fvOptions.H"
#include "simpleControl.H"

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

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

    simpleControl simple(mesh);

    #include "createFields.H"

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

    Info<< "\nCalculating scalar transport\n" << endl;

    #include "CourantNo.H"

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

        while (simple.correctNonOrthogonal())
        {
            fvScalarMatrix TEqn
            (
                fvm::ddt(T)
              + fvm::div(phi, T)
             ==
                fvOptions(T)
            );

            TEqn.relax();
            fvOptions.constrain(TEqn);
            TEqn.solve();
            fvOptions.correct(T);
        }

        runTime.write();
    }

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

    return 0;
}


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

createFields.H

Info<< "Reading field T\n" << endl;

volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);


Info<< "Reading field U\n" << endl;

volVectorField U
(
    IOobject
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);


Info<< "Reading transportProperties\n" << endl;

IOdictionary transportProperties
(
    IOobject
    (
        "transportProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);


Info<< "Reading diffusivity DT\n" << endl;

dimensionedScalar DT
(
    transportProperties.lookup("DT")
);

using std::sin;
using std::cos;
using std::sqrt;
using std::pow;


const scalar pi(M_PI);
scalar r0 = 0.15;
scalar xc_hump = 0.25;
scalar yc_hump = 0.5;
scalar xc_cone = 0.5;
scalar yc_cone = 0.25;
scalar xc_disk = 0.5;
scalar yc_disk = 0.75;

forAll(U,celli)
{
    scalar xx = mesh.C()[celli].x();
    scalar yy = mesh.C()[celli].y();
    U[celli].x() = 0.5-yy;
    U[celli].y() = xx-0.5;
    U[celli].z() = 0;
}
U.correctBoundaryConditions();
U.write();

forAll(T,celli)
{
    scalar xx = mesh.C()[celli].x();
    scalar yy = mesh.C()[celli].y();
    scalar rc_hump = sqrt((xx-xc_hump)*(xx-xc_hump)+(yy-yc_hump)*(yy-yc_hump));
    scalar rc_cone = sqrt((xx-xc_cone)*(xx-xc_cone)+(yy-yc_cone)*(yy-yc_cone));
    scalar rc_disk = sqrt((xx-xc_disk)*(xx-xc_disk)+(yy-yc_disk)*(yy-yc_disk));
    if (rc_hump<=r0)
    {
    	T[celli] = 0.25*(1+cos(pi*(rc_hump/r0)));
    }
    else if (rc_cone<=r0)
    {
    	T[celli] = 1-(rc_cone/r0);
    }
    else if (rc_disk<=r0)
    {
    	if ((sqrt((xx-xc_disk)*(xx-xc_disk))>0.025)||(yy>0.85))
    	{
    	    T[celli] = 1;
    	}
    	else
    	{
    	    T[celli] = 0;
    	}
    }
    else
    {
    	T[celli] = 0;
    }
    
}
T.correctBoundaryConditions();
T.write();


#include "createPhi.H"

#include "createFvOptions.H"

T

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 1 0 0 0];

internalField   uniform 0;

boundaryField
{
    upperWall
    {
        type            cyclic;
    }
    lowerWall
    {
        type            cyclic;
    }
    leftWall
    {
        type            cyclic;
    }
    rightWall
    {
        type            cyclic;
    }
    frontAndBack
    {
        type            empty;
    }
}

}

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

100tria.geo



Point(1) = {0, 0, 0, 1e22};
Point(2) = {1.0, 0, 0, 1e22};
Point(3) = {1.0, 1.0, 0, 1e22};
Point(4) = {0, 1.0, 0, 1e22};
//+
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
//+
Line Loop(1) = {1, 2, 3, 4};
Plane Surface(1) = {1};

Transfinite Line {3,1} = 101 Using Progression 1;
Transfinite Line {2,4} = 101 Using Progression 1;

Transfinite Surface {1};

// Recombine Surface {1};

Extrude {0, 0, 0.1} {
  Surface{1}; Layers{1}; Recombine;
}


Physical Surface("frontAndBack") = {26, 1};
Physical Surface("leftWall") = {25};
Physical Surface("rightWall") = {17};
Physical Surface("upperWall") = {21};
Physical Surface("lowerWall") = {13};
Physical Volume("box") = {1};

clearvars; clc; % adv122data100qX050.m % edit

dataPath = 'D:\SJTU_senior_1st_total\Sundry\grad\hw\hw1\data\1.2.2\';
targetPath = 'D:\SJTU_senior_1st_total\Sundry\grad\hw\hw1\figs\1.2.2\';
targetName = 'X050quad.png'; % edit
targetName = [targetPath, targetName];
tria100nameY025 = '100QuadX=0.50.xlsx'; % edit
tria100nameY025 = [dataPath, tria100nameY025];
tria100matY025 = importdata(tria100nameY025);
tria100exNameY025 = '100QuadX=0.50ex.xlsx'; % edit
tria100exNameY025 = [dataPath, tria100exNameY025];
tria100matexY025 = importdata(tria100exNameY025);

figure(1);
y_llim = -0.2; y_rlim = 1.2;
set(gca, 'ylim', [y_llim, y_rlim]); hold on;
x_to_plot = tria100matY025(:,1); y_to_plot = tria100matY025(:,2);
size = 20;
scatter(x_to_plot, y_to_plot, size, 'Black', 'c', 'filled');
hold on;
x_to_plot = tria100matexY025(:,1); y_to_plot = tria100matexY025(:,2);
plot(x_to_plot, y_to_plot, 'Black', 'LineWidth', 1);
title('Quadrangle X = 0.50', 'FontSize', 15); % edit
legend('Numerical','Analytic','Location','NE', 'FontSize', 15);
saveas(gcf, targetName); close all;

猜你喜欢

转载自blog.csdn.net/joshua_shi_t/article/details/121425266