decorated_tuple(cow_pointer_type d, size_t offset) : super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) { # ifdef CPPA_DEBUG const cow_pointer_type& ptr = m_decorated; // prevent detaching # endif CPPA_REQUIRE((ptr->size() - offset) >= sizeof...(ElementTypes)); CPPA_REQUIRE(offset > 0); size_t i = offset; m_mapping.resize(sizeof...(ElementTypes)); std::generate(m_mapping.begin(), m_mapping.end(), [&]() {return i++;}); }
static void init_vector_type( vector_type &x ) { x.resize( 2 * n ); }
bool read_vtk ( int grid_form, const std::string &file_name, vector_type &p, vector_type &v, vector_type &f ) { typedef typename vector_type::value_type real_type; typedef typename vector_type::size_type index_type; switch ( grid_form ) { case 0: { vtkXMLUnstructuredGridReader *reader = vtkXMLUnstructuredGridReader::New(); reader->SetFileName ( file_name.c_str() ); reader->Update(); vtkUnstructuredGrid *vtk_grid = reader->GetOutput(); vtk_grid->Update(); vtkDoubleArray* velocities = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "velocities" ) ); vtkDoubleArray* forces = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "forces" ) ); index_type size = 3*vtk_grid->GetNumberOfPoints(); p.resize ( size ); v.resize ( size ); f.resize ( size ); for ( vtkIdType i = 0,j = 0; i < vtk_grid->GetNumberOfPoints(), j < size; ++i, j+=3 ) { // Set Positions real_type * tuple = vtk_grid->GetPoint ( i ); p ( j ) = tuple[0]; p ( j+1 ) = tuple[1]; p ( j+2 ) = tuple[2]; // Set Velocities velocities->GetTupleValue ( i, tuple ); v ( j ) = tuple[0]; v ( j+1 ) = tuple[1]; v ( j+2 ) = tuple[2]; // Set Forces forces->GetTupleValue ( i, tuple ); f ( j ) = tuple[0]; f ( j+1 ) = tuple[1]; f ( j+2 ) = tuple[2]; } reader->Delete(); break; } case 1: { vtkXMLStructuredGridReader *reader = vtkXMLStructuredGridReader::New(); reader->SetFileName ( file_name.c_str() ); reader->Update(); vtkStructuredGrid *vtk_grid = reader->GetOutput(); vtk_grid->Update(); vtkDoubleArray* velocities = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "velocities" ) ); vtkDoubleArray* forces = static_cast<vtkDoubleArray*> ( vtk_grid->GetPointData()->GetVectors ( "forces" ) ); index_type size = 3*vtk_grid->GetNumberOfPoints(); p.resize ( size ); v.resize ( size ); f.resize ( size ); for ( vtkIdType i = 0,j = 0; i < vtk_grid->GetNumberOfPoints(), j < size; ++i, j+=3 ) { // Set Positions real_type * tuple = vtk_grid->GetPoint ( i ); p ( j ) = tuple[0]; p ( j+1 ) = tuple[1]; p ( j+2 ) = tuple[2]; // Set Velocities velocities->GetTupleValue ( i, tuple ); v ( j ) = tuple[0]; v ( j+1 ) = tuple[1]; v ( j+2 ) = tuple[2]; // Set Forces forces->GetTupleValue ( i, tuple ); f ( j ) = tuple[0]; f ( j+1 ) = tuple[1]; f ( j+2 ) = tuple[2]; } reader->Delete(); break; } default: { std::cerr << "Grid type not implemented." << std::endl; return 0; } } return 1; }