Exemplo n.º 1
0
        private void EnsureInitialized()
        {
            if (context != null)
            {
                return;
            }
            context = new SimulationContext(SimulationParameters);
            TotalNonLinearIterationCount = 0;

            // build equation system
            equationSystemAdapter = EquationSystemAdapterFactory.GetEquationSystemAdapter();

            for (var i = 0; i < NodeCount; i++)
            {
                equationSystemAdapter.AddVariable();
            }

            foreach (var device in Devices)
            {
                device.RegisterAdditionalVariables(equationSystemAdapter);
            }

            foreach (var device in Devices)
            {
                device.Initialize(equationSystemAdapter, context);
            }

            // get proxies for initial conditions
            initVoltProxies.Clear();
            for (var i = 0; i < initialVoltages.Length; i++)
            {
                if (initialVoltages[i].HasValue)
                {
                    initVoltProxies.Add(equationSystemAdapter.GetMatrixCoefficientProxy(i, i));
                    initVoltProxies.Add(equationSystemAdapter.GetRightHandSideCoefficientProxy(i));
                }
                else
                {
                    initVoltProxies.Add(null);
                    initVoltProxies.Add(null);
                }
            }

            // finalize making changes
            equationSystemAdapter.Freeze();

            // allocate temporary arrays
            currentSolution  = new double[equationSystemAdapter.VariableCount];
            previousSolution = new double[equationSystemAdapter.VariableCount];
        }
Exemplo n.º 2
0
 public void SetQuadDouble()
 {
     EquationSystemAdapterFactory.SetFactory(() => new QdEquationSystemAdapter());
     LoadCircuit();
 }