def addMatrices(db, matricesDir, order, dynamicRuptureMethod, numberOfElasticQuantities, numberOfQuantities): numberOfBasisFunctions = Tools.numberOfBasisFunctions(order) if dynamicRuptureMethod == 'quadrature': numberOfPoints = (order + 1)**2 elif dynamicRuptureMethod == 'cellaverage': numberOfPoints = int(4**math.ceil(math.log(order * (order + 1) / 2, 4))) else: raise ValueError('Unknown dynamic rupture method.') clones = dict() # Load matrices db.update( Tools.parseMatrixFile( '{}/dr_{}_matrices_{}.xml'.format(matricesDir, dynamicRuptureMethod, order), clones)) # Determine matrices # Note: This does only work because the flux does not depend on the mechanisms in the case of viscoelastic attenuation godunovMatrixSpp = np.matlib.zeros( (numberOfQuantities, numberOfQuantities)) godunovMatrixSpp[0:numberOfElasticQuantities, 0:numberOfElasticQuantities] = 1. db.insert( DB.MatrixInfo('godunovMatrix', numberOfQuantities, numberOfQuantities, matrix=godunovMatrixSpp)) fluxSolverSpp = np.matlib.zeros((numberOfQuantities, numberOfQuantities)) fluxSolverSpp[0:numberOfElasticQuantities, :] = 1. db.insert( DB.MatrixInfo('fluxSolver', numberOfQuantities, numberOfQuantities, matrix=fluxSolverSpp)) godunovStateSpp = np.matlib.zeros((numberOfPoints, numberOfQuantities)) godunovStateSpp[:, 0:numberOfElasticQuantities] = 1. db.insert( DB.MatrixInfo('godunovState', numberOfPoints, numberOfQuantities, matrix=godunovStateSpp)) stiffnessOrder = {'Xi': 0, 'Eta': 1, 'Zeta': 2} globalMatrixIdRules = [(r'^pP(\d{1})$', lambda x: (int(x[0]) - 1) * 4), (r'^pM(\d{1})(\d{1})$', lambda x: (int(x[0]) - 1) * 4 + int(x[1])), (r'^nP(\d{1})$', lambda x: 16 + (int(x[0]) - 1) * 4), (r'^nM(\d{1})(\d{1})$', lambda x: 16 + (int(x[0]) - 1) * 4 + int(x[1]))] DB.determineGlobalMatrixIds(globalMatrixIdRules, db, 'dr')
def getGlobalMatrices(order, arch): architecture = Arch.getArchitectureByIdentifier(arch) configs = { 'kXiDivM': [ True ], 'kEtaDivM': [ True ], 'kZetaDivM': [ True ], 'kXiDivMT': [ True ], 'kEtaDivMT': [ True ], 'kZetaDivMT': [ True ], 'fM1': [ True ], 'fM2': [ True ], 'fP111': [ True ], 'fP112': [ True ], 'fP113': [ True ], 'fP121': [ True ], 'fP211': [ True ], 'fP222': [ True ] } stiffnessMatrices = ['kXiDivM', 'kEtaDivM', 'kZetaDivM'] transposedStiffnessBlocks = list() for o in range(2, order+1): stoprow = Tools.alignedNumberOfBasisFunctions(o-1, architecture) startcol = Tools.numberOfBasisFunctions(o-1) stopcol = Tools.numberOfBasisFunctions(o) transposedStiffnessBlocks.append((0, stoprow, startcol, stopcol)) if len(transposedStiffnessBlocks) >= 2: # merge first two blocks block1 = transposedStiffnessBlocks.pop(0) block2 = transposedStiffnessBlocks.pop(0) mergedBlock = ( min(block1[0], block2[0]), max(block1[1], block2[1]), min(block1[2], block2[2]), max(block1[3], block2[3]) ) transposedStiffnessBlocks.insert(0, mergedBlock) stiffnessBlocks = [(block[2], block[3], block[0], block[1]) for block in transposedStiffnessBlocks] noMemsetStiffnessBlocks = list() for i, block in enumerate(stiffnessBlocks): startrow = noMemsetStiffnessBlocks[i-1][1] if i > 0 else block[0] stoprow = architecture.getAlignedIndex(block[1]) noMemsetStiffnessBlocks.append( (startrow, stoprow, block[2], block[3]) ) for matrix in stiffnessMatrices: configs[matrix].append(stiffnessBlocks) configs[matrix].append(noMemsetStiffnessBlocks) configs[matrix + 'T'].append(transposedStiffnessBlocks) return configs
def getGlobalMatrices(order, arch): architecture = Arch.getArchitectureByIdentifier(arch) configs = { 'kXiDivM': [True], 'kEtaDivM': [True], 'kZetaDivM': [True], 'kXiDivMT': [True], 'kEtaDivMT': [True], 'kZetaDivMT': [True], 'fM1': [True], 'fM2': [True], 'fP111': [True], 'fP112': [True], 'fP113': [True], 'fP121': [True], 'fP211': [True], 'fP222': [True] } stiffnessMatrices = ['kXiDivM', 'kEtaDivM', 'kZetaDivM'] transposedStiffnessBlocks = list() for o in range(2, order + 1): stoprow = Tools.alignedNumberOfBasisFunctions(o - 1, architecture) startcol = Tools.numberOfBasisFunctions(o - 1) stopcol = Tools.numberOfBasisFunctions(o) transposedStiffnessBlocks.append((0, stoprow, startcol, stopcol)) if len(transposedStiffnessBlocks) >= 2: # merge first two blocks block1 = transposedStiffnessBlocks.pop(0) block2 = transposedStiffnessBlocks.pop(0) mergedBlock = (min(block1[0], block2[0]), max(block1[1], block2[1]), min(block1[2], block2[2]), max(block1[3], block2[3])) transposedStiffnessBlocks.insert(0, mergedBlock) stiffnessBlocks = [(block[2], block[3], block[0], block[1]) for block in transposedStiffnessBlocks] noMemsetStiffnessBlocks = list() for i, block in enumerate(stiffnessBlocks): startrow = noMemsetStiffnessBlocks[i - 1][1] if i > 0 else block[0] stoprow = architecture.getAlignedIndex(block[1]) noMemsetStiffnessBlocks.append((startrow, stoprow, block[2], block[3])) for matrix in stiffnessMatrices: configs[matrix].append(stiffnessBlocks) configs[matrix].append(noMemsetStiffnessBlocks) configs[matrix + 'T'].append(transposedStiffnessBlocks) return configs
def addMatrices(db, matricesDir, PlasticityMethod, order): numberOfBasisFunctions = Tools.numberOfBasisFunctions(order) clones = dict() # Load matrices db.update(Tools.parseMatrixFile('{}/plasticity_{}_matrices_{}.xml'.format(matricesDir, PlasticityMethod, order), clones)) # force Aligned in order to be compatible with regular DOFs. db.insert(DB.MatrixInfo('stressDOFS', numberOfBasisFunctions, 6, forceAligned=True)) matrixOrder = { 'v': 0, 'vInv': 1 } globalMatrixIdRules = [ (r'^(v|vInv)$', lambda x: matrixOrder[x[0]]) ] DB.determineGlobalMatrixIds(globalMatrixIdRules, db, 'plasticity')
def addMatrices(db, order): numberOfBasisFunctions = Tools.numberOfBasisFunctions(order) for depth in range(0, maxDepth + 1): numberOfSubTriangles = 4**depth db.insert( DB.MatrixInfo('subTriangleProjectionMatrix{}'.format(depth), numberOfSubTriangles, numberOfBasisFunctions, forceAligned=True)) db.insert( DB.MatrixInfo('velocityDOFS', numberOfBasisFunctions, 3, forceAligned=True))
def getGlobalMatrices(order, arch): architecture = Arch.getArchitectureByIdentifier(arch) stiffnessMatrices = ['kXiDivM', 'kEtaDivM', 'kZetaDivM'] groups = {'stiffnessTransposed': map(lambda x: x + 'T', stiffnessMatrices)} if architecture.name in ['knc', 'knl']: blockMerge = 2 configs = { 'kXiDivM': [], 'kEtaDivM': [], 'kZetaDivM': [], 'stiffnessTransposed': [], 'fP1': [], 'fP2': [], 'fP3': [], 'r1DivM': [], 'r2DivM': [], 'r3DivM': [], 'r4DivM': [], 'rT1': [], 'rT2': [], 'rT3': [], 'rT4': [] } else: blockMerge = 1 configs = { 'kXiDivM': [True], 'kEtaDivM': [True], 'kZetaDivM': [True], 'stiffnessTransposed': [True], 'fP1': [True], 'fP2': [True], 'fP3': [True], 'r1DivM': [True], 'r2DivM': [True], 'r3DivM': [True], 'r4DivM': [True], 'rT1': [True], 'rT2': [True], 'rT3': [True], 'rT4': [True] } transposedStiffnessBlocks = list() for o in range(2, order + 1): stoprow = Tools.numberOfBasisFunctions(o - 1) startcol = Tools.numberOfBasisFunctions(o - 1) stopcol = Tools.numberOfBasisFunctions(o) transposedStiffnessBlocks.append((0, stoprow, startcol, stopcol)) for i in range(blockMerge): if len(transposedStiffnessBlocks) >= 2: # merge first blocks block1 = transposedStiffnessBlocks.pop(0) block2 = transposedStiffnessBlocks.pop(0) transposedStiffnessBlocks.insert(0, mergeBlock(block1, block2)) stiffnessBlocks = [(block[2], block[3], block[0], block[1]) for block in transposedStiffnessBlocks] noMemsetStiffnessBlocks = list() for i, block in enumerate(stiffnessBlocks): startrow = noMemsetStiffnessBlocks[i - 1][1] if i > 0 else block[0] stoprow = architecture.getAlignedIndex( block[1]) if i != len(stiffnessBlocks) - 1 else block[1] noMemsetStiffnessBlocks.append((startrow, stoprow, block[2], block[3])) for matrix in stiffnessMatrices: configs[matrix].append(stiffnessBlocks) configs[matrix].append(noMemsetStiffnessBlocks) if groups.has_key('stiffnessTransposed'): configs['stiffnessTransposed'].append(transposedStiffnessBlocks) else: for matrix in stiffnessMatrices: configs[matrix + 'T'].append(transposedStiffnessBlocks) # fP matrices fPBlocks = list() for o in range(1, order + 1): start = Tools.numberOfBasisFunctions2D(o - 1) stop = Tools.numberOfBasisFunctions2D(o) fPBlocks.append((start, stop, start, stop)) # merge first three blocks for i in range(blockMerge + 1): if len(fPBlocks) >= 2: block1 = fPBlocks.pop(0) block2 = fPBlocks.pop(0) fPBlocks.insert(0, mergeBlock(block1, block2)) for i in range(1, 4): configs['fP{}'.format(i)].append(fPBlocks) # rT matrices rTBlocks = list() for o in range(1, order + 1): stoprow = Tools.numberOfBasisFunctions2D(o) startcol = Tools.numberOfBasisFunctions(o - 1) stopcol = Tools.numberOfBasisFunctions(o) rTBlocks.append((0, stoprow, startcol, stopcol)) # merge first three blocks for i in range(blockMerge + 1): if len(rTBlocks) >= 2: block1 = rTBlocks.pop(0) block2 = rTBlocks.pop(0) rTBlocks.insert(0, mergeBlock(block1, block2)) rBlocks = [(block[2], block[3], block[0], block[1]) for block in rTBlocks] noMemsetRBlocks = list() for i, block in enumerate(rBlocks): startrow = noMemsetRBlocks[i - 1][1] if i > 0 else block[0] stoprow = architecture.getAlignedIndex( block[1]) if i != len(rBlocks) - 1 else block[1] noMemsetRBlocks.append((startrow, stoprow, block[2], block[3])) for i in range(1, 5): configs['r{}DivM'.format(i)].append(rBlocks) configs['r{}DivM'.format(i)].append(noMemsetRBlocks) configs['rT{}'.format(i)].append(rTBlocks) # fMrT and rT have the same sparsity pattern for i in range(1, 5): configs['fMrT{}'.format(i)] = copy.deepcopy(configs['rT{}'.format(i)]) return (groups, configs)
cmdLineParser.add_argument('--matricesDir') cmdLineParser.add_argument('--outputDir') cmdLineParser.add_argument('--arch') cmdLineParser.add_argument('--order') cmdLineParser.add_argument('--numberOfMechanisms') cmdLineParser.add_argument('--generator') cmdLineParser.add_argument('--memLayout') cmdLineParser.add_argument('--dynamicRuptureMethod') cmdLineParser.add_argument('--PlasticityMethod') cmdLineArgs = cmdLineParser.parse_args() architecture = Arch.getArchitectureByIdentifier(cmdLineArgs.arch) libxsmmGenerator = cmdLineArgs.generator order = int(cmdLineArgs.order) numberOfMechanisms = int(cmdLineArgs.numberOfMechanisms) numberOfBasisFunctions = Tools.numberOfBasisFunctions(order) numberOfElasticQuantities = 9 numberOfMechanismQuantities = 6 numberOfReducedQuantities = numberOfElasticQuantities + numberOfMechanismQuantities numberOfQuantities = numberOfElasticQuantities + 6*numberOfMechanisms clones = { 'star': [ 'AstarT', 'BstarT', 'CstarT' ] } # Load matrices db = Tools.parseMatrixFile('{}/matrices_{}.xml'.format(cmdLineArgs.matricesDir, numberOfBasisFunctions), clones) db.update(Tools.parseMatrixFile('{}/matrices_viscoelastic.xml'.format(cmdLineArgs.matricesDir), clones)) # Determine sparsity patterns that depend on the number of mechanisms riemannSolverSpp = np.bmat([[np.matlib.ones((9, numberOfReducedQuantities), dtype=np.float64)], [np.matlib.zeros((numberOfReducedQuantities-9, numberOfReducedQuantities), dtype=np.float64)]])
cmdLineParser = argparse.ArgumentParser() cmdLineParser.add_argument('--matricesDir') cmdLineParser.add_argument('--outputDir') cmdLineParser.add_argument('--arch') cmdLineParser.add_argument('--order') cmdLineParser.add_argument('--numberOfMechanisms') cmdLineParser.add_argument('--generator') cmdLineParser.add_argument('--memLayout') cmdLineArgs = cmdLineParser.parse_args() architecture = Arch.getArchitectureByIdentifier(cmdLineArgs.arch) libxsmmGenerator = cmdLineArgs.generator order = int(cmdLineArgs.order) numberOfMechanisms = int(cmdLineArgs.numberOfMechanisms) numberOfBasisFunctions = Tools.numberOfBasisFunctions(order) numberOfQuantities = 9 + 6*numberOfMechanisms clones = { 'star': [ 'AstarT', 'BstarT', 'CstarT' ] } # Load matrices db = Tools.parseMatrixFile('{}/matrices_{}.xml'.format(cmdLineArgs.matricesDir, numberOfBasisFunctions), clones) db.update(Tools.parseMatrixFile('{}/matrices_viscoelastic.xml'.format(cmdLineArgs.matricesDir), clones)) # Determine sparsity patterns that depend on the number of mechanisms riemannSolverSpp = np.bmat([[np.matlib.ones((9, numberOfQuantities), dtype=np.float64)], [np.matlib.zeros((numberOfQuantities-9, numberOfQuantities), dtype=np.float64)]]) db.insert(DB.MatrixInfo('AplusT', numberOfQuantities, numberOfQuantities, sparsityPattern=riemannSolverSpp)) db.insert(DB.MatrixInfo('AminusT', numberOfQuantities, numberOfQuantities, sparsityPattern=riemannSolverSpp))