Skip to content

Commit 0706c52

Browse files
authored
Merge pull request #3421 from roystgnr/still_more_coverage
Still more test coverage
2 parents 397806d + 9229e5e commit 0706c52

24 files changed

Lines changed: 212 additions & 24 deletions

examples/adaptivity/adaptivity_ex4/adaptivity_ex4.C

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include "libmesh/perf_log.h"
5959
#include "libmesh/string_to_enum.h"
6060
#include "libmesh/enum_solver_package.h"
61+
#include "libmesh/dirichlet_boundaries.h"
62+
#include "libmesh/wrapped_function.h"
6163

6264
// Bring in everything from the libMesh namespace
6365
using namespace libMesh;
@@ -71,6 +73,9 @@ using namespace libMesh;
7173
void assemble_biharmonic(EquationSystems & es,
7274
const std::string & system_name);
7375

76+
// Global parameter, to be accessible to the above function
77+
bool penalty_dirichlet = true;
78+
7479

7580
// Prototypes for calculation of the exact solution. Necessary
7681
// for setting boundary conditions.
@@ -189,6 +194,7 @@ int main(int argc, char ** argv)
189194
const Real coarsen_percentage = input_file("coarsen_percentage", 0.5);
190195
const unsigned int dim = input_file("dimension", 2);
191196
const unsigned int max_linear_iterations = input_file("max_linear_iterations", 10000);
197+
penalty_dirichlet = input_file("penalty_dirichlet", penalty_dirichlet);
192198

193199
// Skip higher-dimensional examples on a lower-dimensional libMesh build
194200
libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support");
@@ -217,10 +223,12 @@ int main(int argc, char ** argv)
217223
else
218224
output_file += "clough_";
219225

226+
output_file += approx_order_string;
227+
220228
if (uniform_refine == 0)
221-
output_file += "adaptive";
229+
output_file += "_adaptive";
222230
else
223-
output_file += "uniform";
231+
output_file += "_uniform";
224232

225233
#ifdef LIBMESH_HAVE_EXODUS_API
226234
// If we have Exodus, use the same base output filename
@@ -303,6 +311,26 @@ int main(int argc, char ** argv)
303311
// function.
304312
system.attach_assemble_function (assemble_biharmonic);
305313

314+
// Give the system Dirichlet boundary conditions, if we want to
315+
// enforce those strongly.
316+
if (!penalty_dirichlet)
317+
{
318+
const std::vector<unsigned int>
319+
all_vars(1, system.variable_number("u"));
320+
std::set<boundary_id_type> all_bdys;
321+
for (unsigned int i=0; i != dim; ++i)
322+
{
323+
all_bdys.insert(2*i);
324+
all_bdys.insert(2*i+1);
325+
}
326+
327+
WrappedFunction<Number> exact_val(system, exact_solution);
328+
WrappedFunction<Gradient> exact_grad(system, *exact_derivative);
329+
DirichletBoundary exact_bc(all_bdys, all_vars, exact_val,
330+
exact_grad);
331+
system.get_dof_map().add_dirichlet_boundary(exact_bc);
332+
}
333+
306334
// Initialize the data structures for the equation system.
307335
equation_systems.init();
308336

@@ -377,6 +405,20 @@ int main(int argc, char ** argv)
377405
<< exact_sol.h1_error("Biharmonic", "u") << " "
378406
<< exact_sol.h2_error("Biharmonic", "u") << std::endl;
379407

408+
// Assert that we're not outright diverging here, for regression
409+
// testing. These bounds just come from eyeballing some graphs
410+
// and tacking on a huge tolerance.
411+
const dof_id_type n_dofs = system.n_dofs();
412+
413+
if (exact_sol.l2_error("Biharmonic", "u") > 200*std::pow(n_dofs,-4./3.))
414+
libmesh_error_msg("Unacceptably high L2-error!");
415+
416+
if (exact_sol.h1_error("Biharmonic", "u") > 200./n_dofs)
417+
libmesh_error_msg("Unacceptably high H1-error!");
418+
419+
if (exact_sol.h2_error("Biharmonic", "u") > 400*std::pow(n_dofs,-2./3.))
420+
libmesh_error_msg("Unacceptably high H2-error!");
421+
380422
// Possibly refine the mesh
381423
if (r_step+1 != max_r_steps)
382424
{
@@ -836,12 +878,14 @@ void assemble_biharmonic(EquationSystems & es,
836878

837879

838880
// At this point the interior element integration has
839-
// been completed. However, we have not yet addressed
840-
// boundary conditions. For this example we will only
841-
// consider simple Dirichlet boundary conditions imposed
881+
// been completed. However, we may have not yet addressed
882+
// boundary conditions, if we didn't add a DirichletBoundary to
883+
// our system earlier. In that case, we will demonstrate the
884+
// imposition of simple Dirichlet boundary conditions imposed
842885
// via the penalty method. Note that this is a fourth-order
843886
// problem: Dirichlet boundary conditions include *both*
844887
// boundary values and boundary normal fluxes.
888+
if (penalty_dirichlet)
845889
{
846890
// Start logging the boundary condition computation. We use a
847891
// macro to log everything in this scope.

examples/adaptivity/adaptivity_ex4/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ source $LIBMESH_DIR/examples/run_common.sh
77
example_name=adaptivity_ex4
88

99
run_example "$example_name" approx_type=HERMITE
10+
run_example "$example_name" approx_type=HERMITE penalty_dirichlet=false
1011

1112
# HERMITE elements can p refine in 1D
1213
run_example "$example_name" dimension=1 approx_type=HERMITE approx_order=FOURTH
14+
run_example "$example_name" dimension=1 approx_type=HERMITE approx_order=FOURTH penalty_dirichlet=false
1315

1416
# CLOUGH elements don't currently support threads
1517
run_example_no_extra_options "$example_name" approx_type=CLOUGH $LIBMESH_OPTIONS --n_threads=1
18+
run_example_no_extra_options "$example_name" approx_type=CLOUGH $LIBMESH_OPTIONS --n_threads=1 penalty_dirichlet=false
1619
#run_example "$example_name" approx_type=SECOND # Broken?
1720

1821
# Examples to use for benchmarking

examples/adjoints/adjoints_ex2/adjoints_ex2.C

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,10 @@ int main (int argc, char ** argv)
509509

510510
write_output(equation_systems, a_step, "primal", param);
511511

512-
NumericVector<Number> & primal_solution = *system.solution;
512+
system.assemble_qoi_sides = true;
513513

514514
SensitivityData sensitivities(qois, system, system.get_parameter_vector());
515515

516-
system.assemble_qoi_sides = true;
517-
518516
// Here we solve the adjoint problem inside the adjoint_qoi_parameter_sensitivity
519517
// function, so we have to set the adjoint_already_solved boolean to false
520518
system.set_adjoint_already_solved(false);
@@ -563,8 +561,45 @@ int main (int argc, char ** argv)
563561
libmesh_assert_less(std::abs((sensitivity_QoI_0_0_computed - sensitivity_QoI_0_0_exact)/sensitivity_QoI_0_0_exact), 2.e-4);
564562
libmesh_assert_less(std::abs((sensitivity_QoI_0_1_computed - sensitivity_QoI_0_1_exact)/sensitivity_QoI_0_1_exact), 2.e-4);
565563

566-
NumericVector<Number> & dual_solution_0 = system.get_adjoint_solution(0);
564+
// Let's do a forward sensitivity solve too, unless we're
565+
// told to skip it for backwards compatibility with old
566+
// performance benchmarks.
567+
const bool forward_sensitivity = infile("--forward_sensitivity", true);
568+
569+
if (forward_sensitivity)
570+
{
571+
// This will require two linear solves (one per parameter)
572+
// rather than the adjoint sensitivity's one, but it's useful
573+
// for regression testing.
574+
SensitivityData forward_sensitivities(qois, system, system.get_parameter_vector());
575+
system.forward_qoi_parameter_sensitivity(qois, system.get_parameter_vector(), forward_sensitivities);
576+
577+
libmesh_assert_less(std::abs((forward_sensitivities[0][0] - sensitivity_QoI_0_0_exact)/sensitivity_QoI_0_0_exact), 2.e-4);
578+
libmesh_assert_less(std::abs((forward_sensitivities[0][1] - sensitivity_QoI_0_1_exact)/sensitivity_QoI_0_1_exact), 2.e-4);
579+
580+
// These should be the same linearization, just calculated
581+
// different ways with different roundoff error
582+
libmesh_assert_less
583+
(std::abs((forward_sensitivities[0][0] - sensitivity_QoI_0_0_computed)/sensitivity_QoI_0_0_computed), TOLERANCE);
584+
libmesh_assert_less
585+
(std::abs((forward_sensitivities[0][1] - sensitivity_QoI_0_1_computed)/sensitivity_QoI_0_1_computed), TOLERANCE);
586+
587+
libMesh::out << "The error in forward calculation of sensitivity QoI_0_0 is "
588+
<< std::setprecision(17)
589+
<< std::abs(forward_sensitivities[0][0] - sensitivity_QoI_0_0_exact)/sensitivity_QoI_0_0_exact
590+
<< std::endl;
591+
592+
libMesh::out << "The error in forward calculation of sensitivity QoI_0_1 is "
593+
<< std::setprecision(17)
594+
<< std::abs(forward_sensitivities[0][1] - sensitivity_QoI_0_1_exact)/sensitivity_QoI_0_1_exact
595+
<< std::endl
596+
<< std::endl;
597+
598+
599+
}
567600

601+
NumericVector<Number> & primal_solution = *system.solution;
602+
NumericVector<Number> & dual_solution_0 = system.get_adjoint_solution(0);
568603
primal_solution.swap(dual_solution_0);
569604
write_output(equation_systems, a_step, "adjoint_0", param);
570605

examples/adjoints/adjoints_ex2/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ example_dir=examples/adjoints/$example_name
1111
run_example "$example_name"
1212

1313
# Benchmark parameters
14-
benchmark_example 1 "$example_name" coarserefinements=4
14+
benchmark_example 1 "$example_name" coarserefinements=4 --forward_sensitivity=false

examples/fem_system/fem_system_ex1/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ example_name=fem_system_ex1
99
example_dir=examples/fem_system/$example_name
1010

1111
# First, run with standard options from input files.
12-
run_example "$example_name"
12+
# We'll throw Jacobian verification in too, just to get some test
13+
# coverage there.
14+
run_example "$example_name" verify_analytic_jacobians=1e-6
1315

1416
# Next, lets run with pure fieldsplit without gmg, if we have PETSc
1517

include/partitioning/centroid_partitioner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class CentroidPartitioner : public Partitioner
8282
CentroidPartitioner & operator= (CentroidPartitioner &&) = default;
8383
virtual ~CentroidPartitioner() = default;
8484

85+
virtual PartitionerType type () const override;
86+
8587
/**
8688
* \returns A copy of this partitioner wrapped in a smart pointer.
8789
*/

include/partitioning/hilbert_sfc_partitioner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// Local Includes
2424
#include "libmesh/sfc_partitioner.h"
2525

26+
#include "libmesh/enum_partitioner_type.h"
27+
2628
namespace libMesh
2729
{
2830

@@ -56,6 +58,11 @@ class HilbertSFCPartitioner : public SFCPartitioner
5658
HilbertSFCPartitioner & operator= (HilbertSFCPartitioner &&) = default;
5759
virtual ~HilbertSFCPartitioner() = default;
5860

61+
virtual PartitionerType type () const override
62+
{
63+
return HILBERT_SFC_PARTITIONER;
64+
};
65+
5966
/**
6067
* \returns A copy of this partitioner wrapped in a smart pointer.
6168
*/

include/partitioning/linear_partitioner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class LinearPartitioner : public Partitioner
5454
LinearPartitioner & operator= (LinearPartitioner &&) = default;
5555
virtual ~LinearPartitioner() = default;
5656

57+
virtual PartitionerType type () const override;
58+
5759
/**
5860
* \returns A copy of this partitioner wrapped in a smart pointer.
5961
*/

include/partitioning/mapped_subdomain_partitioner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class MappedSubdomainPartitioner : public Partitioner
5656
MappedSubdomainPartitioner & operator= (MappedSubdomainPartitioner &&) = default;
5757
virtual ~MappedSubdomainPartitioner() = default;
5858

59+
virtual PartitionerType type () const override;
60+
5961
/**
6062
* \returns A copy of this partitioner wrapped in a smart pointer.
6163
*/

include/partitioning/metis_partitioner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class MetisPartitioner : public Partitioner
5252
MetisPartitioner & operator= (MetisPartitioner &&) = default;
5353
virtual ~MetisPartitioner() = default;
5454

55+
virtual PartitionerType type () const override;
56+
5557
/**
5658
* \returns A copy of this partitioner wrapped in a smart pointer.
5759
*/

0 commit comments

Comments
 (0)