CEL教程.docx
《CEL教程.docx》由会员分享,可在线阅读,更多相关《CEL教程.docx(12页珍藏版)》请在冰豆网上搜索。
CEL教程
Chapter 13:
CFXExpressionLanguage(CEL)
CFXExpressionLanguage(CEL)isaninterpreted,declarativelanguagethathasbeendevelopedtoenableCFXuserstoenhancetheirsimulationswithoutrecoursetowritingandlinkingseparateexternalFortranroutines.
YoucanuseCELexpressionsanywhereavalueisrequiredforinputinANSYSCFX.
CELcanbeusedto:
∙Definematerialpropertiesthatdependonothervariables.
∙Specifycomplexboundaryconditions.
∙Addtermstothesolvedequations.
Youcanalsomonitorthevalueofanexpressionduringthesolutionusingmonitorpoints.
Important:
ThereissomeCELthatworkselsewhereinANSYSCFX,butnotinCFD-Post.AnyexpressioncreatedinCFX-PreandusedasaDesignExplorationoutputparametercouldpotentiallycausefatalerrorsduringtheDesignExplorationrun,soyoushouldcreateallexpressionsforDesignExplorationoutputparametersinCFD-Post.
Thischapterdescribes:
∙CELFundamentals
∙CELOperators,Constants,andExpressions
∙CELExamples
∙CELTechnicalDetails
Release13.0-©2010SASIP,Inc.Allrightsreserved.
13.1. CELFundamentals
Thefollowingtopicswillbediscussed:
∙ValuesandExpressions
∙CFXExpressionLanguageStatements
Release13.0-©2010SASIP,Inc.Allrightsreserved.
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:
= +
Inthisexample,youmaywanttopredefineand,butthisisnotrequired.However,inordertoaddtwoquantitiestogether,theymusthavethesamedimension;thatis,itismeaningfultoaddaquantityininchestooneexpressedinmeters,butitisnotmeaningfultoaddoneexpressedinkilogramstooneinsquarefeet.
Expressionscanalsobefunctionsofother(predefined)expressions:
= +
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"@"isaphysicsname;ifthisisnotfound,thenameischeckedinthelistofmeshnames.Thusif"in1"isboththenameofaphysicsareaandthenameofamesharea,"@"istakentoindicatethephysicsarea.
ANSYSCFXalsohas@REGIONCELsyntaxsothatyoucanidentifyanamedareaasbeingamesharea.Thustoidentifythemeshareain1,youwouldusethesyntax:
@REGION:
in1
Notethatifdoesnotappearasaphysicsnameorameshname,theexpressionfails.
Release13.0-©2010SASIP,Inc.Allrightsreserved.
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!
=y.
∙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).
Release13.0-©2010SASIP,Inc.Allrightsreserved.
13.2. CELOperators,Constants,andExpressions
Thefollowingtopicsarediscussed:
∙CELOperators
∙ConditionalifStatement
∙CELConstants
∙UsingExpressions
Release13.0-©2010SASIP,Inc.Allrightsreserved.
13.2.1. CELOperators
CFXprovidesarangeofmathematical,logicalandoperationaloperatorsasbuilt-infunctionstohelpyoucreatecomplexexpressionsusingtheExpressiondetailsview.
Table 13.1 CELOperators
Operator
FirstOperand’sDimensions[x]
SecondOperand’sDimensions[y]
Operands’Values(Approx)
Result’sDimensions
-x
Any
Any
[x]
x+y
Any
[x]
Any
[x]
x-y
Any
[x]
Any
[x]
x*y
Any
Any
Any
[x]*[y]
x/y
Any
Any
0
[x]/[y]
x^y(ifyisasimple,constant,integerexpression)
Any
Dimensionless
Any[a]
[x]^y
x^y(ifyisanysimple,constant,expression)
Any
Dimensionless
x>0
[x]^y
x^y(ifyisnotsimple&constant)
Dimensionless
Dimensionless
x>0
Dimensionless
!
x
Dimensionless
0or1
Dimensionless
x<=y
Any
[x]
0or1
Dimensionless
xAny
[x]
0or1
Dimensionless
x>y
Any
[x]
0or1
Dimensionless
x>=y
Any
[x]
0or1
Dimensionless
x==y
Any
[x]
0or1
Dimensionless
x!
=y
Any
[x]
0or1
Dimensionless
x&&y
Dimensionless
Dimensionless
0or1
Dimensionless
x||y
Dimensionless
Dimensionless
0or1
Dimensionless
[a]Fory<0,xmustbenon-zero.
Release13.0-©2010SASIP,Inc.Allrightsreserved.
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