lidhar 3d coding language

Upload: helover

Post on 03-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Lidhar 3d Coding Language

    1/16

    Strathprints Institutional Repository

    Stickland, Matthew and Fabre, Sylvie and Scanlon, Thomas (2010) User Defined Function: lidar_3D

    : NORSEWInD Report UoSNW006. [Report]

    Strathprints is designed to allow users to access the research output of the University of Strathclyde.

    Copyright c and Moral Rights for the papers on this site are retained by the individual authors

    and/or other copyright owners. You may not engage in further distribution of the material for any

    profitmaking activities or any commercial gain. You may freely distribute both the url (http://

    strathprints.strath.ac.uk/) and the content of this paper for research or study, educational, or

    not-for-profit purposes without prior permission or charge.

    Any correspondence concerning this service should be sent to Strathprints administrator:

    mailto:[email protected]

    http://strathprints.strath.ac.uk/

    http://strathprints.strath.ac.uk/http://strathprints.strath.ac.uk/mailto:[email protected]://strathprints.strath.ac.uk/http://strathprints.strath.ac.uk/mailto:[email protected]://strathprints.strath.ac.uk/http://strathprints.strath.ac.uk/
  • 7/28/2019 Lidhar 3d Coding Language

    2/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    UserDefinedFunction:lidar_3D

    MTStickland,SFabre,TScanlon

    January2010UniversityofStrathclydeNORSEWInDReportUoSNW006

    DepartmentofMechanicalEngineeringUniversityofStrathclyde75MontroseSt,GlasgowG11XJFax +441415525105 Email: [email protected]: +441415482842

  • 7/28/2019 Lidhar 3d Coding Language

    3/16

    UserDefinedFunction:lidar_3DUoSNW006revision01ABSTRACTThisreportdescribestheUserDefinedFunctionLidar_3DusedtointerrogateFLUENTdatafilestoprovidetherelevantdatafortheMathCADLiDARsimulationprogram.TheUDFwaswrittenintheCprogramminglanguageandcompiledusingMicrosoftvisualstudio2008.Thisreportcontainsalistingoftheprogram(version1.03).ThisreportcontainsadescriptionofthemethodologyrequiredtocompiletheUDFsothatitmaybecalledbyan"executeondemand"callfromFLUENT.Thereportalsoincludesadescriptionoftheinputandoutputdatafileformats.

  • 7/28/2019 Lidhar 3d Coding Language

    4/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    1. INTRODUCTION..................................................................................................................42. PROGRAMLISTING.............................................................................................................43. INSTINFOFILEFORMAT...................................................................................................104. COMPILEPROCEDURE......................................................................................................12

    DirectoryStructure...............................................................................................................12CompilingTheUdf................................................................................................................12RunningTheUDFInFLUNET................................................................................................13UDFOutputFile....................................................................................................................14

    5. REFERENCES.....................................................................................................................14

  • 7/28/2019 Lidhar 3d Coding Language

    5/16

    UserDefinedFunction:lidar_3DUoSNW006revision011.INTRODUCTION

    ThisreportdescribeshowtheFLUENTdatafileswereinterrogatedbytheUserDefinedFunction(UDF)"libudf2".TheUDFwaswrittenintheCprogramminglanguageandcompiledusingMicrosoftvisualstudio2008.Alistingoftheprogramversion1.03,whichwastheversioninuseatthetimethatthisreportwaswritten,canbefoundinsection#ofthisreport.ThisreportcontainsadescriptionofthemethodrequiredtocompiletheUDFsothatitmaybecalledbyan"executeondemand"callfromFLUENT.

    ThereportalsoexplainshowtheUDFworksthoughthecommentsmadewithintheprogramlistinginsection2

    2.PROGRAMLISTING/ *Thi s UDF pr ovi ded r el ates t o a support query. Thi s UDF shoul d bet r eat ed as

    a gui del i ne out l i ni ng t he appl i cat i on. Thi s i s not a consul t ancypr oj ectand has not t heref ore been checked under our consul t ancy pr ocedur es. I ti syour r esponsi bi l i t y t o check t he val i di t y of any si mul at i on ut i l i zi ngthi sUDF. Addi t i onal l y, UDF suppor t f or cur r ent l i censehol ders wi l l be l i mi t ed t o gui dance rel ated t o communi cat i on between aUDFand the FLUENT sol ver. Ot her aspect s of t he UDF devel opment pr ocesst hati ncl ude concept ual f unct i on desi gn, i mpl ement at i on ( wr i t i ng C code) ,

    compi l at i on and debuggi ng of C sour ce code, execut i on of t he UDF, andf unct i on desi gn ver i f i cat i on wi l l r emai n t he r esponsi bi l i t y of t he UDFaut hor.Feedback, comments or quer i es ar e most wel come*/

    #i ncl ude "poi nt _i n_cel l . h"#i ncl ude "mat h. h"

    / *bel ow i s t he macr o that det er mi nes t he l ocat i on of t he moni t or poi nt sand out put s r equi r ed i nf or mat i on. Thi s i s t he onl y macr o t hat r equi r esmodi f i cat i on t oaccount f or di f f er ent poi nt s di st r i but i on or t o change t he out putmet hod*/

    / * not e t hat phi i s t he cone angl e *// * not e psi i s t he asi mut h angl e */

  • 7/28/2019 Lidhar 3d Coding Language

    6/16

    UserDefinedFunction:lidar_3DUoSNW006revision01DEFI NE_ON_DEMAND( l i dar _3d){

    i nt yor n, zone;f l oat xl oc, yl oc, z l oc, hei ght , dh, h, nh, ver ;f l oat u, v, w, x, y, z, hmeas[ 50] ;f l oat phi _deg=30. 4, phi _r ad;f l oat npoi nt s=50;f l oat pi =3. 14159;f l oat psi _deg, psi _ i nc, psi _rad;f l oat pl oc[50] [ 3] , Vl os[ 50] [ 50] , asangl e[ 50] ;i nt i , j , nj ;char dummy;

    FI LE *exp_f i l e_pt r ;FI LE * i np_f i l e_pt r ;

    Domai n *d;Thread *ct ;cel l _ t c;r eal poi nt [ 3] ;

    ver=1. 03;

    Message( "l i dar si mul at i on pr ogr am ver si on %. 2f st ar t ed \ n", ver ) ;

    / * open a f i l e t o wr i t e dat a */

    exp_f i l e_pt r =f open( "dat a. dat ", "w") ;

    / * open a f i l e t o r ead dat a */

    i np_f i l e_pt r =f open( "i nsti nf o. dat ", "r ") ;

    / * pr i nt f ( "ent er t he measur ement hei ght of t he l i dar \ n") ; *// * scanf ( "%f ", &hei ght ) ; *// * pr i nt f ( "ent er t he of f set f r om t he or i gi n of t he l i dar x y and z

    \n " ) ; * // * scanf ( "%f %f %f ", &xl oc, &yl oc, &zl oc) ; */

    i f ( i np_f i l e_pt r ! =NULL)

    {f scanf ( i np_f i l e_pt r , "%s %s %s %s %s %s %s \ n", &dummy,

    &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) ;f scanf ( i np_f i l e_pt r , "%d %d %f %f %f %f %f \ n" , &zone,

    &yor n, &hei ght , &nh, &xl oc, &yl oc, &zl oc) ;}

    el se

  • 7/28/2019 Lidhar 3d Coding Language

    7/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    {pr i nt f ( "no f i l e name \ n") ;}

    f cl ose( i np_ f i l e_pt r ) ;

    / * i nput s r equi r ed f or t he f l uent UDF get domai n def i nes t he ent i r edomai n and l ookup t hread get t he t hreadnumber f or t he speci f i ed zone i n t he gi ven domai n */

    d = Get _Domai n( 1) ;ct = Lookup_Thr ead( d, zone) ;

    Message( " \ n %d hei ght s t o be cal cul at ed \ n" , nh) ;

    dh=hei ght / nh;

    phi _r ad=phi _deg*pi / 180;

    psi _i nc= 2*pi / 50;

    i f ( yor n == 1){Message( "ver bose out put ver si on %. 2f \ n" , ver ) ;

    f or ( j =1; j

  • 7/28/2019 Lidhar 3d Coding Language

    8/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    f pr i nt f ( exp_f i l e_pt r , "%6. 1f %6. 3f %6. 3f %6. 3f %6. 3f %6. 3f\ n" , poi nt [ 0] , poi nt [ 1] , poi nt [ 2] , u, v, w) ;

    f pr i nt f ( exp_f i l e_pt r, "L i dar s i mul at i on dat a \ n") ;

    f pr i nt f ( exp_f i l e_pt r , " ps i x y z u vw Vl os \ n") ;

    f or ( i =0; i

  • 7/28/2019 Lidhar 3d Coding Language

    9/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    / *get t he u, v and w vel oci t y component s i n t hat cel l */

    u=C_U( c, ct ) ;v=C_V( c, ct ) ;

    w=C_W( c, ct ) ;

    / *cal cul at e t he V l i ne of si ght based on t he x, y and z wi t ht he Li dar at t he or i gi n */

    Vl os[ j ] [ i ] =( u*x+v*y+w*z) / sqr t ( x*x+y*y+z*z) ;

    / * put t he of f set so that t he l ocat i on of t he measuremementpoi nt s ar e i n t he si mul at i on coor di nat e syst em */

    x = pl oc[ i ] [ 0] + xl oc;y = pl oc[ i ] [ 1] + yl oc;z = pl oc[ i ] [ 2] + zl oc;

    f pr i nt f ( exp_f i l e_ptr , "%6. 1f %6. 3f %6. 3f %6. 3f %6. 3f %6. 3f%6. 3f %6. 3f \ n", psi _rad, x, y, z, u, v, w, Vl os[j ] [ i ] ) ;

    }}

    }el se{Message( "abr evi at ed out put ver si on %. 2f \ n", ver ) ;

    f pr i nt f ( exp_f i l e_pt r , "%. 2f \ n" , nh) ;

    f or ( j =1; j

  • 7/28/2019 Lidhar 3d Coding Language

    10/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    psi _deg=psi _r ad*180/ pi ;pl oc[i ] [ 0] = h*si n( phi _r ad) *si n( psi _r ad) / cos( phi _r ad) ;pl oc[i ] [ 1] = h*si n( phi _r ad) *cos( psi _r ad) / cos( phi _r ad) ;pl oc[i ] [ 2] = h;

    }

    f or ( i =0; i

  • 7/28/2019 Lidhar 3d Coding Language

    11/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    i f ( ( c==c1) &&( ct ==ct 1) ) r et ur n FALSE; / * f ace' s c1 i s c so f i nwar d t oc */

    r et urn TRUE;}

    cxbool ean poi nt _i n_cel l ( r eal poi nt [ ND_ND] , cel l _t c, Thr ead *ct ){i nt i ;real di s t ;r eal p_r el [ ND_ND] , f _cen[ ND_ND] , A[ ND_ND] ;face_t f ;Thread *f t ;cxbool ean i nsi de = TRUE;c_f ace_ l oop( c, ct , i )

    {i f ( i nsi de)

    {f =C_FACE( c, ct , i ) ;

    f t =C_FACE_THREAD( c, ct , i ) ;F_CENTROI D( f _cen, f , f t ) ;F_AREA( A, f , f t ) ;NV_VV( p_r el , =, poi nt , - , f _cen) ; / * poi nt r el at i ve t o f _cen

    */di st =NV_DOT(p_r el , A) ;i f ( out ward_f ace( f , f t , c, ct) ) / * Count as i nsi de i f di st ==

    0. 0 */{i f ( di st > 0. 0) i nsi de = FALSE; }

    el se{i f ( di st < 0. 0) i nsi de = FALSE; }

    }

    }r et ur n i nsi de;}cel l _t cel l _cont ai ni ng_poi nt ( r eal poi nt [ ND_ND] , Thr ead *ct ){

    cel l _ t c ;cel l _t c_i n = NULL_CELL;begi n_c_l oop( c, ct )

    {i f ( c_i n == NULL_CELL) / * i f cel l not f ound yet */

    {i f ( poi nt _ i n_cel l ( poi nt , c, ct ) ) c_ i n = c;

    }

    }end_c_l oop( c, ct )r et ur n c_i n;

    }

    3.INSTINFOFILEFORMATThe

    file

    instinfo.dat,

    table

    1,

    contains

    the

    instructions

    for

    the

    UDF

    about

    where

    to

    interrogatetheFLUENTdataset.

  • 7/28/2019 Lidhar 3d Coding Language

    12/16

    UserDefinedFunction:lidar_3DUoSNW006revision01

    Zone Vebose Height Nh Xloc Yloc zloc2 0 40 20 129 129 25.5

    table1;instinfo.datfileformatZone ThezoneisdefinedbyFluentandistheregioninthedomainthatcontainsthefluid.It

    canbefoundbyselecting Define/Boundaryconditions/ZonefromthemainFLUENTmenu.if intheZonetablethefluidsurroundingthe rigisselectedthenthenumbershownintheIDboxatthebottomofthewindisthenumbertobeentered.ifthisnumberisnotcorrectthenthefollowing errormessageshouldappearError:FLUENTreceivedfatalsignal(ACCESS_VIOLATION)1.Noteexacteventsleadingtoerror.2.Savecase/dataundernewname.3.Exitprogramandrestarttocontinue.4.Reporterrortoyourdistributor.ErrorObject:()

    Verbose Either0or1If0thenallthatisechoedtotheFLUENTwindowisthesequentialnumberoftheheightbeinginterrogatedIf1thenthevelocitydatafromtheinterrogationisechoedtotheFLUENTwindow.

    Height Theheightabovethelidorthatistobeinterrogated

    nh Thenumberofheightstobeinterrogated.Thelocationofthemeasurementheightsarethenheight/nhplusincrementsofheight/nhoptoheight

    Xloc ThelocationoftheLiDARinthexdirectionofthefluentcoordinatesysteminthesamescaleasthefluentmodel

    yloc ThelocationoftheLiDARintheydirectionofthefluentcoordinatesysteminthesamescaleasthefluentmodel

    zloc ThelocationoftheLiDARintheydirectionofthefluentcoordinatesysteminthesamescaleasthefluentmodel

  • 7/28/2019 Lidhar 3d Coding Language

    13/16

    UserDefinedFunction:lidar_3DUoSNW006revision014.COMPILEPROCEDURE

    TocompileaUDFtointerrogatetheFLUENTdatafileasuitableCcompilerandlinkerneedstobeinstalled.ThecompilerandlinkerusedinthiscasewasMicrosoftVisualStudio2008whichistheonerecommendedbyFLUNT.comprehensivedetailsofcreatingUDFcanbefoundintherelevantANSYSFLUENTdocumentation.DirectoryStructureThelibrarystructurewascreatedoffofthedirectorycontainingthedatfiles

    copyuser_nt.udfandmakefile_nt.udffromthemain/fluent/srcdirectoryintothenew/2dor/3ddirectory.copythesourcefilefortheUDFintothe/srcdirectoryCompilingTheUdfedituser_nt.udfchangeSOURCEStoincludethenewsourcefile,VERSIONto2dor3ddependingonmodel,PARALLELNODEtononeifserialsolver.renamemakefile_nt.udftomakefile

  • 7/28/2019 Lidhar 3d Coding Language

    14/16

    UserDefinedFunction:lidar_3DUoSNW006revision01Ifthefollowingerrormessageappearsduringcompilationmakefile[51]:fatalerrorU105needtodefinetheenvironmentvariableFLUENT_INCthemakefileneedstobeeditedtoincludeFLUENT_INC=c:\fluent.incItmaybenecessaryfromtheconsoletorunvcvars32.batifeditingthemakefiledoesnotworkfirsttime.Thepathstatementmustincludealldirectoriesthatcontainfilesthataregoingtobecompiledoraccessedduringthecompileprocess.Tomodifythepathclickonthestartbutton,rightclickoncomputer,clickonproperties,clickadvancedsettings,undertheadvancedtabclickonenvironmentvariables,inthesystemvariableseditthepathstatement.OpentheVisualStudiocommandpromptwindowInthecommandpromptwindowchangedirectorytothe/3d(assumingthatthesimulationis3d)directorythatcontainsthemakefile.runnmakeinthisdirectory.RunningTheUDFInFLUNETWhencompilationhasbeensuccessfultheUDFneedstobeloadedandruninFLUENT.Fromthemainfluentwindowselectdefine/userdefined/functions/managemenuloadthecompiledUDFifsuccessfulamessagesimilartoOpeninglibrary"libudf2"...Library"libudf2\ntx86\3d\libudf.dll"opened

    lidar_3dDone.willappearintheconsolewherelidar_3distheUDFdefinedinthecompiledcode.afterthesimulationhascompletedorthedatahasbeenopenedfromanexistingruntheUDFisexecutedbyselectingdefine/userdefined/executeonedemandandthenselectingtheUDFfromthedropdownlist.NBifthelidar_3DUDFisrunthezoneintheinstinfo.datfilemustcorrespondtothefluidregion.

  • 7/28/2019 Lidhar 3d Coding Language

    15/16

    UserDefinedFunction:lidar_3DUoSNW006revision01UDFOutputFileThelidar_3DUDfcreatesanoutputfiledata.datTheformatofthefileisshownintable2.

    Numberofheightsheight

    Repeated

    forn

    heights

    point x point y point z u v wpsi(rad) x y z u v w Vlos

    Repeatedfor

    360o psi(rad) x y z u v w Vlos

    psi(rad) x y z u v w Vlostable2;lidar_3DUDFoutputfileformat

    TheoutputfilefromtheUDFisreadbytheMathCADLiDARsimulationprogramdetailsofwhichcanbefoundintheprogramdescriptiondocument[1].

    5.REFERENCES1. Stickland,M.,Scanlon,T.,Fabre,S.,"MathCADprogram;ZephIR_lidar_sim"report

    forEUNORSEWInD,UoSNW003,January2010

  • 7/28/2019 Lidhar 3d Coding Language

    16/16

    UserDefinedFunction:lidar_3DUoSNW006revision01