// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file fe_curl.hpp \brief Given a set of cells with geometric node information, sets up data structures used in finite element integration in HCURL. */ #ifndef PDEOPT_FE_CURL_HPP #define PDEOPT_FE_CURL_HPP #include "Teuchos_ParameterList.hpp" #include "Intrepid_FieldContainer.hpp" #include "Intrepid_Basis.hpp" #include "Intrepid_Cubature.hpp" #include "Intrepid_CellTools.hpp" #include "Intrepid_FunctionSpaceTools.hpp" template class FE_CURL { private: const ROL::Ptr > cellNodes_; // coordinates of the cell nodes ROL::Ptr > > basis_; // Intrepid basis const ROL::Ptr > > cubature_; // Intrepid cubature (quadrature, integration) rule const int sideId_; // local side id for boundary integration int c_; // number of cells in the FE object int f_; // number of basis functions per cell int p_; // number of cubature points per cell int d_; // space dimension of the (parent) cells int sd_; // space dimension of the side cells ROL::Ptr cellTopo_; // base (parent) cell topology ROL::Ptr sideTopo_; // side (subcell) topology; assumed uniform std::vector > sideDofs_; // local dofs on cell sides; 1st index: side number; 2nd index: dof number // Containers for local finite element data. ROL::Ptr > cubPoints_; // points of the cubature rule on the reference cell ROL::Ptr > cubWeights_; // weights of the cubature rule on the reference cell ROL::Ptr > cubPointsSubcell_; // cubature points on the side reference cell ROL::Ptr > cubWeightsSubcell_; // cubature weights on the side reference cell ROL::Ptr > cellJac_; // cell Jacobian matrices ROL::Ptr > cellJacInv_; // inverses of cell Jacobians ROL::Ptr > cellJacDet_; // determinants of cell Jacobians ROL::Ptr > cellWeightedMeasure_; // cell measure (Jacobian determinant) multiplied by the cubature weights ROL::Ptr > valReference_; // value of FE basis in reference space ROL::Ptr > curlReference_; // curl of FE basis in reference space ROL::Ptr > valPhysical_; // value of FE basis in physical space ROL::Ptr > curlPhysical_; // curl of FE basis in physical space ROL::Ptr > valPhysicalWeighted_; // value of FE basis in physical space multiplied by weighted cell measure ROL::Ptr > curlPhysicalWeighted_; // curl of FE basis in physical space multiplied by weighted cell measure ROL::Ptr > curlcurlMats_; // cell curl-curl matrices ROL::Ptr > valvalMats_; // cell val-val matrices ROL::Ptr > cubPointsPhysical_; // cubature points on the physical cells ROL::Ptr > dofPoints_; // degree of freedom points on the reference cell public: FE_CURL(const ROL::Ptr > & cellNodes, const ROL::Ptr > > & basis, const ROL::Ptr > > & cubature) : cellNodes_(cellNodes), basis_(basis), cubature_(cubature), sideId_(-1) { // Get base cell topology from basis. cellTopo_ = ROL::makePtr(basis_->getBaseCellTopology()); // Compute dimensions of multidimensional array members. c_ = cellNodes_->dimension(0); f_ = basis_->getCardinality(); p_ = cubature_->getNumPoints(); d_ = cellTopo_->getDimension(); sd_ = d_ - 1; // Get side subcell topology. sideTopo_ = ROL::nullPtr; // Allocate multidimensional arrays. cubPoints_ = ROL::makePtr>(p_, d_); cubWeights_ = ROL::makePtr>(p_); cellJac_ = ROL::makePtr>(c_, p_, d_, d_); cellJacInv_ = ROL::makePtr>(c_, p_, d_, d_); cellJacDet_ = ROL::makePtr>(c_, p_); cellWeightedMeasure_ = ROL::makePtr>(c_, p_); valReference_ = ROL::makePtr>(f_, p_, d_); curlReference_ = ROL::makePtr>(f_, p_, d_); valPhysical_ = ROL::makePtr>(c_, f_, p_, d_); curlPhysical_ = ROL::makePtr>(c_, f_, p_, d_); valPhysicalWeighted_ = ROL::makePtr>(c_, f_, p_, d_); curlPhysicalWeighted_ = ROL::makePtr>(c_, f_, p_, d_); curlcurlMats_ = ROL::makePtr>(c_, f_, f_); valvalMats_ = ROL::makePtr>(c_, f_, f_); cubPointsPhysical_ = ROL::makePtr>(c_, p_, d_); dofPoints_ = ROL::makePtr>(f_, d_); /*** START: Fill multidimensional arrays. ***/ // Compute cubature points and weights. cubature_->getCubature(*cubPoints_, *cubWeights_); // Compute reference basis value and curl. basis_->getValues(*curlReference_, *cubPoints_, Intrepid::OPERATOR_CURL); // evaluate curl operator at cubature points basis_->getValues(*valReference_, *cubPoints_, Intrepid::OPERATOR_VALUE); // evaluate value operator at cubature points // Compute cell Jacobian matrices, its inverses and determinants. Intrepid::CellTools::setJacobian(*cellJac_, *cubPoints_, *cellNodes_, *cellTopo_); // compute cell Jacobians Intrepid::CellTools::setJacobianInv(*cellJacInv_, *cellJac_); // compute inverses of cell Jacobians Intrepid::CellTools::setJacobianDet(*cellJacDet_, *cellJac_); // compute determinants of cell Jacobians // Compute weighted cell measure, i.e., det(J)*(cubature weight). Intrepid::FunctionSpaceTools::computeCellMeasure(*cellWeightedMeasure_, *cellJacDet_, *cubWeights_); // Transform reference values into physical space. Intrepid::FunctionSpaceTools::HCURLtransformVALUE(*valPhysical_, *cellJacInv_, *valReference_); // Multiply with weighted measure to get weighted values in physical space. Intrepid::FunctionSpaceTools::multiplyMeasure(*valPhysicalWeighted_, *cellWeightedMeasure_, *valPhysical_); // Transform reference curls into physical space. Intrepid::FunctionSpaceTools::HCURLtransformCURL(*curlPhysical_, *cellJac_, *cellJacDet_, *curlReference_); // Multiply with weighted measure to get weighted curls in physical space. Intrepid::FunctionSpaceTools::multiplyMeasure(*curlPhysicalWeighted_, *cellWeightedMeasure_, *curlPhysical_); // Compute curl-curl matrices. Intrepid::FunctionSpaceTools::integrate(*curlcurlMats_, *curlPhysical_, *curlPhysicalWeighted_, Intrepid::COMP_CPP); // Compute val-val matrices. Intrepid::FunctionSpaceTools::integrate(*valvalMats_, *valPhysical_, *valPhysicalWeighted_, Intrepid::COMP_CPP); // Map reference cubature points to cells in physical space. Intrepid::CellTools::mapToPhysicalFrame(*cubPointsPhysical_, *cubPoints_, *cellNodes_, *cellTopo_); // Compute local degrees of freedom on reference cell sides. int numSides = cellTopo_->getSideCount(); if (cellTopo_->getDimension() == 1) { numSides = 2; } if ( numSides ) { for (int i=0; i > > coord_iface = ROL::dynamicPtrCast > >(basis_); if (d_ > 1) { coord_iface->getDofCoords(*dofPoints_); } /*** END: Fill multidimensional arrays. ***/ } /** \brief Returns cell Jacobian matrices at cubature points. */ ROL::Ptr > J() const { return cellJac_; } /** \brief Returns inverses of cell Jacobians at cubature points. */ ROL::Ptr > invJ() const { return cellJacInv_; } /** \brief Returns determinants of cell Jacobians at cubature points. */ ROL::Ptr > detJ() const { return cellJacDet_; } /** \brief Returns values of FE basis at cubature points in reference space. */ ROL::Ptr > Nref() const { return valReference_; } /** \brief Returns curls of FE basis at cubature points in reference space. */ ROL::Ptr > curlNref() const { return curlReference_; } /** \brief Returns value of FE basis at cubature points in physical space. */ ROL::Ptr > N() const { return valPhysical_; } /** \brief Returns value of FE basis at cubature points in physical space, multiplied by weighted cell measures. */ ROL::Ptr > NdetJ() const { return valPhysicalWeighted_; } /** \brief Returns curl of FE basis at cubature points in physical space. */ ROL::Ptr > curlN() const { return curlPhysical_; } /** \brief Returns curl of FE basis at cubature points in physical space, multiplied by weighted cell measures. */ ROL::Ptr > curlNdetJ() const { return curlPhysicalWeighted_; } /** \brief Returns curl-curl matrices on cells. */ ROL::Ptr > curlcurlMat() const { return curlcurlMats_; } /** \brief Returns val-val matrices on cells. */ ROL::Ptr > valvalMat() const { return valvalMats_; } /** \brief Returns cubature points on cells in physical space. */ ROL::Ptr > cubPts() const { return cubPointsPhysical_; } /** \brief Builds FE value interpolant and evaluates it at cubature points in physical space. The input coefficients are assumed to be 'signed' (with +/- 1 multiplying the coefficient depending on the alignment with the reference edge direction). */ void evaluateValue(const ROL::Ptr > & fVals, const ROL::Ptr > & inCoeffs) const { Intrepid::FunctionSpaceTools::evaluate(*fVals, *inCoeffs, *valPhysical_); } /** \brief Builds FE value interpolant and evaluates it at cubature points in physical space. The input coefficients are combined with edge signs (with +/- 1 multiplying the coefficient depending on the alignment with the reference edge direction). */ void evaluateValue(const ROL::Ptr > & fVals, const ROL::Ptr > & inCoeffs, const ROL::Ptr > & inSigns) const { Intrepid::FieldContainer coeffsSigned(*inCoeffs); Intrepid::FunctionSpaceTools::applyFieldSigns(coeffsSigned, *inSigns); Intrepid::FunctionSpaceTools::evaluate(*fVals, coeffsSigned, *valPhysical_); } /** \brief Builds FE curl interpolant and evaluates it at cubature points in physical space. The input coefficients are assumed to be 'signed' (with +/- 1 multiplying the coefficient depending on the alignment with the reference edge direction). */ void evaluateCurl(const ROL::Ptr > & fCurls, const ROL::Ptr > & inCoeffs) const { Intrepid::FunctionSpaceTools::evaluate(*fCurls, *inCoeffs, *curlPhysical_); } /** \brief Builds FE value interpolant and evaluates it at cubature points in physical space. The input coefficients are combined with edge signs (with +/- 1 multiplying the coefficient depending on the alignment with the reference edge direction). */ void evaluateCurl(const ROL::Ptr > & fCurls, const ROL::Ptr > & inCoeffs, const ROL::Ptr > & inSigns) const { Intrepid::FieldContainer coeffsSigned(*inCoeffs); Intrepid::FunctionSpaceTools::applyFieldSigns(coeffsSigned, *inSigns); Intrepid::FunctionSpaceTools::evaluate(*fCurls, coeffsSigned, *curlPhysical_); } /** \brief Computes integral of the dot product of values or curls of interpolated FE fields f1 and f2, indexed by (C,P,D). */ void computeIntegral(const ROL::Ptr > & integral, const ROL::Ptr > & f1, const ROL::Ptr > & f2, const bool sumInto = false) const { Intrepid::FieldContainer f2Weighted(*f2); Intrepid::FunctionSpaceTools::scalarMultiplyDataData(f2Weighted, // multiply with weighted measure *cellWeightedMeasure_, *f2); Intrepid::FunctionSpaceTools::integrate(*integral, // compute integral of f1 . f2 *f1, f2Weighted, Intrepid::COMP_CPP, sumInto); } /** \brief Computes the degrees of freedom on a side. */ std::vector computeBoundaryDofs(const int & locSideId) const { std::vector bdrydofs; std::vector nodeids, edgeids, faceids; if (cellTopo_->getDimension() == 1) { nodeids.push_back(locSideId); } else if (cellTopo_->getDimension() == 2) { edgeids.push_back(locSideId); int numVertices = 2; for (int i=0; igetNodeMap(1, locSideId, i)); } //for (unsigned i=0; i