Scalar OperatorTools::getMatrixComponentFromGlobal( const Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LO,GO> >& matrix, const GO global_row, const GO global_col ) { Teuchos::RCP<const Tpetra::Map<LO,GO> > row_map = matrix->getRowMap(); Teuchos::RCP<const Tpetra::Map<LO,GO> > col_map = matrix->getColMap(); LO local_row = row_map->getLocalElement( global_row ); LO local_col = col_map->getLocalElement( global_col ); testPrecondition( local_row != Teuchos::OrdinalTraits<LO>::invalid() ); testPrecondition( local_col != Teuchos::OrdinalTraits<LO>::invalid() ); Teuchos::ArrayView<const LO> local_indices; Teuchos::ArrayView<const Scalar> local_values; matrix->getLocalRowView( local_row, local_indices, local_values ); typename Teuchos::ArrayView<const LO>::const_iterator local_idx_it = std::find( local_indices.begin(), local_indices.end(), local_col ); if ( local_idx_it != local_indices.end() ) { return local_values[ std::distance( local_indices.begin(), local_idx_it ) ]; } else { return 0.0; } }
void FieldManager<Field>::validate() { // Check that the field dimension is the same on every node. Teuchos::Array<int> local_dims( d_comm->getSize(), 0 ); Teuchos::Array<int> local_dims_copy( d_comm->getSize(), 0 ); local_dims[ d_comm->getRank() ] = FT::dim( *d_field ); Teuchos::reduceAll<int,int>( *d_comm, Teuchos::REDUCE_SUM, local_dims.size(), &local_dims[0], &local_dims_copy[0] ); Teuchos::Array<int>::iterator unique_bound; std::sort( local_dims_copy.begin(), local_dims_copy.end() ); unique_bound = std::unique( local_dims_copy.begin(), local_dims_copy.end() ); int unique_dim = std::distance( local_dims_copy.begin(), unique_bound ); testPrecondition( 1 == unique_dim ); local_dims_copy.clear(); // Check that the data dimension is the same as the field dimension. typename FT::size_type num_data = std::distance( FT::begin( *d_field ), FT::end( *d_field ) ); testPrecondition( num_data == FT::size( *d_field ) ); if ( !FT::empty( *d_field ) ) { testPrecondition( num_data / FieldTools<Field>::dimSize( *d_field ) == Teuchos::as<typename FT::size_type>( FT::dim(*d_field)) ); } }
/*! * \brief Tuple constructor. * * \param bounds Tuple containing {x_min, y_min, z_min, x_max, y_max, z_max}. */ BoundingBox::BoundingBox( const Teuchos::Tuple<double,6>& bounds ) : d_x_min( bounds[0] ) , d_y_min( bounds[1] ) , d_z_min( bounds[2] ) , d_x_max( bounds[3] ) , d_y_max( bounds[4] ) , d_z_max( bounds[5] ) { testPrecondition( d_x_min <= d_x_max ); testPrecondition( d_y_min <= d_y_max ); testPrecondition( d_z_min <= d_z_max ); }
/*! * \brief Constructor. * * \param x_min Minimum x coordinate value in the box. * * \param y_min Minimum y coordinate value in the box. * * \param z_min Minimum z coordinate value in the box. * * \param x_max Maximum x coordinate value in the box. * * \param y_max Maximum y coordinate value in the box. * * \param z_max Maximum z coordinate value in the box. */ BoundingBox::BoundingBox( const double x_min, const double y_min, const double z_min, const double x_max, const double y_max, const double z_max ) : d_x_min( x_min ) , d_y_min( y_min ) , d_z_min( z_min ) , d_x_max( x_max ) , d_y_max( y_max ) , d_z_max( z_max ) { testPrecondition( d_x_min <= d_x_max ); testPrecondition( d_y_min <= d_y_max ); testPrecondition( d_z_min <= d_z_max ); }
void IntrepidKernel<Scalar>::evaluate( Teuchos::ArrayRCP<Scalar> &function_values, const Teuchos::ArrayRCP<Scalar> &coeffs, const Teuchos::ArrayRCP<Scalar> &dfunc_values ) { int dim1 = this->b_cardinality; testPrecondition( dim1 == (int) coeffs.size(), "Function coefficients size does not match basis cardinality" ); MDArray function_coeffs( 1, dim1 ); for ( int m = 0; m < dim1; ++m ) { function_coeffs(0,m) = coeffs[m]; } MDArray basis_eval( 1, dim1, 1 ); for ( int i = 0; i < dim1; ++i ) { basis_eval( 0, i, 0 ) = dfunc_values[i]; } Teuchos::Tuple<int,2> function_dimensions; function_dimensions[0] = 1; function_dimensions[1] = 1; MDArray function_eval( function_dimensions, function_values ); Intrepid::FunctionSpaceTools::evaluate<Scalar>( function_eval, function_coeffs, basis_eval ); }
HT HistoryBank<HT>::pop() { testPrecondition( !empty() ); HT history = d_histories.back(); d_histories.pop_back(); return history; }
Scalar OperatorTools::getMatrixComponentFromLocal( const Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LO,GO> >& matrix, const LO local_row, const LO local_col ) { testPrecondition( matrix->getRowMap()->isNodeLocalElement( local_row ) ); testPrecondition( matrix->getColMap()->isNodeLocalElement( local_col ) ); Teuchos::ArrayView<const LO> local_indices; Teuchos::ArrayView<const Scalar> local_values; matrix->getLocalRowView( local_row, local_indices, local_values ); typename Teuchos::ArrayView<const LO>::const_iterator local_idx_it = std::find( local_indices.begin(), local_indices.end(), local_col ); if ( local_idx_it != local_indices.end() ) { return local_values[ std::distance( local_indices.begin(), local_idx_it ) ]; } else { return 0.0; } }
void IntrepidKernel<Scalar>::dfuncValue( Teuchos::ArrayRCP<Scalar> &values, const double param_coords[3] ) { MDArray coords(1,3); coords(0,0) = param_coords[0]; coords(0,1) = param_coords[1]; coords(0,2) = param_coords[2]; if ( this->b_function_space_type == FOOD_HGRAD ) { MDArray grad_values( this->b_cardinality, 1 ); d_intrepid_basis->getValues( grad_values, coords, Intrepid::OPERATOR_VALUE ); values = grad_values.getData(); } else if ( this->b_function_space_type == FOOD_HDIV ) { MDArray div_values( this->b_cardinality, 1, 3 ); d_intrepid_basis->getValues( div_values, coords, Intrepid::OPERATOR_VALUE ); values = div_values.getData(); } else if ( this->b_function_space_type == FOOD_HCURL ) { MDArray curl_values( this->b_cardinality, 1, 3 ); d_intrepid_basis->getValues( curl_values, coords, Intrepid::OPERATOR_VALUE ); values = curl_values.getData(); } 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" ); } }
void IntrepidKernel<Scalar>::dfuncOperator( Teuchos::ArrayRCP<Scalar> &values, const double param_coords[3] ) { MDArray coords(1,3); coords(0,0) = param_coords[0]; coords(0,1) = param_coords[1]; coords(0,2) = param_coords[2]; if ( this->b_function_space_type == FOOD_HGRAD ) { MDArray dfunc_grad( this->b_cardinality, 1, 3 ); d_intrepid_basis->getValues( dfunc_grad, coords, Intrepid::OPERATOR_GRAD ); values = dfunc_grad.getData(); } else if ( this->b_function_space_type == FOOD_HDIV ) { MDArray dfunc_div( this->b_cardinality ); d_intrepid_basis->getValues( dfunc_div, coords, Intrepid::OPERATOR_DIV ); values = dfunc_div.getData(); } else if ( this->b_function_space_type == FOOD_HCURL ) { MDArray dfunc_curl( this->b_cardinality, 1, 3 ); d_intrepid_basis->getValues( dfunc_curl, coords, Intrepid::OPERATOR_CURL ); values = dfunc_curl.getData(); } 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" ); } }
/*! * \brief Compute the volume of the bounding box given its dimension. * * \param dim The dimension of the box we want to compute the volume for. We * need this because the box always stores all 3 dimensions. Lower dimension * boxes are resolved with higher dimensions set to +/- * Teuchos::ScalarTraits<double>::rmax(). For dim = 1, only the x dimension is * used. For dim = 2, the x and y dimensions are used. For dim = 3, the x, y, * and z dimensions are used. * * \return Return the volume of the box. */ double BoundingBox::volume( const int dim ) const { testPrecondition( 0 <= dim && dim <= 3 ); if ( dim == 1 ) { return (d_x_max-d_x_min); } else if ( dim == 2 ) { return (d_x_max-d_x_min)*(d_y_max-d_y_min); } else if ( dim == 3 ) { return (d_x_max-d_x_min)*(d_y_max-d_y_min)*(d_z_max-d_z_min); } return 0; }
/*! * \brief Determine if a point is in the box. * * \param coords Cartesian coordinates to check for point inclusion. The * coordinates must have a dimension between 0 and 3. * * \return Return true if the point is in the box, false if not. A point on * the box boundary will return true. */ bool BoundingBox::pointInBox( const Teuchos::Array<double>& coords ) const { testPrecondition( 0 <= coords.size() && coords.size() <= 3 ); if ( coords.size() == 1 ) { if ( coords[0] >= d_x_min && coords[0] <= d_x_max ) { return true; } } else if ( coords.size() == 2 ) { if ( coords[0] >= d_x_min && coords[1] >= d_y_min && coords[0] <= d_x_max && coords[1] <= d_y_max ) { return true; } } else if ( coords.size() == 3 ) { if ( coords[0] >= d_x_min && coords[1] >= d_y_min && coords[2] >= d_z_min && coords[0] <= d_x_max && coords[1] <= d_y_max && coords[2] <= d_z_max ) { return true; } } return false; }
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 ); }
HT& HistoryBank<HT>::top() { testPrecondition( !empty() ); return d_histories.back(); }