slopeMesh.C 11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | faSavageHutterFOAM
    \\  /    A nd           | Copyright (C) 2017 Matthias Rauter
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of foam-extend.

    foam-extend is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    foam-extend is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.

Application
    slopeMesh

Description
    Application to create simple slope geometries for testing the granular flow solver.

Author
    Matthias Rauter matthias.rauter@uibk.ac.at

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

#include "fvCFD.H"
#include "faCFD.H"
#include "elevationModels/elevationModel/elevationModel.H"

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

int main(int argc, char *argv[])
{
43 44
    #include "setRootCase.H"
    #include "createTime.H"
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

    const word dictName("slopeMeshDict");
    const word polyMeshDir = polyMesh::meshSubDir;

    IOdictionary demMeshDict
    (
         IOobject
         (
              dictName,
              runTime.constant(),
              runTime,
              IOobject::MUST_READ,
              IOobject::NO_WRITE
         )
    );


    if (!demMeshDict.headerOk())
    {
        FatalErrorIn(args.executable())
            << "Cannot open mesh description file\n    "
            << demMeshDict.objectPath()
            << nl
            << exit(FatalError);
    }

    autoPtr<elevationModel> elevation
    (
        elevationModel::New("elevationModel", demMeshDict)
    );


    label cellCountX, cellCountY;
    scalar minX, maxX, minY, maxY, meshH;
    Switch tri;

    demMeshDict.lookup("cellCountX") >> cellCountX;
    demMeshDict.lookup("cellCountY") >> cellCountY;

    demMeshDict.lookup("minX") >> minX;
    demMeshDict.lookup("maxX") >> maxX;
    demMeshDict.lookup("minY") >> minY;
    demMeshDict.lookup("maxY") >> maxY;

    demMeshDict.lookup("h") >> meshH;


    const label cellCountZ = 1;

    const scalar cellCount = cellCountX*cellCountY;
    const scalar pointCount = (cellCountZ+1)*(cellCountX+1)*(cellCountY+1);
    const scalar dx = (maxX-minX)/cellCountX;
    const scalar dy = (maxY-minY)/cellCountY;
    const scalar dz = meshH/cellCountZ;
    const scalar faceCount = cellCount*2+cellCountX*(cellCountY+1)+cellCountY*(cellCountX+1);
    //back+front
    //x-paralell-faces
    //y-paralell-faces


105 106 107 108 109 110 111 112
    Info<< "creating Mesh with "
        << cellCount << " cells, "
        << faceCount << " faces and "
        << pointCount << " points" << nl;

    Info<< "x = [" << minX << ";" << maxX << "] (" << cellCountX << ")" << nl
        << "y = [" << minY << ";" << maxY << "] (" << cellCountY << ")" << nl
        << "cellsize = " << dx << "m x " << dy << "m" << endl;
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303


    pointField points(pointCount);
    faceList faces(faceCount);
    cellList cells(cellCount);
    labelListListList pointi(cellCountX+1);
    labelListListList xplanes(cellCountX+1); //x-y-z
    labelListListList yplanes(cellCountY+1); //y-x-z
    labelListListList zplanes(cellCountZ+1); //z-x-y

    label lp = 0;
    for (int i=0; i<cellCountX+1; i++)
    {
        pointi[i] = labelListList(cellCountY+1);
        for (int j=0; j<cellCountY+1; j++)
        {
            pointi[i][j] = labelList(cellCountZ+1);
            for (int k=0; k<cellCountZ+1; k++)
            {
                points[lp] = elevation->X(vector(minX+dx*i, minY+dy*j, dz*k));
                pointi[i][j][k] = lp++;
            }
        }
    }


    label minXboundary, maxXboundary,
          minYboundary, maxYboundary,
          minZboundary, maxZboundary;

    label lf = 0;


    //creating internal x-planes
    for (int i=1; i<cellCountX; i++)
    {
        xplanes[i] = labelListList(cellCountY);
        for (int j=0; j<cellCountY; j++)
        {
            xplanes[i][j] = labelList(cellCountZ);
            for (int k=0; k<cellCountZ; k++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i][j+1][k];
                f[2] = pointi[i][j+1][k+1];
                f[3] = pointi[i][j][k+1];
                xplanes[i][j][k]=lf++;
            }
        }
    }

    //creating internal y-planes
    for (int j=1; j<cellCountY; j++)
    {
        yplanes[j] = labelListList(cellCountX);
        for (int i=0; i<cellCountX; i++)
        {
            yplanes[j][i] = labelList(cellCountZ);
            for (int k=0; k<cellCountZ; k++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i][j][k+1];
                f[2] = pointi[i+1][j][k+1];
                f[3] = pointi[i+1][j][k];
                yplanes[j][i][k]=lf++;

            }
        }
    }
    //creating internal z-plane
    for (int k=1; k<cellCountZ; k++)
    {
        zplanes[k] = labelListList(cellCountX);
        for (int i=0; i<cellCountX; i++)
        {
            zplanes[k][i] = labelList(cellCountY);
            for (int j=0; j<cellCountY; j++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i+1][j][k];
                f[2] = pointi[i+1][j+1][k];
                f[3] = pointi[i][j+1][k];
                zplanes[k][i][j]=lf++;

            }
        }
    }


    minXboundary = lf;

    //creating x-planes
    for (int l=0; l<2; l++)
    {
        int i = l?cellCountX:0;
        xplanes[i] = labelListList(cellCountY);
        for (int j=0; j<cellCountY; j++)
        {
            xplanes[i][j] = labelList(cellCountZ);
            for (int k=0; k<cellCountZ; k++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i][j][k+1];
                f[2] = pointi[i][j+1][k+1];
                f[3] = pointi[i][j+1][k];
                if (i == cellCountX)
                    f = f.reverseFace();
                xplanes[i][j][k]=lf++;
            }
        }
    }

    maxXboundary=lf-cellCountY*cellCountZ;
    minYboundary=lf;

    //creating y-planes
    for (int l=0; l<2; l++)
    {
        int j = l?cellCountY:0;
        yplanes[j] = labelListList(cellCountX);
        for (int i=0; i<cellCountX; i++)
        {
            yplanes[j][i] = labelList(cellCountZ);
            for (int k=0; k<cellCountZ; k++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i+1][j][k];
                f[2] = pointi[i+1][j][k+1];
                f[3] = pointi[i][j][k+1];
                if (j == cellCountY)
                    f = f.reverseFace();
                yplanes[j][i][k]=lf++;

            }
        }
    }
    maxYboundary=lf-cellCountX*cellCountZ;
    minZboundary=lf;

    //creating z-plane
    for (int l=0; l<2; l++)
    {
        int k = l?cellCountZ:0;
        zplanes[k] = labelListList(cellCountX);
        for (int i=0; i<cellCountX; i++)
        {
            zplanes[k][i] = labelList(cellCountY);
            for (int j=0; j<cellCountY; j++)
            {
                face &f = faces[lf];
                f = face(4);
                f[0] = pointi[i][j][k];
                f[1] = pointi[i][j+1][k];
                f[2] = pointi[i+1][j+1][k];
                f[3] = pointi[i+1][j][k];
                if (k == cellCountZ)
                    f = f.reverseFace();
                zplanes[k][i][j]=lf++;

            }
        }
    }
    maxZboundary=lf-cellCountX*cellCountY;


    for (int i=0; i<cellCountX; i++)
    {
        for (int j=0; j<cellCountY; j++)
        {
            cells[i*(cellCountY)+j] = cell(6);
            cells[i*(cellCountY)+j][0] = xplanes[i][j][0];
            cells[i*(cellCountY)+j][1] = xplanes[i+1][j][0];
            cells[i*(cellCountY)+j][2] = yplanes[j][i][0];
            cells[i*(cellCountY)+j][3] = yplanes[j+1][i][0];
            cells[i*(cellCountY)+j][4] = zplanes[0][i][j];
            cells[i*(cellCountY)+j][5] = zplanes[1][i][j];
        }
    }



304
    word regionName = polyMesh::defaultRegion;
305 306 307 308 309 310 311 312 313

    polyMesh mesh
    (
        IOobject
        (
            regionName,
            runTime.constant(),
            runTime
        ),
314 315 316
        std::move(points),
        std::move(faces),
        std::move(cells)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
    );

    label start[6] = {minXboundary, maxXboundary,
                      minYboundary, maxYboundary,
                      minZboundary, maxZboundary};

    label size[6] = {cellCountY*cellCountZ, cellCountY*cellCountZ,
                     cellCountX*cellCountZ, cellCountX*cellCountZ,
                     cellCountX*cellCountY, cellCountX*cellCountY};

    word name[6] = {"minX", "maxX", "minY", "maxY", "slope", "maxZ"};

    List<polyPatch*> patches(6);

    for (int i=0; i<6;i++)
    {
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
        patches[i] = new polyPatch
        (
            name[i],
            size[i],
            start[i],
            0,
            polyBoundaryMesh
            (
                IOobject
                (
                    regionName,
                    runTime.constant(),
                    runTime
                ),
                mesh
            ),
            "test"
        );
351 352 353 354 355 356 357 358 359 360 361 362 363
    }

    mesh.addPatches(patches);

    Info<< nl << "Writing polyMesh" << endl;
    mesh.removeFiles();
    if (!mesh.write())
    {
        FatalErrorIn(args.executable())
            << "Failed writing polyMesh."
            << exit(FatalError);
    }
/*
364
    Info<< "Points of Interest:" << endl;
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392

    const PtrList<entry> pois
    (
        demMeshDict.lookup("POI")
    );

    wordList poiNames;
    poiNames.setSize(pois.size());

    forAll(poiNames, poiI)
    {
        const entry& poiInfo = pois[poiI];


        if (!poiInfo.isDict())
        {
            FatalIOErrorIn("demMesh.C", demMeshDict)
                << "Entry " << poiInfo << " in POI section is not a"
                << " valid dictionary." << exit(FatalIOError);
        }
        poiNames[poiI] = poiInfo.keyword();

        dictionary poiDict = poiInfo.dict();

        vector localPos;

        poiDict.lookup("localPosition") >> localPos;

393
        Info<< poiNames[poiI] << "(" << localPos << ")" << " = " << elevation->X(localPos) << endl;
394 395 396
    }*/


397 398 399
    Info<< nl << "End" << endl;

    return 0;
400 401
}

402

403
// ************************************************************************* //