void SeparableScatterScalarResponse<PHAL::AlbanyTraits::MPJacobian, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
  // Here we scatter the *global* MP response
  Teuchos::RCP<Stokhos::ProductEpetraVector> g_mp = workset.mp_g;
  if (g_mp != Teuchos::null) {
    for (std::size_t res = 0; res < this->global_response.size(); res++) {
      typename PHAL::Ref<ScalarT>::type val = this->global_response[res];
      for (int block=0; block<g_mp->size(); block++)
        (*g_mp)[block][res] = val.val().coeff(block);
    }
  }

  // Here we scatter the *global* MP response derivatives
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdx_mp =
    workset.mp_dgdx;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdx_mp =
    workset.overlapped_mp_dgdx;
  if (dgdx_mp != Teuchos::null)
    for (int block=0; block<dgdx_mp->size(); block++)
      (*dgdx_mp)[block].Export((*overlapped_dgdx_mp)[block],
                               *workset.x_importer, Add);

  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdxdot_mp =
    workset.mp_dgdxdot;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdxdot_mp =
    workset.overlapped_mp_dgdxdot;
  if (dgdxdot_mp != Teuchos::null)
    for (int block=0; block<dgdxdot_mp->size(); block++)
      (*dgdxdot_mp)[block].Export((*overlapped_dgdxdot_mp)[block],
                                  *workset.x_importer, Add);
}
void FastSolutionTensorInterpolationBase<PHAL::AlbanyTraits::Jacobian, Traits, typename PHAL::AlbanyTraits::Jacobian::ScalarT>::
evaluateFields(typename Traits::EvalData workset)
{
  const int num_dof = this->val_node(0,0,0,0).size();
  const int neq = workset.wsElNodeEqID.dimension(2);
  const auto vecDim = this->vecDim;
  for (std::size_t cell=0; cell < workset.numCells; ++cell) {
    for (std::size_t qp=0; qp < this->numQPs; ++qp) {
      for (std::size_t i=0; i< vecDim; i++) {
        for (std::size_t j=0; j< vecDim; j++) {
          // Zero out for node==0; then += for node = 1 to numNodes
          typename PHAL::Ref<ScalarT>::type vqp = this->val_qp(cell,qp,i,j);

          vqp = this->val_node(cell, 0, i, j) * this->BF(cell, 0, qp);
          vqp = ScalarT(num_dof, this->val_node(cell, 0, i, j).val() * this->BF(cell, 0, qp));
          vqp.fastAccessDx(offset+i*vecDim+j) = this->val_node(cell, 0, i, j).fastAccessDx(offset+i*vecDim+j) * this->BF(cell, 0, qp);
          for (std::size_t node=1; node < this->numNodes; ++node) {
            vqp.val() += this->val_node(cell, node, i, j).val() * this->BF(cell, node, qp);
            vqp.fastAccessDx(neq*node+offset+i*this->vecDim+j)
              += this->val_node(cell, node, i, j).fastAccessDx(neq*node+offset+i*vecDim+j) * this->BF(cell, node, qp);
          }
        }
      }
    }
  }
}
void ScatterScalarResponse<PHAL::AlbanyTraits::Tangent, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
  // Here we scatter the *global* response and tangent
  //Teuchos::RCP<Epetra_Vector> g = workset.g;
  //Teuchos::RCP<Epetra_MultiVector> gx = workset.dgdx;
  //Teuchos::RCP<Epetra_MultiVector> gp = workset.dgdp;
  Teuchos::RCP<Tpetra_Vector> gT = workset.gT;
  Teuchos::RCP<Tpetra_MultiVector> gxT = workset.dgdxT;
  Teuchos::RCP<Tpetra_MultiVector> gpT = workset.dgdpT;
  for (PHAL::MDFieldIterator<ScalarT> gr(this->global_response);
       ! gr.done(); ++gr) {
    typename PHAL::Ref<ScalarT>::type val = *gr;
    const int res = gr.idx();
    if (gT != Teuchos::null){
      Teuchos::ArrayRCP<ST> gT_nonconstView = gT->get1dViewNonConst();
      gT_nonconstView[res] = val.val();
    }
    if (gxT != Teuchos::null)
      for (int col=0; col<workset.num_cols_x; col++)
	gxT->replaceLocalValue(res, col, val.dx(col));
    if (gpT != Teuchos::null)
      for (int col=0; col<workset.num_cols_p; col++)
	gpT->replaceLocalValue(res, col, val.dx(col+workset.param_offset));
  }
}
void SeparableScatterScalarResponse<PHAL::AlbanyTraits::Jacobian, Traits>::
evaluate2DFieldsDerivativesDueToExtrudedSolution(typename Traits::EvalData workset, std::string& sideset, Teuchos::RCP<const CellTopologyData> cellTopo)
{
  // Here we scatter the *local* response derivative
  Teuchos::RCP<Tpetra_MultiVector> dgdxT = workset.overlapped_dgdxT;
  Teuchos::RCP<Tpetra_MultiVector> dgdxdotT = workset.overlapped_dgdxdotT;
  Teuchos::RCP<Tpetra_MultiVector> dgT;
  if (dgdxT != Teuchos::null)
    dgT = dgdxT;
  else
    dgT = dgdxdotT;

  const int neq = workset.wsElNodeEqID[0][0].size();
  const Albany::NodalDOFManager& solDOFManager = workset.disc->getOverlapDOFManager("ordinary_solution");
  const Albany::LayeredMeshNumbering<LO>& layeredMeshNumbering = *workset.disc->getLayeredMeshNumbering();
  int numLayers = layeredMeshNumbering.numLayers;
  const Teuchos::ArrayRCP<Teuchos::ArrayRCP<GO> >& wsElNodeID  = workset.disc->getWsElNodeID()[workset.wsIndex];

  if (workset.sideSets == Teuchos::null)
      TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Side sets not properly specified on the mesh" << std::endl);

  const Albany::SideSetList& ssList = *(workset.sideSets);
  Albany::SideSetList::const_iterator it = ssList.find(sideset);

  if (it != ssList.end()) {
    const std::vector<Albany::SideStruct>& sideSet = it->second;

    for (std::size_t iSide = 0; iSide < sideSet.size(); ++iSide) { // loop over the sides on this ws and name
      // Get the data that corresponds to the side
      const int elem_GID = sideSet[iSide].elem_GID;
      const int elem_LID = sideSet[iSide].elem_LID;
      const int elem_side = sideSet[iSide].side_local_id;
      const CellTopologyData_Subcell& side =  cellTopo->side[elem_side];
      int numSideNodes = side.topology->node_count;

      const Teuchos::ArrayRCP<GO>& elNodeID = wsElNodeID[elem_LID];
      for (std::size_t res = 0; res < this->global_response.size(); res++) {
        typename PHAL::Ref<ScalarT>::type val = this->local_response(elem_LID, res);
        LO base_id, ilayer;
        for (int i = 0; i < numSideNodes; ++i) {
          std::size_t node = side.node[i];
          LO lnodeId = workset.disc->getOverlapNodeMapT()->getLocalElement(elNodeID[node]);
          layeredMeshNumbering.getIndices(lnodeId, base_id, ilayer);
          for (unsigned int il_col=0; il_col<numLayers+1; il_col++) {
            LO inode = layeredMeshNumbering.getId(base_id, il_col);
            for (unsigned int eq_col=0; eq_col<neq; eq_col++) {
              LO dof = solDOFManager.getLocalDOF(inode, eq_col);
              int deriv = neq *this->numNodes+il_col*neq*numSideNodes + neq*i + eq_col;
              dgT->sumIntoLocalValue(dof, res, val.dx(deriv));
            }
          }
        }
      }
    }
  }
}
void SeparableScatterScalarResponse<PHAL::AlbanyTraits::MPJacobian, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  // Here we scatter the *local* MP response derivative
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdx_mp =
    workset.overlapped_mp_dgdx;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdxdot_mp =
    workset.overlapped_mp_dgdxdot;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dg_mp;
  if (dgdx_mp != Teuchos::null)
    dg_mp = dgdx_mp;
  else
    dg_mp = dgdxdot_mp;

  // Loop over cells in workset
  for (std::size_t cell=0; cell < workset.numCells; ++cell) {
    const Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> >& nodeID =
      workset.wsElNodeEqID[cell];

    // Loop over responses
    for (std::size_t res = 0; res < this->global_response.size(); res++) {
      typename PHAL::Ref<ScalarT>::type val = this->local_response(cell, res);

      // Loop over nodes in cell
      for (unsigned int node_dof=0; node_dof<numNodes; node_dof++) {
        int neq = nodeID[node_dof].size();

        // Loop over equations per node
        for (unsigned int eq_dof=0; eq_dof<neq; eq_dof++) {

          // local derivative component
          int deriv = neq * node_dof + eq_dof;

          // local DOF
          int dof = nodeID[node_dof][eq_dof];

          // Set dg/dx
          for (int block=0; block<dg_mp->size(); block++)
            (*dg_mp)[block].SumIntoMyValue(dof, res,
                                           val.dx(deriv).coeff(block));

        } // column equations
      } // response
    } // node
  } // cell
}
void SeparableScatterScalarResponse<PHAL::AlbanyTraits::Jacobian, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  // Here we scatter the *local* response derivative
  Teuchos::RCP<Tpetra_MultiVector> dgdxT = workset.overlapped_dgdxT;
  Teuchos::RCP<Tpetra_MultiVector> dgdxdotT = workset.overlapped_dgdxdotT;
  Teuchos::RCP<Tpetra_MultiVector> dgT;
  if (dgdxT != Teuchos::null)
    dgT = dgdxT;
  else
    dgT = dgdxdotT;

  // Loop over cells in workset
  for (std::size_t cell=0; cell < workset.numCells; ++cell) {
    const Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> >& nodeID =
      workset.wsElNodeEqID[cell];

    // Loop over responses

    for (std::size_t res = 0; res < this->global_response.size(); res++) {
      typename PHAL::Ref<ScalarT>::type val = this->local_response(cell, res);

      // Loop over nodes in cell
      for (unsigned int node_dof=0; node_dof<numNodes; node_dof++) {
        int neq = nodeID[node_dof].size();

        // Loop over equations per node
        for (unsigned int eq_dof=0; eq_dof<neq; eq_dof++) {

          // local derivative component
          int deriv = neq * node_dof + eq_dof;

          // local DOF
          int dof = nodeID[node_dof][eq_dof];

          // Set dg/dx
          dgT->sumIntoLocalValue(dof, res, val.dx(deriv));

        } // column equations
      } // column nodes
    } // response

  } // cell
}
void ATO::TensorPNormResponseSpec<PHAL::AlbanyTraits::MPJacobian, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
  this->global_response[0] = pow(this->global_response[0],1.0/pVal);

  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdx_mp = workset.overlapped_mp_dgdx;
  if(overlapped_dgdx_mp != Teuchos::null){
    for(int block=0; block<overlapped_dgdx_mp->size(); block++){
      typename PHAL::Ref<ScalarT>::type gVal = this->global_response[0];
      double scale = pow(gVal.val().coeff(block),1.0/pVal-1.0)/pVal;
      (*overlapped_dgdx_mp)[block].Scale(scale);
    }
  }

  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdxdot_mp = workset.overlapped_mp_dgdxdot;
  if(overlapped_dgdxdot_mp != Teuchos::null){
    for(int block=0; block<overlapped_dgdxdot_mp->size(); block++){
      typename PHAL::Ref<ScalarT>::type gVal = this->global_response[0];
      double scale = pow(gVal.val().coeff(block),1.0/pVal-1.0)/pVal;
      (*overlapped_dgdxdot_mp)[block].Scale(scale);
    }
  }
}
Ejemplo n.º 8
0
void GatherExtruded2DField<PHAL::AlbanyTraits::Jacobian, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  Teuchos::RCP<const Tpetra_Vector> xT = workset.xT;
  Teuchos::ArrayRCP<const ST> xT_constView = xT->get1dView();

  Kokkos::deep_copy(this->field2D.get_kokkos_view(), ScalarT(0.0));

  const Albany::LayeredMeshNumbering<LO>& layeredMeshNumbering = *workset.disc->getLayeredMeshNumbering();
  const Albany::NodalDOFManager& solDOFManager = workset.disc->getOverlapDOFManager("ordinary_solution");

  int numLayers = layeredMeshNumbering.numLayers;
  this->fieldLevel = (this->fieldLevel < 0) ? numLayers : this->fieldLevel;
  const Teuchos::ArrayRCP<Teuchos::ArrayRCP<GO> >& wsElNodeID  = workset.disc->getWsElNodeID()[workset.wsIndex];


  for (std::size_t cell=0; cell < workset.numCells; ++cell ) {
    const Teuchos::ArrayRCP<GO>& elNodeID = wsElNodeID[cell];
    const Teuchos::ArrayRCP<Teuchos::ArrayRCP<int> >& nodeID  = workset.wsElNodeEqID[cell];
    const int neq = nodeID[0].size();
    const std::size_t num_dof = neq * this->numNodes;

    for (std::size_t node = 0; node < this->numNodes; ++node) {
      int firstunk = neq * node + this->offset;
      LO lnodeId = workset.disc->getOverlapNodeMapT()->getLocalElement(elNodeID[node]);
      LO base_id, ilayer;
      layeredMeshNumbering.getIndices(lnodeId, base_id, ilayer);
      LO inode = layeredMeshNumbering.getId(base_id, this->fieldLevel);
      typename PHAL::Ref<ScalarT>::type val = (this->field2D)(cell,node);

      val = FadType(neq * this->numNodes, xT_constView[solDOFManager.getLocalDOF(inode, this->offset)]);
      val.setUpdateValue(!workset.ignore_residual);
      val.fastAccessDx(firstunk) = workset.j_coeff;
    }
  }
}
void
QCAD::FieldValueScatterScalarResponse<PHAL::AlbanyTraits::MPJacobian, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
  // Here we scatter the *global* MP response
  Teuchos::RCP<Stokhos::ProductEpetraVector> g_mp = workset.mp_g;
  if (g_mp != Teuchos::null) {
    for (int res = 0; res < this->field_components.size(); res++) {
      typename PHAL::Ref<ScalarT>::type val = this->global_response(this->field_components[res]);
      for (int block=0; block<g_mp->size(); block++)
        (*g_mp)[block][res] = val.val().coeff(block);
    }
  }

  // Here we scatter the *global* MP response derivatives
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdx_mp =
    workset.mp_dgdx;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dgdxdot_mp =
    workset.mp_dgdxdot;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdx_mp =
    workset.overlapped_mp_dgdx;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> overlapped_dgdxdot_mp =
    workset.overlapped_mp_dgdxdot;
  Teuchos::RCP<Stokhos::ProductEpetraMultiVector> dg_mp, overlapped_dg_mp;
  if (dgdx_mp != Teuchos::null) {
    dg_mp = dgdx_mp;
    overlapped_dg_mp = overlapped_dgdx_mp;
  }
  else {
    dg_mp = dgdxdot_mp;
    overlapped_dg_mp = overlapped_dgdxdot_mp;
  }

  dg_mp->init(0.0);
  overlapped_dg_mp->init(0.0);

  // Extract derivatives for the cell corresponding to nodeID
  if (nodeID != Teuchos::null) {

    // Loop over responses
    for (int res = 0; res < this->field_components.size(); res++) {
      typename PHAL::Ref<ScalarT>::type val = this->global_response(this->field_components[res]);

      // Loop over nodes in cell
      for (int node_dof=0; node_dof<numNodes; node_dof++) {
        int neq = nodeID[node_dof].size();

        // Loop over equations per node
        for (int eq_dof=0; eq_dof<neq; eq_dof++) {

          // local derivative component
          int deriv = neq * node_dof + eq_dof;

          // local DOF
          int dof = nodeID[node_dof][eq_dof];

          // Set dg/dx
          for (int block=0; block<dg_mp->size(); block++)
            (*overlapped_dg_mp)[block].ReplaceMyValue(dof, res,
                                                      val.dx(deriv).coeff(block));

        } // column equations
      } // response
    } // node
  } // cell belongs to this proc

  for (int block=0; block<dgdx_mp->size(); block++)
    (*dg_mp)[block].Export((*overlapped_dg_mp)[block],
                           *workset.x_importer, Add);
}