Ejemplo n.º 1
0
 private static void SaveCurrentLayer(double[] currentLayer, EquationSolveAnswer answer)
 {
     for (int i = 0; i < currentLayer.Length; i++)
     {
         answer.LastLayer[i] = currentLayer[i];
     }
 }
Ejemplo n.º 2
0
 private void FillNodes(int spaceIntervals, int spaceNodesCount, EquationSolveAnswer answer)
 {
     for (var i = 0; i < spaceNodesCount; i++)
     {
         answer.Nodes[i] = LeftBoundary + (RightBoundary * i) / spaceIntervals;
     }
 }
Ejemplo n.º 3
0
        public EquationSolveAnswer Solve(double timeOfEnd, int spaceIntervals, int timeIntervals)
        {
            var spaceNodesCount = spaceIntervals + 1;
            var timeNodesCount  = timeIntervals + 1;

            var answer = new EquationSolveAnswer
            {
                LastLayer = new double[spaceNodesCount],
                Nodes     = new double[spaceNodesCount],
                TimeOfEnd = timeOfEnd
            };

            FillNodes(spaceIntervals, spaceNodesCount, answer);

            var previousLayer = new double[spaceNodesCount];
            var currentLayer  = new double[spaceNodesCount];

            InitializeFirstLayer(currentLayer, spaceNodesCount, answer);

            var timeStep  = (timeOfEnd / timeIntervals);
            var spaceStep = (RightBoundary - LeftBoundary) / spaceIntervals;

            for (int i = 1; i < timeNodesCount; i++)
            {
                var currentTime = i * timeStep;
                SwapLayers(ref currentLayer, ref previousLayer);
                SolveNextLayer(previousLayer, currentLayer, currentTime, answer.Nodes, timeStep, spaceStep);
            }

            SaveCurrentLayer(currentLayer, answer);

            return(answer);
        }
Ejemplo n.º 4
0
 private void InitializeFirstLayer(double[] previousLayer, int spaceNodesCount, EquationSolveAnswer answer)
 {
     for (var i = 0; i < spaceNodesCount; i++)
     {
         previousLayer[i] = StartCondition(answer.Nodes[i]);
     }
 }