// quad tests
TEUCHOS_UNIT_TEST(tSquareQuadMeshDOFManager, buildTest_quad_edge_orientations2)
{

   // build global (or serial communicator)
   #ifdef HAVE_MPI
      stk::ParallelMachine Comm = MPI_COMM_WORLD;
   #else
      stk::ParallelMachine Comm = WHAT_TO_DO_COMM;
   #endif

   int numProcs = stk::parallel_machine_size(Comm);
   int myRank = stk::parallel_machine_rank(Comm);

   TEUCHOS_ASSERT(numProcs==2);

   // build a geometric pattern from a single basis
   RCP<const panzer::FieldPattern> patternI1 
         = buildFieldPattern<Intrepid2::Basis_HCURL_QUAD_I1_FEM<PHX::exec_space,double,double> >();

   RCP<panzer::ConnManager<int,int> > connManager = buildQuadMesh(Comm,2,2,1,1);
   RCP<panzer::DOFManagerFEI<int,int> > dofManager = rcp(new panzer::DOFManagerFEI<int,int>());

   dofManager->setOrientationsRequired(true);
   TEST_EQUALITY(dofManager->getOrientationsRequired(),true);
   TEST_EQUALITY(dofManager->getConnManager(),Teuchos::null);

   dofManager->setConnManager(connManager,MPI_COMM_WORLD);
   TEST_EQUALITY(dofManager->getConnManager(),connManager);

   dofManager->addField("b",patternI1);

   dofManager->buildGlobalUnknowns();
   dofManager->printFieldInformation(out);

   const std::vector<int> & b_offsets = dofManager->getGIDFieldOffsets("eblock-0_0",dofManager->getFieldNum("b"));

   TEST_EQUALITY(b_offsets.size(),4);

   // unfortunatly this mesh is completly uniform
   double standardO[] = { 1.0, 1.0, -1.0, -1.0 };
   if(myRank==0) {
      std::vector<double> orientation;

      // element 0
      dofManager->getElementOrientation(0,orientation);
      TEST_EQUALITY(orientation.size(),4);

      for(std::size_t i=0;i<4;i++)
         TEST_EQUALITY(orientation[i],standardO[i]);

      // element 1
      dofManager->getElementOrientation(1,orientation);
      TEST_EQUALITY(orientation.size(),4);

      for(std::size_t i=0;i<4;i++)
         TEST_EQUALITY(orientation[i],standardO[i]);
   }
   else if(myRank==1) {
      std::vector<double> orientation;

      // element 0
      dofManager->getElementOrientation(0,orientation);
      TEST_EQUALITY(orientation.size(),4);

      for(std::size_t i=0;i<4;i++)
         TEST_EQUALITY(orientation[i],standardO[i]);

      // element 1
      dofManager->getElementOrientation(1,orientation);
      TEST_EQUALITY(orientation.size(),4);

      for(std::size_t i=0;i<4;i++)
         TEST_EQUALITY(orientation[i],standardO[i]);
   }
   
}
Esempio n. 2
0
// quad tests
TEUCHOS_UNIT_TEST(tCubeHexMeshDOFManager, buildTest_hex)
{
   // build global (or serial communicator)
   #ifdef HAVE_MPI
      stk::ParallelMachine Comm = MPI_COMM_WORLD;
   #else
      stk::ParallelMachine Comm = WHAT_TO_DO_COMM;
   #endif

   int numProcs = stk::parallel_machine_size(Comm);
   int myRank = stk::parallel_machine_rank(Comm);

   TEUCHOS_ASSERT(numProcs<=2);

   // build a geometric pattern from a single basis
   RCP<const panzer::FieldPattern> patternC1 
         = buildFieldPattern<Intrepid::Basis_HGRAD_HEX_C1_FEM<double,FieldContainer> >();

   Teuchos::RCP<panzer_stk::STK_Interface> mesh = buildQuadMesh(Comm,2,2,2,1,1,1);
   RCP<panzer::ConnManager<int,int> > connManager 
         = Teuchos::rcp(new panzer_stk::STKConnManager(mesh));
   RCP<panzer::DOFManager<int,int> > dofManager = rcp(new panzer::DOFManager<int,int>());

   TEST_EQUALITY(dofManager->getOrientationsRequired(),false);
   TEST_EQUALITY(dofManager->getConnManager(),Teuchos::null);

   dofManager->setConnManager(connManager,MPI_COMM_WORLD);
   TEST_EQUALITY(dofManager->getConnManager(),connManager);

   dofManager->addField("ux",patternC1);
   dofManager->addField("uy",patternC1);
   dofManager->addField("p",patternC1);

   std::vector<std::string> fieldOrder;
   fieldOrder.push_back("ux");
   fieldOrder.push_back("uy");
   fieldOrder.push_back("p");
   dofManager->setFieldOrder(fieldOrder);
   dofManager->buildGlobalUnknowns();
   dofManager->printFieldInformation(out);

   if(numProcs==1) {
      std::vector<int> gids_v;
      int * gids = 0;

      TEST_ASSERT(false);

      // element 0
      dofManager->getElementGIDs(0,gids_v);

      gids = &gids_v[0];
      TEST_EQUALITY(gids_v.size(),24);
      TEST_EQUALITY(gids[0],0);  TEST_EQUALITY(gids[1],1);   TEST_EQUALITY(gids[2],2);
      TEST_EQUALITY(gids[3],3);  TEST_EQUALITY(gids[4],4);   TEST_EQUALITY(gids[5],5);
      TEST_EQUALITY(gids[6],12); TEST_EQUALITY(gids[7],13);  TEST_EQUALITY(gids[8],14);
      TEST_EQUALITY(gids[9], 9); TEST_EQUALITY(gids[10],10); TEST_EQUALITY(gids[11],11);

      gids = &gids_v[12];
      TEST_EQUALITY(gids[0],27); TEST_EQUALITY(gids[1],28);  TEST_EQUALITY(gids[2],29);
      TEST_EQUALITY(gids[3],30); TEST_EQUALITY(gids[4],31);  TEST_EQUALITY(gids[5],32);
      TEST_EQUALITY(gids[6],39); TEST_EQUALITY(gids[7],40);  TEST_EQUALITY(gids[8],41);
      TEST_EQUALITY(gids[9],36); TEST_EQUALITY(gids[10],37); TEST_EQUALITY(gids[11],38);
   
      // element 6
      dofManager->getElementGIDs(mesh->elementLocalId(5),gids_v);

      gids = &gids_v[0];
      TEST_EQUALITY(gids_v.size(),24);
      TEST_EQUALITY(gids[0],27); TEST_EQUALITY(gids[1],28);  TEST_EQUALITY(gids[2],29);
      TEST_EQUALITY(gids[3],30); TEST_EQUALITY(gids[4],31);  TEST_EQUALITY(gids[5],32);
      TEST_EQUALITY(gids[6],39); TEST_EQUALITY(gids[7],40);  TEST_EQUALITY(gids[8],41);
      TEST_EQUALITY(gids[9],36); TEST_EQUALITY(gids[10],37); TEST_EQUALITY(gids[11],38);

      gids = &gids_v[12];
      TEST_EQUALITY(gids[0],54); TEST_EQUALITY(gids[1],55);  TEST_EQUALITY(gids[2],56);
      TEST_EQUALITY(gids[3],57); TEST_EQUALITY(gids[4],58);  TEST_EQUALITY(gids[5],59);
      TEST_EQUALITY(gids[6],66); TEST_EQUALITY(gids[7],67);  TEST_EQUALITY(gids[8],68);
      TEST_EQUALITY(gids[9],63); TEST_EQUALITY(gids[10],64); TEST_EQUALITY(gids[11],65);
   }
   else if(myRank==0) {
      // element 7
      const int * gids = connManager->getConnectivity(mesh->elementLocalId(7));
      TEST_EQUALITY(connManager->getConnectivitySize(mesh->elementLocalId(7)),8);

      TEST_EQUALITY(gids[0],12); TEST_EQUALITY(gids[1],13);  
      TEST_EQUALITY(gids[2],16); TEST_EQUALITY(gids[3],15);
      TEST_EQUALITY(gids[4],21); TEST_EQUALITY(gids[5],22);  
      TEST_EQUALITY(gids[6],25); TEST_EQUALITY(gids[7],24);
   }
   else if(myRank==1) {
      // element 2
      const int * gids = connManager->getConnectivity(mesh->elementLocalId(2));
      TEST_EQUALITY(connManager->getConnectivitySize(mesh->elementLocalId(2)),8);

      TEST_EQUALITY(gids[0],1); TEST_EQUALITY(gids[1],2);  
      TEST_EQUALITY(gids[2],5); TEST_EQUALITY(gids[3],4);
      TEST_EQUALITY(gids[4],10); TEST_EQUALITY(gids[5],11);  
      TEST_EQUALITY(gids[6],14); TEST_EQUALITY(gids[7],13);
   }
}
// quad tests
TEUCHOS_UNIT_TEST(tSquareQuadMeshDOFManager_edgetests, buildTest_quad_edge_orientations_fail)
{

   // build global (or serial communicator)
   #ifdef HAVE_MPI
      stk_classic::ParallelMachine Comm = MPI_COMM_WORLD;
   #else
      stk_classic::ParallelMachine Comm = WHAT_TO_DO_COMM;
   #endif

   int numProcs = stk_classic::parallel_machine_size(Comm);

   TEUCHOS_ASSERT(numProcs==1);

   // build a geometric pattern from a single basis
   RCP<const panzer::FieldPattern> patternI1 
         = buildFieldPattern<Intrepid2::Basis_HCURL_QUAD_I1_FEM<double,FieldContainer> >();
   out << *patternI1 << std::endl;

   RCP<panzer::ConnManager<int,int> > connManager = buildQuadMesh(Comm,2,2,1,1);
   RCP<panzer::DOFManagerFEI<int,int> > dofManager = rcp(new panzer::DOFManagerFEI<int,int>());

   dofManager->setOrientationsRequired(true);
   TEST_EQUALITY(dofManager->getOrientationsRequired(),true);
   TEST_EQUALITY(dofManager->getConnManager(),Teuchos::null);

   dofManager->setConnManager(connManager,MPI_COMM_WORLD);
   TEST_EQUALITY(dofManager->getConnManager(),connManager);

   dofManager->addField("b",patternI1);

   dofManager->buildGlobalUnknowns();

   for(int i=0;i<4;i++) {
      const int * indices = connManager->getConnectivity(i);
      TEST_EQUALITY(connManager->getConnectivitySize(i),8);

      out << "cell = " << i << ": ";
      for(int j=0;j<4;j++)
         out << indices[j+4] << " ";
      out << std::endl;
   }
 

   out << "GIDS" << std::endl;
   for(int i=0;i<4;i++) {
      std::vector<int> gids;
      dofManager->getElementGIDs(i,gids);

      TEST_EQUALITY(gids.size(),4);
      out << "cell = " << i << ": ";
      for(int j=0;j<4;j++)
         out << gids[j] << " ";
      out << std::endl;
   }

   std::vector<int> total;
   dofManager->getOwnedIndices(total);
   TEST_EQUALITY(total.size(),12);

   dofManager->printFieldInformation(out);

}
// quad tests
TEUCHOS_UNIT_TEST(tSquareTriMeshDOFManager, buildTest_tri)
{
   PHX::InitializeKokkosDevice();

   // build global (or serial communicator)
   #ifdef HAVE_MPI
      stk_classic::ParallelMachine Comm = MPI_COMM_WORLD;
   #else
      stk_classic::ParallelMachine Comm = WHAT_TO_DO_COMM;
   #endif

   int numProcs = stk_classic::parallel_machine_size(Comm);
   int myRank = stk_classic::parallel_machine_rank(Comm);

   TEUCHOS_ASSERT(numProcs==2);

   // build a geometric pattern from a single basis
   RCP<const panzer::FieldPattern> patternC1 
         = buildFieldPattern<Intrepid2::Basis_HGRAD_TRI_C1_FEM<double,FieldContainer> >();

   RCP<panzer::ConnManager<int,int> > connManager = buildTriMesh(Comm,2,2,1,1);
   RCP<panzer::DOFManagerFEI<int,int> > dofManager = rcp(new panzer::DOFManagerFEI<int,int>());

   TEST_EQUALITY(dofManager->getOrientationsRequired(),false);
   TEST_EQUALITY(dofManager->getConnManager(),Teuchos::null);

   dofManager->setConnManager(connManager,MPI_COMM_WORLD);
   TEST_EQUALITY(dofManager->getConnManager(),connManager);

   dofManager->addField("ux",patternC1);
   dofManager->addField("uy",patternC1);
   dofManager->addField("p",patternC1);

   dofManager->buildGlobalUnknowns();
   dofManager->printFieldInformation(out);

   TEST_EQUALITY(dofManager->getFieldNum("p"),0);
   TEST_EQUALITY(dofManager->getFieldNum("ux"),1);
   TEST_EQUALITY(dofManager->getFieldNum("uy"),2);

   const std::vector<int> & uy_offsets = dofManager->getGIDFieldOffsets("eblock-0_0",dofManager->getFieldNum("uy"));
   const std::vector<int> & p_offsets = dofManager->getGIDFieldOffsets("eblock-0_0",dofManager->getFieldNum("p"));
   const std::vector<int> & ux_offsets = dofManager->getGIDFieldOffsets("eblock-0_0",dofManager->getFieldNum("ux"));

   TEST_EQUALITY(uy_offsets.size(),p_offsets.size());
   TEST_EQUALITY(uy_offsets.size(),ux_offsets.size());

   if(myRank==0) {
      std::vector<int> gids;

      dofManager->getElementGIDs(0,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],0); TEST_EQUALITY(gids[1],1); TEST_EQUALITY(gids[2],2);
      TEST_EQUALITY(gids[3],3); TEST_EQUALITY(gids[4],4); TEST_EQUALITY(gids[5],5);
      TEST_EQUALITY(gids[6],9); TEST_EQUALITY(gids[7],10); TEST_EQUALITY(gids[8],11);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }
   
      dofManager->getElementGIDs(1,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],0); TEST_EQUALITY(gids[1],1); TEST_EQUALITY(gids[2],2);
      TEST_EQUALITY(gids[3],9); TEST_EQUALITY(gids[4],10); TEST_EQUALITY(gids[5],11);
      TEST_EQUALITY(gids[6],6); TEST_EQUALITY(gids[7],7); TEST_EQUALITY(gids[8],8);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }

      dofManager->getElementGIDs(3,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],6); TEST_EQUALITY(gids[1],7); TEST_EQUALITY(gids[2],8);
      TEST_EQUALITY(gids[3],15); TEST_EQUALITY(gids[4],16); TEST_EQUALITY(gids[5],17);
      TEST_EQUALITY(gids[6],12); TEST_EQUALITY(gids[7],13); TEST_EQUALITY(gids[8],14);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }
   }
   else if(myRank==1) {
      std::vector<int> gids;

      dofManager->getElementGIDs(0,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],3); TEST_EQUALITY(gids[1],4); TEST_EQUALITY(gids[2],5);
      TEST_EQUALITY(gids[3],18); TEST_EQUALITY(gids[4],19); TEST_EQUALITY(gids[5],20);
      TEST_EQUALITY(gids[6],21); TEST_EQUALITY(gids[7],22); TEST_EQUALITY(gids[8],23);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }
   
      dofManager->getElementGIDs(1,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],3); TEST_EQUALITY(gids[1],4); TEST_EQUALITY(gids[2],5);
      TEST_EQUALITY(gids[3],21); TEST_EQUALITY(gids[4],22); TEST_EQUALITY(gids[5],23);
      TEST_EQUALITY(gids[6],9); TEST_EQUALITY(gids[7],10); TEST_EQUALITY(gids[8],11);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }

      dofManager->getElementGIDs(3,gids);
      TEST_EQUALITY(gids.size(),9);
      TEST_EQUALITY(gids[0],9); TEST_EQUALITY(gids[1],10); TEST_EQUALITY(gids[2],11);
      TEST_EQUALITY(gids[3],24); TEST_EQUALITY(gids[4],25); TEST_EQUALITY(gids[5],26);
      TEST_EQUALITY(gids[6],15); TEST_EQUALITY(gids[7],16); TEST_EQUALITY(gids[8],17);

      for(std::size_t i=0;i<p_offsets.size();i++) {
         TEST_ASSERT(gids[p_offsets[i]]<gids[ux_offsets[i]]); 
         TEST_ASSERT(gids[p_offsets[i]]<gids[uy_offsets[i]]); 
         TEST_ASSERT(gids[ux_offsets[i]]<gids[uy_offsets[i]]); 
      }
   }
   
   PHX::FinalizeKokkosDevice();
}
 void evaluateFields(typename Traits::EvalData d)
  { std::cout << "unspecialized version of \"ScatterResidual_BlockedTpetra::evaluateFields\" on \""+PHX::TypeString<EvalT>::value+"\" should not be used!" << std::endl;
    TEUCHOS_ASSERT(false); }
 int getElementBlockGIDCount(const std::size_t &) const { TEUCHOS_ASSERT(false); }
  inline
  void panzer::BasisValues<Scalar,Array>::
  evaluateValues(const Array& cub_points,
		 const Array& jac,
 	 	 const Array& jac_det,
		 const Array& jac_inv,
		 const Array& weighted_measure,
		 const Array& node_coordinates)
  {    
    bool buildWeighted = ((&weighted_measure)!= &dummyArray);
    bool buildBasisPoints = ((&node_coordinates)!= &dummyArray);

    // first grab basis descriptor
    PureBasis::EElementSpace elmtspace = getElementSpace();
    int spaceDim = basis_layout->dimension();

    intrepid_basis->getValues(basis_ref, cub_points, 
			      Intrepid::OPERATOR_VALUE);

    if(elmtspace==PureBasis::CONST) {

       Intrepid::FunctionSpaceTools::
         HGRADtransformVALUE<Scalar>(basis,
   				  basis_ref);

       if(buildWeighted) {
          Intrepid::FunctionSpaceTools::
            multiplyMeasure<Scalar>(weighted_basis, 
      			         weighted_measure, 
   			         basis);
       }
    }
    else if(elmtspace==PureBasis::HGRAD) {
       intrepid_basis->getValues(grad_basis_ref, cub_points, 
   			         Intrepid::OPERATOR_GRAD);
    
       Intrepid::FunctionSpaceTools::
         HGRADtransformVALUE<Scalar>(basis,
   				  basis_ref);
       
       Intrepid::FunctionSpaceTools::
         HGRADtransformGRAD<Scalar>(grad_basis,
   				 jac_inv,
   				 grad_basis_ref);

       if(buildWeighted) {
          Intrepid::FunctionSpaceTools::
            multiplyMeasure<Scalar>(weighted_basis, 
      			         weighted_measure, 
   			         basis);
       
          Intrepid::FunctionSpaceTools::
            multiplyMeasure<Scalar>(weighted_grad_basis, 
   	   		         weighted_measure, 
   			         grad_basis);
       }
    }
    else if(elmtspace==PureBasis::HCURL) {
       intrepid_basis->getValues(curl_basis_ref, cub_points, 
   			         Intrepid::OPERATOR_CURL);

       Intrepid::FunctionSpaceTools::
         HCURLtransformVALUE<Scalar>(basis,
                                     jac_inv,
   		  		     basis_ref);

       // the CURL transform differs depending on spactial dimension
       // "In 2D the de Rham complex collapses." But I look at it like this:
       // In 2D the curl is simply  $-\partial_x u_1+\partial_y u_0$ which
       // has the same derivative structure as the divergence in 2D 
       // $\partial_x u_0 + \partial_y u_1$ which means the transformation
       // is the same.
       if(spaceDim==2) 
          Intrepid::FunctionSpaceTools::
            HDIVtransformDIV<Scalar>(curl_basis,
   			             jac_det,   // note only volume deformation is needed!
                                                // this relates directly to this being in
                                                // the divergence space in 2D!
   			             curl_basis_ref);
       else if(spaceDim==3)
          Intrepid::FunctionSpaceTools::
            HCURLtransformCURL<Scalar>(curl_basis,
   	                               jac,
   				       jac_det,
   				       curl_basis_ref);
       else
          TEUCHOS_ASSERT(false); // what you doin?

       if(buildWeighted) {
          Intrepid::FunctionSpaceTools::
            multiplyMeasure<Scalar>(weighted_basis, 
   	   		         weighted_measure, 
   			         basis);
   
          Intrepid::FunctionSpaceTools::
            multiplyMeasure<Scalar>(weighted_curl_basis, 
   	   		         weighted_measure, 
   			         curl_basis);
       }
   }
    

    // If basis supports coordinate values at basis points, then
    // compute these values
    if(buildBasisPoints) {
      Teuchos::RCP<Intrepid::DofCoordsInterface<Array> > coords;
      coords = Teuchos::rcp_dynamic_cast<Intrepid::DofCoordsInterface<Array> >(intrepid_basis);
      if (!Teuchos::is_null(coords)) {
        coords->getDofCoords(basis_coordinates_ref);
        Intrepid::CellTools<Scalar> cell_tools;
        cell_tools.mapToPhysicalFrame(basis_coordinates, 
                                      basis_coordinates_ref,
                                      node_coordinates,
                                      intrepid_basis->getBaseCellTopology());
      }
    }

  }
 /** \brief Get the number used for access to this
   *        field
   *
   * Get the number used for access to this
   * field. This is used as the input parameter
   * to the other functions that provide access
   * to the global unknowns.
   *
   * \param[in] str Human readable name of the field
   *
   * \returns A unique integer associated with the
   *          field if the field exisits. Otherwise
   *          a -1 is returned.
   */
 virtual int getFieldNum(const std::string & str) const
 { TEUCHOS_ASSERT(false); return -1; }
 virtual const std::string & getFieldString(int field) const
 { TEUCHOS_ASSERT(false); static std::string empty = "EMPTY"; return empty; }
void panzer::ScatterDirichletResidual_Tpetra<panzer::Traits::SGJacobian, TRAITS,LO,GO,NodeT>::
evaluateFields(typename TRAITS::EvalData workset)
{ 
/*
   typedef SGTpetraLinearObjContainer<double,LO,GO,NodeT> SGLOC;

   std::vector<GO> GIDs;
   std::vector<LO> LIDs;
 
   // for convenience pull out some objects from workset
   std::string blockId = this->wda(workset).block_id;
   const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;

   Teuchos::RCP<typename LOC::CrsMatrixType> Jac_template = (*sgTpetraContainer_->begin())->get_A();
   Teuchos::RCP<const typename LOC::MapType> map = Jac_template->getRowMap();

   Teuchos::ArrayRCP<double> dc_array = dirichletCounter_->get1dViewNonConst();

   // NOTE: A reordering of these loops will likely improve performance
   //       The "getGIDFieldOffsets may be expensive.  However the
   //       "getElementGIDs" can be cheaper. However the lookup for LIDs
   //       may be more expensive!

   // scatter operation for each cell in workset
   for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
      std::size_t cellLocalId = localCellIds[worksetCellIndex];

      globalIndexer_->getElementGIDs(cellLocalId,GIDs); 

      // caculate the local IDs for this element
      LIDs.resize(GIDs.size());
      for(std::size_t i=0;i<GIDs.size();i++)
         LIDs[i] = map->getLocalElement(GIDs[i]);

      std::vector<bool> is_owned(GIDs.size(), false);
      globalIndexer_->ownedIndices(GIDs,is_owned);

      // loop over each field to be scattered
      for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
         int fieldNum = fieldIds_[fieldIndex];
   
         // this call "should" get the right ordering according to the Intrepid basis
         const std::pair<std::vector<int>,std::vector<int> > & indicePair 
               = globalIndexer_->getGIDFieldOffsets_closure(blockId,fieldNum, side_subcell_dim_, local_side_id_);
         const std::vector<int> & elmtOffset = indicePair.first;
         const std::vector<int> & basisIdMap = indicePair.second;
   
         // loop over basis functions
         for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
            int offset = elmtOffset[basis];
            LO lid = LIDs[offset];
            GO gid = GIDs[offset];
            int basisId = basisIdMap[basis];
            if(lid<0) // not on this processor
               continue;

            const ScalarT scatterField = (scatterFields_[fieldIndex])(worksetCellIndex,basisId);

            // loop over stochastic basis scatter field values to residual vectors
            int stochIndex = 0;
            typename SGLOC::iterator itr; 
            for(itr=sgTpetraContainer_->begin();itr!=sgTpetraContainer_->end();++itr,++stochIndex) {
               Teuchos::RCP<typename LOC::VectorType> r = (*itr)->get_f();
               Teuchos::RCP<typename LOC::CrsMatrixType> Jac = (*itr)->get_A();
               Teuchos::ArrayRCP<double> r_array = r->get1dViewNonConst();

               // zero out matrix row
               {
                  std::size_t sz = Jac->getNumEntriesInLocalRow(lid);
                  std::size_t numEntries = 0;
                  Teuchos::Array<LO> rowIndices(sz);
                  Teuchos::Array<double> rowValues(sz);
   
                  Jac->getLocalRowCopy(lid,rowIndices,rowValues,numEntries);
   
                  for(std::size_t i=0;i<numEntries;i++)
                     rowValues[i] = 0.0;
   
                  Jac->replaceLocalValues(lid,rowIndices,rowValues);
               }
    
               r_array[lid] = scatterField.val().coeff(stochIndex);
       
               // loop over the sensitivity indices: all DOFs on a cell
               std::vector<double> jacRow(scatterField.size(),0.0);
       
               for(int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
                  jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex).coeff(stochIndex);
       
               Jac->replaceGlobalValues(gid, GIDs, jacRow);
            }

            // dirichlet condition application
            dc_array[lid] = 1.0;
         }
      }
   }

*/
 
   TEUCHOS_ASSERT(false); // lets face it this doesn't work
}
 void evaluateFields(typename TRAITS::EvalData d)
 { std::cout << "unspecialized version of \"GatherSolution_BlockedEpetra::evaluateFields\" on "+PHX::typeAsString<EvalT>()+"\" should not be used!" << std::endl;
   TEUCHOS_ASSERT(false); }
  void IntegrationValues2<Scalar>::
  evaluateRemainingValues(const PHX::MDField<Scalar,Cell,NODE,Dim>& in_node_coordinates)
  {
    Intrepid2::CellTools<PHX::Device::execution_space> cell_tools;

    // copy the dynamic data structures into the static data structures
    {
      size_type num_ip = dyn_cub_points.dimension(0);
      size_type num_dims = dyn_cub_points.dimension(1);
     
      for (size_type ip = 0; ip < num_ip;  ++ip) {
        cub_weights(ip) = dyn_cub_weights(ip);
        for (size_type dim = 0; dim < num_dims; ++dim)
          cub_points(ip,dim) = dyn_cub_points(ip,dim);
      }
    }

    if (int_rule->isSide()) {
      const size_type num_ip = dyn_cub_points.dimension(0), num_side_dims = dyn_side_cub_points.dimension(1);
      for (size_type ip = 0; ip < num_ip; ++ip)
        for (size_type dim = 0; dim < num_side_dims; ++dim)
          side_cub_points(ip,dim) = dyn_side_cub_points(ip,dim);
    }
    
    {
      size_type num_cells = in_node_coordinates.dimension(0);
      size_type num_nodes = in_node_coordinates.dimension(1);
      size_type num_dims = in_node_coordinates.dimension(2);
     
      for (size_type cell = 0; cell < num_cells;  ++cell) {
	for (size_type node = 0; node < num_nodes; ++node) {
	  for (size_type dim = 0; dim < num_dims; ++dim) {
	    node_coordinates(cell,node,dim) = 
	      in_node_coordinates(cell,node,dim);
	  }
	}
      }
    }

    cell_tools.setJacobian(jac.get_view(),
                           cub_points.get_view(),
                           node_coordinates.get_view(), 
			   *(int_rule->topology));
    
    cell_tools.setJacobianInv(jac_inv.get_view(), jac.get_view());
    
    cell_tools.setJacobianDet(jac_det.get_view(), jac.get_view());
    
    if (!int_rule->isSide()) {
       Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::
         computeCellMeasure(weighted_measure.get_view(), jac_det.get_view(), cub_weights.get_view());
    }
    else if(int_rule->spatial_dimension==3) {
       Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::
         computeFaceMeasure(weighted_measure.get_view(), jac.get_view(), cub_weights.get_view(),
                            int_rule->side, *int_rule->topology,
                            scratch_for_compute_side_measure.get_view());
    }
    else if(int_rule->spatial_dimension==2) {
       Intrepid2::FunctionSpaceTools<PHX::Device::execution_space>::
         computeEdgeMeasure(weighted_measure.get_view(), jac.get_view(), cub_weights.get_view(),
                            int_rule->side,*int_rule->topology,
                            scratch_for_compute_side_measure.get_view());
    }
    else TEUCHOS_ASSERT(false);
    
    // Shakib contravarient metric tensor
    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
      for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {

	// zero out matrix
	for (size_type i = 0; i < contravarient.dimension(2); ++i)
	  for (size_type j = 0; j < contravarient.dimension(3); ++j)
	    covarient(cell,ip,i,j) = 0.0;
	   
	// g^{ij} = \frac{\parital x_i}{\partial \chi_\alpha}\frac{\parital x_j}{\partial \chi_\alpha}
	for (size_type i = 0; i < contravarient.dimension(2); ++i) {
	  for (size_type j = 0; j < contravarient.dimension(3); ++j) {
	    for (size_type alpha = 0; alpha < contravarient.dimension(2); ++alpha) {
	      covarient(cell,ip,i,j) += jac(cell,ip,i,alpha) * jac(cell,ip,j,alpha);
	    }
	  }
	}	

      }
    }

    Intrepid2::RealSpaceTools<PHX::Device::execution_space>::inverse(contravarient.get_view(), covarient.get_view());

    // norm of g_ij
    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
      for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {
	norm_contravarient(cell,ip) = 0.0;
	for (size_type i = 0; i < contravarient.dimension(2); ++i) {
	  for (size_type j = 0; j < contravarient.dimension(3); ++j) {
	    norm_contravarient(cell,ip) += contravarient(cell,ip,i,j) * contravarient(cell,ip,i,j);
	  }
	}
	norm_contravarient(cell,ip) = std::sqrt(norm_contravarient(cell,ip));
      }
    }
  }
  inline
  void panzer::IntegrationValues<Scalar,Array>::
    evaluateValues(const NodeCoordinateArray& in_node_coordinates)
  {
    int num_space_dim = int_rule->topology->getDimension();
    if (int_rule->isSide() && num_space_dim==1) {
       std::cout << "WARNING: 0-D quadrature rule ifrastructure does not exist!!! Will not be able to do "
                 << "non-natural integration rules.";
       return; 
    }
    
    Intrepid::CellTools<Scalar> cell_tools;
    
    if (!int_rule->isSide())
      intrepid_cubature->getCubature(cub_points, cub_weights);
    else {
      intrepid_cubature->getCubature(side_cub_points, cub_weights);
      
      cell_tools.mapToReferenceSubcell(cub_points, 
				       side_cub_points,
				       int_rule->spatial_dimension-1,
				       int_rule->side, 
				       *(int_rule->topology));
    }


    {
      typedef typename 
	panzer::ArrayTraits<Scalar,NodeCoordinateArray>::size_type size_type;

      size_type num_cells = in_node_coordinates.dimension(0);
      size_type num_nodes = in_node_coordinates.dimension(1);
      size_type num_dims = in_node_coordinates.dimension(2);
     
      for (size_type cell = 0; cell < num_cells;  ++cell) {
	for (size_type node = 0; node < num_nodes; ++node) {
	  for (size_type dim = 0; dim < num_dims; ++dim) {
	    node_coordinates(cell,node,dim) = 
	      in_node_coordinates(cell,node,dim);
	  }
	}
      }
    }

    cell_tools.setJacobian(jac, cub_points, node_coordinates, 
			   *(int_rule->topology));
    
    cell_tools.setJacobianInv(jac_inv, jac);
    
    cell_tools.setJacobianDet(jac_det, jac);
    
    if (!int_rule->isSide()) {
       Intrepid::FunctionSpaceTools::
         computeCellMeasure<Scalar>(weighted_measure, jac_det, cub_weights);
    }
    else if(int_rule->spatial_dimension==3) {
       Intrepid::FunctionSpaceTools::
         computeFaceMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology);
    }
    else if(int_rule->spatial_dimension==2) {
       Intrepid::FunctionSpaceTools::
         computeEdgeMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology);
    }
    else TEUCHOS_ASSERT(false);
    
    // Shakib contravarient metric tensor
    typedef typename 
      panzer::ArrayTraits<Scalar,Array>::size_type size_type;

    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
      for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {

	// zero out matrix
	for (size_type i = 0; i < contravarient.dimension(2); ++i)
	  for (size_type j = 0; j < contravarient.dimension(3); ++j)
	    covarient(cell,ip,i,j) = 0.0;
	   
	// g^{ij} = \frac{\parital x_i}{\partial \chi_\alpha}\frac{\parital x_j}{\partial \chi_\alpha}
	for (size_type i = 0; i < contravarient.dimension(2); ++i) {
	  for (size_type j = 0; j < contravarient.dimension(3); ++j) {
	    for (size_type alpha = 0; alpha < contravarient.dimension(2); ++alpha) {
	      covarient(cell,ip,i,j) += jac(cell,ip,i,alpha) * jac(cell,ip,j,alpha);
	    }
	  }
	}

	

      }
    }

    Intrepid::RealSpaceTools<Scalar>::inverse(contravarient, covarient);

    /*
    for (std::size_t cell = 0; cell < contravarient.dimension(0); ++cell) {
      std::cout << "cell = " << cell << std::endl;
      for (std::size_t ip = 0; ip < contravarient.dimension(1); ++ip) {
      std::cout << "  ip = " << ip << std::endl;
	for (std::size_t i = 0; i < contravarient.dimension(2); ++i) {
	  for (std::size_t j = 0; j < contravarient.dimension(2); ++j) {
	    std::cout << "contravarient(" << i << "," << j << ") = " << contravarient(cell,ip,i,j) << std::endl;
	  }
	}
      }
    }
    */

    // norm of g_ij
    for (size_type cell = 0; cell < contravarient.dimension(0); ++cell) {
      for (size_type ip = 0; ip < contravarient.dimension(1); ++ip) {
	norm_contravarient(cell,ip) = 0.0;
	for (size_type i = 0; i < contravarient.dimension(2); ++i) {
	  for (size_type j = 0; j < contravarient.dimension(3); ++j) {
	    norm_contravarient(cell,ip) += contravarient(cell,ip,i,j) * contravarient(cell,ip,i,j);
	  }
	}
	norm_contravarient(cell,ip) = std::sqrt(norm_contravarient(cell,ip));
      }
    }

    // IP coordinates
    {
      cell_tools.mapToPhysicalFrame(ip_coordinates, cub_points, node_coordinates, *(int_rule->topology));
    }

  }
//**********************************************************************
PHX_EVALUATE_FIELDS(DirichletResidual_EdgeBasis,workset)
{
    if(workset.num_cells<=0)
        return;

    residual.deep_copy(ScalarT(0.0));

    if(workset.subcell_dim==1) {
        Intrepid2::CellTools<ScalarT>::getPhysicalEdgeTangents(edgeTan,
                pointValues.jac,
                this->wda(workset).subcell_index,
                *basis->getCellTopology());

        for(std::size_t c=0; c<workset.num_cells; c++) {
            for(int b=0; b<dof.dimension(1); b++) {
                for(int d=0; d<dof.dimension(2); d++)
                    residual(c,b) += (dof(c,b,d)-value(c,b,d))*edgeTan(c,b,d);
            }
        }
    }
    else if(workset.subcell_dim==2) {
        // we need to compute the tangents on each edge for each cell.
        // how do we do this????
        const shards::CellTopology & parentCell = *basis->getCellTopology();
        int cellDim = parentCell.getDimension();
        int numEdges = dof.dimension(1);

        refEdgeTan = Intrepid2::FieldContainer<ScalarT>(numEdges,cellDim);

        for(int i=0; i<numEdges; i++) {
            Intrepid2::FieldContainer<double> refEdgeTan_local(cellDim);
            Intrepid2::CellTools<double>::getReferenceEdgeTangent(refEdgeTan_local, i, parentCell);

            for(int d=0; d<cellDim; d++)
                refEdgeTan(i,d) = refEdgeTan_local(d);
        }

        // Loop over workset faces and edge points
        for(std::size_t c=0; c<workset.num_cells; c++) {
            for(int pt = 0; pt < numEdges; pt++) {

                // Apply parent cell Jacobian to ref. edge tangent
                for(int i = 0; i < cellDim; i++) {
                    edgeTan(c, pt, i) = 0.0;
                    for(int j = 0; j < cellDim; j++) {
                        edgeTan(c, pt, i) +=  pointValues.jac(c, pt, i, j)*refEdgeTan(pt,j);
                    }// for j
                }// for i
            }// for pt
        }// for pCell

        for(std::size_t c=0; c<workset.num_cells; c++) {
            for(int b=0; b<dof.dimension(1); b++) {
                for(int d=0; d<dof.dimension(2); d++)
                    residual(c,b) += (dof(c,b,d)-value(c,b,d))*edgeTan(c,b,d);
            }
        }

    }
    else {
        // don't know what to do
        TEUCHOS_ASSERT(false);
    }

    // loop over residuals scaling by orientation. This gurantees
    // everything is oriented in the "positive" direction, this allows
    // sums acrossed processor to be oriented in the same way (right?)
    for(std::size_t c=0; c<workset.num_cells; c++) {
        for(int b=0; b<dof.dimension(1); b++) {
            residual(c,b) *= dof_orientation(c,b);
        }
    }
}
 /** Get a yes/no on ownership for each index in a vector
   */
 virtual void ownedIndices(const std::vector<std::pair<int,GlobalOrdinalT> > & indices,std::vector<bool> & isOwned) const
 { TEUCHOS_ASSERT(false); }
 virtual Teuchos::RCP<Teuchos::Comm<int> > getComm() const
 { TEUCHOS_ASSERT(false); return Teuchos::null; }
 void getCoordinates(LocalOrdinalT localElementId,Intrepid2::FieldContainer<double> & points)
 { TEUCHOS_ASSERT(false); }
 /** Is the specified field in the element block? 
   */
 virtual bool fieldInBlock(const std::string & field, const std::string & block) const
 { TEUCHOS_ASSERT(false); return false; }
 //! \brief Get a particular block. If there is no block at this index location return a new one
 virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const {
   TEUCHOS_ASSERT(blockIndex<(int) children_.size());
   return children_[blockIndex];
 }
 /** Get field numbers associated with a particular element block.
   */
 virtual const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const
 { static std::vector<int> data; TEUCHOS_ASSERT(false); return data; }
Esempio n. 21
0
// =============================================================================
void
VIO::TpetraMesh::Mesh::
computeFvmEntities_() const
{
  // Compute the volume of the (Voronoi) control cells for each point.
  TEUCHOS_ASSERT( !elems_.is_null() );
  int numElems = elems_.size();

  Teuchos::RCP<Tpetra::Map<ORD> > map = this->getElemsToNodesMap_();
  controlVolumes_ = Teuchos::rcp( new DoubleVector( map ) );
  edgeLengths_    = Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> >( numElems );
  coedgeLengths_  = Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> >( numElems );

//   Teuchos::ArrayRCP<double> controlVolumesView = controlVolumes_->get1dViewNonConst();

  // Run over the elements and calculate their contributions to the
  // control volumes.
  Teuchos::ArrayRCP<double> cvView = controlVolumes_->get1dViewNonConst();
  for ( int k=0; k<numElems; k++ )
  {
    Teuchos::ArrayRCP<ORD> & elem = elems_[k];

    TEST_FOR_EXCEPTION( elems_[k].size() != 3,
                        std::runtime_error,
                        "Control volumes can only be constructed consistently with triangular elements."
                      );

    // compute the circumcenter
    Point cc = this->computeCircumcenter_( nodes_[elem[0]],
                                           nodes_[elem[1]],
                                           nodes_[elem[2]]
                                         );

    edgeLengths_[k]   = Teuchos::ArrayRCP<double>( 3 );
    coedgeLengths_[k] = Teuchos::ArrayRCP<double>( 3 );
    // iterate over the edges
    for ( int l=0; l<3; l++ )
    {
        int i0 = elem[ l ];
        int i1 = elem[ (l+1)%3 ];

        Point & x0 = nodes_[i0];
        Point & x1 = nodes_[i1];

        // edge midpoint
        Point mp = this->add_( 0.5, x0, 0.5, x1 );

        cvView[ map->getLocalElement(i0) ] += this->getTriangleArea_( x0, cc, mp );
        cvView[ map->getLocalElement(i1) ] += this->getTriangleArea_( x1, cc, mp );

        coedgeLengths_[k][l] = this->norm2_( this->add_( 1.0, mp, -1.0, cc ) );
        edgeLengths_[k][l]   = this->norm2_( this->add_( 1.0, x1, -1.0, x0 ) );
    }
  }

  // sum up the overlapping entries and make sure they're
  // available on all processes
  this->sumInOverlapMap_( controlVolumes_ );

  // TODO move this to another spot
  area_ = this->computeDomainArea_();

  fvmEntitiesUpToDate_ = true;

  return;
}
 /** \brief Get the global IDs for a particular element. This function
   * overwrites the <code>gids</code> variable.
   */
 virtual void getElementGIDs(LocalOrdinalT localElmtId,std::vector<std::pair<int,GlobalOrdinalT> > & gids,const std::string & blockId="") const
 { TEUCHOS_ASSERT(false); }
 virtual void getElementOrientation(short localElmtId,std::vector<double> & gidsOrientation) const
 { TEUCHOS_ASSERT(false); }
 /** \brief Use the field pattern so that you can find a particular
   *        field in the GIDs array.
   */
 virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const
 { TEUCHOS_ASSERT(false); }
 virtual void writeVector(const std::string & identifier,const LinearObjContainer & loc,int id) const
 { TEUCHOS_ASSERT(false); }
 // virtual const std::vector<int> & 
 virtual const std::pair<std::vector<int>,std::vector<int> > & 
 getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum,
                                                             int subcellDim,int subcellId) const
 { static std::pair<std::vector<int>,std::vector<int> >  p; TEUCHOS_ASSERT(false); return p; }
ordinal_type
Stokhos::MonomialProjGramSchmidtPCEBasis<ordinal_type, value_type>::
buildReducedBasis(
  ordinal_type max_p, 
  value_type threshold,
  const Teuchos::SerialDenseMatrix<ordinal_type,value_type>& A, 
  const Teuchos::SerialDenseMatrix<ordinal_type,value_type>& F,
  const Teuchos::Array<value_type>& weights, 
  Teuchos::Array< Stokhos::MultiIndex<ordinal_type> >& terms_,
  Teuchos::Array<ordinal_type>& num_terms_,
  Teuchos::SerialDenseMatrix<ordinal_type,value_type>& Qp_, 
  Teuchos::SerialDenseMatrix<ordinal_type,value_type>& Q_)
{
  // Compute basis terms -- 2-D array giving powers for each linear index
  ordinal_type max_sz;
  CPBUtils::compute_terms(max_p, this->d, max_sz, terms_, num_terms_);

  // Compute B matrix -- monomials in F
  // for i=0,...,nqp-1
  //   for j=0,...,sz-1
  //      B(i,j) = F(i,1)^terms_[j][1] * ... * F(i,d)^terms_[j][d]
  // where sz is the total size of a basis up to order p and terms_[j] 
  // is an array of powers for each term in the total-order basis
  ordinal_type nqp = weights.size();
  SDM B(nqp, max_sz);
  for (ordinal_type i=0; i<nqp; i++) {
    for (ordinal_type j=0; j<max_sz; j++) {
      B(i,j) = 1.0;
      for (ordinal_type k=0; k<this->d; k++)
	B(i,j) *= std::pow(F(i,k), terms_[j][k]);
    }
  }

  // Project B into original basis -- should use SPAM for this
  SDM Bp(this->pce_sz, max_sz);
  const Teuchos::Array<value_type>& basis_norms = 
    this->pce_basis->norm_squared();
  for (ordinal_type i=0; i<this->pce_sz; i++) {
    for (ordinal_type j=0; j<max_sz; j++) {
      Bp(i,j) = 0.0;
      for (ordinal_type k=0; k<nqp; k++)
	Bp(i,j) += weights[k]*B(k,j)*A(k,i);
      Bp(i,j) /= basis_norms[i];
    }
  }

  // Rescale columns of Bp to have unit norm
  for (ordinal_type j=0; j<max_sz; j++) {
    value_type nrm = 0.0;
    for (ordinal_type i=0; i<this->pce_sz; i++)
      nrm += Bp(i,j)*Bp(i,j)*basis_norms[i];
    nrm = std::sqrt(nrm);
    for (ordinal_type i=0; i<this->pce_sz; i++)
      Bp(i,j) /= nrm;
  }

  // Compute our new basis -- each column of Qp is the coefficients of the
  // new basis in the original basis.  Constraint pivoting so first d+1
  // columns and included in Qp.
  Teuchos::Array<value_type> w(this->pce_sz, 1.0);
  SDM R;
  Teuchos::Array<ordinal_type> piv(max_sz);
  for (int i=0; i<this->d+1; i++)
    piv[i] = 1;
  typedef Stokhos::OrthogonalizationFactory<ordinal_type,value_type> SOF;
  ordinal_type sz_ = SOF::createOrthogonalBasis(
    this->orthogonalization_method, threshold, this->verbose, Bp, w, 
    Qp_, R, piv);

  // Evaluate new basis at original quadrature points
  Q_.reshape(nqp, sz_);
  ordinal_type ret = 
    Q_.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, A, Qp_, 0.0);
  TEUCHOS_ASSERT(ret == 0);

  return sz_;
}
 /** Get set of indices owned and shared by this processor.
   * This can be thought of as the ``ghosted'' indices.
   */
 virtual void getOwnedAndSharedIndices(std::vector<std::pair<int,GlobalOrdinalT> > & indices) const
 { TEUCHOS_ASSERT(false); }
Esempio n. 29
0
void
Stokhos::AdaptivityManager::
sumInOperator(Epetra_CrsMatrix & A,const Stokhos::AdaptivityManager::Sparse3TensorHash & Cijk,int k,const Epetra_CrsMatrix & J_k) const
{
   TEUCHOS_ASSERT(J_k.NumMyRows() == int(sg_basis_row_dof_.size()));
   TEUCHOS_ASSERT(J_k.NumMyCols() == int(sg_basis_col_dof_.size()));

   const Teuchos::Array<double> & normValues = sg_master_basis_->norm_squared();

   // loop over deterministic rows 
   for(int localM=0;localM<J_k.NumMyRows();localM++) {
      int m = J_k.GRID(localM);

      // grab row basis
      Teuchos::RCP<const Stokhos::ProductBasis<int,double> > rowStochBasis 
            = sg_basis_row_dof_[localM]; 
 
      // grab row from deterministic system
      int d_numEntries;
      int * d_Indices;
      double * d_Values;
     
      J_k.ExtractMyRowView(localM,d_numEntries,d_Values,d_Indices);
      
      // loop over stochastic degrees of freedom of this row
      for(int rb_i=0;rb_i<rowStochBasis->size();rb_i++) {
         int i = sg_master_basis_->index(rowStochBasis->term(rb_i));

         double normValue = normValues[i]; // sg_master_basis->norm_squared(i);
         
         int sg_m = getGlobalRowId(localM,rb_i);

         // we wipe out old values, capacity should gurantee
         // we don't allocate more often than neccessary!
         std::vector<int> sg_indices;
         std::vector<double> sg_values;

         // sg_indices.resize(0); 
         // sg_values.resize(0);

         // loop over each column
         for(int colInd=0;colInd<d_numEntries;colInd++) {
            int localN = d_Indices[colInd];  // grab local deterministic column id

            // grab row basis
            Teuchos::RCP<const Stokhos::ProductBasis<int,double> > colStochBasis 
                  = sg_basis_col_dof_[localN]; 

            // build values array
            for(int cb_j=0;cb_j<colStochBasis->size();cb_j++) {
               int j = sg_master_basis_->index(colStochBasis->term(cb_j));
               int sg_n = getGlobalColId(localN,cb_j);
               double cijk = Cijk.getValue(i,j,k); 

               // no reason to work it in!
               if(cijk==0) continue;

               if(scaleOp_)
                  cijk = cijk/normValue;

               sg_indices.push_back(sg_n);
               sg_values.push_back(cijk*d_Values[colInd]);
            }
         }

         // add in matrix values
         A.SumIntoGlobalValues(sg_m,sg_indices.size(),&sg_values[0],&sg_indices[0]);
      }
   }
}
// quad tests
TEUCHOS_UNIT_TEST(tSquareQuadMeshDOFManager, multiple_dof_managers)
{

   // build global (or serial communicator)
   #ifdef HAVE_MPI
      stk::ParallelMachine Comm = MPI_COMM_WORLD;
   #else
      stk::ParallelMachine Comm = WHAT_TO_DO_COMM;
   #endif

   int numProcs = stk::parallel_machine_size(Comm);
   int myRank = stk::parallel_machine_rank(Comm);

   TEUCHOS_ASSERT(numProcs==2);

   // build a geometric pattern from a single basis
   RCP<const panzer::FieldPattern> patternC1 
         = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >();
   RCP<const panzer::FieldPattern> patternC2 
         = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C2_FEM<PHX::exec_space,double,double> >();

   // build DOF manager
   RCP<panzer::ConnManager<int,int> > connManager = buildQuadMesh(Comm,2,2,1,1);
   RCP<panzer::DOFManagerFEI<int,int> > dofManager_fluids = rcp(new panzer::DOFManagerFEI<int,int>());
   dofManager_fluids->setConnManager(connManager,MPI_COMM_WORLD);
   dofManager_fluids->addField("ux",patternC2);
   dofManager_fluids->addField("uy",patternC2);
   dofManager_fluids->addField("p",patternC1);
   dofManager_fluids->buildGlobalUnknowns();

   RCP<panzer::DOFManagerFEI<int,int> > dofManager_temp = rcp(new panzer::DOFManagerFEI<int,int>());
   dofManager_temp->setConnManager(connManager,MPI_COMM_WORLD);
   dofManager_temp->addField("T",patternC1);
   dofManager_temp->buildGlobalUnknowns(dofManager_fluids->getGeometricFieldPattern());

   if(myRank==0) {
      std::vector<int> gids;

      dofManager_temp->getElementGIDs(0,gids);
      TEST_EQUALITY(gids.size(),4);
      TEST_EQUALITY(gids[0],0); 
      TEST_EQUALITY(gids[1],1); 
      TEST_EQUALITY(gids[2],3);
      TEST_EQUALITY(gids[3],2); 
   
      dofManager_temp->getElementGIDs(1,gids);
      TEST_EQUALITY(gids.size(),4);
      TEST_EQUALITY(gids[0],2); 
      TEST_EQUALITY(gids[1],3); 
      TEST_EQUALITY(gids[2],5);
      TEST_EQUALITY(gids[3],4);
   }
   else if(myRank==1) {
      std::vector<int> gids;

      dofManager_temp->getElementGIDs(0,gids);
      TEST_EQUALITY(gids.size(),4);
      TEST_EQUALITY(gids[0],1); 
      TEST_EQUALITY(gids[1],6); 
      TEST_EQUALITY(gids[2],7);
      TEST_EQUALITY(gids[3],3); 
   
      dofManager_temp->getElementGIDs(1,gids);
      TEST_EQUALITY(gids.size(),4);
      TEST_EQUALITY(gids[0],3); 
      TEST_EQUALITY(gids[1],7); 
      TEST_EQUALITY(gids[2],8);
      TEST_EQUALITY(gids[3],5);
   }
   else
      TEUCHOS_ASSERT(false);

}