// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file pde_darcy.hpp \brief Implements the local PDE interface for the Darcy porosity optimization problem. */ #ifndef PDE_DARCY_HPP #define PDE_DARCY_HPP #include "../../../../TOOLS/pde.hpp" #include "../../../../TOOLS/fe.hpp" #include "../../../../TOOLS/fieldhelper.hpp" #include "permeability.hpp" #include "../../../../TOOLS/Intrepid_HGRAD_C0_FEM.hpp" #include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" #include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" #include "Intrepid_HGRAD_TRI_C1_FEM.hpp" #include "Intrepid_HGRAD_TRI_C2_FEM.hpp" #include "Intrepid_DefaultCubatureFactory.hpp" #include "Intrepid_FunctionSpaceTools.hpp" #include "ROL_Ptr.hpp" template class PDE_Darcy : public PDE { private: // Finite element basis information ROL::Ptr>> basisPtrPrs_, basisPtrCtrl_; std::vector>>> basisPtrs_, basisPtrsCtrl_; // Cell cubature information ROL::Ptr> cellCub_, bdryCub_; // Cell node information ROL::Ptr> volCellNodes_; std::vector>>> bdryCellNodes_; std::vector>> bdryCellLocIds_; // Finite element definition ROL::Ptr> fePrs_, feCtrl_; std::vector>>> fePrsBdry_, feCtrlBdry_; // Local degrees of freedom on boundary, for each side of the reference cell (first index). std::vector> fpidx_; // Field pattern, offsets, etc. std::vector> fieldPattern_; // local Field/DOF pattern; set from DOF manager int numFields_; // number of fields (equations in the PDE) int numDofs_; // total number of degrees of freedom for all (local) fields std::vector offset_; // for each field, a counting offset std::vector numFieldDofs_; // for each field, number of degrees of freedom std::vector> fieldPatternCtrl_; // local Field/DOF pattern; set from DOF manager int numFieldsCtrl_; // number of fields (equations in the PDE) int numDofsCtrl_; // total number of degrees of freedom for all (local) fields std::vector offsetCtrl_; // for each field, a counting offset std::vector numFieldDofsCtrl_; // for each field, number of degrees of freedom // Problem parameters. Real Patm_, inVelocity_, dynvisco_; bool useNoSlip_; ROL::Ptr> perm_; ROL::Ptr fieldInfo_, fieldInfoCtrl_; void multiplyByRadius(ROL::Ptr> &input, const ROL::Ptr> &cubPts, bool isField, bool useReciprocal = false) const { int c = cubPts->dimension(0); int p = cubPts->dimension(1); Intrepid::FieldContainer r(c,p); for (int i = 0; i < c; ++i) { for (int j = 0; j < p; ++j) { if (!useReciprocal) r(i,j) = (*cubPts)(i,j,0); else r(i,j) = static_cast(1)/(*cubPts)(i,j,0); } } Intrepid::FieldContainer in = *input; if (!isField) Intrepid::FunctionSpaceTools::scalarMultiplyDataData(*input,r,in); else Intrepid::FunctionSpaceTools::scalarMultiplyDataField(*input,r,in); } public: PDE_Darcy(Teuchos::ParameterList &parlist) : Patm_(101.325 /* kg/mm-s^2 */) { // Finite element fields. int cubDegree = parlist.sublist("Problem").get("Cubature Degree",4); int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); int basisDegPres = parlist.sublist("Problem").get("Pressure Basis Degree",1); int basisDegCtrl = parlist.sublist("Problem").get("Density Basis Degree",1); std::string elemType = parlist.sublist("Problem").get("Element Type","TET"); if (elemType == "TET") { if (basisDegPres == 2) { basisPtrPrs_ = ROL::makePtr>>(); } else { std::cout << "\nFirst-order TET basis selected.\n"; basisPtrPrs_ = ROL::makePtr>>(); } if (basisDegCtrl == 1) { basisPtrCtrl_ = ROL::makePtr>>(); } else { basisPtrCtrl_ = ROL::makePtr>>(); } } else { if (basisDegPres == 2) { basisPtrPrs_ = ROL::makePtr>>(); } else { basisPtrPrs_ = ROL::makePtr>>(); } if (basisDegCtrl == 1) { basisPtrCtrl_ = ROL::makePtr>>(); } else { basisPtrCtrl_ = ROL::makePtr>>(); } } basisPtrs_.push_back(basisPtrPrs_); // Pressure component basisPtrsCtrl_.push_back(basisPtrCtrl_); // Control component // Quadrature rules. shards::CellTopology cellType = basisPtrs_[0]->getBaseCellTopology(); // get the cell type from any basis Intrepid::DefaultCubatureFactory cubFactory; // create cubature factory cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature shards::CellTopology bdryCellType = cellType.getCellTopologyData(1, 0); bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree); // Other problem parameters. dynvisco_ = parlist.sublist("Problem").get("Dynamic Viscosity", 0.84e-8); // kg/mm-s Real density = parlist.sublist("Problem").get("Fluid Density", 8.988e-11); // kg/mm^3 Real inRadius = parlist.sublist("Problem").get("Inlet Radius", 0.6875); // mm Real Reynolds = parlist.sublist("Problem").get("Reynolds Number", 50.0); // dimensionless inVelocity_ = Reynolds * dynvisco_ / (density*static_cast(2)*inRadius); // mm/s perm_ = ROL::makePtr>(parlist); useNoSlip_ = parlist.sublist("Problem").get("Use No Slip", false); numDofs_ = 0; numFields_ = basisPtrs_.size(); offset_.resize(numFields_); numFieldDofs_.resize(numFields_); for (int i=0; igetCardinality(); numFieldDofs_[i] = basisPtrs_[i]->getCardinality(); numDofs_ += numFieldDofs_[i]; } numDofsCtrl_ = 0; numFieldsCtrl_ = basisPtrsCtrl_.size(); offsetCtrl_.resize(numFieldsCtrl_); numFieldDofsCtrl_.resize(numFieldsCtrl_); for (int i=0; igetCardinality(); numFieldDofsCtrl_[i] = basisPtrsCtrl_[i]->getCardinality(); numDofsCtrl_ += numFieldDofsCtrl_[i]; } } void residual(ROL::Ptr> & res, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize residuals. res = ROL::makePtr>(c, f); // Evaluate/interpolate finite element fields on cells. ROL::Ptr> gradP, AgradP, valCtrl, alpha; gradP = ROL::makePtr>(c, p, d); AgradP = ROL::makePtr>(c, p, d); valCtrl = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); fePrs_->evaluateGradient(gradP, u_coeff); feCtrl_->evaluateValue(valCtrl, z_coeff); perm_->compute(alpha, valCtrl, fePrs_->cubPts(), 0); Intrepid::FunctionSpaceTools::scalarMultiplyDataData(*AgradP,*alpha,*gradP); /*** Evaluate weak form of the residual. ***/ //multiplyByRadius(AgradP,fePrs_->cubPts(),false); Intrepid::FunctionSpaceTools::integrate(*res, *AgradP, // p *fePrs_->gradNdetJ(), // dPhi/dx Intrepid::COMP_CPP, false); // Boundary conditions. int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { // APPLY DIRICHLET CONDITIONS for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition */ { const int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { const int numCellsSide = bdryCellLocIds_[i][j].size(); if (numCellsSide > 0) { const int numCubPerSide = fePrsBdry_[i][j]->cubPts()->dimension(1); ROL::Ptr> nRes, nVal; nRes = ROL::makePtr>(numCellsSide, f); nVal = ROL::makePtr>(numCellsSide, numCubPerSide); nVal->initialize(-inVelocity_); //multiplyByRadius(nVal,fePrsBdry_[i][j]->cubPts(),false); Intrepid::FunctionSpaceTools::integrate(*nRes, *nVal, *fePrsBdry_[i][j]->NdetJ(), Intrepid::COMP_CPP, false); for (int k = 0; k < numCellsSide; ++k) { const int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < f; ++l) { (*res)(cidx,l) += (*nRes)(k,l); } } } } } else if (i==1) /* outflow condition */ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { (*res)(cidx,fpidx_[j][l]) = (*u_coeff)(cidx,fpidx_[j][l]) - Patm_; } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } } void Jacobian_1(ROL::Ptr> & jac, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize Jacobians. jac = ROL::makePtr>(c, f, f); // Evaluate/interpolate finite element fields on cells. ROL::Ptr> alpha, alphaPhi, valCtrl; valCtrl = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); alphaPhi = ROL::makePtr>(c, f, p, d); feCtrl_->evaluateValue(valCtrl, z_coeff); perm_->compute(alpha, valCtrl, fePrs_->cubPts(), 0); // Multiply velocity with alpha Intrepid::FunctionSpaceTools::scalarMultiplyDataField(*alphaPhi, *alpha, *fePrs_->gradN()); /*** Evaluate weak form of the Jacobian. ***/ //multiplyByRadius(alphaPhi,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*jac, *alphaPhi, // alpha dPhi/dx *fePrs_->gradNdetJ(), // dPhi/dx Intrepid::COMP_CPP, false); // APPLY DIRICHLET CONDITIONS int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition */ {} else if (i==1) /* outflow condition */ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { for (int m = 0; m < f; ++m) { (*jac)(cidx,fpidx_[j][l],m) = static_cast(0); } (*jac)(cidx,fpidx_[j][l],fpidx_[j][l]) = static_cast(1); } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } } void Jacobian_2(ROL::Ptr> & jac, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int fc = feCtrl_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize Jacobians. jac = ROL::makePtr>(c, f, fc); // Evaluate on FE basis. ROL::Ptr> valZ, alpha, alphaN, gradP, gradPgradN; valZ = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); alphaN = ROL::makePtr>(c, fc, p); gradP = ROL::makePtr>(c, p, d); gradPgradN = ROL::makePtr>(c, f, p); fePrs_->evaluateGradient(gradP, u_coeff); feCtrl_->evaluateValue(valZ, z_coeff); perm_->compute(alpha, valZ, fePrs_->cubPts(), 1); Intrepid::FunctionSpaceTools::scalarMultiplyDataField(*alphaN,*alpha,*feCtrl_->N()); Intrepid::FunctionSpaceTools::dotMultiplyDataField(*gradPgradN,*gradP,*fePrs_->gradNdetJ()); /*** Evaluate weak form of the residual. ***/ //multiplyByRadius(gradPgradN,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*jac, *gradPgradN, // dP/dx dPhi/dx *alphaN, // alpha' Phi Intrepid::COMP_CPP, false); // APPLY DIRICHLET CONDITIONS int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition */ {} else if (i==1) /* outflow condition*/ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { for (int m=0; m < fc; ++m) { (*jac)(cidx,fpidx_[j][l],m) = static_cast(0); } } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } } void Jacobian_3(std::vector>> & jac, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Jacobian_3 is zero!"); } void Hessian_11(ROL::Ptr> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_11 is zero!"); } void Hessian_12(ROL::Ptr> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int fc = feCtrl_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize hessians. hess = ROL::makePtr>(c, fc, f); // Apply Dirichlet conditions ROL::Ptr> l0_coeff; l0_coeff = ROL::makePtr>(c, p); *l0_coeff = *l_coeff; int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition */ {} else if (i==1) /* outflow condition */ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { (*l0_coeff)(cidx,fpidx_[j][l]) = static_cast(0); } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } // Evaluate/interpolate finite element fields on cells. ROL::Ptr> valZ, alpha, gradL, alphaL; valZ = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); gradL = ROL::makePtr>(c, p, d); alphaL = ROL::makePtr>(c, fc, p, d); fePrs_->evaluateGradient(gradL, l0_coeff); feCtrl_->evaluateValue(valZ, z_coeff); perm_->compute(alpha, valZ, fePrs_->cubPts(), 1); /*** Evaluate weak form of the Hessian. ***/ // Multiply velocity with alpha for (int j = 0; j < c; ++j) { for (int k = 0; k < fc; ++k) { for (int l = 0; l < p; ++l) { for (int m = 0; m < d; ++m) { (*alphaL)(j,k,l,m) = (*alpha)(j,l) * (*feCtrl_->N())(j,k,l) * (*gradL)(j,l,m); } } } } //multiplyByRadius(alphaL,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*hess, *alphaL, // alpha' dL/dx Phi *fePrs_->gradNdetJ(), // dPhi/dx Intrepid::COMP_CPP, false); } void Hessian_13(std::vector>> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_13 is zero!"); } void Hessian_21(ROL::Ptr> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int fc = feCtrl_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize hessians. hess = ROL::makePtr>(c, f, fc); // Apply Dirichlet conditions ROL::Ptr> l0_coeff; l0_coeff = ROL::makePtr>(c, p); *l0_coeff = *l_coeff; int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition*/ {} else if (i==1) /* outflow condition */ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { (*l0_coeff)(cidx,fpidx_[j][l]) = static_cast(0); } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } // Evaluate/interpolate finite element fields on cells. ROL::Ptr> valZ, alpha, gradL, alphaL; valZ = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); gradL = ROL::makePtr>(c, p, d); alphaL = ROL::makePtr>(c, fc, p, d); fePrs_->evaluateGradient(gradL, l0_coeff); feCtrl_->evaluateValue(valZ, z_coeff); perm_->compute(alpha, valZ, fePrs_->cubPts(), 1); /*** Evaluate weak form of the Hessian. ***/ for (int j = 0; j < c; ++j) { for (int k = 0; k < fc; ++k) { for (int l = 0; l < p; ++l) { for (int m = 0; m < d; ++m) { (*alphaL)(j,k,l,m) = (*alpha)(j,l) * (*feCtrl_->N())(j,k,l) * (*gradL)(j,l,m); } } } } //multiplyByRadius(alphaL,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*hess, *fePrs_->gradNdetJ(), // dPhi/dx *alphaL, // alpha' dL/dx Phi Intrepid::COMP_CPP, false); } void Hessian_22(ROL::Ptr> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int fc = feCtrl_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize hessians. hess = ROL::makePtr>(c, fc, fc); // Apply Dirichlet conditions ROL::Ptr> l0_coeff; l0_coeff = ROL::makePtr>(c, p); *l0_coeff = *l_coeff; int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (i==0) /* inflow condition */ {} else if (i==1) /* outflow condition */ { int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { int numCellsSide = bdryCellLocIds_[i][j].size(); int numBdryDofs = fpidx_[j].size(); for (int k = 0; k < numCellsSide; ++k) { int cidx = bdryCellLocIds_[i][j][k]; for (int l = 0; l < numBdryDofs; ++l) { (*l0_coeff)(cidx,fpidx_[j][l]) = static_cast(0); } } } } else if (useNoSlip_ && i==2) /* do-nothing condition */ {} } } // Evaluate/interpolate finite element fields on cells. ROL::Ptr> valZ, alpha, alphaUL, gradL, gradU; valZ = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); alphaUL = ROL::makePtr>(c, fc, p); gradL = ROL::makePtr>(c, p, d); gradU = ROL::makePtr>(c, p, d); fePrs_->evaluateGradient(gradL, l0_coeff); fePrs_->evaluateGradient(gradU, u_coeff); feCtrl_->evaluateValue(valZ, z_coeff); perm_->compute(alpha, valZ, fePrs_->cubPts(), 2); // Multiply velocity with alpha Real dot(0); for (int i = 0; i < c; ++i) { for (int j = 0; j < fc; ++j) { for (int k = 0; k < p; ++k) { dot = static_cast(0); for (int l = 0; l < d; ++l) { dot += (*gradU)(i,k,l) * (*gradL)(i,k,l); } (*alphaUL)(i,j,k) = (*alpha)(i,k) * (*feCtrl_->N())(i,j,k) * dot; } } } /*** Evaluate weak form of the Hessian. ***/ // Velocity equation. //multiplyByRadius(alphaUL,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*hess, *alphaUL, // alpha'' dU/dx dL/dx Phi *feCtrl_->NdetJ(), // Phi Intrepid::COMP_CPP, false); } void Hessian_23(std::vector>> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_23 is zero!"); } void Hessian_31(std::vector>> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_31 is zero!"); } void Hessian_32(std::vector>> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_32 is zero!"); } void Hessian_33(std::vector>>> & hess, const ROL::Ptr> & l_coeff, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { throw Exception::Zero(">>> Hessian_33 is zero!"); } void RieszMap_1(ROL::Ptr> & riesz) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int f = fePrs_->gradN()->dimension(1); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Initialize Jacobians. riesz = ROL::makePtr>(c, f, f); // Evaluate/interpolate finite element fields on cells. ROL::Ptr> valPhi, gradPhi; valPhi = ROL::makePtr>(c, f, p); gradPhi = ROL::makePtr>(c, f, p, d); *valPhi = *fePrs_->N(); *gradPhi = *fePrs_->gradN(); /*** Evaluate weak form of the Jacobian. ***/ //multiplyByRadius(gradPhi,fePrs_->cubPts(),true); //multiplyByRadius(valPhi,fePrs_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*riesz, *gradPhi, // alpha dPhi/dx *fePrs_->gradNdetJ(), // dPhi/dx Intrepid::COMP_CPP, false); Intrepid::FunctionSpaceTools::integrate(*riesz, *valPhi, // alpha dPhi/dx *fePrs_->NdetJ(), // dPhi/dx Intrepid::COMP_CPP, true); } void RieszMap_2(ROL::Ptr> & riesz) override { // Retrieve dimensions. const int c = feCtrl_->gradN()->dimension(0); const int f = feCtrl_->gradN()->dimension(1); const int p = feCtrl_->gradN()->dimension(2); // Initialize Jacobians. riesz = ROL::makePtr>(c, f, f); // Evaluate on FE basis. ROL::Ptr> valPsi; valPsi = ROL::makePtr>(c, f, p); *valPsi = *feCtrl_->N(); /*** Evaluate weak form of the residual. ***/ //multiplyByRadius(valPsi,feCtrl_->cubPts(),true); Intrepid::FunctionSpaceTools::integrate(*riesz, *valPsi, // Psi *feCtrl_->NdetJ(), // Psi Intrepid::COMP_CPP, false); } std::vector>>> getFields() override { return basisPtrs_; } std::vector>>> getFields2() override { return basisPtrsCtrl_; } void setCellNodes(const ROL::Ptr> &volCellNodes, const std::vector>>> &bdryCellNodes, const std::vector>> &bdryCellLocIds) override { volCellNodes_ = volCellNodes; bdryCellNodes_ = bdryCellNodes; bdryCellLocIds_ = bdryCellLocIds; // Finite element definition. fePrs_ = ROL::makePtr>(volCellNodes_,basisPtrPrs_,cellCub_); feCtrl_ = ROL::makePtr>(volCellNodes_,basisPtrCtrl_,cellCub_,false); fpidx_ = fePrs_->getBoundaryDofs(); // Construct control boundary FE int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { fePrsBdry_.resize(numSideSets); feCtrlBdry_.resize(numSideSets); for (int i = 0; i < numSideSets; ++i) { int numLocSides = bdryCellNodes[i].size(); fePrsBdry_[i].resize(numLocSides); feCtrlBdry_[i].resize(numLocSides); for (int j = 0; j < numLocSides; ++j) { if (bdryCellNodes[i][j] != ROL::nullPtr) { fePrsBdry_[i][j] = ROL::makePtr>(bdryCellNodes[i][j],basisPtrPrs_,bdryCub_,j); feCtrlBdry_[i][j] = ROL::makePtr>(bdryCellNodes[i][j],basisPtrCtrl_,bdryCub_,j); } } } } } void setFieldPattern(const std::vector> &fieldPattern, const std::vector> &fieldPattern2) override { fieldPattern_ = fieldPattern; fieldInfo_ = ROL::makePtr(numFields_,numDofs_,numFieldDofs_,fieldPattern_); fieldPatternCtrl_ = fieldPattern2; fieldInfoCtrl_ = ROL::makePtr(numFieldsCtrl_,numDofsCtrl_,numFieldDofsCtrl_,fieldPatternCtrl_); } void printData(std::string tag, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Evaluate/interpolate finite element fields on cells. ROL::Ptr> gradP, AgradP, valCtrl, alpha; gradP = ROL::makePtr>(c, p, d); AgradP = ROL::makePtr>(c, p, d); valCtrl = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); fePrs_->evaluateGradient(gradP, u_coeff); feCtrl_->evaluateValue(valCtrl, z_coeff); perm_->compute(alpha, valCtrl, fePrs_->cubPts(), 0); Intrepid::FunctionSpaceTools::scalarMultiplyDataData(*AgradP,*alpha,*gradP); // Print to velocity file std::stringstream nameVel; nameVel << "velocity" << tag << ".txt"; std::ofstream fileVel; fileVel.open(nameVel.str()); for (int i = 0; i < c; ++i) { for (int j = 0; j < p; ++j) { fileVel << std::scientific << std::setprecision(15); for (int k = 0; k < d; ++k) fileVel << std::setw(25) << (*fePrs_->cubPts())(i,j,k); for (int k = 0; k < d; ++k) fileVel << std::setw(25) << -(*AgradP)(i,j,k); fileVel << std::endl; } } fileVel.close(); // Print to permeability file std::stringstream namePer; namePer << "permeability" << tag << ".txt"; std::ofstream filePer; filePer.open(namePer.str()); for (int i = 0; i < c; ++i) { for (int j = 0; j < p; ++j) { filePer << std::scientific << std::setprecision(15); for (int k = 0; k < d; ++k) filePer << std::setw(25) << (*fePrs_->cubPts())(i,j,k); filePer << std::setw(25) << dynvisco_*(*alpha)(i,j); filePer << std::endl; } } filePer.close(); } void printCellAverages(std::string tag, const ROL::Ptr> & u_coeff, const ROL::Ptr> & z_coeff = ROL::nullPtr, const ROL::Ptr> & z_param = ROL::nullPtr) override { // Retrieve dimensions. const int c = fePrs_->gradN()->dimension(0); const int p = fePrs_->gradN()->dimension(2); const int d = fePrs_->gradN()->dimension(3); // Evaluate/interpolate finite element fields on cells. ROL::Ptr> gradP, AgradP, velX, velY, velZ, valCtrl, alpha; ROL::Ptr> onesVec, cellVol, avgX, avgY, avgZ, avgP; gradP = ROL::makePtr>(c, p, d); AgradP = ROL::makePtr>(c, p, d); velX = ROL::makePtr>(c, p); velY = ROL::makePtr>(c, p); velZ = ROL::makePtr>(c, p); valCtrl = ROL::makePtr>(c, p); alpha = ROL::makePtr>(c, p); onesVec = ROL::makePtr>(c, p); cellVol = ROL::makePtr>(c); avgX = ROL::makePtr>(c); avgY = ROL::makePtr>(c); avgZ = ROL::makePtr>(c); avgP = ROL::makePtr>(c); fePrs_->evaluateGradient(gradP, u_coeff); feCtrl_->evaluateValue(valCtrl, z_coeff); onesVec->initialize(1.0); perm_->compute(alpha, valCtrl, fePrs_->cubPts(), 0); Intrepid::FunctionSpaceTools::scalarMultiplyDataData(*AgradP,*alpha,*gradP); // Extract velocity components. for (int i = 0; i < c; ++i) { for (int j = 0; j < p; ++j) { (*velX)(i,j) = -(*AgradP)(i,j,0); (*velY)(i,j) = -(*AgradP)(i,j,1); (*velZ)(i,j) = -(*AgradP)(i,j,2); } } // Compute cell volumes. Intrepid::FunctionSpaceTools::integrate(*cellVol, *onesVec, // 1 *onesVec, // 1 Intrepid::COMP_CPP, false); // Compute velocity X cell average. Intrepid::FunctionSpaceTools::integrate(*avgX, *velX, // scalar data *onesVec, // 1 Intrepid::COMP_CPP, false); for (int i = 0; i < c; ++i) {(*avgX)(i) /= (*cellVol)(i);} // Compute velocity Y cell average. Intrepid::FunctionSpaceTools::integrate(*avgY, *velY, // scalar data *onesVec, // 1 Intrepid::COMP_CPP, false); for (int i = 0; i < c; ++i) {(*avgY)(i) /= (*cellVol)(i);} // Compute velocity Z cell average. Intrepid::FunctionSpaceTools::integrate(*avgZ, *velZ, // scalar data *onesVec, // 1 Intrepid::COMP_CPP, false); for (int i = 0; i < c; ++i) {(*avgZ)(i) /= (*cellVol)(i);} // Compute permeability cell average. Intrepid::FunctionSpaceTools::integrate(*avgP, *alpha, // scalar data *onesVec, // 1 Intrepid::COMP_CPP, false); for (int i = 0; i < c; ++i) {(*avgP)(i) /= (*cellVol)(i);} Intrepid::RealSpaceTools::scale(*avgP, dynvisco_); // Print to velocity file std::stringstream nameVel; nameVel << "velocity" << tag << ".txt"; std::ofstream fileVel; fileVel.open(nameVel.str()); for (int i = 0; i < c; ++i) { fileVel << std::scientific << std::setprecision(15); fileVel << std::setw(25) << (*avgX)(i); fileVel << std::setw(25) << (*avgY)(i); fileVel << std::setw(25) << (*avgZ)(i); fileVel << std::endl; } fileVel.close(); // Print to permeability file std::stringstream namePer; namePer << "permeability" << tag << ".txt"; std::ofstream filePer; filePer.open(namePer.str()); for (int i = 0; i < c; ++i) { filePer << std::scientific << std::setprecision(15); filePer << std::setw(25) << (*avgP)(i); filePer << std::endl; } filePer.close(); } const ROL::Ptr> getPressureFE(void) const { return fePrs_; } const ROL::Ptr> getControlFE(void) const { return feCtrl_; } const std::vector>> getPressureBdryFE(const int sideset = -1) const { int side = (sideset < 0 || sideset > 3) ? 0 : sideset; return fePrsBdry_[side]; } const std::vector>> getControlBdryFE(const int sideset = -1) const { int side = (sideset < 0 || sideset > 3) ? 0 : sideset; return feCtrlBdry_[side]; } const std::vector> getBdryCellLocIds(const int sideset = -1) const { int side = (sideset < 0 || sideset > 3) ? 0 : sideset; return bdryCellLocIds_[side]; } const ROL::Ptr> getPermeability(void) const { return perm_; } const ROL::Ptr getStateFieldInfo(void) const { return fieldInfo_; } const ROL::Ptr getControlFieldInfo(void) const { return fieldInfoCtrl_; } }; // PDE_Darcy #endif