//----------------------------------------------------------------------------- void ALE::move(Mesh& mesh, const GenericFunction& displacement) { // Check dimensions const std::size_t gdim = mesh.geometry().dim(); if (!((displacement.value_rank() == 0 && gdim == 1) || (displacement.value_rank() == 1 && gdim == displacement.value_dimension(0)))) { dolfin_error("ALE.cpp", "move mesh using mesh smoothing", "Illegal value dimension of displacement function"); } // Interpolate at vertices const std::size_t N = mesh.num_vertices(); std::vector<double> vertex_values; displacement.compute_vertex_values(vertex_values, mesh); // Move vertex coordinates MeshGeometry& geometry = mesh.geometry(); std::vector<double> x(gdim); for (std::size_t i = 0; i < N; i++) { for (std::size_t j = 0; j < gdim; j++) x[j] = geometry.x(i, j) + vertex_values[j*N + i]; geometry.set(i, x.data()); } }
//----------------------------------------------------------------------------- void FunctionSpace::interpolate(GenericVector& expansion_coefficients, const GenericFunction& v) const { dolfin_assert(_mesh); dolfin_assert(_element); dolfin_assert(_dofmap); // Check that function ranks match if (_element->value_rank() != v.value_rank()) { dolfin_error("FunctionSpace.cpp", "interpolate function into function space", "Rank of function (%d) does not match rank of function space (%d)", v.value_rank(), element()->value_rank()); } // Check that function dims match for (std::size_t i = 0; i < _element->value_rank(); ++i) { if (_element->value_dimension(i) != v.value_dimension(i)) { dolfin_error("FunctionSpace.cpp", "interpolate function into function space", "Dimension %d of function (%d) does not match dimension %d of function space (%d)", i, v.value_dimension(i), i, element()->value_dimension(i)); } } // Initialize vector of expansion coefficients if (expansion_coefficients.size() != _dofmap->global_dimension()) { dolfin_error("FunctionSpace.cpp", "interpolate function into function space", "Wrong size of vector"); } expansion_coefficients.zero(); // Initialize local arrays std::vector<double> cell_coefficients(_dofmap->max_element_dofs()); // Iterate over mesh and interpolate on each cell ufc::cell ufc_cell; std::vector<double> vertex_coordinates; for (CellIterator cell(*_mesh); !cell.end(); ++cell) { // Update to current cell cell->get_vertex_coordinates(vertex_coordinates); cell->get_cell_data(ufc_cell); // Restrict function to cell v.restrict(cell_coefficients.data(), *_element, *cell, vertex_coordinates.data(), ufc_cell); // Tabulate dofs const ArrayView<const dolfin::la_index> cell_dofs = _dofmap->cell_dofs(cell->index()); // Copy dofs to vector expansion_coefficients.set_local(cell_coefficients.data(), _dofmap->num_element_dofs(cell->index()), cell_dofs.data()); } // Finalise changes expansion_coefficients.apply("insert"); }