| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Panzer: A partial differential equation assembly |
| 4 |
// engine for strongly coupled complex multiphysics systems |
| 5 |
// |
| 6 |
// Copyright 2011 NTESS and the Panzer contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
|
| 11 |
#include <Teuchos_ConfigDefs.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_TimeMonitor.hpp> |
| 15 |
|
| 16 |
using Teuchos::RCP; |
| 17 |
using Teuchos::rcp; |
| 18 |
|
| 19 |
#include "Teuchos_DefaultComm.hpp" |
| 20 |
#include "Teuchos_GlobalMPISession.hpp" |
| 21 |
|
| 22 |
#include "Panzer_FieldManagerBuilder.hpp" |
| 23 |
#include "Panzer_DOFManager.hpp" |
| 24 |
#include "Panzer_PureBasis.hpp" |
| 25 |
#include "Panzer_BasisIRLayout.hpp" |
| 26 |
#include "Panzer_Workset.hpp" |
| 27 |
#include "Panzer_Integrator_BasisTimesVector.hpp" |
| 28 |
#include "Panzer_WorksetContainer.hpp" |
| 29 |
|
| 30 |
#include "Panzer_STK_Version.hpp" |
| 31 |
#include "PanzerAdaptersSTK_config.hpp" |
| 32 |
#include "Panzer_STK_Interface.hpp" |
| 33 |
#include "Panzer_STK_SquareQuadMeshFactory.hpp" |
| 34 |
#include "Panzer_STK_SetupUtilities.hpp" |
| 35 |
#include "Panzer_STKConnManager.hpp" |
| 36 |
#include "Panzer_STK_WorksetFactory.hpp" |
| 37 |
|
| 38 |
#include "Teuchos_DefaultMpiComm.hpp" |
| 39 |
#include "Teuchos_OpaqueWrapper.hpp" |
| 40 |
|
| 41 |
#include "PointEvaluator.hpp" |
| 42 |
|
| 43 |
#include "user_app_EquationSetFactory.hpp" |
| 44 |
|
| 45 |
#include <cstdio> // for get char |
| 46 |
#include <vector> |
| 47 |
#include <string> |
| 48 |
|
| 49 |
#include "Panzer_Evaluator_WithBaseImpl.hpp" |
| 50 |
|
| 51 |
namespace panzer { |
| 52 |
|
| 53 |
Teuchos::RCP<panzer::PureBasis> buildBasis(const std::size_t& worksetSize,const std::string & basisName); |
| 54 |
void testInitialization(const Teuchos::RCP<Teuchos::ParameterList>& ipb); |
| 55 |
Teuchos::RCP<panzer_stk::STK_Interface> buildMesh(int elemX,int elemY); |
| 56 |
Teuchos::RCP<panzer::IntegrationRule> buildIR(const std::size_t& worksetSize,const int& cubature_degree); |
| 57 |
|
| 58 |
class BilinearPointEvaluator : public PointEvaluation<panzer::Traits::Residual::ScalarT> { |
| 59 |
public: |
| 60 |
virtual ~BilinearPointEvaluator() {} |
| 61 |
virtual void evaluateContainer(const PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::IP,panzer::Dim> & points, |
| 62 |
PHX::MDField<panzer::Traits::Residual::ScalarT> & field) const |
| 63 |
{ |
| 64 |
int num_cells = field.extent(0); |
| 65 |
int num_qp = points.extent(1); |
| 66 |
auto points_v = points.get_static_view(); |
| 67 |
auto field_v = field.get_static_view(); |
| 68 |
Kokkos::parallel_for(num_cells, KOKKOS_LAMBDA (int i) { |
| 69 |
for(int j=0;j<num_qp;j++) { |
| 70 |
double x = points(i,j,0); // just x and y |
| 71 |
double y = points(i,j,1); |
| 72 |
|
| 73 |
field(i,j,0) = (x+y)*(x+y); |
| 74 |
field(i,j,1) = sin(x+y); |
| 75 |
} |
| 76 |
}); |
| 77 |
} |
| 78 |
}; |
| 79 |
|
| 80 |
TEUCHOS_UNIT_TEST(basis_time_vector, residual) |
| 81 |
{ |
| 82 |
|
| 83 |
const std::size_t workset_size = 1; |
| 84 |
const std::string fieldName_q1 = "TEMPERATURE"; |
| 85 |
const std::string fieldName_qedge1 = "ION_TEMPERATURE"; |
| 86 |
|
| 87 |
Teuchos::RCP<panzer_stk::STK_Interface> mesh = buildMesh(1,1); |
| 88 |
|
| 89 |
// build input physics block |
| 90 |
Teuchos::RCP<panzer::PureBasis> basis_q1 = buildBasis(workset_size,"Q1"); |
| 91 |
Teuchos::RCP<panzer::PureBasis> basis_qedge1 = buildBasis(workset_size,"QEdge1"); |
| 92 |
|
| 93 |
Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList(); |
| 94 |
testInitialization(ipb); |
| 95 |
|
| 96 |
const int default_int_order = 1; |
| 97 |
std::string eBlockID = "eblock-0_0"; |
| 98 |
Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); |
| 99 |
panzer::CellData cellData(workset_size,mesh->getCellTopology("eblock-0_0")); |
| 100 |
Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); |
| 101 |
Teuchos::RCP<panzer::PhysicsBlock> physicsBlock = |
| 102 |
Teuchos::rcp(new PhysicsBlock(ipb,eBlockID,default_int_order,cellData,eqset_factory,gd,false)); |
| 103 |
|
| 104 |
Teuchos::RCP<panzer::IntegrationRule> ir = buildIR(workset_size,4); |
| 105 |
Teuchos::RCP<panzer::BasisIRLayout> layout_qedge1 = Teuchos::rcp(new panzer::BasisIRLayout(basis_qedge1,*ir)); |
| 106 |
|
| 107 |
// build connection manager and field manager |
| 108 |
const Teuchos::RCP<panzer::ConnManager> conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh)); |
| 109 |
RCP<panzer::DOFManager> dofManager = Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD)); |
| 110 |
dofManager->addField(fieldName_q1,Teuchos::rcp(new panzer::Intrepid2FieldPattern(basis_q1->getIntrepid2Basis()))); |
| 111 |
dofManager->addField(fieldName_qedge1,Teuchos::rcp(new panzer::Intrepid2FieldPattern(basis_qedge1->getIntrepid2Basis()))); |
| 112 |
dofManager->setOrientationsRequired(true); |
| 113 |
dofManager->buildGlobalUnknowns(); |
| 114 |
|
| 115 |
// build worksets |
| 116 |
std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; |
| 117 |
physicsBlocks.push_back(physicsBlock); // pushing back singular |
| 118 |
|
| 119 |
panzer::WorksetContainer wkstContainer; // (Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)),physicsBlocks,workset_size); |
| 120 |
|
| 121 |
wkstContainer.setFactory(Teuchos::rcp(new panzer_stk::WorksetFactory(mesh))); |
| 122 |
for(size_t i=0;i<physicsBlocks.size();i++) |
| 123 |
wkstContainer.setNeeds(physicsBlocks[i]->elementBlockID(),physicsBlocks[i]->getWorksetNeeds()); |
| 124 |
wkstContainer.setGlobalIndexer(dofManager); |
| 125 |
wkstContainer.setWorksetSize(workset_size); |
| 126 |
|
| 127 |
const panzer::WorksetDescriptor wd = panzer::blockDescriptor(eBlockID); |
| 128 |
Teuchos::RCP<std::vector<panzer::Workset> > work_sets = wkstContainer.getWorksets(wd); |
| 129 |
TEST_EQUALITY(work_sets->size(),1); |
| 130 |
|
| 131 |
// setup field manager, add evaluator under test |
| 132 |
///////////////////////////////////////////////////////////// |
| 133 |
|
| 134 |
PHX::FieldManager<panzer::Traits> fm; |
| 135 |
|
| 136 |
{ |
| 137 |
Teuchos::ParameterList pl; |
| 138 |
pl.set("Name","Integrand"); |
| 139 |
pl.set("IR",ir); |
| 140 |
pl.set("Is Vector",true); |
| 141 |
pl.set<Teuchos::RCP<const PointEvaluation<panzer::Traits::Residual::ScalarT> > >("Point Evaluator", |
| 142 |
Teuchos::rcp(new BilinearPointEvaluator)); |
| 143 |
|
| 144 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator |
| 145 |
= Teuchos::rcp(new PointEvaluator<panzer::Traits::Residual,panzer::Traits>(pl)); |
| 146 |
|
| 147 |
fm.registerEvaluator<panzer::Traits::Residual>(evaluator); |
| 148 |
} |
| 149 |
|
| 150 |
{ |
| 151 |
Teuchos::ParameterList pl; |
| 152 |
pl.set("Residual Name","Residual"); |
| 153 |
pl.set("Value Name","Integrand"); |
| 154 |
// pl.set("Test Field Name",fieldName_qedge1); |
| 155 |
pl.set("Basis",layout_qedge1); |
| 156 |
pl.set("IR",ir); |
| 157 |
pl.set<double>("Multiplier", 1.0); |
| 158 |
Teuchos::RCP<const std::vector<std::string> > vec |
| 159 |
= Teuchos::rcp(new std::vector<std::string>); |
| 160 |
pl.set("Field Multipliers", vec); |
| 161 |
|
| 162 |
Teuchos::RCP<PHX::Evaluator<panzer::Traits> > evaluator |
| 163 |
= Teuchos::rcp(new panzer::Integrator_BasisTimesVector<panzer::Traits::Residual,panzer::Traits>(pl)); |
| 164 |
|
| 165 |
fm.registerEvaluator<panzer::Traits::Residual>(evaluator); |
| 166 |
fm.requireField<panzer::Traits::Residual>(*evaluator->evaluatedFields()[0]); |
| 167 |
} |
| 168 |
|
| 169 |
std::vector<PHX::index_size_type> derivative_dimensions; |
| 170 |
derivative_dimensions.push_back(8); |
| 171 |
fm.setKokkosExtendedDataTypeDimensions<panzer::Traits::Jacobian>(derivative_dimensions); |
| 172 |
|
| 173 |
panzer::Traits::SD sd; |
| 174 |
sd.worksets_ = work_sets; |
| 175 |
fm.postRegistrationSetup(sd); |
| 176 |
|
| 177 |
// run tests |
| 178 |
///////////////////////////////////////////////////////////// |
| 179 |
|
| 180 |
panzer::Workset & workset = (*work_sets)[0]; |
| 181 |
workset.alpha = 0.0; |
| 182 |
workset.beta = 0.0; |
| 183 |
workset.time = 0.0; |
| 184 |
workset.evaluate_transient_terms = false; |
| 185 |
|
| 186 |
fm.evaluateFields<panzer::Traits::Residual>(workset); |
| 187 |
|
| 188 |
PHX::MDField<panzer::Traits::Residual::ScalarT,panzer::Cell,panzer::BASIS> |
| 189 |
fieldData_qedge1("Residual",basis_qedge1->functional); |
| 190 |
|
| 191 |
fm.getFieldData<panzer::Traits::Residual>(fieldData_qedge1); |
| 192 |
|
| 193 |
TEST_EQUALITY(fieldData_qedge1.extent(0),1); |
| 194 |
TEST_EQUALITY(fieldData_qedge1.extent(1),4); |
| 195 |
|
| 196 |
// Transformation is [x,y] = F[x_ref,y_ref] = 0.5*[1,1]+0.5*[1,0;0,1]*[x_ref,y_ref] |
| 197 |
// therefore transformation matrix is DF^{-T} = 2*[1,0;0,1] |
| 198 |
// so curl vector u_ref:Ref_coord=>Ref_Vec transforms with |
| 199 |
// |
| 200 |
// u(x,y)=DF^{-T}*u_ref(F^{-1}(x,y)) |
| 201 |
|
| 202 |
auto fieldData_qedge1_h = Kokkos::create_mirror_view(fieldData_qedge1.get_view()); |
| 203 |
Kokkos::deep_copy(fieldData_qedge1_h, fieldData_qedge1.get_view()); |
| 204 |
TEST_FLOATING_EQUALITY(fieldData_qedge1_h(0,0),5.0/6.0,1e-5); // 0 edge basis is [(1-y_ref)/2, 0] |
| 205 |
TEST_FLOATING_EQUALITY(fieldData_qedge1_h(0,2),3.0/2.0,1e-5); // 2 edge basis is [(1+y_ref)/2, 0] |
| 206 |
|
| 207 |
// these two have sign changes because of the mesh topology! |
| 208 |
TEST_FLOATING_EQUALITY(fieldData_qedge1_h(0,1),2*0.428925006266,1e-5); // 1 edge basis is [(1+x_ref)/2, 0] |
| 209 |
TEST_FLOATING_EQUALITY(fieldData_qedge1_h(0,3),2*0.344719536524,1e-5); // 3 edge basis is [(1-x_ref)/2, 0] |
| 210 |
} |
| 211 |
|
| 212 |
Teuchos::RCP<panzer::IntegrationRule> buildIR(const std::size_t& workset_size, const int& cubature_degree) |
| 213 |
{ |
| 214 |
Teuchos::RCP<shards::CellTopology> topo = |
| 215 |
Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); |
| 216 |
|
| 217 |
const panzer::CellData cell_data(workset_size,topo); |
| 218 |
|
| 219 |
return Teuchos::rcp(new panzer::IntegrationRule(cubature_degree, cell_data)); |
| 220 |
} |
| 221 |
|
| 222 |
Teuchos::RCP<panzer::PureBasis> buildBasis(const std::size_t& worksetSize, |
| 223 |
const std::string& basisName) |
| 224 |
{ |
| 225 |
Teuchos::RCP<shards::CellTopology> topo = |
| 226 |
Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); |
| 227 |
|
| 228 |
panzer::CellData cellData(worksetSize,topo); |
| 229 |
// hard coded to first order |
| 230 |
return Teuchos::rcp(new panzer::PureBasis(basisName,1,cellData)); |
| 231 |
} |
| 232 |
|
| 233 |
Teuchos::RCP<panzer_stk::STK_Interface> buildMesh(int elemX,int elemY) |
| 234 |
{ |
| 235 |
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); |
| 236 |
pl->set("X Blocks",1); |
| 237 |
pl->set("Y Blocks",1); |
| 238 |
pl->set("X Elements",elemX); |
| 239 |
pl->set("Y Elements",elemY); |
| 240 |
|
| 241 |
panzer_stk::SquareQuadMeshFactory factory; |
| 242 |
factory.setParameterList(pl); |
| 243 |
RCP<panzer_stk::STK_Interface> mesh = factory.buildUncommitedMesh(MPI_COMM_WORLD); |
| 244 |
factory.completeMeshConstruction(*mesh,MPI_COMM_WORLD); |
| 245 |
|
| 246 |
return mesh; |
| 247 |
} |
| 248 |
|
| 249 |
void testInitialization(const Teuchos::RCP<Teuchos::ParameterList>& ipb) |
| 250 |
{ |
| 251 |
// Physics block |
| 252 |
ipb->setName("test physics"); |
| 253 |
{ |
| 254 |
Teuchos::ParameterList& p = ipb->sublist("a"); |
| 255 |
p.set("Type","Energy"); |
| 256 |
p.set("Prefix",""); |
| 257 |
p.set("Model ID","solid"); |
| 258 |
p.set("Basis Type","HGrad"); |
| 259 |
p.set("Basis Order",2); |
| 260 |
p.set("Integration Order",1); |
| 261 |
} |
| 262 |
{ |
| 263 |
Teuchos::ParameterList& p = ipb->sublist("b"); |
| 264 |
p.set("Type","Energy"); |
| 265 |
p.set("Prefix","ION_"); |
| 266 |
p.set("Model ID","solid"); |
| 267 |
p.set("Basis Type","HCurl"); |
| 268 |
p.set("Basis Order",1); |
| 269 |
p.set("Integration Order",4); |
| 270 |
} |
| 271 |
|
| 272 |
} |
| 273 |
|
| 274 |
} |