//simulation run once /// <summary> /// run once simulation.Simulate single cycle of transient. /// </summary> /// <returns>true if simulation completet successfully. Otherwise returns false</returns> bool SIM_RunOnce() { int NodeCount = SystemGrid.NodeCount; int VoltageCount = SystemGrid.VoltageCount; double[,] _Gmat = Mathf.GenerateMatrix <double>(NodeCount, NodeCount, 0); double[,] _Bmat = Mathf.GenerateMatrix <double>(NodeCount, VoltageCount, 0); double[,] _Cmat = Mathf.GenerateMatrix <double>(VoltageCount, NodeCount, 0); double[,] _Dmat = Mathf.GenerateMatrix <double>(VoltageCount, VoltageCount, 0); double[] _Zmat = Mathf.GenerateMatrix <double>(VoltageCount + NodeCount, 0); foreach (Component c in _comps) { c.Modify_G_Matrix(_Gmat); c.Modify_B_Matrix(_Bmat); c.Modify_C_Matrix(_Cmat); c.Modify_D_Matrix(_Dmat); c.Modify_Z_Matrix(_Zmat); } double[,] A = Mathf.ConcatenateMatrix(_Gmat, _Bmat, _Cmat, _Dmat); SystemGrid.solutionMatrix = Mathf.GaussianReduction(A, _Zmat); foreach (Component c in _comps) { //components receive their calculated value c.SetCalculatedInfo(); _SimOutput.Add(c.GetCalculatedInfo()); } return(true); }
void SIM_Transient() { double deltaTime; int NodeCount = SystemGrid.NodeCount; int VoltageCount = SystemGrid.VoltageCount; int loopCount = 0; double[,] _Gmat = Mathf.GenerateMatrix <double>(NodeCount, NodeCount, 0); double[,] _Bmat = Mathf.GenerateMatrix <double>(NodeCount, VoltageCount, 0); double[,] _Cmat = Mathf.GenerateMatrix <double>(VoltageCount, NodeCount, 0); double[,] _Dmat = Mathf.GenerateMatrix <double>(VoltageCount, VoltageCount, 0); double[] _Zmat = Mathf.GenerateMatrix <double>(VoltageCount + NodeCount, 0); for (deltaTime = 0; deltaTime <= SystemGrid.EndTime; deltaTime += SystemGrid.TimeSpace) { //skip the first time cos it's already populated. //makes it a little bit efficient SystemGrid.dTime = deltaTime; loopCount++; if (deltaTime != 0) { Mathf.PopulateArray <double>(_Gmat, 0, NodeCount, NodeCount); Mathf.PopulateArray <double>(_Bmat, 0, NodeCount, VoltageCount); Mathf.PopulateArray <double>(_Cmat, 0, VoltageCount, NodeCount); Mathf.PopulateArray <double>(_Dmat, 0, VoltageCount, VoltageCount); Mathf.PopulateArray <double>(_Zmat, 0); } foreach (Component c in _comps) { c.Modify_G_Matrix(_Gmat); c.Modify_B_Matrix(_Bmat); c.Modify_C_Matrix(_Cmat); c.Modify_D_Matrix(_Dmat); c.Modify_Z_Matrix(_Zmat); } double[,] A = Mathf.ConcatenateMatrix(_Gmat, _Bmat, _Cmat, _Dmat); SystemGrid.solutionMatrix = Mathf.GaussianReduction(A, _Zmat); string output = ""; foreach (Component c in _comps) { c.SetCalculatedInfo(); c.UpdateValues(); output += c.GetCalculatedInfo() + " "; } for (int iter = 0; iter < SystemGrid.solutionMatrix.Length; iter++) { output += SystemGrid.solutionMatrix[iter].ToString() + " "; } Informer.OnSimulationCycleEnd(output); } SystemGrid.DatasetLength = loopCount; }
public void MatrixCombination_SouldCombineMatrix() { double[,] expexted = { { 1, 2, 3, 10, 14 }, { 4, 5, 6, 11, 15 }, { 7, 8, 9, 12, 16 }, { 10, 11, 12, 0, 0 }, { 14, 15, 16, 0, 0 } }; double[,] g = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; double[,] b = { { 10, 14 }, { 11, 15 }, { 12, 16 } }; double[,] c = { { 10, 11, 12 }, { 14, 15, 16 } }; double[,] d = { { 0, 0 }, { 0, 0 } }; double[,] actual = Mathf.ConcatenateMatrix(g, b, c, d); Assert.Equal(expexted, actual); }