CEL教程Word文档下载推荐.docx
《CEL教程Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《CEL教程Word文档下载推荐.docx(12页珍藏版)》请在冰豆网上搜索。
∙CELExamples
∙CELTechnicalDetails
Release13.0-©
2010SASIP,Inc.Allrightsreserved.
13.1.
CELFundamentals
Thefollowingtopicswillbediscussed:
∙ValuesandExpressions
∙CFXExpressionLanguageStatements
13.1.1.
ValuesandExpressions
CELcanbeusedtogeneratebothvaluesandexpressions.Valuesaredimensional(thatis,withunits)ordimensionlessconstants.Thesimplesttypeofdefinitionisthedimensionlessvalue,forexample:
b=3.743
Youcanalsospecifyavaluewithunits,forexample:
g=9.81[ms^-2]
ThedimensionsofthequantitiesofinterestforCFDcalculationscanbewrittenintermsofmass,length,time,temperatureandangle.Theconceptofunitsisfundamentaltothebehaviorofvaluesandexpressions.
Valuescanbeuseddirectly,ortheycanbeusedaspartofanexpression.Forexample,youcanuseanexpressiontoaddtwovaluestogether:
<
Expr_1>
=
Value_1>
+
Value_2>
Inthisexample,youmaywanttopredefine<
and<
butthisisnotrequired.However,inordertoaddtwoquantitiestogether,theymusthavethesamedimension;
thatis,itismeaningfultoaddaquantityininchestooneexpressedinmeters,butitisnotmeaningfultoaddoneexpressedinkilogramstooneinsquarefeet.
Expressionscanalsobefunctionsofother(predefined)expressions:
Expr_2>
Value_3>
UnitsfollowtheconventionsintherestofCFX,inthatacalculationhasasetofsolutionunits(bydefault,SIunits),andthatanyquantitycanbedefinedeitherintermsofthesolutionunits,oranyothersetofunitswiththecorrectform.
Anexpressiondoesnothaveitsownunitsstring,butifitreferencesquantitiesthathavedimensions,thesewilldeterminetheresultingunitsfortheexpression.Forexample,ifanexpressiondependsinverselyonthesquareofthex
coordinate,thenithasimplieddimensionsoflengthtothepower-2.
13.1.1.1.
UsingLocatorsinExpressions
ACFXsimulationhasphysicsareasandmeshareas;
physicsareasareboundarieswhilemeshareasareregions.Thesetwotypesofareacanoccupycompletelydifferentspacesinasimulation;
however,thereisnorequirementthatareanamesbeuniquebetweenphysicsandmesh.Thiscanleadtoambiguitieswhenyouusethesenamesinexpressions.
Toavoidtheseambiguities,ANSYSCFXfirstcheckstoseeif"
@<
locator>
"
isaphysicsname;
ifthisisnotfound,thenameischeckedinthelistofmeshnames.Thusif"
in1"
isboththenameofaphysicsareaandthenameofamesharea,"
istakentoindicatethephysicsarea.
ANSYSCFXalsohas@REGIONCELsyntaxsothatyoucanidentifyanamedareaasbeingamesharea.Thustoidentifythemeshareain1,youwouldusethesyntax:
@REGION:
in1
Notethatif<
doesnotappearasaphysicsnameorameshname,theexpressionfails.
13.1.2.
CFXExpressionLanguageStatements
TheCFXExpressionLanguageisdeclarative.Youdeclarethenameanddefinitionoftheexpressionusingexpressionlanguagestatements.ThestatementsmustconformtoapredefinedsyntaxthatissimilartoFortranmathematicalstatementsandtoCstatementsforlogicalexpressions.
Thestatementmustconsistofthefollowing:
∙anumber,optionallywithassociatedunits.Thisdefinesaconstant.Constantswithoutunitsaretermeddimensionless.
∙formathematicalexpressions,oneormorereferencestomathematicalconstants,systemvariables,orexistinguservariables,separatedby+(addition),-(subtraction),*
(multiplication),/(division)and^(exponentiation),withoptionalgroupingofthesebyparentheses.Thesyntaxrulesfortheseexpressionsarethesameasthoseforconventionalarithmetic.
∙forlogicalexpressionsinvolvingrelationaloperators,oneormorereferencestomathematicalconstantsorresultsfrommathematicalexpressions,separatedby<
=(islessthanorequalto),<
(islessthan),==(isequalto),!
=(isnotequalto),>
(isgreaterthan)and>
=(isgreaterthanorequalto)withoptionalgroupingofthesebyparentheses.
∙forlogicalexpressionsinvolvinglogicaloperators,oneormorereferencestologicalconstantsorresultsfromrelationaloperationsseparatedby!
(negation),&
&
(logicalAND)and||(logicalOR),withoptionalgroupingbyparentheses.
13.1.2.1.
UseofConstants
Constantsdonotneedtobedefinedpriortobeingusedinanexpression.Forexample,youcouldchoosetoevaluatetheexpressionx+5[m].Or,youcoulddefineaconstant,b=5[m]andthencreateanexpressionx+b.
Thelogicalconstantsarefalseandtrue.Resultsoflogicalexpressionsareexpressedas0and1(correspondingtofalseandtrue,respectively).
Theuseofconstantsmaybeofbenefitingeneratingcomplicatedexpressionsorifyouhaveseveralexpressionsthatusethesameconstants.
13.1.2.2.
ExpressionSyntax
Allnumbersaretreatedasrealnumbers.
Theprecedenceofmathematicaloperatorsisasfollows(fromhighesttolowest):
∙Thepoweroperator^asinx^y.
∙Theunaryminusornegationoperator-asin-x.
∙Multiplicationanddivisionasinx*y/z.
∙Additionandsubtractionasinx+y-z.
Pleasenotethat,asofANSYSCFX10.0,theprecedenceofmathematicaloperatorshasbeenmadeconsistentwithstandardprogramminglanguagessuchasFortranandC.Therefore,thepoweroperator,whichpreviouslyhadlowerprecedencethanunaryminus,nowhasthehighestprecedence.
Theprecedenceoflogicalandrelationaloperatorsisasfollows(fromhighesttolowest):
∙Thenegationoperator!
asin!
x.
∙Therelationaloperatorsinvolvinglessthanorgreaterthan(<
=,<
>
and>
=)asinx>
=y.
∙Therelationaloperatorisequaltoandisnotequalto(==and!
=)asinx!
∙ThelogicalANDoperator(&
)asinx&
y.
∙ThelogicalORoperator(||)asinx||y.
13.1.2.3.
Multiple-LineExpressions
Itisoftenuseful,particularlywithcomplexexpressions,tousemorethanonelinewhencreatingyourexpression.CFXallowsyoutousemultiplelinestogenerateanexpression,providedeachlineisseparatedbyanappropriateoperator.
Forexample,youmayhaveanequation,A+B/C,thatconsistsofthreecomplexterms,A,B,andC.Inthiscase,youcouldusethreelinestosimplifycreatingtheexpression:
A+
B
/C
Notethattheoperatormaybeusedattheendofaline(A+)oratthebeginningofaline(/C).Youdonotneedtoentertheoperatortwice.
Oncetheexpressionhasbeencreated,itwillappearintheExistingDefinitionslistboxasifitweregeneratedonasingleline(A+B/C).
13.2.
CELOperators,Constants,andExpressions
Thefollowingtopicsarediscussed:
∙CELOperators
∙ConditionalifStatement
∙CELConstants
∙UsingExpressions
13.2.1.
CELOperators
CFXprovidesarangeofmathematical,logicalandoperationaloperatorsasbuilt-infunctionstohelpyoucreatecomplexexpressionsusingtheExpressiondetailsview.
Table
13.1
Operator
FirstOperand’sDimensions[x]
SecondOperand’sDimensions[y]
Operands’Values(Approx)
Result’sDimensions
-x
Any
[x]
x+y
Any
x-y
x*y
[x]*[y]
x/y
[x]/[y]
x^y(ifyisasimple,constant,integerexpression)
Dimensionless
Any[a]
[x]^y
x^y(ifyisanysimple,constant,expression)
x>
0
x^y(ifyisnotsimple&
constant)
!
x
0or1
x<
=y
y
x==y
x!
x&
x||y
[a]Fory<
0,xmustbenon-zero.
13.2.2.
ConditionalifStatement
CELsupportstheconditionalifstatementusingthefollowingsyntax:
if(cond_expr,true_expr,false_expr)
where:
∙cond_expr:
isthelogicalexpressionusedastheconditionaltest
∙true_expr:
isthemathematicalexpressionusedtodeterminetheresultiftheconditionaltestistrue.
∙false_expr:
isthemathematicalexpressionusedtodeterminetheresultiftheconditionaltestisfalse.
Note:
Theexpressionstrue_exprandfalse_exprarealwaysevaluatedindependentofwhethertheevaluationofcond_expristrueorfalse.Asaconsequence,aconditionalstate