1、OpenFOAM编程格式要求OpenFOAM Code Style GuideGeneral 80 character lines max The normal indentation is 4 spaces per logical level. Use spaces for indentation, not tab characters. Avoid trailing whitespace. The body of control statements (eg,if,else,while, etc). is always delineated with brace brackets. A p
2、ossible exception can be made in conjunction withbreakorcontinueas part of a control structure. The body ofcasestatements is usually delineated with brace brackets. A fall-throughcaseshould be commented as such. stream outputo is always four characters after the start of the stream, so that thesymbo
3、ls align, i.e.Info.os.fsoWarningIn(className:functionName()WarningmessagenotWarningIn(className:functionName()Warningmessage no unnecessary class section headers, i.e. remove/*PrivateMemberFunctions*/Check/Edit/Writeif they contain nothing, even if planned for future use class titles are centred/*-*
4、ClassexampleClassDeclaration*-*/not/*-*ClassexampleClassDeclaration*-*/The.HFiles header file spacingo Leave two empty lines between sections (as per functions in the.Cfile etc) use/- Commentcomments in header file to add descriptions to class data and functions do be included in the Doxygen documen
5、tation:o text on the line starting with/-becomes the Doxygen brief description;o text on subsequent lines becomes the Doxygen detailed descriptione.g./-Afunctionwhichreturnsathing/Thisisadetaileddescriptionofthefunction/whichprocessesstuffandreturnsotherstuff/dependingonthings.thingfunction(stuff1,s
6、tuff2);o list entries start with-or-#for numbered lists but cannot start on the line immediately below the brief description so/-ComparetriFaces/Returns:/-0:different/-+1:identical/-1:sameface,butdifferentorientationstaticinlineintcompare(consttriFace&,consttriFace&);or/-ComparetriFacesreturning0,+1
7、or-1/-0:different/-+1:identical/-1:sameface,butdifferentorientationstaticinlineintcompare(consttriFace&,consttriFace&);not/-ComparetriFacesreturning0,+1or-1/-0:different/-+1:identical/-1:sameface,butdifferentorientationstaticinlineintcompare(consttriFace&,consttriFace&);o list can be nested for exam
8、ple/-Searchforemname/inthefollowinghierarchy:/-#personalsettings:/-/.OpenFOAM/forversion-specificfiles/-/.OpenFOAM/forversion-independentfiles/-#site-widesettings:/-$WM_PROJECT_INST_DIR/site/forversion-specificfiles/-$WM_PROJECT_INST_DIR/site/forversion-independentfiles/-#shippedsettings:/-$WM_PROJE
9、CT_DIR/etc/returnthefullpathnameorfileName()ifthenamecannotbefound/OptionallyabortifthefilecannotbefoundfileNamefindEtcFile(constfileName&,boolmandatory=false);o for more details see the Doxygen documentation. destructoro If adding a comment to the destructor - use/-and code as a normal function:/-D
10、estructorclassName(); inline functionso Use inline functions where appropriate in a separateclassNameI.Hfile. Avoid cluttering the header file with function bodies.The.CFiles Do not open/close namespaces in a.Cfileo Fully scope the function name, i.e.Foam:returnTypeFoam:className:functionName()notna
11、mespaceFoam.returnTypeclassName:functionName().EXCEPTIONWhen there are multiple levels of namespace, they may be used in the.Cfile, i.e.namespaceFoamnamespacecompressiblenamespaceRASModels./EndnamespaceRASModels/Endnamespacecompressible/EndnamespaceFoam Use two empty lines between functionsCoding Pr
12、actice passing data as arguments or return values.o Pass bool, label and scalar as copy, anything larger by reference. consto Use everywhere it is applicable. variable initialisation usingconstclassName&variableName=otherClass.data();notconstclassName&variableName(otherClass.data(); virtual function
13、so If a class is virtual, make all derived classes virtual.Conditional Statementsif(condition)code;ORif(longcondition)code;not(no space betweenifand(used)if(condition)code;forandwhileLoopsfor(i=0;imaxI;i+)code;ORfor(i=0;imaxI;i+)code;notthis (no space betweenforand(used)for(i=0;imaxI;i+)code;Note th
14、at when indexing through iterators, it is often slightly more efficient to use the pre-increment form. Eg,+iterinstead ofiter+forAll,forAllIter,forAllConstIter, etc. loopslikeforloops, butforAll(notforAll(Using theforAllIterandforAllConstItermacros is generally advantageous - less typing, easier to
15、find later. However, since they are macros, they will fail if the iterated object contains any commas.The following will FAIL!:forAllIter(HashTablelabelPair,edge,Hash,foo,iter)These convenience macros are also generally avoided in other container classes and OpenFOAM primitive classes.Splitting Over
16、 Multiple LinesSplitting return type and function name split initially after the function return type and left align do not putconstonto its own line - use a split to keep it with the function name and arguments.constFoam:longReturnTypeName&Foam:longClassName:longFunctionNameconstnotconstFoam:longRe
17、turnTypeName&Foam:longClassName:longFunctionNameconstnorconstFoam:longReturnTypeName&Foam:longClassName:longFunctionNameconstnorconstFoam:longReturnTypeName&Foam:longClassName:longFunctionNameconst if it needs to be split again, split at the function name (leaving behind the preceding scoping =:=s),
18、 and again, left align, i.e.constFoam:longReturnTypeName&Foam:veryveryveryverylongClassName:veryveryveryverylongFunctionNameconstSplitting long lines at an “=”Indent after splitvariableName=longClassName.longFunctionName(longArgument);OR (where necessary)variableName=longClassName.longFunctionName(l
19、ongArgument1,longArgument2);notvariableName=longClassName.longFunctionName(longArgument);norvariableName=longClassName.longFunctionName(longArgument1,longArgument2);Maths and Logic operator spacinga+b,a-ba*b,a/ba&b,aba=b,a!=bab,a=b,a=ba|b,a&b splitting formulae over several linesSplit and indent as
20、per “splitting long lines at an =” with the operator on the lower line. Align operator so that first variable, function or bracket on the next line is 4 spaces indented i.e.variableName=a*(a+b)*exp(c/d)*(k+t);This is sometimes more legible when surrounded by extra parentheses:variableName=(a*(a+b)*e
21、xp(c/d)*(k+t); splitting logical tests over several linesoutdent the operator so that the next variable to test is aligned with the four space indentation, i.e.if(a=true&b=c)General For readability in the comment blocks, certain tags are used that are translated by pre-filtering the file before send
22、ing it to Doxygen. The tags start in column 1, the contents follow on the next lines and indented by 4 spaces. The filter removes the leading 4 spaces from the following lines until the next tag that starts in column 1. The Class and Description tags are the most important ones. The first paragraph
23、following the Description will be used for the brief description, the remaining paragraphs become the detailed description.For example,ClassFoam:myClassDescriptionAclassforspecifyingthedocumentationstyle.Theclassisimplementedasasetofrecommendationsthatmaysometimesbeuseful. The class name must be qua
24、lified by its namespace, otherwise Doxygen will think you are documenting some other class. If you dont have anything to say about the class (at the moment), use the namespace-qualified class name for the description. This aids with finding these under-documented classes later.ClassFoam:myUnderDocum
25、entedClassDescriptionFoam:myUnderDocumentedClass Use Class and Namespace tags in the header files. The Description block then applies to documenting the class. Use InClass and InNamespace in the source files. The Description block then applies to documenting the file itself.InClassFoam:myClassDescri
26、ptionImplementsthereadandwritingoffiles.Doxygen Special CommandsDoxygen has a large number of special commands with a =prefix.Since the filtering removes the leading spaces within the blocks, the Doxygencommmands can be inserted within the block without problems.InClassFoam:myClassDescriptionImplementsthereadandwritingoffiles.Anexampleinputfile:verbatimpatchNametypemyPatchType;refValue1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1