LoginSignup
0
3

More than 5 years have passed since last update.

OpenFOAMでのtest

Last updated at Posted at 2017-12-07

この記事はOpenFOAMのtestについてちょっとだけ調べてみた記事です.

アプリケーションのインストール先

OpenFOAMのアプリケーション(ソルバーなど)がインストールされた$FOAM_APPディレクトリには,いくつかのサブディレクトリがある.

$ cd $FOAM_APP
$ ls
Allwmake  solvers  test  utilities

solversは標準ソルバーが入ったディレクトリ,utilitiesはプリ・ポストなどのユーティリティが入ったディレクトリであり,この二つは慣れたOpenFOAMerならば中身にアクセスしたことがあるかと思う.testについては普段立ち入ることもなく情報もないので,少し調べてみる.

testディレクトリの中身

OpenFOAM-v1706のtestディレクトリの中身を確認してみる.

$ cd $FOAM_APP/test
$ ls
BinSum             alloc                          nullObject
Circulator         base64                         objectRegistry
CompactIOList      boundBox                       pTraits
CompactListList    callback                       parallel
DLList             codeStream                     parallel-communicators
Dictionary         cplusplus1                     parallel-nonBlocking
Distribution       cpuInfo                        parallelOverset
DynamicField       cstring                        passiveParticle
DynamicList        cubicEqn                       patchRegion
Field              cyclic                         pointField
FixedList          delete                         predicates
Function1          dictionary                     prefixOSstream
GAMGAgglomeration  dimensionedType                primitivePatch
HashPtrTable       dynamicIndexedOctree           quaternion
HashSet            edges                          reconstruct
HashTable          ensightFile                    regex
HashTable2         ensightFoamReader              rigidBodyDynamics
HashTable3         error                          router
Hashing            etcFiles                       sha1
HashingSpeed       extendedStencil                simpleMatrix
IOobjectList       externalCoupler                sizeof
ISLList            faces                          slicedField
IStringStream      fieldDependency                sort
IndirectList       fieldMapping                   speed
List               fileName                       sphericalTensorField
ListOps            fileNameClean                  spline
Map                findCell-octree                string
Matrix             findSphereFeatureEdges-octree  stringList
NamedEnum          findTimes                      surfaceIntersection
ODE                foamVersion                    symmTensorField
OStringStream      fvSolutionCombine              syncTools
POSIX              fvc                            sysInfo
PackedList         fvc2D                          tensor
PackedList1        globalIndex                    tensor2D
PackedList2        globalMeshData                 tetTetOverlap
PackedList3        graph                          thermoMixture
PackedList4        graphXi                        tmpField
PatchEdgeFaceWave  hexRef8                        tokenize
PatchTools         io                             triTet
PointEdgeWave      labelRanges                    unitConversion
Polynomial         liquid                         vector
PtrList            mapDistributePolyMesh          vectorTools
PtrListDictionary  mappedPatch                    volField
SLList             maxMem                         volPointInterpolation
StaticHashTable    memInfo                        wallDist
Tuple2             mesh                           wallDistDyM
UDictionary        mkdir                          wordRe
UIndirectList      momentOfInertia                xfer
UniformField       mvBak

ディレクトリがたくさんあり,v1706の場合,146もある.察しの良い方はわかるとおり,OpenFOAMのテストディレクトリである."テスト"なので,正しい実装なのかどうかはわからない.名前から想像がつくテストのコードを眺めたり実行するのは勉強になるかもしれない.

簡単なテストの例

ioは名前からして入出力関連だな,と想像でき,試してみる.まずは自分のユーザ環境($FOAM_RUNなど)にコピーしてソースを見てみる.

$ cd $FOAM_RUN
$ cd ..  # $FOAM_RUNより一つ上のディレクトリ
$ mkdir test # テスト用ディレクトリを作成
$ cd test
$ cp -r $FOAM_APP/test/io ./
$ cd io
$ ls
Make  Test-io.C

本体のソースコードTest-io.CMakeディレクトリがある.Makeディレクトリの中にはfilesoptionsがある.

$ ls Make/
files  options
$ cat files
Test-io.C
EXE = $(FOAM_USER_APPBIN)/Test-io

filesは上記の2行が書かれているだけであり,optionsは何も書かれていない.すなわち,このテストはTest-io.C単体でコンパイル・実行ができる.コンパイル・実行前にソースを見てみる.

Test-io.C

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM 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.

    OpenFOAM 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 OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    test

Description

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

#include "IOstreams.H"
#include "IOmanip.H"
#include "scalar.H"
#include "List.H"

using namespace Foam;

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

int main(void)
{
    string st("sfdsf  sdfs23df sdf32f .  sdfsdff23/2sf32");
    Info<< word(string::validate<word>(st)) << "END" << endl;

    string st1("1234567");

    Info<< label(st1.size()) << tab << string(word(st1)) << endl;

    Info<< setw(20) << setprecision(3) << 1.234234 << endl;

    Info<< hex << 255 << endl;

    Info.operator Foam::OSstream&() << "stop" << endl;
}

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

文字列とか16進数とかのテストしているんだな,と大体わかる.コンパイルして実行してみる.

$ wmake
Making dependency list for source file Test-io.C
g++ -std=c++11 -m64 ... #省略

環境によって出力されるメッセージは異なるが無事にコンパイルされて$FOAM_USER_APPBIN以下にTest-ioが出来上がるはずである.あとはただ単にテストを実行するのみである.

$ ls $FOAM_USER_APPBIN 
Test-io
$ run # 一応,$FOAM_RUNに移動
$ Test-io
sfdsfsdfs23dfsdf32f.sdfsdff232sf32END
7   "1234567"
                1.23
ff
stop

期待どおりの動作であることがわかる.

まとめ

testディレクトリには単体のテストコードがたくさんあることがわかった.ソルバーカスタマイズなどの実用には使えないが,たまに学習用途で探検してみると,OpenFOAMでコードを書く際の技術力アップにつながるかもしれない(無駄かもしれない).

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3