void TPSLaplaceResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // Note that all the integration operations are ScalarT! We need the partials of the Jacobian to show up in the // system Jacobian as the solution is a function of coordinates (it IS the coordinates!). // This adds significant time to the compile Intrepid2::CellTools<ScalarT>::setJacobian(jacobian, refPoints, solnVec, *cellType); // Since Intrepid2 will perform calculations on the entire workset size and not // just the used portion, we must fill the excess with reasonable values. // Leaving this out leads to a floating point exception in // Intrepid2::RealSpaceTools<Scalar>::det(ArrayDet & detArray, // const ArrayIn & inMats). for (std::size_t cell = workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp = 0; qp < numQPs; ++qp) for (std::size_t i = 0; i < numDims; ++i) jacobian(cell, qp, i, i) = 1.0; Intrepid2::CellTools<ScalarT>::setJacobianDet(jacobian_det, jacobian); // Straight Laplace's equation evaluation for the nodal coord solution for(std::size_t cell = 0; cell < workset.numCells; ++cell) { for(std::size_t node_a = 0; node_a < numNodes; ++node_a) { for(std::size_t eq = 0; eq < numDims; eq++) { solnResidual(cell, node_a, eq) = 0.0; } for(std::size_t qp = 0; qp < numQPs; ++qp) { for(std::size_t node_b = 0; node_b < numNodes; ++node_b) { ScalarT kk = 0.0; for(std::size_t i = 0; i < numDims; i++) { kk += grad_at_cub_points(node_a, qp, i) * grad_at_cub_points(node_b, qp, i); } for(std::size_t eq = 0; eq < numDims; eq++) { solnResidual(cell, node_a, eq) += kk * solnVec(cell, node_b, eq) * jacobian_det(cell, qp) * refWeights(qp); } } } } } }
void LaplaceResid<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // setJacobian only needs to be RealType since the data type is only // used internally for Basis Fns on reference elements, which are // not functions of coordinates. This save 18min of compile time!!! Intrepid::CellTools<MeshScalarT>::setJacobian(jacobian, refPoints, coordVec, *cellType); // Since Intrepid will perform calculations on the entire workset size and not // just the used portion, we must fill the excess with reasonable values. // Leaving this out leads to a floating point exception in // Intrepid::RealSpaceTools<Scalar>::det(ArrayDet & detArray, // const ArrayIn & inMats). for (std::size_t cell = workset.numCells; cell < worksetSize; ++cell) for (std::size_t qp = 0; qp < numQPs; ++qp) for (std::size_t i = 0; i < numDims; ++i) jacobian(cell, qp, i, i) = 1.0; Intrepid::CellTools<MeshScalarT>::setJacobianDet(jacobian_det, jacobian); // Straight Laplace's equation evaluation for the nodal coord solution for(std::size_t cell = 0; cell < workset.numCells; ++cell) { for(std::size_t node_a = 0; node_a < numNodes; ++node_a) { for(std::size_t eq = 0; eq < numDims; eq++) { solnResidual(cell, node_a, eq) = 0.0; } for(std::size_t qp = 0; qp < numQPs; ++qp) { for(std::size_t node_b = 0; node_b < numNodes; ++node_b) { ScalarT kk = 0.0; for(std::size_t i = 0; i < numDims; i++) { kk += grad_at_cub_points(node_a, qp, i) * grad_at_cub_points(node_b, qp, i); } for(std::size_t eq = 0; eq < numDims; eq++) { solnResidual(cell, node_a, eq) += kk * solnVec(cell, node_b, eq) * jacobian_det(cell, qp) * refWeights(qp); } } } } } }
void IntrepidKernel<Scalar>::jacobianDet( Scalar &determinant, const double param_coords[3], const iMesh_Instance mesh, const iBase_EntityHandle physical_cell ) { int error = 0; iBase_EntityHandle *element_nodes = 0; int element_nodes_allocated = 0; int element_nodes_size = 0; iMesh_getEntAdj( mesh, physical_cell, iBase_VERTEX, &element_nodes, &element_nodes_allocated, &element_nodes_size, &error ); assert( iBase_SUCCESS == error ); TopologyTools::MBCN2Shards( element_nodes, element_nodes_size, this->b_topology ); int coords_allocated = 0; int coords_size = 0; double *coord_array = 0; iMesh_getVtxArrCoords( mesh, element_nodes, element_nodes_size, iBase_INTERLEAVED, &coord_array, &coords_allocated, &coords_size, &error ); assert( iBase_SUCCESS == error ); Teuchos::Tuple<int,3> cell_node_dimensions; cell_node_dimensions[0] = 1; cell_node_dimensions[1] = element_nodes_size; cell_node_dimensions[2] = 3; MDArray cell_nodes( Teuchos::Array<int>(cell_node_dimensions), coord_array ); MDArray reference_coords( 1, 3 ); reference_coords(0,0) = param_coords[0]; reference_coords(0,1) = param_coords[1]; reference_coords(0,2) = param_coords[2]; MDArray jacobian( 1, 1, 3, 3 ); Intrepid::CellTools<double>::setJacobian( jacobian, reference_coords, cell_nodes, d_intrepid_basis->getBaseCellTopology() ); MDArray jacobian_det( 1, 1 ); Intrepid::CellTools<double>::setJacobianDet( jacobian_det, jacobian ); determinant = jacobian_det(0,0); free( element_nodes ); free( coord_array ); }
void IntrepidKernel<Scalar>::transformOperator( Teuchos::ArrayRCP<Scalar> &transformed_values, const Teuchos::ArrayRCP<Scalar> &values, const double param_coords[3], const iMesh_Instance mesh, const iBase_EntityHandle physical_cell ) { int error = 0; iBase_EntityHandle *element_nodes = 0; int element_nodes_allocated = 0; int element_nodes_size = 0; iMesh_getEntAdj( mesh, physical_cell, iBase_VERTEX, &element_nodes, &element_nodes_allocated, &element_nodes_size, &error ); assert( iBase_SUCCESS == error ); TopologyTools::MBCN2Shards( element_nodes, element_nodes_size, this->b_topology ); int coords_allocated = 0; int coords_size = 0; double *coord_array = 0; iMesh_getVtxArrCoords( mesh, element_nodes, element_nodes_size, iBase_INTERLEAVED, &coord_array, &coords_allocated, &coords_size, &error ); assert( iBase_SUCCESS == error ); Teuchos::Tuple<int,3> cell_node_dimensions; cell_node_dimensions[0] = 1; cell_node_dimensions[1] = element_nodes_size; cell_node_dimensions[2] = 3; MDArray cell_nodes( Teuchos::Array<int>(cell_node_dimensions), coord_array ); MDArray jacobian( 1, 1, 3, 3 ); MDArray jacobian_det( 1, 1 ); MDArray jacobian_inv( 1, 1, 3, 3 ); MDArray reference_point( 1, 3 ); reference_point(0,0) = param_coords[0]; reference_point(0,1) = param_coords[1]; reference_point(0,2) = param_coords[2]; if ( this->b_function_space_type == FOOD_HGRAD ) { Intrepid::CellTools<double>::setJacobian( jacobian, reference_point, cell_nodes, d_intrepid_basis->getBaseCellTopology() ); Intrepid::CellTools<double>::setJacobianInv( jacobian_inv, jacobian ); MDArray transformed_grad( 1, this->b_cardinality, 1, 3 ); Teuchos::Tuple<int,3> grad_dimensions; grad_dimensions[0] = this->b_cardinality; grad_dimensions[1] = 1; grad_dimensions[2] = 3; MDArray basis_grad( grad_dimensions, values ); Intrepid::FunctionSpaceTools::HGRADtransformGRAD<double>( transformed_grad, jacobian_inv, basis_grad ); transformed_values = transformed_grad.getData(); } else if ( this->b_function_space_type == FOOD_HDIV ) { } else if ( this->b_function_space_type == FOOD_HCURL ) { } else { testPrecondition( this->b_function_space_type == FOOD_HGRAD || this->b_function_space_type == FOOD_HDIV || this->b_function_space_type == FOOD_HCURL, "Invalid function space type" ); } free( coord_array ); free( element_nodes ); }
int FunctionSpaceTools_Test02(const bool verbose) { typedef ValueType value_type; Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); *outStream \ << "===============================================================================\n" \ << "| |\n" \ << "| Unit Test (FunctionSpaceTools) |\n" \ << "| |\n" \ << "| 1) basic operator transformations and integration in HCURL |\n" \ << "| |\n" \ << "| Questions? Contact Pavel Bochev ([email protected]) or |\n" \ << "| Denis Ridzal ([email protected]). |\n" \ << "| |\n" \ << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ << "| Trilinos website: http://trilinos.sandia.gov |\n" \ << "| |\n" \ << "===============================================================================\n"; typedef FunctionSpaceTools<DeviceSpaceType> fst; typedef Kokkos::DynRankView<value_type,DeviceSpaceType> DynRankView; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) int errorFlag = 0; *outStream \ << "\n" << "===============================================================================\n"\ << "| TEST 1: correctness of math operations |\n"\ << "===============================================================================\n"; outStream->precision(20); try { shards::CellTopology cellType = shards::getCellTopologyData< shards::Hexahedron<> >(); // cell type: hex /* Related to cubature. */ DefaultCubatureFactory<double> cubFactory; // create cubature factory int cubDegree = 20; // cubature degree Teuchos::RCP<Cubature<double> > myCub = cubFactory.create(cellType, cubDegree); // create default cubature int spaceDim = myCub->getDimension(); // get spatial dimension int numCubPoints = myCub->getNumPoints(); // get number of cubature points /* Related to basis. */ Basis_HCURL_HEX_I1_FEM<double, FieldContainer<double> > hexBasis; // create H-curl basis on a hex int numFields = hexBasis.getCardinality(); // get basis cardinality /* Cell geometries and orientations. */ int numCells = 4; int numNodes = 8; int numCellData = numCells*numNodes*spaceDim; int numSignData = numCells*numFields; double hexnodes[] = { // hex 0 -- affine -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, // hex 1 -- affine -3.0, -3.0, 1.0, 6.0, 3.0, 1.0, 7.0, 8.0, 0.0, -2.0, 2.0, 0.0, -3.0, -3.0, 4.0, 6.0, 3.0, 4.0, 7.0, 8.0, 3.0, -2.0, 2.0, 3.0, // hex 2 -- affine -3.0, -3.0, 0.0, 9.0, 3.0, 0.0, 15.0, 6.1, 0.0, 3.0, 0.1, 0.0, 9.0, 3.0, 0.1, 21.0, 9.0, 0.1, 27.0, 12.1, 0.1, 15.0, 6.1, 0.1, // hex 3 -- nonaffine -2.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0, 6.0, 0.0, -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0 }; double edgesigns[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1 }; /* Computational arrays. */ FieldContainer<double> cub_points(numCubPoints, spaceDim); FieldContainer<double> cub_weights(numCubPoints); FieldContainer<double> cell_nodes(numCells, numNodes, spaceDim); FieldContainer<double> field_signs(numCells, numFields); FieldContainer<double> jacobian(numCells, numCubPoints, spaceDim, spaceDim); FieldContainer<double> jacobian_inv(numCells, numCubPoints, spaceDim, spaceDim); FieldContainer<double> jacobian_det(numCells, numCubPoints); FieldContainer<double> weighted_measure(numCells, numCubPoints); FieldContainer<double> curl_of_basis_at_cub_points(numFields, numCubPoints, spaceDim); FieldContainer<double> transformed_curl_of_basis_at_cub_points(numCells, numFields, numCubPoints, spaceDim); FieldContainer<double> weighted_transformed_curl_of_basis_at_cub_points(numCells, numFields, numCubPoints, spaceDim); FieldContainer<double> stiffness_matrices(numCells, numFields, numFields); FieldContainer<double> value_of_basis_at_cub_points(numFields, numCubPoints, spaceDim); FieldContainer<double> transformed_value_of_basis_at_cub_points(numCells, numFields, numCubPoints, spaceDim); FieldContainer<double> weighted_transformed_value_of_basis_at_cub_points(numCells, numFields, numCubPoints, spaceDim); FieldContainer<double> mass_matrices(numCells, numFields, numFields); /******************* START COMPUTATION ***********************/ // get cubature points and weights myCub->getCubature(cub_points, cub_weights); // fill cell vertex array cell_nodes.setValues(hexnodes, numCellData); // set basis function signs, for each cell field_signs.setValues(edgesigns, numSignData); // compute geometric cell information CellTools<double>::setJacobian(jacobian, cub_points, cell_nodes, cellType); CellTools<double>::setJacobianInv(jacobian_inv, jacobian); CellTools<double>::setJacobianDet(jacobian_det, jacobian); // compute weighted measure fst::computeCellMeasure<double>(weighted_measure, jacobian_det, cub_weights); // Computing stiffness matrices: // tabulate curls of basis functions at (reference) cubature points hexBasis.getValues(curl_of_basis_at_cub_points, cub_points, OPERATOR_CURL); // transform curls of basis functions fst::HCURLtransformCURL<double>(transformed_curl_of_basis_at_cub_points, jacobian, jacobian_det, curl_of_basis_at_cub_points); // multiply with weighted measure fst::multiplyMeasure<double>(weighted_transformed_curl_of_basis_at_cub_points, weighted_measure, transformed_curl_of_basis_at_cub_points); // we can apply the field signs to the basis function arrays, or after the fact, see below fst::applyFieldSigns<double>(transformed_curl_of_basis_at_cub_points, field_signs); fst::applyFieldSigns<double>(weighted_transformed_curl_of_basis_at_cub_points, field_signs); // compute stiffness matrices fst::integrate<double>(stiffness_matrices, transformed_curl_of_basis_at_cub_points, weighted_transformed_curl_of_basis_at_cub_points, COMP_CPP); // Computing mass matrices: // tabulate values of basis functions at (reference) cubature points hexBasis.getValues(value_of_basis_at_cub_points, cub_points, OPERATOR_VALUE); // transform values of basis functions fst::HCURLtransformVALUE<double>(transformed_value_of_basis_at_cub_points, jacobian_inv, value_of_basis_at_cub_points); // multiply with weighted measure fst::multiplyMeasure<double>(weighted_transformed_value_of_basis_at_cub_points, weighted_measure, transformed_value_of_basis_at_cub_points); // compute mass matrices fst::integrate<double>(mass_matrices, transformed_value_of_basis_at_cub_points, weighted_transformed_value_of_basis_at_cub_points, COMP_CPP); // apply field signs (after the fact, as a post-processing step) fst::applyLeftFieldSigns<double>(mass_matrices, field_signs); fst::applyRightFieldSigns<double>(mass_matrices, field_signs); /******************* STOP COMPUTATION ***********************/ /******************* START COMPARISON ***********************/ string basedir = "./testdata"; for (int cell_id = 0; cell_id < numCells-1; cell_id++) { stringstream namestream; string filename; namestream << basedir << "/mass_HCURL_HEX_I1_FEM" << "_" << "0" << cell_id+1 << ".dat"; namestream >> filename; ifstream massfile(&filename[0]); if (massfile.is_open()) { if (compareToAnalytic<double>(&mass_matrices(cell_id, 0, 0), massfile, 1e-10, iprint) > 0) errorFlag++; massfile.close(); } else { errorFlag = -1; std::cout << "End Result: TEST FAILED\n"; return errorFlag; } namestream.clear(); namestream << basedir << "/stiff_HCURL_HEX_I1_FEM" << "_" << "0" << cell_id+1 << ".dat"; namestream >> filename; ifstream stifffile(&filename[0]); if (stifffile.is_open()) { if (compareToAnalytic<double>(&stiffness_matrices(cell_id, 0, 0), stifffile, 1e-10, iprint) > 0) errorFlag++; stifffile.close(); } else { errorFlag = -1; std::cout << "End Result: TEST FAILED\n"; return errorFlag; } } for (int cell_id = 3; cell_id < numCells; cell_id++) { stringstream namestream; string filename; namestream << basedir << "/mass_fp_HCURL_HEX_I1_FEM" << "_" << "0" << cell_id+1 << ".dat"; namestream >> filename; ifstream massfile(&filename[0]); if (massfile.is_open()) { if (compareToAnalytic<double>(&mass_matrices(cell_id, 0, 0), massfile, 1e-4, iprint, INTREPID2_UTILS_SCALAR) > 0) errorFlag++; massfile.close(); } else { errorFlag = -1; std::cout << "End Result: TEST FAILED\n"; return errorFlag; } namestream.clear(); namestream << basedir << "/stiff_fp_HCURL_HEX_I1_FEM" << "_" << "0" << cell_id+1 << ".dat"; namestream >> filename; ifstream stifffile(&filename[0]); if (stifffile.is_open()) { if (compareToAnalytic<double>(&stiffness_matrices(cell_id, 0, 0), stifffile, 1e-4, iprint, INTREPID2_UTILS_SCALAR) > 0) errorFlag++; stifffile.close(); } else { errorFlag = -1; std::cout << "End Result: TEST FAILED\n"; return errorFlag; } } /******************* STOP COMPARISON ***********************/ *outStream << "\n"; } catch (std::logic_error err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; }; if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); Kokkos::finalize(); return errorFlag; }