//@HEADER // ************************************************************************ // // MiniFE: Simple Finite Element Assembly and Solve // Copyright (2006-2013) Sandia Corporation // // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive // license for use of this work by or on behalf of the U.S. Government. // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA // // ************************************************************************ //@HEADER #ifndef _MatrixInitOp_hpp_ #define _MatrixInitOp_hpp_ #include #include #include #include #include template void sort_if_needed(GlobalOrdinal* list, GlobalOrdinal list_len) { bool need_to_sort = false; for(GlobalOrdinal i=list_len-1; i>=1; --i) { if (list[i] < list[i-1]) { need_to_sort = true; break; } } if (need_to_sort) { std::sort(list,list+list_len); } } template struct MatrixInitOp { }; template<> struct MatrixInitOp > { MatrixInitOp(const std::vector& rows_vec, const std::vector& row_offsets_vec, const std::vector& row_coords_vec, int global_nx, int global_ny, int global_nz, MINIFE_GLOBAL_ORDINAL global_n_rows, const miniFE::simple_mesh_description& input_mesh, miniFE::CSRMatrix& matrix) : rows(&rows_vec[0]), row_offsets(&row_offsets_vec[0]), row_coords(&row_coords_vec[0]), global_nodes_x(global_nx), global_nodes_y(global_ny), global_nodes_z(global_nz), global_nrows(global_n_rows), mesh(&input_mesh), dest_rows(&matrix.rows[0]), dest_rowoffsets(&matrix.row_offsets[0]), dest_cols(&matrix.packed_cols[0]), dest_coefs(&matrix.packed_coefs[0]), n(matrix.rows.size()) { if (matrix.packed_cols.capacity() != matrix.packed_coefs.capacity()) { std::cout<<"Warning, packed_cols.capacity ("<* mesh; inline void operator()(int i) { dest_rows[i] = rows[i]; int offset = row_offsets[i]; dest_rowoffsets[i] = offset; int ix = row_coords[i*3]; int iy = row_coords[i*3+1]; int iz = row_coords[i*3+2]; GlobalOrdinalType nnz = 0; for(int sz=-1; sz<=1; ++sz) { for(int sy=-1; sy<=1; ++sy) { for(int sx=-1; sx<=1; ++sx) { GlobalOrdinalType col_id = miniFE::get_id(global_nodes_x, global_nodes_y, global_nodes_z, ix+sx, iy+sy, iz+sz); if (col_id >= 0 && col_id < global_nrows) { GlobalOrdinalType col = mesh->map_id_to_row(col_id); if (col >= global_nrows) { std::cout << "mesh->map_id_to_row produced col="<