Esempio n. 1
0
 public void Initialize()
 {
     if (childAnalyzer == null)
     {
         throw new InvalidOperationException("Static analyzer must contain an embedded analyzer.");
     }
     //InitalizeMatrices();
     childAnalyzer.Initialize();
 }
Esempio n. 2
0
 public void Initialize()
 {
     if (childAnalyzer == null)
     {
         throw new InvalidOperationException("Static analyzer must contain an embedded analyzer.");
     }
     //InitializeCoefficients();
     InitializeInternalVectors();
     //InitializeMatrices();
     InitializeRHSs();
     childAnalyzer.Initialize();
 }
        public void Solve()
        {
            if (childAnalyzer == null)
            {
                throw new InvalidOperationException("Polynomial chaos analyzer must contain an embedded analyzer.");
            }

            //BuildStochasticMatrices();
            InitializeNonZeroPsi();
            if (shouldFactorizeMatrices)
            {
                MakePreconditioners();
            }
            childAnalyzer.Initialize();
            childAnalyzer.Solve();

            int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[1][DOFType.X];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[84][DOFType.Y];
            //int dofNo = 112;
            var subdomain  = subdomains.Select(x => x.Value).First();
            int meanLength = subdomain.Solution.Length / coefficientsProvider.Calculator.PsiSize;

            double[] values       = new double[simulations];
            string[] valuesString = new string[simulations];
            for (int m = 0; m < simulations; m++)
            {
                var psii = EvaluatePSI(randomNumbers[m]);
                for (int i = 0; i < coefficientsProvider.Calculator.PsiSize; i++)
                {
                    values[m] += subdomain.Solution[i * meanLength + dofNo] * psii[i];
                }
                valuesString[m] = values[m].ToString();
            }
            File.WriteAllLines(String.Format(@"polychaos{0}-{1}-{2}.txt", coefficientsProvider.OrderM, coefficientsProvider.OrderP, expansionOrder), valuesString);

            //string[] values = new string[simulations];
            //for (int i = 0; i < simulations; i++)
            //{
            //    currentSimulation = i;
            //    values[i] = subdomains[1].Solution[28].ToString();
            //}

            //File.WriteAllLines(String.Format(@"polychaos{0}.txt", expansionOrder), values);
        }
Esempio n. 4
0
        public void Solve()
        {
            if (childAnalyzer == null)
            {
                throw new InvalidOperationException("Monte Carlo analyzer must contain an embedded analyzer.");
            }

            string[] values = new string[simulations];
            for (int i = 0; i < simulations; i++)
            {
                currentSimulation = i;
                ComposeStochasticMatrixFromMatrices();
                childAnalyzer.Initialize();
                childAnalyzer.Solve();
                values[i] = subdomains[1].Solution[28].ToString();
            }

            File.WriteAllLines(String.Format(@"montecarlo{0}.txt", expansionOrder), values);
        }
        private void SolveNormal()
        {
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[150][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[84][DOFType.Y];
            int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[1][DOFType.X];

            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[450][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[601][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[6051][DOFType.Y];
            //int dofNo = model.Subdomains[36].NodalDOFsDictionary[6051][DOFType.Y];
            string[]     values             = new string[simulations];
            var          fileName           = String.Format(@"{0}-{1}-{2}.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            var          fileNameIterations = String.Format(@"{0}-{1}-{2}-Iters.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            var          fileNameTimes      = String.Format(@"{0}-{1}-{2}-Times.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            StreamWriter sw;

            sw = File.CreateText(fileName);
            sw.Dispose();
            sw = File.CreateText(fileNameIterations);
            sw.Dispose();
            var times = new Dictionary <string, TimeSpan>();

            times.Add("all", TimeSpan.Zero);
            times.Add("element", TimeSpan.Zero);
            times.Add("factorize", TimeSpan.Zero);
            times.Add("solution", TimeSpan.Zero);
            var start           = DateTime.Now;
            var iterationCount  = new int[simulations - simulationStartFrom];
            int totalIterations = 0;

            for (int i = simulationStartFrom; i < simulationStartFrom + simulations; i++)
            {
                currentSimulation = i;
                coefficientsProvider.RandomVariables = randomNumbers[currentSimulation];
                var e = DateTime.Now;
                BuildMatrices();
                times["element"] += DateTime.Now - e;
                if (stiffnessMatrixProductionMode == StiffnessMatrixProductionMode.StoreToDisk)
                {
                    continue;
                }

                e = DateTime.Now;
                childAnalyzer.Initialize();
                times["factorize"]    += DateTime.Now - e;
                GCSettings.LatencyMode = GCLatencyMode.LowLatency;
                e = DateTime.Now;
                childAnalyzer.Solve();

                times["solution"]              += DateTime.Now - e;
                GCSettings.LatencyMode          = GCLatencyMode.Batch;
                values[i - simulationStartFrom] = subdomains[1].Solution[dofNo].ToString();
                //values[i] = subdomains[36].Solution[dofNo].ToString();

                //values[i] = matrixMagnitudes[i].ToString();
                using (sw = File.AppendText(fileName))
                    sw.WriteLine(values[i - simulationStartFrom]);
                using (sw = File.AppendText(fileNameIterations))
                    sw.WriteLine(iterationCount[i - simulationStartFrom].ToString());
                using (sw = File.CreateText(fileNameTimes))
                {
                    sw.WriteLine(String.Format("Elements: {0}", times["element"].ToString()));
                    sw.WriteLine(String.Format("Factorize: {0}", times["factorize"].ToString()));
                    sw.WriteLine(String.Format("Solution: {0}", times["solution"].ToString()));
                    sw.WriteLine(String.Format("All: {0}", times["all"].ToString()));
                    sw.WriteLine(String.Format("Total iterations: {0}", totalIterations.ToString()));
                }
            }
            times["all"] = DateTime.Now - start;

            //File.WriteAllLines(String.Format(@"{0}-{1}.txt", fileNameForLogging, expansionOrder), values);
        }
        private void SolveNormal()
        {
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[150][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[84][DOFType.Y];
            int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[80][DOFType.X];

            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[450][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[601][DOFType.Y];
            //int dofNo = model.Subdomains[0].GlobalNodalDOFsDictionary[6051][DOFType.Y];
            //int dofNo = model.Subdomains[36].NodalDOFsDictionary[6051][DOFType.Y];
            string[]     values             = new string[simulations];
            var          fileName           = String.Format(@"{0}-{1}-{2}.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            var          fileNameIterations = String.Format(@"{0}-{1}-{2}-Iters.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            var          fileNameTimes      = String.Format(@"{0}-{1}-{2}-Times.txt", fileNameForLogging, expansionOrder, simulationStartFrom);
            StreamWriter sw;

            sw = File.CreateText(fileName);
            sw.Dispose();
            sw = File.CreateText(fileNameIterations);
            sw.Dispose();
            var times = new Dictionary <string, TimeSpan>();

            times.Add("all", TimeSpan.Zero);
            times.Add("element", TimeSpan.Zero);
            times.Add("factorize", TimeSpan.Zero);
            times.Add("solution", TimeSpan.Zero);
            var start           = DateTime.Now;
            var iterationCount  = new int[simulations - simulationStartFrom];
            int totalIterations = 0;

            currentSimulation = 0;
            var dofValuesPerPhi = new Dictionary <int, double[][]>(model.Nodes.Count);

            foreach (var d in model.NodalDOFsDictionary)
            {
                dofValuesPerPhi.Add(d.Key, new double[][] { new double[coefficientsProvider.NPhi], new double[coefficientsProvider.NPhi], new double[coefficientsProvider.NPhi] });
            }
            var vrfPerNPtsVRF = new Dictionary <int, double[][]>(model.Nodes.Count);

            foreach (var d in model.NodalDOFsDictionary)
            {
                vrfPerNPtsVRF.Add(d.Key, new double[][] { new double[coefficientsProvider.NPtsVRF], new double[coefficientsProvider.NPtsVRF], new double[coefficientsProvider.NPtsVRF] });
            }

            for (int i = 0; i < coefficientsProvider.NPtsVRF; i++)
            {
                coefficientsProvider.CurrentFrequency = i;
                for (int j = 0; j < coefficientsProvider.NPhi; j++)
                {
                    coefficientsProvider.RandomVariables = randomNumbers[currentSimulation];
                    coefficientsProvider.CurrentMCS      = j;
                    var e = DateTime.Now;
                    BuildMatrices();
                    times["element"] += DateTime.Now - e;
                    //if (stiffnessMatrixProductionMode == StiffnessMatrixProductionMode.StoreToDisk) continue;

                    e = DateTime.Now;
                    childAnalyzer.Initialize();
                    times["factorize"]    += DateTime.Now - e;
                    GCSettings.LatencyMode = GCLatencyMode.LowLatency;
                    e = DateTime.Now;
                    childAnalyzer.Solve();

                    times["solution"]              += DateTime.Now - e;
                    GCSettings.LatencyMode          = GCLatencyMode.Batch;
                    values[i - simulationStartFrom] = subdomains[1].Solution[dofNo].ToString();
                    //values[i] = subdomains[36].Solution[dofNo].ToString();

                    //values[i] = matrixMagnitudes[i].ToString();
                    using (sw = File.AppendText(fileName))
                        //sw.WriteLine(values[i - simulationStartFrom]);
                        sw.WriteLine(GetCSVText(subdomains[1].Solution));
                    using (sw = File.AppendText(fileNameIterations))
                        sw.WriteLine(iterationCount[i - simulationStartFrom].ToString());
                    using (sw = File.CreateText(fileNameTimes))
                    {
                        sw.WriteLine(String.Format("Elements: {0}", times["element"].ToString()));
                        sw.WriteLine(String.Format("Factorize: {0}", times["factorize"].ToString()));
                        sw.WriteLine(String.Format("Solution: {0}", times["solution"].ToString()));
                        sw.WriteLine(String.Format("All: {0}", times["all"].ToString()));
                        sw.WriteLine(String.Format("Total iterations: {0}", totalIterations.ToString()));
                    }

                    foreach (var d in model.NodalDOFsDictionary)
                    {
                        if (d.Value.ContainsKey(DOFType.X) && d.Value[DOFType.X] > -1)
                        {
                            dofValuesPerPhi[d.Key][0][j] = subdomains[1].Solution[d.Value[DOFType.X]];
                        }
                        if (d.Value.ContainsKey(DOFType.Y) && d.Value[DOFType.Y] > -1)
                        {
                            dofValuesPerPhi[d.Key][1][j] = subdomains[1].Solution[d.Value[DOFType.Y]];
                        }
                        if (d.Value.ContainsKey(DOFType.Z) && d.Value[DOFType.Z] > -1)
                        {
                            dofValuesPerPhi[d.Key][2][j] = subdomains[1].Solution[d.Value[DOFType.Z]];
                        }
                    }

                    currentSimulation++;
                }
                foreach (var d in model.NodalDOFsDictionary)
                {
                    if (d.Value.ContainsKey(DOFType.X) && d.Value[DOFType.X] > -1)
                    {
                        vrfPerNPtsVRF[d.Key][0][i] = StandardDeviation(dofValuesPerPhi[d.Key][0]) / coefficientsProvider.SpectrumStandardDeviation;
                    }
                    if (d.Value.ContainsKey(DOFType.Y) && d.Value[DOFType.Y] > -1)
                    {
                        vrfPerNPtsVRF[d.Key][1][i] = StandardDeviation(dofValuesPerPhi[d.Key][1]) / coefficientsProvider.SpectrumStandardDeviation;
                    }
                    if (d.Value.ContainsKey(DOFType.Z) && d.Value[DOFType.Z] > -1)
                    {
                        vrfPerNPtsVRF[d.Key][2][i] = StandardDeviation(dofValuesPerPhi[d.Key][2]) / coefficientsProvider.SpectrumStandardDeviation;
                    }
                }
            }
            times["all"] = DateTime.Now - start;

            vrfs = CalculateVRF(vrfPerNPtsVRF);
            //File.WriteAllLines(String.Format(@"{0}-{1}.txt", fileNameForLogging, expansionOrder), values);
        }