OpenFOAM编程格式要求.docx

上传人:b****3 文档编号:5531825 上传时间:2022-12-18 格式:DOCX 页数:10 大小:19.17KB
下载 相关 举报
OpenFOAM编程格式要求.docx_第1页
第1页 / 共10页
OpenFOAM编程格式要求.docx_第2页
第2页 / 共10页
OpenFOAM编程格式要求.docx_第3页
第3页 / 共10页
OpenFOAM编程格式要求.docx_第4页
第4页 / 共10页
OpenFOAM编程格式要求.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

OpenFOAM编程格式要求.docx

《OpenFOAM编程格式要求.docx》由会员分享,可在线阅读,更多相关《OpenFOAM编程格式要求.docx(10页珍藏版)》请在冰豆网上搜索。

OpenFOAM编程格式要求.docx

OpenFOAM编程格式要求

OpenFOAMCodeStyleGuide

General

∙80characterlinesmax

∙Thenormalindentationis4spacesperlogicallevel.

∙Usespacesforindentation,nottabcharacters.

∙Avoidtrailingwhitespace.

∙Thebodyofcontrolstatements(eg, if, else, while,etc).isalwaysdelineatedwithbracebrackets.Apossibleexceptioncanbemadeinconjunctionwith break or continue aspartofacontrolstructure.

∙Thebodyof case statementsisusuallydelineatedwithbracebrackets.

∙Afall-through case shouldbecommentedassuch.

∙streamoutput

o<< isalwaysfourcharactersafterthestartofthestream,sothatthe << symbolsalign,i.e.

Info<< ... 

os  << ...f 

so

WarningIn("className:

:

functionName()") 

    << "Warning message" 

not

WarningIn("className:

:

functionName()") 

<< "Warning message" 

∙nounnecessaryclasssectionheaders,i.e.remove

// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * // 

    // Check 

    // Edit 

    // Write 

iftheycontainnothing,evenifplannedfor‘futureuse’

∙classtitlesarecentred

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

                        Class exampleClass Declaration 

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

not

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

                Class exampleClass Declaration 

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

The .H Files

∙headerfilespacing

oLeavetwoemptylinesbetweensections(asperfunctionsinthe .C fileetc)

∙use //-Comment commentsinheaderfiletoadddescriptionstoclassdataandfunctionsdobeincludedintheDoxygendocumentation:

otextonthelinestartingwith //- becomestheDoxygenbriefdescription;

otextonsubsequentlinesbecomestheDoxygendetaileddescription e.g.

//- A function which returns a thing 

//  This is a detailed description of the function 

//  which processes stuff and returns other stuff 

//  depending on things. 

thing function(stuff1, stuff2); 

olistentriesstartwith - or -# fornumberedlistsbutcannotstartonthelineimmediatelybelowthebriefdescriptionso

//- Compare triFaces 

//  Returns:

 

//  -  0:

 different 

//  - +1:

 identical 

//  - -1:

 same face, but different orientation 

static inline int compare(const triFace&, const triFace&); 

or

//- Compare triFaces returning 0, +1 or -1 

// 

//  -  0:

 different 

//  - +1:

 identical 

//  - -1:

 same face, but different orientation 

static inline int compare(const triFace&, const triFace&); 

not

//- Compare triFaces returning 0, +1 or -1 

//  -  0:

 different 

//  - +1:

 identical 

//  - -1:

 same face, but different orientation 

static inline int compare(const triFace&, const triFace&); 

olistcanbenestedforexample

//- Search for \em name 

//  in the following hierarchy:

 

//  -# personal settings:

 

//    - ~/.OpenFOAM/< VERSION>/ 

//      for version-specific files 

//    - ~/.OpenFOAM/ 

//      for version-independent files 

//  -# site-wide settings:

 

//    - $WM_PROJECT_INST_DIR/site/< VERSION> 

//      for version-specific files 

//    - $WM_PROJECT_INST_DIR/site/ 

//      for version-independent files 

//  -# shipped settings:

 

//    - $WM_PROJECT_DIR/etc/ 

// 

//  return the full path name or fileName() if the name cannot be found 

//  Optionally abort if the file cannot be found 

fileName findEtcFile(const fileName&, bool mandatory=false); 

oformoredetailsseetheDoxygendocumentation.

∙destructor

oIfaddingacommenttothedestructor-use //- andcodeasanormalfunction:

//- Destructor 

~className(); 

∙inlinefunctions

oUseinlinefunctionswhereappropriateinaseparate classNameI.H file.Avoidclutteringtheheaderfilewithfunctionbodies.

The .C Files

∙Donotopen/closenamespacesina .C file

oFullyscopethefunctionname,i.e.

Foam:

:

returnType Foam:

:

className:

:

functionName() 

not

namespace Foam 

    ... 

    returnType className:

:

functionName() 

    ... 

EXCEPTION

Whentherearemultiplelevelsofnamespace,theymaybeusedinthe .C file,i.e.

namespace Foam 

namespace compressible 

namespace RASModels 

    ... 

} // End namespace RASModels 

} // End namespace compressible 

} // End namespace Foam 

∙Usetwoemptylinesbetweenfunctions

CodingPractice

∙passingdataasargumentsorreturnvalues.

oPassbool,labelandscalarascopy,anythinglargerbyreference.

∙const

oUseeverywhereitisapplicable.

∙variableinitialisationusing

const className& variableName = otherClass.data(); 

not

const className& variableName(otherClass.data()); 

∙virtualfunctions

oIfaclassisvirtual,makeallderivedclassesvirtual.

ConditionalStatements

if (condition) 

    code; 

OR

if 

( 

   long condition 

) 

    code; 

not (nospacebetween if and ( used)

if(condition) 

    code; 

for and while Loops

for (i = 0; i < maxI; i++) 

    code; 

OR

for 

( 

    i = 0; 

    i < maxI; 

    i++ 

) 

    code; 

not this(nospacebetween for and ( used)

for(i = 0; i < maxI; i++) 

    code; 

Notethatwhenindexingthroughiterators,itisoftenslightlymoreefficienttousethepre-incrementform.Eg, ++iter insteadofiter++

forAll, forAllIter, forAllConstIter,etc.loops

like for loops,but

forAll( 

not

forAll ( 

Usingthe forAllIter and forAllConstIter macrosisgenerallyadvantageous-lesstyping,easiertofindlater.However,sincetheyaremacros,theywillfailiftheiteratedobjectcontainsanycommas.

ThefollowingwillFAIL!

:

forAllIter(HashTable >, foo, iter) 

TheseconveniencemacrosarealsogenerallyavoidedinothercontainerclassesandOpenFOAMprimitiveclasses.

SplittingOverMultipleLines

Splittingreturntypeandfunctionname

∙splitinitiallyafterthefunctionreturntypeandleftalign

∙donotput const ontoitsownline-useasplittokeepitwiththefunctionnameandarguments.

const Foam:

:

longReturnTypeName& 

Foam:

:

longClassName:

:

longFunctionName const 

not

const Foam:

:

longReturnTypeName& 

    Foam:

:

longClassName:

:

longFunctionName const 

nor

const Foam:

:

longReturnTypeName& Foam:

:

longClassName:

:

longFunctionName 

const 

nor

const Foam:

:

longReturnTypeName& Foam:

:

longClassName:

:

 

longFunctionName const 

∙ifitneedstobesplitagain,splitatthefunctionname(leavingbehindtheprecedingscoping=:

:

=s),andagain,leftalign,i.e.

const Foam:

:

longReturnTypeName& 

Foam:

:

veryveryveryverylongClassName:

:

 

veryveryveryverylongFunctionName const 

Splittinglonglinesatan“=”

Indentaftersplit

variableName = 

    longClassName.longFunctionName(longArgument); 

OR(wherenecessary)

variableName = 

    longClassName.longFunctionName 

    ( 

        longArgument1, 

        longArgument2 

    ); 

not

variableName = 

longClassName.longFunctionName(longArgument); 

nor

variableName = longClassName.longFunctionName 

( 

    longArgument1, 

    longArgument2 

); 

MathsandLogic

∙operatorspacing

a + b, a - b 

a*b, a/b 

a & b, a ^ b 

a = b, a !

= b 

a < b, a > b, a >= b, a <= b 

a || b, a && b 

∙splittingformulaeoverseverallines

Splitandindentasper“splittinglonglinesatan=”withtheoperatoronthelowerline.Alignoperatorsothatfirstvariable,functionorbracketonthenextlineis4spacesindentedi.e.

variableName = 

    a*(a + b) 

   *exp(c/d) 

   *(k + t); 

Thisissometimesmorelegiblewhensurroundedbyextraparentheses:

variableName = 

( 

    a*(a + b) 

   *exp(c/d) 

   *(k + t) 

); 

∙splittinglogicaltestsoverseverallines

outdenttheoperatorsothatthenextvariabletotestisalignedwiththefourspaceindentation,i.e.

if 

( 

    a == true 

 && b == c 

) 

General

∙Forreadabilityinthecommentblocks,certaintagsareusedthataretranslatedbypre-filteringthefilebeforesendingittoDoxygen.

∙Thetagsstartincolumn1,thecontentsfollowonthenextlinesandindentedby4spaces.Thefilterremovestheleading4spacesfromthefollowinglinesuntilthenexttagthatstartsincolumn1.

∙The‘Class’and‘Description’tagsarethemostimportantones.

∙Thefirstparagraphfollowingthe‘Description’willbeusedforthebriefdescription,theremainingparagraphsbecomethedetaileddescription.

Forexample,

Class 

    Foam:

:

myClass 

Description 

    A class for specifying the documentation style. 

    The class is implemented as a set of recommendations that may 

    sometimes be useful. 

∙Theclassnamemustbequalifiedbyitsnamespace,otherwiseDoxygenwillthinkyouaredocumentingsomeotherclass.

∙Ifyoudon’thaveanythingtosayabouttheclass(atthemoment),usethenamespace-qualifiedclassnameforthedescription.Thisaidswithfindingtheseunder-documentedclasseslater.

Class 

    Foam:

:

myUnderDocumentedClass 

Description 

    Foam:

:

myUnderDocumentedClass 

∙Use‘Class’and‘Namespace’tagsintheheaderfiles.TheDescriptionblockthenappliestodocumentingtheclass.

∙Use‘InClass’and‘InNamespace’inthesourcefiles.TheDescriptionblockthenappliestodocumentingthefileitself.

InClass 

    Foam:

:

myClass 

Description 

    Implements the read and writing of files. 

DoxygenSpecialCommands

Doxygenhasalargenumberofspecialcommandswitha=prefix.

Sincethefilteringremovestheleadingspaceswithintheblocks,theDoxygencommmandscanbeinsertedwithintheblockwithoutproblems.

InClass 

    Foam:

:

myClass 

Description 

    Implements the read and writing of files. 

    An example input file:

 

    \verbatim 

        patchName 

        { 

            type        myPatchType; 

            refValue    1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1