// Create a direct coupled model with all necessary mass elastic and excitation data
// Number of branches: 	1
// Number of masses:	12
// Components: Engine and propeller
// Engine type: Two-stroke inline, type S80MC, using theoretical cylinder pressure approach

// Create inertias
dataModel.Add(M1 = new Inertia() { X=50; Y=100 });
dataModel.Add(M2 = new Cylinder() { X=51; Y=100 } );
dataModel.Add(M3 = new Cylinder() { X=52; Y=100 } );
dataModel.Add(M4 = new Cylinder() { X=53; Y=100 } );
dataModel.Add(M5 = new Cylinder() { X=54; Y=100 } );
dataModel.Add(M6 = new Cylinder() { X=55; Y=100 } );
dataModel.Add(M7 = new Cylinder() { X=56; Y=100 } );
dataModel.Add(M8 = new Cylinder() { X=57; Y=100 } );
dataModel.Add(M9 = new Inertia() { X=58; Y=100 } );
dataModel.Add(M10 = new Inertia() { X=59; Y=100 } );
dataModel.Add(M11 = new Inertia() { X=60; Y=100 } );
dataModel.Add(M12 = new Propeller() { X=61; Y=100 } );

// Align inertias
AlignInertias(AlignDirection.Horizontal, [1,2,3,4,5,6,7,8,9,10,11,12]);

// Add stiffness
dataModel.Add(S1 = new Stiffness(M1, M2));
dataModel.Add(S2 = new Crankthrow(M2, M3));
dataModel.Add(S3 = new Crankthrow(M3, M4));
dataModel.Add(S4 = new Crankthrow(M4, M5));
dataModel.Add(S5 = new Crankthrow(M5, M6));
dataModel.Add(S6 = new Crankthrow(M6, M7));
dataModel.Add(S7 = new Crankthrow(M7, M8));
dataModel.Add(S8 = new Stiffness(M8, M9));
dataModel.Add(S9 = new Stiffness(M9, M10));
dataModel.Add(S10 = new Stiffness(M10, M11));
dataModel.Add(S11 = new Stiffness(M11, M12));

// Group into diesel engine
DieselEngine1 = new DieselEngine();
DieselEngine1.Add(M1);
DieselEngine1.Add(M2);
DieselEngine1.Add(M3);
DieselEngine1.Add(M4);
DieselEngine1.Add(M5);
DieselEngine1.Add(M6);
DieselEngine1.Add(M7);
DieselEngine1.Add(M8);
DieselEngine1.Add(M9);
dataModel.Add(DieselEngine1);

// Mass properties
M1.MomentOfInertia=1901 kg*m^2;
M2.MomentOfInertia=38420 kg*m^2;
M3.MomentOfInertia=38420 kg*m^2;
M4.MomentOfInertia=38420 kg*m^2;
M5.MomentOfInertia=38420 kg*m^2;
M6.MomentOfInertia=38420 kg*m^2;
M7.MomentOfInertia=38420 kg*m^2;
M8.MomentOfInertia=38420 kg*m^2;
M9.MomentOfInertia=16040 kg*m^2;
M10.MomentOfInertia=21100 kg*m^2;
M11.MomentOfInertia=2048 kg*m^2;

// Stiffness properties
S1.TorsionalStiffness=3.086E+009 N*m/rad;
S2.TorsionalStiffness=2.463E+009 N*m/rad;
S3.TorsionalStiffness=2.564E+009 N*m/rad;
S4.TorsionalStiffness=2.358E+009 N*m/rad;
S5.TorsionalStiffness=2.364E+009 N*m/rad;
S6.TorsionalStiffness=2.564E+009 N*m/rad;
S7.TorsionalStiffness=2.655E+009 N*m/rad;
S8.TorsionalStiffness=3.390E+009 N*m/rad;
S9.TorsionalStiffness=3.704E+009 N*m/rad;
S10.TorsionalStiffness=1.313E+008 N*m/rad;
S11.TorsionalStiffness=3.169E+008 N*m/rad;

// Outer diameter on shafts
S1.DiamOuter = 0.896 m;
S2.DiamOuter = 0.896 m;
S3.DiamOuter = 0.896 m;
S4.DiamOuter = 0.896 m;
S5.DiamOuter = 0.896 m;
S6.DiamOuter = 0.896 m;
S7.DiamOuter = 0.896 m;
S8.DiamOuter = 0.808 m;
S9.DiamOuter = 0.808 m;
S10.DiamOuter = 0.630 m;
S11.DiamOuter = 0.765 m;

// Inner diameter on shafts
S1.DiamInner = 0.448 m;
S2.DiamInner = 0.448 m;
S3.DiamInner = 0.448 m;
S4.DiamInner = 0.448 m;
S5.DiamInner = 0.448 m;
S6.DiamInner = 0.448 m;
S7.DiamInner = 0.448 m;
S8.DiamInner = 0.150 m;

// Mass damping
for (i=2;i<=8;i++) { dataModel.GetInertia(i).DynamicMagnifier = 70; }

// Shaft damping
for (i=1;i<=11;i++) { dataModel.GetStiffness(i).DynamicMagnifier = 180; }
for (s=2;s<=9;s++) { dataModel.GetStiffness(s).DynamicMagnifier = 50; }

// Propeller properties
M12.PowerMCR = 25480 kW;
M12.BladeNumber = 4;
M12.DampingModel = "Schwaneke";
M12.EntrainedWaterModel = "Schwaneke";
M12.InertiaInAir = 318340 kg*m^2;
M12.DiameterBoss = 1.57 m;
M12.DiameterPropeller = 9.8 m;
M12.ExpandedAreaRatio = 0.47;
M12.PitchRatio = 0.66;
M12.FirstOrderTorqueAmplitude = 0.07;
M12.SecondOrderTorqueAmplitude = 0.02;

// Diesel engine properties
DieselEngine1.Manufacturer = "HSD MAN";
DieselEngine1.TypeDesignation = "7S80MC";
DieselEngine1.PowerMCR = 25480 kW;
DieselEngine1.SpeedMCR = 79 rpm;
DieselEngine1.NumberOfStrokes = "2";
DieselEngine1.Bore = 0.8 m;
DieselEngine1.StrokeLength = 3.056 m;
DieselEngine1.ConnectingRodRatio = 0.436;
DieselEngine1.ReciprocatingMass = 12243 kg;
DieselEngine1.EfficiencyMechanical = 0.95;

// Cylinder index and firing order
M2.CylinderIndex = 1;
M3.CylinderIndex = 2;
M4.CylinderIndex = 3;
M5.CylinderIndex = 4;
M6.CylinderIndex = 5;
M7.CylinderIndex = 6;
M8.CylinderIndex = 7;
M2.FiringAngleBankA = 0 deg;
M3.FiringAngleBankA = 102.86 deg;
M4.FiringAngleBankA = 257.14 deg;
M5.FiringAngleBankA = 205.71 deg;
M6.FiringAngleBankA = 154.29 deg;
M7.FiringAngleBankA = 308.57 deg;
M8.FiringAngleBankA = 51.43 deg;

// Engine excitation data (theoretical cylinder pressure)
DieselEngine1.ExcitationMethod = ExcitationMethodType.Harmonics;
DieselEngine1.ExcitationData.NormalFiringDataPath = "O:\Machinery\Tools\Nauticus Torsional Vibration\Harmonic components\MAN BW Copenhagen\Excitation\T240856.wri";
DieselEngine1.ExcitationData.MisfiringDataPath = "O:\Machinery\Tools\Nauticus Torsional Vibration\Harmonic components\MAN BW Copenhagen\Excitation\Tm40856.wri";

// Operating conditions and load cases
dataModel.AddOperatingMode(OPM1 = new OperatingMode() { Name="MCR operation" });
dataModel.AddLoadCase(OPM1,LC1 = new LoadCase() { Name="Normal firing"; MaxSpeed=100; MinSpeed=20; StepSpeed=1; Type="Propeller law - full pitch"});
