예제 #1
0
        /// <summary>
        /// Loads a BoSSS grid from an grid file; the file type (see <see cref="ImporterTypes"/>) are determined by the file ending.
        /// </summary>
        public static GridCommons Import(string fileName)
        {
            using (var tr = new FuncTrace()) {
                ImporterTypes importerType = GetImporterType(fileName);

                tr.Info(string.Format("Loading {0} file '{1}'...", importerType.ToString(), fileName));
                IGridImporter importer;
                using (new BlockTrace("Import", tr)) {
                    switch (importerType)
                    {
                    case ImporterTypes.Gambit:
                        GambitNeutral gn = new GambitNeutral(fileName);
                        if (gn.BoSSSConversionNeccessary())
                        {
                            gn = gn.ToLinearElements();
                        }

                        importer = gn;
                        break;

                    case ImporterTypes.CGNS:
                        importer = new Cgns(fileName);
                        break;

                    case ImporterTypes.Gmsh:
                        importer = new Gmsh(fileName);
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                tr.Info("Converting to BoSSS grid ...");
                GridCommons grid;
                using (new BlockTrace("Conversion", tr)) {
                    grid = importer.GenerateBoSSSGrid();
                }

                return(grid);
            }
        }
예제 #2
0
        static public GridCommons ToBoSSSGrid(this Cgns cgns, int BaseNodeIndex = 0)
        {
            var b = cgns.base_t.ElementAt(BaseNodeIndex);
            int D = b.CellDimension;



            var grid = CreateBoSSSGrid(b);

            long GlobalID_cnt = 0;

            int[] NodesPerZone = b.zones.Select(delegate(Cgns.Zone_t z) {
                if (!(z is Cgns.UnstructuredZone_t))
                {
                    throw new NotSupportedException("Only unstructured Grids are supported for CGNS ot BoSSS conversion.");
                }

                Cgns.UnstructuredZone_t uz = (Cgns.UnstructuredZone_t)z;

                int Ncoords = uz.coord[0].Length;
                for (int d = 1; d < uz.coord.Length; d++)
                {
                    if (uz.coord[d].Length != Ncoords)
                    {
                        throw new ApplicationException("invalid cgns data.");
                    }
                }

                return(Ncoords);
            }).ToArray();


            // import cells
            // ============

            {
                List <Cell> Cells      = new List <Cell>();
                int         NodeOffset = 0;
                for (int iZone = 0; iZone < b.zones.Length; iZone++)
                {
                    var z = b.zones[iZone];

                    if (!(z is Cgns.UnstructuredZone_t))
                    {
                        throw new NotSupportedException("Only unstructured Grids are supported for CGNS ot BoSSS conversion.");
                    }

                    Cgns.UnstructuredZone_t uz = (Cgns.UnstructuredZone_t)z;

                    int NumberOfNodes = NodesPerZone[iZone];


                    foreach (Cgns.Elements_t elm in uz.elements)
                    {
                        if (elm.element_type.Dimension() != D)
                        {
                            continue;
                        }

                        CellType BoSSSCelType = elm.element_type.ToBoSSSCellType();

                        for (int j = 0; j < elm.ielem.GetLength(0); j++)
                        {
                            Cell cell = new Cell();
                            cell.GlobalID = GlobalID_cnt;
                            cell.Type     = BoSSSCelType;

                            int[] CgnsNodes = elm.ielem.GetRow(j);
                            foreach (int iNode in CgnsNodes)
                            {
                                if (iNode > NumberOfNodes)
                                {
                                    throw new ArgumentException("CGNS node index out of range.");
                                }
                            }
                            cell.NodeIndices = GetBoSSSConnectivityNodes(elm.element_type, CgnsNodes);
                            for (int iNode = 0; iNode < cell.NodeIndices.Length; iNode++)
                            {
                                cell.NodeIndices[iNode] += NodeOffset;
                            }

                            cell.TransformationParams = GetTransformationParams(elm.element_type, CgnsNodes, uz.coord, D);

                            GlobalID_cnt++;

                            Cells.Add(cell);
                        }
                    }

                    NodeOffset += NumberOfNodes;
                }
                grid.Cells = Cells.ToArray();
            }

            // import Bc
            // =========
            {
                List <BCElement> BcCells = new List <BCElement>();

                byte EdgeTagCnt = 0;

                int NodeOffset = 0;
                for (int iZone = 0; iZone < b.zones.Length; iZone++)
                {
                    var z = b.zones[iZone];

                    if (!(z is Cgns.UnstructuredZone_t))
                    {
                        throw new NotSupportedException("Only unstructured Grids are supported.");
                    }

                    Cgns.UnstructuredZone_t uz = (Cgns.UnstructuredZone_t)z;

                    int NumberOfNodes = NodesPerZone[iZone];

                    foreach (Cgns.BC_t bc in uz.bcs)
                    {
                        Cgns.Elements_t bc_elements = uz.elements.Single(
                            elem => (elem.Name.Equals(bc.Name)));

                        byte EdgeTag;
                        if (!(grid.EdgeTagNames.Values.Contains(bc.Name, (x, y) => x.Equals(y))))
                        {
                            EdgeTagCnt++;
                            grid.EdgeTagNames.Add(EdgeTagCnt, bc.Name);
                            EdgeTag = EdgeTagCnt;
                        }
                        else
                        {
                            var f = grid.EdgeTagNames.Single(kv => kv.Value.Equals(bc.Name));
                            EdgeTag = f.Key;
                        }

                        CellType BoSSSCelType = bc_elements.element_type.ToBoSSSCellType();

                        for (int j = 0; j < bc_elements.ielem.GetLength(0); j++)
                        {
                            BCElement cell = new BCElement();
                            cell.GlobalID = GlobalID_cnt;
                            cell.Type     = BoSSSCelType;
                            cell.EdgeTag  = EdgeTag;

                            int[] CgnsNodes = bc_elements.ielem.GetRow(j);
                            foreach (int iNode in CgnsNodes)
                            {
                                if (iNode > NumberOfNodes)
                                {
                                    throw new ArgumentException("CGNS node index out of range.");
                                }
                            }
                            cell.NodeIndices = GetBoSSSConnectivityNodes(bc_elements.element_type, CgnsNodes);
                            for (int iNode = 0; iNode < cell.NodeIndices.Length; iNode++)
                            {
                                cell.NodeIndices[iNode] += NodeOffset;
                            }

                            cell.TransformationParams = GetTransformationParams(bc_elements.element_type, CgnsNodes, uz.coord, D);

                            GlobalID_cnt++;

                            BcCells.Add(cell);
                        }
                    }

                    NodeOffset += NumberOfNodes;
                }

                if (BcCells.Count > 0)
                {
                    grid.BcCells = BcCells.ToArray();
                }
            }


            // finalize & return
            // =================

            if (b.zones.Length > 1)
            {
                grid.MergeAndCheckNodes();
            }
            grid.CompressGlobalID();
            grid.CompressNodeIndices();
            grid.CheckAndFixJacobianDeterminat();

            return(grid);
        }
예제 #3
0
        /// <summary>
        /// Loads a BoSSS grid from an grid file; the file type (see <see cref="ImporterTypes"/>) are determined by the file ending.
        /// </summary>
        public static GridCommons Import(string fileName)
        {
            using (var tr = new FuncTrace()) {
                int myrank;
                int size;
                csMPI.Raw.Comm_Rank(csMPI.Raw._COMM.WORLD, out myrank);
                csMPI.Raw.Comm_Size(csMPI.Raw._COMM.WORLD, out size);

                ImporterTypes importerType = default(ImporterTypes);
                if (myrank == 0)
                {
                    importerType = GetImporterType(fileName);
                }
                importerType = importerType.MPIBroadcast(0);


                IGridImporter importer;
                {
                    tr.Info(string.Format("Loading {0} file '{1}'...", importerType.ToString(), fileName));

                    using (new BlockTrace("Import", tr)) {
                        switch (importerType)
                        {
                        case ImporterTypes.Gambit:
                            if (size > 1)
                            {
                                throw new NotSupportedException("Not supported in parallel mode");
                            }
                            GambitNeutral gn = new GambitNeutral(fileName);
                            if (gn.BoSSSConversionNeccessary())
                            {
                                gn = gn.ToLinearElements();
                            }

                            importer = gn;
                            break;

                        case ImporterTypes.CGNS:
                            if (size > 1)
                            {
                                throw new NotSupportedException("Not supported in parallel mode");
                            }
                            importer = new Cgns(fileName);
                            break;

                        case ImporterTypes.Gmsh:
                            importer = new Gmsh(fileName);
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                    }

                    tr.Info("Converting to BoSSS grid ...");
                }

                GridCommons grid;
                using (new BlockTrace("Conversion", tr)) {
                    grid = importer.GenerateBoSSSGrid();
                }


                return(grid);
            }
        }