function(spec) { // ------------------------------------------------------------------------ var that = {}; that.boat = spec === undefined ? 'Boat' : spec; var Appendage = "Boat.Centre.FrontFoil"; // Which appendage var ElementID = 1; // Which element of the appendage var iCPOpt = [0, 1, 2, 3, 4, 5, 6]; // Index of CPs you want to optimise // Could read existing foil parameters here and store for later use, e.g. for global scaling of chord // ------------------------------------------------------------------------ // When model loads, set initial chord lengths according to the current chord definition // ------------------------------------------------------------------------ that.init = function (callType) { if (Host.foilHolder().foilDefinition("Boat.Centre.FrontFoil")) { // print("init " + callType); for (var i = 0; i < iCPOpt.length; i++) { var iCP = iCPOpt[i]; var input = B("Boat.Centre.ChordCP" + i); if (input != null) { var initChord = Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).chordDefinition().CP(iCP); B("Boat.Centre.ChordCP" + i).setValue(initChord); // These need to be a states, not JS functions } } }; }; // ------------------------------------------------------------------------ // Update model with new chord values // ------------------------------------------------------------------------ that.preUpdate = function(callType) { if (Host.foilHolder().foilDefinition("Boat.Centre.FrontFoil")) { // print("preUpdate " + callType); for (var i = 0; i < iCPOpt.length; i++) { var iCP = iCPOpt[i]; var input = B("Boat.Centre.ChordCP" + i); // These need to be states, not JS functions if (input != null) { var CPy = input.outputValue(); Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).chordDefinition().setCPy(iCP, 0, CPy); } } B(Appendage).updateFoilFromDefinition(Host.foilHolder().foilDefinition(Appendage), false) // // Update structural properties at all time steps of the optimisation (not after a manual change) // if (callType != G.CallTypes.MANUAL_INIT_MAJOR) { // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).xnSCDefinition().estimate(); // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).ynSCDefinition().estimate(); // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).EIDefinition().estimate(); // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).GKDefinition().estimate(); // } // Update structural properties only if optimisation is successful. if (callType == G.CallTypes.OPTIMISATION_SUCCESS) { // print("preUpdate " + callType); Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).xnSCDefinition().estimate(); Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).ynSCDefinition().estimate(); Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).EIDefinition().estimate(); Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).GKDefinition().estimate(); } } // Other foil access: // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).rondureDefinition().setCP(iCP,x,y); // Host.foilHolder().foilDefinition(Appendage).elementDefinition(ElementID).twistDefinition().setCPy(iCP, 0, twist, false); // To see full list of available functions, use query() in Gomboc Commands window // e.g. query(Host.foilHolder().foilDefinition("Boat.Centre.FrontFoil").elementDefinition(0)); }; return that; };