GMoor Script - Set Critical Damping
18/08/2021
Many people have been asking for sample scripts for common requirements, so we're going to start sharing some samples of our favourites. The one will iteratively adjust Extra Damping until a certain target percent critical damping is achieved.
Either copy-paste the code below as a new "Batch Script" within your GMoor database, or save the linked file - SetCriticalDamping.cs - to %USERPROFILE%\.GM\GMoor10\Batch in order to use with all databases. To run the script once added (via either method), just click the button that appears on the Scripted Batch group as shown above.
Complete Script Code
// attempt to calculate extra damping to provide 30% critical damping var targetDampingPct = 30; // target value (% critical damping) var tolerance = 0.01; // tolerance (stop when within this value of target) // iterate up to 10 times to attempt to converge on target % critical for(int n = 0; n < 10; ++n) { // run with current inputs and get vessel results var results = RunAnalysis(InteractiveSpread, InteractiveConfig, new NoFailure()); var vessel = results.Vessel; // calculate current differences from target % critical var errx = Math.Abs(vessel.CriticalX - targetDampingPct); var erry = Math.Abs(vessel.CriticalY - targetDampingPct); var errn = Math.Abs(vessel.CriticalN - targetDampingPct); // stop iterating if within tolerance if(errx < tolerance && erry < tolerance && errn < tolerance) break; // calculate expected extra damping values var factor = 25.0 / Math.PI; var xdamp = targetDampingPct * vessel.MassX.Tonnes / (factor * vessel.NaturalPeriodX.Seconds) - (vessel.LinearDampingX - vessel.LinearExtraDampingX).KilonewtonsPerMetrePerSecond; var ydamp = targetDampingPct * vessel.MassY.Tonnes / (factor * vessel.NaturalPeriodY.Seconds) - (vessel.LinearDampingY - vessel.LinearExtraDampingY).KilonewtonsPerMetrePerSecond; var ndamp = targetDampingPct * vessel.MassN.TonneMetresSquared / (factor * vessel.NaturalPeriodN.Seconds) - (vessel.LinearDampingN - vessel.LinearExtraDampingN).KilonewtonMetresPerRadianPerSecond; // set new extra damping for next iteration InteractiveConfig.Settings.ExtraDampingSway = LinearDamping.FromKilonewtonsPerMetrePerSecond(xdamp); InteractiveConfig.Settings.ExtraDampingSurge = LinearDamping.FromKilonewtonsPerMetrePerSecond(ydamp); InteractiveConfig.Settings.ExtraDampingYaw = RotationalLinearDamping.FromKilonewtonMetresPerRadianPerSecond(ndamp); }