// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file dofmanager.hpp \brief Given a mesh with connectivity information, sets up data structures for the indexing of the global degrees of freedom (Dofs). */ #ifndef DOFMANAGER_HPP #define DOFMANAGER_HPP #include "Teuchos_ParameterList.hpp" #include "Intrepid_FieldContainer.hpp" #include "Intrepid_Basis.hpp" #include "meshmanager.hpp" template class DofManager { private: using GO = typename Tpetra::Map<>::global_ordinal_type; ROL::Ptr > meshManager_; std::vector > > > intrepidBasis_; GO numCells_; // number of mesh cells GO numNodes_; // number of mesh nodes GO numEdges_; // number of mesh edges ROL::Ptr > meshCellToNodeMap_; ROL::Ptr > meshCellToEdgeMap_; // Local dof information. int numBases_; // number of bases (fields) int numLocalNodes_; // number of nodes in the basic cell topology int numLocalEdges_; // number of edges in the basic cell topology int numLocalFaces_; // number of faces in the basic cell topology int numLocalNodeDofs_; // number of local (single-cell) node dofs for all bases int numLocalEdgeDofs_; // number of local (single-cell) edge dofs for all bases int numLocalFaceDofs_; // number of local (single-cell) face dofs for all bases int numLocalDofs_; // total number of local (single-cell) face dofs for all bases std::vector numDofsPerNode_; // number of dofs per node in a cell (assumed constant), per basis std::vector numDofsPerEdge_; // number of dofs per edge in a cell (assumed constant), per basis std::vector numDofsPerFace_; // number of dofs per face in a cell (assumed constant), per basis std::vector > fieldPattern_; // local indexing of fields into the array [0,1,...,numLocalDofs-1]; // contains [number of bases] index vectors, where each index vector // is of size [basis cardinality] // Global dof information. GO numNodeDofs_; // number of global node dofs GO numEdgeDofs_; // number of global edge dofs GO numFaceDofs_; // number of global face dofs GO numDofs_; // total number of global dofs ROL::Ptr > nodeDofs_; // global node dofs, of size [numNodes_ x numLocalNodeDofs_] ROL::Ptr > edgeDofs_; // global edge dofs, of size [numEdges_ x numLocalEdgeDofs_] ROL::Ptr > faceDofs_; // global face dofs, of size [numFaces_ x numLocalFaceDofs_] ROL::Ptr > cellDofs_; // global cell dofs, of size [numCells_ x numLocalDofs_]; // ordered by subcell (node, then edge, then face) and basis index std::vector > > fieldDofs_; // global cell dofs, indexed by field/basis, of size [numCells_ x basis cardinality]; // ordered by subcell (node, then edge, then face) public: DofManager(ROL::Ptr > &meshManager, std::vector > > > &intrepidBasis) { meshManager_ = meshManager; intrepidBasis_ = intrepidBasis; numCells_ = meshManager_->getNumCells(); numNodes_ = meshManager_->getNumNodes(); numEdges_ = meshManager_->getNumEdges(); // Mesh data structures. meshCellToNodeMap_ = meshManager_->getCellToNodeMap(); meshCellToEdgeMap_ = meshManager_->getCellToEdgeMap(); // Local degree-of-freedom footprint. numBases_ = static_cast(intrepidBasis_.size()); numDofsPerNode_.resize(numBases_, 0); numDofsPerEdge_.resize(numBases_, 0); numDofsPerFace_.resize(numBases_, 0); numLocalDofs_ = 0; for (int i=0; i > dofTags = (intrepidBasis_[i])->getAllDofTags(); for (int j=0; j<(intrepidBasis_[i])->getCardinality(); j++) { if (dofTags[j][0] == 0) { numDofsPerNode_[i] = dofTags[j][3]; } else if (dofTags[j][0] == 1) { numDofsPerEdge_[i] = dofTags[j][3]; } else if (dofTags[j][0] == 2) { numDofsPerFace_[i] = dofTags[j][3]; } } numLocalDofs_ += (intrepidBasis_[i])->getCardinality(); } numLocalNodeDofs_ = 0; numLocalEdgeDofs_ = 0; numLocalFaceDofs_ = 0; for (int i=0; i( (intrepidBasis_[0])->getBaseCellTopology().getVertexCount() ); numLocalEdges_ = static_cast( (intrepidBasis_[0])->getBaseCellTopology().getEdgeCount() ); numLocalFaces_ = 1; computeFieldPattern(); // Global data structures. computeDofArrays(); computeCellDofs(); computeFieldDofs(); } ROL::Ptr > getNodeDofs() const { return nodeDofs_; } ROL::Ptr > getEdgeDofs() const { return edgeDofs_; } ROL::Ptr > getFaceDofs() const { return faceDofs_; } ROL::Ptr > getCellDofs() const { return cellDofs_; } std::vector > > getFieldDofs() const { return fieldDofs_; } ROL::Ptr > getFieldDofs(const int & fieldNumber) const { return fieldDofs_[fieldNumber]; } GO getNumNodeDofs() const { return numNodeDofs_; } GO getNumEdgeDofs() const { return numEdgeDofs_; } GO getNumFaceDofs() const { return numFaceDofs_; } GO getNumDofs() const { return numDofs_; } int getNumFields() const { return numBases_; } int getLocalFieldSize() const { return numLocalDofs_; } int getLocalFieldSize(const int & fieldNumber) const { return (intrepidBasis_[fieldNumber])->getCardinality(); } std::vector > getFieldPattern() const { return fieldPattern_; } std::vector getFieldPattern(const int & fieldNumber) const { return fieldPattern_[fieldNumber]; } private: void computeDofArrays() { nodeDofs_ = ROL::makePtr>(numNodes_, numLocalNodeDofs_); edgeDofs_ = ROL::makePtr>(numEdges_, numLocalEdgeDofs_); faceDofs_ = ROL::makePtr>(numCells_, numLocalFaceDofs_); Intrepid::FieldContainer &nodeDofs = *nodeDofs_; Intrepid::FieldContainer &edgeDofs = *edgeDofs_; Intrepid::FieldContainer &faceDofs = *faceDofs_; int dofCt = -1; // // This is the independent node id --> edge id --> cell id ordering. // For example, for a Q2-Q2-Q1 basis (Taylor-Hood), we would have: // // Q2 Q2 Q1 // -------------- // n1 1 1 1 // n2 1 1 1 // ... // e1 1 1 0 // e2 1 1 0 // ... // c1 1 1 0 // c2 1 1 0 // ... // // count node dofs for (GO i=0; i>(numCells_, numLocalDofs_); // Grab object references, for easier indexing. Intrepid::FieldContainer &cdofs = *cellDofs_; Intrepid::FieldContainer &nodeDofs = *nodeDofs_; Intrepid::FieldContainer &edgeDofs = *edgeDofs_; Intrepid::FieldContainer &faceDofs = *faceDofs_; Intrepid::FieldContainer &ctn = *meshCellToNodeMap_; Intrepid::FieldContainer &cte = *meshCellToEdgeMap_; for (GO i=0; i &cdofs = *cellDofs_; for (int fieldNum=0; fieldNumgetCardinality(); fieldDofs_[fieldNum] = ROL::makePtr>(numCells_, basisCard); Intrepid::FieldContainer &fdofs = *(fieldDofs_[fieldNum]); for (GO i=0; i