From f281509dcb3eb3727cd9981bc2b77316c45d2644 Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 25 Jul 2021 15:04:55 -0400 Subject: [PATCH 01/12] refactored block info --- cgnsutilities/cgnsutilities.py | 62 ++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/cgnsutilities/cgnsutilities.py b/cgnsutilities/cgnsutilities.py index 933c6b5..ca99783 100644 --- a/cgnsutilities/cgnsutilities.py +++ b/cgnsutilities/cgnsutilities.py @@ -51,6 +51,13 @@ def __init__(self): self.name = "domain" self.cellDim = 3 + @staticmethod + def getBlockCellsNodes(blk): + blockCells = (blk.dims[0] - 1) * (blk.dims[1] - 1) * (blk.dims[2] - 1) + blockNodes = blk.dims[0] * blk.dims[1] * blk.dims[2] + + return blockCells, blockNodes + def getTotalCellsNodes(self): """ Returns the total number of Cells and Nodes in the grid. @@ -65,8 +72,9 @@ def getTotalCellsNodes(self): totalCells = 0 totalNodes = 0 for blk in self.blocks: - totalCells += (blk.dims[0] - 1) * (blk.dims[1] - 1) * (blk.dims[2] - 1) - totalNodes += blk.dims[0] * blk.dims[1] * blk.dims[2] + blockCells, blockNodes = self.getBlockCellsNodes(blk) + totalCells += blockCells + totalNodes += blockNodes return totalCells, totalNodes @@ -127,26 +135,52 @@ def printInfo(self): print("Wall Boundary Cells:", boundaryCells) print("Wall Boundary Nodes:", boundaryNodes) - def printBlockInfo(self): - """Print some information on each block to screen. - This info can be helpful assessing overset meshes""" + def getBlockInfo(self): + """Get the number of nodes, number of cells, BCs, and + the dimensions for each block. This info can be helpful + for assessing overset meshes.""" totalCells = 0 totalNodes = 0 counter = 1 + allBlocksInfo = {} + for blk in self.blocks: - nCells = (blk.dims[0] - 1) * (blk.dims[1] - 1) * (blk.dims[2] - 1) - nNodes = blk.dims[0] * blk.dims[1] * blk.dims[2] - print("Block Number:", counter) - print("Number of Cells:", nCells) - print("Number of Nodes:", nNodes) - print("Block dimensions:", list(blk.dims)) + blockInfo = {} + nCells, nNodes = self.getBlockCellsNodes(blk) + blockInfo["nCells"] = nCells + blockInfo["nNodes"] = nNodes + blockInfo["dims"] = list(blk.dims) + blockInfo["BCs"] = [boco.type for boco in blk.bocos] + allBlocksInfo[f"{counter}"] = blockInfo totalCells += nCells totalNodes += nNodes counter += 1 - print("Total Zones:", len(self.blocks)) - print("Total Cells:", totalCells) - print("Total Nodes:", totalNodes) + + allBlocksInfo["totalZones"] = len(self.blocks) + allBlocksInfo["totalCells"] = totalCells + allBlocksInfo["totalNodes"] = totalNodes + + return allBlocksInfo + + def printBlockInfo(self): + """Print the number of nodes, number of cells, and + the dimensions for each block. This info can be helpful + for assessing overset meshes.""" + + allBlocksInfo = self.getBlockInfo() + + for i in range(len(self.blocks)): + blockNumber = str(i + 1) + print("Block Number:", blockNumber) + blockInfo = allBlocksInfo[blockNumber] + print("Number of Cells:", blockInfo["nCells"]) + print("Number of Nodes:", blockInfo["nNodes"]) + print("Block dimensions:", blockInfo["dims"]) + + print("Total Zones:", allBlocksInfo["totalZones"]) + print("Total Cells:", allBlocksInfo["totalCells"]) + print("Total Nodes:", allBlocksInfo["totalNodes"]) def addBlock(self, blk): From 349dff601dc565681b8cf3a9e99771e705c87b0e Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 25 Jul 2021 15:05:53 -0400 Subject: [PATCH 02/12] updated tests --- tests/test_cgnsutilities.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/test_cgnsutilities.py b/tests/test_cgnsutilities.py index 819655f..c425ad8 100644 --- a/tests/test_cgnsutilities.py +++ b/tests/test_cgnsutilities.py @@ -1,6 +1,7 @@ import os import subprocess import unittest +from baseclasses import BaseRegTest from cgnsutilities.cgnsutilities import readGrid, BC baseDir = os.path.dirname(os.path.abspath(__file__)) @@ -10,15 +11,34 @@ class TestGrid(unittest.TestCase): def setUp(self): self.grid = readGrid(os.path.abspath(os.path.join(baseDir, "../examples/717_wl_L2.cgns"))) - def test_getTotalCellsNodes(self): + def test_getTotalCellsNodes(self, train=False): totalCells, totalNodes = self.grid.getTotalCellsNodes() - self.assertEqual(totalCells, 15120) - self.assertEqual(totalNodes, 18753) + refFile = os.path.join(baseDir, "ref", "totalCellsNodes.ref") + with BaseRegTest(refFile, train=train) as handler: + handler.root_add_val("Total cells", totalCells, tol=0) + handler.root_add_val("Total nodes", totalNodes, tol=0) - def test_getWallCellsNodes(self): + def train_getTotalCellsNodes(self): + self.test_getTotalCellsNodes(train=True) + + def test_getWallCellsNodes(self, train=False): nWallCells, nWallNodes = self.grid.getWallCellsNodes() - self.assertEqual(nWallCells, 756) - self.assertEqual(nWallNodes, 893) + refFile = os.path.join(baseDir, "ref", "wallCellsNodes.ref") + with BaseRegTest(refFile, train=train) as handler: + handler.root_add_val("Wall cells", nWallCells, tol=0) + handler.root_add_val("Wall nodes", nWallNodes, tol=0) + + def train_getWallCellsNodes(self): + self.test_getWallCellsNodes(train=True) + + def test_getBlockInfo(self, train=False): + blockInfo = self.grid.getBlockInfo() + refFile = os.path.join(baseDir, "ref", "blockInfo.ref") + with BaseRegTest(refFile, train=train) as handler: + handler.root_add_dict("Block info", blockInfo, tol=0) + + def train_getBlockInfo(self): + self.test_getBlockInfo(train=True) def test_overwriteFamilies(self): # Find a specific BC and overwrite the family From d37c14d49843094927b1c576467a021f889e23ae Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 25 Jul 2021 15:06:12 -0400 Subject: [PATCH 03/12] added ref files --- tests/ref/blockInfo.ref | 184 ++++++++++++++++++++++++++++++++++ tests/ref/totalCellsNodes.ref | 12 +++ tests/ref/wallCellsNodes.ref | 12 +++ 3 files changed, 208 insertions(+) create mode 100644 tests/ref/blockInfo.ref create mode 100644 tests/ref/totalCellsNodes.ref create mode 100644 tests/ref/wallCellsNodes.ref diff --git a/tests/ref/blockInfo.ref b/tests/ref/blockInfo.ref new file mode 100644 index 0000000..85c8b48 --- /dev/null +++ b/tests/ref/blockInfo.ref @@ -0,0 +1,184 @@ +{ + "Block info": { + "1": { + "BCs": [ + 22, + 7, + 16 + ], + "dims": [ + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 21, + "dtype": "int32", + "shape": [] + } + ], + "nCells": { + "__ndarray__": 6480, + "dtype": "int64", + "shape": [] + }, + "nNodes": { + "__ndarray__": 7581, + "dtype": "int32", + "shape": [] + } + }, + "2": { + "BCs": [ + 22, + 7, + 16 + ], + "dims": [ + { + "__ndarray__": 3, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 21, + "dtype": "int32", + "shape": [] + } + ], + "nCells": { + "__ndarray__": 720, + "dtype": "int64", + "shape": [] + }, + "nNodes": { + "__ndarray__": 1197, + "dtype": "int32", + "shape": [] + } + }, + "3": { + "BCs": [ + 22, + 7, + 16 + ], + "dims": [ + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 21, + "dtype": "int32", + "shape": [] + } + ], + "nCells": { + "__ndarray__": 6480, + "dtype": "int64", + "shape": [] + }, + "nNodes": { + "__ndarray__": 7581, + "dtype": "int32", + "shape": [] + } + }, + "4": { + "BCs": [ + 22, + 7, + 16 + ], + "dims": [ + { + "__ndarray__": 3, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 21, + "dtype": "int32", + "shape": [] + } + ], + "nCells": { + "__ndarray__": 720, + "dtype": "int64", + "shape": [] + }, + "nNodes": { + "__ndarray__": 1197, + "dtype": "int32", + "shape": [] + } + }, + "5": { + "BCs": [ + 22, + 7 + ], + "dims": [ + { + "__ndarray__": 3, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 19, + "dtype": "int32", + "shape": [] + }, + { + "__ndarray__": 21, + "dtype": "int32", + "shape": [] + } + ], + "nCells": { + "__ndarray__": 720, + "dtype": "int64", + "shape": [] + }, + "nNodes": { + "__ndarray__": 1197, + "dtype": "int32", + "shape": [] + } + }, + "totalCells": { + "__ndarray__": 15120, + "dtype": "int64", + "shape": [] + }, + "totalNodes": { + "__ndarray__": 18753, + "dtype": "int64", + "shape": [] + }, + "totalZones": 5 + } +} \ No newline at end of file diff --git a/tests/ref/totalCellsNodes.ref b/tests/ref/totalCellsNodes.ref new file mode 100644 index 0000000..7a7b7bd --- /dev/null +++ b/tests/ref/totalCellsNodes.ref @@ -0,0 +1,12 @@ +{ + "Total cells": { + "__ndarray__": 15120, + "dtype": "int64", + "shape": [] + }, + "Total nodes": { + "__ndarray__": 18753, + "dtype": "int64", + "shape": [] + } +} \ No newline at end of file diff --git a/tests/ref/wallCellsNodes.ref b/tests/ref/wallCellsNodes.ref new file mode 100644 index 0000000..c5999e4 --- /dev/null +++ b/tests/ref/wallCellsNodes.ref @@ -0,0 +1,12 @@ +{ + "Wall cells": { + "__ndarray__": 756, + "dtype": "int64", + "shape": [] + }, + "Wall nodes": { + "__ndarray__": 893, + "dtype": "int64", + "shape": [] + } +} \ No newline at end of file From eaac1b91ccc9138bcef127921423ef6cf5c82676 Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 25 Jul 2021 15:06:47 -0400 Subject: [PATCH 04/12] updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 80159f4..8210f4c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.mod *.o *.so +*.out # auto generated files src/libcgns_utils-f2pywrappers2.f90 From da043c41f9b76c31947eba0cdc746005ad9054f1 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Mon, 26 Jul 2021 15:57:52 -0400 Subject: [PATCH 05/12] add coverage --- .github/azure-pipelines.yaml | 13 +++++++------ .github/build_real.sh | 2 +- .github/test_real.sh | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/azure-pipelines.yaml b/.github/azure-pipelines.yaml index 4640435..35dee98 100644 --- a/.github/azure-pipelines.yaml +++ b/.github/azure-pipelines.yaml @@ -1,15 +1,15 @@ trigger: -- master + - master pr: -- master + - master resources: repositories: - - repository: azure_template - type: github - name: mdolab/.github - endpoint: mdolab + - repository: azure_template + type: github + name: mdolab/.github + endpoint: mdolab extends: template: azure/azure_template.yaml@azure_template @@ -17,3 +17,4 @@ extends: REPO_NAME: cgnsutilities GCC_CONFIG: config/defaults/config.LINUX_GFORTRAN.mk INTEL_CONFIG: config/defaults/config.LINUX_INTEL.mk + COVERAGE: true diff --git a/.github/build_real.sh b/.github/build_real.sh index dd8e716..a3d6c85 100755 --- a/.github/build_real.sh +++ b/.github/build_real.sh @@ -2,4 +2,4 @@ set -e cp $CONFIG_FILE config/config.mk make -pip install . +pip install -e . diff --git a/.github/test_real.sh b/.github/test_real.sh index 339e987..03a8b60 100755 --- a/.github/test_real.sh +++ b/.github/test_real.sh @@ -2,7 +2,7 @@ set -e # Run tests -testflo -v -n 1 . +testflo -v -n 1 --coverage --coverpkg cgnsutilities # Check that we can run the command line script cd $HOME From 4af1d7d37285f4a8e0bdd3c440962b582bf23619 Mon Sep 17 00:00:00 2001 From: Neil Wu <602725+nwu63@users.noreply.github.com> Date: Mon, 26 Jul 2021 16:13:17 -0400 Subject: [PATCH 06/12] Added codecov badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 47c7ea0..84718c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # cgnsUtilities [![Build Status](https://dev.azure.com/mdolab/Public/_apis/build/status/mdolab.cgnsutilities?repoName=mdolab%2Fcgnsutilities&branchName=master)](https://dev.azure.com/mdolab/Public/_build/latest?definitionId=30&repoName=mdolab%2Fcgnsutilities&branchName=master) +[![codecov](https://codecov.io/gh/mdolab/cgnsutilities/branch/master/graph/badge.svg?token=ZCO3MR2LNL)](https://codecov.io/gh/mdolab/cgnsutilities) This repository contains a single program called `cgns_utils` that provides many useful functions for working with cgns grids. From 021f54b8b2325449c66d22216a2e2ae293484f1d Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 8 Aug 2021 15:06:34 -0400 Subject: [PATCH 07/12] added testing dependency --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 1f74ccc..a6858e7 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ packages=["cgnsutilities"], package_data={"cgnsutilities": ["*.so"]}, install_requires=["numpy>=1.16"], + extras_require={"testing": ["mdolab-baseclasses>=1.3", "testflo"]}, classifiers=["Operating System :: Linux", "Programming Language :: Python, Fortran"], entry_points={"console_scripts": ["cgns_utils = cgnsutilities.cgns_utils:main"]}, ) From a4f586c091f677894fb882373b7b13da9ec2fda1 Mon Sep 17 00:00:00 2001 From: sseraj Date: Sun, 8 Aug 2021 15:06:56 -0400 Subject: [PATCH 08/12] changed static method --- cgnsutilities/cgnsutilities.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cgnsutilities/cgnsutilities.py b/cgnsutilities/cgnsutilities.py index ca99783..385dcbb 100644 --- a/cgnsutilities/cgnsutilities.py +++ b/cgnsutilities/cgnsutilities.py @@ -51,8 +51,7 @@ def __init__(self): self.name = "domain" self.cellDim = 3 - @staticmethod - def getBlockCellsNodes(blk): + def getBlockCellsNodes(self, blk): blockCells = (blk.dims[0] - 1) * (blk.dims[1] - 1) * (blk.dims[2] - 1) blockNodes = blk.dims[0] * blk.dims[1] * blk.dims[2] From 3b59f365c08919e902e5a15c403753cea822eaac Mon Sep 17 00:00:00 2001 From: Eirikur Jonsson Date: Mon, 9 Aug 2021 14:31:37 +0000 Subject: [PATCH 09/12] Adding new getNumCells and getNumNodes for Block. Refactoring other implementation. --- cgnsutilities/cgnsutilities.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/cgnsutilities/cgnsutilities.py b/cgnsutilities/cgnsutilities.py index 385dcbb..3a174f2 100644 --- a/cgnsutilities/cgnsutilities.py +++ b/cgnsutilities/cgnsutilities.py @@ -51,12 +51,6 @@ def __init__(self): self.name = "domain" self.cellDim = 3 - def getBlockCellsNodes(self, blk): - blockCells = (blk.dims[0] - 1) * (blk.dims[1] - 1) * (blk.dims[2] - 1) - blockNodes = blk.dims[0] * blk.dims[1] * blk.dims[2] - - return blockCells, blockNodes - def getTotalCellsNodes(self): """ Returns the total number of Cells and Nodes in the grid. @@ -71,9 +65,8 @@ def getTotalCellsNodes(self): totalCells = 0 totalNodes = 0 for blk in self.blocks: - blockCells, blockNodes = self.getBlockCellsNodes(blk) - totalCells += blockCells - totalNodes += blockNodes + totalCells += blk.getNumCells() + totalNodes += blk.getNumNodes() return totalCells, totalNodes @@ -139,23 +132,20 @@ def getBlockInfo(self): the dimensions for each block. This info can be helpful for assessing overset meshes.""" - totalCells = 0 - totalNodes = 0 counter = 1 allBlocksInfo = {} for blk in self.blocks: blockInfo = {} - nCells, nNodes = self.getBlockCellsNodes(blk) - blockInfo["nCells"] = nCells - blockInfo["nNodes"] = nNodes + blockInfo["nCells"] = blk.getNumCells() + blockInfo["nNodes"] = blk.getNumNodes() blockInfo["dims"] = list(blk.dims) blockInfo["BCs"] = [boco.type for boco in blk.bocos] allBlocksInfo[f"{counter}"] = blockInfo - totalCells += nCells - totalNodes += nNodes counter += 1 + totalCells, totalNodes = self.getTotalCellsNodes() + allBlocksInfo["totalZones"] = len(self.blocks) allBlocksInfo["totalCells"] = totalCells allBlocksInfo["totalNodes"] = totalNodes @@ -2295,6 +2285,14 @@ def getFaceCoords(self, blockID): return libcgns_utils.utils.computefacecoords(self.coords, nFace, blockID) + def getNumCells(self): + """Computes and returns the number of cells for this block""" + return (self.dims[0] - 1) * (self.dims[1] - 1) * (self.dims[2] - 1) + + def getNumNodes(self): + """Computes and returns the number of nodes for this block""" + return self.dims[0] * self.dims[1] * self.dims[2] + class Boco(object): From 015d7a7cb74732b55b10bf953dc207d8964f5d48 Mon Sep 17 00:00:00 2001 From: Eirikur Jonsson Date: Mon, 9 Aug 2021 14:32:18 +0000 Subject: [PATCH 10/12] Adding tests for new getNumCells and getNumNodes functions --- tests/ref/block_getNumCells.ref | 7 +++++++ tests/ref/block_getNumNodes.ref | 7 +++++++ tests/test_cgnsutilities.py | 25 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/ref/block_getNumCells.ref create mode 100644 tests/ref/block_getNumNodes.ref diff --git a/tests/ref/block_getNumCells.ref b/tests/ref/block_getNumCells.ref new file mode 100644 index 0000000..c0a6989 --- /dev/null +++ b/tests/ref/block_getNumCells.ref @@ -0,0 +1,7 @@ +{ + "Number of cells": { + "__ndarray__": 6480, + "dtype": "int64", + "shape": [] + } +} \ No newline at end of file diff --git a/tests/ref/block_getNumNodes.ref b/tests/ref/block_getNumNodes.ref new file mode 100644 index 0000000..45f4ecd --- /dev/null +++ b/tests/ref/block_getNumNodes.ref @@ -0,0 +1,7 @@ +{ + "Number of nodes in the first block": { + "__ndarray__": 7581, + "dtype": "int32", + "shape": [] + } +} \ No newline at end of file diff --git a/tests/test_cgnsutilities.py b/tests/test_cgnsutilities.py index c425ad8..f9339a6 100644 --- a/tests/test_cgnsutilities.py +++ b/tests/test_cgnsutilities.py @@ -90,3 +90,28 @@ def test_overwriteFamilies(self): self.assertFalse(out.returncode) self.assertTrue(os.path.isfile("717_wl_L2_overwriteFamilies.cgns")) os.remove("717_wl_L2_overwriteFamilies.cgns") + + +class TestBlock(unittest.TestCase): + def setUp(self): + self.grid = readGrid(os.path.abspath(os.path.join(baseDir, "../examples/717_wl_L2.cgns"))) + + def test_getNumCells(self, train=False): + refFile = os.path.join(baseDir, "ref", "block_getNumCells.ref") + with BaseRegTest(refFile, train=train) as handler: + # Just pick the first block from the grid to test + numCells = self.grid.blocks[0].getNumCells() + handler.root_add_val("Number of cells", numCells, tol=0) + + def train_getNumCells(self): + self.test_getNumCells(train=True) + + def test_getNumNodes(self, train=False): + refFile = os.path.join(baseDir, "ref", "block_getNumNodes.ref") + with BaseRegTest(refFile, train=train) as handler: + # Just pick the first block from the grid to test + numCells = self.grid.blocks[0].getNumNodes() + handler.root_add_val("Number of nodes in the first block", numCells, tol=0) + + def train_getNumNodes(self): + self.test_getNumNodes(train=True) \ No newline at end of file From 29bad2ebdd4ed384534b03841fc466a2b566a355 Mon Sep 17 00:00:00 2001 From: Eirikur Jonsson Date: Mon, 9 Aug 2021 14:54:38 +0000 Subject: [PATCH 11/12] Formatting --- tests/test_cgnsutilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cgnsutilities.py b/tests/test_cgnsutilities.py index f9339a6..8b17356 100644 --- a/tests/test_cgnsutilities.py +++ b/tests/test_cgnsutilities.py @@ -114,4 +114,4 @@ def test_getNumNodes(self, train=False): handler.root_add_val("Number of nodes in the first block", numCells, tol=0) def train_getNumNodes(self): - self.test_getNumNodes(train=True) \ No newline at end of file + self.test_getNumNodes(train=True) From ceb192808394c6d598feda8fff7a3e7e0a57a326 Mon Sep 17 00:00:00 2001 From: Neil Wu <602725+nwu63@users.noreply.github.com> Date: Wed, 11 Aug 2021 09:06:16 -0400 Subject: [PATCH 12/12] Update build_real.sh --- .github/build_real.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/build_real.sh b/.github/build_real.sh index a3d6c85..a28dcbc 100755 --- a/.github/build_real.sh +++ b/.github/build_real.sh @@ -2,4 +2,4 @@ set -e cp $CONFIG_FILE config/config.mk make -pip install -e . +pip install -e .[testing]