From 7ab35df590de655f4be482f4c7f473c0804d7ebd Mon Sep 17 00:00:00 2001 From: "Roy H. Stogner" Date: Wed, 3 Jun 2015 17:04:52 -0500 Subject: [PATCH] Use common FEMParameters in adjoints_ex4 --- examples/adjoints/adjoints_ex4/Makefile.am | 11 +- examples/adjoints/adjoints_ex4/adjoints_ex4.C | 2 +- .../adjoints/adjoints_ex4/femparameters.C | 78 ------- .../adjoints/adjoints_ex4/femparameters.h | 193 ++++++++++++------ 4 files changed, 147 insertions(+), 137 deletions(-) delete mode 100644 examples/adjoints/adjoints_ex4/femparameters.C diff --git a/examples/adjoints/adjoints_ex4/Makefile.am b/examples/adjoints/adjoints_ex4/Makefile.am index 1d0f8d5f6de..e53fd673dfd 100644 --- a/examples/adjoints/adjoints_ex4/Makefile.am +++ b/examples/adjoints/adjoints_ex4/Makefile.am @@ -1,3 +1,12 @@ +BUILT_SOURCES = femparameters.C # femparameters.h +DISTCLEANFILES = $(BUILT_SOURCES) + +femparameters.C: $(top_srcdir)/examples/adjoints/adjoints_ex1/femparameters.C + $(AM_V_GEN)$(LN_S) -f $< $@ + +#femparameters.h: $(top_srcdir)/examples/adjoints/adjoints_ex1/femparameters.h +# $(AM_V_GEN)$(LN_S) -f $< . + example_name = adjoints_ex4 check_SCRIPTS = run.sh install_dir = $(examples_install_path)/adjoints/ex4 @@ -8,7 +17,7 @@ CLEANFILES = primal.out.* adjoint_*.out.* # also need links for VPATH builds if LIBMESH_VPATH_BUILD - BUILT_SOURCES = .linkstamp + BUILT_SOURCES += .linkstamp .linkstamp: -rm -f general.in && $(LN_S) -f $(srcdir)/general.in . -rm -f lshaped.xda && $(LN_S) -f $(srcdir)/lshaped.xda . diff --git a/examples/adjoints/adjoints_ex4/adjoints_ex4.C b/examples/adjoints/adjoints_ex4/adjoints_ex4.C index 2adfbaf3ed7..91e1c6f0765 100644 --- a/examples/adjoints/adjoints_ex4/adjoints_ex4.C +++ b/examples/adjoints/adjoints_ex4/adjoints_ex4.C @@ -219,7 +219,7 @@ int main (int argc, char** argv) GetPot infile("general.in"); // Read in parameters from the input file - FEMParameters param; + FEMParameters param(init.comm()); param.read(infile); // Skip this default-2D example if libMesh was compiled as 1D-only. diff --git a/examples/adjoints/adjoints_ex4/femparameters.C b/examples/adjoints/adjoints_ex4/femparameters.C deleted file mode 100644 index 17ee827f894..00000000000 --- a/examples/adjoints/adjoints_ex4/femparameters.C +++ /dev/null @@ -1,78 +0,0 @@ -#include "femparameters.h" - -#define GETPOT_INPUT(A) { A = input(#A, A); \ - std::string stringval = input(#A, std::string()); \ - variable_names.push_back(std::string(#A "=") + stringval); }; -#define GETPOT_INT_INPUT(A) { A = input(#A, (int)A); \ - std::string stringval = input(#A, std::string()); \ - variable_names.push_back(std::string(#A "=") + stringval); }; -#define GETPOT_REGISTER(A) { \ - std::string stringval = input(#A, std::string()); \ - variable_names.push_back(std::string(#A "=") + stringval); }; - - -void FEMParameters::read(GetPot &input) -{ - std::vector variable_names; - - - GETPOT_INT_INPUT(coarserefinements); - GETPOT_INPUT(domainfile); - - GETPOT_INPUT(solver_quiet); - GETPOT_INPUT(reuse_preconditioner); - GETPOT_INPUT(require_residual_reduction); - GETPOT_INPUT(min_step_length); - GETPOT_INT_INPUT(max_linear_iterations); - GETPOT_INT_INPUT(max_nonlinear_iterations); - GETPOT_INPUT(relative_step_tolerance); - GETPOT_INPUT(relative_residual_tolerance); - GETPOT_INPUT(initial_linear_tolerance); - GETPOT_INPUT(minimum_linear_tolerance); - GETPOT_INPUT(linear_tolerance_multiplier); - GETPOT_INT_INPUT(nelem_target); - GETPOT_INPUT(global_tolerance); - GETPOT_INPUT(refine_fraction); - GETPOT_INPUT(coarsen_fraction); - GETPOT_INPUT(coarsen_threshold); - GETPOT_INT_INPUT(max_adaptivesteps); - GETPOT_INPUT(refine_uniformly); - GETPOT_INPUT(indicator_type); - GETPOT_INPUT(patch_reuse); - - GETPOT_REGISTER(fe_family); - const unsigned int n_fe_family = - std::max(1u, input.vector_variable_size("fe_family")); - fe_family.resize(n_fe_family, "LAGRANGE"); - for (unsigned int i=0; i != n_fe_family; ++i) - fe_family[i] = input("fe_family", fe_family[i].c_str(), i); - GETPOT_REGISTER(fe_order); - const unsigned int n_fe_order = - input.vector_variable_size("fe_order"); - fe_order.resize(n_fe_order, 1); - for (unsigned int i=0; i != n_fe_order; ++i) - fe_order[i] = input("fe_order", (int)fe_order[i], i); - - GETPOT_INPUT(analytic_jacobians); - GETPOT_INPUT(verify_analytic_jacobians); - GETPOT_INPUT(print_solution_norms); - GETPOT_INPUT(print_solutions); - GETPOT_INPUT(print_residual_norms); - GETPOT_INPUT(print_residuals); - GETPOT_INPUT(print_jacobian_norms); - GETPOT_INPUT(print_jacobians); - - std::vector bad_variables = - input.unidentified_arguments(variable_names); - - if (libMesh::global_processor_id() == 0 && !bad_variables.empty()) - { - libMesh::err << "ERROR: Unrecognized variable(s):" << std::endl; - for (unsigned int i = 0; i != bad_variables.size(); ++i) - libMesh::err << bad_variables[i] << std::endl; - libMesh::err << "\nRecognized variables are:" << std::endl; - for (unsigned int i = 0; i != variable_names.size(); ++i) - libMesh::err << variable_names[i] << std::endl; - libmesh_error_msg("Fix/remove the unrecognized variables and try again."); - } -} diff --git a/examples/adjoints/adjoints_ex4/femparameters.h b/examples/adjoints/adjoints_ex4/femparameters.h index 536020414c9..82d6b2c5945 100644 --- a/examples/adjoints/adjoints_ex4/femparameters.h +++ b/examples/adjoints/adjoints_ex4/femparameters.h @@ -1,70 +1,149 @@ + #ifndef __fem_parameters_h__ #define __fem_parameters_h__ +#include "libmesh/libmesh_common.h" +#include "libmesh/dof_map.h" +#include "libmesh/enum_norm_type.h" +#include "libmesh/function_base.h" +#include "libmesh/getpot.h" +#include "libmesh/id_types.h" +#include "libmesh/parallel_object.h" +#include "libmesh/periodic_boundaries.h" +#include "libmesh/periodic_boundary.h" + #include +#include #include +#include -#include "libmesh/libmesh_common.h" -#include "libmesh/getpot.h" -// Bring in everything from the libMesh namespace -using namespace libMesh; -class FEMParameters +class FEMParameters : public libMesh::ParallelObject { public: - FEMParameters() : - domainfile("lshaped.xda"), - coarserefinements(0), - solver_quiet(true), - reuse_preconditioner(false), - require_residual_reduction(true), - min_step_length(1e-5), - max_linear_iterations(200000), max_nonlinear_iterations(20), - relative_step_tolerance(1.e-7), relative_residual_tolerance(1.e-10), - initial_linear_tolerance(1.e-3), minimum_linear_tolerance(TOLERANCE*TOLERANCE), - linear_tolerance_multiplier(1.e-3), - nelem_target(30000), global_tolerance(0.0), - refine_fraction(0.3), coarsen_fraction(0.3), coarsen_threshold(10), - refine_uniformly(false), - max_adaptivesteps(1), - indicator_type("kelly"), patch_reuse(true), - fe_family(1, "LAGRANGE"), fe_order(1, 1), - analytic_jacobians(true), verify_analytic_jacobians(0.0), - print_solution_norms(false), print_solutions(false), - print_residual_norms(false), print_residuals(false), - print_jacobian_norms(false), print_jacobians(false) {} - - void read(GetPot &input); - - std::string domainfile; - unsigned int coarserefinements; - - bool solver_quiet, reuse_preconditioner, require_residual_reduction; - Real min_step_length; - unsigned int max_linear_iterations, max_nonlinear_iterations; - Real relative_step_tolerance, relative_residual_tolerance, - initial_linear_tolerance, minimum_linear_tolerance, - linear_tolerance_multiplier; - - unsigned int nelem_target; - Real global_tolerance; - Real refine_fraction, coarsen_fraction, coarsen_threshold; - bool refine_uniformly; - unsigned int max_adaptivesteps; - - std::string indicator_type; - bool patch_reuse; - - std::vector fe_family; - std::vector fe_order; - - bool analytic_jacobians; - Real verify_analytic_jacobians; - - bool print_solution_norms, print_solutions, - print_residual_norms, print_residuals, - print_jacobian_norms, print_jacobians; + FEMParameters(const libMesh::Parallel::Communicator &comm_in); + + ~FEMParameters(); + + void read(GetPot &input, + const std::vector* other_variable_names = NULL); + + // Parameters applicable to entire EquationSystems: + + unsigned int initial_timestep, n_timesteps; + bool transient; + unsigned int deltat_reductions; + std::string timesolver_core; + libMesh::Real end_time, deltat, timesolver_theta, + timesolver_maxgrowth, timesolver_tolerance, + timesolver_upper_tolerance, steadystate_tolerance; + std::vector timesolver_norm; + + // Mesh generation + + unsigned int dimension; + std::string domaintype, domainfile, elementtype; + libMesh::Real elementorder; + libMesh::Real domain_xmin, domain_ymin, domain_zmin; + libMesh::Real domain_edge_width, domain_edge_length, domain_edge_height; + unsigned int coarsegridx, coarsegridy, coarsegridz; + unsigned int coarserefinements, extrarefinements; + std::string mesh_redistribute_func; + + // Mesh refinement + + unsigned int nelem_target; + libMesh::Real global_tolerance; + libMesh::Real refine_fraction, coarsen_fraction, coarsen_threshold; + unsigned int max_adaptivesteps; + unsigned int initial_adaptivesteps; + + // Output + + unsigned int write_interval; + bool write_gmv_error, write_tecplot_error, + write_exodus_error, + output_xda, output_xdr, + output_bz2, output_gz, + output_gmv, output_tecplot, + output_exodus, output_nemesis; + + // Types of Systems to create + + std::vector system_types; + + // Parameters applicable to each system: + + // Boundary and initial conditions + + std::vector periodic_boundaries; + + std::map *> + initial_conditions; + std::map *> + dirichlet_conditions, + neumann_conditions; + std::map > + dirichlet_condition_variables, + neumann_condition_variables; + std::map *> > + other_interior_functions; + std::map *> > + other_boundary_functions; + + // Execution type + + bool run_simulation, run_postprocess; + + // Approximation type + + std::vector fe_family; + std::vector fe_order; + int extra_quadrature_order; + + // Assembly options + + bool analytic_jacobians; + libMesh::Real verify_analytic_jacobians; + libMesh::Real numerical_jacobian_h; + + bool print_solution_norms, print_solutions, + print_residual_norms, print_residuals, + print_jacobian_norms, print_jacobians, + print_element_solutions, + print_element_residuals, + print_element_jacobians; + + // Solver options + + bool use_petsc_snes; + bool time_solver_quiet, solver_quiet, solver_verbose, + reuse_preconditioner, require_residual_reduction; + libMesh::Real min_step_length; + unsigned int max_linear_iterations, max_nonlinear_iterations; + libMesh::Real relative_step_tolerance, relative_residual_tolerance, + absolute_residual_tolerance, + initial_linear_tolerance, minimum_linear_tolerance, + linear_tolerance_multiplier; + + // Initialization + + unsigned int initial_sobolev_order; + unsigned int initial_extra_quadrature; + + // Error indicators + + bool refine_uniformly; + std::string indicator_type; + bool patch_reuse; + unsigned int sobolev_order; + + // System-specific parameters file + + std::string system_config_file; }; #endif // __fem_parameters_h__