public static double[] CalculateFppReactionsVector(Subdomain subdomain, IElementMatrixProvider elementProvider,
                                                           IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes, IVectorView solution, IVectorView dSolution,
                                                           Dictionary <int, Dictionary <IDofType, double> > initialConvergedBoundaryDisplacements, Dictionary <int, Dictionary <IDofType, double> > totalBoundaryDisplacements,
                                                           int nIncrement, int totalIncrements)
        {
            //TODOGerasimos: 1) Subdomain2 einai h upo kataskevh subdomain.cs ths Marias gia na mporoume na anaferthoume sthn methodo ths CalculateElementNodalDisplacements(..,..).
            // Otan parei telikh morfh tha taftizetai me thn Subdomain.cs
            // 2)IVector solution, IVector dSolution EINAI AFTA ME TA OPOIA kaloume thn GetRHSFromSolution sthn 213 tou NRNLAnalyzer
            double[] FppReactionVector;
            Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes);

            FppReactionVector = new double[boundaryNodesOrder.Count * scaleTransitions.PrescribedDofsPerNode()]; // h allliws subdomain.Forces.GetLength(0)


            var times      = new Dictionary <string, TimeSpan>();
            var totalStart = DateTime.Now;

            times.Add("rowIndexCalculation", DateTime.Now - totalStart);
            times.Add("element", TimeSpan.Zero);
            times.Add("addition", TimeSpan.Zero);
            foreach (Element element in subdomain.Elements)
            {
                var isEmbeddedElement = element.ElementType is IEmbeddedElement;
                var elStart           = DateTime.Now;
                //IMatrix2D ElementK = elementProvider.Matrix(element);
                var localSolution = subdomain.GetLocalVectorFromGlobalWithoutPrescribedDisplacements(element, solution);
                subdomain.ImposePrescribedDisplacementsWithInitialConditionSEffect(element, localSolution, boundaryNodes, initialConvergedBoundaryDisplacements, totalBoundaryDisplacements, nIncrement, totalIncrements);
                double[] localdSolution = subdomain.GetLocalVectorFromGlobalWithoutPrescribedDisplacements(element, dSolution);
                double[] f = element.ElementType.CalculateForces(element, localSolution, localdSolution);

                times["element"] += DateTime.Now - elStart;

                elStart = DateTime.Now;
                var elementDOFTypes     = element.ElementType.DofEnumerator.GetDofTypesForMatrixAssembly(element);
                var matrixAssemblyNodes = element.ElementType.DofEnumerator.GetNodesForMatrixAssembly(element);
                int iElementMatrixRow   = 0;
                for (int i = 0; i < elementDOFTypes.Count; i++)
                {
                    INode nodeRow = matrixAssemblyNodes[i];
                    if (boundaryNodes.ContainsKey(nodeRow.ID))
                    {
                        for (int i1 = 0; i1 < scaleTransitions.PrescribedDofsPerNode(); i1++)
                        {
                            int dofrow_p = scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[nodeRow.ID] - 1) + i1;
                            FppReactionVector[dofrow_p] += f[iElementMatrixRow + i1];
                        }
                    }
                    iElementMatrixRow += elementDOFTypes[i].Count;
                }
                times["addition"] += DateTime.Now - elStart;
            }
            var totalTime = DateTime.Now - totalStart;

            return(FppReactionVector);
        }
        public static double[] CalculateDqFpp(double[] FppReactionVector, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes)
        {
            double[] DqFpp = new double[scaleTransitions.MacroscaleVariableDimension()];

            Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes);

            foreach (Node boundaryNode in boundaryNodes.Values)
            {
                double[] FppDataTriplette = new double[scaleTransitions.PrescribedDofsPerNode()];
                for (int i2 = 0; i2 < scaleTransitions.PrescribedDofsPerNode(); i2++)
                {
                    FppDataTriplette[i2] = FppReactionVector[scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[boundaryNode.ID] - 1) + i2];
                }
                double[] contribution = scaleTransitions.MicroToMacroTransition(boundaryNode, FppDataTriplette);
                for (int i3 = 0; i3 < scaleTransitions.MacroscaleVariableDimension(); i3++)
                {
                    DqFpp[i3] += contribution[i3];
                }
            }

            return(DqFpp);
        }
        public static double[,] CalculateDqCondDq(double[][] f4_vectors, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes)
        {
            double[,] DqCondDq = new double[scaleTransitions.MacroscaleVariableDimension(), scaleTransitions.MacroscaleVariableDimension()];

            Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes);

            foreach (Node boundaryNode in boundaryNodes.Values)
            {
                for (int i1 = 0; i1 < f4_vectors.GetLength(0); i1++)
                {
                    double[] f4DataTriplette = new double[scaleTransitions.PrescribedDofsPerNode()];
                    for (int i2 = 0; i2 < scaleTransitions.PrescribedDofsPerNode(); i2++)
                    {
                        f4DataTriplette[i2] = f4_vectors[i1][scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[boundaryNode.ID] - 1) + i2];
                    }
                    double[] contribution = scaleTransitions.MicroToMacroTransition(boundaryNode, f4DataTriplette);
                    for (int i3 = 0; i3 < scaleTransitions.MacroscaleVariableDimension(); i3++)
                    {
                        DqCondDq[i3, i1] += contribution[i3];
                    }
                }
            }
            return(DqCondDq);
        }
        public static double[][] CalculateKpfKffinverseKfpDq(double[][] f2_vectors, Subdomain subdomain, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions, Dictionary <int, INode> boundaryNodes)
        {
            var dofOrdering = subdomain.FreeDofOrdering;          //.1
            var FreeDofs    = subdomain.FreeDofOrdering.FreeDofs; //.1Dictionary<int, Dictionary<DOFType, int>> nodalDOFsDictionary = subdomain.NodalDOFsDictionary;

            double[][] f3_vectors = new double[f2_vectors.GetLength(0)][];
            for (int i1 = 0; i1 < f2_vectors.GetLength(0); i1++)
            {
                f3_vectors[i1] = new double[scaleTransitions.PrescribedDofsPerNode() * boundaryNodes.Count];
            }
            Dictionary <int, int> boundaryNodesOrder = GetNodesOrderInDictionary(boundaryNodes);


            var times      = new Dictionary <string, TimeSpan>();
            var totalStart = DateTime.Now;

            times.Add("rowIndexCalculation", DateTime.Now - totalStart);
            times.Add("element", TimeSpan.Zero);
            times.Add("addition", TimeSpan.Zero);
            foreach (Element element in subdomain.Elements) //.3 ElementsDictionary.Values)
            {
                var     isEmbeddedElement = element.ElementType is IEmbeddedElement;
                var     elStart           = DateTime.Now;
                IMatrix ElementK          = elementProvider.Matrix(element);
                times["element"] += DateTime.Now - elStart;

                elStart = DateTime.Now;
                var elementDOFTypes     = element.ElementType.DofEnumerator.GetDofTypesForMatrixAssembly(element);
                var matrixAssemblyNodes = element.ElementType.DofEnumerator.GetNodesForMatrixAssembly(element);
                int iElementMatrixRow   = 0;
                for (int i = 0; i < elementDOFTypes.Count; i++)
                {
                    INode nodeRow = matrixAssemblyNodes[i];
                    if (boundaryNodes.ContainsKey(nodeRow.ID))
                    {
                        for (int i1 = 0; i1 < scaleTransitions.PrescribedDofsPerNode(); i1++)
                        {
                            int dofrow_p             = scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[nodeRow.ID] - 1) + i1;
                            int iElementMatrixColumn = 0;
                            for (int j = 0; j < elementDOFTypes.Count; j++)
                            {
                                INode nodeColumn            = matrixAssemblyNodes[j];
                                int   dofTypeColumnToNumber = -1;
                                foreach (IDofType dofTypeColumn in elementDOFTypes[j])
                                {
                                    dofTypeColumnToNumber++;
                                    bool isFree = FreeDofs.TryGetValue(matrixAssemblyNodes[j], elementDOFTypes[j][dofTypeColumnToNumber],
                                                                       out int dofColumn); // v2.4 int dofColumn = nodalDOFsDictionary.ContainsKey(nodeColumn.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeColumn.ID][dofTypeColumn];
                                    if (isFree)                                            // TODOGerasimos edw pithanws thelei kai elegxo alliws an den ta exoume afhsei constrained ta p kai einai elefthera px me to an anhkoun sto baoundary nodes
                                    {                                                      // alla etsi einai oti akrivws thewritai kai sto assembly tou Kff opote ok
                                        for (int i2 = 0; i2 < f2_vectors.GetLength(0); i2++)
                                        {
                                            f3_vectors[i2][dofrow_p] += ElementK[iElementMatrixRow + i1, iElementMatrixColumn] * f2_vectors[i2][dofColumn];
                                        }
                                    }
                                    iElementMatrixColumn++;
                                }
                            }
                        }
                    }
                    iElementMatrixRow += elementDOFTypes[i].Count;
                }
                times["addition"] += DateTime.Now - elStart;
            }
            var totalTime = DateTime.Now - totalStart;

            return(f3_vectors);
        }
Beispiel #5
0
        public void UpdateVectors(IElement element, IMatrix ElementK)
        {
            ISubdomain subdomain = element.Subdomain;

            if (boundaryElements[subdomain.ID].ContainsKey(element.ID))//COPIED From UpdateSubdomainKffAndCalculateKfpDqAndKppDqp (prosoxh boundary elements Dictionary diathetoun kai to model kai to subdomain kai einai diaforetika edw exei diorthwthei
            {
                //ADDED these lines from another part of UpdateSubdomainKffAndCalculateKfpDqAndKppDqp
                var isEmbeddedElement   = element.ElementType is ISAAR.MSolve.FEM.Interfaces.IEmbeddedElement;
                var elementDOFTypes     = element.ElementType.DofEnumerator.GetDofTypesForMatrixAssembly(element);
                var matrixAssemblyNodes = element.ElementType.DofEnumerator.GetNodesForMatrixAssembly(element);


                #region KfpDq Multiplication
                int iElementMatrixRow = 0;
                for (int i = 0; i < elementDOFTypes.Count; i++)
                {
                    INode nodeRow            = matrixAssemblyNodes[i];
                    int   dofTypeRowToNumber = -1; //v2.6
                    foreach (IDofType dofTypeRow in elementDOFTypes[i])
                    {
                        dofTypeRowToNumber++;
                        bool isFree = subdomain.FreeDofOrdering.FreeDofs.TryGetValue(matrixAssemblyNodes[i], elementDOFTypes[i][dofTypeRowToNumber],
                                                                                     out int dofRow); //v2.6
                        //int dofRow = nodalDOFsDictionary.ContainsKey(nodeRow.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeRow.ID][dofTypeRow];
                        if (isFree)                                                                   // TODOGerasimos edw pithanws thelei kai elegxo alliws an den ta exoume afhsei constrained ta p kai einai elefthera px me to an anhkoun sto baoundary nodes
                        {                                                                             // alla etsi einai oti akrivws thewritai kai sto assembly tou Kff opote ok
                            int iElementMatrixColumn = 0;
                            for (int j = 0; j < elementDOFTypes.Count; j++)
                            {
                                INode nodeColumn = matrixAssemblyNodes[j];
                                //foreach (DOFType dofTypeColumn in elementDOFTypes[j])
                                //{
                                //    int dofColumn = nodalDOFsDictionary.ContainsKey(nodeColumn.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeColumn.ID][dofTypeColumn];
                                //    if (dofColumn != -1)
                                //    {
                                //        int height = dofRow - dofColumn;
                                //        if (height >= 0)
                                //            K.Data[K.RowIndex[dofRow] + height] += ElementK[iElementMatrixRow, iElementMatrixColumn];
                                //    }
                                //    iElementMatrixColumn++;
                                //}
                                int nodalDofsNumber = elementDOFTypes[j].Count; //TODOGerasimos elegxos oti edw oi ginetai prosvash apo 0:1:megethos
                                if (boundaryNodes.ContainsKey(nodeColumn.ID))
                                {
                                    double[] element_Kfp_triplette = new double[nodalDofsNumber]; //nodalDofsNumber: giati oxi scaleTransitions.PrescribedDofsPerNode()? Dioti tou ta pairname ola(triplette) kai dialegei to
                                    for (int j1 = 0; j1 < nodalDofsNumber; j1++)                  //scaleTransitions.MicroToMacroTransition ti tha xrhsimopoihsei apo afta analoga pws einai implemented
                                    {
                                        element_Kfp_triplette[j1] = ElementK[iElementMatrixRow, iElementMatrixColumn + j1];
                                    }

                                    double[] contribution = scaleTransitions.MicroToMacroTransition(nodeColumn, element_Kfp_triplette);
                                    for (int j2 = 0; j2 < contribution.GetLength(0); j2++)
                                    {
                                        KfpDqVectors[subdomain.ID][j2][dofRow] += contribution[j2]; // TODO diorthothike
                                    }
                                }
                                iElementMatrixColumn += nodalDofsNumber;
                            }
                        }
                        iElementMatrixRow++;
                    }
                }
                #endregion

                #region KppDq Multiplications
                iElementMatrixRow = 0;
                for (int i = 0; i < elementDOFTypes.Count; i++)
                {
                    INode nodeRow = matrixAssemblyNodes[i];
                    if (boundaryNodes.ContainsKey(nodeRow.ID))
                    {
                        for (int i1 = 0; i1 < scaleTransitions.PrescribedDofsPerNode(); i1++)
                        {
                            int dofrow_p             = scaleTransitions.PrescribedDofsPerNode() * (boundaryNodesOrder[nodeRow.ID] - 1) + i1;
                            int iElementMatrixColumn = 0;
                            for (int j = 0; j < elementDOFTypes.Count; j++)
                            {
                                INode nodeColumn = matrixAssemblyNodes[j];
                                //
                                //foreach (DOFType dofTypeColumn in elementDOFTypes[j])
                                //{
                                //    int dofColumn = nodalDOFsDictionary.ContainsKey(nodeColumn.ID) == false && isEmbeddedElement ? -1 : nodalDOFsDictionary[nodeColumn.ID][dofTypeColumn];
                                //    if (dofColumn != -1)// TODOGerasimos edw pithanws thelei kai elegxo alliws an den ta exoume afhsei constrained ta p kai einai elefthera px me to an anhkoun sto baoundary nodes
                                //    {                   // alla etsi einai oti akrivws thewritai kai sto assembly tou Kff opote ok

                                //        for (int i2 = 0; i2 < f2_vectors.GetLength(0); i2++)
                                //        {
                                //            f3_vectors[i2][dofrow_p] += ElementK[iElementMatrixRow + i1, iElementMatrixColumn] * f2_vectors[i2][dofColumn]; /////
                                //        }

                                //    }
                                //    iElementMatrixColumn++;
                                //}
                                //
                                int nodalDofsNumber = elementDOFTypes[j].Count;
                                if (boundaryNodes.ContainsKey(nodeColumn.ID))
                                {
                                    double[] element_Kpp_triplette = new double[scaleTransitions.PrescribedDofsPerNode()];
                                    for (int j2 = 0; j2 < scaleTransitions.PrescribedDofsPerNode(); j2++)
                                    {
                                        element_Kpp_triplette[j2] = ElementK[iElementMatrixRow + i1, iElementMatrixColumn + j2]; // mallon iElementMatrixRow + i1
                                    }
                                    double[] contribution = scaleTransitions.MicroToMacroTransition(nodeColumn, element_Kpp_triplette);
                                    for (int j1 = 0; j1 < contribution.GetLength(0); j1++)
                                    {
                                        KppDqVectors[subdomain.ID][j1][dofrow_p] += contribution[j1];
                                    }
                                }
                                iElementMatrixColumn += nodalDofsNumber;
                            }
                        }
                    }
                    iElementMatrixRow += elementDOFTypes[i].Count;
                }
                #endregion
            }
        }
Beispiel #6
0
        //int currentSubdomainID;

        public (Dictionary <int, double[][]>, Dictionary <int, double[][]>) UpdateSubdomainKffAndCalculateKfpDqAndKppDqpMultipleObje(Model model, IElementMatrixProvider elementProvider, IScaleTransitions scaleTransitions,
                                                                                                                                     Dictionary <int, Node> boundaryNodes, Dictionary <int, Dictionary <int, Element> > boundaryElements, ISolver solver)
        {
            IReadOnlyDictionary <int, ILinearSystem> linearSystems = solver.LinearSystems; //v2.3

            Dictionary <int, double[][]> KfpDqSubdomains        = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count);
            Dictionary <int, double[][]> KppDqVectorsSubdomains = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count);

            this.boundaryElements = boundaryElements;
            this.boundaryNodes    = boundaryNodes;
            this.scaleTransitions = scaleTransitions;

            KfpDqVectors = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count);
            KppDqVectors = new Dictionary <int, double[][]>(model.SubdomainsDictionary.Count);
            foreach (Subdomain subdomain in model.Subdomains)
            {
                #region Create KfpDq and KppDq vectors
                KfpDqVectors[subdomain.ID] = new double[scaleTransitions.MacroscaleVariableDimension()][];
                for (int j1 = 0; j1 < scaleTransitions.MacroscaleVariableDimension(); j1++)
                {
                    KfpDqVectors[subdomain.ID][j1] = new double[subdomain.FreeDofOrdering.NumFreeDofs]; //v2.2 subdomain.TotalDOFs];
                }

                KppDqVectors[subdomain.ID] = new double[scaleTransitions.MacroscaleVariableDimension()][];
                boundaryNodesOrder         = SubdomainCalculations.GetNodesOrderInDictionary(boundaryNodes);
                for (int j1 = 0; j1 < scaleTransitions.MacroscaleVariableDimension(); j1++)
                {
                    KppDqVectors[subdomain.ID][j1] = new double[boundaryNodesOrder.Count * scaleTransitions.PrescribedDofsPerNode()]; // h allliws subdomain.Forces.GetLength(0)
                }
                #endregion
            }

            var StiffnessProvider = new StiffnessProviderSimu(this);
            Dictionary <int, IMatrix> subdomainKs = solver.BuildGlobalMatrices(StiffnessProvider);

            foreach (Subdomain subdomain in model.Subdomains)
            {
                //dofOrdering = subdomain.FreeDofOrdering; //.1
                //FreeDofs = subdomain.FreeDofOrdering.FreeDofs;//.1 nodalDOFsDictionary = subdomain.NodalDOFsDictionary;
                //currentSubdomainID = subdomain.ID;



                //v2.4 var subdomainK= GlobalMatrixAssemblerSkyline.CalculateFreeFreeGlobalMatrix(subdomain, StiffnessProvider);

                linearSystems[subdomain.ID].Matrix = subdomainKs[subdomain.ID];
                //v2.5 linearSystems[subdomain.ID].Matrix = subdomainK;

                KfpDqSubdomains.Add(subdomain.ID, KfpDqVectors[subdomain.ID]);
                KppDqVectorsSubdomains.Add(subdomain.ID, KppDqVectors[subdomain.ID]);
            }

            return(KfpDqSubdomains, KppDqVectorsSubdomains);
        }