public static FlatArray <ITile> GenerateRandomMap(int x, int y, VisualMode mode) { FlatArray <ITile> resultTiles = new FlatArray <ITile>(x, y); switch (mode) { case VisualMode.ASCII: { for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { int val = rng.Next(0, 100); if (val > 70) { Terrain wall = new Terrain("wall", "#", Tile.MaxVolume); resultTiles[i, j] = new Tile(new Point(i, j), wall); } else { Terrain grass = new Terrain("grass", ",", 5, Flags.IsTransparent); resultTiles[i, j] = new Tile(new Point(i, j), grass); } } } break; } case VisualMode.Sprites: break; } return(resultTiles); }
/// <summary> /// draw a fan of triangles like the following /// all active |left inactive |left & bottom inactive| all inactive /// 10--11--12 13 14 | 10--11--12 13 14 | 10--11--12 13 14 | 10--11--12 13 14 /// |\ | /| | |\ | /| | |\ | /| | |\ /| /// | \ | / | | | \ | / | | | \ | / | | | \ / | /// | \|/ | | | \|/ | | | \|/ | | | \ / | /// 5---6---7 8 9 | 5 6---7 8 9 | 5 6---7 8 9 | 5 6 7 8 9 /// | /|\ | | | /|\ | | | / \ | | | / \ | /// | / | \ | | | / | \ | | | / \ | | | / \ | /// |/ | \| | |/ | \| | |/ \| | |/ \| /// 0---1---2 3 4 | 0---1---2 3 4 | 0---1---2 3 4 | 0---1---2 3 4 /// </summary> /// <param name="bottomLeftIndex">the bottom left point in the fan</param> /// <returns></returns> private int[] GetTriangleFan(int bottomLeftIndex, bool bottomActive, bool rightActive, bool topActive, bool leftActive) { List <int> tris = new List <int>(); int centreIndex = FlatArray.GetIndexOnNextRow(bottomLeftIndex, _pointsOnSide) + 1; int bottomRightIndex = bottomLeftIndex + 2; int topLeftIndex = FlatArray.GetIndexOnNextRow(FlatArray.GetIndexOnNextRow(bottomLeftIndex, _pointsOnSide), _pointsOnSide); int topRightIndex = topLeftIndex + 2; // bottom fans tris.Add(bottomLeftIndex); tris.Add(centreIndex); if (bottomActive) { tris.Add(bottomLeftIndex + 1); tris.Add(bottomLeftIndex + 1); tris.Add(centreIndex); } tris.Add(bottomLeftIndex + 2); // right fans tris.Add(bottomRightIndex); tris.Add(centreIndex); if (rightActive) { tris.Add(FlatArray.GetIndexOnNextRow(bottomRightIndex, _pointsOnSide)); tris.Add(FlatArray.GetIndexOnNextRow(bottomRightIndex, _pointsOnSide)); tris.Add(centreIndex); } tris.Add(topRightIndex); // top fans tris.Add(topRightIndex); tris.Add(centreIndex); if (topActive) { tris.Add(topRightIndex - 1); tris.Add(topRightIndex - 1); tris.Add(centreIndex); } tris.Add(topLeftIndex); // left fans tris.Add(topLeftIndex); tris.Add(centreIndex); if (leftActive) { tris.Add(FlatArray.GetIndexOnPreviousRow(topLeftIndex, _pointsOnSide)); tris.Add(FlatArray.GetIndexOnPreviousRow(topLeftIndex, _pointsOnSide)); tris.Add(centreIndex); } tris.Add(bottomLeftIndex); return(tris.ToArray()); }
public void Test_FlatArray() { int[] theFirstArray = { 2, 52, 56, 12, 3 }; int[] theSecondArray = { 1, 0, 65, 42 }; int[] theThirdArray = { 3, 4, 6 }; int[] expected = { 1, 0, 2, 3, 4, 6, 12, 42, 52, 56, 65 }; Assert.Equal(expected, FlatArray.Combine()); }
public void Test_FlatArray() { int[] theFirstArray = { 2, 52, 56, 12, 3 }; int[] theSecondArray = { 1, 0, 65, 42 }; int[] theThirdArray = { 3, 4, 6 }; int[] ExpectedResult = { 0, 1, 2, 3, 3, 4, 6, 12, 42, 52, 56, 65 }; Assert.Equal(ExpectedResult, FlatArray.Combine(theFirstArray, theSecondArray, theThirdArray)); }
public static void SaveGame(FlatArray<GameCell> gameField) { SaveUnits(); SaveMap(gameField); SaveGameStats(); SaveItemsToDB(Item.ItemsGenerated); GameEngine.MessageLog.SendMessage("Game saved."); }
public void tes_combine_array() { int[] arr1 = { 2, 52 }; int[] arr2 = { 65, 42 }; int[] arr3 = { 3, 4, 6 }; int[] expected = { 2, 3, 4, 6, 42, 52, 65 }; Assert.Equal(expected, FlatArray.Combine(arr1, arr2, arr3)); }
/// <summary> /// builds a flattened 2D array of vertices like the following: /// /// 15--16--17--18--19 /// | | | | | /// 10--11--12--13--14 /// | | | | | /// 5---6---7---8---9 /// | | | | | /// 0---1---2---3---4 /// /// NOTE: <see cref="AddNeighbors"/> must be called after this method to /// ensure that we properly detect the correct neighbors /// </summary> private void GenerateVertices() { // start from the passed in _bottomLeft Vector3 and build list of QuadVerts int rows = Subdivisions + 2; int cols = rows; float colVertOffset = 0F; float rowVertOffset = 0F; colVertOffset = Size / (Subdivisions + 1F); rowVertOffset = Size / (Subdivisions + 1F); float uvScalar = 1 / (4 * Face.Size); float xBottomLeftOffset = -Size / 2F; float yBottomLeftOffset = -Size / 2F; float zBottomLeftOffset = 0F; Vector3 bottomLeftCorner = new Vector3(xBottomLeftOffset, yBottomLeftOffset, zBottomLeftOffset); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { int index = FlatArray.GetIndexFromRowCol(row, col, cols); Vector3 v = new Vector3((col * colVertOffset) + bottomLeftCorner.x, (row * rowVertOffset) + bottomLeftCorner.y, bottomLeftCorner.z); if (index == 0) { BottomLeft = v.Clone(); } if (index == FlatArray.GetBottomRightIndex(cols)) { BottomRight = v.Clone(); } if (index == FlatArray.GetTopLeftIndex(rows, cols)) { TopLeft = v.Clone(); } if (index == FlatArray.GetTopRightIndex(rows, cols)) { TopRight = v.Clone(); } Vector3 scaledUV = Face.ToLocalVert(ToWorldVert(v)) * uvScalar; var uvOffset = Face.GetUVOffset(); Vector2 uv = new Vector2(uvOffset.x + scaledUV.x, uvOffset.y + scaledUV.y); // set elevation v = GetInverseOffsetFromRoot(Face.ApplyElevation(GetOffsetFromRoot(v), uv)); Vertices[index] = v; UVs[index] = uv; } } DistanceTestCentre = GetInverseOffsetFromRoot(Face.ApplyElevation(GetOffsetFromRoot(CentrePoint), Face.GetUVOffset())); }
public void Nested_Array_Null_Without_Split_Character() { // Arrange FlatArray flatArray = new FlatArray(); // Act flatArray.BuildTheFlatArray(null); // Assert Assert.AreEqual(0, flatArray.ConvertStringArrayToIntegerArray().Length); }
/// <summary> /// Initializes a new instance of the <see cref="Map" /> class. /// </summary> /// <param name="tiles">FlatArray of <typeparamref name="T"/> elements, /// representing the actual Game Map.</param> /// <param name="id">Map ID.</param> /// <param name="name">Map Name.</param> /// <param name="flags">Map flags.</param> /// <param name="viewBoxTileSize">Size of the Map view-box in number of Tiles.</param> public Map(FlatArray <T> tiles, int id, string name, Flags flags, Point viewBoxTileSize) : base(id, name, flags) { this.Tiles = tiles; this.ViewBoxTileCount = viewBoxTileSize; this.fieldOfView = new FieldOfView <T>(this.Tiles); Rectangle mapWindow = new Rectangle( LeftMargin, TopMargin, this.ViewBoxTileCount.X * Sprite.TileSize, this.ViewBoxTileCount.Y * Sprite.TileSize); }
public IMap GenerateDungeonMap(int width, int height) { this.generatedMapTiles = new FlatArray <ITile>(width, height); // Fill the whole map solid ITerrain rock = new Terrain("rock", "[]", 125); this.FillMap(rock); // . . . return(new MapContainer(this.generatedMapTiles)); }
public void Nested_Array_Check_if_Empty_false() { // Arrange FlatArray flatArray = new FlatArray(); char comma = ','; // Act flatArray.BuildTheFlatArray("[1, 2,[3]],4]", comma); // Assert Assert.AreEqual(false, flatArray.IsFlatArrayEmpty()); }
public void Nested_Array_Without_Intergers() { // Arrange FlatArray flatArray = new FlatArray(); char comma = ','; // Act flatArray.BuildTheFlatArray("[A, D,[B]],C]", comma); // Assert Assert.AreEqual(true, flatArray.IsFlatArrayEmpty()); }
public void Nested_Array_Check_if_Empty_true() { // Arrange FlatArray flatArray = new FlatArray(); char comma = ','; // Act flatArray.BuildTheFlatArray("", comma); // Assert Assert.AreEqual(true, flatArray.IsFlatArrayEmpty()); }
public void Nested_Array_Empty_With_Null_Split_Character() { // Arrange FlatArray flatArray = new FlatArray(); char empty = '\0'; // Act flatArray.BuildTheFlatArray("", empty); // Assert Assert.AreEqual(0, flatArray.ConvertStringArrayToIntegerArray().Length); }
public void Nested_Array_With_Expected_Output() { // Arrange FlatArray flatArray = new FlatArray(); int[] expectedArray = new int[] { 1, 2, 3, 4 }; // Act flatArray.BuildTheFlatArray("[[1, 2,[3]],4]", ','); // Assert CollectionAssert.AreEqual(expectedArray, flatArray.ConvertStringArrayToIntegerArray()); }
/// <summary> /// draw a fan of triangles like the following, leaving edges empty /// | | | /// --------- /// |\|/| /// --------- /// |/|\| /// --------- /// | | | /// </summary> private void GenerateCentreTriangles() { if (_centreTriangleCache == null) { List <int> tris = new List <int>(); int rows = _pointsOnSide - 4; // stop before last 2 rows of verts int cols = rows; // stop before last 2 columns of verts // skip the edge triangles as they are special case and just generate the centre triangle fans for (int row = 2; row < rows; row += 2) { for (int col = 2; col < cols; col += 2) { tris.AddRange(GetTriangleFan( FlatArray.GetIndexFromRowCol(row, col, _pointsOnSide), true, true, true, true)); } } _centreTriangleCache = tris.ToArray(); } }
/// <summary> /// Convert the enter nested array into flat array. /// </summary> static void ConvertNestedToFlatArray() { IFlatArray flatArray = new FlatArray(); if (_splitCharacterChar != '\0') { flatArray.BuildTheFlatArray(_nestedArray, _splitCharacterChar); } else { flatArray.BuildTheFlatArray(_nestedArray); } if (!flatArray.IsFlatArrayEmpty()) { flatArray.PrintNestedArray(); } else { flatArray.PrintEmptyNestedArray(); } }
public static void NewGame() { string pcName = "SCiENiDE_TESTING"; //for testing purposes we set the char name manually; //else use the bottom row. //string pcName = UIElements.PromptForName(); UIElements.InGameUI(); messageLog = new MessageLog(0, Globals.CONSOLE_HEIGHT - 1, Globals.GAME_FIELD_BOTTOM_RIGHT.X, (Globals.CONSOLE_HEIGHT - (Globals.GAME_FIELD_BOTTOM_RIGHT.Y + 1)), true); MessageLog.SendMessage("~w13!Message ~W2!log ~l11!i~l3!n~s11!itialized."); MessageLog.DeleteLog(); Units.Clear(); gameField = SaveLoadTools.LoadMap(); //load map; change it to generate map! MapFileName = @"../../maps/0.wocm"; Item.LastItemID = SaveLoadTools.LastItemID(); Flags pcFlags = Flags.IsCollidable | Flags.IsMovable | Flags.IsPlayerControl; Unit pc = new Unit(10, 10, pcFlags, '@', ConsoleColor.White, pcName, new UnitAttributes()); Units.Add(pc); GameTime = new GameTime(); Initialize(pc); }
public static void SpawnItemsOnMap(ref FlatArray<GameCell> gameField) { XDocument savedItems = XDocument.Load(ITEMS_ON_MAP_FILE); XElement root = savedItems.Element("item-cells"); var itemCells = root.Elements("cell"); foreach (var cell in itemCells) { int x = int.Parse(cell.Attribute("x").Value); int y = int.Parse(cell.Attribute("y").Value); var items = cell.Elements("item_id"); foreach (var item in items) { int itemID = int.Parse(item.Value); Item itemOnMap = new Item(Database.ItemDatabase[itemID]); gameField[x, y].ItemList.Add(itemOnMap); } } }
/// <summary> /// Construct a FieldOfView instance given a map of IFovCell objects /// </summary> /// <param name="inGrid"></param> public FieldOfView(FlatArray <TFovCell> inGrid) { grid = inGrid; }
private IEnumerable <string> GenerateInterface(TypeName name, Node node) { var i = node.@interface; var genericParams = this.GetGenericParams(node); var genericParamSpec = genericParams.IsEmpty ? string.Empty : $"<{string.Join(", ", genericParams)}>"; yield return($@" {this.GetDocComment(node)} public interface {name.Identifier}{genericParamSpec} : {CnNamespace}.Rpc.ICapability{GetSupertypes(i.superclasses)} {this.GetGenericConstraints(genericParams)} {{"); foreach (var tuple in i.methods .Select((method, ordinal) => ((method: method, ordinal))) .OrderBy(m => m.method.codeOrder)) { var(method, ordinal) = tuple; _implicitParameters = method.implicitParameters; var returnType = _typeNames.ContainsKey(method.resultStructType) ? $"{this.GetTypeName(name, this[method.resultStructType], method.resultBrand)}" : "void"; IEnumerable <string> genericArgsSpec = method.implicitParameters.Select(p => this.ToName(p.name)); var genericArgs = method.implicitParameters.Count > 0 ? $"<{string.Join(", ", genericArgsSpec)}>" : string.Empty; var parameter = _typeNames.ContainsKey(method.paramStructType) ? $"{this.GetTypeName(name, this[method.paramStructType], method.paramBrand)} parameters" : string.Empty; yield return($@" {GetDocComment(method.annotations)} [{CnNamespace}.Ordinal({ordinal})] {returnType} {this.ToName(method.name)}{genericArgs}({parameter}) {this.GetGenericConstraints(genericArgsSpec)};"); ordinal++; } _implicitParameters = default; yield return("}"); if (name.SideContainer != null) { yield return($@" public static class {name.SideContainer.Identifier}{genericParamSpec} {this.GetGenericConstraints(genericParams)} {{"); foreach (var code in _typeNames .Where(kvp => kvp.Value.Parent == name.SideContainer) .SelectMany(kvp => this.GenerateNode(this[kvp.Key]))) { yield return(code); } yield return("}"); } string GetSupertypes(FlatArray <Superclass> extends) { var names = string.Join(", ", extends.Select(e => this.GetTypeName(name.Parent, e))); return(string.IsNullOrEmpty(names) ? string.Empty : ", " + names); } }
public static FlatArray<GameCell> LoadMap(string mapFileName = null) { bool newMap = mapFileName == null; if (newMap) mapFileName = @"../../maps/0.wocm"; Database.LoadDatabases(); FlatArray<GameCell> gameGrid = new FlatArray<GameCell>(Globals.GAME_FIELD_BOTTOM_RIGHT.X, Globals.GAME_FIELD_BOTTOM_RIGHT.Y); using (var sReader = new StreamReader(mapFileName, ENCODING)) { char procCh = (char)sReader.Read(); StringBuilder mapName = new StringBuilder(); //--> map name do { mapName.Append(procCh); procCh = (char)sReader.Read(); } while (procCh != '['); GameEngine.MapName = mapName.ToString(); StringBuilder xSize = new StringBuilder(4); //--> gameField.GetLength(0) procCh = (char)sReader.Read(); do { xSize.Append(procCh); procCh = (char)sReader.Read(); } while (procCh != ';'); StringBuilder ySize = new StringBuilder(4); //--> gameField.GetLength(1) procCh = (char)sReader.Read(); do { ySize.Append(procCh); procCh = (char)sReader.Read(); } while (procCh != ']'); int charCode = sReader.Peek(); for (int x = 0; x < int.Parse(xSize.ToString()); x++) { for (int y = 0; y < int.Parse(ySize.ToString()); y++) { gameGrid[x, y] = new GameCell(); if (charCode != -1) { char readChar = (char)sReader.Read(); StringBuilder posInTerrainDB = new StringBuilder(4); //--> position in DB readChar = (char)sReader.Read(); do { posInTerrainDB.Append(readChar); readChar = (char)sReader.Read(); } while (readChar != ']' && readChar != '<'); int index = int.Parse(posInTerrainDB.ToString()); gameGrid[x, y].Terrain = new Terrain(Database.TerrainDatabase[index]); gameGrid[x, y].Terrain.X = x; gameGrid[x, y].Terrain.Y = y; if (readChar == '<') { StringBuilder posInInGameObjDB = new StringBuilder(4); //--> position in DB readChar = (char)sReader.Read(); do { posInInGameObjDB.Append(readChar); readChar = (char)sReader.Read(); } while (readChar != '>'); readChar = (char)sReader.Read(); int objIndex = int.Parse(posInInGameObjDB.ToString()); gameGrid[x, y].IngameObject = new InGameObject(Database.ObjectDatabase[objIndex]); gameGrid[x, y].IngameObject.X = x; gameGrid[x, y].IngameObject.Y = y; } } } } GameEngine.MessageLog.SendMessage("Map loaded."); if (!newMap) SpawnItemsOnMap(ref gameGrid); return gameGrid; } }
public static void SaveMap(FlatArray<GameCell> gameField) { StringBuilder parseMap = new StringBuilder(); XDocument mapItems = new XDocument(new XElement("item-cells")); XElement itemCells = mapItems.Element("item-cells"); for (int x = 0; x < gameField.Height; x++) { for (int y = 0; y < gameField.Width; y++) { parseMap.AppendFormat("[{0}", gameField[x, y].Terrain.PositionInDB); if (gameField[x, y].IngameObject == null) parseMap.Append("]"); else parseMap.AppendFormat("<{0}>]", gameField[x, y].IngameObject.PositionInDB); //save items on map if (gameField[x, y].ItemList.Count > 0) { XElement cell; itemCells.Add( cell = new XElement("cell", new XAttribute("x", x), new XAttribute("y", y))); foreach (var item in gameField[x, y].ItemList) cell.Add(new XElement("item_id", item.ID - 1)); } } } mapItems.Save(ITEMS_ON_MAP_FILE); //save map using (var sWriter = new StreamWriter(string.Format(@"../../maps/{0}.wocm", GameEngine.MapID), false, ENCODING)) { sWriter.Write(GameEngine.MapName); sWriter.Write(string.Format("[{0};{1}]", gameField.Height, gameField.Width)); sWriter.Write(parseMap.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="Map" /> class. /// </summary> /// <param name="tiles">FlatArray of <typeparamref name="T"/> elements, /// representing the actual Game Map.</param> /// <param name="id">Map ID.</param> /// <param name="name">Map Name.</param> public Map(FlatArray <T> tiles, int id, string name) : this(tiles, id, name, Flags.None, new Point(16, 10)) { }
private void GenerateCase(int caseId, bool topActive, bool bottomActive, bool leftActive, bool rightActive) { int rows = _pointsOnSide - 4; int cols = _pointsOnSide - 4; List <int> tris = new List <int>(_centreTriangleCache); if (rows > 0) { // bottom left tris.AddRange(GetTriangleFan(0, bottomActive, true, true, leftActive)); // bottom for (int col = 2; col < cols; col += 2) { tris.AddRange(GetTriangleFan(col, bottomActive, true, true, true)); } // bottom right tris.AddRange(GetTriangleFan(_pointsOnSide - 3, bottomActive, rightActive, true, true)); // right for (int row = 2; row < rows; row += 2) { tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(row, _pointsOnSide - 3, _pointsOnSide), true, rightActive, true, true)); } // top right tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(_pointsOnSide - 3, _pointsOnSide - 3, _pointsOnSide), true, rightActive, topActive, true)); // top for (int col = 2; col < cols; col += 2) { tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(_pointsOnSide - 3, col, _pointsOnSide), true, true, topActive, true)); } // top left tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(_pointsOnSide - 3, 0, _pointsOnSide), true, true, topActive, leftActive)); // left for (int row = 2; row < rows; row += 2) { tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(row, 0, _pointsOnSide), true, true, true, leftActive)); } } else if (rows == 0) { // bottom left tris.AddRange(GetTriangleFan(0, bottomActive, true, true, leftActive)); // bottom right tris.AddRange(GetTriangleFan(_pointsOnSide - 3, bottomActive, rightActive, true, true)); // top right tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(_pointsOnSide - 3, _pointsOnSide - 3, _pointsOnSide), true, rightActive, topActive, true)); // top left tris.AddRange(GetTriangleFan(FlatArray.GetIndexFromRowCol(_pointsOnSide - 3, 0, _pointsOnSide), true, true, topActive, leftActive)); } else { tris.AddRange(GetTriangleFan(0, bottomActive, rightActive, topActive, leftActive)); } _triangleCache[caseId] = tris.ToArray(); }
private string GetDocComment(FlatArray <Annotation> annotations) { // TODO return(string.Empty); }
public void UpdateCoarseGrid() { // cout << "UpdateCoarseGrid" << endl; // if (is_updated) return; NgMPI_Comm comm = mesh.GetCommunicator(); int id = comm.Rank(); int ntasks = comm.Size(); if (ntasks == 1) { return; } Reset(); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timer = NgProfiler::CreateTimer("UpdateCoarseGrid"); NgProfiler.RegionTimer reg = new NgProfiler.RegionTimer(UpdateCoarseGrid_timer); (*testout) << "UPDATE COARSE GRID PARALLEL TOPOLOGY " << "\n"; if (id == 0) { PrintMessage(1, "update parallel topology"); } // UpdateCoarseGridGlobal(); // MPI_Barrier (MPI_COMM_WORLD); MPI_Group MPI_GROUP_comm = new MPI_Group(); MPI_Group MPI_LocalGroup = new MPI_Group(); MPI_Comm MPI_LocalComm = new MPI_Comm(); int[] process_ranks = { 0 }; MPI_Comm_group(comm, MPI_GROUP_comm); MPI_Group_excl(MPI_GROUP_comm, 1, process_ranks, MPI_LocalGroup); MPI_Comm_create(comm, MPI_LocalGroup, MPI_LocalComm); if (id == 0) { return; } MeshTopology topology = mesh.GetTopology(); Array <int> cnt_send = new Array <int>(ntasks - 1); // update new vertices after mesh-refinement if (mesh.mlbetweennodes.Size() > 0) { // cout << "UpdateCoarseGrid - vertices" << endl; int newnv = mesh.mlbetweennodes.Size(); loc2distvert.ChangeSize(mesh.mlbetweennodes.Size()); /* * for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) * { * PointIndex v1 = mesh.mlbetweennodes[pi][0]; * PointIndex v2 = mesh.mlbetweennodes[pi][1]; * if (mesh.mlbetweennodes[pi][0] != PointIndex::BASE-1) * for (int dest = 1; dest < ntasks; dest++) * if (IsExchangeVert (dest, v1) && IsExchangeVert (dest, v2)) * SetDistantPNum(dest, pi); * } */ bool changed = true; while (changed) { changed = false; // build exchange vertices cnt_send = 0; foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { cnt_send[dist - 1]++; } } TABLE <int> dest2vert = new TABLE <int>(cnt_send); foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { dest2vert.Add(dist - 1, pi); } } for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { // for (int dest = 1; dest < ntasks; dest++) foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { cnt_send[dest - 1]++; } } } } TABLE <int> dest2pair = new TABLE <int>(cnt_send); // for (int dest = 1; dest < ntasks; dest++) for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { dest2pair.Add(dest - 1, pi); } } } } cnt_send = 0; int v1; int v2; for (PointIndex pi = PointIndex.BASE; pi < newnv + PointIndex.BASE; pi++) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { foreach (int dest in GetDistantPNums(v1 - PointIndex.BASE)) { if (IsExchangeVert(dest, new netgen.PointIndex(v2))) { cnt_send[dest - 1] += 2; } } } } TABLE <int> send_verts = new TABLE <int>(cnt_send); Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { loc2exchange = -1; int cnt = 0; /* * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } // for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) foreach (PointIndex pi in dest2pair[dest - 1]) { PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { if (IsExchangeVert(dest, new netgen.PointIndex(v1)) && IsExchangeVert(dest, new netgen.PointIndex(v2))) { send_verts.Add(dest - 1, loc2exchange[v1]); send_verts.Add(dest - 1, loc2exchange[v2]); } } } } } TABLE <int> recv_verts = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_verts, recv_verts, MPI_TAG_MESH + 9, MPI_LocalComm); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { loc2exchange = -1; int cnt = 0; /* * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } FlatArray <int> recvarray = recv_verts[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 2) { foreach (PointIndex pi in dest2pair[dest - 1]) { // for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) PointIndex v1 = mesh.mlbetweennodes[pi][0]; PointIndex v2 = mesh.mlbetweennodes[pi][1]; if (mesh.mlbetweennodes[pi][0] != PointIndex.BASE - 1) { INDEX_2 re = new INDEX_2(recvarray[ii], recvarray[ii + 1]); INDEX_2 es = new INDEX_2(loc2exchange[v1], loc2exchange[v2]); if (es == re && !IsExchangeVert(dest, new netgen.PointIndex(pi))) { SetDistantPNum(dest, new netgen.PointIndex(pi)); changed = true; } } } } } } } } Array <int> sendarray = new Array <int>(); Array <int> recvarray = new Array <int>(); // cout << "UpdateCoarseGrid - edges" << endl; // static int timerv = NgProfiler::CreateTimer ("UpdateCoarseGrid - ex vertices"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timere = NgProfiler::CreateTimer("UpdateCoarseGrid - ex edges"); //C++ TO C# CONVERTER NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method: // static int timerf = NgProfiler::CreateTimer("UpdateCoarseGrid - ex faces"); NgProfiler.StartTimer(UpdateCoarseGrid_timere); int nfa = topology.GetNFaces(); int ned = topology.GetNEdges(); // build exchange vertices cnt_send = 0; foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { cnt_send[dist - 1]++; } } TABLE <int> dest2vert = new TABLE <int>(cnt_send); foreach (PointIndex pi in mesh.Points().Range()) { foreach (int dist in GetDistantPNums(pi - PointIndex.BASE)) { dest2vert.Add(dist - 1, pi); } } // exchange edges cnt_send = 0; int v1; int v2; for (int edge = 1; edge <= ned; edge++) { topology.GetEdgeVertices(edge, ref v1, ref v2); for (int dest = 1; dest < ntasks; dest++) { if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { cnt_send[dest - 1] += 1; } } } TABLE <int> dest2edge = new TABLE <int>(cnt_send); foreach (int v in cnt_send) { v *= 2; } TABLE <int> send_edges = new TABLE <int>(cnt_send); for (int edge = 1; edge <= ned; edge++) { topology.GetEdgeVertices(edge, ref v1, ref v2); for (int dest = 1; dest < ntasks; dest++) { if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { dest2edge.Add(dest - 1, edge); } } } Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { loc2exchange = -1; int cnt = 0; foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } foreach (int edge in dest2edge[dest - 1]) { topology.GetEdgeVertices(edge, ref v1, ref v2); if (IsExchangeVert(dest, v1) && IsExchangeVert(dest, v2)) { send_edges.Add(dest - 1, loc2exchange[v1]); send_edges.Add(dest - 1, loc2exchange[v2]); } } } // cout << "UpdateCoarseGrid - edges mpi-exchange" << endl; TABLE <int> recv_edges = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_edges, recv_edges, MPI_TAG_MESH + 9, MPI_LocalComm); // cout << "UpdateCoarseGrid - edges mpi-exchange done" << endl; /* * for (int dest = 1; dest < ntasks; dest++) * { * auto ex2loc = dest2vert[dest-1]; * FlatArray<int> recvarray = recv_edges[dest-1]; * for (int ii = 0; ii < recvarray.Size(); ii+=2) * for (int edge : dest2edge[dest-1]) * { * topology.GetEdgeVertices (edge, v1, v2); * INDEX_2 re(ex2loc[recvarray[ii]], * ex2loc[recvarray[ii+1]]); * INDEX_2 es(v1, v2); * if (es == re) * SetDistantEdgeNum(dest, edge); * } * } */ for (int dest = 1; dest < ntasks; dest++) { var ex2loc = dest2vert[dest - 1]; if (ex2loc.Size() == 0) { continue; } INDEX_2_CLOSED_HASHTABLE <int> vert2edge = new INDEX_2_CLOSED_HASHTABLE <int>((uint)(2 * dest2edge[dest - 1].Size() + 10)); foreach (int edge in dest2edge[dest - 1]) { topology.GetEdgeVertices(edge, ref v1, ref v2); vert2edge.Set(new INDEX_2(v1, v2), edge); } FlatArray <int> recvarray = recv_edges[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 2) { INDEX_2 re = new INDEX_2(ex2loc[recvarray[ii]], ex2loc[recvarray[ii + 1]]); if (vert2edge.Used(re)) { SetDistantEdgeNum(dest, vert2edge.Get(re)); } } } NgProfiler.StopTimer(UpdateCoarseGrid_timere); // MPI_Barrier (MPI_LocalComm); // cout << "UpdateCoarseGrid - faces" << endl; if (mesh.GetDimension() == 3) { NgProfiler.StartTimer(UpdateCoarseGrid_timerf); Array <int> verts = new Array <int>(); // exchange faces cnt_send = 0; for (int face = 1; face <= nfa; face++) { topology.GetFaceVertices(face, verts); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { cnt_send[dest - 1]++; } } } } TABLE <int> dest2face = new TABLE <int>(cnt_send); for (int face = 1; face <= nfa; face++) { topology.GetFaceVertices(face, verts); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { dest2face.Add(dest - 1, face); } } } } foreach (int c in cnt_send) { c *= 3; } TABLE <int> send_faces = new TABLE <int>(cnt_send); Array <int, PointIndex.BASE> loc2exchange = new Array <int, PointIndex.BASE>(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { if (dest != id) { /* * loc2exchange = -1; * int cnt = 0; * for (PointIndex pi : mesh.Points().Range()) * if (IsExchangeVert(dest, pi)) * loc2exchange[pi] = cnt++; */ if (dest2vert[dest - 1].Size() == 0) { continue; } loc2exchange = -1; int cnt = 0; foreach (PointIndex pi in dest2vert[dest - 1]) { loc2exchange[pi] = cnt++; } foreach (int face in dest2face[dest - 1]) { topology.GetFaceVertices(face, verts); if (IsExchangeVert(dest, verts[0]) && IsExchangeVert(dest, verts[1]) && IsExchangeVert(dest, verts[2])) { send_faces.Add(dest - 1, loc2exchange[verts[0]]); send_faces.Add(dest - 1, loc2exchange[verts[1]]); send_faces.Add(dest - 1, loc2exchange[verts[2]]); } } } } // cout << "UpdateCoarseGrid - faces mpi-exchange" << endl; TABLE <int> recv_faces = new TABLE <int>(ntasks - 1); netgen.GlobalMembers.MyMPI_ExchangeTable(send_faces, recv_faces, MPI_TAG_MESH + 9, MPI_LocalComm); // cout << "UpdateCoarseGrid - faces mpi-exchange done" << endl; /* * for (int dest = 1; dest < ntasks; dest++) * if (dest != id) * { * loc2exchange = -1; * int cnt = 0; * for (PointIndex pi : dest2vert[dest-1]) * loc2exchange[pi] = cnt++; * * FlatArray<int> recvarray = recv_faces[dest-1]; * for (int ii = 0; ii < recvarray.Size(); ii+=3) * for (int face : dest2face[dest-1]) * { * topology.GetFaceVertices (face, verts); * INDEX_3 re(recvarray[ii], recvarray[ii+1], recvarray[ii+2]); * INDEX_3 es(loc2exchange[verts[0]], loc2exchange[verts[1]], loc2exchange[verts[2]]); * if (es == re) * SetDistantFaceNum(dest, face); * } * } */ for (int dest = 1; dest < ntasks; dest++) { var ex2loc = dest2vert[dest - 1]; if (ex2loc.Size() == 0) { continue; } INDEX_3_CLOSED_HASHTABLE <int> vert2face = new INDEX_3_CLOSED_HASHTABLE <int>(2 * dest2face[dest - 1].Size() + 10); foreach (int face in dest2face[dest - 1]) { topology.GetFaceVertices(face, verts); vert2face.Set(new INDEX_3(verts[0], verts[1], verts[2]), face); } FlatArray <int> recvarray = recv_faces[dest - 1]; for (int ii = 0; ii < recvarray.Size(); ii += 3) { INDEX_3 re = new INDEX_3(ex2loc[recvarray[ii]], ex2loc[recvarray[ii + 1]], ex2loc[recvarray[ii + 2]]); if (vert2face.Used(re)) { SetDistantFaceNum(dest, vert2face.Get(re)); } } } /* * Array<int,1> glob2loc; * * int maxface = 0; * for (int face = 1; face <= nfa; face++) * maxface = max (maxface, GetGlobalFaceNum (face)); * * // glob2loc.SetSize (nfaglob); * glob2loc.SetSize (maxface); * glob2loc = -1; * * for (int loc = 1; loc <= nfa; loc++) * glob2loc[GetGlobalFaceNum(loc)] = loc; * * cnt_send = 0; * Array<int> verts; * for (int face = 1; face <= nfa; face++) * { * topology.GetFaceVertices (face, verts); * for (int dest = 1; dest < ntasks; dest++) * if (IsExchangeVert (dest, verts[0]) && * IsExchangeVert (dest, verts[1]) && * IsExchangeVert (dest, verts[2])) * { * cnt_send[dest-1]+=2; * } * } * * TABLE<int> send_faces(cnt_send); * for (int face = 1; face <= nfa; face++) * { * topology.GetFaceVertices (face, verts); * for (int dest = 1; dest < ntasks; dest++) * { * if (IsExchangeVert (dest, verts[0]) && * IsExchangeVert (dest, verts[1]) && * IsExchangeVert (dest, verts[2])) * { * send_faces.Add (dest-1, GetGlobalFaceNum(face)); * send_faces.Add (dest-1, face); * } * } * } * TABLE<int> recv_faces(ntasks-1); * MyMPI_ExchangeTable (send_faces, recv_faces, MPI_TAG_MESH+8, MPI_LocalComm); * * for (int sender = 1; sender < ntasks; sender ++) * if (id != sender) * { * FlatArray<int> recvarray = recv_faces[sender-1]; * * for (int ii = 0; ii < recvarray.Size(); ) * { * int globf = recvarray[ii++]; * int distf = recvarray[ii++]; * * if (globf <= maxface) * { * int locf = glob2loc[globf]; * if (locf != -1) * SetDistantFaceNum (sender, locf); * } * } * } */ NgProfiler.StopTimer(UpdateCoarseGrid_timerf); } // cout << "UpdateCoarseGrid - done" << endl; is_updated = true; }
public MapContainer(FlatArray <ITile> tiles) { this.Tiles = tiles; }