class ADERDGBase(ABC): def __init__(self, order, multipleSimulations, matricesDir): self.order = order self.alignStride = lambda name: True if multipleSimulations > 1: self.alignStride = lambda name: name.startswith('fP') transpose = multipleSimulations > 1 self.transpose = lambda name: transpose self.t = (lambda x: x[::-1]) if transpose else (lambda x: x) self.db = parseXMLMatrixFile('{}/matrices_{}.xml'.format( matricesDir, self.numberOf3DBasisFunctions()), transpose=self.transpose, alignStride=self.alignStride) clonesQP = {'v': ['evalAtQP'], 'vInv': ['projectQP']} self.db.update( parseXMLMatrixFile('{}/plasticity_ip_matrices_{}.xml'.format( matricesDir, order), clonesQP, transpose=self.transpose, alignStride=self.alignStride)) qShape = (self.numberOf3DBasisFunctions(), self.numberOfQuantities()) self.Q = OptionalDimTensor('Q', 's', multipleSimulations, 0, qShape, alignStride=True) self.I = OptionalDimTensor('I', 's', multipleSimulations, 0, qShape, alignStride=True) Aplusminus_spp = self.flux_solver_spp() self.AplusT = Tensor('AplusT', Aplusminus_spp.shape, spp=Aplusminus_spp) self.AminusT = Tensor('AminusT', Aplusminus_spp.shape, spp=Aplusminus_spp) Tshape = (self.numberOfExtendedQuantities(), self.numberOfExtendedQuantities()) trans_spp = self.transformation_spp() self.T = Tensor('T', trans_spp.shape, spp=trans_spp) trans_inv_spp = self.transformation_inv_spp() self.Tinv = Tensor('Tinv', trans_inv_spp.shape, spp=trans_inv_spp) godunov_spp = self.godunov_spp() self.QgodLocal = Tensor('QgodLocal', godunov_spp.shape, spp=godunov_spp) self.QgodNeighbor = Tensor('QgodNeighbor', godunov_spp.shape, spp=godunov_spp) self.oneSimToMultSim = Tensor('oneSimToMultSim', (self.Q.optSize(), ), spp={(i, ): '1.0' for i in range(self.Q.optSize())}) def numberOf2DBasisFunctions(self): return self.order * (self.order + 1) // 2 def numberOf3DBasisFunctions(self): return self.order * (self.order + 1) * (self.order + 2) // 6 def numberOf3DQuadraturePoints(self): return (self.order + 1)**3 def godunov_spp(self): shape = (self.numberOfQuantities(), self.numberOfQuantities()) return np.ones(shape, dtype=bool) def flux_solver_spp(self): shape = (self.numberOfQuantities(), self.numberOfExtendedQuantities()) return np.ones(shape, dtype=bool) def transformation_spp(self): shape = (self.numberOfExtendedQuantities(), self.numberOfExtendedQuantities()) return np.ones(shape, dtype=bool) def transformation_inv_spp(self): return self.godunov_spp() @abstractmethod def numberOfQuantities(self): pass @abstractmethod def numberOfExtendedQuantities(self): pass @abstractmethod def extendedQTensor(self): pass @abstractmethod def starMatrix(self, dim): pass def addInit(self, generator): fluxScale = Scalar('fluxScale') computeFluxSolverLocal = self.AplusT['ij'] <= fluxScale * self.Tinv[ 'ki'] * self.QgodLocal['kq'] * self.starMatrix( 0)['ql'] * self.T['jl'] generator.add('computeFluxSolverLocal', computeFluxSolverLocal) computeFluxSolverNeighbor = self.AminusT[ 'ij'] <= fluxScale * self.Tinv['ki'] * self.QgodNeighbor[ 'kq'] * self.starMatrix(0)['ql'] * self.T['jl'] generator.add('computeFluxSolverNeighbor', computeFluxSolverNeighbor) QFortran = Tensor( 'QFortran', (self.numberOf3DBasisFunctions(), self.numberOfQuantities())) multSimToFirstSim = Tensor('multSimToFirstSim', (self.Q.optSize(), ), spp={(0, ): '1.0'}) if self.Q.hasOptDim(): copyQToQFortran = QFortran[ 'kp'] <= self.Q['kp'] * multSimToFirstSim['s'] else: copyQToQFortran = QFortran['kp'] <= self.Q['kp'] generator.add('copyQToQFortran', copyQToQFortran) @abstractmethod def addLocal(self, generator): pass @abstractmethod def addNeighbor(self, generator): pass @abstractmethod def addTime(self, generator): pass
class ADERDGBase(ABC): def __init__(self, order, multipleSimulations, matricesDir): self.order = order self.alignStride = lambda name: True if multipleSimulations > 1: self.alignStride = lambda name: name.startswith('fP') transpose = multipleSimulations > 1 self.transpose = lambda name: transpose self.t = (lambda x: x[::-1]) if transpose else (lambda x: x) self.db = parseXMLMatrixFile('{}/matrices_{}.xml'.format( matricesDir, self.numberOf3DBasisFunctions()), transpose=self.transpose, alignStride=self.alignStride) clonesQP = {'v': ['evalAtQP'], 'vInv': ['projectQP']} self.db.update( parseXMLMatrixFile('{}/plasticity_ip_matrices_{}.xml'.format( matricesDir, order), clonesQP, transpose=self.transpose, alignStride=self.alignStride)) self.db.update( parseJSONMatrixFile( '{}/sampling_directions.json'.format(matricesDir))) self.db.update( parseJSONMatrixFile('{}/mass_{}.json'.format(matricesDir, order))) qShape = (self.numberOf3DBasisFunctions(), self.numberOfQuantities()) self.Q = OptionalDimTensor('Q', 's', multipleSimulations, 0, qShape, alignStride=True) self.I = OptionalDimTensor('I', 's', multipleSimulations, 0, qShape, alignStride=True) Aplusminus_spp = self.flux_solver_spp() self.AplusT = Tensor('AplusT', Aplusminus_spp.shape, spp=Aplusminus_spp) self.AminusT = Tensor('AminusT', Aplusminus_spp.shape, spp=Aplusminus_spp) Tshape = (self.numberOfExtendedQuantities(), self.numberOfExtendedQuantities()) trans_spp = self.transformation_spp() self.T = Tensor('T', trans_spp.shape, spp=trans_spp) trans_inv_spp = self.transformation_inv_spp() self.Tinv = Tensor('Tinv', trans_inv_spp.shape, spp=trans_inv_spp) godunov_spp = self.godunov_spp() self.QgodLocal = Tensor('QgodLocal', godunov_spp.shape, spp=godunov_spp) self.QgodNeighbor = Tensor('QgodNeighbor', godunov_spp.shape, spp=godunov_spp) self.oneSimToMultSim = Tensor('oneSimToMultSim', (self.Q.optSize(), ), spp={(i, ): '1.0' for i in range(self.Q.optSize())}) self.db.update( parseJSONMatrixFile( '{}/nodal/nodalBoundary_matrices_{}.json'.format( matricesDir, self.order), {}, alignStride=self.alignStride, transpose=self.transpose, namespace='nodal')) self.INodal = OptionalDimTensor( 'INodal', 's', False, #multipleSimulations, 0, (self.numberOf2DBasisFunctions(), self.numberOfQuantities()), alignStride=True) project2nFaceTo3m = tensor_collection_from_constant_expression( base_name='project2nFaceTo3m', expressions=lambda i: self.db.rDivM[i]['jk'] * self.db.V2nTo2m['kl' ], group_indices=range(4), target_indices='jl') self.db.update(project2nFaceTo3m) def numberOf2DBasisFunctions(self): return self.order * (self.order + 1) // 2 def numberOf3DBasisFunctions(self): return self.order * (self.order + 1) * (self.order + 2) // 6 def numberOf3DQuadraturePoints(self): return (self.order + 1)**3 def godunov_spp(self): shape = (self.numberOfQuantities(), self.numberOfQuantities()) return np.ones(shape, dtype=bool) def flux_solver_spp(self): shape = (self.numberOfQuantities(), self.numberOfExtendedQuantities()) return np.ones(shape, dtype=bool) def transformation_spp(self): shape = (self.numberOfExtendedQuantities(), self.numberOfExtendedQuantities()) return np.ones(shape, dtype=bool) def transformation_inv_spp(self): return self.godunov_spp() @abstractmethod def numberOfQuantities(self): pass @abstractmethod def numberOfExtendedQuantities(self): pass @abstractmethod def extendedQTensor(self): pass @abstractmethod def starMatrix(self, dim): pass def addInit(self, generator): fluxScale = Scalar('fluxScale') computeFluxSolverLocal = self.AplusT['ij'] <= fluxScale * self.Tinv[ 'ki'] * self.QgodLocal['kq'] * self.starMatrix( 0)['ql'] * self.T['jl'] generator.add('computeFluxSolverLocal', computeFluxSolverLocal) computeFluxSolverNeighbor = self.AminusT[ 'ij'] <= fluxScale * self.Tinv['ki'] * self.QgodNeighbor[ 'kq'] * self.starMatrix(0)['ql'] * self.T['jl'] generator.add('computeFluxSolverNeighbor', computeFluxSolverNeighbor) QFortran = Tensor( 'QFortran', (self.numberOf3DBasisFunctions(), self.numberOfQuantities())) multSimToFirstSim = Tensor('multSimToFirstSim', (self.Q.optSize(), ), spp={(0, ): '1.0'}) if self.Q.hasOptDim(): copyQToQFortran = QFortran[ 'kp'] <= self.Q['kp'] * multSimToFirstSim['s'] else: copyQToQFortran = QFortran['kp'] <= self.Q['kp'] generator.add('copyQToQFortran', copyQToQFortran) stiffnessTensor = Tensor('stiffnessTensor', (3, 3, 3, 3)) direction = Tensor('direction', (3, )) christoffel = Tensor('christoffel', (3, 3)) computeChristoffel = christoffel[ 'ik'] <= stiffnessTensor['ijkl'] * direction['j'] * direction['l'] generator.add('computeChristoffel', computeChristoffel) @abstractmethod def addLocal(self, generator, targets): pass @abstractmethod def addNeighbor(self, generator, targets): pass @abstractmethod def addTime(self, generator, targets): pass def add_include_tensors(self, include_tensors): include_tensors.add(self.db.samplingDirections) include_tensors.add(self.db.M2inv)
class ADERDGBase(ABC): def __init__(self, order, multipleSimulations, matricesDir): self.order = order self.alignStride = lambda name: True if multipleSimulations > 1: self.alignStride = lambda name: name.startswith('fP') transpose = multipleSimulations > 1 self.transpose = lambda name: transpose self.t = (lambda x: x[::-1]) if transpose else (lambda x: x) self.db = parseXMLMatrixFile('{}/matrices_{}.xml'.format(matricesDir, self.numberOf3DBasisFunctions()), transpose=self.transpose, alignStride=self.alignStride) clonesQP = { 'v': [ 'evalAtQP' ], 'vInv': [ 'projectQP' ] } self.db.update( parseXMLMatrixFile('{}/plasticity_ip_matrices_{}.xml'.format(matricesDir, order), clonesQP, transpose=self.transpose, alignStride=self.alignStride)) qShape = (self.numberOf3DBasisFunctions(), self.numberOfQuantities()) self.Q = OptionalDimTensor('Q', 's', multipleSimulations, 0, qShape, alignStride=True) self.I = OptionalDimTensor('I', 's', multipleSimulations, 0, qShape, alignStride=True) Ashape = (self.numberOfQuantities(), self.numberOfExtendedQuantities()) self.AplusT = Tensor('AplusT', Ashape) self.AminusT = Tensor('AminusT', Ashape) Tshape = (self.numberOfExtendedQuantities(), self.numberOfExtendedQuantities()) self.T = Tensor('T', Tshape) QgodShape = (self.numberOfQuantities(), self.numberOfQuantities()) self.Tinv = Tensor('Tinv', QgodShape) self.QgodLocal = Tensor('QgodLocal', QgodShape) self.QgodNeighbor = Tensor('QgodNeighbor', QgodShape) self.oneSimToMultSim = Tensor('oneSimToMultSim', (self.Q.optSize(),), spp={(i,): '1.0' for i in range(self.Q.optSize())}) def numberOf2DBasisFunctions(self): return self.order*(self.order+1)//2 def numberOf3DBasisFunctions(self): return self.order*(self.order+1)*(self.order+2)//6 def numberOf3DQuadraturePoints(self): return (self.order+1)**3 @abstractmethod def numberOfQuantities(self): pass @abstractmethod def numberOfExtendedQuantities(self): pass @abstractmethod def extendedQTensor(self): pass @abstractmethod def starMatrix(self, dim): pass def addInit(self, generator): fluxScale = Scalar('fluxScale') computeFluxSolverLocal = self.AplusT['ij'] <= fluxScale * self.Tinv['ki'] * self.QgodLocal['kq'] * self.db.star[0]['ql'] * self.T['jl'] generator.add('computeFluxSolverLocal', computeFluxSolverLocal) computeFluxSolverNeighbor = self.AminusT['ij'] <= fluxScale * self.Tinv['ki'] * self.QgodNeighbor['kq'] * self.db.star[0]['ql'] * self.T['jl'] generator.add('computeFluxSolverNeighbor', computeFluxSolverNeighbor) QFortran = Tensor('QFortran', (self.numberOf3DBasisFunctions(), self.numberOfQuantities())) multSimToFirstSim = Tensor('multSimToFirstSim', (self.Q.optSize(),), spp={(0,): '1.0'}) if self.Q.hasOptDim(): copyQToQFortran = QFortran['kp'] <= self.Q['kp'] * multSimToFirstSim['s'] else: copyQToQFortran = QFortran['kp'] <= self.Q['kp'] generator.add('copyQToQFortran', copyQToQFortran) @abstractmethod def addLocal(self, generator): pass @abstractmethod def addNeighbor(self, generator): pass @abstractmethod def addTime(self, generator): pass