OpenFOAM编程格式要求.doc_第1页
OpenFOAM编程格式要求.doc_第2页
OpenFOAM编程格式要求.doc_第3页
OpenFOAM编程格式要求.doc_第4页
OpenFOAM编程格式要求.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 possible 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 thesymbols 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/*-*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 documentation: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,stuff2);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,+1or-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 example/-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_PROJECT_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:/-DestructorclassName(); 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()notnamespaceFoam.returnTypeclassName:functionName().EXCEPTIONWhen there are multiple levels of namespace, they may be used in the.Cfile, spaceFoamnamespacecompressiblenamespaceRASModels./EndnamespaceRASModels/Endnamespacecompressible/EndnamespaceFoam Use two empty lines between functionsCoding Practice 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 functionso 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 that 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 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 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:longReturnTypeName&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), 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(longArgument1,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 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)*exp(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 sending 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 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 qualified 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:myUnderDocumentedClassDescriptionFoam: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:myClassDescriptionImplementsthereadandwritingoffiles.Doxygen Special CommandsDoxygen has a large number of special commands with a =prefix.Since the filtering removes the leading spaces within the blocks, the Doxygen commmands can be inserted within the block without problems.InClassFoam:myClassDescriptionImplementsthereadandwritingoffiles.Anexampleinputfile:verbatimpatchNametypemyPatchType;refValue100;valueuniform1;endverbatimWithintheimplementation,aloopoverallpatchesisdone:codeforAll(patches,patchI)./someoperationendcodeHTML Special CommandsSince Doxygen also handles HTML tags to a certain extent, the angle brackets need quoting in the documentation blocks. Non-HTML tags cause Doxygen to complain, but seem to work anyhow.eg, The template with typeis a bad example. The template with typeis a better example. The template with typecauses Doxygen to complain about an unknown html type, but it seems to work okay anyhow.Documenting Namespaces If namespaces are explictly declared with theNamespace()macro, they should be documented there. If the namespaces is used to hold sub-models, the namespace can be documented in the same file as the class with the model selector. eg,documentednamespaceFoam:functionEntrieswithintheclassFoam:functionEntry If nothing else helps, find some sensible header. eg,namespaceFoamisdocumentedinthefoamVersion.HfileDocumenting typedefs and classes defined via macros not yet properly resolvedDocumenting ApplicationsAny number of classes might be defined by a particular application, but these classes will not, however, be available to other parts of OpenFOAM. At the moment, the sole purpuse for running Doxygen on the applications is to extract program usage information for the -doc option.The documentation

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论