Mr. Wilson Wang 0 Report post Posted February 2, 2016 I have a source to export offset file, but it is too time-consuming. what I would like to do is to make a string array to store all the string and put it all together to one file instead of writing it line by line. // --- This feature creator has been automatically modified to suit the new syntax of if-commands. --- if (export) goto(exportfile) else goto(end) endif exportFile: string workingDir(designdir+"/") // create a new path for the working directory mkpath(workingDir) // open a file for writing FFile out(workingDir+shipName+".off") out.openWrite() out.writeLine("1") out.writeLine("****** Hull Form Data for SRI CFD Program ******") out.writeLine("* Ship Form Export from the FRIENDSHIP-Framework") out.writeLine("* Ship Name = "+shipName) out.writeLine("************************************************") out.writeLine("* [1] General Information **********************") out.writeLine("* alpp xmid") out.writeLine(" 1.0000 0.0000") out.writeLine("* [2] Profile Points ***************************") out.writeLine("* Sec.ID x z 0/1 Corner") unsigned sizeProfile(profileExport.getSize()) integer i(0) point temp() point tempCheck() unsigned c(0) unsigned flag(0) double tempVal(0) loop1: if (OR(profileExport.at(i):y.toInt() == profileExport.at(i):y, (profileExport.at(i):y.toInt() + 1 - profileExport.at(i):y) > 0.0001)) |tempCheck.setVector(#(profileExport.at(i))) else |tempCheck.setVector([#(profileExport.at(i):x), #(profileExport.at(i):y.toInt() + 1), #(profileExport.at(i):z)]) endif temp.setX(#profileExport.at(i).getX()) temp.setY(#tempCheck.getY().toInt()) temp.setZ(if(abs(profileExport.at(i).getZ())<0.00005,0,#profileExport.at(i).getZ())) flag.setValue((#abs(tempCheck.getY()*10)-#abs(temp.getY()*10)).toInt()) tempVal.setValue(#abs(tempCheck.getY()*1000)-#abs(temp.getY()*1000)) c.setValue(#tempVal-#abs(flag*100)) out.writeLine(" "+temp.getY()+" "+temp.getX()+" "+temp.getZ()+" "+flag+" "+c) i+=1 if (i < sizeProfile) goto(loop1) endif out.writeLine(" -999 0.000000 0.000000 1 0") out.writeLine("* [3] Flat Planes ******************************") out.writeLine("* y_sflat; half breadth of side flat plane") out.writeLine(""+halfbeam/lpp) out.writeLine("* z_bflat; z-coordinate of bottom flat plane. Assumed to be 0") out.writeLine("* [4] sectionsExport *********************************") unsigned sizeSections(sectionsExport.getSize()) unsigned sizeSection(0) i=0 integer j(0) sectionsLoop: sectionsExport.at(i).removeDuplicates() out.writeLine("*** Station No. "+(i+1)) out.writeLine(""+(i+1)+" "+sectionsExport.at(i).getFirst().getX()+" 0.000000") out.writeLine("* dz y") sizeSection=sectionsExport.at(i).getSize() j=0 pointLoop: if (j == 0) goto(next1) endif if (AND(IF(abs(sectionsExport.at(i).at(j - 1):y) < 3e-05, 0, sectionsExport.at(i).at(j - 1):y) == IF(abs(sectionsExport.at(i).at(j):y) < 3e-05, 0, sectionsExport.at(i).at(j):y), IF(abs(sectionsExport.at(i).at(j - 1):z) < 5e-05, 0, sectionsExport.at(i).at(j - 1):z) == IF(abs(sectionsExport.at(i).at(j):z) < 5e-05, 0, sectionsExport.at(i).at(j):z))) goto(next2) endif next1: out.writeLine(""+if(abs(sectionsExport.at(i).at(j).getZ())<0.00005,0,sectionsExport.at(i).at(j).getZ())+" "+if(abs(sectionsExport.at(i).at(j).getY())<0.00003,0,sectionsExport.at(i).at(j).getY())) next2: j+=1 if (j < sizeSection) goto(pointloop) endif out.writeLine(" 0 -999 ; delimiter") i+=1 if (i < sizeSections) goto(sectionsloop) endif out.writeLine("* Sec.ID x z0 ----------------------") out.writeLine(" -999 0 0 ; delimiter") out.writeLine("* [5] Trim *************************************") out.writeLine("* FP AP") out.writeLine(""+draftAP/lpp+" "+draftFP/lpp) out.close() //export.setValue(false) end: double finish(1) Share this post Link to post Share on other sites
Karsten Wenzke 12 Report post Posted February 2, 2016 Dear Scott, can you attach a sample project_What are the arguments of the feature. The time comsuming is not the line by line writing.You can use the debugger and the profiling function which helps you to find out how much time each line nedds to be executed.Which Version do you use? Change point temp() point tempCheck() to vector temp() vector tempCheck() And your If statements with the and and or's are super expensive.And you are exporting every single point of each offset which might be 100 or even more. I don't like goto statements at all because they are very complicated to understand at least for me but if you like them okay. Cheers, Karsten Share this post Link to post Share on other sites
Stefan Wunderlich 6 Report post Posted February 2, 2016 Hi Wilson, There are some parts that can be optimized within the feature. Since we do not have an optimizing compiler, each statement has to be executed like it is. So it is a good practice to use temporary variables to simplify the code. To give you an example: if (OR(profileExport.at(i):y.toInt() == profileExport.at(i):y, (profileExport.at(i):y.toInt() + 1 - profileExport.at(i):y) > 0.0001)) |tempCheck.setVector(#(profileExport.at(i)))else |tempCheck.setVector([#(profileExport.at(i):x), #(profileExport.at(i):y.toInt() + 1), #(profileExport.at(i):z)])endif the statement "profileExport.at(i)" has to be executed several times. Putting it in a temporary is a good idea: FVector3 vec(profileExport.at(i)) if (OR(vec:y.toInt() == vec:y, (vec:y.toInt() + 1 - vec:y) > 0.0001)) |tempCheck.setVector(vec)else |tempCheck.setVector([vec:x, vec:y.toInt() + 1, vec:z])endif You could even write: FVector3 vec(profileExport.at(i))double y(vec:y) if (OR(y.toInt() == y, (y.toInt() + 1 - y) > 0.0001)) |tempCheck.setVector(vec)else |tempCheck.setVector([vec:x, y.toInt() + 1, vec:z])endif I am confident that you can really speed up the feature by only modifying it in the mentioned way. If you are interested, check out the blog entry of my college Arne who is diving deeply into the subject of effective feature programming:https://www.caeses.com/forum/index.php?/blog/3/entry-5-a-christmas-present-effective-fpl Cheers,Stefan Share this post Link to post Share on other sites
Mr. Wilson Wang 0 Report post Posted February 2, 2016 Dear Scott, can you attach a sample project_What are the arguments of the feature. The time comsuming is not the line by line writing.You can use the debugger and the profiling function which helps you to find out how much time each line nedds to be executed.Which Version do you use? Change point temp() point tempCheck() to vector temp() vector tempCheck() And your If statements with the and and or's are super expensive.And you are exporting every single point of each offset which might be 100 or even more. I don't like goto statements at all because they are very complicated to understand at least for me but if you like them okay. Cheers, KarstenThank you very much, Karsten.sectionExport is a FOffsetGroup.profileExport is a FOffset.export=false.The version is 4.03.I don't like goto either. It is not my code and I'm freshman. is there any syntax like return and any instruction for the basic syntax? Share this post Link to post Share on other sites
Mr. Wilson Wang 0 Report post Posted February 2, 2016 Hi Wilson, There are some parts that can be optimized within the feature. Since we do not have an optimizing compiler, each statement has to be executed like it is. So it is a good practice to use temporary variables to simplify the code. To give you an example: if (OR(profileExport.at(i):y.toInt() == profileExport.at(i):y, (profileExport.at(i):y.toInt() + 1 - profileExport.at(i):y) > 0.0001)) |tempCheck.setVector(#(profileExport.at(i)))else |tempCheck.setVector([#(profileExport.at(i):x), #(profileExport.at(i):y.toInt() + 1), #(profileExport.at(i):z)])endif the statement "profileExport.at(i)" has to be executed several times. Putting it in a temporary is a good idea: FVector3 vec(profileExport.at(i)) if (OR(vec:y.toInt() == vec:y, (vec:y.toInt() + 1 - vec:y) > 0.0001)) |tempCheck.setVector(vec)else |tempCheck.setVector([vec:x, vec:y.toInt() + 1, vec:z])endif You could even write: FVector3 vec(profileExport.at(i))double y(vec:y) if (OR(y.toInt() == y, (y.toInt() + 1 - y) > 0.0001)) |tempCheck.setVector(vec)else |tempCheck.setVector([vec:x, y.toInt() + 1, vec:z])endif I am confident that you can really speed up the feature by only modifying it in the mentioned way. If you are interested, check out the blog entry of my college Arne who is diving deeply into the subject of effective feature programming:https://www.caeses.com/forum/index.php?/blog/3/entry-5-a-christmas-present-effective-fpl Cheers,Stefan hi Stefan Thank you very much for your help. It is really instructive. Share this post Link to post Share on other sites
Karsten Wenzke 12 Report post Posted February 2, 2016 Hey Scott, The pdf Stefan has mentioned is pretty good and I would recommend scanning it for buzzwords you are interested in (go to, while, loop) and read the specific section. General information about feature programming and its basic syntax can be found here:1) documentation browser > features in the header you can find a link to FFeaturedefinition which explains the syntax and how to use it which some examples as well.2) documentation browser > tutorials > features > Introduction and loopsThe loops tutorial last page shows the difference between go to and loop and how to use a loop instead of a goto statement :-)3) take a look at feature programming forum here and there a lot posts about exports as well.4) (In the create function tab of the feature definition). You can you the code snippet menu (blue rectangular icon) the first entry. holds all available control structures. Hope this helps and also Stefans information and changes should improve the speed of the feature.If you still have problems and/or questions let us know. Cheers, Karsten Share this post Link to post Share on other sites