©2012ANSYS,Inc.June17,20131Release14.514.5ReleaseChapter2UDFCompilationandInterpretationUserDefinedFunctionsinANSYSFluent©2012ANSYS,Inc.June17,20132Release14.5HowtouseUDFsUDFsmustbecompiledandlinkedtothemaincodeTherearetwooptions:•Interpreted–TheUDFistranslatedintoassemblycodewhichisexecutedona“line-by-line”basisatruntime–Doesnotneedaseparatecompiler(completelyautomatic)–Slowerexecutionandusesmorememory–OnlybasiclanguageandFLUENTfeaturesimplemented–Restrictedfunctionalityinparallelcases•Compiled–TheUDFfilesarecompiledandlinkedtothemaincode–FullClanguageandallstandardlibraries–AccesstofullFLUENTfunctionset–NeedsacompilerforeveryOStobeusedon©2012ANSYS,Inc.June17,20133Release14.5InterpretedUDFsTheinterpreterdoesnothaveallofthecapabilitiesofthestandardCcompilerInterpretedUDFscannotcontain•declarationsoflocalstructures,unions,pointerstofunctions,andarraysoffunctions•directstructurereferencesCanaccessdatastoredinaFLUENTstructureonlyviaalimitedsetofmacrosUsersarestronglyencouragedtousecompilationforallbutthemostsimpleUDFs©2012ANSYS,Inc.June17,20134Release14.5Define→UserDefined→InterpretedInterpretingtheUDFsClickInterpretDefaultstacksizemightbetoosmallforlargearrayssomayneedincreasingTheassemblylanguagecodewillbedisplayedifnoerrorsarefound.©2012ANSYS,Inc.June17,20135Release14.5CompilingtheUDFsDefine→UserDefined→Function→Compiled•ClickBuild•Thecompilerwillbuildthesharedobjectfiles•Loadthesharedlibrary•OnWindowstorecompileyouwillneedtounloadapreviouslycompiledUDFlibraryusing:–Define→UserDefined→Function→Manage–SelectthelibraryandthenclickUnload©2012ANSYS,Inc.June17,20136Release14.5libudfntx86w-profile.cmakefileuser_nt.udflibudf.dllmakefileuser_nt.udfsrcWindowsTree3d2dlibudfMakefilesrcultramakefileUnixTreew-profile.c3d2dMachinedependent:ultrawin64lnamd64ntx86DirectoryTreeforaCompiledUDFLibrarymakefilelibudf.dllw-profile.clibudf.souser.udfw-profile.clibudf.souser.udfmakefileSymboliclinks,notcopies