From: Jean-Paul Pelteret Date: Thu, 16 Nov 2017 16:13:43 +0000 (+0100) Subject: Test to show that a zero-valued function can have non-zero derivatives. X-Git-Tag: v9.0.0-rc1~765^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d38352beebe4d1ddd6c551a78233598a2fca5c5e;p=dealii.git Test to show that a zero-valued function can have non-zero derivatives. --- diff --git a/tests/sacado/zero_val_nonzero_deriv_01.cc b/tests/sacado/zero_val_nonzero_deriv_01.cc new file mode 100644 index 0000000000..f82ff75ef6 --- /dev/null +++ b/tests/sacado/zero_val_nonzero_deriv_01.cc @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, 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. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// Tests the computation of the first derivatives of a function with zero +// input can have a non-zero first derivative. + + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +int main() +{ + initlog(); + + const unsigned int dim = 2; + Triangulation triangulation; + FE_Q fe (1); + QGauss quadrature_formula(2); + DoFHandler dof_handler (triangulation); + Vector zero_solution; + + FEValues fe_values (fe, quadrature_formula, + update_values | update_gradients | update_JxW_values); + + GridGenerator::hyper_cube (triangulation, -1, 1); + dof_handler.distribute_dofs (fe); + zero_solution.reinit (dof_handler.n_dofs()); + + const FEValuesExtractors::Scalar extractor_sclr(0); + + typedef Sacado::Fad::DFad ad_type; + DoFHandler::active_cell_iterator cell = dof_handler.begin_active(); + DoFHandler::active_cell_iterator endc = dof_handler.end(); + for (; cell!=endc; ++cell) + { + fe_values.reinit (cell); + + // Extract (zero'd) DoF values + Vector local_dof_values(cell->get_fe().dofs_per_cell); + cell->get_dof_values(zero_solution, local_dof_values); + + // Configure AD-equivalent DoF values. These + // are the independent variables "x". + std::vector local_ad_dof_values (fe.n_dofs_per_cell()); + for (unsigned int i=0; i local_qp_soln_values_ad (fe.n_dofs_per_cell()); + fe_values[extractor_sclr].get_function_values_from_local_dof_values(local_ad_dof_values,local_qp_soln_values_ad); + + // Compute the dependent variable "f(x)". + ad_type f_x = 0.0; + for (unsigned int i=0; i