from dataclasses import dataclass
from ..conesFunctions import local2Global, printCones
[docs]
@dataclass
class conesClip:
"""
A Class for clippings
:Author: Paolo Errante
:Version: 1.0.0
"""
def __init__(self, name):
"""
Initialize the conesClip class.
:param name: The name of the clipping
:type name: str
"""
self.path = str()
self.name = name
self.verbose = True
self.nRanks = int()
self.ranks = []
self.localCellList = []
self.globalCellList = []
[docs]
def get_clip_data(self, globalCellList):
"""
Reads and sets the clippings cell lists
:param globalCellList: List of global cells ids
:type globalCellList: list
:returns: None
"""
clipGlobalCellList = []
clipLocalCellList = []
for irank in range(0, self.nRanks):
fpath = self.path + "processor"+str(irank) + "/constant/polyMesh/sets/"+self.name
localRankCellList = []
globalRankCellList = []
with open(fpath) as file:
lines = file.readlines()
nCells = int(lines[17].strip())
for icell in range(0, nCells):
localCellID = int(lines[19+icell].strip())
globalCellID = local2Global(localCellID, globalCellList, irank)
globalRankCellList.append(globalCellID)
localRankCellList.append(localCellID)
localRankCellList.sort()
globalRankCellList.sort()
clipLocalCellList.append(localRankCellList)
clipGlobalCellList.append(globalRankCellList)
if (self.verbose):
printCones("Clip:", self.name, " localCellList ", clipLocalCellList)
printCones("Clip:", self.name, " globalCellList", clipGlobalCellList)
self.localCellList = clipLocalCellList
self.globalCellList = clipGlobalCellList
return
[docs]
def report(self):
"""
Print to stdout a report of the clipping object
"""
print("\n================ CLIP REPORT ==================\n")
print("Name: ", self.name)
print("Path: ", self.path)
print("ranks: ", self.ranks)
print("local cells ID: ", self.localCellList)
print("global cells ID: ", self.globalCellList)
print("\n===============================================\n")
return