TEUCHOS_UNIT_TEST(integration_values, volume) { PHX::KokkosDeviceSession session; Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 20; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); const int cubature_degree = 2; RCP<IntegrationRule> int_rule = rcp(new IntegrationRule(cubature_degree, cell_data)); panzer::IntegrationValues<double,Intrepid::FieldContainer<double> > int_values; int_values.setupArrays(int_rule); const int num_vertices = int_rule->topology->getNodeCount(); FieldContainer<double> node_coordinates(num_cells, num_vertices, base_cell_dimension); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) typedef panzer::ArrayTraits<double,FieldContainer<double> >::size_type size_type; const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { node_coordinates(cell,0,x) = 0.0; node_coordinates(cell,0,y) = 0.0; node_coordinates(cell,1,x) = 1.0; node_coordinates(cell,1,y) = 0.0; node_coordinates(cell,2,x) = 1.0; node_coordinates(cell,2,y) = 1.0; node_coordinates(cell,3,x) = 0.0; node_coordinates(cell,3,y) = 1.0; } int_values.evaluateValues(node_coordinates); TEST_EQUALITY(int_values.ip_coordinates.dimension(1), 4); double realspace_x_coord = (1.0/std::sqrt(3.0) + 1.0) / 2.0; double realspace_y_coord = (1.0/std::sqrt(3.0) + 1.0) / 2.0; TEST_FLOATING_EQUALITY(int_values.ip_coordinates(0,0,0), realspace_x_coord, 1.0e-8); TEST_FLOATING_EQUALITY(int_values.ip_coordinates(0,0,1), realspace_y_coord, 1.0e-8); }
void PointValues<Scalar,Array>:: copyNodeCoords(const CoordinateArray& in_node_coords) { // copy cell node coordinates { size_type num_cells = in_node_coords.dimension(0); size_type num_nodes = in_node_coords.dimension(1); size_type num_dims = in_node_coords.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_coords(cell,node,dim); } }
void IntegrationValues2<Scalar>:: getCubatureCV(const PHX::MDField<Scalar,Cell,NODE,Dim>& 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 infrastructure does not exist!!! Will not be able to do " << "non-natural integration rules."; return; } { 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); dyn_node_coordinates(cell,node,dim) = Sacado::ScalarValue<Scalar>::eval(in_node_coordinates(cell,node,dim)); } } } } if (int_rule->cv_type == "side") intrepid_cubature->getCubature(dyn_phys_cub_points.get_view(),dyn_phys_cub_norms.get_view(),dyn_node_coordinates.get_view()); else intrepid_cubature->getCubature(dyn_phys_cub_points.get_view(),dyn_phys_cub_weights.get_view(),dyn_node_coordinates.get_view()); size_type num_cells = dyn_phys_cub_points.dimension(0); size_type num_ip =dyn_phys_cub_points.dimension(1); size_type num_dims = dyn_phys_cub_points.dimension(2); for (size_type cell = 0; cell < num_cells; ++cell) { for (size_type ip = 0; ip < num_ip; ++ip) { if (int_rule->cv_type != "side") weighted_measure(cell,ip) = dyn_phys_cub_weights(cell,ip); for (size_type dim = 0; dim < num_dims; ++dim) { ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim); if (int_rule->cv_type == "side") weighted_normals(cell,ip,dim) = dyn_phys_cub_norms(cell,ip,dim); } } } }
void use_case_5_generate_mesh( const std::string& mesh_options , stk::mesh::BulkData & mesh , const VectorFieldType & node_coord , stk::mesh::Part & hex_block , stk::mesh::Part & quad_shell_block ) { mesh.modification_begin(); const unsigned parallel_size = mesh.parallel_size(); const unsigned parallel_rank = mesh.parallel_rank(); double t = 0 ; size_t num_hex = 0 ; size_t num_shell = 0 ; size_t num_nodes = 0 ; size_t num_block = 0 ; int error_flag = 0 ; try { Iogn::GeneratedMesh gmesh( mesh_options, parallel_size, parallel_rank ); num_nodes = gmesh.node_count_proc(); num_block = gmesh.block_count(); t = stk::wall_time(); std::vector<int> node_map( num_nodes , 0 ); gmesh.node_map( node_map ); { for ( size_t i = 1 ; i <= num_block ; ++i ) { const size_t num_elem = gmesh.element_count_proc(i); const std::pair<std::string,int> top_info = gmesh.topology_type(i); std::vector<int> elem_map( num_elem , 0 ); std::vector<int> elem_conn( num_elem * top_info.second ); gmesh.element_map( i, elem_map ); gmesh.connectivity( i , elem_conn ); if ( top_info.second == 8 ) { for ( size_t j = 0 ; j < num_elem ; ++j ) { const int * const local_node_id = & elem_conn[ j * 8 ] ; const stk::mesh::EntityId node_id[8] = { local_node_id[0] , local_node_id[1] , local_node_id[2] , local_node_id[3] , local_node_id[4] , local_node_id[5] , local_node_id[6] , local_node_id[7] }; const stk::mesh::EntityId elem_id = elem_map[ j ]; stk::mesh::fem::declare_element( mesh , hex_block , elem_id , node_id ); ++num_hex ; } } else if ( top_info.second == 4 ) { for ( size_t j = 0 ; j < num_elem ; ++j ) { const int * const local_node_id = & elem_conn[ j * 4 ] ; const stk::mesh::EntityId node_id[4] = { local_node_id[0] , local_node_id[1] , local_node_id[2] , local_node_id[3] }; const stk::mesh::EntityId elem_id = elem_map[ j ]; stk::mesh::fem::declare_element( mesh , quad_shell_block , elem_id , node_id ); ++num_shell ; } } } } std::vector<double> node_coordinates( 3 * node_map.size() ); gmesh.coordinates( node_coordinates ); if ( 3 * node_map.size() != node_coordinates.size() ) { std::ostringstream msg ; msg << " P" << mesh.parallel_rank() << ": ERROR, node_map.size() = " << node_map.size() << " , node_coordinates.size() / 3 = " << ( node_coordinates.size() / 3 ); throw std::runtime_error( msg.str() ); } for ( unsigned i = 0 ; i < node_map.size() ; ++i ) { const unsigned i3 = i * 3 ; stk::mesh::Entity * const node = mesh.get_entity( stk::mesh::fem::FEMMetaData::NODE_RANK , node_map[i] ); if ( NULL == node ) { std::ostringstream msg ; msg << " P:" << mesh.parallel_rank() << " ERROR, Node not found: " << node_map[i] << " = node_map[" << i << "]" ; throw std::runtime_error( msg.str() ); } double * const data = field_data( node_coord , *node ); data[0] = node_coordinates[ i3 + 0 ]; data[1] = node_coordinates[ i3 + 1 ]; data[2] = node_coordinates[ i3 + 2 ]; } } catch ( const std::exception & X ) { std::cout << " P:" << mesh.parallel_rank() << ": " << X.what() << std::endl ; std::cout.flush(); error_flag = 1 ; } catch( ... ) { std::cout << " P:" << mesh.parallel_rank() << " Caught unknown exception" << std::endl ; std::cout.flush(); error_flag = 1 ; } stk::all_reduce( mesh.parallel() , stk::ReduceMax<1>( & error_flag ) ); if ( error_flag ) { std::string msg( "Failed mesh generation" ); throw std::runtime_error( msg ); } mesh.modification_end(); double dt = stk::wall_dtime( t ); stk::all_reduce( mesh.parallel() , stk::ReduceMax<1>( & dt ) ); std::cout << " P" << mesh.parallel_rank() << ": Meshed Hex = " << num_hex << " , Shell = " << num_shell << " , Node = " << num_nodes << " in " << dt << " sec" << std::endl ; std::cout.flush(); }
void IntegrationValues2<Scalar>:: evaluateValuesCV(const PHX::MDField<Scalar,Cell,NODE,Dim> & in_node_coordinates) { Intrepid2::CellTools<Scalar> cell_tools; { 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); dyn_node_coordinates(cell,node,dim) = Sacado::ScalarValue<Scalar>::eval(in_node_coordinates(cell,node,dim)); } } } } if (int_rule->cv_type == "volume") intrepid_cubature->getCubature(dyn_phys_cub_points,dyn_phys_cub_weights,dyn_node_coordinates); else if (int_rule->cv_type == "side") intrepid_cubature->getCubature(dyn_phys_cub_points,dyn_phys_cub_norms,dyn_node_coordinates); if (int_rule->cv_type == "volume") { size_type num_cells = dyn_phys_cub_points.dimension(0); size_type num_ip = dyn_phys_cub_points.dimension(1); size_type num_dims = dyn_phys_cub_points.dimension(2); for (size_type cell = 0; cell < num_cells; ++cell) { for (size_type ip = 0; ip < num_ip; ++ip) { weighted_measure(cell,ip) = dyn_phys_cub_weights(cell,ip); for (size_type dim = 0; dim < num_dims; ++dim) ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim); } } cell_tools.mapToReferenceFrame(ref_ip_coordinates, ip_coordinates, node_coordinates, *(int_rule->topology),-1); cell_tools.setJacobian(jac, ref_ip_coordinates, node_coordinates, *(int_rule->topology)); } else if (int_rule->cv_type == "side") { size_type num_cells = dyn_phys_cub_points.dimension(0); size_type num_ip = dyn_phys_cub_points.dimension(1); size_type num_dims = dyn_phys_cub_points.dimension(2); for (size_type cell = 0; cell < num_cells; ++cell) { for (size_type ip = 0; ip < num_ip; ++ip) { for (size_type dim = 0; dim < num_dims; ++dim) { ip_coordinates(cell,ip,dim) = dyn_phys_cub_points(cell,ip,dim); weighted_normals(cell,ip,dim) = dyn_phys_cub_norms(cell,ip,dim); } } } cell_tools.mapToReferenceFrame(ref_ip_coordinates, ip_coordinates, node_coordinates, *(int_rule->topology),-1); cell_tools.setJacobian(jac, ref_ip_coordinates, node_coordinates, *(int_rule->topology)); } cell_tools.setJacobianInv(jac_inv, jac); cell_tools.setJacobianDet(jac_det, jac); }
void IntegrationValues2<Scalar>:: evaluateRemainingValues(const PHX::MDField<Scalar,Cell,NODE,Dim>& in_node_coordinates) { Intrepid2::CellTools<Scalar> 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, cub_points, node_coordinates, *(int_rule->topology)); cell_tools.setJacobianInv(jac_inv, jac); cell_tools.setJacobianDet(jac_det, jac); if (!int_rule->isSide()) { Intrepid2::FunctionSpaceTools:: computeCellMeasure<Scalar>(weighted_measure, jac_det, cub_weights); } else if(int_rule->spatial_dimension==3) { Intrepid2::FunctionSpaceTools:: computeFaceMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology); } else if(int_rule->spatial_dimension==2) { Intrepid2::FunctionSpaceTools:: computeEdgeMeasure<Scalar>(weighted_measure, jac, cub_weights,int_rule->side,*int_rule->topology); } 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<Scalar>::inverse(contravarient, covarient); // 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)); } } }
TEUCHOS_UNIT_TEST(point_values, intrepid_container) { PHX::KokkosDeviceSession session; Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 4; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); int num_points = 3; RCP<PointRule> point_rule = rcp(new PointRule("RandomPoints",num_points, cell_data)); TEST_EQUALITY(point_rule->num_points,num_points); panzer::PointValues<double,Intrepid::FieldContainer<double> > point_values; panzer::IntrepidFieldContainerFactory af; point_values.setupArrays(point_rule,af); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) const int num_vertices = point_rule->topology->getNodeCount(); Intrepid::FieldContainer<double> node_coordinates(num_cells, num_vertices, base_cell_dimension); typedef panzer::ArrayTraits<double,FieldContainer<double> >::size_type size_type; const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { int xleft = cell % 2; int yleft = int(cell/2); node_coordinates(cell,0,x) = xleft*0.5; node_coordinates(cell,0,y) = yleft*0.5; node_coordinates(cell,1,x) = (xleft+1)*0.5; node_coordinates(cell,1,y) = yleft*0.5; node_coordinates(cell,2,x) = (xleft+1)*0.5; node_coordinates(cell,2,y) = (yleft+1)*0.5; node_coordinates(cell,3,x) = xleft*0.5; node_coordinates(cell,3,y) = (yleft+1)*0.5; out << "Cell " << cell << " = "; for(int i=0;i<4;i++) out << "(" << node_coordinates(cell,i,x) << ", " << node_coordinates(cell,i,y) << ") "; out << std::endl; } // Build the evaluation points Intrepid::FieldContainer<double> point_coordinates(num_points, base_cell_dimension); point_coordinates(0,0) = 0.0; point_coordinates(0,1) = 0.0; // mid point point_coordinates(1,0) = 0.5; point_coordinates(1,1) = 0.5; // mid point of upper left quadrant point_coordinates(2,0) = -0.5; point_coordinates(2,1) = 0.0; // mid point of line from center to left side point_values.evaluateValues(node_coordinates,point_coordinates); for(size_type p=0;p<num_points;p++) for(size_type d=0;d<base_cell_dimension;d++) TEST_EQUALITY(point_values.coords_ref(p,d),point_coordinates(p,d)); for(size_type c=0;c<num_cells;c++) { double dx = 0.5; double dy = 0.5; for(size_type p=0;p<num_points;p++) { double x = dx*(point_coordinates(p,0)+1.0)/2.0 + node_coordinates(c,0,0); double y = dy*(point_coordinates(p,1)+1.0)/2.0 + node_coordinates(c,0,1); TEST_FLOATING_EQUALITY(point_values.point_coords(c,p,0),x,1e-10); TEST_FLOATING_EQUALITY(point_values.point_coords(c,p,1),y,1e-10); } } }
TEUCHOS_UNIT_TEST(point_values, md_field_evaluate) { typedef panzer::Traits::FadType ScalarType; typedef PHX::MDField<ScalarType> ArrayType; typedef PHX::KokkosViewFactory<ScalarType,PHX::Device> ViewFactory; typedef PHX::MDField<double>::size_type size_type; PHX::KokkosDeviceSession session; Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 4; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); int num_points = 3; RCP<PointRule> point_rule = rcp(new PointRule("RandomPoints",num_points, cell_data)); TEST_EQUALITY(point_rule->num_points,num_points); panzer::PointValues<ScalarType,PHX::MDField<ScalarType> > point_values; panzer::MDFieldArrayFactory af("prefix_"); point_values.setupArrays(point_rule,af); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) const size_type derivative_dim = 4; const std::vector<PHX::index_size_type> ddims(1,derivative_dim); const int num_vertices = point_rule->topology->getNodeCount(); ArrayType node_coordinates = af.buildArray<ScalarType,Cell,NODE,Dim>("node_coordinates",num_cells, num_vertices, base_cell_dimension); node_coordinates.setFieldData(ViewFactory::buildView(node_coordinates.fieldTag(),ddims)); const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { int xleft = cell % 2; int yleft = int(cell/2); node_coordinates(cell,0,x) = xleft*0.5; node_coordinates(cell,0,y) = yleft*0.5; node_coordinates(cell,1,x) = (xleft+1)*0.5; node_coordinates(cell,1,y) = yleft*0.5; node_coordinates(cell,2,x) = (xleft+1)*0.5; node_coordinates(cell,2,y) = (yleft+1)*0.5; node_coordinates(cell,3,x) = xleft*0.5; node_coordinates(cell,3,y) = (yleft+1)*0.5; out << "Cell " << cell << " = "; for(int i=0;i<4;i++) out << "(" << node_coordinates(cell,i,x) << ", " << node_coordinates(cell,i,y) << ") "; out << std::endl; } // Build the evaluation points ArrayType point_coordinates = af.buildArray<ScalarType,IP,Dim>("points",num_points, base_cell_dimension); point_coordinates.setFieldData(ViewFactory::buildView(point_coordinates.fieldTag(),ddims)); point_coordinates(0,0) = 0.0; point_coordinates(0,1) = 0.0; // mid point point_coordinates(1,0) = 0.5; point_coordinates(1,1) = 0.5; // mid point of upper left quadrant point_coordinates(2,0) = -0.5; point_coordinates(2,1) = 0.0; // mid point of line from center to left side point_values.coords_ref.setFieldData(ViewFactory::buildView(point_values.coords_ref.fieldTag(),ddims)); point_values.node_coordinates.setFieldData(ViewFactory::buildView(point_values.node_coordinates.fieldTag(),ddims)); point_values.point_coords.setFieldData(ViewFactory::buildView(point_values.point_coords.fieldTag(),ddims)); point_values.jac.setFieldData(ViewFactory::buildView(point_values.jac.fieldTag(),ddims)); point_values.jac_inv.setFieldData(ViewFactory::buildView(point_values.jac_inv.fieldTag(),ddims)); point_values.jac_det.setFieldData(ViewFactory::buildView(point_values.jac_det.fieldTag(),ddims)); point_values.evaluateValues(node_coordinates,point_coordinates); // check the reference values (ensure copying) for(int p=0;p<num_points;p++) for(size_type d=0;d<base_cell_dimension;d++) TEST_EQUALITY(point_values.coords_ref(p,d).val(),point_coordinates(p,d).val()); // check the shifted values (ensure physical mapping) for(size_type c=0;c<num_cells;c++) { double dx = 0.5; double dy = 0.5; for(int p=0;p<num_points;p++) { double x = dx*(point_coordinates(p,0).val()+1.0)/2.0 + node_coordinates(c,0,0).val(); double y = dy*(point_coordinates(p,1).val()+1.0)/2.0 + node_coordinates(c,0,1).val(); TEST_FLOATING_EQUALITY(point_values.point_coords(c,p,0).val(),x,1e-10); TEST_FLOATING_EQUALITY(point_values.point_coords(c,p,1).val(),y,1e-10); } } // check the jacobian for(size_type c=0;c<num_cells;c++) { double dx = 0.5; double dy = 0.5; for(int p=0;p<num_points;p++) { TEST_FLOATING_EQUALITY(point_values.jac(c,p,0,0).val(),dx/2.0,1e-10); TEST_FLOATING_EQUALITY(point_values.jac(c,p,0,1).val(),0.0,1e-10); TEST_FLOATING_EQUALITY(point_values.jac(c,p,1,0).val(),0.0,1e-10); TEST_FLOATING_EQUALITY(point_values.jac(c,p,1,1).val(),dy/2.0,1e-10); } } for(size_type c=0;c<num_cells;c++) { double dx = 0.5; double dy = 0.5; for(int p=0;p<num_points;p++) { TEST_FLOATING_EQUALITY(point_values.jac_det(c,p).val(),dy*dx/4.0,1e-10); } } out << "TESTING" << std::endl; for(size_type c=0;c<point_values.jac_det.size();c++) { point_values.jac_det[c] = c+1.0; out << " " << point_values.jac_det[c] << ", " << c+1.0 << std::endl; } out << "TESTING B" << std::endl; for(size_type c=0;c<point_values.jac_det.size();c++) out << " " << point_values.jac_det[c] << ", " << c << std::endl; // check the inverse jacobian for(size_type c=0;c<num_cells;c++) { double dx = 0.5; double dy = 0.5; for(int p=0;p<num_points;p++) { TEST_FLOATING_EQUALITY(point_values.jac_inv(c,p,0,0).val(),2.0/dx,1e-10); TEST_FLOATING_EQUALITY(point_values.jac_inv(c,p,0,1).val(),0.0,1e-10); TEST_FLOATING_EQUALITY(point_values.jac_inv(c,p,1,0).val(),0.0,1e-10); TEST_FLOATING_EQUALITY(point_values.jac_inv(c,p,1,1).val(),2.0/dy,1e-10); } } }
TEUCHOS_UNIT_TEST(integration_values, control_volume) { PHX::KokkosDeviceSession session; Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 20; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); std::string cv_type = "volume"; RCP<IntegrationRule> int_rule_vol = rcp(new IntegrationRule(cell_data, cv_type)); panzer::IntegrationValues2<double> int_values_vol("prefix_",true); panzer::MDFieldArrayFactory af("prefix_",true); int_values_vol.setupArrays(int_rule_vol); cv_type = "side"; RCP<IntegrationRule> int_rule_side = rcp(new IntegrationRule(cell_data, cv_type)); panzer::IntegrationValues2<double> int_values_side("prefix_",true); int_values_side.setupArrays(int_rule_side); const int num_vertices = int_rule_vol->topology->getNodeCount(); PHX::MDField<double,Cell,NODE,Dim> node_coordinates = af.buildStaticArray<double,Cell,NODE,Dim>("nc",num_cells, num_vertices, base_cell_dimension); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) typedef panzer::ArrayTraits<double,PHX::MDField<double> >::size_type size_type; const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { node_coordinates(cell,0,x) = 0.0; node_coordinates(cell,0,y) = 0.0; node_coordinates(cell,1,x) = 1.0; node_coordinates(cell,1,y) = 0.0; node_coordinates(cell,2,x) = 1.0; node_coordinates(cell,2,y) = 1.0; node_coordinates(cell,3,x) = 0.0; node_coordinates(cell,3,y) = 1.0; } int_values_vol.evaluateValues(node_coordinates); int_values_side.evaluateValues(node_coordinates); TEST_EQUALITY(int_values_vol.ip_coordinates.dimension(1), 4); TEST_EQUALITY(int_values_side.ip_coordinates.dimension(1), 4); TEST_EQUALITY(int_values_side.weighted_normals.dimension(1), 4); double realspace_x_coord_1 = 0.25; double realspace_y_coord_1 = 0.25; TEST_FLOATING_EQUALITY(int_values_vol.ip_coordinates(0,0,0), realspace_x_coord_1, 1.0e-8); TEST_FLOATING_EQUALITY(int_values_vol.ip_coordinates(0,0,1), realspace_y_coord_1, 1.0e-8); double realspace_x_coord_2 = 0.5; double realspace_y_coord_2 = 0.25; TEST_FLOATING_EQUALITY(int_values_side.ip_coordinates(0,0,0), realspace_x_coord_2, 1.0e-8); TEST_FLOATING_EQUALITY(int_values_side.ip_coordinates(0,0,1), realspace_y_coord_2, 1.0e-8); }
TEUCHOS_UNIT_TEST(point_values, intrepid_container_dfad) { Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 4; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); int num_points = 3; RCP<PointRule> point_rule = rcp(new PointRule("RandomPoints",num_points, cell_data)); TEST_EQUALITY(point_rule->num_points,num_points); typedef panzer::Traits::FadType ScalarType; panzer::PointValues<ScalarType,Kokkos::DynRankView<ScalarType,PHX::Device> > point_values; panzer::Intrepid2FieldContainerFactory af; point_values.setupArrays(point_rule,af); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) const int num_vertices = point_rule->topology->getNodeCount(); Kokkos::DynRankView<ScalarType,PHX::Device> node_coordinates("node_coordinates",num_cells, num_vertices, base_cell_dimension); typedef panzer::ArrayTraits<ScalarType,Kokkos::DynRankView<ScalarType,PHX::Device> >::size_type size_type; const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { int xleft = cell % 2; int yleft = int(cell/2); node_coordinates(cell,0,x) = xleft*0.5; node_coordinates(cell,0,y) = yleft*0.5; node_coordinates(cell,1,x) = (xleft+1)*0.5; node_coordinates(cell,1,y) = yleft*0.5; node_coordinates(cell,2,x) = (xleft+1)*0.5; node_coordinates(cell,2,y) = (yleft+1)*0.5; node_coordinates(cell,3,x) = xleft*0.5; node_coordinates(cell,3,y) = (yleft+1)*0.5; out << "Cell " << cell << " = "; for(int i=0;i<4;i++) out << "(" << node_coordinates(cell,i,x) << ", " << node_coordinates(cell,i,y) << ") "; out << std::endl; } // Build the evaluation points Kokkos::DynRankView<ScalarType,PHX::Device> point_coordinates(num_points, base_cell_dimension); point_coordinates(0,0) = 0.0; point_coordinates(0,1) = 0.0; // mid point point_coordinates(1,0) = 0.5; point_coordinates(1,1) = 0.5; // mid point of upper left quadrant point_coordinates(2,0) = -0.5; point_coordinates(2,1) = 0.0; // mid point of line from center to left side point_values.evaluateValues(node_coordinates,point_coordinates); }
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)); } }