コード例 #1
0
ファイル: CGNS2BoSSSGrid.cs プロジェクト: xyuan/BoSSS
        static int[] GetBoSSSConnectivityNodes(ElementType_t t, int[] cgNodes)
        {
            if (t == ElementType_t.NODE)
            {
                return(cgNodes.CloneAs());
            }
            if (t == ElementType_t.BAR_2 || t == ElementType_t.BAR_3)
            {
                return(new int[] { cgNodes[0], cgNodes[1] });
            }
            if (t == ElementType_t.TRI_3 || t == ElementType_t.TRI_6)
            {
                //return new int[] { cgNodes[0], cgNodes[1], cgNodes[2] };
                return(new int[] { cgNodes[2], cgNodes[1], cgNodes[0] });
            }
            if (t == ElementType_t.QUAD_4 || t == ElementType_t.QUAD_8 || t == ElementType_t.QUAD_9)
            {
                return(new int[] { cgNodes[3], cgNodes[0], cgNodes[2], cgNodes[1] });
            }
            if (t == ElementType_t.TETRA_4 || t == ElementType_t.TETRA_10)
            {
                return(new int[] { cgNodes[3], cgNodes[1], cgNodes[0], cgNodes[2] });
            }
            if (t == ElementType_t.HEXA_8 || t == ElementType_t.HEXA_20 || t == ElementType_t.HEXA_27)
            {
                return(new int[] { cgNodes[3], cgNodes[0], cgNodes[7], cgNodes[2], cgNodes[4], cgNodes[5], cgNodes[1], cgNodes[6] });
            }

            throw new NotSupportedException();
        }
コード例 #2
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private int NumberOfFaceEdges(ElementType_t type)
 {
     if (Is3D(type))
     {
         if (type.Equals(ElementType_t.HEXA_8))
         {
             return(4);
         }
         return(3);
     }
     else
     {
         if (number_of_coord_dimensions == 3)
         {
             if (type.Equals(ElementType_t.TRI_3))
             {
                 return(3);
             }
             if (type.Equals(ElementType_t.QUAD_4))
             {
                 return(4);
             }
         }
         return(2);
     }
 }
コード例 #3
0
ファイル: CGNS2BoSSSGrid.cs プロジェクト: xyuan/BoSSS
        static CellType ToBoSSSCellType(this ElementType_t t)
        {
            switch (t)
            {
            case ElementType_t.ElementTypeNull: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.ElementTypeUserDefined: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.NODE: return(CellType.Point);

            case ElementType_t.BAR_2: return(CellType.Line_2);

            case ElementType_t.BAR_3: return(CellType.Line_3);

            case ElementType_t.TRI_3: return(CellType.Triangle_3);

            case ElementType_t.TRI_6: return(CellType.Triangle_6);

            case ElementType_t.QUAD_4: return(CellType.Square_4);

            case ElementType_t.QUAD_8: return(CellType.Square_8);

            case ElementType_t.QUAD_9: return(CellType.Square_9);

            case ElementType_t.TETRA_4: return(CellType.Tetra_Linear);

            case ElementType_t.TETRA_10: return(CellType.Tetra_10);

            case ElementType_t.PYRA_5: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PYRA_14: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_6: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_15: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_18: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.HEXA_8: return(CellType.Cube_8);

            case ElementType_t.HEXA_20: return(CellType.Cube_20);

            case ElementType_t.HEXA_27: return(CellType.Cube_27);

            case ElementType_t.MIXED: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.NGON_n: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            default: throw new NotImplementedException();
            }
        }
コード例 #4
0
ファイル: CGNS2BoSSSGrid.cs プロジェクト: xyuan/BoSSS
        static RefElement GetBoSSSElement(this ElementType_t t)
        {
            switch (t)
            {
            case ElementType_t.ElementTypeNull: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.ElementTypeUserDefined: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.NODE: return(Point.Instance);

            case ElementType_t.BAR_2: return(Line.Instance);

            case ElementType_t.BAR_3: return(Line.Instance);

            case ElementType_t.TRI_3: return(Triangle.Instance);

            case ElementType_t.TRI_6: return(Triangle.Instance);

            case ElementType_t.QUAD_4: return(Square.Instance);

            case ElementType_t.QUAD_8: return(Square.Instance);

            case ElementType_t.QUAD_9: return(Square.Instance);

            case ElementType_t.TETRA_4: return(Tetra.Instance);

            case ElementType_t.TETRA_10: return(Tetra.Instance);

            case ElementType_t.PYRA_5: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PYRA_14: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_6: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_15: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.PENTA_18: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.HEXA_8: return(Cube.Instance);

            case ElementType_t.HEXA_20: return(Cube.Instance);

            case ElementType_t.HEXA_27: return(Cube.Instance);

            case ElementType_t.MIXED: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            case ElementType_t.NGON_n: throw new NotSupportedException(string.Format("CGNS Element {0} not supported in BoSSS.", t.ToString()));

            default: throw new NotImplementedException();
            }
        }
コード例 #5
0
ファイル: CgnsDriver.cs プロジェクト: xyuan/BoSSS
        /// <summary>
        /// number of nodes for element of type <paramref name="t"/>.
        /// </summary>
        public static int NoOfNodes(this ElementType_t t)
        {
            switch (t)
            {
            case ElementType_t.ElementTypeNull: throw new NotSupportedException();

            case ElementType_t.ElementTypeUserDefined: throw new NotSupportedException();

            case ElementType_t.NODE: return(1);

            case ElementType_t.BAR_2: return(2);

            case ElementType_t.BAR_3: return(3);

            case ElementType_t.TRI_3: return(3);

            case ElementType_t.TRI_6: return(6);

            case ElementType_t.QUAD_4: return(4);

            case ElementType_t.QUAD_8: return(8);

            case ElementType_t.QUAD_9: return(9);

            case ElementType_t.TETRA_4: return(4);

            case ElementType_t.TETRA_10: return(10);

            case ElementType_t.PYRA_5: return(5);

            case ElementType_t.PYRA_14: return(14);

            case ElementType_t.PENTA_6: return(6);

            case ElementType_t.PENTA_15: return(15);

            case ElementType_t.PENTA_18: return(18);

            case ElementType_t.HEXA_8: return(8);

            case ElementType_t.HEXA_20: return(20);

            case ElementType_t.HEXA_27: return(27);

            case ElementType_t.MIXED: throw new NotSupportedException();

            case ElementType_t.NGON_n: throw new NotSupportedException();

            default: throw new NotImplementedException();
            }
        }
コード例 #6
0
ファイル: CGNS2BoSSSGrid.cs プロジェクト: xyuan/BoSSS
        static MultidimensionalArray GetTransformationParams(ElementType_t t, int[] cgNodes, double[][] coords, int D)
        {
            var R = MultidimensionalArray.Create(cgNodes.Length, D);

            int[] NodePerm = GetBoSSSNodes(t, cgNodes);
            for (int l = 0; l < NodePerm.Length; l++)
            {
                for (int d = 0; d < D; d++)
                {
                    R[l, d] = coords[d][NodePerm[l] - 1];
                }
            }
            return(R);
        }
コード例 #7
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private int NumberOfFacesPerElement(ElementType_t type)
 {
     if (number_of_coord_dimensions == 3)
     {
         if (type.Equals(ElementType_t.TRI_3) || type.Equals(ElementType_t.QUAD_4))
         {
             return(1);
         }
     }
     if (type.Equals(ElementType_t.HEXA_8))
     {
         return(6);
     }
     char[] number = type.ToString().ToCharArray();
     return(number[number.Length - 1] - 48);
 }
コード例 #8
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private bool ChoosenBoSSSCompliantElementType(ElementType_t type)
 {
     return(type.Equals(bosss_element_type));
 }
コード例 #9
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private static bool BoSSSCompliantElementType(ElementType_t type)
 {
     return(type.Equals(ElementType_t.TRI_3) || type.Equals(ElementType_t.TETRA_4) || type.Equals(ElementType_t.QUAD_4) || type.Equals(ElementType_t.HEXA_8));
 }
コード例 #10
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private static bool Is3D(ElementType_t type)
 {
     return(type.Equals(ElementType_t.TETRA_4) || type.Equals(ElementType_t.HEXA_8));
 }
コード例 #11
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
 private static int NumberOfNodesPerElement(ElementType_t type)
 {
     char[] number = type.ToString().ToCharArray();
     return(number[number.Length - 1] - 48);
 }
コード例 #12
0
ファイル: CgnsZoneToBoSSSGrid.cs プロジェクト: xyuan/BoSSS
        /// <summary>
        /// Generates zoneless arrays
        /// </summary>
        private void GenerateZonelessAndSectionlessArrays()
        {
            int i, j, k, l, m, n, a, b, c;

            zone_types = new ZoneType_t[] { m_zone.zone_type }; // zone_types_of_all_zones;

            int array_length = 0;

            for (i = 0; i < zone_types.Length; i++)
            {
                array_length += m_zone.x.GetLength(0);    // x_of_all_zones[i].GetLength(0);
            }

            x = new double[array_length];
            y = new double[array_length];
            z = new double[array_length];

            node_to_element_indices = new List <int> [array_length];
            to_node_index           = new int[zone_types.Length][];
            to_element_index        = new int[zone_types.Length][][];
            for (i = 0, j = 0; i < zone_types.Length; i++) // over zone indices
            {
                a = m_zone.x.GetLength(0);                 //x_of_all_zones[i].GetLength(0);
                to_node_index[i] = new int[a];
                for (k = 0; k < a; j++, k++)               // over coordinate indices per zone
                {
                    x[j] = m_zone.x[k, 0, 0];              //x_of_all_zones[i][k, 0, 0];
                    y[j] = m_zone.y[k, 0, 0];              //y_of_all_zones[i][k, 0, 0];
                    z[j] = m_zone.z[k, 0, 0];              //z_of_all_zones[i][k, 0, 0];
                    to_node_index[i][k]        = j;        // i|k index -> j index
                    node_to_element_indices[j] = new List <int>();
                }
            }

            array_length = 0;
            //for (i = 0; i < elements_of_all_zones.Length; i++) {
            {
                a = m_zone.elements.Length; // elements_of_all_zones[i].Length;
                for (k = 0; k < a; k++)
                {
                    array_length += m_zone.elements[k].GetLength(0);  // elements_of_all_zones[i][k].GetLength(0);
                }
            }

            element_types = new ElementType_t[array_length];
            elements      = new int[array_length][];
            //for (i = 0, j = 0, m = 0; i < elements_of_all_zones.Length; i++) // over zone indices
            j = 0;
            m = 0;
            i = 0;
            {
                a = m_zone.elements.Length;                               // elements_of_all_zones[i].Length;
                to_element_index[i] = new int[a][];
                for (k = 0; k < a; j++, k++)                              // over section indices per zone
                {
                    b = m_zone.elements[k].GetLength(0);                  //elements_of_all_zones[i][k].GetLength(0);
                    c = NumberOfNodesPerElement(m_zone.element_types[k]); // element_types_of_all_zones[i][k]);
                    to_element_index[i][k] = new int[b];
                    for (l = 0; l < b; l++, m++)                          // over element indices (per section) per zone
                    {
                        to_element_index[i][k][l] = m;                    // i|k|l index -> m index
                        elements[m]      = new int[c];
                        element_types[m] = m_zone.element_types[k];       // element_types_of_all_zones[i][k];
                        if (Is3D(element_types[m]))
                        {
                            number_of_coord_dimensions = 3;
                        }
                        if (BoSSSCompliantElementType(element_types[m]))
                        {
                            if (verticesPerCell < c)
                            {
                                verticesPerCell    = c;
                                bosss_element_type = element_types[m];
                            }
                            if (number_of_face_edges < NumberOfFaceEdges(element_types[m]))
                            {
                                number_of_face_edges = NumberOfFaceEdges(element_types[m]);
                                bosss_element_type   = element_types[m];
                            }
                            if (number_of_faces_per_element < NumberOfFacesPerElement(element_types[m]))
                            {
                                number_of_faces_per_element      = NumberOfFacesPerElement(element_types[m]);
                                number_of_faces_per_element_mask = (1 << number_of_faces_per_element) - 1;
                                bosss_element_type = element_types[m];
                            }
                        }
                        for (n = 0; n < c; n++)   // over coordinate indices per elements (per section) per zone
                        {
                            node_to_element_indices[elements[m][n] = to_node_index[i][m_zone.elements /*elements_of_all_zones[i]*/[k][l, n] - 1]].Add(m);
                        }
                    }
                }
            }
            // Michael: Das gehört hier raus! War wohl vergessen worden zu löschen (siehe direkt oben)

            /*
             * for (m = 0; m < elements.Length; m++) {
             *  if (BoSSSCompliantElementType(element_types[m]) && (number_of_coord_dimensions == 2 || Is3D(element_types[m]))) {
             *      c = NumberOfNodesPerElement(element_types[m]);
             *      if (verticesPerCell > c) {
             *          verticesPerCell = c;
             *          bosss_element_type = element_types[m];
             *      }
             *      if (number_of_face_edges > NumberOfFaceEdges(element_types[m])) {
             *          number_of_face_edges = NumberOfFaceEdges(element_types[m]);
             *          bosss_element_type = element_types[m];
             *      }
             *      if (number_of_faces_per_element > NumberOfFacesPerElement(element_types[m])) {
             *          number_of_faces_per_element = NumberOfFacesPerElement(element_types[m]);
             *          number_of_faces_per_element_mask = (1 << number_of_faces_per_element) - 1;
             *          bosss_element_type = element_types[m];
             *      }
             *  }
             * }*/
            cgns_element_index_to_bosss_element_index = new int[elements.Length];
            bosss_element_index_to_cgns_element_index = new int[elements.Length];
            for (m = 0; m < elements.Length; m++)
            {
                if (ChoosenBoSSSCompliantElementType(element_types[m]))
                {
                    bosss_element_index_to_cgns_element_index[cgns_element_index_to_bosss_element_index[m] = bosss_elements++] = m;
                }
            }
            array_length = 0;
            //for (i = 0; i < bcelements_of_all_zones.Length; i++) // over zone indices
            {
                a = /*bcelements_of_all_zones[i]*/ m_zone.bcelements.Length;
                for (k = 0; k < a; k++)   // over section indices per zone
                {
                    array_length += /*bcelements_of_all_zones[i]*/ m_zone.bcelements[k].Length;
                }
            }

            gridlocation_types = new GridLocation_t[array_length];
            pointset_types     = new PointSetType_t[array_length];
            bc_types           = new BCType_t[array_length];
            boconames          = new char[array_length][];
            bcelements         = new int[array_length][];
            normal_indices     = new int[array_length][];
            //for (i = 0, j = 0, m = 0; i < bcelements_of_all_zones.Length; i++) // over zone indices
            i = 0;
            j = 0;
            m = 0;
            {
                a = /*bcelements_of_all_zones[i]*/ m_zone.bcelements.Length;
                for (k = 0; k < a; j++, k++)   // over section indices per zone
                {
                    b = /*bcelements_of_all_zones[i]*/ m_zone.bcelements[k].Length;
                    for (l = 0; l < b; l++, m++)   // over boundary condition indices (per section) per zone
                    {
                        gridlocation_types[m] = /*gridlocation_types_of_all_zones[i]*/ m_zone.gridlocation_types[k][l];

                        // Michael: Wieso ist diese Einschränkung hier? Gab es mal Probleme ohne diese Exception? Mache ich mal raus.
                        if (!gridlocation_types[m].Equals(GridLocation_t.FaceCenter) && !gridlocation_types[m].Equals(GridLocation_t.Vertex))
                        {
                            // ThrowError("Unsupported gridlocation");
                        }

                        pointset_types[m] = /*pointset_types_of_all_zones[i]*/ m_zone.pointset_types[k][l];
                        bc_types[m]       = /*bc_types_of_all_zones[i]*/ m_zone.bc_types[k][l];
                        boconames[m]      = /*boconames_of_all_zones[i]*/ m_zone.boconames[k][l];
                        normal_indices[m] = /*normal_indices_of_all_zones[i]*/ m_zone.normal_indices[k][l];
                        c             = /*bcelements_of_all_zones[i]*/ m_zone.bcelements[k][l].Length;
                        bcelements[m] = new int[c];
                        for (n = 0; n < c; n++)   // over coordinate indices per boundary condition (per section) per zone
                        {
                            if (gridlocation_types[m].Equals(GridLocation_t.Vertex))
                            {
                                bcelements[m][n] = to_node_index[i][/*bcelements_of_all_zones[i]*/ m_zone.bcelements[k][l][n] - 1];
                            }
                            else
                            {
                                bcelements[m][n] = /*bcelements_of_all_zones[i]*/ m_zone.bcelements[k][l][n] - 1;
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: CGNS2BoSSSGrid.cs プロジェクト: xyuan/BoSSS
        /// <summary>
        /// permutation between CGNS node numbering and BoSSS node numbering
        /// </summary>
        /// <remarks>
        /// Falls irgendwo ein Fehler ist, nicht bei mir beschweren, sondern reparieren:
        /// http://www.grc.nasa.gov/WWW/cgns/CGNS_docs_current/sids/sids.pdf, Seite 20 ff;
        /// </remarks>
        static int[] GetBoSSSNodes(ElementType_t t, int[] cgNodes)
        {
            if (t == ElementType_t.NODE)
            {
                return(cgNodes.CloneAs());
            }
            // ---------------------
            if (t == ElementType_t.BAR_2)
            {
                return(new int[] { cgNodes[0], cgNodes[1] });
            }
            if (t == ElementType_t.BAR_3)
            {
                return(new int[] { cgNodes[2], cgNodes[0], cgNodes[1] });
            }
            // ---------------------
            if (t == ElementType_t.TRI_3)
            {
                //return new int[] { cgNodes[0], cgNodes[1], cgNodes[2] };
                return(new int[] { cgNodes[2], cgNodes[1], cgNodes[0] });
            }
            if (t == ElementType_t.TRI_6)
            {
                return(new int[] { cgNodes[3], cgNodes[4], cgNodes[5], cgNodes[0], cgNodes[1], cgNodes[2] });
            }
            // ---------------------
            if (t == ElementType_t.QUAD_4)
            {
                return(new int[] { cgNodes[3], cgNodes[0], cgNodes[2], cgNodes[1] });
            }
            if (t == ElementType_t.QUAD_8)
            {
                return(new int[] { cgNodes[6], cgNodes[4], cgNodes[5], cgNodes[7], cgNodes[3], cgNodes[0], cgNodes[2], cgNodes[1] });
            }
            if (t == ElementType_t.QUAD_9)
            {
                return(new int[] { cgNodes[8], cgNodes[6], cgNodes[4], cgNodes[5], cgNodes[7], cgNodes[3], cgNodes[0], cgNodes[2], cgNodes[1] });
            }
            // ---------------------
            if (t == ElementType_t.TETRA_4)
            {
                return(new int[] { cgNodes[3], cgNodes[1], cgNodes[0], cgNodes[2] });
            }
            if (t == ElementType_t.TETRA_10)
            {
                return(new int[] { cgNodes[4], cgNodes[6], cgNodes[5], cgNodes[7], cgNodes[9], cgNodes[8], cgNodes[3], cgNodes[1], cgNodes[0], cgNodes[2] });
            }
            // ---------------------
            if (t == ElementType_t.HEXA_8)
            {
                return(new int[] { cgNodes[3], cgNodes[0], cgNodes[7], cgNodes[2], cgNodes[4], cgNodes[5], cgNodes[1], cgNodes[6] });
            }
            if (t == ElementType_t.HEXA_20)
            {
                return(new int[] { cgNodes[15], cgNodes[14], cgNodes[18], cgNodes[10], cgNodes[12], cgNodes[13], cgNodes[16], cgNodes[8], cgNodes[17], cgNodes[19], cgNodes[9], cgNodes[11], cgNodes[3], cgNodes[0], cgNodes[7], cgNodes[2], cgNodes[4], cgNodes[5], cgNodes[1], cgNodes[6] });
            }
            if (t == ElementType_t.HEXA_27)
            {
                return(new int[] { cgNodes[26], cgNodes[23], cgNodes[21], cgNodes[25], cgNodes[20], cgNodes[22], cgNodes[24], cgNodes[15], cgNodes[14], cgNodes[18], cgNodes[10], cgNodes[12], cgNodes[13], cgNodes[16], cgNodes[8], cgNodes[17], cgNodes[19], cgNodes[9], cgNodes[11], cgNodes[3], cgNodes[0], cgNodes[7], cgNodes[2], cgNodes[4], cgNodes[5], cgNodes[1], cgNodes[6] });
            }

            throw new NotSupportedException();
        }
コード例 #14
0
        /// <summary>
        /// Generates zoneless arrays
        /// </summary>
        private void GenerateZonelessAndSectionlessArrays()
        {
            if (need_struct_conversion)
            {
                ThrowError("Struct conversion needed");
            }

            int i, j, k, l, m, n, a, b, c;

            zone_types = zone_types_of_all_zones;

            int array_length = 0;

            for (i = 0; i < zone_types.Length; i++)
            {
                array_length += x_of_all_zones[i].GetLength(0);
            }

            x = new double[array_length];
            y = new double[array_length];
            z = new double[array_length];

            node_to_element_indices = new List <int> [array_length];
            to_node_index           = new int[zone_types.Length][];
            to_element_index        = new int[zone_types.Length][][];
            for (i = 0, j = 0; i < zone_types.Length; i++)   // over zone indices
            {
                a = x_of_all_zones[i].GetLength(0);
                to_node_index[i] = new int[a];
                for (k = 0; k < a; j++, k++)   // over coordinate indices per zone
                {
                    x[j] = x_of_all_zones[i][k, 0, 0];
                    y[j] = y_of_all_zones[i][k, 0, 0];
                    z[j] = z_of_all_zones[i][k, 0, 0];
                    to_node_index[i][k]        = j; // i|k index -> j index
                    node_to_element_indices[j] = new List <int>();
                }
            }

            array_length = 0;
            for (i = 0; i < elements_of_all_zones.Length; i++)
            {
                a = elements_of_all_zones[i].Length;
                for (k = 0; k < a; k++)
                {
                    array_length += elements_of_all_zones[i][k].GetLength(0);
                }
            }

            element_types = new ElementType_t[array_length];
            elements      = new int[array_length][];
            for (i = 0, j = 0, m = 0; i < elements_of_all_zones.Length; i++)   // over zone indices
            {
                a = elements_of_all_zones[i].Length;
                to_element_index[i] = new int[a][];
                for (k = 0; k < a; j++, k++)   // over section indices per zone
                {
                    b = elements_of_all_zones[i][k].GetLength(0);
                    c = NumberOfNodesPerElement(element_types_of_all_zones[i][k]);
                    to_element_index[i][k] = new int[b];
                    for (l = 0; l < b; l++, m++)       // over element indices (per section) per zone
                    {
                        to_element_index[i][k][l] = m; // i|k|l index -> m index
                        elements[m]      = new int[c];
                        element_types[m] = element_types_of_all_zones[i][k];
                        if (Is3D(element_types[m]))
                        {
                            number_of_coord_dimensions = 3;
                        }
                        if (BoSSSCompliantElementType(element_types[m]))
                        {
                            if (verticesPerCell < c)
                            {
                                verticesPerCell    = c;
                                bosss_element_type = element_types[m];
                            }
                            if (number_of_face_edges < NumberOfFaceEdges(element_types[m]))
                            {
                                number_of_face_edges = NumberOfFaceEdges(element_types[m]);
                                bosss_element_type   = element_types[m];
                            }
                            if (number_of_faces_per_element < NumberOfFacesPerElement(element_types[m]))
                            {
                                number_of_faces_per_element      = NumberOfFacesPerElement(element_types[m]);
                                number_of_faces_per_element_mask = (1 << number_of_faces_per_element) - 1;
                                bosss_element_type = element_types[m];
                            }
                        }
                        for (n = 0; n < c; n++)   // over coordinate indices per elements (per section) per zone
                        {
                            node_to_element_indices[elements[m][n] = to_node_index[i][elements_of_all_zones[i][k][l, n] - 1]].Add(m);
                        }
                    }
                }
            }
            for (m = 0; m < elements.Length; m++)
            {
                if (BoSSSCompliantElementType(element_types[m]) && (number_of_coord_dimensions == 2 || Is3D(element_types[m])))
                {
                    c = NumberOfNodesPerElement(element_types[m]);
                    if (verticesPerCell > c)
                    {
                        verticesPerCell    = c;
                        bosss_element_type = element_types[m];
                    }
                    if (number_of_face_edges > NumberOfFaceEdges(element_types[m]))
                    {
                        number_of_face_edges = NumberOfFaceEdges(element_types[m]);
                        bosss_element_type   = element_types[m];
                    }
                    if (number_of_faces_per_element > NumberOfFacesPerElement(element_types[m]))
                    {
                        number_of_faces_per_element      = NumberOfFacesPerElement(element_types[m]);
                        number_of_faces_per_element_mask = (1 << number_of_faces_per_element) - 1;
                        bosss_element_type = element_types[m];
                    }
                }
            }
            cgns_element_index_to_bosss_element_index = new int[elements.Length];
            bosss_element_index_to_cgns_element_index = new int[elements.Length];
            for (m = 0; m < elements.Length; m++)
            {
                if (ChoosenBoSSSCompliantElementType(element_types[m]))
                {
                    bosss_element_index_to_cgns_element_index[cgns_element_index_to_bosss_element_index[m] = bosss_elements++] = m;
                }
            }
            array_length = 0;
            for (i = 0; i < bcelements_of_all_zones.Length; i++)   // over zone indices
            {
                a = bcelements_of_all_zones[i].Length;
                for (k = 0; k < a; k++)   // over section indices per zone
                {
                    array_length += bcelements_of_all_zones[i][k].Length;
                }
            }

            gridlocation_types = new GridLocation_t[array_length];
            pointset_types     = new PointSetType_t[array_length];
            bc_types           = new BCType_t[array_length];
            boconames          = new char[array_length][];
            bcelements         = new int[array_length][];
            normal_indices     = new int[array_length][];
            for (i = 0, j = 0, m = 0; i < bcelements_of_all_zones.Length; i++)   // over zone indices
            {
                a = bcelements_of_all_zones[i].Length;
                for (k = 0; k < a; j++, k++)   // over section indices per zone
                {
                    b = bcelements_of_all_zones[i][k].Length;
                    for (l = 0; l < b; l++, m++)   // over boundary condition indices (per section) per zone
                    {
                        gridlocation_types[m] = gridlocation_types_of_all_zones[i][k][l];

                        if (!gridlocation_types[m].Equals(GridLocation_t.FaceCenter) && !gridlocation_types[m].Equals(GridLocation_t.Vertex))
                        {
                            ThrowError("Unsupported gridlocation");
                        }

                        pointset_types[m] = pointset_types_of_all_zones[i][k][l];
                        bc_types[m]       = bc_types_of_all_zones[i][k][l];
                        boconames[m]      = boconames_of_all_zones[i][k][l];
                        normal_indices[m] = normal_indices_of_all_zones[i][k][l];
                        c             = bcelements_of_all_zones[i][k][l].Length;
                        bcelements[m] = new int[c];
                        for (n = 0; n < c; n++)   // over coordinate indices per boundary condition (per section) per zone
                        {
                            if (gridlocation_types[m].Equals(GridLocation_t.Vertex))
                            {
                                bcelements[m][n] = to_node_index[i][bcelements_of_all_zones[i][k][l][n] - 1];
                            }
                            else
                            {
                                bcelements[m][n] = bcelements_of_all_zones[i][k][l][n] - 1;
                            }
                        }
                    }
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// loads or saves an adf or hdf5 file from or to a specified path
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="hdf5"></param>
        /// <param name="context"></param>
        public void Build(string filePath, bool hdf5, GridData context)
        {
            using (CgnsDriver cg = new CgnsDriver(hdf5)) {
                int    index_file    = 0;
                int    index_base    = 0;
                int    index_zone    = 0;
                int    index_section = 0;
                char[] basename      = new char[100];
                char[] zonename      = new char[100];
                char[] coordnameX    = new char[100];
                char[] coordnameY    = new char[100];
                char[] coordnameZ    = new char[100];
                char[] flow          = new char[100];
                char[] secname       = new char[100];
                char[] boconame;
                char[] solname = new char[100];
                int[,] isize = new int[3, 3];
                int[]      irmin = new int[3];
                int[]      irmax = new int[3];
                int        celldim, physdim;   // zone definition
                int        start, end, nbndry; // element definition
                DataType_t data_type;


                // some header information
                // =======================

                basename   = "Base".ToNullTermCharAry();
                zonename   = "Zone".ToNullTermCharAry();
                coordnameX = "CoordinateX".ToNullTermCharAry();
                coordnameY = "CoordinateY".ToNullTermCharAry();
                coordnameZ = "CoordinateZ".ToNullTermCharAry();
                flow       = "VectorMagnitude".ToNullTermCharAry();
                secname    = "Section".ToNullTermCharAry();
                boconame   = "BoundaryCondition".ToNullTermCharAry();
                solname    = "FlowSolution".ToNullTermCharAry();
                data_type  = DataType_t.RealDouble;

                int index_coord;
                int index_flow;
                int index_field;

                if (cg.open(filePath.ToNullTermCharAry(), (int)Mode.MODE_WRITE, out index_file) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                celldim = physdim = context.Grid.SpatialDimension;

                if (cg.base_write(index_file, basename, celldim, physdim, out index_base) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                cg.gopath(index_file, "/Base".ToNullTermCharAry());

                cg.descriptor_write("Information".ToNullTermCharAry(), title.ToNullTermCharAry());

                GridCommons grd = context.Grid;

                ElementType_t bosss_element_type = ElementType_t.ElementTypeNull;

                if (grd.RefElements.Length > 1)
                {
                    throw new NotSupportedException("implementation todo");
                }
                var RefElm = grd.RefElements[0];
                if (RefElm.GetType() == typeof(Line))
                {
                    bosss_element_type = ElementType_t.BAR_2;
                }
                else if (RefElm.GetType() == typeof(Square))
                {
                    bosss_element_type = ElementType_t.QUAD_4;
                }
                else if (RefElm.GetType() == typeof(Triangle))
                {
                    bosss_element_type = ElementType_t.TRI_3;
                }
                else if (RefElm.GetType() == typeof(Cube))
                {
                    bosss_element_type = ElementType_t.HEXA_8;
                }
                else if (RefElm.GetType() == typeof(Tetra))
                {
                    bosss_element_type = ElementType_t.TETRA_4;
                }
                else
                {
                    ThrowError("Unsupported BoSSS element type", index_file, cg);
                }

                if (!showJumps)
                {
                    isize[0, 0] = totalVertices;
                }
                else
                {
                    isize[0, 0] = NoOfCells * verticesPerCell;
                }
                isize[0, 1] = totalCells;
                isize[0, 2] = 0;

                if (cg.zone_write(index_file, index_base, zonename, isize, ZoneType_t.Unstructured, out index_zone) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                // write grid vertices
                // ===================

                double[, ,] x = null;
                double[, ,] y = null;
                double[, ,] z = null;

                if (!showJumps)
                {
                    x = new double[isize[0, 0], 1, 1];
                    for (int vertex = 0; vertex < isize[0, 0]; vertex++)
                    {
                        x[vertex, 0, 0] = vertices[vertex, 0];
                    }
                    if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameX, x, out index_coord) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    y = new double[isize[0, 0], 1, 1];
                    for (int vertex = 0; vertex < isize[0, 0]; vertex++)
                    {
                        y[vertex, 0, 0] = vertices[vertex, 1];
                    }
                    if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameY, y, out index_coord) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (celldim > 2)
                    {
                        z = new double[isize[0, 0], 1, 1];
                        for (int vertex = 0; vertex < isize[0, 0]; vertex++)
                        {
                            z[vertex, 0, 0] = vertices[vertex, 2];
                        }
                        if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameZ, z, out index_coord) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                    }
                }
                else
                {
                    x = new double[isize[0, 0], 1, 1];
                    int cnt = 0;
                    for (int j = 0; j < NoOfCells; j++)
                    {
                        for (int i = 0; i < verticesPerCell; i++)
                        {
                            x[cnt, 0, 0] = verticeCoordinates[j, i, 0];
                            cnt++;
                        }
                    }
                    if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameX, x, out index_coord) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    y   = new double[isize[0, 0], 1, 1];
                    cnt = 0;
                    for (int j = 0; j < NoOfCells; j++)
                    {
                        for (int i = 0; i < verticesPerCell; i++)
                        {
                            y[cnt, 0, 0] = verticeCoordinates[j, i, 1];
                            cnt++;
                        }
                    }
                    if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameY, y, out index_coord) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                    if (celldim > 2)
                    {
                        z   = new double[isize[0, 0], 1, 1];
                        cnt = 0;
                        for (int j = 0; j < NoOfCells; j++)
                        {
                            for (int i = 0; i < verticesPerCell; i++)
                            {
                                z[cnt, 0, 0] = verticeCoordinates[j, i, 2];
                                cnt++;
                            }
                        }
                        if (cg.coord_write3(index_file, index_base, index_zone, data_type, coordnameZ, z, out index_coord) != (int)Error.CG_OK)
                        {
                            ThrowError(index_file, cg);
                        }
                    }
                }

                if (cg.sol_write(index_file, index_base, index_zone, solname, GridLocation_t.Vertex, out index_flow) != (int)Error.CG_OK)
                {
                    ThrowError(index_file, cg);
                }

                // write DG fields
                // ===============

                foreach (Field field in fields)
                {
                    calculateField(field);

                    if (!showJumps)
                    {
                        cg.field_write1(index_file, index_base, index_zone, index_flow, data_type, field.ToString().ToNullTermCharAry(), smoothedResult, out index_field);
                    }
                    else
                    {
                        cg.field_write1(index_file, index_base, index_zone, index_flow, data_type, field.ToString().ToNullTermCharAry(), notSmoothedResult, out index_field);
                    }
                }

                // write cell connectivity
                // =======================

                int[] permutationTable = elementTypeToPermutationTableMap[bosss_element_type];
                if (!showJumps)
                {
                    int[,] permutedConnectivity = new int[isize[0, 1], connectivity.GetLength(1)];

                    for (int i = 0; i < isize[0, 1]; i++)
                    {
                        for (int j = 0; j < permutationTable.Length; j++)
                        {
                            permutedConnectivity[i, j] = 1 + connectivity[i, permutationTable[j]];
                        }
                    }

                    start  = 1;
                    end    = isize[0, 1];
                    nbndry = 0;

                    if (cg.section_write2(index_file, index_base, index_zone, secname, bosss_element_type, start, end, nbndry, permutedConnectivity, out index_section) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                }
                else
                {
                    int[, ,] permutedConnectivity = new int[NoOfCells, subdivisionsPerCell, permutationTable.Length];
                    for (int j = 0; j < NoOfCells; j++)
                    {
                        for (int jj = 0; jj < subdivisionsPerCell; jj++)
                        {
                            for (int i = 0; i < permutationTable.Length; i++)
                            {
                                permutedConnectivity[j, jj, i] = 1 + j * verticesPerCell + subdivisionTreeLeaves[jj].GlobalVerticeInd[permutationTable[i]];
                            }
                        }
                    }

                    start  = 1;
                    end    = isize[0, 1];
                    nbndry = 0;

                    if (cg.section_write3(index_file, index_base, index_zone, secname, bosss_element_type, start, end, nbndry, permutedConnectivity, out index_section) != (int)Error.CG_OK)
                    {
                        ThrowError(index_file, cg);
                    }
                }
                if (cg.close(index_file) != (int)Error.CG_OK)
                {
                    ThrowError(cg);
                }
            }
        }