Skip to content

Commit

Permalink
Added function to get block info (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Wu <[email protected]>
Co-authored-by: Neil Wu <[email protected]>
Co-authored-by: Eirikur Jonsson <[email protected]>
  • Loading branch information
4 people authored Aug 11, 2021
1 parent cc29c74 commit b9a4e3e
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 32 deletions.
13 changes: 7 additions & 6 deletions .github/azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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
parameters:
REPO_NAME: cgnsutilities
GCC_CONFIG: config/defaults/config.LINUX_GFORTRAN.mk
INTEL_CONFIG: config/defaults/config.LINUX_INTEL.mk
COVERAGE: true
2 changes: 1 addition & 1 deletion .github/build_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
cp $CONFIG_FILE config/config.mk
make
pip install .
pip install -e .[testing]
2 changes: 1 addition & 1 deletion .github/test_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.mod
*.o
*.so
*.out

# auto generated files
src/libcgns_utils-f2pywrappers2.f90
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
67 changes: 49 additions & 18 deletions cgnsutilities/cgnsutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ 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]
totalCells += blk.getNumCells()
totalNodes += blk.getNumNodes()

return totalCells, totalNodes

Expand Down Expand Up @@ -127,26 +127,49 @@ 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))
totalCells += nCells
totalNodes += nNodes
blockInfo = {}
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
counter += 1
print("Total Zones:", len(self.blocks))
print("Total Cells:", totalCells)
print("Total Nodes:", totalNodes)

totalCells, totalNodes = self.getTotalCellsNodes()

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):

Expand Down Expand Up @@ -2262,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):

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
)
184 changes: 184 additions & 0 deletions tests/ref/blockInfo.ref
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions tests/ref/block_getNumCells.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Number of cells": {
"__ndarray__": 6480,
"dtype": "int64",
"shape": []
}
}
7 changes: 7 additions & 0 deletions tests/ref/block_getNumNodes.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Number of nodes in the first block": {
"__ndarray__": 7581,
"dtype": "int32",
"shape": []
}
}
12 changes: 12 additions & 0 deletions tests/ref/totalCellsNodes.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Total cells": {
"__ndarray__": 15120,
"dtype": "int64",
"shape": []
},
"Total nodes": {
"__ndarray__": 18753,
"dtype": "int64",
"shape": []
}
}
12 changes: 12 additions & 0 deletions tests/ref/wallCellsNodes.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Wall cells": {
"__ndarray__": 756,
"dtype": "int64",
"shape": []
},
"Wall nodes": {
"__ndarray__": 893,
"dtype": "int64",
"shape": []
}
}
Loading

0 comments on commit b9a4e3e

Please sign in to comment.