示例#1
0
    def __init__(self, order, multipleSimulations, matricesDir, memLayout,
                 numberOfMechanisms, **kwargs):

        super().__init__(order, multipleSimulations, matricesDir)
        clones = {
            'star': ['star(0)', 'star(1)', 'star(2)'],
        }
        self.db.update(
            parseXMLMatrixFile(
                '{}/matrices_poroelastic.xml'.format(matricesDir), clones))
        self.db.update(
            parseJSONMatrixFile('{}/stp_{}.json'.format(matricesDir, order),
                                clones))

        memoryLayoutFromFile(memLayout, self.db, clones)
示例#2
0
def addKernels(generator, aderdg, matricesDir, dynamicRuptureMethod):
  if dynamicRuptureMethod == 'quadrature':
    numberOfPoints = (aderdg.order+1)**2
  elif dynamicRuptureMethod == 'cellaverage':
    numberOfPoints = int(4**math.ceil(math.log(aderdg.order*(aderdg.order+1)/2,4)))
  else:
    raise ValueError('Unknown dynamic rupture method.')

  clones = dict()

  # Load matrices
  db = parseJSONMatrixFile('{}/dr_{}_matrices_{}.json'.format(matricesDir, dynamicRuptureMethod, aderdg.order), clones, alignStride=aderdg.alignStride, transpose=aderdg.transpose)

  # Determine matrices
  # Note: This does only work because the flux does not depend on the mechanisms in the case of viscoelastic attenuation
  godShape = (aderdg.numberOfQuantities(), aderdg.numberOfQuantities())
  godunovMatrix = Tensor('godunovMatrix', godShape)
  fluxSolverShape = (aderdg.numberOfQuantities(), aderdg.numberOfExtendedQuantities())
  fluxSolver    = Tensor('fluxSolver', fluxSolverShape)
  
  gShape = (numberOfPoints, aderdg.numberOfQuantities())
  godunovState = OptionalDimTensor('godunovState', aderdg.Q.optName(), aderdg.Q.optSize(), aderdg.Q.optPos(), gShape, alignStride=True)

  generator.add('rotateGodunovStateLocal', godunovMatrix['qp'] <= aderdg.Tinv['kq'] * aderdg.QgodLocal['kp'])
  generator.add('rotateGodunovStateNeighbor', godunovMatrix['qp'] <= aderdg.Tinv['kq'] * aderdg.QgodNeighbor['kp'])

  fluxScale = Scalar('fluxScale')
  generator.add('rotateFluxMatrix', fluxSolver['qp'] <= fluxScale * aderdg.starMatrix(0)['qk'] * aderdg.T['pk'])

  def godunovStateGenerator(i,h):
    target = godunovState['kp']
    term = db.V3mTo2n[i,h][aderdg.t('kl')] * aderdg.Q['lq'] * godunovMatrix['qp']
    if h == 0:
      return target <= term
    return target <= target + term
  godunovStatePrefetch = lambda i,h: godunovState
  generator.addFamily('godunovState', simpleParameterSpace(4,4), godunovStateGenerator, godunovStatePrefetch)

  nodalFluxGenerator = lambda i,h: aderdg.extendedQTensor()['kp'] <= aderdg.extendedQTensor()['kp'] + db.V3mTo2nTWDivM[i,h][aderdg.t('kl')] * godunovState['lq'] * fluxSolver['qp']
  nodalFluxPrefetch = lambda i,h: aderdg.I
  generator.addFamily('nodalFlux', simpleParameterSpace(4,4), nodalFluxGenerator, nodalFluxPrefetch)
示例#3
0
  def __init__(self, order, multipleSimulations, matricesDir, memLayout, numberOfMechanisms, **kwargs):
    super().__init__(order, multipleSimulations, matricesDir)

    self.numberOfMechanisms = numberOfMechanisms

    clones = {
      'star': ['star(0)', 'star(1)', 'star(2)'],
    }
    self.db.update( parseXMLMatrixFile('{}/matrices_viscoelastic.xml'.format(matricesDir), clones) )
    memoryLayoutFromFile(memLayout, self.db, clones)

    self._qShapeExtended = (self.numberOf3DBasisFunctions(), self.numberOfExtendedQuantities())
    self._qShapeAnelastic = (self.numberOf3DBasisFunctions(), self.numberOfAnelasticQuantities(), self.numberOfMechanisms)
    self.Qext = OptionalDimTensor('Qext', self.Q.optName(), self.Q.optSize(), self.Q.optPos(), self._qShapeExtended, alignStride=True)
    self.Qane = OptionalDimTensor('Qane', self.Q.optName(), self.Q.optSize(), self.Q.optPos(), self._qShapeAnelastic, alignStride=True)
    self.Iane = OptionalDimTensor('Iane', self.Q.optName(), self.Q.optSize(), self.Q.optPos(), self._qShapeAnelastic, alignStride=True)

    self.E = Tensor('E', (self.numberOfAnelasticQuantities(), self.numberOfMechanisms, self.numberOfQuantities()))
    self.w = Tensor('w', (self.numberOfMechanisms,))
    self.W = Tensor('W', (self.numberOfMechanisms, self.numberOfMechanisms), np.eye(self.numberOfMechanisms, dtype=bool), CSCMemoryLayout)

    selectElaSpp = np.zeros((self.numberOfExtendedQuantities(), self.numberOfQuantities()))
    selectElaSpp[0:self.numberOfQuantities(),0:self.numberOfQuantities()] = np.eye(self.numberOfQuantities())
    self.selectEla = Tensor('selectEla', (self.numberOfExtendedQuantities(), self.numberOfQuantities()), selectElaSpp, CSCMemoryLayout)

    selectAneSpp = np.zeros((self.numberOfExtendedQuantities(), self.numberOfAnelasticQuantities()))
    selectAneSpp[self.numberOfQuantities():self.numberOfExtendedQuantities(),0:self.numberOfAnelasticQuantities()] = np.eye(self.numberOfAnelasticQuantities())
    self.selectAne = Tensor('selectAne', (self.numberOfExtendedQuantities(), self.numberOfAnelasticQuantities()), selectAneSpp, CSCMemoryLayout)

    self.db.update(
      parseJSONMatrixFile('{}/nodal/nodalBoundary_matrices_{}.json'.format(matricesDir,
                                                                           self.order),
                          {},
                          alignStride=self.alignStride,
                          transpose=self.transpose,
                          namespace='nodal')
    )
示例#4
0
文件: acoustics.py 项目: TUM-I5/LinA
order = int(cmdLineArgs.order)
degree = order - 1
numberOf1DBasisFunctions = order
numberOfQuadraturePoints = order + 1
numberOfQuantities = 3

qShape = (numberOf1DBasisFunctions, numberOf1DBasisFunctions,
          numberOfQuantities)
qShape1 = (numberOf1DBasisFunctions, numberOfQuantities)

clones = {'kDivM': ['kDivM', 'kDivMT'], 'kTDivM': ['kTDivM', 'kTDivMT']}
transpose = {'kDivMT', 'kTDivMT'}
alignStride = {'kDivM', 'kTDivM'}
db = parseJSONMatrixFile('{}/matrices_{}.json'.format(cmdLineArgs.matricesDir,
                                                      degree),
                         clones,
                         transpose=transpose,
                         alignStride=alignStride)
db.update(parseJSONMatrixFile('{}/star.json'.format(cmdLineArgs.matricesDir)))
memoryLayoutFromFile(cmdLineArgs.memLayout, db, dict())

Q = Tensor('Q', qShape)
Q1 = Tensor('Q1', qShape1)
Q1Neighbour = Tensor('Q1Neighbour', qShape1)
dQ0 = Tensor('dQ(0)', qShape)
I = Tensor('I', qShape)
phi = [
    Tensor('phi({})'.format(i), (numberOf1DBasisFunctions, )) for i in range(2)
]
phiDivM = [
    Tensor('phiDivM({})'.format(i), (numberOf1DBasisFunctions, ))
示例#5
0
    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)
示例#6
0
def addKernels(generator, aderdg, matricesDir, dynamicRuptureMethod):
    if dynamicRuptureMethod == 'quadrature':
        numberOfPoints = (aderdg.order + 1)**2
    elif dynamicRuptureMethod == 'cellaverage':
        numberOfPoints = int(4**math.ceil(
            math.log(aderdg.order * (aderdg.order + 1) / 2, 4)))
    else:
        raise ValueError('Unknown dynamic rupture method.')

    clones = dict()

    # Load matrices
    db = parseJSONMatrixFile('{}/dr_{}_matrices_{}.json'.format(
        matricesDir, dynamicRuptureMethod, aderdg.order),
                             clones,
                             alignStride=aderdg.alignStride,
                             transpose=aderdg.transpose)
    db.update(
        parseJSONMatrixFile('{}/resample_{}.json'.format(
            matricesDir, aderdg.order)))

    # Determine matrices
    # Note: This does only work because the flux does not depend on the mechanisms in the case of viscoelastic attenuation
    trans_inv_spp_T = aderdg.transformation_inv_spp().transpose()
    TinvT = Tensor('TinvT', trans_inv_spp_T.shape, spp=trans_inv_spp_T)
    flux_solver_spp = aderdg.flux_solver_spp()
    fluxSolver = Tensor('fluxSolver',
                        flux_solver_spp.shape,
                        spp=flux_solver_spp)

    gShape = (numberOfPoints, aderdg.numberOfQuantities())
    QInterpolated = OptionalDimTensor('QInterpolated',
                                      aderdg.Q.optName(),
                                      aderdg.Q.optSize(),
                                      aderdg.Q.optPos(),
                                      gShape,
                                      alignStride=True)

    generator.add('transposeTinv', TinvT['ij'] <= aderdg.Tinv['ji'])

    fluxScale = Scalar('fluxScale')
    generator.add(
        'rotateFluxMatrix', fluxSolver['qp'] <=
        fluxScale * aderdg.starMatrix(0)['qk'] * aderdg.T['pk'])

    def interpolateQGenerator(i, h):
        return QInterpolated['kp'] <= db.V3mTo2n[i, h][aderdg.t(
            'kl')] * aderdg.Q['lq'] * TinvT['qp']

    interpolateQPrefetch = lambda i, h: QInterpolated
    generator.addFamily('evaluateAndRotateQAtInterpolationPoints',
                        simpleParameterSpace(4, 4), interpolateQGenerator,
                        interpolateQPrefetch)

    nodalFluxGenerator = lambda i, h: aderdg.extendedQTensor()[
        'kp'] <= aderdg.extendedQTensor()['kp'] + db.V3mTo2nTWDivM[i, h][
            aderdg.t('kl')] * QInterpolated['lq'] * fluxSolver['qp']
    nodalFluxPrefetch = lambda i, h: aderdg.I
    generator.addFamily('nodalFlux', simpleParameterSpace(4, 4),
                        nodalFluxGenerator, nodalFluxPrefetch)

    return {db.resample}