From ca864cb0f607c04b8dfadc79facff2460a6afa1d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 4 Mar 2013 01:26:06 +0100 Subject: [PATCH 01/64] Some work on Euler - start with the coupled flow - heat problem. --- 2d-advanced/euler/CMakeLists.txt | 3 + 2d-advanced/euler/euler_util.cpp | 5 + 2d-advanced/euler/euler_util.h | 23 ++ 2d-advanced/euler/forms_explicit.cpp | 7 +- .../heating-flow-coupling/CMakeLists.txt | 4 + .../euler/heating-flow-coupling/main.cpp | 271 ++++++++++++++++++ .../euler/heating-flow-coupling/square.mesh | 29 ++ 2d-advanced/euler/initial_condition.cpp | 2 +- 8 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 2d-advanced/euler/heating-flow-coupling/CMakeLists.txt create mode 100644 2d-advanced/euler/heating-flow-coupling/main.cpp create mode 100644 2d-advanced/euler/heating-flow-coupling/square.mesh diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index e0a888e..895de4f 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -11,3 +11,6 @@ add_subdirectory(heating-induced-vortex) # add_subdirectory(euler-coupled) # add_subdirectory(euler-coupled-adapt) + + +add_subdirectory(heating-flow-coupling) \ No newline at end of file diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index b39e8bb..46bb91d 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -1297,6 +1297,11 @@ void PressureFilter::filter_fn(int n, Hermes::vector values, double* re result[i] = (kappa - 1.) * (values.at(3)[i] - (values.at(1)[i]*values.at(1)[i] + values.at(2)[i]*values.at(2)[i])/(2*values.at(0)[i])); } +void VelocityFilter::filter_fn(int n, Hermes::vector values, double* result) +{ + for (int i = 0; i < n; i++) + result[i] = values.at(0)[i] * values.at(1)[i]; +} void EntropyFilter::filter_fn(int n, Hermes::vector values, double* result) { diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index 1e14db7..4a1048c 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -236,6 +236,29 @@ class PressureFilter : public Hermes::Hermes2D::SimpleFilter double kappa; }; +class VelocityFilter : public Hermes::Hermes2D::SimpleFilter +{ +public: + // Vector of solutions: 0-th position - density, 1-st position - velocity component. + VelocityFilter(Hermes::vector*> solutions) : SimpleFilter(solutions) {}; + ~VelocityFilter() + { + }; + + MeshFunction* clone() const + { + Hermes::vector*> slns; + for(int i = 0; i < this->num; i++) + slns.push_back(this->sln[i]->clone()); + + VelocityFilter* filter = new VelocityFilter(slns); + filter->setDeleteSolutions(); + return filter; + } +protected: + virtual void filter_fn(int n, Hermes::vector values, double* result); +}; + class EntropyFilter : public Hermes::Hermes2D::SimpleFilter { public: diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index b25ed94..814e5df 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -829,7 +829,12 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm wf->ext.clear(); for(unsigned int i = 0; i < this->ext.size(); i++) - wf->ext.push_back(this->ext[i]->clone()); + { + Solution* ext = static_cast*>(this->ext[i]->clone()); + if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + ext->set_type(HERMES_SLN); + wf->ext.push_back(ext); + } wf->set_current_time_step(this->get_current_time_step()); diff --git a/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt b/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt new file mode 100644 index 0000000..242fb66 --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt @@ -0,0 +1,4 @@ +project(heating-flow-coupling) + +add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp) +set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp new file mode 100644 index 0000000..4b1057e --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -0,0 +1,271 @@ +#define HERMES_REPORT_INFO +#define HERMES_REPORT_FILE "application.log" +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::Views; + +// This example solves the compressible Euler equations using a basic +// piecewise-constant finite volume method, or Discontinuous Galerkin method of higher order with no adaptivity. +// +// Equations: Compressible Euler equations, perfect gas state equation. +// +// Domain: A square, see file square.mesh. +// +// BC: Solid walls, inlet, no outlet. +// +// IC: Constant state identical to inlet, only with higher pressure. +// +// The following parameters can be changed: + +// Visualization. +// Set to "true" to enable Hermes OpenGL visualization. +const bool HERMES_VISUALIZATION = true; +// Set to "true" to enable VTK output. +const bool VTK_VISUALIZATION = false; +// Set visual output for every nth step. +const unsigned int EVERY_NTH_STEP = 1; + +// Shock capturing. +enum shockCapturingType +{ + FEISTAUER, + KUZMIN, + KRIVODONOVA +}; +bool SHOCK_CAPTURING = true; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +// Quantitative parameter of the discontinuity detector in case of Krivodonova. +double DISCONTINUITY_DETECTOR_PARAM = 1.0; +// Quantitative parameter of the shock capturing in case of Feistauer. +const double NU_1 = 0.1; +const double NU_2 = 0.1; + +// For saving/loading of solution. +bool REUSE_SOLUTION = false; + +// Initial polynomial degree. +const int P_INIT = 1; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 4; +// CFL value. +double CFL_NUMBER = 0.5; +// Initial time step. +double time_step = 1E-4; +// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, +// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. +const MatrixSolverType matrix_solver = SOLVER_UMFPACK; + +// Equation parameters. +// Exterior pressure (dimensionless). +const double P_EXT = 2.0; +// Initial pressure (dimensionless). +const double P_INITIAL_HIGH = 1.5; +// Initial pressure (dimensionless). +const double P_INITIAL_LOW = 1.0; +// Inlet density (dimensionless). +const double RHO_EXT = 1.0; +// Initial density (dimensionless). +const double RHO_INITIAL_HIGH = 0.5; +// Initial density (dimensionless). +const double RHO_INITIAL_LOW = 0.3; +// Inlet x-velocity (dimensionless). +const double V1_EXT = 0.0; +// Inlet y-velocity (dimensionless). +const double V2_EXT = 0.0; +// Kappa. +const double KAPPA = 1.4; + +// Boundary markers. +const std::string BDY_INLET = "Inlet"; +const std::string BDY_SOLID_WALL = "Solid"; + +// Area (square) size. +// Must be in accordance with the mesh file. +const double MESH_SIZE = 3.0; + +// Weak forms. +#include "../forms_explicit.cpp" + +// Initial condition. +#include "../initial_condition.cpp" + +int main(int argc, char* argv[]) +{ + // Load the mesh. + Mesh mesh; + MeshReaderH2D mloader; + mloader.load("square.mesh", &mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh.refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + L2Space space_rho(&mesh, P_INIT); + L2Space space_rho_v_x(&mesh, P_INIT); + L2Space space_rho_v_y(&mesh, P_INIT); + L2Space space_e(&mesh, P_INIT); + L2Space space_stabilization(&mesh, 0); + int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + + // Initialize solutions, set initial conditions. + InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); + ConstantSolution prev_rho_v_x(&mesh, 0.0); + ConstantSolution prev_rho_v_y(&mesh, 0.0); + InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + + // Filters for visualization of Mach number, pressure and entropy. + PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); + VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + VectorView velocity_view("Velocity", new WinGeom(0, 400, 600, 300)); + ScalarView velocity_view_x("Velocity - x", new WinGeom(0, 400, 600, 300)); + ScalarView velocity_view_y("Velocity - y", new WinGeom(700, 400, 600, 300)); + ScalarView density_view("Density", new WinGeom(1400, 0, 600, 300)); + + // Set up the solver, matrix, and rhs according to the solver selection. + SparseMatrix* matrix = create_matrix(); + Vector* rhs = create_vector(); + Vector* rhs_stabilization = create_vector(); + LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + + // Set up CFL calculation class. + CFLCalculation CFL(CFL_NUMBER, KAPPA); + + // Look for a saved solution on the disk. + CalculationContinuity continuity(CalculationContinuity::onlyTime); + int iteration = 0; double t = 0; + + if(REUSE_SOLUTION && continuity.have_record_available()) + { + continuity.get_last_record()->load_mesh(&mesh); + Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); + space_rho.copy(spaceVector[0], &mesh); + space_rho_v_x.copy(spaceVector[1], &mesh); + space_rho_v_y.copy(spaceVector[2], &mesh); + space_e.copy(spaceVector[3], &mesh); + continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e)); + continuity.get_last_record()->load_time_step_length(time_step); + t = continuity.get_last_record()->get_time(); + iteration = continuity.get_num(); + } + + // Initialize weak formulation. + Hermes::vector solid_wall_markers; + solid_wall_markers.push_back(BDY_SOLID_WALL); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, + inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); + + EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); + + if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); + + // Initialize the FE problem. + DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); + + // If the FE problem is in fact a FV problem. + if(P_INIT == 0) + dp.set_fvm(); + + // Time stepping loop. + for(; t < 10.0; t += time_step) + { + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + + if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + { + assert(space_stabilization.get_num_dofs() == space_stabilization.get_mesh()->get_num_active_elements()); + dp_stabilization.assemble(rhs_stabilization); + bool* discreteIndicator = new bool[space_stabilization.get_num_dofs()]; + memset(discreteIndicator, 0, space_stabilization.get_num_dofs() * sizeof(bool)); + Element* e; + for_all_active_elements(e, space_stabilization.get_mesh()) + { + AsmList al; + space_stabilization.get_element_assembly_list(e, &al); + if(rhs_stabilization->get(al.get_dof()[0]) >= 1) + discreteIndicator[e->id] = true; + } + wf.set_discreteIndicator(discreteIndicator, space_stabilization.get_num_dofs()); + } + + // Set the current time step. + wf.set_current_time_step(time_step); + + // Assemble the stiffness matrix and rhs. + Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); + dp.assemble(matrix, rhs); + + // Solve the matrix problem. + Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); + if(solver->solve()) + { + if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) + { + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + } + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e), true); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e)); + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(); + + flux_limiter->limit_according_to_detector(); + + flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + } + } + else + throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); + + CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + + // Visualization. + if((iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + pressure.reinit(); + vel_x.reinit(); + vel_y.reinit(); + pressure_view.show(&pressure); + velocity_view.show(&vel_x, &vel_y); + density_view.show(&prev_rho); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure.reinit(); + Linearizer lin_pressure; + char filename[40]; + sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); + lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + } + } + } + + pressure_view.close(); + + return 0; +} diff --git a/2d-advanced/euler/heating-flow-coupling/square.mesh b/2d-advanced/euler/heating-flow-coupling/square.mesh new file mode 100644 index 0000000..28edcc3 --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling/square.mesh @@ -0,0 +1,29 @@ +# Everything is in meters: + +vertices = [ + [ 0, 0 ], + [ 1, 0 ], + [ 2, 0 ], + [ 3, 0 ], + [ 3, 3 ], + [ 2, 3 ], + [ 1, 3 ], + [ 0, 3 ] +] + +elements = [ + [ 0, 1, 6, 7, 0 ], + [ 1, 2, 5, 6, 0 ], + [ 2, 3, 4, 5, 0 ] +] + +boundaries = [ + [ 0, 1, "Solid" ], + [ 1, 2, "Solid" ], + [ 2, 3, "Inlet" ], + [ 3, 4, "Solid" ], + [ 4, 5, "Solid" ], + [ 5, 6, "Solid" ], + [ 6, 7, "Solid" ], + [ 7, 0, "Solid" ] +] \ No newline at end of file diff --git a/2d-advanced/euler/initial_condition.cpp b/2d-advanced/euler/initial_condition.cpp index 3ccb6ea..5933283 100644 --- a/2d-advanced/euler/initial_condition.cpp +++ b/2d-advanced/euler/initial_condition.cpp @@ -47,7 +47,7 @@ class InitialSolutionLinearProgress : public ExactSolutionScalar return Ord(1); } - MeshFunction* clone() const { return new InitialSolutionLinearProgress(mesh, max, min, size); } + MeshFunction* clone() const { if(this->get_type() == HERMES_SLN) return Solution::clone(); else return new InitialSolutionLinearProgress(mesh, max, min, size); } // Value. double max, min, size; From 83d753d405ecb7b0bf9785dfa3c1e5cbb5ed2245 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 4 Mar 2013 17:56:15 +0100 Subject: [PATCH 02/64] Work on Euler. --- 2d-advanced/euler/euler_util.cpp | 2 +- 2d-advanced/euler/forms_explicit.cpp | 245 +++++++++++------- .../euler/heating-flow-coupling/main.cpp | 64 +++-- 3 files changed, 182 insertions(+), 129 deletions(-) diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index 46bb91d..a1047b1 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -1300,7 +1300,7 @@ void PressureFilter::filter_fn(int n, Hermes::vector values, double* re void VelocityFilter::filter_fn(int n, Hermes::vector values, double* result) { for (int i = 0; i < n; i++) - result[i] = values.at(0)[i] * values.at(1)[i]; + result[i] = values.at(1)[i] / values.at(0)[i]; } void EntropyFilter::filter_fn(int n, Hermes::vector values, double* result) diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index 814e5df..78da4e5 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -602,6 +602,8 @@ class EulerEquationsWeakFormExplicit : public WeakForm }; */ + + class EulerEquationsWeakFormSemiImplicit : public WeakForm { public: @@ -633,8 +635,6 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm // For cache handling. class EulerEquationsMatrixFormSurfSemiImplicit; class EulerEquationsMatrixFormSemiImplicitInletOutlet; - Hermes::vector dgForms; - Hermes::vector dgFormsInletOutlet; bool cacheReadyDG; bool cacheReadySurf; double** P_plus_cache_DG; @@ -697,17 +697,14 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); - dgForms.push_back(formDG); add_matrix_form_DG(formDG); EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - dgFormsInletOutlet.push_back(formSurf); add_matrix_form_surf(formSurf); if(outlet_markers.size() > 0) { formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - dgFormsInletOutlet.push_back(formSurf); add_matrix_form_surf(formSurf); } @@ -767,18 +764,15 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); - dgForms.push_back(formDG); add_matrix_form_DG(formDG); for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) { EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext[inlet_i], v1_ext[inlet_i], v2_ext[inlet_i], energy_ext[inlet_i], inlet_markers[inlet_i], kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - dgFormsInletOutlet.push_back(formSurf); add_matrix_form_surf(formSurf); } EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - dgFormsInletOutlet.push_back(formSurf); add_matrix_form_surf(formSurf); add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(form_i, form_j, solid_wall_markers, kappa)); @@ -907,13 +901,6 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm public: EulerEquationsBilinearFormTime(int i) : MatrixFormVol(i, i) {} - template - Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return int_u_v(n, wt, u, v); - } - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { @@ -1023,7 +1010,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return Ord(10); } MatrixFormVol* clone() const @@ -1415,7 +1402,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return int_u_v(n, wt, ext[this->i], v); } VectorFormVol* clone() const { return new EulerEquationsLinearFormTime(this->i); } @@ -1452,89 +1439,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm P[2][2] = (kappa - 1) * (-v_2) * e->ny[point_i]; P[2][3] = (kappa - 1) * e->ny[point_i]; - if(i == 0 && j == 0) - { - result += wt[point_i] * P[0][0] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 0 && j == 1) - { - result += wt[point_i] * P[0][1] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 0 && j == 2) - { - result += wt[point_i] * P[0][2] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 0 && j == 3) - { - result += wt[point_i] * P[0][3] * u->val[point_i] * v->val[point_i]; - continue; - } - - if(i == 1 && j == 0) - { - result += wt[point_i] * P[1][0] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 1 && j == 1) - { - result += wt[point_i] * P[1][1] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 1 && j == 2) - { - result += wt[point_i] * P[1][2] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 1 && j == 3) - { - result += wt[point_i] * P[1][3] * u->val[point_i] * v->val[point_i]; - continue; - } - - if(i == 2 && j == 0) - { - result += wt[point_i] * P[2][0] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 2 && j == 1) - { - result += wt[point_i] * P[2][1] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 2 && j == 2) - { - result += wt[point_i] * P[2][2] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 2 && j == 3) - { - result += wt[point_i] * P[2][3] * u->val[point_i] * v->val[point_i]; - continue; - } - - if(i == 3 && j == 0) - { - result += wt[point_i] * P[3][0] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 3 && j == 1) - { - result += wt[point_i] * P[3][1] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 3 && j == 2) - { - result += wt[point_i] * P[3][2] * u->val[point_i] * v->val[point_i]; - continue; - } - if(i == 3 && j == 3) - { - result += wt[point_i] * P[3][3] * u->val[point_i] * v->val[point_i]; - continue; - } + result += wt[point_i] * P[i][j] * u->val[point_i] * v->val[point_i]; } return result * wf->get_current_time_step(); @@ -1625,8 +1530,148 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm double nu_2; }; + + }; +class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsWeakFormSemiImplicit +{ +public: + Solution* prev_temp; + + EulerEquationsWeakFormSemiImplicitCoupledWithHeat(double kappa, + double rho_ext, double v1_ext, double v2_ext, double pressure_ext, + Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, + Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, Solution* prev_temp, + bool fvm_only = false) : EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, + prev_density_vel_x, prev_density_vel_y, prev_energy, fvm_only, 5), prev_temp(prev_temp) + { + add_matrix_form(new HeatBilinearFormTime(4)); + + add_vector_form(new HeatLinearFormTime(4)); + + this->add_vector_form_surf(new HeatLinearSurfForm(4, inlet_markers)); + + this->ext.push_back(prev_temp); + } + + WeakForm* clone() const + { + EulerEquationsWeakFormSemiImplicitCoupledWithHeat* wf; + wf = new EulerEquationsWeakFormSemiImplicitCoupledWithHeat(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->prev_temp, this->fvm_only); + + wf->ext.clear(); + + for(unsigned int i = 0; i < this->ext.size(); i++) + { + Solution* ext = static_cast*>(this->ext[i]->clone()); + if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + ext->set_type(HERMES_SLN); + wf->ext.push_back(ext); + } + + wf->set_current_time_step(this->get_current_time_step()); + + return wf; + } + + class HeatBilinearFormTime : public MatrixFormVol + { + public: + HeatBilinearFormTime(int i) : MatrixFormVol(i, i), c_p(1e2), lambda(1e2) {} + + double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) + { + double rho = ext[0]->val[point_i]; + result += wt[point_i] * u->val[point_i] * v->val[point_i] * rho * c_p; + result -= wt[point_i] * (u->dx[point_i] * v->dx[point_i] + u->dy[point_i] * v->dy[point_i]) * lambda; + result -= (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i] * c_p; + } + return result; + } + + Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, + Func* *ext) const + { + Ord result = Ord(0); + for (int point_i = 0; point_i < n; point_i++) + { + Ord rho = ext[0]->val[point_i]; + result += wt[point_i] * (u->val[point_i] * v->val[point_i] * rho - u->dx[point_i] * v->dx[point_i] - u->dy[point_i] * v->dy[point_i] - rho * rho * (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i]); + } + return result; + } + + MatrixFormVol* clone() const { return new HeatBilinearFormTime(this->i); } + + double c_p, lambda; + }; + + class HeatLinearFormTime : public VectorFormVol + { + public: + HeatLinearFormTime(int i) + : VectorFormVol(i), c_p(1e2) {} + + double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const + { + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) + { + double rho = ext[0]->val[point_i]; + result += wt[i] * v->val[point_i] * rho * ext[this->i]->val[point_i] * c_p; + } + return result; + } + + Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const + { + return wt[0] * v->val[0] * ext[0]->val[0] * ext[this->i]->val[0]; + } + + VectorFormVol* clone() const { return new HeatLinearFormTime(this->i); } + + double c_p; + }; + + class HeatLinearSurfForm : public VectorFormSurf + { + public: + HeatLinearSurfForm(int i, Hermes::vector areas) + : VectorFormSurf(i), neumann_value(1e-6), lambda(1e2) + { + this->set_areas(areas); + } + + double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const + { + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) + result -= wt[i] * v->val[point_i] * neumann_value * lambda; + return result; + } + + Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const + { + return wt[0] * v->val[0]; + } + + VectorFormSurf* clone() const { return new HeatLinearSurfForm(this->i, this->areas); } + + double neumann_value, lambda; + }; +}; + + /* class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm { diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 4b1057e..250bebc 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -50,7 +50,7 @@ const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 4; // CFL value. -double CFL_NUMBER = 0.5; +double CFL_NUMBER = 0.7; // Initial time step. double time_step = 1E-4; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, @@ -59,13 +59,13 @@ const MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Equation parameters. // Exterior pressure (dimensionless). -const double P_EXT = 2.0; +const double P_EXT = 1.5; // Initial pressure (dimensionless). const double P_INITIAL_HIGH = 1.5; // Initial pressure (dimensionless). const double P_INITIAL_LOW = 1.0; // Inlet density (dimensionless). -const double RHO_EXT = 1.0; +const double RHO_EXT = 0.5; // Initial density (dimensionless). const double RHO_INITIAL_HIGH = 0.5; // Initial density (dimensionless). @@ -77,6 +77,10 @@ const double V2_EXT = 0.0; // Kappa. const double KAPPA = 1.4; +// Stability for the concentration part. +double ADVECTION_STABILITY_CONSTANT = 0.1; +const double DIFFUSION_STABILITY_CONSTANT = 0.1; + // Boundary markers. const std::string BDY_INLET = "Inlet"; const std::string BDY_SOLID_WALL = "Solid"; @@ -93,6 +97,8 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { + Hermes2DApi.set_integral_param_value(numThreads, 1); + // Load the mesh. Mesh mesh; MeshReaderH2D mloader; @@ -103,12 +109,16 @@ int main(int argc, char* argv[]) mesh.refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. + Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); + EssentialBCs bcs(&bc_temp_zero); + L2Space space_rho(&mesh, P_INIT); L2Space space_rho_v_x(&mesh, P_INIT); L2Space space_rho_v_y(&mesh, P_INIT); L2Space space_e(&mesh, P_INIT); + H1Space space_temp(&mesh, &bcs, 1); L2Space space_stabilization(&mesh, 0); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. @@ -116,6 +126,7 @@ int main(int argc, char* argv[]) ConstantSolution prev_rho_v_x(&mesh, 0.0); ConstantSolution prev_rho_v_y(&mesh, 0.0); InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + ConstantSolution prev_temp(&mesh, 0.0); // Filters for visualization of Mach number, pressure and entropy. PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); @@ -127,6 +138,7 @@ int main(int argc, char* argv[]) ScalarView velocity_view_x("Velocity - x", new WinGeom(0, 400, 600, 300)); ScalarView velocity_view_y("Velocity - y", new WinGeom(700, 400, 600, 300)); ScalarView density_view("Density", new WinGeom(1400, 0, 600, 300)); + ScalarView temperature_view("Temperature", new WinGeom(1400, 400, 600, 300)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(); @@ -136,26 +148,11 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); + ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, 1e2); // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); int iteration = 0; double t = 0; - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - } - // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); @@ -163,8 +160,8 @@ int main(int argc, char* argv[]) inlet_markers.push_back(BDY_INLET); Hermes::vector outlet_markers; - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); + EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, + inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp); EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); @@ -172,13 +169,9 @@ int main(int argc, char* argv[]) wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); - // If the FE problem is in fact a FV problem. - if(P_INIT == 0) - dp.set_fvm(); - // Time stepping loop. for(; t < 10.0; t += time_step) { @@ -215,7 +208,7 @@ int main(int argc, char* argv[]) if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) { Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + &space_rho_v_y, &space_e, &space_temp), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp)); } else { @@ -233,6 +226,9 @@ int main(int argc, char* argv[]) flux_limiter->limit_according_to_detector(); flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e)), &space_temp, &prev_temp); } } else @@ -240,6 +236,14 @@ int main(int argc, char* argv[]) CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + double util_time_step = time_step; + + ADES.calculate(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y), &mesh, util_time_step); + + if(util_time_step < time_step) + time_step = util_time_step; + + // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) { @@ -252,6 +256,7 @@ int main(int argc, char* argv[]) pressure_view.show(&pressure); velocity_view.show(&vel_x, &vel_y); density_view.show(&prev_rho); + temperature_view.show(&prev_temp); } // Output solution in VTK format. if(VTK_VISUALIZATION) @@ -266,6 +271,9 @@ int main(int argc, char* argv[]) } pressure_view.close(); + velocity_view.close(); + density_view.close(); + temperature_view.close(); return 0; } From 107efb8da5434357a43c512483ed55a8f614f801 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 5 Mar 2013 17:54:34 +0100 Subject: [PATCH 03/64] Progress on Euler. --- 2d-advanced/euler/CMakeLists.txt | 3 +- 2d-advanced/euler/euler_util.cpp | 475 ++- 2d-advanced/euler/euler_util.h | 3 - 2d-advanced/euler/forms_explicit.cpp | 3418 ++++------------- .../CMakeLists.txt | 4 + .../heating-flow-coupling-adapt/main.cpp | 244 ++ .../heating-flow-coupling-adapt/square.mesh | 29 + .../euler/heating-induced-vortex/main.cpp | 158 +- 8 files changed, 1198 insertions(+), 3136 deletions(-) create mode 100644 2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt create mode 100644 2d-advanced/euler/heating-flow-coupling-adapt/main.cpp create mode 100644 2d-advanced/euler/heating-flow-coupling-adapt/square.mesh diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index 895de4f..9e044a5 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -13,4 +13,5 @@ add_subdirectory(heating-induced-vortex) # add_subdirectory(euler-coupled-adapt) -add_subdirectory(heating-flow-coupling) \ No newline at end of file +add_subdirectory(heating-flow-coupling) +add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index a1047b1..5c589bc 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -52,20 +52,20 @@ void CFLCalculation::calculate(Hermes::vector*> solutions, Mesh Element *e; for_all_active_elements(e, mesh) { - AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); - double rho = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); - double v1 = sln_vector[al.get_dof()[0]] / rho; - constant_rho_v_y_space.get_element_assembly_list(e, &al); - double v2 = sln_vector[al.get_dof()[0]] / rho; - constant_energy_space.get_element_assembly_list(e, &al); - double energy = sln_vector[al.get_dof()[0]]; - - double condition = e->get_area() * CFL_number / (std::sqrt(v1*v1 + v2*v2) + QuantityCalculator::calc_sound_speed(rho, rho*v1, rho*v2, energy, kappa)); - - if(condition < min_condition || min_condition == 0.) - min_condition = condition; + AsmList al; + constant_rho_space.get_element_assembly_list(e, &al); + double rho = sln_vector[al.get_dof()[0]]; + constant_rho_v_x_space.get_element_assembly_list(e, &al); + double v1 = sln_vector[al.get_dof()[0]] / rho; + constant_rho_v_y_space.get_element_assembly_list(e, &al); + double v2 = sln_vector[al.get_dof()[0]] / rho; + constant_energy_space.get_element_assembly_list(e, &al); + double energy = sln_vector[al.get_dof()[0]]; + + double condition = e->get_area() * CFL_number / (std::sqrt(v1*v1 + v2*v2) + QuantityCalculator::calc_sound_speed(rho, rho*v1, rho*v2, energy, kappa)); + + if(condition < min_condition || min_condition == 0.) + min_condition = condition; } time_step = min_condition; @@ -93,66 +93,66 @@ void CFLCalculation::calculate_semi_implicit(Hermes::vector*> s double w[4]; for_all_active_elements(e, mesh) { -AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); - w[0] = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); - w[1] = sln_vector[al.get_dof()[0]]; - constant_rho_v_y_space.get_element_assembly_list(e, &al); - w[2] = sln_vector[al.get_dof()[0]]; - constant_energy_space.get_element_assembly_list(e, &al); - w[3] = sln_vector[al.get_dof()[0]]; - - double edge_length_max_lambda = 0.0; + AsmList al; + constant_rho_space.get_element_assembly_list(e, &al); + w[0] = sln_vector[al.get_dof()[0]]; + constant_rho_v_x_space.get_element_assembly_list(e, &al); + w[1] = sln_vector[al.get_dof()[0]]; + constant_rho_v_y_space.get_element_assembly_list(e, &al); + w[2] = sln_vector[al.get_dof()[0]]; + constant_energy_space.get_element_assembly_list(e, &al); + w[3] = sln_vector[al.get_dof()[0]]; + + double edge_length_max_lambda = 0.0; - solutions[0]->set_active_element(e); - for(unsigned int edge_i = 0; edge_i < e->get_nvert(); edge_i++) { - // Initialization. - SurfPos surf_pos; - surf_pos.marker = e->marker; - surf_pos.surf_num = edge_i; - int eo = solutions[1]->get_quad_2d()->get_edge_points(surf_pos.surf_num, 20, e->get_mode()); - double3* tan = NULL; - Geom* geom = init_geom_surf(solutions[0]->get_refmap(), surf_pos.surf_num, surf_pos.marker, eo, tan); - int np = solutions[1]->get_quad_2d()->get_num_points(eo, e->get_mode()); + solutions[0]->set_active_element(e); + for(unsigned int edge_i = 0; edge_i < e->get_nvert(); edge_i++) { + // Initialization. + SurfPos surf_pos; + surf_pos.marker = e->marker; + surf_pos.surf_num = edge_i; + int eo = solutions[1]->get_quad_2d()->get_edge_points(surf_pos.surf_num, 20, e->get_mode()); + double3* tan = NULL; + Geom* geom = init_geom_surf(solutions[0]->get_refmap(), surf_pos.surf_num, surf_pos.marker, eo, tan); + int np = solutions[1]->get_quad_2d()->get_num_points(eo, e->get_mode()); + + // Calculation of the edge length. + double edge_length = std::sqrt(std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->x - e->vn[edge_i]->x, 2) + std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->y - e->vn[edge_i]->y, 2)); + + // Calculation of the maximum eigenvalue of the matrix P. + double max_eigen_value = 0.0; + for(int point_i = 0; point_i < np; point_i++) { + // Transform to the local coordinates. + double transformed[4]; + transformed[0] = w[0]; + transformed[1] = geom->nx[point_i] * w[1] + geom->ny[point_i] * w[2]; + transformed[2] = -geom->ny[point_i] * w[1] + geom->nx[point_i] * w[2]; + transformed[3] = w[3]; + + // Calc sound speed. + double a = QuantityCalculator::calc_sound_speed(transformed[0], transformed[1], transformed[2], transformed[3], kappa); + + // Calc max eigenvalue. + if(transformed[1] / transformed[0] - a > max_eigen_value || point_i == 0) + max_eigen_value = transformed[1] / transformed[0] - a; + if(transformed[1] / transformed[0] > max_eigen_value) + max_eigen_value = transformed[1] / transformed[0]; + if(transformed[1] / transformed[0] + a> max_eigen_value) + max_eigen_value = transformed[1] / transformed[0] + a; + } - // Calculation of the edge length. - double edge_length = std::sqrt(std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->x - e->vn[edge_i]->x, 2) + std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->y - e->vn[edge_i]->y, 2)); + if(edge_length * max_eigen_value > edge_length_max_lambda || edge_i == 0) + edge_length_max_lambda = edge_length * max_eigen_value; - // Calculation of the maximum eigenvalue of the matrix P. - double max_eigen_value = 0.0; - for(int point_i = 0; point_i < np; point_i++) { - // Transform to the local coordinates. - double transformed[4]; - transformed[0] = w[0]; - transformed[1] = geom->nx[point_i] * w[1] + geom->ny[point_i] * w[2]; - transformed[2] = -geom->ny[point_i] * w[1] + geom->nx[point_i] * w[2]; - transformed[3] = w[3]; - - // Calc sound speed. - double a = QuantityCalculator::calc_sound_speed(transformed[0], transformed[1], transformed[2], transformed[3], kappa); - - // Calc max eigenvalue. - if(transformed[1] / transformed[0] - a > max_eigen_value || point_i == 0) - max_eigen_value = transformed[1] / transformed[0] - a; - if(transformed[1] / transformed[0] > max_eigen_value) - max_eigen_value = transformed[1] / transformed[0]; - if(transformed[1] / transformed[0] + a> max_eigen_value) - max_eigen_value = transformed[1] / transformed[0] + a; + geom->free(); + delete geom; } - if(edge_length * max_eigen_value > edge_length_max_lambda || edge_i == 0) - edge_length_max_lambda = edge_length * max_eigen_value; - geom->free(); - delete geom; - } + double condition = e->get_area() * CFL_number / edge_length_max_lambda; - - double condition = e->get_area() * CFL_number / edge_length_max_lambda; - - if(condition < min_condition || min_condition == 0.) - min_condition = condition; + if(condition < min_condition || min_condition == 0.) + min_condition = condition; } time_step = min_condition; @@ -188,22 +188,22 @@ void ADEStabilityCalculation::calculate(Hermes::vector*> soluti Element *e; for_all_active_elements(e, mesh) { -AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); - double rho = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); - double v1 = sln_vector[al.get_dof()[0] + constant_rho_space.get_num_dofs()] / rho; - constant_rho_v_y_space.get_element_assembly_list(e, &al); - double v2 = sln_vector[al.get_dof()[0] + constant_rho_space.get_num_dofs() + constant_rho_space.get_num_dofs()] / rho; - - double condition_advection = AdvectionRelativeConstant * approximate_inscribed_circle_radius(e) / std::sqrt(v1*v1 + v2*v2); - double condition_diffusion = DiffusionRelativeConstant * e->get_area() / epsilon; - - if(condition_advection < min_condition_advection || min_condition_advection == 0.) - min_condition_advection = condition_advection; - - if(condition_diffusion < min_condition_diffusion || min_condition_diffusion == 0.) - min_condition_diffusion = condition_diffusion; + AsmList al; + constant_rho_space.get_element_assembly_list(e, &al); + double rho = sln_vector[al.get_dof()[0]]; + constant_rho_v_x_space.get_element_assembly_list(e, &al); + double v1 = sln_vector[al.get_dof()[0] + constant_rho_space.get_num_dofs()] / rho; + constant_rho_v_y_space.get_element_assembly_list(e, &al); + double v2 = sln_vector[al.get_dof()[0] + 2 * constant_rho_space.get_num_dofs()] / rho; + + double condition_advection = AdvectionRelativeConstant * e->get_diameter() / std::sqrt(v1*v1 + v2*v2); + double condition_diffusion = DiffusionRelativeConstant * e->get_area() / epsilon; + + if(condition_advection < min_condition_advection || min_condition_advection == 0.) + min_condition_advection = condition_advection; + + if(condition_diffusion < min_condition_diffusion || min_condition_diffusion == 0.) + min_condition_diffusion = condition_diffusion; } time_step = std::min(min_condition_advection, min_condition_diffusion); @@ -211,17 +211,6 @@ AsmList al; delete [] sln_vector; } -double ADEStabilityCalculation::approximate_inscribed_circle_radius(Element * e) -{ - double h = std::sqrt(std::pow(e->vn[(0 + 1) % e->get_nvert()]->x - e->vn[0]->x, 2) + std::pow(e->vn[(0 + 1) % e->get_nvert()]->y - e->vn[0]->y, 2)); - for(int edge_i = 0; edge_i < e->get_nvert(); edge_i++) { - double edge_length = std::sqrt(std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->x - e->vn[edge_i]->x, 2) + std::pow(e->vn[(edge_i + 1) % e->get_nvert()]->y - e->vn[edge_i]->y, 2)); - if(edge_length < h) - h = edge_length; - } - return h / 2; -} - DiscontinuityDetector::DiscontinuityDetector(Hermes::vector*> spaces, Hermes::vector*> solutions) : spaces(spaces), solutions(solutions) { @@ -314,7 +303,7 @@ double KrivodonovaDiscontinuityDetector::calculate_relative_flow_direction(Eleme double3* tan; Geom* geom = init_geom_surf(solutions[1]->get_refmap(), surf_pos.surf_num, surf_pos.marker, eo, tan); - + double* jwt = new double[np]; for(int i = 0; i < np; i++) jwt[i] = pt[i][2] * tan[i][2]; @@ -556,77 +545,77 @@ std::set& KuzminDiscontinuityDetector::get_discontinuous_element_ids() u_i_min_first_order[i][j] = std::numeric_limits::infinity(); u_i_max_first_order[i][j] = -std::numeric_limits::infinity(); } - find_u_i_min_max_first_order(e, u_i_min_first_order, u_i_max_first_order); + find_u_i_min_max_first_order(e, u_i_min_first_order, u_i_max_first_order); - // alpha_i calculation. - double alpha_i_first_order[4]; - find_alpha_i_first_order(u_i_min_first_order, u_i_max_first_order, u_c, u_i, alpha_i_first_order); + // alpha_i calculation. + double alpha_i_first_order[4]; + find_alpha_i_first_order(u_i_min_first_order, u_i_max_first_order, u_c, u_i, alpha_i_first_order); - // measure. - for(unsigned int i = 0; i < 4; i++) - { - if(1.0 > alpha_i_first_order[i]) - { - // check for sanity. - if(std::abs(u_c[i]) > 1E-12) - discontinuous_element_ids.insert(e->id); - } - if(std::abs(u_c[i]) < 1e-3) - continue; - bool bnd = false; - for(unsigned int j = 0; j < 4; j++) - if(e->en[j]->bnd) - bnd = true; - if(bnd) - continue; - double high_limit = -std::numeric_limits::infinity(); - double low_limit = std::numeric_limits::infinity(); - for(unsigned int j = 0; j < 4; j++) - { - if(u_i_max_first_order[i][j] > high_limit) - high_limit = u_i_max_first_order[i][j]; - if(u_i_min_first_order[i][j] < low_limit) - low_limit = u_i_min_first_order[i][j]; - } - if(u_c[i] > high_limit && std::abs(u_c[i] - high_limit) > 1e-3) + // measure. + for(unsigned int i = 0; i < 4; i++) { - high_limit = (u_i_max_first_order[i][0] + u_i_max_first_order[i][1] + u_i_max_first_order[i][2] + u_i_max_first_order[i][3] + u_i_min_first_order[i][0] + u_i_min_first_order[i][1] + u_i_min_first_order[i][2] + u_i_min_first_order[i][3]) / 8.0; - switch(i) + if(1.0 > alpha_i_first_order[i]) { - case 0: - oscillatory_element_idsRho.insert(std::pair(e->id, high_limit)); - break; - case 1: - oscillatory_element_idsRhoVX.insert(std::pair(e->id, high_limit)); - break; - case 2: - oscillatory_element_idsRhoVY.insert(std::pair(e->id, high_limit)); - break; - case 3: - oscillatory_element_idsRhoE.insert(std::pair(e->id, high_limit)); - break; + // check for sanity. + if(std::abs(u_c[i]) > 1E-12) + discontinuous_element_ids.insert(e->id); } - } - if(u_c[i] < low_limit && std::abs(u_c[i] - low_limit) > 1e-3) - { - low_limit = (u_i_max_first_order[i][0] + u_i_max_first_order[i][1] + u_i_max_first_order[i][2] + u_i_max_first_order[i][3] + u_i_min_first_order[i][0] + u_i_min_first_order[i][1] + u_i_min_first_order[i][2] + u_i_min_first_order[i][3]) / 8.0; - switch(i) + if(std::abs(u_c[i]) < 1e-3) + continue; + bool bnd = false; + for(unsigned int j = 0; j < 4; j++) + if(e->en[j]->bnd) + bnd = true; + if(bnd) + continue; + double high_limit = -std::numeric_limits::infinity(); + double low_limit = std::numeric_limits::infinity(); + for(unsigned int j = 0; j < 4; j++) + { + if(u_i_max_first_order[i][j] > high_limit) + high_limit = u_i_max_first_order[i][j]; + if(u_i_min_first_order[i][j] < low_limit) + low_limit = u_i_min_first_order[i][j]; + } + if(u_c[i] > high_limit && std::abs(u_c[i] - high_limit) > 1e-3) + { + high_limit = (u_i_max_first_order[i][0] + u_i_max_first_order[i][1] + u_i_max_first_order[i][2] + u_i_max_first_order[i][3] + u_i_min_first_order[i][0] + u_i_min_first_order[i][1] + u_i_min_first_order[i][2] + u_i_min_first_order[i][3]) / 8.0; + switch(i) + { + case 0: + oscillatory_element_idsRho.insert(std::pair(e->id, high_limit)); + break; + case 1: + oscillatory_element_idsRhoVX.insert(std::pair(e->id, high_limit)); + break; + case 2: + oscillatory_element_idsRhoVY.insert(std::pair(e->id, high_limit)); + break; + case 3: + oscillatory_element_idsRhoE.insert(std::pair(e->id, high_limit)); + break; + } + } + if(u_c[i] < low_limit && std::abs(u_c[i] - low_limit) > 1e-3) { - case 0: - oscillatory_element_idsRho.insert(std::pair(e->id, low_limit)); - break; - case 1: - oscillatory_element_idsRhoVX.insert(std::pair(e->id, low_limit)); - break; - case 2: - oscillatory_element_idsRhoVY.insert(std::pair(e->id, low_limit)); - break; - case 3: - oscillatory_element_idsRhoE.insert(std::pair(e->id, low_limit)); - break; + low_limit = (u_i_max_first_order[i][0] + u_i_max_first_order[i][1] + u_i_max_first_order[i][2] + u_i_max_first_order[i][3] + u_i_min_first_order[i][0] + u_i_min_first_order[i][1] + u_i_min_first_order[i][2] + u_i_min_first_order[i][3]) / 8.0; + switch(i) + { + case 0: + oscillatory_element_idsRho.insert(std::pair(e->id, low_limit)); + break; + case 1: + oscillatory_element_idsRhoVX.insert(std::pair(e->id, low_limit)); + break; + case 2: + oscillatory_element_idsRhoVY.insert(std::pair(e->id, low_limit)); + break; + case 3: + oscillatory_element_idsRhoE.insert(std::pair(e->id, low_limit)); + break; + } } } - } } return discontinuous_element_ids; @@ -650,7 +639,7 @@ std::set& KuzminDiscontinuityDetector::get_second_order_discontinuous_eleme // Vertex values. double u_d_i[4][4][2]; find_vertex_derivatives(e, u_d_i); - + // Boundaries for alpha_i calculation. double u_d_i_min_second_order[4][4][2]; double u_d_i_max_second_order[4][4][2]; @@ -662,20 +651,20 @@ std::set& KuzminDiscontinuityDetector::get_second_order_discontinuous_eleme u_d_i_max_second_order[i][j][k] = -std::numeric_limits::infinity(); } - find_u_i_min_max_second_order(e, u_d_i_min_second_order, u_d_i_max_second_order); + find_u_i_min_max_second_order(e, u_d_i_min_second_order, u_d_i_max_second_order); - // alpha_i calculation. - double alpha_i_second_order[4]; - find_alpha_i_second_order(u_d_i_min_second_order, u_d_i_max_second_order, values, values, u_d_i, alpha_i_second_order); + // alpha_i calculation. + double alpha_i_second_order[4]; + find_alpha_i_second_order(u_d_i_min_second_order, u_d_i_max_second_order, values, values, u_d_i, alpha_i_second_order); - // measure. - for(unsigned int i = 0; i < 4; i++) - if(1.0 > alpha_i_second_order[i]) - { - // check for sanity. - if(std::abs(values[i][0][1]) > 1E-12 || std::abs(values[i][0][2]) > 1E-12) - second_order_discontinuous_element_ids.insert(e->id); - } + // measure. + for(unsigned int i = 0; i < 4; i++) + if(1.0 > alpha_i_second_order[i]) + { + // check for sanity. + if(std::abs(values[i][0][1]) > 1E-12 || std::abs(values[i][0][2]) > 1E-12) + second_order_discontinuous_element_ids.insert(e->id); + } } return second_order_discontinuous_element_ids; @@ -707,13 +696,13 @@ void KuzminDiscontinuityDetector::find_second_centroid_derivatives(Hermes::Herme double c_ref_x, c_ref_y; if(e->get_nvert() == 3) { - c_x = (0.33333333333333333) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); - c_y = (0.33333333333333333) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); + c_x = (0.33333333333333333) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); + c_y = (0.33333333333333333) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); } else { - c_x = (0.25) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); - c_y = (0.25) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); + c_x = (0.25) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); + c_y = (0.25) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); } for(unsigned int i = 0; i < this->solutions.size(); i++) @@ -774,7 +763,7 @@ void KuzminDiscontinuityDetector::find_u_i_min_max_first_order(Hermes::Hermes2D: solutions[0]->get_refmap()->untransform(en, x_center, y_center, x_center_ref, y_center_ref); find_centroid_values(en, u_c, x_center_ref, y_center_ref); - + for(unsigned int min_i = 0; min_i < 4; min_i++) if(u_i_min[min_i][j] > u_c[min_i]) u_i_min[min_i][j] = u_c[min_i]; @@ -850,19 +839,19 @@ void KuzminDiscontinuityDetector::find_alpha_i_first_order(double u_i_min[4][4], } } } - + void KuzminDiscontinuityDetector::find_alpha_i_first_order_real(Hermes::Hermes2D::Element* e, double u_i[4][4], double u_c[4], double u_dx_c[4], double u_dy_c[4], double alpha_i_real[4]) { double c_x, c_y; if(e->get_nvert() == 3) { - c_x = (1/3) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); - c_y = (1/3) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); + c_x = (1/3) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); + c_y = (1/3) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); } else { - c_x = (1/4) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); - c_y = (1/4) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); + c_x = (1/4) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); + c_y = (1/4) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); } alpha_i_real[0] = alpha_i_real[1] = alpha_i_real[2] = alpha_i_real[3] = -std::numeric_limits::infinity(); @@ -914,7 +903,7 @@ void KuzminDiscontinuityDetector::find_u_i_min_max_second_order(Hermes::Hermes2D solutions[0]->get_refmap()->untransform(en, x_center, y_center, x_center_ref, y_center_ref); find_centroid_derivatives(en, u_dx_c, u_dy_c, x_center_ref, y_center_ref); - + for(unsigned int min_i = 0; min_i < 4; min_i++) { if(u_d_i_min[min_i][(j + 1) % e->get_nvert()][0] > u_dx_c[min_i]) @@ -1012,19 +1001,19 @@ void KuzminDiscontinuityDetector::find_alpha_i_second_order(double u_d_i_min[4][ } } } - + void KuzminDiscontinuityDetector::find_alpha_i_second_order_real(Hermes::Hermes2D::Element* e, double u_i[4][4][2], double u_dx_c[4], double u_dy_c[4], double u_dxx_c[4], double u_dxy_c[4], double u_dyy_c[4], double alpha_i_real[4]) { double c_x, c_y; if(e->get_nvert() == 3) { - c_x = (1/3) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); - c_y = (1/3) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); + c_x = (1/3) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x); + c_y = (1/3) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y); } else { - c_x = (1/4) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); - c_y = (1/4) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); + c_x = (1/4) * (e->vn[0]->x + e->vn[1]->x + e->vn[2]->x + e->vn[3]->x); + c_y = (1/4) * (e->vn[0]->y + e->vn[1]->y + e->vn[2]->y + e->vn[3]->y); } alpha_i_real[0] = alpha_i_real[1] = alpha_i_real[2] = alpha_i_real[3] = -std::numeric_limits::infinity(); @@ -1049,12 +1038,12 @@ FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, double* solution_vector Solution::vector_to_solutions(solution_vector, spaces, limited_solutions); switch(type) { - case Krivodonova: - this->detector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); - break; - case Kuzmin: - this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); - break; + case Krivodonova: + this->detector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); + break; + case Kuzmin: + this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); + break; } }; @@ -1071,12 +1060,12 @@ FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, Hermes::vectordetector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); - break; - case Kuzmin: - this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); - break; + case Krivodonova: + this->detector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); + break; + case Kuzmin: + this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); + break; } }; @@ -1100,7 +1089,7 @@ int FluxLimiter::limit_according_to_detector(Hermes::vector *> coa std::set > oscillatory_element_idsRhoVX = this->detector->get_oscillatory_element_idsRhoVX(); std::set > oscillatory_element_idsRhoVY = this->detector->get_oscillatory_element_idsRhoVY(); std::set > oscillatory_element_idsRhoE = this->detector->get_oscillatory_element_idsRhoE(); - + // First adjust the solution_vector. int running_dofs = 0; for(unsigned int space_i = 0; space_i < spaces.size(); space_i++) @@ -1112,7 +1101,7 @@ int FluxLimiter::limit_according_to_detector(Hermes::vector *> coa spaces[space_i]->get_element_assembly_list(spaces[space_i]->get_mesh()->get_element(*it), &al); for(unsigned int shape_i = 0; shape_i < al.get_cnt(); shape_i++) if(H2D_GET_H_ORDER(spaces[space_i]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 0 || H2D_GET_V_ORDER(spaces[space_i]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 0) - solution_vector[running_dofs + al.get_dof()[shape_i]] = 0.0; + solution_vector[running_dofs + al.get_dof()[shape_i]] = 0.0; } if(this->limitOscillations) running_dofs += spaces[space_i]->get_num_dofs(); @@ -1236,52 +1225,52 @@ void FluxLimiter::limit_second_orders_according_to_detector(Hermes::vectorget_num_dofs(); } - // Now adjust the solutions. - Solution::vector_to_solutions(solution_vector, spaces, limited_solutions); - if(dynamic_cast(this->detector)) - { - bool Kuzmin_limit_all_orders_independently = dynamic_cast(this->detector)->get_limit_all_orders_independently(); - delete detector; - this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); - } - else - { - delete detector; - this->detector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); - } + // Now adjust the solutions. + Solution::vector_to_solutions(solution_vector, spaces, limited_solutions); + if(dynamic_cast(this->detector)) + { + bool Kuzmin_limit_all_orders_independently = dynamic_cast(this->detector)->get_limit_all_orders_independently(); + delete detector; + this->detector = new KuzminDiscontinuityDetector(spaces, limited_solutions, Kuzmin_limit_all_orders_independently); + } + else + { + delete detector; + this->detector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); + } - if(coarse_spaces_to_limit != Hermes::vector*>()) { - // Now set the element order to zero. - Element* e; - - for_all_elements(e, spaces[0]->get_mesh()) - e->visited = false; - - for(std::set::iterator it = discontinuous_elements.begin(); it != discontinuous_elements.end(); it++) { - AsmList al; - spaces[0]->get_element_assembly_list(spaces[0]->get_mesh()->get_element(*it), &al); - for(unsigned int shape_i = 0; shape_i < al.get_cnt(); shape_i++) { - if(H2D_GET_H_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 1 || H2D_GET_V_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 1) { - int h_order_to_set = std::min(1, H2D_GET_H_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode()))); - int v_order_to_set = std::min(1, H2D_GET_V_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode()))); - spaces[0]->get_mesh()->get_element(*it)->visited = true; - bool all_sons_visited = true; - for(unsigned int son_i = 0; son_i < 4; son_i++) - if(!spaces[0]->get_mesh()->get_element(*it)->parent->sons[son_i]->visited) - { - all_sons_visited = false; - break; - } - if(all_sons_visited) - for(unsigned int space_i = 0; space_i < spaces.size(); space_i++) - coarse_spaces_to_limit[space_i]->set_element_order_internal(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, H2D_MAKE_QUAD_ORDER(h_order_to_set, v_order_to_set)); - } + if(coarse_spaces_to_limit != Hermes::vector*>()) { + // Now set the element order to zero. + Element* e; + + for_all_elements(e, spaces[0]->get_mesh()) + e->visited = false; + + for(std::set::iterator it = discontinuous_elements.begin(); it != discontinuous_elements.end(); it++) { + AsmList al; + spaces[0]->get_element_assembly_list(spaces[0]->get_mesh()->get_element(*it), &al); + for(unsigned int shape_i = 0; shape_i < al.get_cnt(); shape_i++) { + if(H2D_GET_H_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 1 || H2D_GET_V_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode())) > 1) { + int h_order_to_set = std::min(1, H2D_GET_H_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode()))); + int v_order_to_set = std::min(1, H2D_GET_V_ORDER(spaces[0]->get_shapeset()->get_order(al.get_idx()[shape_i], e->get_mode()))); + spaces[0]->get_mesh()->get_element(*it)->visited = true; + bool all_sons_visited = true; + for(unsigned int son_i = 0; son_i < 4; son_i++) + if(!spaces[0]->get_mesh()->get_element(*it)->parent->sons[son_i]->visited) + { + all_sons_visited = false; + break; + } + if(all_sons_visited) + for(unsigned int space_i = 0; space_i < spaces.size(); space_i++) + coarse_spaces_to_limit[space_i]->set_element_order_internal(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, H2D_MAKE_QUAD_ORDER(h_order_to_set, v_order_to_set)); } } - - for(int i = 0; i < coarse_spaces_to_limit.size(); i++) - coarse_spaces_to_limit.at(i)->assign_dofs(); } + + for(int i = 0; i < coarse_spaces_to_limit.size(); i++) + coarse_spaces_to_limit.at(i)->assign_dofs(); + } }; void MachNumberFilter::filter_fn(int n, Hermes::vector values, double* result) diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index 4a1048c..106b28a 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -41,9 +41,6 @@ class ADEStabilityCalculation public: ADEStabilityCalculation(double AdvectionRelativeConstant, double DiffusionRelativeConstant, double epsilon); - // The method in fact returns half teh length of the shortest edge. - double approximate_inscribed_circle_radius(Element * e); - // If the time step is necessary to decrease / possible to increase, the value time_step will be rewritten. void calculate(Hermes::vector*> solutions, Mesh* mesh, double & time_step); diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index 78da4e5..edac085 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -45,2460 +45,530 @@ class EulerEquationsWeakFormStabilization : public WeakForm }; }; -/* -class EulerEquationsWeakFormExplicit : public WeakForm +class EulerEquationsWeakFormSemiImplicit : public WeakForm { public: - // Constructor. - EulerEquationsWeakFormExplicit(double kappa, double rho_ext, double v1_ext, double v2_ext, double pressure_ext, - std::string solid_wall_bottom_marker, std::string solid_wall_top_marker, std::string inlet_marker, std::string outlet_marker, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, bool fvm_only = false, int num_of_equations = 4) : - WeakForm(num_of_equations), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), pressure_ext(pressure_ext), - energy_ext(QuantityCalculator::calc_energy(rho_ext, rho_ext * v1_ext, rho_ext * v2_ext, pressure_ext, kappa)), euler_fluxes(new EulerFluxes(kappa)) - { - add_matrix_form(new EulerEquationsBilinearFormTime(0)); - add_matrix_form(new EulerEquationsBilinearFormTime(1)); - add_matrix_form(new EulerEquationsBilinearFormTime(2)); - add_matrix_form(new EulerEquationsBilinearFormTime(3)); - add_vector_form(new EulerEquationsLinearFormTime(0)); - add_vector_form(new EulerEquationsLinearFormTime(1)); - add_vector_form(new EulerEquationsLinearFormTime(2)); - add_vector_form(new EulerEquationsLinearFormTime(3)); - - if(!fvm_only) - { - add_vector_form(new EulerEquationsLinearFormDensity()); - add_vector_form(new EulerEquationsLinearFormDensityVelX(kappa)); - add_vector_form(new EulerEquationsLinearFormDensityVelY(kappa)); - add_vector_form(new EulerEquationsLinearFormEnergy(kappa)); - } - - add_vector_form_DG(new EulerEquationsLinearFormInterface(0, kappa)); - add_vector_form_DG(new EulerEquationsLinearFormInterface(1, kappa)); - add_vector_form_DG(new EulerEquationsLinearFormInterface(2, kappa)); - add_vector_form_DG(new EulerEquationsLinearFormInterface(3, kappa)); + double kappa; + bool fvm_only; + Hermes::vector solid_wall_markers; + Hermes::vector inlet_markers; + Hermes::vector outlet_markers; - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(0, solid_wall_bottom_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(1, solid_wall_bottom_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(2, solid_wall_bottom_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(3, solid_wall_bottom_marker, kappa)); + Solution* prev_density; + Solution* prev_density_vel_x; + Solution* prev_density_vel_y; + Solution* prev_energy; - if(solid_wall_bottom_marker != solid_wall_top_marker) - { - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(0, solid_wall_top_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(1, solid_wall_top_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(2, solid_wall_top_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormSolidWall(3, solid_wall_top_marker, kappa)); - } - else - Hermes::Mixins::Loggable::Static::warn("Are you sure that solid wall top and bottom markers should coincide?"); + // External state. + Hermes::vector rho_ext; + Hermes::vector v1_ext; + Hermes::vector v2_ext; + Hermes::vector pressure_ext; + Hermes::vector energy_ext; - add_vector_form_surf(new EulerEquationsLinearFormInlet(0, inlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormInlet(1, inlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormInlet(2, inlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormInlet(3, inlet_marker, kappa)); + // Fluxes for calculation. + EulerFluxes* euler_fluxes; - add_vector_form_surf(new EulerEquationsLinearFormOutlet(0, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormOutlet(1, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormOutlet(2, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsLinearFormOutlet(3, outlet_marker, kappa)); + // Discrete indicator in the case of Feistauer limiting. + bool* discreteIndicator; + int discreteIndicatorSize; - for(unsigned int vector_form_i = 0;vector_form_i < this->vfvol.size();vector_form_i++) - vfvol.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + // For cache handling. + class EulerEquationsMatrixFormSurfSemiImplicit; + class EulerEquationsMatrixFormSemiImplicitInletOutlet; + bool cacheReadyDG; + bool cacheReadySurf; + double** P_plus_cache_DG; + double** P_minus_cache_DG; + double** P_plus_cache_surf; + double** P_minus_cache_surf; - for(unsigned int vector_form_i = 0;vector_form_i < this->vfsurf.size();vector_form_i++) - vfsurf.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + // Utility. + bool oneInflow; - for(unsigned int vector_form_i = 0;vector_form_i < this->vfDG.size();vector_form_i++) - vfDG.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - }; + // Constructor for one inflow. + EulerEquationsWeakFormSemiImplicit(double kappa, + double rho_ext, double v1_ext, double v2_ext, double pressure_ext, + Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, + Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, + bool fvm_only = false, int num_of_equations = 4) : - void set_time_step(double tau) + WeakForm(num_of_equations), + kappa(kappa), + solid_wall_markers(solid_wall_markers), inlet_markers(inlet_markers), outlet_markers(outlet_markers), + prev_density(prev_density), prev_density_vel_x(prev_density_vel_x), prev_density_vel_y(prev_density_vel_y), prev_energy(prev_energy), + fvm_only(fvm_only), + euler_fluxes(new EulerFluxes(kappa)), discreteIndicator(NULL) { - this->tau = tau; - } + oneInflow = true; - double get_tau() const - { - return tau; - } + this->rho_ext.push_back(rho_ext); + this->v1_ext.push_back(v1_ext); + this->v2_ext.push_back(v2_ext); + this->pressure_ext.push_back(pressure_ext); + energy_ext.push_back(QuantityCalculator::calc_energy(rho_ext, rho_ext * v1_ext, rho_ext * v2_ext, pressure_ext, kappa)); - // Destructor. - ~EulerEquationsWeakFormExplicit() {}; -protected: - class EulerEquationsBilinearFormTime : public MatrixFormVol - { - public: - EulerEquationsBilinearFormTime(int i) : MatrixFormVol(i, i) {} + P_plus_cache_DG = new double*[13]; + P_minus_cache_DG = new double*[13]; + P_plus_cache_surf = new double*[13]; + P_minus_cache_surf = new double*[13]; - template - Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const + for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) { - return int_u_v(n, wt, u, v); + P_plus_cache_DG[coordinate_i] = new double[16]; + P_minus_cache_DG[coordinate_i] = new double[16]; + P_plus_cache_surf[coordinate_i] = new double[16]; + P_minus_cache_surf[coordinate_i] = new double[16]; } - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const + for(int form_i = 0; form_i < 4; form_i++) { - return matrix_form(n, wt, u_ext, u, v, e, ext); - } + add_matrix_form(new EulerEquationsBilinearFormTime(form_i)); - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - return matrix_form(n, wt, u_ext, u, v, e, ext); - } + add_vector_form(new EulerEquationsLinearFormTime(form_i)); - MatrixFormVol* clone() const { return new EulerEquationsBilinearFormTime(this->i); } - }; + add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa)); - class EulerEquationsLinearFormDensity : public VectorFormVol - { - public: - EulerEquationsLinearFormDensity() : VectorFormVol(0) {} + if(outlet_markers.size() > 0) + add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, 0, 0, 0, 0, outlet_markers, kappa)); - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - double result = double(0); - for (int i = 0;i < n;i++) + for(int form_j = 0; form_j < 4; form_j++) { - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_0_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_0_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_0_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_0_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_0_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_0_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_0_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_0_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - } - return result * static_cast(wf)->get_tau(); - } + if(!fvm_only) + add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return Ord(20); - } - VectorFormVol* clone() const - { - EulerEquationsLinearFormDensity* form = new EulerEquationsLinearFormDensity(*this); - form->wf = this->wf; - return form; - } - }; + EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); + add_matrix_form_DG(formDG); - class EulerEquationsLinearFormDensityVelX : public VectorFormVol - { - public: - EulerEquationsLinearFormDensityVelX(double kappa) - : VectorFormVol(1), kappa(kappa) {} + EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); + add_matrix_form_surf(formSurf); - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - double result = double(0); - for (int i = 0;i < n;i++) - { - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_1_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_1_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_1_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_1_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_1_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_1_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_1_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_1_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - } - return result * static_cast(wf)->get_tau(); - } + if(outlet_markers.size() > 0) + { + formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); + add_matrix_form_surf(formSurf); + } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return Ord(20); + add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(form_i, form_j, solid_wall_markers, kappa)); + } } - double kappa; - VectorFormVol* clone() const { return new EulerEquationsLinearFormDensityVelX(*this); } + this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); }; - class EulerEquationsLinearFormDensityVelY : public VectorFormVol + // Constructor for more inflows. + EulerEquationsWeakFormSemiImplicit(double kappa, + Hermes::vector rho_ext, Hermes::vector v1_ext, Hermes::vector v2_ext, Hermes::vector pressure_ext, + Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, + Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, + bool fvm_only = false, int num_of_equations = 4) : + + WeakForm(num_of_equations), + kappa(kappa), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), pressure_ext(pressure_ext), + solid_wall_markers(solid_wall_markers), inlet_markers(inlet_markers), outlet_markers(outlet_markers), + prev_density(prev_density), prev_density_vel_x(prev_density_vel_x), prev_density_vel_y(prev_density_vel_y), prev_energy(prev_energy), + fvm_only(fvm_only), + euler_fluxes(new EulerFluxes(kappa)), discreteIndicator(NULL) { - public: - EulerEquationsLinearFormDensityVelY(double kappa) - : VectorFormVol(2), kappa(kappa) {} + oneInflow = false; - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) + energy_ext.push_back(QuantityCalculator::calc_energy(rho_ext[inlet_i], rho_ext[inlet_i] * v1_ext[inlet_i], rho_ext[inlet_i] * v2_ext[inlet_i], pressure_ext[inlet_i], kappa)); + + P_plus_cache_DG = new double*[13]; + P_minus_cache_DG = new double*[13]; + P_plus_cache_surf = new double*[13]; + P_minus_cache_surf = new double*[13]; + + for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) { - double result = double(0); - for (int i = 0;i < n;i++) - { - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_2_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_2_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_2_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_2_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_2_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_2_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_2_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_2_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - } - return result * static_cast(wf)->get_tau(); + P_plus_cache_DG[coordinate_i] = new double[16]; + P_minus_cache_DG[coordinate_i] = new double[16]; + P_plus_cache_surf[coordinate_i] = new double[16]; + P_minus_cache_surf[coordinate_i] = new double[16]; } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const + for(int form_i = 0; form_i < 4; form_i++) { - return Ord(20); - } + add_matrix_form(new EulerEquationsBilinearFormTime(form_i)); - VectorFormVol* clone() const { return new EulerEquationsLinearFormDensityVelY(*this); } + add_vector_form(new EulerEquationsLinearFormTime(form_i)); - double kappa; - }; + for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) + add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext[inlet_i], v1_ext[inlet_i], v2_ext[inlet_i], energy_ext[inlet_i], inlet_markers[inlet_i], kappa)); - class EulerEquationsLinearFormEnergy : public VectorFormVol - { - public: - EulerEquationsLinearFormEnergy(double kappa) - : VectorFormVol(3), kappa(kappa) {} + add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, 0, 0, 0, 0, outlet_markers, kappa)); - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - double result = double(0); - for (int i = 0;i < n;i++) + for(int form_j = 0; form_j < 4; form_j++) { - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_3_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], ext[3]->val[i]) - * v->dx[i]; - result += wt[i] * ext[0]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_3_0(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], ext[3]->val[i]) - * v->dy[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_3_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], ext[3]->val[i]) - * v->dx[i]; - result += wt[i] * ext[1]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_3_1(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_3_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[2]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_3_2(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], ext[3]->val[i]) - * v->dy[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_1_3_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dx[i]; - result += wt[i] * ext[3]->val[i] - * (static_cast(wf))->euler_fluxes->A_2_3_3(ext[0]->val[i], ext[1]->val[i], ext[2]->val[i], double(0)) - * v->dy[i]; - } - return result * static_cast(wf)->get_tau(); - } + if(!fvm_only) + add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return Ord(20); + EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); + add_matrix_form_DG(formDG); + + for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) + { + EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext[inlet_i], v1_ext[inlet_i], v2_ext[inlet_i], energy_ext[inlet_i], inlet_markers[inlet_i], kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); + add_matrix_form_surf(formSurf); + } + + EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); + add_matrix_form_surf(formSurf); + + add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(form_i, form_j, solid_wall_markers, kappa)); + } } - VectorFormVol* clone() const { return new EulerEquationsLinearFormEnergy(*this); } - double kappa; + this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); }; - class EulerEquationsLinearFormTime : public VectorFormVol + virtual ~EulerEquationsWeakFormSemiImplicit() { - public: - EulerEquationsLinearFormTime(int i) - : VectorFormVol(i), component_i(i) {} + delete this->euler_fluxes; - template - Scalar vector_form(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) { - return int_u_v(n, wt, ext[component_i], v); + delete [] P_plus_cache_DG[coordinate_i]; + delete [] P_minus_cache_DG[coordinate_i]; + delete [] P_plus_cache_surf[coordinate_i]; + delete [] P_minus_cache_surf[coordinate_i]; } - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - return vector_form(n, wt, u_ext, v, e, ext); - } + delete [] P_plus_cache_DG; + delete [] P_minus_cache_DG; + delete [] P_plus_cache_surf; + delete [] P_minus_cache_surf; + } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - return vector_form(n, wt, u_ext, v, e, ext); - } + void set_active_edge_state(Element** e, int isurf) + { + this->cacheReadySurf = false; + } - VectorFormVol* clone() const { return new EulerEquationsLinearFormTime(*this); } - // Member. - int component_i; - }; + void set_active_DG_state(Element** e, int isurf) + { + this->cacheReadyDG = false; + } - class EulerEquationsLinearFormInterface : public VectorFormDG + WeakForm* clone() const { - public: - EulerEquationsLinearFormInterface(int i, double kappa) - : VectorFormDG(i), element(i), num_flux(new StegerWarmingNumericalFlux(kappa)) {} + EulerEquationsWeakFormSemiImplicit* wf; + if(this->oneInflow) + wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); + else + wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext, this->v1_ext, this->v2_ext, this->pressure_ext, + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); + + wf->ext.clear(); - ~EulerEquationsLinearFormInterface() + for(unsigned int i = 0; i < this->ext.size(); i++) { - delete num_flux; + Solution* ext = static_cast*>(this->ext[i]->clone()); + if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + ext->set_type(HERMES_SLN); + wf->ext.push_back(ext); } - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - double result = 0; - double w_L[4], w_R[4]; - for (int point_i = 0; point_i < n;point_i++) - { - w_L[0] = ext[0]->get_val_central(point_i); - w_R[0] = ext[0]->get_val_neighbor(point_i); - - w_L[1] = ext[1]->get_val_central(point_i); - w_R[1] = ext[1]->get_val_neighbor(point_i); + wf->set_current_time_step(this->get_current_time_step()); - w_L[2] = ext[2]->get_val_central(point_i); - w_R[2] = ext[2]->get_val_neighbor(point_i); + /* + EulerEquationsWeakFormSemiImplicit* wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext, this->v1_ext, this->v2_ext, this->pressure_ext, + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); - w_L[3] = ext[3]->get_val_central(point_i); - w_R[3] = ext[3]->get_val_neighbor(point_i); - result -= wt[point_i] * v->val[point_i] - * num_flux->numerical_flux_i(element, w_L, w_R, e->nx[point_i], e->ny[point_i]); - } - return result * static_cast(wf)->get_tau(); + if(this->discreteIndicator != NULL) + { + bool* discreteIndicatorLocal = new bool[this->discreteIndicatorSize]; + memcpy(discreteIndicatorLocal, this->discreteIndicator, this->discreteIndicatorSize * sizeof(bool)); + wf->set_discreteIndicator(discreteIndicatorLocal, this->discreteIndicatorSize); } + */ - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const + return wf; + } + + void cloneMembers(const WeakForm* otherWf) + { + } + + void set_stabilization(Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, double nu_1, double nu_2) + { + int mfvol_size = this->mfvol.size(); + int mfsurf_size = this->mfsurf.size(); + + add_matrix_form(new EulerEquationsFormStabilizationVol(0, nu_1)); + add_matrix_form(new EulerEquationsFormStabilizationVol(1, nu_1)); + add_matrix_form(new EulerEquationsFormStabilizationVol(2, nu_1)); + add_matrix_form(new EulerEquationsFormStabilizationVol(3, nu_1)); + + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 0, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 1, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 2, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 3, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 0, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 1, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 2, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 3, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 0, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 1, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 2, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 3, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 0, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 1, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 2, nu_2)); + add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 3, nu_2)); + + for(unsigned int matrix_form_i = mfvol_size;matrix_form_i < this->mfvol.size();matrix_form_i++) { - return Ord(20); + mfvol.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); } - VectorFormDG* clone() + for(unsigned int matrix_form_i = mfsurf_size;matrix_form_i < this->mfsurf.size();matrix_form_i++) { - EulerEquationsLinearFormInterface* form = new EulerEquationsLinearFormInterface(this->i, this->num_flux->kappa); - form->wf = this->wf; - return form; + mfsurf.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); } + } - // Members. - int element; - NumericalFlux* num_flux; - }; + void set_discreteIndicator(bool* discreteIndicator, int size) + { + this->discreteIndicator = discreteIndicator; + this->discreteIndicatorSize = size; + } - class EulerEquationsLinearFormSolidWall : public VectorFormSurf + class EulerEquationsBilinearFormTime : public MatrixFormVol { public: - EulerEquationsLinearFormSolidWall(int i, std::string marker, double kappa) - : VectorFormSurf(i), element(i), num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker); } - - ~EulerEquationsLinearFormSolidWall() - { - delete num_flux; - } + EulerEquationsBilinearFormTime(int i) : MatrixFormVol(i, i) {} - double value(int n, double *wt, Func *u_ext[], Func *v, + double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - double result = 0; - for (int i = 0;i < n;i++) - { - double w_L[4]; - w_L[0] = ext[0]->val[i]; - w_L[1] = ext[1]->val[i]; - w_L[2] = ext[2]->val[i]; - w_L[3] = ext[3]->val[i]; - - result -= wt[i] * v->val[i] * num_flux->numerical_flux_solid_wall_i(element, - w_L, e->nx[i], e->ny[i]); - } - return result * static_cast(wf)->get_tau(); + return int_u_v(n, wt, u, v); } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(20); - } - - VectorFormSurf* clone() - { - EulerEquationsLinearFormSolidWall* form = new EulerEquationsLinearFormSolidWall(i, areas[0], num_flux->kappa); - form->wf = this->wf; - return form; + return int_u_v(n, wt, u, v); } - // Members. - int element; - NumericalFlux* num_flux; + MatrixFormVol* clone() const { return new EulerEquationsBilinearFormTime(this->i); } }; - class EulerEquationsLinearFormInlet : public VectorFormSurf + class EulerEquationsBilinearForm : public MatrixFormVol { public: - EulerEquationsLinearFormInlet(int i, std::string marker, double kappa) - : VectorFormSurf(i), element(i), num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker); } + EulerEquationsBilinearForm(int i, int j, EulerFluxes* fluxes) + : MatrixFormVol(i, j), fluxes(fluxes) {} - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const + double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, + Func* *ext) const { - double result = 0; - double w_L[4], w_B[4]; - - for (int i = 0;i < n;i++) + double result = 0.; + for (int point_i = 0; point_i < n;point_i++) { - // Left (inner) state from the previous time level solution. - w_L[0] = ext[0]->val[i]; - w_L[1] = ext[1]->val[i]; - w_L[2] = ext[2]->val[i]; - w_L[3] = ext[3]->val[i]; - - w_B[0] = static_cast(wf)->rho_ext; - w_B[1] = static_cast(wf)->rho_ext - * static_cast(wf)->v1_ext; - w_B[2] = static_cast(wf)->rho_ext - * static_cast(wf)->v2_ext; - w_B[3] = static_cast(wf)->energy_ext; - - result -= wt[i] * v->val[i] * num_flux->numerical_flux_inlet_i(element, - w_L, w_B, e->nx[i], e->ny[i]); + double rho = ext[0]->val[point_i]; + double rho_v_x = ext[1]->val[point_i]; + double rho_v_y = ext[2]->val[point_i]; + double rho_e = ext[3]->val[point_i]; + + switch(i) + { + case 0: + switch(j) + { + case 0: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 1: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 2: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 3: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + } + break; + case 1: + switch(j) + { + case 0: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 1: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 2: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 3: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + } + break; + case 2: + switch(j) + { + case 0: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 1: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 2: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + case 3: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); + break; + } + break; + case 3: + switch(j) + { + case 0: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_0(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_0(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); + break; + case 1: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_1(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_1(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); + break; + case 2: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_2(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_2(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); + break; + case 3: + result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_3(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_3(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); + break; + } + } } - return result * static_cast(wf)->get_tau(); + + return - result * wf->get_current_time_step(); } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const + Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(20); + return Ord(10); } - VectorFormSurf* clone() + MatrixFormVol* clone() const { - EulerEquationsLinearFormInlet* form = new EulerEquationsLinearFormInlet(i, areas[0], num_flux->kappa); - form->wf = this->wf; - return form; + return new EulerEquationsBilinearForm(this->i, this->j, this->fluxes); } - // Members. - int element; - NumericalFlux* num_flux; + EulerFluxes* fluxes; }; - class EulerEquationsLinearFormOutlet : public VectorFormSurf + class EulerEquationsMatrixFormSurfSemiImplicit : public MatrixFormDG { public: - EulerEquationsLinearFormOutlet(int i, std::string marker, double kappa) : VectorFormSurf(i), element(i), num_flux(new StegerWarmingNumericalFlux(kappa)) - { set_area(marker); } - - ~EulerEquationsLinearFormOutlet() + EulerEquationsMatrixFormSurfSemiImplicit(int i, int j, double kappa, EulerFluxes* fluxes, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) + : MatrixFormDG(i, j), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache), fluxes(fluxes) { - delete num_flux; } - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + ~EulerEquationsMatrixFormSurfSemiImplicit() { - double result = 0; - double w_L[4]; - for (int i = 0;i < n;i++) - { - w_L[0] = ext[0]->val[i]; - w_L[1] = ext[1]->val[i]; - w_L[2] = ext[2]->val[i]; - w_L[3] = ext[3]->val[i]; - result -= wt[i] * v->val[i] - * num_flux->numerical_flux_outlet_i(element, w_L, - static_cast(wf)->pressure_ext, - e->nx[i], e->ny[i]); - } - return result * static_cast(wf)->get_tau(); + delete num_flux; } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const + double value(int n, double *wt, DiscontinuousFunc *u, + DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const { - return Ord(20); - } + double w[4]; + double result = 0.; - VectorFormSurf* clone() - { - EulerEquationsLinearFormOutlet* form = new EulerEquationsLinearFormOutlet(i, areas[0], num_flux->kappa); - form->wf = this->wf; - return form; - } + if(!(*this->cacheReady)) + { + for (int point_i = 0; point_i < n; point_i++) + { + { + w[0] = ext[0]->val[point_i]; + w[1] = ext[1]->val[point_i]; + w[2] = ext[2]->val[point_i]; + w[3] = ext[3]->val[point_i]; - // Members. - int element; - NumericalFlux* num_flux; - }; - // Members. - double rho_ext; - double v1_ext; - double v2_ext; - double pressure_ext; - double energy_ext; - double tau; + double e_1_1[4] = {1, 0, 0, 0}; + double e_2_1[4] = {0, 1, 0, 0}; + double e_3_1[4] = {0, 0, 1, 0}; + double e_4_1[4] = {0, 0, 0, 1}; - EulerFluxes* euler_fluxes; + num_flux->P_plus(this->P_plus_cache[point_i], w, e_1_1, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 4, w, e_2_1, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 8, w, e_3_1, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 12, w, e_4_1, e->nx[point_i], e->ny[point_i]); - friend class EulerEquationsWeakFormExplicitCoupled; - friend class EulerEquationsWeakFormExplicitMultiComponent; - friend class EulerEquationsWeakFormSemiImplicit; - friend class EulerEquationsWeakFormSemiImplicitCoupled; -}; -*/ + w[0] = ext[0]->val_neighbor[point_i]; + w[1] = ext[1]->val_neighbor[point_i]; + w[2] = ext[2]->val_neighbor[point_i]; + w[3] = ext[3]->val_neighbor[point_i]; + double e_1_2[4] = {1, 0, 0, 0}; + double e_2_2[4] = {0, 1, 0, 0}; + double e_3_2[4] = {0, 0, 1, 0}; + double e_4_2[4] = {0, 0, 0, 1}; + num_flux->P_minus(this->P_minus_cache[point_i], w, e_1_2, e->nx[point_i], e->ny[point_i]); + num_flux->P_minus(this->P_minus_cache[point_i] + 4, w, e_2_2, e->nx[point_i], e->ny[point_i]); + num_flux->P_minus(this->P_minus_cache[point_i] + 8, w, e_3_2, e->nx[point_i], e->ny[point_i]); + num_flux->P_minus(this->P_minus_cache[point_i] + 12, w, e_4_2, e->nx[point_i], e->ny[point_i]); + } + } + *(const_cast(this))->cacheReady = true; + } -class EulerEquationsWeakFormSemiImplicit : public WeakForm -{ -public: - double kappa; - bool fvm_only; - Hermes::vector solid_wall_markers; - Hermes::vector inlet_markers; - Hermes::vector outlet_markers; + int index = j * 4 + i; - Solution* prev_density; - Solution* prev_density_vel_x; - Solution* prev_density_vel_y; - Solution* prev_energy; - - // External state. - Hermes::vector rho_ext; - Hermes::vector v1_ext; - Hermes::vector v2_ext; - Hermes::vector pressure_ext; - Hermes::vector energy_ext; - - // Fluxes for calculation. - EulerFluxes* euler_fluxes; - - // Discrete indicator in the case of Feistauer limiting. - bool* discreteIndicator; - int discreteIndicatorSize; - - // For cache handling. - class EulerEquationsMatrixFormSurfSemiImplicit; - class EulerEquationsMatrixFormSemiImplicitInletOutlet; - bool cacheReadyDG; - bool cacheReadySurf; - double** P_plus_cache_DG; - double** P_minus_cache_DG; - double** P_plus_cache_surf; - double** P_minus_cache_surf; - - // Utility. - bool oneInflow; - - // Constructor for one inflow. - EulerEquationsWeakFormSemiImplicit(double kappa, - double rho_ext, double v1_ext, double v2_ext, double pressure_ext, - Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, - bool fvm_only = false, int num_of_equations = 4) : - - WeakForm(num_of_equations), - kappa(kappa), - solid_wall_markers(solid_wall_markers), inlet_markers(inlet_markers), outlet_markers(outlet_markers), - prev_density(prev_density), prev_density_vel_x(prev_density_vel_x), prev_density_vel_y(prev_density_vel_y), prev_energy(prev_energy), - fvm_only(fvm_only), - euler_fluxes(new EulerFluxes(kappa)), discreteIndicator(NULL) - { - oneInflow = true; - - this->rho_ext.push_back(rho_ext); - this->v1_ext.push_back(v1_ext); - this->v2_ext.push_back(v2_ext); - this->pressure_ext.push_back(pressure_ext); - energy_ext.push_back(QuantityCalculator::calc_energy(rho_ext, rho_ext * v1_ext, rho_ext * v2_ext, pressure_ext, kappa)); - - P_plus_cache_DG = new double*[13]; - P_minus_cache_DG = new double*[13]; - P_plus_cache_surf = new double*[13]; - P_minus_cache_surf = new double*[13]; - - for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) - { - P_plus_cache_DG[coordinate_i] = new double[16]; - P_minus_cache_DG[coordinate_i] = new double[16]; - P_plus_cache_surf[coordinate_i] = new double[16]; - P_minus_cache_surf[coordinate_i] = new double[16]; - } - - for(int form_i = 0; form_i < 4; form_i++) - { - add_matrix_form(new EulerEquationsBilinearFormTime(form_i)); - - add_vector_form(new EulerEquationsLinearFormTime(form_i)); - - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa)); - - if(outlet_markers.size() > 0) - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, 0, 0, 0, 0, outlet_markers, kappa)); - - for(int form_j = 0; form_j < 4; form_j++) - { - if(!fvm_only) - add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); - - EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); - add_matrix_form_DG(formDG); - - EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - add_matrix_form_surf(formSurf); - - if(outlet_markers.size() > 0) - { - formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - add_matrix_form_surf(formSurf); - } - - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(form_i, form_j, solid_wall_markers, kappa)); - } - } - - this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - }; - - // Constructor for more inflows. - EulerEquationsWeakFormSemiImplicit(double kappa, - Hermes::vector rho_ext, Hermes::vector v1_ext, Hermes::vector v2_ext, Hermes::vector pressure_ext, - Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, - bool fvm_only = false, int num_of_equations = 4) : - - WeakForm(num_of_equations), - kappa(kappa), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), pressure_ext(pressure_ext), - solid_wall_markers(solid_wall_markers), inlet_markers(inlet_markers), outlet_markers(outlet_markers), - prev_density(prev_density), prev_density_vel_x(prev_density_vel_x), prev_density_vel_y(prev_density_vel_y), prev_energy(prev_energy), - fvm_only(fvm_only), - euler_fluxes(new EulerFluxes(kappa)), discreteIndicator(NULL) - { - oneInflow = false; - - for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) - energy_ext.push_back(QuantityCalculator::calc_energy(rho_ext[inlet_i], rho_ext[inlet_i] * v1_ext[inlet_i], rho_ext[inlet_i] * v2_ext[inlet_i], pressure_ext[inlet_i], kappa)); - - P_plus_cache_DG = new double*[13]; - P_minus_cache_DG = new double*[13]; - P_plus_cache_surf = new double*[13]; - P_minus_cache_surf = new double*[13]; - - for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) - { - P_plus_cache_DG[coordinate_i] = new double[16]; - P_minus_cache_DG[coordinate_i] = new double[16]; - P_plus_cache_surf[coordinate_i] = new double[16]; - P_minus_cache_surf[coordinate_i] = new double[16]; - } - - for(int form_i = 0; form_i < 4; form_i++) - { - add_matrix_form(new EulerEquationsBilinearFormTime(form_i)); - - add_vector_form(new EulerEquationsLinearFormTime(form_i)); - - for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext[inlet_i], v1_ext[inlet_i], v2_ext[inlet_i], energy_ext[inlet_i], inlet_markers[inlet_i], kappa)); - - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, 0, 0, 0, 0, outlet_markers, kappa)); - - for(int form_j = 0; form_j < 4; form_j++) - { - if(!fvm_only) - add_matrix_form(new EulerEquationsBilinearForm(form_i, form_j, euler_fluxes)); - - EulerEquationsMatrixFormSurfSemiImplicit* formDG = new EulerEquationsMatrixFormSurfSemiImplicit(form_i, form_j, kappa, euler_fluxes, &this->cacheReadyDG, this->P_plus_cache_DG, this->P_minus_cache_DG); - add_matrix_form_DG(formDG); - - for(unsigned int inlet_i = 0; inlet_i < inlet_markers.size(); inlet_i++) - { - EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext[inlet_i], v1_ext[inlet_i], v2_ext[inlet_i], energy_ext[inlet_i], inlet_markers[inlet_i], kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - add_matrix_form_surf(formSurf); - } - - EulerEquationsMatrixFormSemiImplicitInletOutlet* formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); - add_matrix_form_surf(formSurf); - - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(form_i, form_j, solid_wall_markers, kappa)); - } - } - - this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - }; - - virtual ~EulerEquationsWeakFormSemiImplicit() - { - delete this->euler_fluxes; - - for(int coordinate_i = 0; coordinate_i < 13; coordinate_i++) - { - delete [] P_plus_cache_DG[coordinate_i]; - delete [] P_minus_cache_DG[coordinate_i]; - delete [] P_plus_cache_surf[coordinate_i]; - delete [] P_minus_cache_surf[coordinate_i]; - } - - delete [] P_plus_cache_DG; - delete [] P_minus_cache_DG; - delete [] P_plus_cache_surf; - delete [] P_minus_cache_surf; - } - - void set_active_edge_state(Element** e, int isurf) - { - this->cacheReadySurf = false; - } - - void set_active_DG_state(Element** e, int isurf) - { - this->cacheReadyDG = false; - } - - WeakForm* clone() const - { - EulerEquationsWeakFormSemiImplicit* wf; - if(this->oneInflow) - wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], - this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); - else - wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext, this->v1_ext, this->v2_ext, this->pressure_ext, - this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); - - wf->ext.clear(); - - for(unsigned int i = 0; i < this->ext.size(); i++) - { - Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) - ext->set_type(HERMES_SLN); - wf->ext.push_back(ext); - } - - wf->set_current_time_step(this->get_current_time_step()); - - /* - EulerEquationsWeakFormSemiImplicit* wf = new EulerEquationsWeakFormSemiImplicit(this->kappa, this->rho_ext, this->v1_ext, this->v2_ext, this->pressure_ext, - this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->fvm_only, this->neq); - - - if(this->discreteIndicator != NULL) - { - bool* discreteIndicatorLocal = new bool[this->discreteIndicatorSize]; - memcpy(discreteIndicatorLocal, this->discreteIndicator, this->discreteIndicatorSize * sizeof(bool)); - wf->set_discreteIndicator(discreteIndicatorLocal, this->discreteIndicatorSize); - } - */ - - return wf; - } - - void cloneMembers(const WeakForm* otherWf) - { - } - - void set_stabilization(Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, double nu_1, double nu_2) - { - int mfvol_size = this->mfvol.size(); - int mfsurf_size = this->mfsurf.size(); - - add_matrix_form(new EulerEquationsFormStabilizationVol(0, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(1, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(2, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(3, nu_1)); - - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 3, nu_2)); - - for(unsigned int matrix_form_i = mfvol_size;matrix_form_i < this->mfvol.size();matrix_form_i++) - { - mfvol.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - } - - for(unsigned int matrix_form_i = mfsurf_size;matrix_form_i < this->mfsurf.size();matrix_form_i++) - { - mfsurf.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - } - } - - void set_discreteIndicator(bool* discreteIndicator, int size) - { - this->discreteIndicator = discreteIndicator; - this->discreteIndicatorSize = size; - } - - class EulerEquationsBilinearFormTime : public MatrixFormVol - { - public: - EulerEquationsBilinearFormTime(int i) : MatrixFormVol(i, i) {} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return int_u_v(n, wt, u, v); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - return int_u_v(n, wt, u, v); - } - - MatrixFormVol* clone() const { return new EulerEquationsBilinearFormTime(this->i); } - }; - - class EulerEquationsBilinearForm : public MatrixFormVol - { - public: - EulerEquationsBilinearForm(int i, int j, EulerFluxes* fluxes) - : MatrixFormVol(i, j), fluxes(fluxes) {} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n;point_i++) - { - double rho = ext[0]->val[point_i]; - double rho_v_x = ext[1]->val[point_i]; - double rho_v_y = ext[2]->val[point_i]; - double rho_e = ext[3]->val[point_i]; - - switch(i) - { - case 0: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 1: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 2: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 3: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_0_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_0_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - } - break; - case 1: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 1: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 2: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 3: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_1_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_1_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - } - break; - case 2: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_0(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_0(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 1: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_1(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_1(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 2: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_2(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_2(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - case 3: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_2_3(rho, rho_v_x, rho_v_y, 0) * v->dx[point_i] + fluxes->A_2_2_3(rho, rho_v_x, rho_v_y, 0) * v->dy[point_i]); - break; - } - break; - case 3: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_0(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_0(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); - break; - case 1: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_1(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_1(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); - break; - case 2: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_2(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_2(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); - break; - case 3: - result += wt[point_i] * u->val[point_i] * (fluxes->A_1_3_3(rho, rho_v_x, rho_v_y, rho_e) * v->dx[point_i] + fluxes->A_2_3_3(rho, rho_v_x, rho_v_y, rho_e) * v->dy[point_i]); - break; - } - } - } - - return - result * wf->get_current_time_step(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const - { - return Ord(10); - } - - MatrixFormVol* clone() const - { - return new EulerEquationsBilinearForm(this->i, this->j, this->fluxes); - } - - EulerFluxes* fluxes; - }; - - class EulerEquationsMatrixFormSurfSemiImplicit : public MatrixFormDG - { - public: - EulerEquationsMatrixFormSurfSemiImplicit(int i, int j, double kappa, EulerFluxes* fluxes, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) - : MatrixFormDG(i, j), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache), fluxes(fluxes) - { - } - - ~EulerEquationsMatrixFormSurfSemiImplicit() - { - delete num_flux; - } - - double value(int n, double *wt, DiscontinuousFunc *u, - DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const - { - double w[4]; - double result = 0.; - - if(!(*this->cacheReady)) - { - for (int point_i = 0; point_i < n; point_i++) - { - { - w[0] = ext[0]->val[point_i]; - w[1] = ext[1]->val[point_i]; - w[2] = ext[2]->val[point_i]; - w[3] = ext[3]->val[point_i]; - - double e_1_1[4] = {1, 0, 0, 0}; - double e_2_1[4] = {0, 1, 0, 0}; - double e_3_1[4] = {0, 0, 1, 0}; - double e_4_1[4] = {0, 0, 0, 1}; - - num_flux->P_plus(this->P_plus_cache[point_i], w, e_1_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 4, w, e_2_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 8, w, e_3_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 12, w, e_4_1, e->nx[point_i], e->ny[point_i]); - - w[0] = ext[0]->val_neighbor[point_i]; - w[1] = ext[1]->val_neighbor[point_i]; - w[2] = ext[2]->val_neighbor[point_i]; - w[3] = ext[3]->val_neighbor[point_i]; - - double e_1_2[4] = {1, 0, 0, 0}; - double e_2_2[4] = {0, 1, 0, 0}; - double e_3_2[4] = {0, 0, 1, 0}; - double e_4_2[4] = {0, 0, 0, 1}; - - num_flux->P_minus(this->P_minus_cache[point_i], w, e_1_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(this->P_minus_cache[point_i] + 4, w, e_2_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(this->P_minus_cache[point_i] + 8, w, e_3_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(this->P_minus_cache[point_i] + 12, w, e_4_2, e->nx[point_i], e->ny[point_i]); - } - } - *(const_cast(this))->cacheReady = true; - } - - int index = j * 4 + i; - - if(u->val == NULL) - if(v->val == NULL) - for (int point_i = 0; point_i < n; point_i++) - result -= wt[point_i] * (this->P_minus_cache[point_i][index] * u->val_neighbor[point_i]) * v->val_neighbor[point_i]; - else - for (int point_i = 0; point_i < n; point_i++) - result += wt[point_i] * (this->P_minus_cache[point_i][index] * u->val_neighbor[point_i]) * v->val[point_i]; - else - if(v->val == NULL) - for (int point_i = 0; point_i < n; point_i++) - result -= wt[point_i] * (this->P_plus_cache[point_i][index] * u->val[point_i]) * v->val_neighbor[point_i]; - else - for (int point_i = 0; point_i < n; point_i++) - result += wt[point_i] * (this->P_plus_cache[point_i][index] * u->val[point_i]) * v->val[point_i]; - - return result * wf->get_current_time_step(); - } - - MatrixFormDG* clone() const - { - EulerEquationsMatrixFormSurfSemiImplicit* form = new EulerEquationsMatrixFormSurfSemiImplicit(this->i, this->j, this->num_flux->kappa, this->fluxes, this->cacheReady, this->P_plus_cache, this->P_minus_cache); - form->wf = this->wf; - return form; - } - - bool* cacheReady; - double** P_plus_cache; - double** P_minus_cache; - StegerWarmingNumericalFlux* num_flux; - EulerFluxes* fluxes; - }; - - class EulerEquationsMatrixFormSemiImplicitInletOutlet : public MatrixFormSurf - { - public: - EulerEquationsMatrixFormSemiImplicitInletOutlet(int i, int j, double rho_ext, double v1_ext, double v2_ext, double energy_ext, std::string marker, double kappa, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) - : MatrixFormSurf(i, j), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache) - { - set_area(marker); - } - EulerEquationsMatrixFormSemiImplicitInletOutlet(int i, int j, double rho_ext, double v1_ext, double v2_ext, double energy_ext, Hermes::vector markers, double kappa, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) - : MatrixFormSurf(i, j), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache) - { - set_areas(markers); - } - - ~EulerEquationsMatrixFormSemiImplicitInletOutlet() - { - delete num_flux; - } - - double value(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const - { - double result = 0.; - - if(!(*this->cacheReady)) - { - for (int point_i = 0; point_i < n; point_i++) - { - double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - - // Inner state. - w_L[0] = ext[0]->val[point_i]; - w_L[1] = ext[1]->val[point_i]; - w_L[2] = ext[2]->val[point_i]; - w_L[3] = ext[3]->val[point_i]; - - // Transformation of the inner state to the local coordinates. - num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); - - // Initialize the matrices. - double T[4][4]; - double T_inv[4][4]; - for(unsigned int ai = 0; ai < 4; ai++) - { - for(unsigned int aj = 0; aj < 4; aj++) - { - T[ai][aj] = 0.0; - T_inv[ai][aj] = 0.0; - } - alpha[ai] = 0; - beta[ai] = 0; - q_ji[ai] = 0; - w_ji[ai] = 0; - eigenvalues[ai] = 0; - } - - // Calculate Lambda^-. - num_flux->Lambda(eigenvalues); - num_flux->T_1(T); - num_flux->T_2(T); - num_flux->T_3(T); - num_flux->T_4(T); - num_flux->T_inv_1(T_inv); - num_flux->T_inv_2(T_inv); - num_flux->T_inv_3(T_inv); - num_flux->T_inv_4(T_inv); - - // "Prescribed" boundary state. - w_B[0] = this->rho_ext; - w_B[1] = this->rho_ext * this->v1_ext; - w_B[2] = this->rho_ext * this->v2_ext; - w_B[3] = this->energy_ext; - - num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); - - for(unsigned int ai = 0; ai < 4; ai++) - for(unsigned int aj = 0; aj < 4; aj++) - alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; - - for(unsigned int bi = 0; bi < 4; bi++) - for(unsigned int bj = 0; bj < 4; bj++) - beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; - - for(unsigned int si = 0; si< 4; si++) - for(unsigned int sj = 0; sj < 4; sj++) - if(eigenvalues[sj] < 0) - q_ji[si] += beta[sj] * T[si][sj]; - else - q_ji[si] += alpha[sj] * T[si][sj]; - - num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); - - double P_minus[4]; - - double w_temp[4]; - w_temp[0] = (w_ji[0] + w_L[0]) / 2; - w_temp[1] = (w_ji[1] + w_L[1]) / 2; - w_temp[2] = (w_ji[2] + w_L[2]) / 2; - w_temp[3] = (w_ji[3] + w_L[3]) / 2; - - double e_1[4] = {1, 0, 0, 0}; - double e_2[4] = {0, 1, 0, 0}; - double e_3[4] = {0, 0, 1, 0}; - double e_4[4] = {0, 0, 0, 1}; - - num_flux->P_plus(this->P_plus_cache[point_i], w_temp, e_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 4, w_temp, e_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 8, w_temp, e_3, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(this->P_plus_cache[point_i] + 12, w_temp, e_4, e->nx[point_i], e->ny[point_i]); - } - - *(const_cast(this))->cacheReady = true; - } - - int index = j * 4 + i; - for (int point_i = 0; point_i < n; point_i++) - { - result += wt[point_i] * P_plus_cache[point_i][index] * u->val[point_i] * v->val[point_i]; - } - - return result * wf->get_current_time_step(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return Ord(24); - } - - MatrixFormSurf* clone() const - { - EulerEquationsMatrixFormSemiImplicitInletOutlet* form = new EulerEquationsMatrixFormSemiImplicitInletOutlet(this->i, this->j, this->rho_ext, this->v1_ext, this->v2_ext, this->energy_ext, this->areas, this->num_flux->kappa, this->cacheReady, this->P_plus_cache, this->P_minus_cache); - form->wf = this->wf; - return form; - } - - double rho_ext; - double v1_ext; - double v2_ext; - double energy_ext; - bool* cacheReady; - double** P_plus_cache; - double** P_minus_cache; - StegerWarmingNumericalFlux* num_flux; - }; - - class EulerEquationsVectorFormSemiImplicitInletOutlet : public VectorFormSurf - { - public: - EulerEquationsVectorFormSemiImplicitInletOutlet(int i, double rho_ext, double v1_ext, double v2_ext, double energy_ext, std::string marker, double kappa) - : VectorFormSurf(i), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), - num_flux(new StegerWarmingNumericalFlux(kappa)) - { - set_area(marker); - } - EulerEquationsVectorFormSemiImplicitInletOutlet(int i, double rho_ext, double v1_ext, double v2_ext, double energy_ext, Hermes::vector markers, double kappa) - : VectorFormSurf(i), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), - num_flux(new StegerWarmingNumericalFlux(kappa)) - { - set_areas(markers); - } - - ~EulerEquationsVectorFormSemiImplicitInletOutlet() - { - delete num_flux; - } - - double value(int n, double *wt, Func *u_ext[], - Func *v, Geom *e, Func* *ext) const - { - double result = 0.; - - double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - - for (int point_i = 0; point_i < n; point_i++) - { - // Inner state. - w_L[0] = ext[0]->val[point_i]; - w_L[1] = ext[1]->val[point_i]; - w_L[2] = ext[2]->val[point_i]; - w_L[3] = ext[3]->val[point_i]; - - // Transformation of the inner state to the local coordinates. - num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); - - // Initialize the matrices. - double T[4][4]; - double T_inv[4][4]; - for(unsigned int ai = 0; ai < 4; ai++) - { - for(unsigned int aj = 0; aj < 4; aj++) - { - T[ai][aj] = 0.0; - T_inv[ai][aj] = 0.0; - } - alpha[ai] = 0; - beta[ai] = 0; - q_ji[ai] = 0; - w_ji[ai] = 0; - eigenvalues[ai] = 0; - } - - // Calculate Lambda^-. - num_flux->Lambda(eigenvalues); - num_flux->T_1(T); - num_flux->T_2(T); - num_flux->T_3(T); - num_flux->T_4(T); - num_flux->T_inv_1(T_inv); - num_flux->T_inv_2(T_inv); - num_flux->T_inv_3(T_inv); - num_flux->T_inv_4(T_inv); - - // "Prescribed" boundary state. - w_B[0] = this->rho_ext; - w_B[1] = this->rho_ext * this->v1_ext; - w_B[2] = this->rho_ext * this->v2_ext; - w_B[3] = this->energy_ext; - - num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); - - for(unsigned int ai = 0; ai < 4; ai++) - for(unsigned int aj = 0; aj < 4; aj++) - alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; - - for(unsigned int bi = 0; bi < 4; bi++) - for(unsigned int bj = 0; bj < 4; bj++) - beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; - - for(unsigned int si = 0; si< 4; si++) - for(unsigned int sj = 0; sj < 4; sj++) - if(eigenvalues[sj] < 0) - q_ji[si] += beta[sj] * T[si][sj]; - else - q_ji[si] += alpha[sj] * T[si][sj]; - - num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); - - double P_minus[4]; - - double w_temp[4]; - w_temp[0] = (w_ji[0] + w_L[0]) / 2; - w_temp[1] = (w_ji[1] + w_L[1]) / 2; - w_temp[2] = (w_ji[2] + w_L[2]) / 2; - w_temp[3] = (w_ji[3] + w_L[3]) / 2; - - num_flux->P_minus(P_minus, w_temp, w_ji, e->nx[point_i], e->ny[point_i]); - - result += wt[point_i] * (P_minus[i]) * v->val[point_i]; - } - - return - result * wf->get_current_time_step(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - return Ord(24); - } - - VectorFormSurf* clone() const - { - EulerEquationsVectorFormSemiImplicitInletOutlet* form = new EulerEquationsVectorFormSemiImplicitInletOutlet(this->i, this->rho_ext, this->v1_ext, this->v2_ext, this->energy_ext, this->areas, this->num_flux->kappa); - form->wf = this->wf; - return form; - } - - double rho_ext; - double v1_ext; - double v2_ext; - double energy_ext; - StegerWarmingNumericalFlux* num_flux; - }; - - class EulerEquationsLinearFormTime : public VectorFormVol - { - public: - EulerEquationsLinearFormTime(int i) - : VectorFormVol(i) {} - - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return int_u_v(n, wt, ext[this->i], v); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return int_u_v(n, wt, ext[this->i], v); - } - - VectorFormVol* clone() const { return new EulerEquationsLinearFormTime(this->i); } - }; - - class EulerEquationsMatrixFormSolidWall : public MatrixFormSurf - { - public: - EulerEquationsMatrixFormSolidWall(int i, int j, Hermes::vector markers, double kappa) - : MatrixFormSurf(i, j), kappa(kappa) {set_areas(markers);} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const - { - double result = 0.; - - for (int point_i = 0; point_i < n; point_i++) - { - double rho = ext[0]->val[point_i]; - double v_1 = ext[1]->val[point_i] / rho; - double v_2 = ext[2]->val[point_i] / rho; - - double P[4][4]; - for(unsigned int P_i = 0; P_i < 4; P_i++) - for(unsigned int P_j = 0; P_j < 4; P_j++) - P[P_i][P_j] = 0.0; - - P[1][0] = (kappa - 1) * (v_1 * v_1 + v_2 * v_2) * e->nx[point_i] / 2; - P[1][1] = (kappa - 1) * (-v_1) * e->nx[point_i]; - P[1][2] = (kappa - 1) * (-v_2) * e->nx[point_i]; - P[1][3] = (kappa - 1) * e->nx[point_i]; - - P[2][0] = (kappa - 1) * (v_1 * v_1 + v_2 * v_2) * e->ny[point_i] / 2; - P[2][1] = (kappa - 1) * (-v_1) * e->ny[point_i]; - P[2][2] = (kappa - 1) * (-v_2) * e->ny[point_i]; - P[2][3] = (kappa - 1) * e->ny[point_i]; - - result += wt[point_i] * P[i][j] * u->val[point_i] * v->val[point_i]; - } - - return result * wf->get_current_time_step(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const - { - return Ord(24); - } - - MatrixFormSurf* clone() const - { - EulerEquationsMatrixFormSolidWall* form = new EulerEquationsMatrixFormSolidWall(this->i, this->j, this->areas, this->kappa); - form->wf = this->wf; - return form; - } - - // Members. - double kappa; - }; - - class EulerEquationsFormStabilizationVol : public MatrixFormVol - { - public: - EulerEquationsFormStabilizationVol(int i, double nu_1) : MatrixFormVol(i, i), nu_1(nu_1) {} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - double result = 0.; - if(static_cast(wf)->discreteIndicator[e->id]) - result = int_grad_u_grad_v(n, wt, u, v) * nu_1 * e->diam; - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - return int_grad_u_grad_v(n, wt, u, v); - } - MatrixFormVol* clone() const - { - EulerEquationsFormStabilizationVol* form = new EulerEquationsFormStabilizationVol(this->i, nu_1); - return form; - } - private: - double nu_1; - }; - - class EulerEquationsFormStabilizationSurf : public MatrixFormDG - { - public: - EulerEquationsFormStabilizationSurf(int i, int j, double nu_2) - : MatrixFormDG(i, j), nu_2(nu_2) {} - - double value(int n, double *wt, DiscontinuousFunc *u, - DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const - { - double result = 0.; - - if(static_cast(wf)->discreteIndicator[e->id] && static_cast(wf)->discreteIndicator[e->get_neighbor_id()]) - { - if(u->val == NULL) - if(v->val == NULL) - for (int point_i = 0; point_i < n; point_i++) - result += wt[i] * (- u->val_neighbor[point_i]) * (- v->val_neighbor[point_i]); - else - for (int point_i = 0; point_i < n; point_i++) - result += wt[i] * (- u->val_neighbor[point_i]) * ( v->val[point_i]); - else - if(v->val == NULL) - for (int point_i = 0; point_i < n; point_i++) - result += wt[i] * (u->val[point_i]) * (- v->val_neighbor[point_i]); - else - for (int point_i = 0; point_i < n; point_i++) - result += wt[i] * (u->val[point_i]) * ( v->val[point_i]); - } - - return result * nu_2; - } - - MatrixFormDG* clone() const - { - EulerEquationsFormStabilizationSurf* form = new EulerEquationsFormStabilizationSurf(this->i, this->j, nu_2); - form->wf = this->wf; - return form; - } - - double nu_2; - }; - - -}; - -class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsWeakFormSemiImplicit -{ -public: - Solution* prev_temp; - - EulerEquationsWeakFormSemiImplicitCoupledWithHeat(double kappa, - double rho_ext, double v1_ext, double v2_ext, double pressure_ext, - Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, Solution* prev_temp, - bool fvm_only = false) : EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, - prev_density_vel_x, prev_density_vel_y, prev_energy, fvm_only, 5), prev_temp(prev_temp) - { - add_matrix_form(new HeatBilinearFormTime(4)); - - add_vector_form(new HeatLinearFormTime(4)); - - this->add_vector_form_surf(new HeatLinearSurfForm(4, inlet_markers)); - - this->ext.push_back(prev_temp); - } - - WeakForm* clone() const - { - EulerEquationsWeakFormSemiImplicitCoupledWithHeat* wf; - wf = new EulerEquationsWeakFormSemiImplicitCoupledWithHeat(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], - this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->prev_temp, this->fvm_only); - - wf->ext.clear(); - - for(unsigned int i = 0; i < this->ext.size(); i++) - { - Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) - ext->set_type(HERMES_SLN); - wf->ext.push_back(ext); - } - - wf->set_current_time_step(this->get_current_time_step()); - - return wf; - } - - class HeatBilinearFormTime : public MatrixFormVol - { - public: - HeatBilinearFormTime(int i) : MatrixFormVol(i, i), c_p(1e2), lambda(1e2) {} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n; point_i++) - { - double rho = ext[0]->val[point_i]; - result += wt[point_i] * u->val[point_i] * v->val[point_i] * rho * c_p; - result -= wt[point_i] * (u->dx[point_i] * v->dx[point_i] + u->dy[point_i] * v->dy[point_i]) * lambda; - result -= (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i] * c_p; - } - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - Ord result = Ord(0); - for (int point_i = 0; point_i < n; point_i++) - { - Ord rho = ext[0]->val[point_i]; - result += wt[point_i] * (u->val[point_i] * v->val[point_i] * rho - u->dx[point_i] * v->dx[point_i] - u->dy[point_i] * v->dy[point_i] - rho * rho * (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i]); - } - return result; - } - - MatrixFormVol* clone() const { return new HeatBilinearFormTime(this->i); } - - double c_p, lambda; - }; - - class HeatLinearFormTime : public VectorFormVol - { - public: - HeatLinearFormTime(int i) - : VectorFormVol(i), c_p(1e2) {} - - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n; point_i++) - { - double rho = ext[0]->val[point_i]; - result += wt[i] * v->val[point_i] * rho * ext[this->i]->val[point_i] * c_p; - } - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return wt[0] * v->val[0] * ext[0]->val[0] * ext[this->i]->val[0]; - } - - VectorFormVol* clone() const { return new HeatLinearFormTime(this->i); } - - double c_p; - }; - - class HeatLinearSurfForm : public VectorFormSurf - { - public: - HeatLinearSurfForm(int i, Hermes::vector areas) - : VectorFormSurf(i), neumann_value(1e-6), lambda(1e2) - { - this->set_areas(areas); - } - - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n; point_i++) - result -= wt[i] * v->val[point_i] * neumann_value * lambda; - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return wt[0] * v->val[0]; - } - - VectorFormSurf* clone() const { return new HeatLinearSurfForm(this->i, this->areas); } - - double neumann_value, lambda; - }; -}; - - -/* -class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm -{ -public: - // Constructor. - EulerEquationsWeakFormSemiImplicitTwoInflows(double kappa, double rho_ext1, double v1_ext1, double v2_ext1, double pressure_ext1, double rho_ext2, double v1_ext2, double v2_ext2, double pressure_ext2, - std::string wall_marker, std::string inlet_marker1, std::string inlet_marker2, std::string outlet_marker, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, bool fvm_only = false, int num_of_equations = 4) : - WeakForm(num_of_equations), - rho_ext1(rho_ext1), v1_ext1(v1_ext1), v2_ext1(v2_ext1), pressure_ext1(pressure_ext1), - energy_ext1(QuantityCalculator::calc_energy(rho_ext1, rho_ext1* v1_ext1, rho_ext1 * v2_ext1, pressure_ext1, kappa)), - rho_ext2(rho_ext2), v1_ext2(v1_ext2), v2_ext2(v2_ext2), pressure_ext2(pressure_ext2), - energy_ext2(QuantityCalculator::calc_energy(rho_ext2, rho_ext2 * v1_ext2, rho_ext2 * v2_ext2, pressure_ext2, kappa)), - euler_fluxes(new EulerFluxes(kappa)) - { - add_matrix_form(new EulerEquationsBilinearFormTime(0)); - add_matrix_form(new EulerEquationsBilinearFormTime(1)); - add_matrix_form(new EulerEquationsBilinearFormTime(2)); - add_matrix_form(new EulerEquationsBilinearFormTime(3)); - - add_vector_form(new EulerEquationsLinearFormTime(0)); - add_vector_form(new EulerEquationsLinearFormTime(1)); - add_vector_form(new EulerEquationsLinearFormTime(2)); - add_vector_form(new EulerEquationsLinearFormTime(3)); - - if(!fvm_only) - { - add_matrix_form(new EulerEquationsBilinearForm(0, 0)); - add_matrix_form(new EulerEquationsBilinearForm(0, 1)); - add_matrix_form(new EulerEquationsBilinearForm(0, 2)); - add_matrix_form(new EulerEquationsBilinearForm(0, 3)); - add_matrix_form(new EulerEquationsBilinearForm(1, 0)); - add_matrix_form(new EulerEquationsBilinearForm(1, 1)); - add_matrix_form(new EulerEquationsBilinearForm(1, 2)); - add_matrix_form(new EulerEquationsBilinearForm(1, 3)); - add_matrix_form(new EulerEquationsBilinearForm(2, 0)); - add_matrix_form(new EulerEquationsBilinearForm(2, 1)); - add_matrix_form(new EulerEquationsBilinearForm(2, 2)); - add_matrix_form(new EulerEquationsBilinearForm(2, 3)); - add_matrix_form(new EulerEquationsBilinearForm(3, 0)); - add_matrix_form(new EulerEquationsBilinearForm(3, 1)); - add_matrix_form(new EulerEquationsBilinearForm(3, 2)); - add_matrix_form(new EulerEquationsBilinearForm(3, 3)); - } - - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(0, 0, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(1, 0, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(2, 0, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(3, 0, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(0, 1, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(1, 1, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(2, 1, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(3, 1, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(0, 2, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(1, 2, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(2, 2, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(3, 2, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(0, 3, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(1, 3, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(2, 3, kappa)); - add_matrix_form_DG(new EulerEquationsMatrixFormSurfSemiImplicit(3, 3, kappa)); - - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(0, 0, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(1, 0, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(2, 0, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(3, 0, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(0, 1, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(1, 1, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(2, 1, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(3, 1, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(0, 2, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(1, 2, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(2, 2, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(3, 2, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(0, 3, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(1, 3, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(2, 3, wall_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSolidWall(3, 3, wall_marker, kappa)); - - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 0, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 0, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 0, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 0, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 1, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 1, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 1, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 1, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 2, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 2, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 2, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 2, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 3, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 3, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 3, inlet_marker1, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 3, inlet_marker1, kappa)); - - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(0, inlet_marker1, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(1, inlet_marker1, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(2, inlet_marker1, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(3, inlet_marker1, kappa)); - - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(0, 0, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(1, 0, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(2, 0, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(3, 0, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(0, 1, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(1, 1, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(2, 1, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(3, 1, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(0, 2, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(1, 2, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(2, 2, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(3, 2, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(0, 3, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(1, 3, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(2, 3, inlet_marker2, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet2(3, 3, inlet_marker2, kappa)); - - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet2(0, inlet_marker2, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet2(1, inlet_marker2, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet2(2, inlet_marker2, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet2(3, inlet_marker2, kappa)); - - - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 0, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 0, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 0, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 0, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 1, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 1, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 1, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 1, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 2, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 2, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 2, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 2, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(0, 3, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(1, 3, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(2, 3, outlet_marker, kappa)); - add_matrix_form_surf(new EulerEquationsMatrixFormSemiImplicitInletOutlet1(3, 3, outlet_marker, kappa)); - - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(0, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(1, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(2, outlet_marker, kappa)); - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet1(3, outlet_marker, kappa)); - - for(unsigned int vector_form_i = 0;vector_form_i < this->vfvol.size();vector_form_i++) - vfvol.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - - for(unsigned int vector_form_i = 0;vector_form_i < this->vfsurf.size();vector_form_i++) - vfsurf.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - - for(unsigned int vector_form_i = 0;vector_form_i < this->vfDG.size();vector_form_i++) - vfDG.at(vector_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - - for(unsigned int matrix_form_i = 0;matrix_form_i < this->mfvol.size();matrix_form_i++) - mfvol.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - - for(unsigned int matrix_form_i = 0;matrix_form_i < this->mfsurf.size();matrix_form_i++) - mfsurf.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - - for(unsigned int matrix_form_i = 0;matrix_form_i < this->mfDG.size();matrix_form_i++) - mfDG.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - }; - - void set_time_step(double tau) - { - this->tau = tau; - } - - double get_tau() const - { - return tau; - } - - void set_stabilization(Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, double nu_1, double nu_2) - { - int mfvol_size = this->mfvol.size(); - int mfsurf_size = this->mfsurf.size(); - - add_matrix_form(new EulerEquationsFormStabilizationVol(0, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(1, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(2, nu_1)); - add_matrix_form(new EulerEquationsFormStabilizationVol(3, nu_1)); - - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(0, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(1, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(2, 3, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 0, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 1, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 2, nu_2)); - add_matrix_form_DG(new EulerEquationsFormStabilizationSurf(3, 3, nu_2)); - - for(unsigned int matrix_form_i = mfvol_size;matrix_form_i < this->mfvol.size();matrix_form_i++) - { - mfvol.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - } - - for(unsigned int matrix_form_i = mfsurf_size;matrix_form_i < this->mfsurf.size();matrix_form_i++) - { - mfsurf.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); - } - } - - void set_discreteIndicator(bool* discreteIndicator) - { - this->discreteIndicator = discreteIndicator; - } - -protected: - class EulerEquationsBilinearFormTime : public MatrixFormVol - { - public: - EulerEquationsBilinearFormTime(int i) : MatrixFormVol(i, i) {} - - template - Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return int_u_v(n, wt, u, v); - } - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return matrix_form(n, wt, u_ext, u, v, e, ext); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - return matrix_form(n, wt, u_ext, u, v, e, ext); - } - - MatrixFormVol* clone() const { return new EulerEquationsBilinearFormTime(this->i); } - }; - - class EulerEquationsBilinearForm : public MatrixFormVol - { - public: - EulerEquationsBilinearForm(int i, int j) : MatrixFormVol(i, j) {} - - double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, - Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n;point_i++) - { - switch(i) - { - case 0: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_0_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_0_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 1: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_0_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_0_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 2: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_0_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_0_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 3: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_0_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_0_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - } - break; - case 1: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_1_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_1_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 1: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_1_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_1_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 2: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_1_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_1_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 3: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_1_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_1_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - } - break; - case 2: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_2_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_2_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 1: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_2_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_2_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 2: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_2_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_2_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 3: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_2_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_2_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - } - break; - case 3: - switch(j) - { - case 0: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_3_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], ext[3]->val[point_i]) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_3_0(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], ext[3]->val[point_i]) - * v->dy[point_i]; - break; - case 1: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_3_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], ext[3]->val[point_i]) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_3_1(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - case 2: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_3_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_3_2(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], ext[3]->val[point_i]) - * v->dy[point_i]; - break; - case 3: - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_1_3_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dx[point_i]; - result += wt[point_i] * u->val[point_i] - * (static_cast(wf))->euler_fluxes->A_2_3_3(ext[0]->val[point_i], ext[1]->val[point_i], ext[2]->val[point_i], 0) - * v->dy[point_i]; - break; - } - } - } - - return - result * static_cast(wf)->get_tau(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const - { - return Ord(24); - } - MatrixFormVol* clone() const - { - EulerEquationsBilinearForm* form = new EulerEquationsBilinearForm(this->i, this->j); - form->wf = this->wf; - return form; - } - }; - - class EulerEquationsMatrixFormSurfSemiImplicit : public MatrixFormDG - { - public: - EulerEquationsMatrixFormSurfSemiImplicit(int i, int j, double kappa) - : MatrixFormDG(i, j), - num_flux(new StegerWarmingNumericalFlux(kappa)) {} - - virtual ~EulerEquationsMatrixFormSurfSemiImplicit() - { - delete num_flux; - } - - double value(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const - { - double w[4]; - double result = 0.; - for (int point_i = 0; point_i < n; point_i++) - { - w[0] = ext[0]->get_val_central(point_i); - w[1] = ext[1]->get_val_central(point_i); - w[2] = ext[2]->get_val_central(point_i); - w[3] = ext[3]->get_val_central(point_i); - - double e_1_1[4] = {1, 0, 0, 0}; - double e_2_1[4] = {0, 1, 0, 0}; - double e_3_1[4] = {0, 0, 1, 0}; - double e_4_1[4] = {0, 0, 0, 1}; - - double P_plus_1[4]; - double P_plus_2[4]; - double P_plus_3[4]; - double P_plus_4[4]; - - num_flux->P_plus(P_plus_1, w, e_1_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_2, w, e_2_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_3, w, e_3_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_4, w, e_4_1, e->nx[point_i], e->ny[point_i]); - - w[0] = ext[0]->get_val_neighbor(point_i); - w[1] = ext[1]->get_val_neighbor(point_i); - w[2] = ext[2]->get_val_neighbor(point_i); - w[3] = ext[3]->get_val_neighbor(point_i); - - double e_1_2[4] = {1, 0, 0, 0}; - double e_2_2[4] = {0, 1, 0, 0}; - double e_3_2[4] = {0, 0, 1, 0}; - double e_4_2[4] = {0, 0, 0, 1}; - - double P_minus_1[4]; - double P_minus_2[4]; - double P_minus_3[4]; - double P_minus_4[4]; - - num_flux->P_minus(P_minus_1, w, e_1_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(P_minus_2, w, e_2_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(P_minus_3, w, e_3_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_minus(P_minus_4, w, e_4_2, e->nx[point_i], e->ny[point_i]); - - if(i == 0 && j == 0) - result += wt[point_i] * (P_plus_1[0] * u->get_val_central(point_i) + P_minus_1[0] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 0 && j == 1) - result += wt[point_i] * (P_plus_2[0] * u->get_val_central(point_i) + P_minus_2[0] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 0 && j == 2) - result += wt[point_i] * (P_plus_3[0] * u->get_val_central(point_i) + P_minus_3[0] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 0 && j == 3) - result += wt[point_i] * (P_plus_4[0] * u->get_val_central(point_i) + P_minus_4[0] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - - if(i == 1 && j == 0) - result += wt[point_i] * (P_plus_1[1] * u->get_val_central(point_i) + P_minus_1[1] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 1 && j == 1) - result += wt[point_i] * (P_plus_2[1] * u->get_val_central(point_i) + P_minus_2[1] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 1 && j == 2) - result += wt[point_i] * (P_plus_3[1] * u->get_val_central(point_i) + P_minus_3[1] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 1 && j == 3) - result += wt[point_i] * (P_plus_4[1] * u->get_val_central(point_i) + P_minus_4[1] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - - if(i == 2 && j == 0) - result += wt[point_i] * (P_plus_1[2] * u->get_val_central(point_i) + P_minus_1[2] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 2 && j == 1) - result += wt[point_i] * (P_plus_2[2] * u->get_val_central(point_i) + P_minus_2[2] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 2 && j == 2) - result += wt[point_i] * (P_plus_3[2] * u->get_val_central(point_i) + P_minus_3[2] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 2 && j == 3) - result += wt[point_i] * (P_plus_4[2] * u->get_val_central(point_i) + P_minus_4[2] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - - if(i == 3 && j == 0) - result += wt[point_i] * (P_plus_1[3] * u->get_val_central(point_i) + P_minus_1[3] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 3 && j == 1) - result += wt[point_i] * (P_plus_2[3] * u->get_val_central(point_i) + P_minus_2[3] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 3 && j == 2) - result += wt[point_i] * (P_plus_3[3] * u->get_val_central(point_i) + P_minus_3[3] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - if(i == 3 && j == 3) - result += wt[point_i] * (P_plus_4[3] * u->get_val_central(point_i) + P_minus_4[3] * u->get_val_neighbor(point_i)) * (v->get_val_central(point_i) - v->get_val_neighbor(point_i)) * static_cast(wf)->get_tau(); - } - - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return Ord(24); - } - - MatrixFormDG* clone() const - { - EulerEquationsMatrixFormSurfSemiImplicit* form = new EulerEquationsMatrixFormSurfSemiImplicit(this->i, this->j, this->num_flux->kappa); - form->wf = this->wf; - return form; - } - StegerWarmingNumericalFlux* num_flux; - }; - - class EulerEquationsMatrixFormSemiImplicitInletOutlet1 : public MatrixFormSurf - { - public: - EulerEquationsMatrixFormSemiImplicitInletOutlet1(int i, int j, - std::string marker, double kappa) - : MatrixFormSurf(i, j), - num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker);} - - virtual ~EulerEquationsMatrixFormSemiImplicitInletOutlet1() - { - delete num_flux; - } - - double value(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const - { - double result = 0.; - - double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - - for (int point_i = 0; point_i < n; point_i++) - { - // Inner state. - w_L[0] = ext[0]->val[point_i]; - w_L[1] = ext[1]->val[point_i]; - w_L[2] = ext[2]->val[point_i]; - w_L[3] = ext[3]->val[point_i]; - - // Transformation of the inner state to the local coordinates. - num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); - - // Initialize the matrices. - double T[4][4]; - double T_inv[4][4]; - for(unsigned int ai = 0; ai < 4; ai++) - { - for(unsigned int aj = 0; aj < 4; aj++) - { - T[ai][aj] = 0.0; - T_inv[ai][aj] = 0.0; - } - alpha[ai] = 0; - beta[ai] = 0; - q_ji[ai] = 0; - w_ji[ai] = 0; - eigenvalues[ai] = 0; - } - - // Calculate Lambda^-. - num_flux->Lambda(eigenvalues); - num_flux->T_1(T); - num_flux->T_2(T); - num_flux->T_3(T); - num_flux->T_4(T); - num_flux->T_inv_1(T_inv); - num_flux->T_inv_2(T_inv); - num_flux->T_inv_3(T_inv); - num_flux->T_inv_4(T_inv); - - // "Prescribed" boundary state. - w_B[0] = static_cast(wf)->rho_ext1; - w_B[1] = static_cast(wf)->rho_ext1 - * static_cast(wf)->v1_ext1; - w_B[2] = static_cast(wf)->rho_ext1 - * static_cast(wf)->v2_ext1; - w_B[3] = static_cast(wf)->energy_ext1; - - num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); - - for(unsigned int ai = 0; ai < 4; ai++) - for(unsigned int aj = 0; aj < 4; aj++) - alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; - - for(unsigned int bi = 0; bi < 4; bi++) - for(unsigned int bj = 0; bj < 4; bj++) - beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; - - for(unsigned int si = 0; si< 4; si++) - for(unsigned int sj = 0; sj < 4; sj++) - if(eigenvalues[sj] < 0) - q_ji[si] += beta[sj] * T[si][sj]; - else - q_ji[si] += alpha[sj] * T[si][sj]; - - num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); - - double P_minus[4]; - - double w_temp[4]; - w_temp[0] = (w_ji[0] + w_L[0]) / 2; - w_temp[1] = (w_ji[1] + w_L[1]) / 2; - w_temp[2] = (w_ji[2] + w_L[2]) / 2; - w_temp[3] = (w_ji[3] + w_L[3]) / 2; - - double e_1[4] = {1, 0, 0, 0}; - double e_2[4] = {0, 1, 0, 0}; - double e_3[4] = {0, 0, 1, 0}; - double e_4[4] = {0, 0, 0, 1}; - - double P_plus_1[4]; - double P_plus_2[4]; - double P_plus_3[4]; - double P_plus_4[4]; - - num_flux->P_plus(P_plus_1, w_temp, e_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_2, w_temp, e_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_3, w_temp, e_3, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_4, w_temp, e_4, e->nx[point_i], e->ny[point_i]); - - if(i == 0 && j == 0) - result += wt[point_i] * P_plus_1[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 1) - result += wt[point_i] * P_plus_2[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 2) - result += wt[point_i] * P_plus_3[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 3) - result += wt[point_i] * P_plus_4[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 1 && j == 0) - result += wt[point_i] * P_plus_1[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 1) - result += wt[point_i] * P_plus_2[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 2) - result += wt[point_i] * P_plus_3[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 3) - result += wt[point_i] * P_plus_4[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 2 && j == 0) - result += wt[point_i] * P_plus_1[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 1) - result += wt[point_i] * P_plus_2[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 2) - result += wt[point_i] * P_plus_3[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 3) - result += wt[point_i] * P_plus_4[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 3 && j == 0) - result += wt[point_i] * P_plus_1[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 1) - result += wt[point_i] * P_plus_2[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 2) - result += wt[point_i] * P_plus_3[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 3) - result += wt[point_i] * P_plus_4[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - } - - return result; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const - { - return Ord(24); + if(u->val == NULL) + if(v->val == NULL) + for (int point_i = 0; point_i < n; point_i++) + result -= wt[point_i] * (this->P_minus_cache[point_i][index] * u->val_neighbor[point_i]) * v->val_neighbor[point_i]; + else + for (int point_i = 0; point_i < n; point_i++) + result += wt[point_i] * (this->P_minus_cache[point_i][index] * u->val_neighbor[point_i]) * v->val[point_i]; + else + if(v->val == NULL) + for (int point_i = 0; point_i < n; point_i++) + result -= wt[point_i] * (this->P_plus_cache[point_i][index] * u->val[point_i]) * v->val_neighbor[point_i]; + else + for (int point_i = 0; point_i < n; point_i++) + result += wt[point_i] * (this->P_plus_cache[point_i][index] * u->val[point_i]) * v->val[point_i]; + + return result * wf->get_current_time_step(); } - MatrixFormSurf* clone() const - { - EulerEquationsMatrixFormSemiImplicitInletOutlet1* form = new EulerEquationsMatrixFormSemiImplicitInletOutlet1(this->i, this->j, this->areas[0], this->num_flux->kappa); + MatrixFormDG* clone() const + { + EulerEquationsMatrixFormSurfSemiImplicit* form = new EulerEquationsMatrixFormSurfSemiImplicit(this->i, this->j, this->num_flux->kappa, this->fluxes, this->cacheReady, this->P_plus_cache, this->P_minus_cache); form->wf = this->wf; return form; } + + bool* cacheReady; + double** P_plus_cache; + double** P_minus_cache; StegerWarmingNumericalFlux* num_flux; + EulerFluxes* fluxes; }; - class EulerEquationsVectorFormSemiImplicitInletOutlet1 : public VectorFormSurf + class EulerEquationsMatrixFormSemiImplicitInletOutlet : public MatrixFormSurf { public: - EulerEquationsVectorFormSemiImplicitInletOutlet1(int i, std::string marker, double kappa) - : VectorFormSurf(i), - num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker);} - - ~EulerEquationsVectorFormSemiImplicitInletOutlet1() - { - delete num_flux; - } - - double value(int n, double *wt, Func *u_ext[], - Func *v, Geom *e, Func* *ext) const - { - double result = 0.; - - double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - - for (int point_i = 0; point_i < n; point_i++) - { - // Inner state. - w_L[0] = ext[0]->val[point_i]; - w_L[1] = ext[1]->val[point_i]; - w_L[2] = ext[2]->val[point_i]; - w_L[3] = ext[3]->val[point_i]; - - // Transformation of the inner state to the local coordinates. - num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); - - // Initialize the matrices. - double T[4][4]; - double T_inv[4][4]; - for(unsigned int ai = 0; ai < 4; ai++) - { - for(unsigned int aj = 0; aj < 4; aj++) - { - T[ai][aj] = 0.0; - T_inv[ai][aj] = 0.0; - } - alpha[ai] = 0; - beta[ai] = 0; - q_ji[ai] = 0; - w_ji[ai] = 0; - eigenvalues[ai] = 0; - } - - // Calculate Lambda^-. - num_flux->Lambda(eigenvalues); - num_flux->T_1(T); - num_flux->T_2(T); - num_flux->T_3(T); - num_flux->T_4(T); - num_flux->T_inv_1(T_inv); - num_flux->T_inv_2(T_inv); - num_flux->T_inv_3(T_inv); - num_flux->T_inv_4(T_inv); - - // "Prescribed" boundary state. - w_B[0] = static_cast(wf)->rho_ext1; - w_B[1] = static_cast(wf)->rho_ext1 - * static_cast(wf)->v1_ext1; - w_B[2] = static_cast(wf)->rho_ext1 - * static_cast(wf)->v2_ext1; - w_B[3] = static_cast(wf)->energy_ext1; - - num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); - - for(unsigned int ai = 0; ai < 4; ai++) - for(unsigned int aj = 0; aj < 4; aj++) - alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; - - for(unsigned int bi = 0; bi < 4; bi++) - for(unsigned int bj = 0; bj < 4; bj++) - beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; - - for(unsigned int si = 0; si< 4; si++) - for(unsigned int sj = 0; sj < 4; sj++) - if(eigenvalues[sj] < 0) - q_ji[si] += beta[sj] * T[si][sj]; - else - q_ji[si] += alpha[sj] * T[si][sj]; - - num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); - - double P_minus[4]; - - double w_temp[4]; - w_temp[0] = (w_ji[0] + w_L[0]) / 2; - w_temp[1] = (w_ji[1] + w_L[1]) / 2; - w_temp[2] = (w_ji[2] + w_L[2]) / 2; - w_temp[3] = (w_ji[3] + w_L[3]) / 2; - - num_flux->P_minus(P_minus, w_temp, w_ji, e->nx[point_i], e->ny[point_i]); - - result += wt[point_i] * (P_minus[i]) * v->val[point_i]; - } - - return - result * static_cast(wf)->get_tau(); - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const - { - return Ord(24); + EulerEquationsMatrixFormSemiImplicitInletOutlet(int i, int j, double rho_ext, double v1_ext, double v2_ext, double energy_ext, std::string marker, double kappa, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) + : MatrixFormSurf(i, j), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache) + { + set_area(marker); } - - VectorFormSurf* clone() const - { - EulerEquationsVectorFormSemiImplicitInletOutlet1* form = new EulerEquationsVectorFormSemiImplicitInletOutlet1(this->i, this->areas[0], this->num_flux->kappa); - form->wf = this->wf; - return form; + EulerEquationsMatrixFormSemiImplicitInletOutlet(int i, int j, double rho_ext, double v1_ext, double v2_ext, double energy_ext, Hermes::vector markers, double kappa, bool* cacheReady, double** P_plus_cache, double** P_minus_cache) + : MatrixFormSurf(i, j), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), num_flux(new StegerWarmingNumericalFlux(kappa)), cacheReady(cacheReady), P_plus_cache(P_plus_cache), P_minus_cache(P_minus_cache) + { + set_areas(markers); } - StegerWarmingNumericalFlux* num_flux; - }; - - class EulerEquationsMatrixFormSemiImplicitInletOutlet2 : public MatrixFormSurf - { - public: - EulerEquationsMatrixFormSemiImplicitInletOutlet2(int i, int j, - std::string marker, double kappa) - : MatrixFormSurf(i, j), - num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker);} - virtual ~EulerEquationsMatrixFormSemiImplicitInletOutlet2() + ~EulerEquationsMatrixFormSemiImplicitInletOutlet() { delete num_flux; } @@ -2508,135 +578,103 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm { double result = 0.; - double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - - for (int point_i = 0; point_i < n; point_i++) + if(!(*this->cacheReady)) { - // Inner state. - w_L[0] = ext[0]->val[point_i]; - w_L[1] = ext[1]->val[point_i]; - w_L[2] = ext[2]->val[point_i]; - w_L[3] = ext[3]->val[point_i]; + for (int point_i = 0; point_i < n; point_i++) + { + double w_B[4], w_L[4], eigenvalues[4], alpha[4], q_ji_star[4], beta[4], q_ji[4], w_ji[4]; - // Transformation of the inner state to the local coordinates. - num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); + // Inner state. + w_L[0] = ext[0]->val[point_i]; + w_L[1] = ext[1]->val[point_i]; + w_L[2] = ext[2]->val[point_i]; + w_L[3] = ext[3]->val[point_i]; - // Initialize the matrices. - double T[4][4]; - double T_inv[4][4]; - for(unsigned int ai = 0; ai < 4; ai++) - { - for(unsigned int aj = 0; aj < 4; aj++) + // Transformation of the inner state to the local coordinates. + num_flux->Q(num_flux->get_q(), w_L, e->nx[point_i], e->ny[point_i]); + + // Initialize the matrices. + double T[4][4]; + double T_inv[4][4]; + for(unsigned int ai = 0; ai < 4; ai++) { - T[ai][aj] = 0.0; - T_inv[ai][aj] = 0.0; + for(unsigned int aj = 0; aj < 4; aj++) + { + T[ai][aj] = 0.0; + T_inv[ai][aj] = 0.0; + } + alpha[ai] = 0; + beta[ai] = 0; + q_ji[ai] = 0; + w_ji[ai] = 0; + eigenvalues[ai] = 0; } - alpha[ai] = 0; - beta[ai] = 0; - q_ji[ai] = 0; - w_ji[ai] = 0; - eigenvalues[ai] = 0; - } - // Calculate Lambda^-. - num_flux->Lambda(eigenvalues); - num_flux->T_1(T); - num_flux->T_2(T); - num_flux->T_3(T); - num_flux->T_4(T); - num_flux->T_inv_1(T_inv); - num_flux->T_inv_2(T_inv); - num_flux->T_inv_3(T_inv); - num_flux->T_inv_4(T_inv); + // Calculate Lambda^-. + num_flux->Lambda(eigenvalues); + num_flux->T_1(T); + num_flux->T_2(T); + num_flux->T_3(T); + num_flux->T_4(T); + num_flux->T_inv_1(T_inv); + num_flux->T_inv_2(T_inv); + num_flux->T_inv_3(T_inv); + num_flux->T_inv_4(T_inv); - // "Prescribed" boundary state. - w_B[0] = static_cast(wf)->rho_ext2; - w_B[1] = static_cast(wf)->rho_ext2 - * static_cast(wf)->v1_ext2; - w_B[2] = static_cast(wf)->rho_ext2 - * static_cast(wf)->v2_ext2; - w_B[3] = static_cast(wf)->energy_ext2; + // "Prescribed" boundary state. + w_B[0] = this->rho_ext; + w_B[1] = this->rho_ext * this->v1_ext; + w_B[2] = this->rho_ext * this->v2_ext; + w_B[3] = this->energy_ext; - num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); + num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); - for(unsigned int ai = 0; ai < 4; ai++) - for(unsigned int aj = 0; aj < 4; aj++) - alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; + for(unsigned int ai = 0; ai < 4; ai++) + for(unsigned int aj = 0; aj < 4; aj++) + alpha[ai] += T_inv[ai][aj] * num_flux->get_q()[aj]; - for(unsigned int bi = 0; bi < 4; bi++) - for(unsigned int bj = 0; bj < 4; bj++) - beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; + for(unsigned int bi = 0; bi < 4; bi++) + for(unsigned int bj = 0; bj < 4; bj++) + beta[bi] += T_inv[bi][bj] * q_ji_star[bj]; - for(unsigned int si = 0; si< 4; si++) - for(unsigned int sj = 0; sj < 4; sj++) - if(eigenvalues[sj] < 0) - q_ji[si] += beta[sj] * T[si][sj]; - else - q_ji[si] += alpha[sj] * T[si][sj]; + for(unsigned int si = 0; si< 4; si++) + for(unsigned int sj = 0; sj < 4; sj++) + if(eigenvalues[sj] < 0) + q_ji[si] += beta[sj] * T[si][sj]; + else + q_ji[si] += alpha[sj] * T[si][sj]; + + num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); + + double P_minus[4]; + + double w_temp[4]; + w_temp[0] = (w_ji[0] + w_L[0]) / 2; + w_temp[1] = (w_ji[1] + w_L[1]) / 2; + w_temp[2] = (w_ji[2] + w_L[2]) / 2; + w_temp[3] = (w_ji[3] + w_L[3]) / 2; - num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); + double e_1[4] = {1, 0, 0, 0}; + double e_2[4] = {0, 1, 0, 0}; + double e_3[4] = {0, 0, 1, 0}; + double e_4[4] = {0, 0, 0, 1}; - double P_minus[4]; + num_flux->P_plus(this->P_plus_cache[point_i], w_temp, e_1, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 4, w_temp, e_2, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 8, w_temp, e_3, e->nx[point_i], e->ny[point_i]); + num_flux->P_plus(this->P_plus_cache[point_i] + 12, w_temp, e_4, e->nx[point_i], e->ny[point_i]); + } - double w_temp[4]; - w_temp[0] = (w_ji[0] + w_L[0]) / 2; - w_temp[1] = (w_ji[1] + w_L[1]) / 2; - w_temp[2] = (w_ji[2] + w_L[2]) / 2; - w_temp[3] = (w_ji[3] + w_L[3]) / 2; + *(const_cast(this))->cacheReady = true; + } - double e_1[4] = {1, 0, 0, 0}; - double e_2[4] = {0, 1, 0, 0}; - double e_3[4] = {0, 0, 1, 0}; - double e_4[4] = {0, 0, 0, 1}; - - double P_plus_1[4]; - double P_plus_2[4]; - double P_plus_3[4]; - double P_plus_4[4]; - - num_flux->P_plus(P_plus_1, w_temp, e_1, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_2, w_temp, e_2, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_3, w_temp, e_3, e->nx[point_i], e->ny[point_i]); - num_flux->P_plus(P_plus_4, w_temp, e_4, e->nx[point_i], e->ny[point_i]); - - if(i == 0 && j == 0) - result += wt[point_i] * P_plus_1[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 1) - result += wt[point_i] * P_plus_2[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 2) - result += wt[point_i] * P_plus_3[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 3) - result += wt[point_i] * P_plus_4[0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 1 && j == 0) - result += wt[point_i] * P_plus_1[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 1) - result += wt[point_i] * P_plus_2[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 2) - result += wt[point_i] * P_plus_3[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 3) - result += wt[point_i] * P_plus_4[1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 2 && j == 0) - result += wt[point_i] * P_plus_1[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 1) - result += wt[point_i] * P_plus_2[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 2) - result += wt[point_i] * P_plus_3[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 3) - result += wt[point_i] * P_plus_4[2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 3 && j == 0) - result += wt[point_i] * P_plus_1[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 1) - result += wt[point_i] * P_plus_2[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 2) - result += wt[point_i] * P_plus_3[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 3) - result += wt[point_i] * P_plus_4[3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); + int index = j * 4 + i; + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * P_plus_cache[point_i][index] * u->val[point_i] * v->val[point_i]; } - return result; + return result * wf->get_current_time_step(); } Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, @@ -2645,23 +683,40 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm return Ord(24); } - MatrixFormSurf* clone() const - { - EulerEquationsMatrixFormSemiImplicitInletOutlet2* form = new EulerEquationsMatrixFormSemiImplicitInletOutlet2(this->i, this->j, this->areas[0], this->num_flux->kappa); + MatrixFormSurf* clone() const + { + EulerEquationsMatrixFormSemiImplicitInletOutlet* form = new EulerEquationsMatrixFormSemiImplicitInletOutlet(this->i, this->j, this->rho_ext, this->v1_ext, this->v2_ext, this->energy_ext, this->areas, this->num_flux->kappa, this->cacheReady, this->P_plus_cache, this->P_minus_cache); form->wf = this->wf; return form; } + + double rho_ext; + double v1_ext; + double v2_ext; + double energy_ext; + bool* cacheReady; + double** P_plus_cache; + double** P_minus_cache; StegerWarmingNumericalFlux* num_flux; }; - class EulerEquationsVectorFormSemiImplicitInletOutlet2 : public VectorFormSurf + class EulerEquationsVectorFormSemiImplicitInletOutlet : public VectorFormSurf { public: - EulerEquationsVectorFormSemiImplicitInletOutlet2(int i, std::string marker, double kappa) - : VectorFormSurf(i), - num_flux(new StegerWarmingNumericalFlux(kappa)) { set_area(marker);} + EulerEquationsVectorFormSemiImplicitInletOutlet(int i, double rho_ext, double v1_ext, double v2_ext, double energy_ext, std::string marker, double kappa) + : VectorFormSurf(i), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), + num_flux(new StegerWarmingNumericalFlux(kappa)) + { + set_area(marker); + } + EulerEquationsVectorFormSemiImplicitInletOutlet(int i, double rho_ext, double v1_ext, double v2_ext, double energy_ext, Hermes::vector markers, double kappa) + : VectorFormSurf(i), rho_ext(rho_ext), v1_ext(v1_ext), v2_ext(v2_ext), energy_ext(energy_ext), + num_flux(new StegerWarmingNumericalFlux(kappa)) + { + set_areas(markers); + } - ~EulerEquationsVectorFormSemiImplicitInletOutlet2() + ~EulerEquationsVectorFormSemiImplicitInletOutlet() { delete num_flux; } @@ -2713,12 +768,10 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm num_flux->T_inv_4(T_inv); // "Prescribed" boundary state. - w_B[0] = static_cast(wf)->rho_ext2; - w_B[1] = static_cast(wf)->rho_ext2 - * static_cast(wf)->v1_ext2; - w_B[2] = static_cast(wf)->rho_ext2 - * static_cast(wf)->v2_ext2; - w_B[3] = static_cast(wf)->energy_ext2; + w_B[0] = this->rho_ext; + w_B[1] = this->rho_ext * this->v1_ext; + w_B[2] = this->rho_ext * this->v2_ext; + w_B[3] = this->energy_ext; num_flux->Q(q_ji_star, w_B, e->nx[point_i], e->ny[point_i]); @@ -2752,7 +805,7 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm result += wt[point_i] * (P_minus[i]) * v->val[point_i]; } - return - result * static_cast(wf)->get_tau(); + return - result * wf->get_current_time_step(); } Ord ord(int n, double *wt, Func *u_ext[], Func *v, @@ -2761,12 +814,17 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm return Ord(24); } - VectorFormSurf* clone() const - { - EulerEquationsVectorFormSemiImplicitInletOutlet2* form = new EulerEquationsVectorFormSemiImplicitInletOutlet2(this->i, this->areas[0], this->num_flux->kappa); + VectorFormSurf* clone() const + { + EulerEquationsVectorFormSemiImplicitInletOutlet* form = new EulerEquationsVectorFormSemiImplicitInletOutlet(this->i, this->rho_ext, this->v1_ext, this->v2_ext, this->energy_ext, this->areas, this->num_flux->kappa); form->wf = this->wf; return form; } + + double rho_ext; + double v1_ext; + double v2_ext; + double energy_ext; StegerWarmingNumericalFlux* num_flux; }; @@ -2785,16 +843,17 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return int_u_v(n, wt, ext[this->i], v); } + VectorFormVol* clone() const { return new EulerEquationsLinearFormTime(this->i); } }; class EulerEquationsMatrixFormSolidWall : public MatrixFormSurf { public: - EulerEquationsMatrixFormSolidWall(int i, int j, std::string marker, double kappa) - : MatrixFormSurf(i, j), kappa(kappa) {set_area(marker);} + EulerEquationsMatrixFormSolidWall(int i, int j, Hermes::vector markers, double kappa) + : MatrixFormSurf(i, j), kappa(kappa) {set_areas(markers);} double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { @@ -2821,44 +880,10 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm P[2][2] = (kappa - 1) * (-v_2) * e->ny[point_i]; P[2][3] = (kappa - 1) * e->ny[point_i]; - if(i == 0 && j == 0) - result += wt[point_i] * P[0][0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 1) - result += wt[point_i] * P[0][1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 2) - result += wt[point_i] * P[0][2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 0 && j == 3) - result += wt[point_i] * P[0][3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 1 && j == 0) - result += wt[point_i] * P[1][0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 1) - result += wt[point_i] * P[1][1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 2) - result += wt[point_i] * P[1][2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 1 && j == 3) - result += wt[point_i] * P[1][3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 2 && j == 0) - result += wt[point_i] * P[2][0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 1) - result += wt[point_i] * P[2][1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 2) - result += wt[point_i] * P[2][2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 2 && j == 3) - result += wt[point_i] * P[2][3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - - if(i == 3 && j == 0) - result += wt[point_i] * P[3][0] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 1) - result += wt[point_i] * P[3][1] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 2) - result += wt[point_i] * P[3][2] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); - if(i == 3 && j == 3) - result += wt[point_i] * P[3][3] * u->val[point_i] * v->val[point_i] * static_cast(wf)->get_tau(); + result += wt[point_i] * P[i][j] * u->val[point_i] * v->val[point_i]; } - return result; + return result * wf->get_current_time_step(); } Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const @@ -2866,12 +891,13 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm return Ord(24); } - MatrixFormSurf* clone() const + MatrixFormSurf* clone() const { - EulerEquationsMatrixFormSolidWall* form = new EulerEquationsMatrixFormSolidWall(this->i, this->j, this->areas[0], this->kappa); + EulerEquationsMatrixFormSolidWall* form = new EulerEquationsMatrixFormSolidWall(this->i, this->j, this->areas, this->kappa); form->wf = this->wf; return form; } + // Members. double kappa; }; @@ -2884,18 +910,22 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - double result_i = 0.; - if(static_cast(wf)->discreteIndicator[e->id]) - return int_grad_u_grad_v(n, wt, u, v) * nu_1 * e->diam; + double result = 0.; + if(static_cast(wf)->discreteIndicator[e->id]) + result = int_grad_u_grad_v(n, wt, u, v) * nu_1 * e->diam; + return result; } Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return int_grad_u_grad_v(n, wt, u, v); + } + MatrixFormVol* clone() const + { + EulerEquationsFormStabilizationVol* form = new EulerEquationsFormStabilizationVol(this->i, nu_1); + return form; } - - MatrixFormVol* clone() const { return new EulerEquationsFormStabilizationVol(this->i, this->nu_1); } private: double nu_1; }; @@ -2906,334 +936,178 @@ class EulerEquationsWeakFormSemiImplicitTwoInflows : public WeakForm EulerEquationsFormStabilizationSurf(int i, int j, double nu_2) : MatrixFormDG(i, j), nu_2(nu_2) {} - double value(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const + double value(int n, double *wt, DiscontinuousFunc *u, + DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const { double result = 0.; - if(static_cast(wf)->discreteIndicator[e->id] && static_cast(wf)->discreteIndicator[e->get_neighbor_id()]) - for (int i = 0;i < n;i++) - result += wt[i] * (u->get_val_central(i) - u->get_val_neighbor(i)) * (v->get_val_central(i) - v->get_val_neighbor(i)) * nu_2; + if(static_cast(wf)->discreteIndicator[e->id] && static_cast(wf)->discreteIndicator[e->get_neighbor_id()]) + { + if(u->val == NULL) + if(v->val == NULL) + for (int point_i = 0; point_i < n; point_i++) + result += wt[i] * (- u->val_neighbor[point_i]) * (- v->val_neighbor[point_i]); + else + for (int point_i = 0; point_i < n; point_i++) + result += wt[i] * (- u->val_neighbor[point_i]) * ( v->val[point_i]); + else + if(v->val == NULL) + for (int point_i = 0; point_i < n; point_i++) + result += wt[i] * (u->val[point_i]) * (- v->val_neighbor[point_i]); + else + for (int point_i = 0; point_i < n; point_i++) + result += wt[i] * (u->val[point_i]) * ( v->val[point_i]); + } - return result; + return result * nu_2; } - Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, Func* *ext) const + MatrixFormDG* clone() const { - return Ord(24); + EulerEquationsFormStabilizationSurf* form = new EulerEquationsFormStabilizationSurf(this->i, this->j, nu_2); + form->wf = this->wf; + return form; } - MatrixFormDG* clone() const { return new EulerEquationsFormStabilizationSurf(this->i, this->j, this->nu_2); } - double nu_2; }; - // Members. - double rho_ext1; - double v1_ext1; - double v2_ext1; - double pressure_ext1; - double energy_ext1; - - double rho_ext2; - double v1_ext2; - double v2_ext2; - double pressure_ext2; - double energy_ext2; - - double tau; - EulerFluxes* euler_fluxes; - bool* discreteIndicator; + }; -class EulerEquationsWeakFormExplicitCoupled : public EulerEquationsWeakFormExplicit +class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsWeakFormSemiImplicit { public: - // Constructor. - EulerEquationsWeakFormExplicitCoupled(double kappa, - double rho_ext, double v1_ext, double v2_ext, - double pressure_ext, std::string solid_wall_marker_bottom, std::string solid_wall_marker_top, - std::string inlet_marker, std::string outlet_marker, - Hermes::vector natural_bc_concentration_markers, - Solution* prev_density, Solution* prev_density_vel_x, - Solution* prev_density_vel_y, Solution* prev_energy, - Solution* prev_concentration, double epsilon, bool fvm_only = false) - : EulerEquationsWeakFormExplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, - solid_wall_marker_bottom, solid_wall_marker_top, inlet_marker, - outlet_marker, prev_density, prev_density_vel_x, - prev_density_vel_y, prev_energy, fvm_only, 5) + Solution* prev_temp; + double lambda, c_p, heat_flux; + + EulerEquationsWeakFormSemiImplicitCoupledWithHeat(double kappa, + double rho_ext, double v1_ext, double v2_ext, double pressure_ext, + Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, + Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, Solution* prev_temp, double lambda, double c_p, double heat_flux): EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, + prev_density_vel_x, prev_density_vel_y, prev_energy, false, 5), prev_temp(prev_temp), lambda(lambda), c_p(c_p), heat_flux(heat_flux) + { + add_matrix_form(new HeatBilinearFormTime(4, c_p, lambda)); + + add_vector_form(new HeatLinearFormTime(4, c_p)); + + //this->add_vector_form_surf(new HeatLinearSurfForm(4, inlet_markers, heat_flux, lambda)); + + this->ext.push_back(prev_temp); + } + + WeakForm* clone() const { - add_matrix_form(new EulerEquationsWeakFormExplicit::EulerEquationsBilinearFormTime(4)); + EulerEquationsWeakFormSemiImplicitCoupledWithHeat* wf; + wf = new EulerEquationsWeakFormSemiImplicitCoupledWithHeat(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->prev_temp, this->lambda, this->c_p, this->heat_flux); - add_vector_form(new VectorFormConcentrationAdvectionDiffusion(4, epsilon)); - vfvol.back()->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy, prev_concentration)); + wf->ext.clear(); - for(unsigned int i = 0;i < natural_bc_concentration_markers.size();i++) + for(unsigned int i = 0; i < this->ext.size(); i++) { - add_vector_form_surf(new VectorFormConcentrationNatural(4, natural_bc_concentration_markers[i])); - vfsurf.back()->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy, prev_concentration)); + Solution* ext = static_cast*>(this->ext[i]->clone()); + if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + ext->set_type(HERMES_SLN); + wf->ext.push_back(ext); } - EulerEquationsWeakFormExplicit::EulerEquationsLinearFormTime* vector_form_time = new EulerEquationsWeakFormExplicit::EulerEquationsLinearFormTime(4); - vector_form_time->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy, prev_concentration)); - add_vector_form(vector_form_time); - }; + wf->set_current_time_step(this->get_current_time_step()); - // Destructor. - ~EulerEquationsWeakFormExplicitCoupled() {}; -protected: + return wf; + } - class VectorFormConcentrationAdvectionDiffusion : public VectorFormVol + class HeatBilinearFormTime : public MatrixFormVol { public: - VectorFormConcentrationAdvectionDiffusion(int i, double epsilon) - : VectorFormVol(i), epsilon(epsilon) {} + HeatBilinearFormTime(int i, double c_p, double lambda) : MatrixFormVol(i, i), c_p(c_p), lambda(lambda) {} - template - Scalar vector_form(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const + double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const { - Scalar result = Scalar(0); - Real h_e = e->diam; - Real s_c = Real(0.9); - - Func* density_prev = ext[0]; - Func* density_vel_x_prev = ext[1]; - Func* density_vel_y_prev = ext[2]; - Func* concentration_prev = ext[4]; - - for (int point_i=0; point_i < n; point_i++) + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) { - Scalar v_1 = density_vel_x_prev->val[point_i] / density_prev->val[point_i]; - Scalar v_2 = density_vel_y_prev->val[point_i] / density_prev->val[point_i]; + double rho = ext[0]->val[point_i]; + result += wt[point_i] * u->val[point_i] * v->val[point_i] * rho * c_p / this->wf->get_current_time_step(); + result += wt[point_i] * (u->dx[point_i] * v->dx[point_i] + u->dy[point_i] * v->dy[point_i]) * lambda; + result += (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i] * c_p; + } + return result; + } - result += wt[point_i] * (epsilon * (concentration_prev->dx[point_i]*v->dx[point_i] + concentration_prev->dy[point_i]*v->dy[point_i]) - - (v_1 * concentration_prev->val[point_i] * v->dx[point_i] + v_2 * concentration_prev->val[point_i] * v->dy[point_i])); + Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, + Func* *ext) const + { + Ord result = Ord(0); + for (int point_i = 0; point_i < n; point_i++) + { + Ord rho = ext[0]->val[point_i]; + result += wt[point_i] * (u->val[point_i] * v->val[point_i] * rho - u->dx[point_i] * v->dx[point_i] - u->dy[point_i] * v->dy[point_i] - rho * rho * (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i]); + } + return result; + } - result += 100 * wt[point_i] * ((v_1 * concentration_prev->dx[point_i] + v_2 * concentration_prev->dy[point_i]) - (epsilon * (concentration_prev->dx[point_i]*concentration_prev->dx[point_i] + concentration_prev->dy[point_i]*concentration_prev->dy[point_i]))) - * (v_1 * v->dx[point_i] + v_2 * v->dy[point_i]) * h_e / (2 * std::sqrt(v_1*v_1 + v_2*v_2)); + MatrixFormVol* clone() const { return new HeatBilinearFormTime(*this); } - // Real R_squared = Hermes::pow(v_1 * u->dx[i] + v_2 * u->dy[i], 2.); - // Real R = Hermes::sqrt(R_squared); //This just does fabs(b1 * u->dx[i] + b2 * u->dy[i]); but it can be parsed - // result += wt[i] * s_c * 0.5 * h_e * R * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) / (Hermes::sqrt(Hermes::pow(u->dx[i], 2) + Hermes::pow(u->dy[i], 2)) + 1.e-8); + double c_p, lambda; + }; - // Scalar b_norm = Hermes::sqrt(v_1 * v_1 + v_2 * v_2); - // Real tau = 1. / Hermes::sqrt( 9 * Hermes::pow(4 * epsilon / Hermes::pow(h_e, 2), 2) + Hermes::pow(2 * b_norm / h_e, 2)); - // result += wt[i] * tau * (-v_1 * v->dx[i] - v_2 * v->dy[i] + epsilon * v->laplace[i]) * (-v_1 * u->dx[i] - v_2 * u->dy[i] + epsilon * u->laplace[i]); - } - return result * static_cast(wf)->get_tau(); - } + class HeatLinearFormTime : public VectorFormVol + { + public: + HeatLinearFormTime(int i, double c_p) + : VectorFormVol(i), c_p(c_p) {} - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const { - return vector_form(n, wt, u_ext, v, e, ext); + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) + { + double rho = ext[0]->val[point_i]; + result += wt[i] * v->val[point_i] * rho * ext[this->i]->val[point_i]; + } + return result * c_p / this->wf->get_current_time_step(); } Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return wt[0] * v->val[0] * ext[0]->val[0] * ext[this->i]->val[0]; } - VectorFormVol* clone() const - { - VectorFormConcentrationAdvectionDiffusion* form = new VectorFormConcentrationAdvectionDiffusion(this->i, this->epsilon); - form->wf = this->wf; - return form; - } + VectorFormVol* clone() const { return new HeatLinearFormTime(*this); } - // Member. - double epsilon; + double c_p; }; - class VectorFormConcentrationNatural : public VectorFormSurf + class HeatLinearSurfForm : public VectorFormSurf { public: - VectorFormConcentrationNatural(int i, std::string marker) - : VectorFormSurf(i) {set_area(marker);} - - template - Scalar vector_form(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + HeatLinearSurfForm(int i, Hermes::vector areas, double heat_flux, double lambda) + : VectorFormSurf(i), heat_flux(heat_flux), lambda(lambda) { - Func* density_prev = ext[0]; - Func* density_vel_x_prev = ext[1]; - Func* density_vel_y_prev = ext[2]; - Func* concentration_prev = ext[4]; - - Scalar result = Scalar(0); - for (int i = 0;i < n;i++) - result += wt[i] * v->val[i] * concentration_prev->val[i] - * (density_vel_x_prev->val[i] * e->nx[i] + density_vel_y_prev->val[i] * e->ny[i]) - / density_prev->val[i]; - // (OR: for inlet/outlet) result += wt[i] * v->val[i] * concentration_prev->val[i] - // * (V1_EXT * e->nx[i] + V2_EXT * e->ny[i]); - return result * static_cast(wf)->get_tau(); - + this->set_areas(areas); } - double value(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, Func* *ext) const + double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func* *ext) const { - return vector_form(n, wt, u_ext, v, e, ext); + double result = 0.; + for (int point_i = 0; point_i < n; point_i++) + result += wt[i] * v->val[point_i]; + return result * heat_flux * lambda; } Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { - return Ord(24); - } - - VectorFormSurf* clone() const - { - VectorFormConcentrationNatural* form = new VectorFormConcentrationNatural(this->i, this->areas[0]); - form->wf = this->wf; - return form; + return wt[0] * v->val[0]; } - }; -}; - -class EulerEquationsWeakFormSemiImplicitCoupled : public EulerEquationsWeakFormSemiImplicit -{ -public: -// Constructor. -EulerEquationsWeakFormSemiImplicitCoupled(double kappa, -double rho_ext, double v1_ext, double v2_ext, -double pressure_ext, std::string solid_wall_marker_bottom, std::string solid_wall_marker_top, -std::string inlet_marker, std::string outlet_marker, -Hermes::vector natural_bc_concentration_markers, -Solution* prev_density, Solution* prev_density_vel_x, -Solution* prev_density_vel_y, Solution* prev_energy, -Solution* prev_concentration, double epsilon, bool fvm_only = false) -: EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, -solid_wall_marker_bottom, solid_wall_marker_top, inlet_marker, -outlet_marker, prev_density, prev_density_vel_x, -prev_density_vel_y, prev_energy, fvm_only, 5) -{ -add_matrix_form(new EulerEquationsWeakFormSemiImplicit::EulerEquationsBilinearFormTime(4)); - -add_matrix_form(new MatrixFormConcentrationAdvectionDiffusion(4, 4, epsilon)); -mfvol.back()->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); -for(unsigned int i = 0;i < natural_bc_concentration_markers.size();i++) -{ -add_matrix_form_surf(new MatrixFormConcentrationNatural(4, 4, natural_bc_concentration_markers[i])); -mfsurf.back()->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); -} - -EulerEquationsWeakFormSemiImplicit::EulerEquationsLinearFormTime* vector_form_time = new EulerEquationsWeakFormSemiImplicit::EulerEquationsLinearFormTime(4); -vector_form_time->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy, prev_concentration)); -add_vector_form(vector_form_time); -}; - -// Destructor. -~EulerEquationsWeakFormSemiImplicitCoupled() {}; -protected: - -class MatrixFormConcentrationAdvectionDiffusion : public MatrixFormVol -{ -public: -MatrixFormConcentrationAdvectionDiffusion(int i, int j, double epsilon) -: MatrixFormVol(i, j), epsilon(epsilon) {} - -template -Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const -{ -Scalar result = Scalar(0); -Real h_e = e->diam; -Real s_c = Real(0.9); - -Func* density_prev = ext[0]; -Func* density_vel_x_prev = ext[1]; -Func* density_vel_y_prev = ext[2]; - -for (int point_i=0; point_i < n; point_i++) -{ -Scalar v_1 = density_vel_x_prev->val[point_i] / density_prev->val[point_i]; -Scalar v_2 = density_vel_y_prev->val[point_i] / density_prev->val[point_i]; - -result += wt[point_i] * (epsilon * (u->dx[point_i]*v->dx[point_i] + u->dy[point_i]*v->dy[point_i]) -- (v_1 * u->dx[point_i] * v->val[point_i] + v_2 * u->dy[point_i] * v->val[point_i])); - -//result += 1. * wt[point_i] * ((v_1 * u->dx[point_i] + v_2 * u->dy[point_i]) - (epsilon * (u->dx[point_i]*u->dx[point_i] + u->dy[point_i]*u->dy[point_i]))) -// * (v_1 * v->dx[point_i] + v_2 * v->dy[point_i]) * h_e / (2 * std::sqrt(v_1*v_1 + v_2*v_2)); - -// Real R_squared = Hermes::pow(v_1 * u->dx[i] + v_2 * u->dy[i], 2.); -// Real R = Hermes::sqrt(R_squared); //This just does fabs(b1 * u->dx[i] + b2 * u->dy[i]); but it can be parsed -// result += wt[i] * s_c * 0.5 * h_e * R * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) / (Hermes::sqrt(Hermes::pow(u->dx[i], 2) + Hermes::pow(u->dy[i], 2)) + 1.e-8); - -// Scalar b_norm = Hermes::sqrt(v_1 * v_1 + v_2 * v_2); -// Real tau = 1. / Hermes::sqrt( 9 * Hermes::pow(4 * epsilon / Hermes::pow(h_e, 2), 2) + Hermes::pow(2 * b_norm / h_e, 2)); -// result += wt[i] * tau * (-v_1 * v->dx[i] - v_2 * v->dy[i] + epsilon * v->laplace[i]) * (-v_1 * u->dx[i] - v_2 * u->dy[i] + epsilon * u->laplace[i]); -} -return result * static_cast(wf)->get_tau(); -} + VectorFormSurf* clone() const { return new HeatLinearSurfForm(*this); } -double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, -Geom *e, Func* *ext) const -{ -return matrix_form(n, wt, u_ext, u, v, e, ext); -} - -Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, -Func* *ext) const -{ -return Ord(24); -} - -MatrixFormVol* clone() const -{ -MatrixFormConcentrationAdvectionDiffusion* form = new MatrixFormConcentrationAdvectionDiffusion(this->i, this->j, this->epsilon); -form->wf = this->wf; -return form; -} - -// Member. -double epsilon; -}; - -class MatrixFormConcentrationNatural : public MatrixFormSurf -{ -public: -MatrixFormConcentrationNatural(int i, int j, std::string marker) -: MatrixFormSurf(i, j) {set_area(marker);} - -template -Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, -Geom *e, Func* *ext) const -{ -Func* density_prev = ext[0]; -Func* density_vel_x_prev = ext[1]; -Func* density_vel_y_prev = ext[2]; - -return Scalar(0.0); -Scalar result = Scalar(0); -for (int point_i = 0; point_i < n; point_i++) -result += wt[i] * v->val[i] * u->val[i] * (density_vel_x_prev->val[i] * e->nx[i] + density_vel_y_prev->val[i] * e->ny[i]) -/ density_prev->val[i]; -return result * static_cast(wf)->get_tau(); -} - -double value(int n, double *wt, Func *u_ext[], Func *u, Func *v, -Geom *e, Func* *ext) const -{ -return matrix_form(n, wt, u_ext, u, v, e, ext); -} - -Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, -Func* *ext) const -{ -return Ord(24); -} - -MatrixFormSurf* clone() const -{ -MatrixFormConcentrationNatural* form = new MatrixFormConcentrationNatural(this->i, this->j, this->areas[0]); -form->wf = this->wf; -return form; -} -}; -}; - -*/ \ No newline at end of file + double heat_flux, lambda; + }; +}; \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt b/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt new file mode 100644 index 0000000..40ae1a3 --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt @@ -0,0 +1,4 @@ +project(heating-flow-coupling-adapt) + +add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp) +set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp new file mode 100644 index 0000000..d4552c9 --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -0,0 +1,244 @@ +#define HERMES_REPORT_INFO +#define HERMES_REPORT_FILE "application.log" +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::RefinementSelectors; +using namespace Hermes::Hermes2D::Views; + +// Visualization. +// Set to "true" to enable Hermes OpenGL visualization. +const bool HERMES_VISUALIZATION = false; +// Set to "true" to enable VTK output. +const bool VTK_VISUALIZATION = false; +// Set visual output for every nth step. +const unsigned int EVERY_NTH_STEP = 1; + + +// Initial polynomial degree. +const int P_INIT_FLOW = 1; +const int P_INIT_HEAT = 1; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 2; + +// Shock capturing. +enum shockCapturingType +{ + KUZMIN, + KRIVODONOVA +}; +bool SHOCK_CAPTURING = true; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +// Quantitative parameter of the discontinuity detector in case of Krivodonova. +double DISCONTINUITY_DETECTOR_PARAM = 1.0; + +// Equation parameters. +// Exterior pressure (dimensionless). +const double P_EXT = 1.5; +// Initial pressure (dimensionless). +const double P_INITIAL_HIGH = 1.5; +// Initial pressure (dimensionless). +const double P_INITIAL_LOW = 1.0; +// Inlet density (dimensionless). +const double RHO_EXT = 1.0; +// Initial density (dimensionless). +const double RHO_INITIAL_HIGH = 1.0; +// Initial density (dimensionless). +const double RHO_INITIAL_LOW = 0.66; +// Inlet x-velocity (dimensionless). +const double V1_EXT = 0.0; +// Inlet y-velocity (dimensionless). +const double V2_EXT = 0.0; +// Kappa. +const double KAPPA = 1.4; +// Lambda. +const double LAMBDA = 1e3; +// heat_capacity. +const double C_P = 1e2; +// heat flux through the inlet. +const double HEAT_FLUX = 1e-3; + +// CFL value. +const double CFL_NUMBER = 0.1; +// Initial time step. +double time_step = 1E-5; +// Stability for the concentration part. +double ADVECTION_STABILITY_CONSTANT = 1e16; +const double DIFFUSION_STABILITY_CONSTANT = 1e16; + +// Boundary markers. +const std::string BDY_INLET = "Inlet"; +const std::string BDY_SOLID_WALL = "Solid"; + +// Area (square) size. +// Must be in accordance with the mesh file. +const double MESH_SIZE = 3.0; + +// Weak forms. +#include "../forms_explicit.cpp" + +// Initial condition. +#include "../initial_condition.cpp" + +int main(int argc, char* argv[]) +{ + Hermes2DApi.set_integral_param_value(numThreads, 1); + + // Load the mesh. + Mesh mesh, mesh_heat; + MeshReaderH2D mloader; + mloader.load("square.mesh", &mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh.refine_all_elements(0, true); + + mesh_heat.copy(&mesh); + mesh_heat.refine_towards_boundary("Inlet", 3, false); + mesh.refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); + Hermes2D::DefaultEssentialBCConst bc_temp_nonzero("Inlet", 1.0); + Hermes::vector*> bc_vector(&bc_temp_zero, &bc_temp_nonzero); + EssentialBCs bcs(bc_vector); + + L2Space space_rho(&mesh, P_INIT_FLOW); + L2Space space_rho_v_x(&mesh, P_INIT_FLOW); + L2Space space_rho_v_y(&mesh, P_INIT_FLOW); + L2Space space_e(&mesh, P_INIT_FLOW); + H1Space space_temp(&mesh_heat, &bcs, P_INIT_HEAT); + int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + + // Initialize solutions, set initial conditions. + InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); + ConstantSolution prev_rho_v_x(&mesh, 0.0); + ConstantSolution prev_rho_v_y(&mesh, 0.0); + InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + ConstantSolution prev_temp(&mesh_heat, 0.0); + + // Filters for visualization of Mach number, pressure and entropy. + PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); + VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); + VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); + ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); + ScalarView temperature_view("Temperature", new WinGeom(900, 700, 800, 600)); + + // Set up the solver, matrix, and rhs according to the solver selection. + SparseMatrix* matrix = create_matrix(); + Vector* rhs = create_vector(); + Vector* rhs_stabilization = create_vector(); + LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + + // Set up stability calculation class. + CFLCalculation CFL(CFL_NUMBER, KAPPA); + ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, LAMBDA); + + // Look for a saved solution on the disk. + int iteration = 0; double t = 0; + + // Initialize weak formulation. + Hermes::vector solid_wall_markers; + solid_wall_markers.push_back(BDY_SOLID_WALL); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + + EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, + inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp, LAMBDA, C_P, HEAT_FLUX); + + // Initialize the FE problem. + DiscreteProblemLinear dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); + + // Time stepping loop. + for(; t < 10.0; t += time_step) + { + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + + // Set the current time step. + wf.set_current_time_step(time_step); + + // Assemble the stiffness matrix and rhs. + Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); + dp.assemble(matrix, rhs); + + // Solve the matrix problem. + Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); + if(solver->solve()) + { + if(!SHOCK_CAPTURING) + { + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e, &space_temp), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp)); + } + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e), true); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e)); + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(); + + flux_limiter->limit_according_to_detector(); + + flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, + &space_rho_v_y, &space_e)), &space_temp, &prev_temp); + } + } + else + throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); + + CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + + double util_time_step = time_step; + + ADES.calculate(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y), &mesh, util_time_step); + + if(util_time_step < time_step) + time_step = util_time_step; + + // Visualization. + if((iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + pressure.reinit(); + vel_x.reinit(); + vel_y.reinit(); + pressure_view.show(&pressure); + velocity_view.show(&vel_x, &vel_y); + density_view.show(&prev_rho); + temperature_view.show(&prev_temp, HERMES_EPS_HIGH); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure.reinit(); + Linearizer lin_pressure; + char filename[40]; + sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); + lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + } + } + } + + pressure_view.close(); + velocity_view.close(); + density_view.close(); + temperature_view.close(); + + return 0; +} diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/square.mesh b/2d-advanced/euler/heating-flow-coupling-adapt/square.mesh new file mode 100644 index 0000000..28edcc3 --- /dev/null +++ b/2d-advanced/euler/heating-flow-coupling-adapt/square.mesh @@ -0,0 +1,29 @@ +# Everything is in meters: + +vertices = [ + [ 0, 0 ], + [ 1, 0 ], + [ 2, 0 ], + [ 3, 0 ], + [ 3, 3 ], + [ 2, 3 ], + [ 1, 3 ], + [ 0, 3 ] +] + +elements = [ + [ 0, 1, 6, 7, 0 ], + [ 1, 2, 5, 6, 0 ], + [ 2, 3, 4, 5, 0 ] +] + +boundaries = [ + [ 0, 1, "Solid" ], + [ 1, 2, "Solid" ], + [ 2, 3, "Inlet" ], + [ 3, 4, "Solid" ], + [ 4, 5, "Solid" ], + [ 5, 6, "Solid" ], + [ 6, 7, "Solid" ], + [ 7, 0, "Solid" ] +] \ No newline at end of file diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index c22de62..ce022a2 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -4,21 +4,9 @@ using namespace Hermes; using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::RefinementSelectors; using namespace Hermes::Hermes2D::Views; -// This example solves the compressible Euler equations using a basic -// piecewise-constant finite volume method, or Discontinuous Galerkin method of higher order with no adaptivity. -// -// Equations: Compressible Euler equations, perfect gas state equation. -// -// Domain: A square, see file square.mesh. -// -// BC: Solid walls, inlet, no outlet. -// -// IC: Constant state identical to inlet, only with higher pressure. -// -// The following parameters can be changed: - // Visualization. // Set to "true" to enable Hermes OpenGL visualization. const bool HERMES_VISUALIZATION = true; @@ -27,55 +15,47 @@ const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; + +// Initial polynomial degree. +const int P_INIT_FLOW = 0; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 2; + // Shock capturing. enum shockCapturingType { - FEISTAUER, KUZMIN, KRIVODONOVA }; bool SHOCK_CAPTURING = false; -shockCapturingType SHOCK_CAPTURING_TYPE = FEISTAUER; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; -// Quantitative parameter of the shock capturing in case of Feistauer. -const double NU_1 = 0.1; -const double NU_2 = 0.1; - -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - -// Initial polynomial degree. -const int P_INIT = 0; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 3; -// CFL value. -double CFL_NUMBER = 0.5; -// Initial time step. -double time_step = 1E-4; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -const MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Equation parameters. // Exterior pressure (dimensionless). -const double P_EXT = 2.0; +const double P_EXT = 10.5; // Initial pressure (dimensionless). -const double P_INITIAL_HIGH = 1.5; +const double P_INITIAL_HIGH = 10.5; // Initial pressure (dimensionless). const double P_INITIAL_LOW = 1.0; // Inlet density (dimensionless). -const double RHO_EXT = 1.0; +const double RHO_EXT = 0.5; // Initial density (dimensionless). const double RHO_INITIAL_HIGH = 0.5; // Initial density (dimensionless). -const double RHO_INITIAL_LOW = 0.3; +const double RHO_INITIAL_LOW = 0.3; // Inlet x-velocity (dimensionless). const double V1_EXT = 0.0; // Inlet y-velocity (dimensionless). const double V2_EXT = 0.0; // Kappa. -const double KAPPA = 1.4; +const double KAPPA = 1.4; + +// CFL value. +const double CFL_NUMBER = 0.1; +// Initial time step. +double time_step = 1E-5; // Boundary markers. const std::string BDY_INLET = "Inlet"; @@ -94,20 +74,18 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + Mesh mesh, mesh_heat; MeshReaderH2D mloader; mloader.load("square.mesh", &mesh); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) + for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(0, true); - // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - L2Space space_stabilization(&mesh, 0); + L2Space space_rho(&mesh, P_INIT_FLOW); + L2Space space_rho_v_x(&mesh, P_INIT_FLOW); + L2Space space_rho_v_y(&mesh, P_INIT_FLOW); + L2Space space_e(&mesh, P_INIT_FLOW); int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -118,18 +96,13 @@ int main(int argc, char* argv[]) InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_INITIAL_HIGH, P_INITIAL_HIGH); + VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); + VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); - VectorView velocity_view("Velocity", new WinGeom(700, 400, 600, 300)); - ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); - ScalarView s2("prev_rho_v_x", new WinGeom(700, 0, 600, 300)); - ScalarView s3("prev_rho_v_y", new WinGeom(0, 400, 600, 300)); - ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); + VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); + ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(); @@ -137,28 +110,12 @@ int main(int argc, char* argv[]) Vector* rhs_stabilization = create_vector(); LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - // Set up CFL calculation class. + // Set up stability calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); int iteration = 0; double t = 0; - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - } - // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); @@ -166,44 +123,17 @@ int main(int argc, char* argv[]) inlet_markers.push_back(BDY_INLET); Hermes::vector outlet_markers; - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, (P_INIT == 0)); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, + inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); - EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); - - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); - // Initialize the FE problem. DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); - DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); - - // If the FE problem is in fact a FV problem. - if(P_INIT == 0) - dp.set_fvm(); // Time stepping loop. for(; t < 10.0; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - { - assert(space_stabilization.get_num_dofs() == space_stabilization.get_mesh()->get_num_active_elements()); - dp_stabilization.assemble(rhs_stabilization); - bool* discreteIndicator = new bool[space_stabilization.get_num_dofs()]; - memset(discreteIndicator, 0, space_stabilization.get_num_dofs() * sizeof(bool)); - Element* e; - for_all_active_elements(e, space_stabilization.get_mesh()) - { - AsmList al; - space_stabilization.get_element_assembly_list(e, &al); - if(rhs_stabilization->get(al.get_dof()[0]) >= 1) - discreteIndicator[e->id] = true; - } - wf.set_discreteIndicator(discreteIndicator, space_stabilization.get_num_dofs()); - } - // Set the current time step. wf.set_current_time_step(time_step); @@ -215,7 +145,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); if(solver->solve()) { - if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) + if(!SHOCK_CAPTURING) { Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); @@ -225,7 +155,7 @@ int main(int argc, char* argv[]) FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + &space_rho_v_y, &space_e), true); else flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); @@ -249,34 +179,28 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); pressure.reinit(); - entropy.reinit(); + vel_x.reinit(); + vel_y.reinit(); pressure_view.show(&pressure); - entropy_production_view.show(&entropy); - Mach_number_view.show(&Mach_number); - pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + velocity_view.show(&vel_x, &vel_y); + density_view.show(&prev_rho); } // Output solution in VTK format. if(VTK_VISUALIZATION) { pressure.reinit(); - Mach_number.reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); - Linearizer lin_mach; - sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); } } } pressure_view.close(); - entropy_production_view.close(); - Mach_number_view.close(); - + velocity_view.close(); + density_view.close(); + return 0; } From 5f3efda3e00341ff4ab0d47f599eec5382f38b78 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 6 Mar 2013 07:20:40 +0100 Subject: [PATCH 04/64] Add missing file. --- cmake/cxx_flag_overrides.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 cmake/cxx_flag_overrides.cmake diff --git a/cmake/cxx_flag_overrides.cmake b/cmake/cxx_flag_overrides.cmake new file mode 100644 index 0000000..3164378 --- /dev/null +++ b/cmake/cxx_flag_overrides.cmake @@ -0,0 +1,13 @@ +# This overrides CXX flags for MSVC +if(MSVC) + set(MSVC_DEFINES "/DWIN32 /D_WINDOWS /Dpopen=_popen /Dpclose=_pclose /D__value=_value /Dfinite=_finite /Dhypot=_hypot /Disatty=_isatty /Dfileno=_fileno /D_CRT_SECURE_NO_WARNINGS /DYY_NO_UNISTD_H /D_USE_MATH_DEFINES /DIMPLEMENT_C99 /wd4275 /wd4251 /wd4661 /wd4018 /wd4244 /wd4273") + set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /Od /Ob2 /MDd /Zi /RTC1 ${MSVC_DEFINES}") + set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O2 /Ob2 /MD ${MSVC_DEFINES}") + set(CMAKE_CXX_FLAGS_RELEASE_INIT "/DNDEBUG /O2 /Ob2 /MD ${MSVC_DEFINES}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/DNDEBUG /O2 /Ob2 /MD /Zi ${MSVC_DEFINES}") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") +else(MSVC) + set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT} -D_DEBUG") +endif(MSVC) + From 7c9cdfe624cb2b6454d85e2f45ff2978ec5ee74f Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 13 Mar 2013 21:40:15 +0100 Subject: [PATCH 05/64] Work on Euler for shared_ptrs. --- 2d-advanced/euler/CMakeLists.txt | 8 +- .../euler/euler-coupled-adapt/main.cpp | 25 -- 2d-advanced/euler/euler_util.cpp | 150 ++++----- 2d-advanced/euler/euler_util.h | 55 ++-- 2d-advanced/euler/forms_explicit.cpp | 47 ++- 2d-advanced/euler/forward-step-adapt/main.cpp | 214 +++++------- 2d-advanced/euler/forward-step/main.cpp | 112 +++---- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 226 +++++-------- 2d-advanced/euler/gamm-channel/main.cpp | 154 +++------ .../heating-flow-coupling-adapt/main.cpp | 311 +++++++++++++----- .../euler/heating-flow-coupling/main.cpp | 199 +++++------ .../heating-induced-vortex-adapt/main.cpp | 183 +++++------ .../euler/heating-induced-vortex/main.cpp | 66 ++-- 2d-advanced/euler/initial_condition.cpp | 2 +- .../euler/joukowski-profile-adapt/main.cpp | 28 -- .../euler/reflected-shock-adapt/main.cpp | 216 +++++------- 2d-advanced/euler/reflected-shock/main.cpp | 103 +++--- 17 files changed, 935 insertions(+), 1164 deletions(-) diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index 9e044a5..e15d70e 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -1,11 +1,11 @@ add_subdirectory(forward-step) -#add_subdirectory(forward-step-adapt) +add_subdirectory(forward-step-adapt) add_subdirectory(reflected-shock) -#add_subdirectory(reflected-shock-adapt) +add_subdirectory(reflected-shock-adapt) add_subdirectory(gamm-channel) -#add_subdirectory(gamm-channel-adapt) +add_subdirectory(gamm-channel-adapt) add_subdirectory(heating-induced-vortex) -#add_subdirectory(heating-induced-vortex-adapt) +add_subdirectory(heating-induced-vortex-adapt) #add_subdirectory(joukowski-profile) #add_subdirectory(joukowski-profile-adapt) diff --git a/2d-advanced/euler/euler-coupled-adapt/main.cpp b/2d-advanced/euler/euler-coupled-adapt/main.cpp index 3c0ed19..fe0831b 100644 --- a/2d-advanced/euler/euler-coupled-adapt/main.cpp +++ b/2d-advanced/euler/euler-coupled-adapt/main.cpp @@ -339,20 +339,6 @@ int main(int argc, char* argv[]) ogProjection.project_global(ref_space_stabilization, &prev_rho, &prev_rho_stabilization); - if(as > 1) - { - delete rsln_rho.get_mesh(); - - delete rsln_rho_v_x.get_mesh(); - - delete rsln_rho_v_y.get_mesh(); - - delete rsln_e.get_mesh(); - - delete rsln_c.get_mesh(); - - } - // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, @@ -541,17 +527,6 @@ int main(int argc, char* argv[]) prev_e.copy(&rsln_e); prev_c.copy(&rsln_c); - delete rsln_rho.get_mesh(); - - delete rsln_rho_v_x.get_mesh(); - - delete rsln_rho_v_y.get_mesh(); - - delete rsln_e.get_mesh(); - - delete rsln_c.get_mesh(); - - // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) { diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index 5c589bc..def3fdd 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -33,18 +33,18 @@ CFLCalculation::CFLCalculation(double CFL_number, double kappa) : CFL_number(CFL { } -void CFLCalculation::calculate(Hermes::vector*> solutions, Mesh* mesh, double & time_step) const +void CFLCalculation::calculate(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const { // Create spaces of constant functions over the given mesh. - L2Space constant_rho_space(mesh, 0); - L2Space constant_rho_v_x_space(mesh, 0); - L2Space constant_rho_v_y_space(mesh, 0); - L2Space constant_energy_space(mesh, 0); + SpaceSharedPtr constant_rho_space(new L2Space (mesh, 0)); + SpaceSharedPtr constant_rho_v_x_space(new L2Space (mesh, 0)); + SpaceSharedPtr constant_rho_v_y_space(new L2Space (mesh, 0)); + SpaceSharedPtr constant_energy_space(new L2Space (mesh, 0)); - double* sln_vector = new double[constant_rho_space.get_num_dofs() * 4]; + double* sln_vector = new double[constant_rho_space->get_num_dofs() * 4]; OGProjection ogProjection; - ogProjection.project_global(Hermes::vector*>(&constant_rho_space, &constant_rho_v_x_space, &constant_rho_v_y_space, &constant_energy_space), solutions, sln_vector); + ogProjection.project_global(Hermes::vector >(constant_rho_space, constant_rho_v_x_space, constant_rho_v_y_space, constant_energy_space), solutions, sln_vector); // Determine the time step according to the CFL condition. @@ -53,13 +53,13 @@ void CFLCalculation::calculate(Hermes::vector*> solutions, Mesh for_all_active_elements(e, mesh) { AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); + constant_rho_space->get_element_assembly_list(e, &al); double rho = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); + constant_rho_v_x_space->get_element_assembly_list(e, &al); double v1 = sln_vector[al.get_dof()[0]] / rho; - constant_rho_v_y_space.get_element_assembly_list(e, &al); + constant_rho_v_y_space->get_element_assembly_list(e, &al); double v2 = sln_vector[al.get_dof()[0]] / rho; - constant_energy_space.get_element_assembly_list(e, &al); + constant_energy_space->get_element_assembly_list(e, &al); double energy = sln_vector[al.get_dof()[0]]; double condition = e->get_area() * CFL_number / (std::sqrt(v1*v1 + v2*v2) + QuantityCalculator::calc_sound_speed(rho, rho*v1, rho*v2, energy, kappa)); @@ -73,18 +73,18 @@ void CFLCalculation::calculate(Hermes::vector*> solutions, Mesh delete [] sln_vector; } -void CFLCalculation::calculate_semi_implicit(Hermes::vector*> solutions, Mesh* mesh, double & time_step) const +void CFLCalculation::calculate_semi_implicit(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const { // Create spaces of constant functions over the given mesh. - L2Space constant_rho_space(mesh, 0); - L2Space constant_rho_v_x_space(mesh, 0); - L2Space constant_rho_v_y_space(mesh, 0); - L2Space constant_energy_space(mesh, 0); + SpaceSharedPtr constant_rho_space(new L2Space(mesh, 0)); + SpaceSharedPtr constant_rho_v_x_space(new L2Space(mesh, 0)); + SpaceSharedPtr constant_rho_v_y_space(new L2Space(mesh, 0)); + SpaceSharedPtr constant_energy_space(new L2Space(mesh, 0)); - double* sln_vector = new double[constant_rho_space.get_num_dofs() * 4]; + double* sln_vector = new double[constant_rho_space->get_num_dofs() * 4]; OGProjection ogProjection; - ogProjection.project_global(Hermes::vector*>(&constant_rho_space, &constant_rho_v_x_space, &constant_rho_v_y_space, &constant_energy_space), solutions, sln_vector); + ogProjection.project_global(Hermes::vector >(constant_rho_space, constant_rho_v_x_space, constant_rho_v_y_space, constant_energy_space), solutions, sln_vector); // Determine the time step according to the CFL condition. @@ -94,13 +94,13 @@ void CFLCalculation::calculate_semi_implicit(Hermes::vector*> s for_all_active_elements(e, mesh) { AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); + constant_rho_space->get_element_assembly_list(e, &al); w[0] = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); + constant_rho_v_x_space->get_element_assembly_list(e, &al); w[1] = sln_vector[al.get_dof()[0]]; - constant_rho_v_y_space.get_element_assembly_list(e, &al); + constant_rho_v_y_space->get_element_assembly_list(e, &al); w[2] = sln_vector[al.get_dof()[0]]; - constant_energy_space.get_element_assembly_list(e, &al); + constant_energy_space->get_element_assembly_list(e, &al); w[3] = sln_vector[al.get_dof()[0]]; double edge_length_max_lambda = 0.0; @@ -170,17 +170,17 @@ ADEStabilityCalculation::ADEStabilityCalculation(double AdvectionRelativeConstan { } -void ADEStabilityCalculation::calculate(Hermes::vector*> solutions, Mesh* mesh, double & time_step) +void ADEStabilityCalculation::calculate(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) { // Create spaces of constant functions over the given mesh. - L2Space constant_rho_space(mesh, 0); - L2Space constant_rho_v_x_space(mesh, 0); - L2Space constant_rho_v_y_space(mesh, 0); + SpaceSharedPtr constant_rho_space(new L2Space(mesh, 0)); + SpaceSharedPtr constant_rho_v_x_space(new L2Space(mesh, 0)); + SpaceSharedPtr constant_rho_v_y_space(new L2Space(mesh, 0)); - double* sln_vector = new double[constant_rho_space.get_num_dofs() * 3]; + double* sln_vector = new double[constant_rho_space->get_num_dofs() * 3]; OGProjection ogProjection; - ogProjection.project_global(Hermes::vector*>(&constant_rho_space, &constant_rho_v_x_space, &constant_rho_v_y_space), solutions, sln_vector); + ogProjection.project_global(Hermes::vector >(constant_rho_space, constant_rho_v_x_space, constant_rho_v_y_space), solutions, sln_vector); // Determine the time step according to the conditions. double min_condition_advection = 0.; @@ -189,12 +189,12 @@ void ADEStabilityCalculation::calculate(Hermes::vector*> soluti for_all_active_elements(e, mesh) { AsmList al; - constant_rho_space.get_element_assembly_list(e, &al); + constant_rho_space->get_element_assembly_list(e, &al); double rho = sln_vector[al.get_dof()[0]]; - constant_rho_v_x_space.get_element_assembly_list(e, &al); - double v1 = sln_vector[al.get_dof()[0] + constant_rho_space.get_num_dofs()] / rho; - constant_rho_v_y_space.get_element_assembly_list(e, &al); - double v2 = sln_vector[al.get_dof()[0] + 2 * constant_rho_space.get_num_dofs()] / rho; + constant_rho_v_x_space->get_element_assembly_list(e, &al); + double v1 = sln_vector[al.get_dof()[0] + constant_rho_space->get_num_dofs()] / rho; + constant_rho_v_y_space->get_element_assembly_list(e, &al); + double v2 = sln_vector[al.get_dof()[0] + 2 * constant_rho_space->get_num_dofs()] / rho; double condition_advection = AdvectionRelativeConstant * e->get_diameter() / std::sqrt(v1*v1 + v2*v2); double condition_diffusion = DiffusionRelativeConstant * e->get_area() / epsilon; @@ -211,22 +211,24 @@ void ADEStabilityCalculation::calculate(Hermes::vector*> soluti delete [] sln_vector; } -DiscontinuityDetector::DiscontinuityDetector(Hermes::vector*> spaces, - Hermes::vector*> solutions) : spaces(spaces), solutions(solutions) +DiscontinuityDetector::DiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions) : spaces(spaces), solutions(solutions) { + for(int i = 0; i < solutions.size(); i++) + this->solutionsInternal.push_back((Solution*)solutions[i].get()); }; DiscontinuityDetector::~DiscontinuityDetector() {}; -KrivodonovaDiscontinuityDetector::KrivodonovaDiscontinuityDetector(Hermes::vector*> spaces, - Hermes::vector*> solutions) : DiscontinuityDetector(spaces, solutions) +KrivodonovaDiscontinuityDetector::KrivodonovaDiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions) : DiscontinuityDetector(spaces, solutions) { // A check that all meshes are the same in the spaces. unsigned int mesh0_seq = spaces[0]->get_mesh()->get_seq(); for(unsigned int i = 0; i < spaces.size(); i++) if(spaces[i]->get_mesh()->get_seq() != mesh0_seq) - throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh."); + throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh->"); mesh = spaces[0]->get_mesh(); }; @@ -309,8 +311,8 @@ double KrivodonovaDiscontinuityDetector::calculate_relative_flow_direction(Eleme jwt[i] = pt[i][2] * tan[i][2]; // Calculate. - Func* density_vel_x = init_fn(solutions[1], eo); - Func* density_vel_y = init_fn(solutions[2], eo); + Func* density_vel_x = init_fn(solutions[1].get(), eo); + Func* density_vel_y = init_fn(solutions[2].get(), eo); double result = 0.0; for(int point_i = 0; point_i < np; point_i++) @@ -373,10 +375,10 @@ void KrivodonovaDiscontinuityDetector::calculate_jumps(Element* e, int edge_i, d jwt[i] = pt[i][2] * tan[i][2]; // Prepare functions on the central element. - Func* density = init_fn(solutions[0], eo); - Func* density_vel_x = init_fn(solutions[1], eo); - Func* density_vel_y = init_fn(solutions[2], eo); - Func* energy = init_fn(solutions[3], eo); + Func* density = init_fn(solutions[0].get(), eo); + Func* density_vel_x = init_fn(solutions[1].get(), eo); + Func* density_vel_y = init_fn(solutions[2].get(), eo); + Func* energy = init_fn(solutions[3].get(), eo); // Set neighbor element to the solutions. solutions[0]->set_active_element(ns.get_neighb_el()); @@ -393,10 +395,10 @@ void KrivodonovaDiscontinuityDetector::calculate_jumps(Element* e, int edge_i, d } // Prepare functions on the neighbor element. - Func* density_neighbor = init_fn(solutions[0], eo); - Func* density_vel_x_neighbor = init_fn(solutions[1], eo); - Func* density_vel_y_neighbor = init_fn(solutions[2], eo); - Func* energy_neighbor = init_fn(solutions[3], eo); + Func* density_neighbor = init_fn(solutions[0].get(), eo); + Func* density_vel_x_neighbor = init_fn(solutions[1].get(), eo); + Func* density_vel_y_neighbor = init_fn(solutions[2].get(), eo); + Func* energy_neighbor = init_fn(solutions[3].get(), eo); DiscontinuousFunc density_discontinuous(density, density_neighbor, true); DiscontinuousFunc density_vel_x_discontinuous(density_vel_x, density_vel_x_neighbor, true); @@ -468,10 +470,10 @@ void KrivodonovaDiscontinuityDetector::calculate_norms(Element* e, int edge_i, d jwt[i] = pt[i][2] * tan[i][2]; // Calculate. - Func* density = init_fn(solutions[0], eo); - Func* density_vel_x = init_fn(solutions[1], eo); - Func* density_vel_y = init_fn(solutions[2], eo); - Func* energy = init_fn(solutions[3], eo); + Func* density = init_fn(solutions[0].get(), eo); + Func* density_vel_x = init_fn(solutions[1].get(), eo); + Func* density_vel_y = init_fn(solutions[2].get(), eo); + Func* energy = init_fn(solutions[3].get(), eo); for(int point_i = 0; point_i < np; point_i++) { result[0] = std::max(result[0], std::abs(density->val[point_i])); @@ -495,14 +497,14 @@ void KrivodonovaDiscontinuityDetector::calculate_norms(Element* e, int edge_i, d delete energy; }; -KuzminDiscontinuityDetector::KuzminDiscontinuityDetector(Hermes::vector*> spaces, - Hermes::vector*> solutions, bool limit_all_orders_independently) : DiscontinuityDetector(spaces, solutions), limit_all_orders_independently(limit_all_orders_independently) +KuzminDiscontinuityDetector::KuzminDiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions, bool limit_all_orders_independently) : DiscontinuityDetector(spaces, solutions), limit_all_orders_independently(limit_all_orders_independently) { // A check that all meshes are the same in the spaces. unsigned int mesh0_seq = spaces[0]->get_mesh()->get_seq(); for(unsigned int i = 0; i < spaces.size(); i++) if(spaces[i]->get_mesh()->get_seq() != mesh0_seq) - throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh."); + throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh->"); mesh = spaces[0]->get_mesh(); }; @@ -634,7 +636,7 @@ std::set& KuzminDiscontinuityDetector::get_second_order_discontinuous_eleme double*** values = new double**[this->solutions.size()]; for(int i = 0; i < this->solutions.size(); i++) - values[i] = solutions[i]->get_ref_values_transformed(e, c_x, c_y); + values[i] = solutionsInternal[i]->get_ref_values_transformed(e, c_x, c_y); // Vertex values. double u_d_i[4][4][2]; @@ -678,15 +680,15 @@ bool KuzminDiscontinuityDetector::get_limit_all_orders_independently() void KuzminDiscontinuityDetector::find_centroid_values(Hermes::Hermes2D::Element* e, double u_c[4], double x_ref, double y_ref) { for(unsigned int i = 0; i < this->solutions.size(); i++) - u_c[i] = solutions[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 0); + u_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 0); } void KuzminDiscontinuityDetector::find_centroid_derivatives(Hermes::Hermes2D::Element* e, double u_dx_c[4], double u_dy_c[4], double x_ref, double y_ref) { for(unsigned int i = 0; i < this->solutions.size(); i++) { - u_dx_c[i] = solutions[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 1); - u_dy_c[i] = solutions[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 2); + u_dx_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 1); + u_dy_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, x_ref, y_ref, 0, 2); } } @@ -709,9 +711,9 @@ void KuzminDiscontinuityDetector::find_second_centroid_derivatives(Hermes::Herme { solutions[i]->set_active_element(e); solutions[i]->get_refmap()->untransform(e, c_x, c_y, c_ref_x, c_ref_y); - u_dxx_c[i] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 3); - u_dyy_c[i] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 4); - u_dxy_c[i] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 5); + u_dxx_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 3); + u_dyy_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 4); + u_dxy_c[i] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 5); } } @@ -724,7 +726,7 @@ void KuzminDiscontinuityDetector::find_vertex_values(Hermes::Hermes2D::Element* { solutions[i]->get_refmap()->set_active_element(e); solutions[i]->get_refmap()->untransform(e, e->vn[j]->x, e->vn[j]->y, c_ref_x, c_ref_y); - vertex_values[i][j] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 0); + vertex_values[i][j] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 0); } } } @@ -738,8 +740,8 @@ void KuzminDiscontinuityDetector::find_vertex_derivatives(Hermes::Hermes2D::Elem { solutions[i]->get_refmap()->set_active_element(e); solutions[i]->get_refmap()->untransform(e, e->vn[j]->x, e->vn[j]->y, c_ref_x, c_ref_y); - vertex_derivatives[i][j][0] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 1); - vertex_derivatives[i][j][1] = solutions[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 2); + vertex_derivatives[i][j][0] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 1); + vertex_derivatives[i][j][1] = solutionsInternal[i]->get_ref_value_transformed(e, c_ref_x, c_ref_y, 0, 2); } } } @@ -1030,7 +1032,7 @@ void KuzminDiscontinuityDetector::find_alpha_i_second_order_real(Hermes::Hermes2 } -FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, double* solution_vector, Hermes::vector*> spaces, bool Kuzmin_limit_all_orders_independently) : solution_vector(solution_vector), spaces(spaces), limitOscillations(false) +FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, double* solution_vector, Hermes::vector > spaces, bool Kuzmin_limit_all_orders_independently) : solution_vector(solution_vector), spaces(spaces), limitOscillations(false) { for(unsigned int sol_i = 0; sol_i < spaces.size(); sol_i++) limited_solutions.push_back(new Hermes::Hermes2D::Solution(spaces[sol_i]->get_mesh())); @@ -1047,7 +1049,7 @@ FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, double* solution_vector } }; -FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, Hermes::vector*> solutions, Hermes::vector*> spaces, bool Kuzmin_limit_all_orders_independently) : spaces(spaces), limitOscillations(false) +FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, Hermes::vector > solutions, Hermes::vector > spaces, bool Kuzmin_limit_all_orders_independently) : spaces(spaces), limitOscillations(false) { for(unsigned int sol_i = 0; sol_i < spaces.size(); sol_i++) limited_solutions.push_back(new Hermes::Hermes2D::Solution(spaces[sol_i]->get_mesh())); @@ -1071,18 +1073,16 @@ FluxLimiter::FluxLimiter(FluxLimiter::LimitingType type, Hermes::vector*> solutions_to_limit) +void FluxLimiter::get_limited_solutions(Hermes::vector > solutions_to_limit) { for(unsigned int i = 0; i < solutions_to_limit.size(); i++) solutions_to_limit[i]->copy(this->limited_solutions[i]); } -int FluxLimiter::limit_according_to_detector(Hermes::vector *> coarse_spaces_to_limit) +int FluxLimiter::limit_according_to_detector(Hermes::vector > coarse_spaces_to_limit) { std::set discontinuous_elements = this->detector->get_discontinuous_element_ids(); std::set > oscillatory_element_idsRho = this->detector->get_oscillatory_element_idsRho(); @@ -1165,7 +1165,7 @@ int FluxLimiter::limit_according_to_detector(Hermes::vector *> coa // Now adjust the solutions. Solution::vector_to_solutions(solution_vector, spaces, limited_solutions); - if(coarse_spaces_to_limit != Hermes::vector*>()) + if(coarse_spaces_to_limit != Hermes::vector >()) { // Now set the element order to zero. Element* e; @@ -1202,7 +1202,7 @@ int FluxLimiter::limit_according_to_detector(Hermes::vector *> coa return discontinuous_elements.size() + oscillatory_element_idsRho.size() + oscillatory_element_idsRhoVX.size() + oscillatory_element_idsRhoVY.size() + oscillatory_element_idsRhoE.size(); }; -void FluxLimiter::limit_second_orders_according_to_detector(Hermes::vector *> coarse_spaces_to_limit) +void FluxLimiter::limit_second_orders_according_to_detector(Hermes::vector > coarse_spaces_to_limit) { std::set discontinuous_elements; if(dynamic_cast(this->detector)) @@ -1239,7 +1239,7 @@ void FluxLimiter::limit_second_orders_according_to_detector(Hermes::vectordetector = new KrivodonovaDiscontinuityDetector(spaces, limited_solutions); } - if(coarse_spaces_to_limit != Hermes::vector*>()) { + if(coarse_spaces_to_limit != Hermes::vector >()) { // Now set the element order to zero. Element* e; diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index 106b28a..b8c106c 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -26,8 +26,8 @@ class CFLCalculation CFLCalculation(double CFL_number, double kappa); // If the time step is necessary to decrease / possible to increase, the value time_step will be rewritten. - void calculate(Hermes::vector*> solutions, Mesh* mesh, double & time_step) const; - void calculate_semi_implicit(Hermes::vector*> solutions, Mesh* mesh, double & time_step) const; + void calculate(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const; + void calculate_semi_implicit(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const; void set_number(double new_CFL_number); @@ -42,7 +42,7 @@ class ADEStabilityCalculation ADEStabilityCalculation(double AdvectionRelativeConstant, double DiffusionRelativeConstant, double epsilon); // If the time step is necessary to decrease / possible to increase, the value time_step will be rewritten. - void calculate(Hermes::vector*> solutions, Mesh* mesh, double & time_step); + void calculate(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step); protected: double AdvectionRelativeConstant; @@ -54,8 +54,8 @@ class DiscontinuityDetector { public: /// Constructor. - DiscontinuityDetector(Hermes::vector *> spaces, - Hermes::vector *> solutions); + DiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions); /// Destructor. ~DiscontinuityDetector(); @@ -69,22 +69,23 @@ class DiscontinuityDetector protected: /// Members. - Hermes::vector *> spaces; - Hermes::vector *> solutions; + Hermes::vector > spaces; + Hermes::vector > solutions; + Hermes::vector*> solutionsInternal; std::set discontinuous_element_ids; std::set > oscillatory_element_idsRho; std::set > oscillatory_element_idsRhoVX; std::set > oscillatory_element_idsRhoVY; std::set > oscillatory_element_idsRhoE; - Mesh* mesh; + MeshSharedPtr mesh; }; class KrivodonovaDiscontinuityDetector : public DiscontinuityDetector { public: /// Constructor. - KrivodonovaDiscontinuityDetector(Hermes::vector *> spaces, - Hermes::vector *> solutions); + KrivodonovaDiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions); /// Destructor. ~KrivodonovaDiscontinuityDetector(); @@ -111,8 +112,8 @@ class KuzminDiscontinuityDetector : public DiscontinuityDetector { public: /// Constructor. - KuzminDiscontinuityDetector(Hermes::vector *> spaces, - Hermes::vector *> solutions, bool limit_all_orders_independently = false); + KuzminDiscontinuityDetector(Hermes::vector > spaces, + Hermes::vector > solutions, bool limit_all_orders_independently = false); /// Destructor. ~KuzminDiscontinuityDetector(); @@ -162,41 +163,41 @@ class FluxLimiter Kuzmin }; /// Constructor. - FluxLimiter(LimitingType type, double* solution_vector, Hermes::vector *> spaces, bool Kuzmin_limit_all_orders_independently = false); - FluxLimiter(FluxLimiter::LimitingType type, Hermes::vector*> solutions, Hermes::vector*> spaces, bool Kuzmin_limit_all_orders_independently = false); + FluxLimiter(LimitingType type, double* solution_vector, Hermes::vector > spaces, bool Kuzmin_limit_all_orders_independently = false); + FluxLimiter(FluxLimiter::LimitingType type, Hermes::vector > solutions, Hermes::vector > spaces, bool Kuzmin_limit_all_orders_independently = false); /// Destructor. ~FluxLimiter(); /// Do the limiting. /// With the possibility to also limit the spaces from which the spaces in the constructors are refined. - virtual int limit_according_to_detector(Hermes::vector *> coarse_spaces_to_limit = Hermes::vector *>()); + virtual int limit_according_to_detector(Hermes::vector > coarse_spaces_to_limit = Hermes::vector >()); /// For Kuzmin's detector. - virtual void limit_second_orders_according_to_detector(Hermes::vector *> coarse_spaces_to_limit = Hermes::vector *>()); + virtual void limit_second_orders_according_to_detector(Hermes::vector > coarse_spaces_to_limit = Hermes::vector >()); - void get_limited_solutions(Hermes::vector*> solutions_to_limit); + void get_limited_solutions(Hermes::vector > solutions_to_limit); bool limitOscillations; protected: /// Members. double* solution_vector; - Hermes::vector *> spaces; + Hermes::vector > spaces; DiscontinuityDetector* detector; - Hermes::vector*> limited_solutions; + Hermes::vector > limited_solutions; }; // Filters. class MachNumberFilter : public Hermes::Hermes2D::SimpleFilter { public: - MachNumberFilter(Hermes::vector*> solutions, double kappa) : SimpleFilter(solutions), kappa(kappa) {}; + MachNumberFilter(Hermes::vector > solutions, double kappa) : SimpleFilter(solutions), kappa(kappa) {}; ~MachNumberFilter() { }; MeshFunction* clone() const { - Hermes::vector*> slns; + Hermes::vector > slns; for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); MachNumberFilter* filter = new MachNumberFilter(slns, this->kappa); @@ -213,14 +214,14 @@ class MachNumberFilter : public Hermes::Hermes2D::SimpleFilter class PressureFilter : public Hermes::Hermes2D::SimpleFilter { public: - PressureFilter(Hermes::vector*> solutions, double kappa) : SimpleFilter(solutions), kappa(kappa) {}; + PressureFilter(Hermes::vector > solutions, double kappa) : SimpleFilter(solutions), kappa(kappa) {}; ~PressureFilter() { }; MeshFunction* clone() const { - Hermes::vector*> slns; + Hermes::vector > slns; for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); PressureFilter* filter = new PressureFilter(slns, this->kappa); @@ -237,14 +238,14 @@ class VelocityFilter : public Hermes::Hermes2D::SimpleFilter { public: // Vector of solutions: 0-th position - density, 1-st position - velocity component. - VelocityFilter(Hermes::vector*> solutions) : SimpleFilter(solutions) {}; + VelocityFilter(Hermes::vector > solutions) : SimpleFilter(solutions) {}; ~VelocityFilter() { }; MeshFunction* clone() const { - Hermes::vector*> slns; + Hermes::vector > slns; for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); @@ -259,13 +260,13 @@ class VelocityFilter : public Hermes::Hermes2D::SimpleFilter class EntropyFilter : public Hermes::Hermes2D::SimpleFilter { public: - EntropyFilter(Hermes::vector*> solutions, double kappa, double rho_ext, double p_ext) : SimpleFilter(solutions), kappa(kappa), rho_ext(rho_ext), p_ext(p_ext) {}; + EntropyFilter(Hermes::vector > solutions, double kappa, double rho_ext, double p_ext) : SimpleFilter(solutions), kappa(kappa), rho_ext(rho_ext), p_ext(p_ext) {}; ~EntropyFilter() { }; MeshFunction* clone() const { - Hermes::vector*> slns; + Hermes::vector > slns; for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); EntropyFilter* filter = new EntropyFilter(slns, this->kappa, rho_ext, p_ext); diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index edac085..99481d4 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -9,7 +9,7 @@ class EulerEquationsWeakFormStabilization : public WeakForm { public: - EulerEquationsWeakFormStabilization(Solution* prev_rho) : WeakForm() + EulerEquationsWeakFormStabilization(MeshFunctionSharedPtr prev_rho) : WeakForm() { this->set_ext(prev_rho); add_vector_form_DG(new DGVectorFormIndicator()); @@ -23,11 +23,10 @@ class EulerEquationsWeakFormStabilization : public WeakForm { } - double value(int n, double *wt, Func *u_ext[], Func *v, + double value(int n, double *wt, DiscontinuousFunc *u_ext[], Func *v, Geom *e, DiscontinuousFunc* *ext) const { double result = 0; - double w_L[4], w_R[4]; for (int i = 0;i < n;i++) result += wt[i] * v->val[i] * (ext[0]->val[i] - ext[0]->val_neighbor[i]) * (ext[0]->val[i] - ext[0]->val_neighbor[i]); @@ -35,7 +34,7 @@ class EulerEquationsWeakFormStabilization : public WeakForm return result / (e->diam * std::pow(e->area, 0.75)); } - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Ord ord(int n, double *wt, DiscontinuousFunc *u_ext[], Func *v, Geom *e, Func* *ext) const { return v->val[0] * v->val[0] * Ord(6); @@ -54,10 +53,10 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Hermes::vector inlet_markers; Hermes::vector outlet_markers; - Solution* prev_density; - Solution* prev_density_vel_x; - Solution* prev_density_vel_y; - Solution* prev_energy; + MeshFunctionSharedPtr prev_density; + MeshFunctionSharedPtr prev_density_vel_x; + MeshFunctionSharedPtr prev_density_vel_y; + MeshFunctionSharedPtr prev_energy; // External state. Hermes::vector rho_ext; @@ -90,7 +89,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm EulerEquationsWeakFormSemiImplicit(double kappa, double rho_ext, double v1_ext, double v2_ext, double pressure_ext, Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, + MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, bool fvm_only = false, int num_of_equations = 4) : WeakForm(num_of_equations), @@ -130,7 +129,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext, v1_ext, v2_ext, energy_ext[0], inlet_markers, kappa)); if(outlet_markers.size() > 0) - add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, 0, 0, 0, 0, outlet_markers, kappa)); + add_vector_form_surf(new EulerEquationsVectorFormSemiImplicitInletOutlet(form_i, rho_ext, v1_ext, v2_ext, energy_ext[0], outlet_markers, kappa)); for(int form_j = 0; form_j < 4; form_j++) { @@ -145,7 +144,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm if(outlet_markers.size() > 0) { - formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, 0,0,0,0, outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); + formSurf = new EulerEquationsMatrixFormSemiImplicitInletOutlet(form_i, form_j, rho_ext, v1_ext, v2_ext, energy_ext[0], outlet_markers, kappa, &this->cacheReadySurf, this->P_plus_cache_surf, this->P_minus_cache_surf); add_matrix_form_surf(formSurf); } @@ -153,14 +152,14 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm } } - this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + this->set_ext(Hermes::vector >(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); }; // Constructor for more inflows. EulerEquationsWeakFormSemiImplicit(double kappa, Hermes::vector rho_ext, Hermes::vector v1_ext, Hermes::vector v2_ext, Hermes::vector pressure_ext, Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, + MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, bool fvm_only = false, int num_of_equations = 4) : WeakForm(num_of_equations), @@ -220,7 +219,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm } } - this->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + this->set_ext(Hermes::vector >(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); }; virtual ~EulerEquationsWeakFormSemiImplicit() @@ -266,7 +265,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm for(unsigned int i = 0; i < this->ext.size(); i++) { Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + if((static_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) ext->set_type(HERMES_SLN); wf->ext.push_back(ext); } @@ -293,7 +292,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm { } - void set_stabilization(Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, double nu_1, double nu_2) + void set_stabilization(MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, double nu_1, double nu_2) { int mfvol_size = this->mfvol.size(); int mfsurf_size = this->mfsurf.size(); @@ -322,12 +321,12 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm for(unsigned int matrix_form_i = mfvol_size;matrix_form_i < this->mfvol.size();matrix_form_i++) { - mfvol.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + mfvol.at(matrix_form_i)->set_ext(Hermes::vector >(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); } for(unsigned int matrix_form_i = mfsurf_size;matrix_form_i < this->mfsurf.size();matrix_form_i++) { - mfsurf.at(matrix_form_i)->set_ext(Hermes::vector*>(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); + mfsurf.at(matrix_form_i)->set_ext(Hermes::vector >(prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy)); } } @@ -475,7 +474,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm delete num_flux; } - double value(int n, double *wt, DiscontinuousFunc *u, + double value(int n, double *wt, DiscontinuousFunc **u_ext, DiscontinuousFunc *u, DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const { double w[4]; @@ -646,8 +645,6 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm num_flux->Q_inv(w_ji, q_ji, e->nx[point_i], e->ny[point_i]); - double P_minus[4]; - double w_temp[4]; w_temp[0] = (w_ji[0] + w_L[0]) / 2; w_temp[1] = (w_ji[1] + w_L[1]) / 2; @@ -936,7 +933,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm EulerEquationsFormStabilizationSurf(int i, int j, double nu_2) : MatrixFormDG(i, j), nu_2(nu_2) {} - double value(int n, double *wt, DiscontinuousFunc *u, + double value(int n, double *wt, DiscontinuousFunc **u_ext, DiscontinuousFunc *u, DiscontinuousFunc *v, Geom *e, DiscontinuousFunc* *ext) const { double result = 0.; @@ -978,13 +975,13 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsWeakFormSemiImplicit { public: - Solution* prev_temp; + MeshFunctionSharedPtr prev_temp; double lambda, c_p, heat_flux; EulerEquationsWeakFormSemiImplicitCoupledWithHeat(double kappa, double rho_ext, double v1_ext, double v2_ext, double pressure_ext, Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - Solution* prev_density, Solution* prev_density_vel_x, Solution* prev_density_vel_y, Solution* prev_energy, Solution* prev_temp, double lambda, double c_p, double heat_flux): EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, + MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, MeshFunctionSharedPtr prev_temp, double lambda, double c_p, double heat_flux): EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, prev_density_vel_x, prev_density_vel_y, prev_energy, false, 5), prev_temp(prev_temp), lambda(lambda), c_p(c_p), heat_flux(heat_flux) { add_matrix_form(new HeatBilinearFormTime(4, c_p, lambda)); @@ -1007,7 +1004,7 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW for(unsigned int i = 0; i < this->ext.size(); i++) { Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i]))->get_type() == HERMES_SLN) + if((static_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) ext->set_type(HERMES_SLN); wf->ext.push_back(ext); } diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index 077bfa8..8957a03 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -31,9 +31,6 @@ bool SHOCK_CAPTURING = true; // Quantitative parameter of the discontinuity detector. double DISCONTINUITY_DETECTOR_PARAM = 1.0; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. @@ -117,40 +114,40 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh, base_mesh; + MeshSharedPtr mesh(new Mesh), base_mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("ffs.mesh", &base_mesh); + mloader.load("ffs.mesh", base_mesh); - base_mesh.refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); + base_mesh->refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - base_mesh.refine_all_elements(0, true); + base_mesh->refine_all_elements(0, true); - mesh.copy(&base_mesh); + mesh->copy(base_mesh); // Initialize boundary condition types and spaces with default shapesets. - L2Spacespace_rho(&mesh, P_INIT); - L2Spacespace_rho_v_x(&mesh, P_INIT); - L2Spacespace_rho_v_y(&mesh, P_INIT); - L2Spacespace_e(&mesh, P_INIT); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); - - // Initialize solutions, set initial conditions. - ConstantSolution sln_rho(&mesh, RHO_EXT); - ConstantSolution sln_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution sln_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution sln_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); - - ConstantSolution prev_rho(&mesh, RHO_EXT); - ConstantSolution prev_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution prev_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); - - ConstantSolution rsln_rho(&mesh, RHO_EXT); - ConstantSolution rsln_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution rsln_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution rsln_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + + MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + + MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); @@ -160,11 +157,11 @@ int main(int argc, char* argv[]) outlet_markers.push_back(BDY_OUTLET); EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); @@ -181,25 +178,6 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - bool loaded_now = false; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time() + time_step; - iteration = (continuity.get_num()) * EVERY_NTH_STEP + 1; - loaded_now = true; - } - // Time stepping loop. for(; t < 14.5; t += time_step) { @@ -217,7 +195,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - Hermes::vector *>* ref_spacesNoDerefinement; + Hermes::vector >* ref_spacesNoDerefinement; // Periodic global derefinements. if (as == 1 && (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0)) @@ -226,28 +204,28 @@ int main(int argc, char* argv[]) REFINEMENT_COUNT = 0; - space_rho.unrefine_all_mesh_elements(true); + space_rho->unrefine_all_mesh_elements(true); - space_rho.adjust_element_order(-1, P_INIT); - space_rho_v_x.adjust_element_order(-1, P_INIT); - space_rho_v_y.adjust_element_order(-1, P_INIT); - space_e.adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); } - Mesh::ReferenceMeshCreator refMeshCreatorFlow(&mesh); - Mesh* ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); int order_increase = 1; - Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, ref_mesh_flow, order_increase); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, ref_mesh_flow, order_increase); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector*> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) @@ -257,23 +235,13 @@ int main(int argc, char* argv[]) ndofs_prev = Space::get_num_dofs(ref_spaces_const); - // Project the previous time level solution onto the new fine mesh. - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); - if(loaded_now) - { - loaded_now = false; - - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector *>(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); - } - else - { + // Project the previous time level solution onto the new fine mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; - ogProjection.project_global(ref_spaces_const, Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector()); - } + ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); - FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), ref_spaces_const, true); + FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), ref_spaces_const, true); flux_limiterLoading.limitOscillations = true; @@ -286,23 +254,15 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Limited in %d-th step: %d.", ++counter, limited); } - flux_limiterLoading.get_limited_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); - - if(iteration > std::max((int)(continuity.get_num() * EVERY_NTH_STEP + 1), 1)) - { - delete rsln_rho.get_mesh(); - delete rsln_rho_v_x.get_mesh(); - delete rsln_rho_v_y.get_mesh(); - delete rsln_e.get_mesh(); - } + flux_limiterLoading.get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem dp(&wf, ref_spaces_const); SparseMatrix* matrix = create_matrix(); @@ -325,16 +285,16 @@ int main(int argc, char* argv[]) if(!SHOCK_CAPTURING) Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const, true); - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - flux_limiter.limit_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - flux_limiter.get_limited_solutions(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } } catch(std::exception& e) @@ -342,32 +302,32 @@ int main(int argc, char* argv[]) std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), - Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), + Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)) * 100; + Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), ref_space_rho->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), ref_space_rho->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - if (Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)) >= NDOF_STOP) { Hermes::Mixins::Loggable::Static::info("Max. number of DOFs exceeded."); REFINEMENT_COUNT++; @@ -375,7 +335,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -391,24 +351,22 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - pressure.reinit(); - pressure_view.show(&pressure); - Mach_number_view.show(&Mach_number); - pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure); + Mach_number_view.show(Mach_number); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - Mach_number.reinit(); + Mach_number->reinit(); Linearizer lin; Orderizer ord; char filename[40]; sprintf(filename, "Density-%i.vtk", iteration); - lin.save_solution_vtk(&rsln_rho, filename, "Density", false); + lin.save_solution_vtk(rsln_rho, filename, "Density", false); sprintf(filename, "Mach number-%i.vtk", iteration); - lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false); + lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); sprintf(filename, "Space-%i.vtk", iteration); ord.save_orders_vtk(ref_space_rho, filename); sprintf(filename, "Mesh-%i.vtk", iteration); @@ -418,8 +376,8 @@ int main(int argc, char* argv[]) // Save the progress. if(iteration > 1) { - continuity.add_record(t, Hermes::vector(&mesh, &mesh, &mesh, &mesh), Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), - Hermes::vector *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), time_step); + continuity.add_record(t, Hermes::vector(mesh, mesh, mesh, mesh), Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), time_step); } } @@ -434,10 +392,10 @@ int main(int argc, char* argv[]) iteration++; // Copy the solutions into the previous time level ones. - prev_rho.copy(&rsln_rho); - prev_rho_v_x.copy(&rsln_rho_v_x); - prev_rho_v_y.copy(&rsln_rho_v_y); - prev_e.copy(&rsln_e); + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); } pressure_view.close(); diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index ce6a281..fe36652 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -40,9 +40,6 @@ double DISCONTINUITY_DETECTOR_PARAM = 1.0; const double NU_1 = 0.1; const double NU_2 = 0.1; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. @@ -52,10 +49,7 @@ const int INIT_REF_NUM_STEP = 2; // CFL value. double CFL_NUMBER = 0.25; // Initial time step. -double time_step = 1E-6; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -const MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double time_step = 1E-6; // Equation parameters. // Exterior pressure (dimensionless). @@ -93,37 +87,38 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("ffs.mesh", &mesh); mesh.refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); MeshView m; - m.show(&mesh); + m.show(mesh); // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - L2Space space_stabilization(&mesh, 0); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - ConstantSolution prev_rho(&mesh, RHO_EXT); - ConstantSolution prev_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution prev_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA, RHO_EXT, P_EXT)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); @@ -136,25 +131,6 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - } - // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); Hermes::vector inlet_markers; @@ -163,19 +139,17 @@ int main(int argc, char* argv[]) outlet_markers.push_back(BDY_OUTLET); EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, (P_INIT == 0)); - EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); + EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); - DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); + DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); LinearSolver solver(&dp); - // If the FE problem is in fact a FV problem. - if(P_INIT == 0) - dp.set_fvm(); - // Time stepping loop. + int iteration = 0; + double t = 0.0; for(; t < 10.0; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); @@ -194,25 +168,25 @@ int main(int argc, char* argv[]) solver.solve(); if(!SHOCK_CAPTURING) { - Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } } catch(std::exception& e) @@ -220,7 +194,7 @@ int main(int argc, char* argv[]) std::cout << e.what(); } - CFL.calculate(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + CFL.calculate(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) @@ -228,27 +202,25 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - pressure.reinit(); - entropy.reinit(); - pressure_view.show(&pressure); - entropy_production_view.show(&entropy); - Mach_number_view.show(&Mach_number); - pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + Mach_number->reinit(); + pressure->reinit(); + entropy->reinit(); + pressure_view.show(pressure); + entropy_production_view.show(entropy); + Mach_number_view.show(Mach_number); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); - Mach_number.reinit(); + pressure->reinit(); + Mach_number->reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); Linearizer lin_mach; sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); } } } diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index dc9779d..590b778 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -33,7 +33,7 @@ enum shockCapturingType KUZMIN, KRIVODONOVA }; -bool SHOCK_CAPTURING = false; +bool SHOCK_CAPTURING = true; shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; @@ -41,9 +41,6 @@ double DISCONTINUITY_DETECTOR_PARAM = 1.0; const double NU_1 = 0.1; const double NU_2 = 0.1; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. @@ -134,42 +131,43 @@ const std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", &mesh); + mloader.load("GAMM-channel.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - L2Spacespace_rho(&mesh, P_INIT); - L2Spacespace_rho_v_x(&mesh, P_INIT); - L2Spacespace_rho_v_y(&mesh, P_INIT); - L2Spacespace_e(&mesh, P_INIT); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - ConstantSolution sln_rho(&mesh, RHO_EXT); - ConstantSolution sln_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution sln_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution sln_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - ConstantSolution* prev_rho = new ConstantSolution(&mesh, RHO_EXT); - ConstantSolution* prev_rho_v_x = new ConstantSolution(&mesh, RHO_EXT * V1_EXT); - ConstantSolution* prev_rho_v_y = new ConstantSolution(&mesh, RHO_EXT * V2_EXT); - ConstantSolution* prev_e = new ConstantSolution(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - ConstantSolution* rsln_rho = new ConstantSolution(&mesh, RHO_EXT); - ConstantSolution* rsln_rho_v_x = new ConstantSolution(&mesh, RHO_EXT * V1_EXT); - ConstantSolution* rsln_rho_v_y = new ConstantSolution(&mesh, RHO_EXT * V2_EXT); - ConstantSolution* rsln_e = new ConstantSolution(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA, RHO_EXT, P_EXT); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA, RHO_EXT, P_EXT)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); @@ -186,26 +184,9 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - bool loaded_now = false; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_time_step_length(time_step_n); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - loaded_now = true; - } - // Time stepping loop. + int iteration = 1; + double t = 0.0; for(; t < 3.5; t += time_step_n) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); @@ -216,12 +197,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); REFINEMENT_COUNT = 0; - space_rho.unrefine_all_mesh_elements(true); + space_rho->unrefine_all_mesh_elements(true); - space_rho.adjust_element_order(-1, P_INIT); - space_rho_v_x.adjust_element_order(-1, P_INIT); - space_rho_v_y.adjust_element_order(-1, P_INIT); - space_e.adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); } // Adaptivity loop: @@ -235,21 +216,21 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh and setup reference space. int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; - Mesh::ReferenceMeshCreator refMeshCreatorFlow(&mesh); - Mesh* ref_mesh = refMeshCreatorFlow.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, ref_mesh, order_increase); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, ref_mesh, order_increase); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, ref_mesh, order_increase); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, ref_mesh, order_increase); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector*> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - L2Space refspace_stabilization(ref_space_rho->get_mesh(), 0); + SpaceSharedPtr refspace_stabilization(new L2Space(ref_space_rho->get_mesh(), 0)); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) @@ -259,37 +240,15 @@ int main(int argc, char* argv[]) ndofs_prev = Space::get_num_dofs(ref_spaces_const); - // Project the previous time level solution onto the new fine mesh. - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); - if(iteration == 1) - { - delete prev_rho; - delete prev_rho_v_x; - delete prev_rho_v_y; - delete prev_e; - - prev_rho = new ConstantSolution((ref_spaces_const)[0]->get_mesh(), RHO_EXT); - prev_rho_v_x = new ConstantSolution((ref_spaces_const)[0]->get_mesh(), RHO_EXT * V1_EXT); - prev_rho_v_y = new ConstantSolution((ref_spaces_const)[0]->get_mesh(), RHO_EXT * V2_EXT); - prev_e = new ConstantSolution((ref_spaces_const)[0]->get_mesh(), QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); - } - else if(loaded_now) - { - loaded_now = false; - - continuity.get_last_record()->load_solutions(Hermes::vector*>(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector *>(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); - } - else - { - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector*>(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector*>(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); - } + // Project the previous time level solution onto the new fine mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); + OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); @@ -304,9 +263,9 @@ int main(int argc, char* argv[]) // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem dp(&wf, ref_spaces_const); - DiscreteProblem dp_stabilization(&wf_stabilization, &refspace_stabilization); + DiscreteProblem dp_stabilization(&wf_stabilization, refspace_stabilization); bool* discreteIndicator = NULL; SparseMatrix* matrix = create_matrix(); @@ -317,10 +276,6 @@ int main(int argc, char* argv[]) // Set the current time step. wf.set_current_time_step(time_step_n); - // If the FE problem is in fact a FV problem. - if(P_INIT == 0 && CAND_LIST == H2D_H_ANISO) - dp.set_fvm(); - FluxLimiter* flux_limiter; dp.assemble(matrix, rhs); @@ -331,58 +286,58 @@ int main(int argc, char* argv[]) if(!SHOCK_CAPTURING) { Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, - Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } else { if(SHOCK_CAPTURING_TYPE == KUZMIN) - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const); else - FluxLimiter flux_limiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), ref_spaces_const); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), ref_spaces_const); if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter->limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter->limit_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter->limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter->get_limited_solutions(Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } } else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), - Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), + Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), - Hermes::vector*>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; + Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate(Hermes::vector *>(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step_n); + CFL.calculate(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step_n); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); REFINEMENT_COUNT++; - if (Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)) >= NDOF_STOP) done = true; else as++; @@ -394,30 +349,27 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - pressure.reinit(); - entropy.reinit(); - pressure_view.show(&pressure, 1); - entropy_production_view.show(&entropy, 1); - Mach_number_view.show(&Mach_number, 1); - - pressure_view.save_numbered_screenshot("pressure %i.bmp", iteration); - Mach_number_view.save_numbered_screenshot("Mach no %i.bmp", iteration); + Mach_number->reinit(); + pressure->reinit(); + entropy->reinit(); + pressure_view.show(pressure, 1); + entropy_production_view.show(entropy, 1); + Mach_number_view.show(Mach_number, 1); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); - Mach_number.reinit(); - entropy.reinit(); + pressure->reinit(); + Mach_number->reinit(); + entropy->reinit(); Linearizer lin; char filename[40]; sprintf(filename, "Pressure-%i.vtk", iteration - 1); - lin.save_solution_vtk(&pressure, filename, "Pressure", false); + lin.save_solution_vtk(pressure, filename, "Pressure", false); sprintf(filename, "Mach number-%i.vtk", iteration - 1); - lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false); + lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); sprintf(filename, "Entropy-%i.vtk", iteration - 1); - lin.save_solution_vtk(&entropy, filename, "Entropy", false); + lin.save_solution_vtk(entropy, filename, "Entropy", false); } } @@ -435,12 +387,6 @@ int main(int argc, char* argv[]) prev_rho_v_x->copy(rsln_rho_v_x); prev_rho_v_y->copy(rsln_rho_v_y); prev_e->copy(rsln_e); - - delete rsln_rho->get_mesh(); - - delete rsln_rho_v_x->get_mesh(); - delete rsln_rho_v_y->get_mesh(); - delete rsln_e->get_mesh(); } pressure_view.close(); diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index 0c74288..d81bdc3 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -22,7 +22,7 @@ using namespace Hermes::Hermes2D::Views; // Visualization. // Set to "true" to enable Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = false; +const bool HERMES_VISUALIZATION = true; // Set to "true" to enable VTK output. const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. @@ -43,24 +43,14 @@ double DISCONTINUITY_DETECTOR_PARAM = 1.0; const double NU_1 = 0.1; const double NU_2 = 0.1; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. -const int P_INIT = 2; +const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 3; // CFL value. -double CFL_NUMBER = 0.1; -// Initial time step. -double time_step_n = 1E-6; +double CFL_NUMBER = 0.1; // Initial time step. -double time_step_n_minus_one = 1E-6; - -// Matrix solver for orthogonal projections: -// SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double time_step = 1E-6; // Equation parameters. // Exterior pressure (dimensionless). @@ -89,32 +79,32 @@ std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", &mesh); + mloader.load("GAMM-channel.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - L2Space space_stabilization(&mesh, 0); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - ConstantSolution prev_rho(&mesh, RHO_EXT); - ConstantSolution prev_rho_v_x(&mesh, RHO_EXT * V1_EXT); - ConstantSolution prev_rho_v_y(&mesh, RHO_EXT * V2_EXT); - ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); @@ -132,26 +122,6 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); - continuity.get_last_record()->load_time_step_length(time_step_n); - continuity.get_last_record()->load_time_step_length_n_minus_one(time_step_n_minus_one); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - } - // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); Hermes::vector inlet_markers; @@ -159,48 +129,24 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, (P_INIT == 0)); - - EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); + EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); - DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); - bool* discreteIndicator = NULL; - - // If the FE problem is in fact a FV problem. - if(P_INIT == 0) - dp.set_fvm(); + DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); // Time stepping loop. - for(; t < 3.0; t += time_step_n) + int iteration = 0; + double t = 0.0; + for(; t < 10.0; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - { - dp_stabilization.assemble(rhs_stabilization); - if(discreteIndicator != NULL) - delete [] discreteIndicator; - discreteIndicator = new bool[space_stabilization.get_mesh()->get_max_element_id() + 1]; - for(unsigned int i = 0; i < space_stabilization.get_mesh()->get_max_element_id() + 1; i++) - discreteIndicator[i] = false; - Element* e; - for_all_active_elements(e, space_stabilization.get_mesh()) - { - AsmList al; - space_stabilization.get_element_assembly_list(e, &al); - if(rhs_stabilization->get(al.get_dof()[0]) >= 1) - discreteIndicator[e->id] = true; - } - wf.set_discreteIndicator(discreteIndicator, space_stabilization.get_mesh()->get_max_element_id() + 1); - } - // Set the current time step. - wf.set_current_time_step(time_step_n); + wf.set_current_time_step(time_step); // Assemble the stiffness matrix and rhs. Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); @@ -212,37 +158,35 @@ int main(int argc, char* argv[]) try { solver->solve(); + if(!SHOCK_CAPTURING) { - if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) - { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } } - } - catch(Hermes::Exceptions::LinearMatrixSolverException& e) + catch(std::exception& e) { - e.print_msg(); + std::cout << e.what(); } - CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step_n); + CFL.calculate(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) @@ -250,25 +194,23 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - pressure.reinit(); - pressure_view.show(&pressure); - Mach_number_view.show(&Mach_number); - pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure); + Mach_number_view.show(Mach_number); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); - Mach_number.reinit(); + pressure->reinit(); + Mach_number->reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); Linearizer lin_mach; sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); } } } diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index d4552c9..a142651 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D::Views; // Visualization. // Set to "true" to enable Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = false; +const bool HERMES_VISUALIZATION = true; // Set to "true" to enable VTK output. const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. @@ -17,10 +17,10 @@ const unsigned int EVERY_NTH_STEP = 1; // Initial polynomial degree. -const int P_INIT_FLOW = 1; +const int P_INIT_FLOW = 0; const int P_INIT_HEAT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 1; // Shock capturing. enum shockCapturingType @@ -75,6 +75,19 @@ const std::string BDY_SOLID_WALL = "Solid"; // Must be in accordance with the mesh file. const double MESH_SIZE = 3.0; +// Every UNREF_FREQth time step the mesh is unrefined. +const int UNREF_FREQ = 5; + +// Adaptivity +int REFINEMENT_COUNT = 0; +const double THRESHOLD = 0.3; +const int STRATEGY = 0; +CandList CAND_LIST = H2D_HP_ANISO; +const int MAX_P_ORDER = -1; +const int MESH_REGULARITY = -1; +const double CONV_EXP = 1; +double ERR_STOP = 5.0; + // Weak forms. #include "../forms_explicit.cpp" @@ -86,17 +99,17 @@ int main(int argc, char* argv[]) Hermes2DApi.set_integral_param_value(numThreads, 1); // Load the mesh. - Mesh mesh, mesh_heat; + MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); - mesh_heat.copy(&mesh); - mesh_heat.refine_towards_boundary("Inlet", 3, false); - mesh.refine_all_elements(0, true); + mesh_heat->copy(mesh); + mesh_heat->refine_towards_boundary("Inlet", 3, false); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); @@ -104,30 +117,56 @@ int main(int argc, char* argv[]) Hermes::vector*> bc_vector(&bc_temp_zero, &bc_temp_nonzero); EssentialBCs bcs(bc_vector); - L2Space space_rho(&mesh, P_INIT_FLOW); - L2Space space_rho_v_x(&mesh, P_INIT_FLOW); - L2Space space_rho_v_y(&mesh, P_INIT_FLOW); - L2Space space_e(&mesh, P_INIT_FLOW); - H1Space space_temp(&mesh_heat, &bcs, P_INIT_HEAT); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_temp(new H1Space(mesh_heat, &bcs, P_INIT_HEAT)); + + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp); + Hermes::vector > cspaces(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution prev_rho_v_x(&mesh, 0.0); - ConstantSolution prev_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); - ConstantSolution prev_temp(&mesh_heat, 0.0); + MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); + MeshFunctionSharedPtr prev_temp(new ConstantSolution (mesh_heat, 0.0)); + Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp); + Hermes::vector > cprev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp); + + MeshFunctionSharedPtr sln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr sln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); + MeshFunctionSharedPtr sln_temp(new ConstantSolution (mesh_heat, 0.0)); + + Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e, sln_temp); + Hermes::vector > cslns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e, sln_temp); + + MeshFunctionSharedPtr rsln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr rsln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); + MeshFunctionSharedPtr rsln_temp(new ConstantSolution (mesh_heat, 0.0)); + Hermes::vector > rslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e, rsln_temp); + Hermes::vector > crslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e, rsln_temp); + + Hermes::vector > flow_spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + Hermes::vector > flow_slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); + Hermes::vector > rflow_slns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e); // Filters for visualization of Mach number, pressure and entropy. - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); - VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr vel_x(new VelocityFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x))); + MeshFunctionSharedPtr vel_y(new VelocityFilter(Hermes::vector >(rsln_rho, rsln_rho_v_y))); - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); - VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); - ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); - ScalarView temperature_view("Temperature", new WinGeom(900, 700, 800, 600)); + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 400, 300)); + VectorView velocity_view("Velocity", new WinGeom(0, 400, 400, 300)); + ScalarView density_view("Density", new WinGeom(500, 0, 400, 300)); + ScalarView temperature_view("Temperature", new WinGeom(500, 400, 400, 300)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(); @@ -139,6 +178,11 @@ int main(int argc, char* argv[]) CFLCalculation CFL(CFL_NUMBER, KAPPA); ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, LAMBDA); + // Initialize refinement selector. + L2ProjBasedSelector l2_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + l2_selector.set_error_weights(1.0, 1.0, 1.0); + H1ProjBasedSelector h1_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + // Look for a saved solution on the disk. int iteration = 0; double t = 0; @@ -150,95 +194,196 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp, LAMBDA, C_P, HEAT_FLUX); - + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P, HEAT_FLUX); + // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); + DiscreteProblemLinear dp(&wf, cspaces); // Time stepping loop. for(; t < 10.0; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + // Periodic global derefinements. + if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) + { + Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); + REFINEMENT_COUNT = 0; + + space_rho->unrefine_all_mesh_elements(true); + space_temp->unrefine_all_mesh_elements(true); + + space_rho->adjust_element_order(-1, P_INIT_FLOW); + space_rho_v_x->adjust_element_order(-1, P_INIT_FLOW); + space_rho_v_y->adjust_element_order(-1, P_INIT_FLOW); + space_e->adjust_element_order(-1, P_INIT_FLOW); + space_temp->adjust_element_order(-1, P_INIT_HEAT); + Space::assign_dofs(spaces); + } + // Set the current time step. wf.set_current_time_step(time_step); - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - dp.assemble(matrix, rhs); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) + // Adaptivity loop: + int as = 1; + bool done = false; + do { - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e, &space_temp), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp)); - } - else + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + + // Construct globally refined reference mesh and setup reference space. + int order_increase = 1; + + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorTemperature(mesh_heat); + MeshSharedPtr ref_mesh_heat = refMeshCreatorTemperature.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); + + Space::ReferenceSpaceCreator refSpaceCreatorT(space_temp, ref_mesh_heat, order_increase); + SpaceSharedPtr ref_space_temp = refSpaceCreatorT.create_ref_space(); + + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e, ref_space_temp); + Hermes::vector > cref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e, ref_space_temp); + + Hermes::vector > cref_flow_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + + // Project the previous time level solution onto the new fine mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); + OGProjection ogProjection; ogProjection.project_global(cref_spaces, prev_slns, prev_slns, Hermes::vector(), iteration > 1); + + // Report NDOFs. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", + Space::get_num_dofs(spaces), Space::get_num_dofs(cref_spaces)); + + // Assemble the reference problem. + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + DiscreteProblem dp(&wf, cref_spaces); + + // Assemble the stiffness matrix and rhs. + Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); + dp.assemble(matrix, rhs); + + // Solve the matrix problem. + Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); + if(solver->solve()) { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + if(!SHOCK_CAPTURING) + { + Solution::vector_to_solutions(solver->get_sln_vector(), cref_spaces, rslns); + } else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), cref_flow_spaces, true); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), cref_flow_spaces); - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(flow_spaces); - flux_limiter->limit_according_to_detector(); + flux_limiter->limit_according_to_detector(flow_spaces); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(rflow_slns); - Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), &space_temp, &prev_temp); + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(cref_flow_spaces), ref_space_temp, rsln_temp); + } } - } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); + else + throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); - double util_time_step = time_step; + // Calculate element errors and total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - ADES.calculate(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y), &mesh, util_time_step); + Adapt* adaptivity_flow = new Adapt(flow_spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + Adapt* adaptivity_heat = new Adapt(space_temp, HERMES_H1_NORM); + double error_flow = adaptivity_flow->calc_err_est(flow_slns, rflow_slns) * 100; + double error_heat = adaptivity_heat->calc_err_est(sln_temp, rsln_temp) * 100; - if(util_time_step < time_step) - time_step = util_time_step; + CFL.calculate_semi_implicit(rflow_slns, ref_mesh_flow, time_step); - // Visualization. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) + double util_time_step = time_step; + + ADES.calculate(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y), ref_mesh_heat, util_time_step); + + if(util_time_step < time_step) + time_step = util_time_step; + + // Report results. + Hermes::Mixins::Loggable::Static::info("Error-flow: %g%%, error-heat: %g%%.", error_flow, error_heat); + + // If err_est too large, adapt the mesh-> + if (error_flow < ERR_STOP) + done = true; + else { - pressure.reinit(); - vel_x.reinit(); - vel_y.reinit(); - pressure_view.show(&pressure); - velocity_view.show(&vel_x, &vel_y); - density_view.show(&prev_rho); - temperature_view.show(&prev_temp, HERMES_EPS_HIGH); + Hermes::Mixins::Loggable::Static::info("Adapting flow mesh->"); + done = adaptivity_flow->adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector), + THRESHOLD, STRATEGY, MESH_REGULARITY); } - // Output solution in VTK format. - if(VTK_VISUALIZATION) + + if(error_heat >= ERR_STOP) { - pressure.reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + Hermes::Mixins::Loggable::Static::info("Adapting heat mesh->"); + done = adaptivity_heat->adapt(&h1_selector, THRESHOLD, STRATEGY, MESH_REGULARITY) & done; } + + as++; + + // Visualization. + if((iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + pressure->reinit(); + vel_x->reinit(); + vel_y->reinit(); + pressure_view.show(pressure); + velocity_view.show(vel_x, vel_y); + density_view.show(prev_rho); + temperature_view.show(prev_temp, HERMES_EPS_HIGH); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure->reinit(); + Linearizer lin_pressure; + char filename[40]; + sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); + } + } + + delete adaptivity_flow; + delete adaptivity_heat; } + while (!done); + + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); + prev_temp->copy(rsln_temp); } pressure_view.close(); velocity_view.close(); density_view.close(); temperature_view.close(); - + return 0; } diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 250bebc..4c3a5f7 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -4,21 +4,9 @@ using namespace Hermes; using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::RefinementSelectors; using namespace Hermes::Hermes2D::Views; -// This example solves the compressible Euler equations using a basic -// piecewise-constant finite volume method, or Discontinuous Galerkin method of higher order with no adaptivity. -// -// Equations: Compressible Euler equations, perfect gas state equation. -// -// Domain: A square, see file square.mesh. -// -// BC: Solid walls, inlet, no outlet. -// -// IC: Constant state identical to inlet, only with higher pressure. -// -// The following parameters can be changed: - // Visualization. // Set to "true" to enable Hermes OpenGL visualization. const bool HERMES_VISUALIZATION = true; @@ -27,10 +15,16 @@ const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; + +// Initial polynomial degree. +const int P_INIT_FLOW = 1; +const int P_INIT_HEAT = 1; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 2; + // Shock capturing. enum shockCapturingType { - FEISTAUER, KUZMIN, KRIVODONOVA }; @@ -38,48 +32,40 @@ bool SHOCK_CAPTURING = true; shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; -// Quantitative parameter of the shock capturing in case of Feistauer. -const double NU_1 = 0.1; -const double NU_2 = 0.1; - -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - -// Initial polynomial degree. -const int P_INIT = 1; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 4; -// CFL value. -double CFL_NUMBER = 0.7; -// Initial time step. -double time_step = 1E-4; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -const MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Equation parameters. // Exterior pressure (dimensionless). -const double P_EXT = 1.5; +const double P_EXT = 1.5; // Initial pressure (dimensionless). const double P_INITIAL_HIGH = 1.5; // Initial pressure (dimensionless). const double P_INITIAL_LOW = 1.0; // Inlet density (dimensionless). -const double RHO_EXT = 0.5; +const double RHO_EXT = 1.0; // Initial density (dimensionless). -const double RHO_INITIAL_HIGH = 0.5; +const double RHO_INITIAL_HIGH = 1.0; // Initial density (dimensionless). -const double RHO_INITIAL_LOW = 0.3; +const double RHO_INITIAL_LOW = 0.66; // Inlet x-velocity (dimensionless). const double V1_EXT = 0.0; // Inlet y-velocity (dimensionless). const double V2_EXT = 0.0; // Kappa. -const double KAPPA = 1.4; +const double KAPPA = 1.4; +// Lambda. +const double LAMBDA = 1e3; +// heat_capacity. +const double C_P = 1e2; +// heat flux through the inlet. +const double HEAT_FLUX = 1e-3; +// CFL value. +const double CFL_NUMBER = 0.1; +// Initial time step. +double time_step = 1E-5; // Stability for the concentration part. -double ADVECTION_STABILITY_CONSTANT = 0.1; -const double DIFFUSION_STABILITY_CONSTANT = 0.1; +double ADVECTION_STABILITY_CONSTANT = 1e16; +const double DIFFUSION_STABILITY_CONSTANT = 1e16; // Boundary markers. const std::string BDY_INLET = "Inlet"; @@ -100,45 +86,48 @@ int main(int argc, char* argv[]) Hermes2DApi.set_integral_param_value(numThreads, 1); // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + mesh_heat->copy(mesh); + mesh_heat->refine_towards_boundary("Inlet", 3, false); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); - EssentialBCs bcs(&bc_temp_zero); - - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - H1Space space_temp(&mesh, &bcs, 1); - L2Space space_stabilization(&mesh, 0); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); + Hermes2D::DefaultEssentialBCConst bc_temp_nonzero("Inlet", 1.0); + Hermes::vector*> bc_vector(&bc_temp_zero, &bc_temp_nonzero); + EssentialBCs bcs(bc_vector); + + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_temp(new H1Space(mesh_heat, &bcs, P_INIT_HEAT)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution prev_rho_v_x(&mesh, 0.0); - ConstantSolution prev_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); - ConstantSolution prev_temp(&mesh, 0.0); - + MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); + MeshFunctionSharedPtr prev_temp(new ConstantSolution (mesh_heat, 0.0)); + // Filters for visualization of Mach number, pressure and entropy. - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); - VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr vel_x(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_x))); + MeshFunctionSharedPtr vel_y(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_y))); - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - VectorView velocity_view("Velocity", new WinGeom(0, 400, 600, 300)); - ScalarView velocity_view_x("Velocity - x", new WinGeom(0, 400, 600, 300)); - ScalarView velocity_view_y("Velocity - y", new WinGeom(700, 400, 600, 300)); - ScalarView density_view("Density", new WinGeom(1400, 0, 600, 300)); - ScalarView temperature_view("Temperature", new WinGeom(1400, 400, 600, 300)); + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); + VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); + ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); + ScalarView temperature_view("Temperature", new WinGeom(900, 700, 800, 600)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(); @@ -146,9 +135,9 @@ int main(int argc, char* argv[]) Vector* rhs_stabilization = create_vector(); LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - // Set up CFL calculation class. + // Set up stability calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, 1e2); + ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, LAMBDA); // Look for a saved solution on the disk. int iteration = 0; double t = 0; @@ -161,39 +150,16 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P, HEAT_FLUX); - EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); - - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); - // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_temp)); - DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); + DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp)); // Time stepping loop. for(; t < 10.0; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - { - assert(space_stabilization.get_num_dofs() == space_stabilization.get_mesh()->get_num_active_elements()); - dp_stabilization.assemble(rhs_stabilization); - bool* discreteIndicator = new bool[space_stabilization.get_num_dofs()]; - memset(discreteIndicator, 0, space_stabilization.get_num_dofs() * sizeof(bool)); - Element* e; - for_all_active_elements(e, space_stabilization.get_mesh()) - { - AsmList al; - space_stabilization.get_element_assembly_list(e, &al); - if(rhs_stabilization->get(al.get_dof()[0]) >= 1) - discreteIndicator[e->id] = true; - } - wf.set_discreteIndicator(discreteIndicator, space_stabilization.get_num_dofs()); - } - // Set the current time step. wf.set_current_time_step(time_step); @@ -205,67 +171,66 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); if(solver->solve()) { - if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) + if(!SHOCK_CAPTURING) { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e, &space_temp), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_temp)); + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e, space_temp), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp)); } else - { + { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), &space_temp, &prev_temp); + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), space_temp, prev_temp); } } else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); double util_time_step = time_step; - ADES.calculate(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y), &mesh, util_time_step); + ADES.calculate(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y), mesh, util_time_step); if(util_time_step < time_step) time_step = util_time_step; - // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) { // Hermes visualization. if(HERMES_VISUALIZATION) { - pressure.reinit(); - vel_x.reinit(); - vel_y.reinit(); - pressure_view.show(&pressure); - velocity_view.show(&vel_x, &vel_y); - density_view.show(&prev_rho); - temperature_view.show(&prev_temp); + pressure->reinit(); + vel_x->reinit(); + vel_y->reinit(); + pressure_view.show(pressure); + velocity_view.show(vel_x, vel_y); + density_view.show(prev_rho); + temperature_view.show(prev_temp, HERMES_EPS_HIGH); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); + pressure->reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); } } } diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 37ffc85..9f9c89c 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -11,7 +11,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // // Equations: Compressible Euler equations, perfect gas state equation. // -// Domain: A square, see file square.mesh. +// Domain: A square, see file square.mesh-> // // BC: Solid walls, inlet, no outlet. // @@ -32,9 +32,6 @@ bool SHOCK_CAPTURING = true; // Quantitative parameter of the discontinuity detector. double DISCONTINUITY_DETECTOR_PARAM = 1.0; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. @@ -138,40 +135,37 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - L2Spacespace_rho(&mesh, P_INIT); - L2Spacespace_rho_v_x(&mesh, P_INIT); - L2Spacespace_rho_v_y(&mesh, P_INIT); - L2Spacespace_e(&mesh, P_INIT); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - InitialSolutionLinearProgress sln_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution sln_rho_v_x(&mesh, 0.0); - ConstantSolution sln_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress sln_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); - - InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution prev_rho_v_x(&mesh, 0.0); - ConstantSolution prev_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - InitialSolutionLinearProgress rsln_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution rsln_rho_v_x(&mesh, 0.0); - ConstantSolution rsln_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress rsln_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + MeshFunctionSharedPtr sln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr sln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - // For saving to the disk. - CalculationContinuity continuity(CalculationContinuity::onlyNumber); + MeshFunctionSharedPtr rsln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr rsln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); // Initialize weak formulation. Hermes::vector solid_wall_markers; @@ -181,12 +175,12 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_INITIAL_HIGH, P_INITIAL_HIGH); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA, RHO_INITIAL_HIGH, P_INITIAL_HIGH)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); VectorView velocity_view("Velocity", new WinGeom(700, 400, 600, 300)); @@ -213,12 +207,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); REFINEMENT_COUNT = 0; - space_rho.unrefine_all_mesh_elements(true); + space_rho->unrefine_all_mesh_elements(true); - space_rho.adjust_element_order(-1, P_INIT); - space_rho_v_x.adjust_element_order(-1, P_INIT); - space_rho_v_y.adjust_element_order(-1, P_INIT); - space_e.adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); } // Adaptivity loop: @@ -232,20 +226,20 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh and setup reference space. int order_increase = 1; - Mesh::ReferenceMeshCreator refMeshCreatorFlow(&mesh); - Mesh* ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, ref_mesh_flow, order_increase); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, ref_mesh_flow, order_increase); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector*> ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector*> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) @@ -255,19 +249,19 @@ int main(int argc, char* argv[]) ndofs_prev = Space::get_num_dofs(ref_spaces_const); - // Project the previous time level solution onto the new fine mesh. - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector(), iteration > 1); + // Project the previous time level solution onto the new fine mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); + OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem dp(&wf, ref_spaces_const); SparseMatrix* matrix = create_matrix(); @@ -283,53 +277,53 @@ int main(int argc, char* argv[]) if(solver->solve()) if(!SHOCK_CAPTURING) Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const); - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter.limit_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter.get_limited_solutions(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - ogProjection.project_global(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), - Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), + Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)) * 100; + Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP && Space::get_num_dofs(ref_spaces_const) > NDOFS_MIN) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); REFINEMENT_COUNT++; - if (Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)) >= NDOF_STOP) done = true; else as++; @@ -340,26 +334,14 @@ int main(int argc, char* argv[]) delete matrix; delete rhs; delete adaptivity; - if(!done) - for(unsigned int i = 0; i < ref_spaces.size(); i++) - delete (ref_spaces_const)[i]; } while (done == false); // Copy the solutions into the previous time level ones. - prev_rho.copy(&rsln_rho); - prev_rho_v_x.copy(&rsln_rho_v_x); - prev_rho_v_y.copy(&rsln_rho_v_y); - prev_e.copy(&rsln_e); - - delete rsln_rho.get_mesh(); - - delete rsln_rho_v_x.get_mesh(); - - delete rsln_rho_v_y.get_mesh(); - - delete rsln_e.get_mesh(); - + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); // Visualization and saving on disk. if((iteration - 1) % EVERY_NTH_STEP == 0) @@ -367,27 +349,24 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - pressure.reinit(); - pressure_view.show(&pressure); - velocity_view.show(&rsln_rho_v_x, &rsln_rho_v_y); - - pressure_view.save_numbered_screenshot("pressure %i.bmp", iteration); - velocity_view.save_numbered_screenshot("Velocity %i.bmp", iteration); + pressure->reinit(); + pressure_view.show(pressure); + velocity_view.show(rsln_rho_v_x, rsln_rho_v_y); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); + pressure->reinit(); Linearizer lin; char filename[40]; sprintf(filename, "Pressure-%i.vtk", iteration - 1); - lin.save_solution_vtk(&pressure, filename, "Pressure", false); + lin.save_solution_vtk(pressure, filename, "Pressure", false); sprintf(filename, "VelocityX-%i.vtk", iteration - 1); - lin.save_solution_vtk(&prev_rho_v_x, filename, "VelocityX", false); + lin.save_solution_vtk(prev_rho_v_x, filename, "VelocityX", false); sprintf(filename, "VelocityY-%i.vtk", iteration - 1); - lin.save_solution_vtk(&prev_rho_v_y, filename, "VelocityY", false); + lin.save_solution_vtk(prev_rho_v_y, filename, "VelocityY", false); sprintf(filename, "Rho-%i.vtk", iteration - 1); - lin.save_solution_vtk(&prev_rho, filename, "Rho", false); + lin.save_solution_vtk(prev_rho, filename, "Rho", false); } } } diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index ce022a2..dd52a62 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -74,31 +74,31 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh, mesh_heat; + MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); - L2Space space_rho(&mesh, P_INIT_FLOW); - L2Space space_rho_v_x(&mesh, P_INIT_FLOW); - L2Space space_rho_v_y(&mesh, P_INIT_FLOW); - L2Space space_e(&mesh, P_INIT_FLOW); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT_FLOW)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT_FLOW)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - InitialSolutionLinearProgress prev_rho(&mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE); - ConstantSolution prev_rho_v_x(&mesh, 0.0); - ConstantSolution prev_rho_v_y(&mesh, 0.0); - InitialSolutionLinearProgress prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE); + MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress (mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); + MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); // Filters for visualization of Mach number, pressure and entropy. - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - VelocityFilter vel_x(Hermes::vector*>(&prev_rho, &prev_rho_v_x)); - VelocityFilter vel_y(Hermes::vector*>(&prev_rho, &prev_rho_v_y)); + MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr vel_x(new VelocityFilter (Hermes::vector >(prev_rho, prev_rho_v_x))); + MeshFunctionSharedPtr vel_y(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_y))); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); @@ -124,10 +124,10 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); // Time stepping loop. for(; t < 10.0; t += time_step) @@ -147,31 +147,31 @@ int main(int argc, char* argv[]) { if(!SHOCK_CAPTURING) { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } } else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) @@ -179,21 +179,21 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - pressure.reinit(); - vel_x.reinit(); - vel_y.reinit(); - pressure_view.show(&pressure); - velocity_view.show(&vel_x, &vel_y); - density_view.show(&prev_rho); + pressure->reinit(); + vel_x->reinit(); + vel_y->reinit(); + pressure_view.show(pressure); + velocity_view.show(vel_x, vel_y); + density_view.show(prev_rho); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); + pressure->reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); } } } diff --git a/2d-advanced/euler/initial_condition.cpp b/2d-advanced/euler/initial_condition.cpp index 5933283..d1a478c 100644 --- a/2d-advanced/euler/initial_condition.cpp +++ b/2d-advanced/euler/initial_condition.cpp @@ -32,7 +32,7 @@ class ConcentrationTimedepEssentialBC : public EssentialBoundaryCondition { public: - InitialSolutionLinearProgress(const Mesh* mesh, double max, double min, double size) : ExactSolutionScalar(mesh), max(max), min(min), size(size) {}; + InitialSolutionLinearProgress(MeshSharedPtr mesh, double max, double min, double size) : ExactSolutionScalar(mesh), max(max), min(min), size(size) {}; virtual double value (double x, double y) const { return min + ((max - min) * (size - y) / size); diff --git a/2d-advanced/euler/joukowski-profile-adapt/main.cpp b/2d-advanced/euler/joukowski-profile-adapt/main.cpp index 61831f8..64c388f 100644 --- a/2d-advanced/euler/joukowski-profile-adapt/main.cpp +++ b/2d-advanced/euler/joukowski-profile-adapt/main.cpp @@ -275,21 +275,6 @@ int main(int argc, char* argv[]) { OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector()); - if(iteration > std::max((int)(continuity.get_num() * EVERY_NTH_STEP + 2), 1) && as > 1) - { - delete rsln_rho.get_mesh(); - - - delete rsln_rho_v_x.get_mesh(); - - - delete rsln_rho_v_y.get_mesh(); - - - delete rsln_e.get_mesh(); - - - } } // Report NDOFs. @@ -413,19 +398,6 @@ int main(int argc, char* argv[]) prev_rho_v_x.copy(&rsln_rho_v_x); prev_rho_v_y.copy(&rsln_rho_v_y); prev_e.copy(&rsln_e); - - delete rsln_rho.get_mesh(); - - - delete rsln_rho_v_x.get_mesh(); - - - delete rsln_rho_v_y.get_mesh(); - - - delete rsln_e.get_mesh(); - - } pressure_view.close(); diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index 66810cc..130d8b3 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -11,7 +11,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // // Equations: Compressible Euler equations, perfect gas state equation. // -// Domain: A rectangular channel, see channel.mesh. +// Domain: A rectangular channel, see channel.mesh-> // // BC: Solid walls, inlet / outlet. In this case there are two inlets (the left, and the upper wall). // @@ -42,9 +42,6 @@ const unsigned int EVERY_NTH_STEP = 1; // Quantitative parameter of the discontinuity detector. double DISCONTINUITY_DETECTOR_PARAM = 1.0; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 0; @@ -135,37 +132,37 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("channel.mesh", &mesh); + mloader.load("channel.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - ConstantSolution sln_rho(&mesh, RHO_INIT); - ConstantSolution sln_rho_v_x(&mesh, RHO_INIT * V1_INIT); - ConstantSolution sln_rho_v_y(&mesh, RHO_INIT * V2_INIT); - ConstantSolution sln_e(&mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA)); + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_INIT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); - ConstantSolution prev_rho(&mesh, RHO_INIT); - ConstantSolution prev_rho_v_x(&mesh, RHO_INIT * V1_INIT); - ConstantSolution prev_rho_v_y(&mesh, RHO_INIT * V2_INIT); - ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA)); + MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_INIT)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); + MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); - ConstantSolution rsln_rho(&mesh, RHO_INIT); - ConstantSolution rsln_rho_v_x(&mesh, RHO_INIT * V1_INIT); - ConstantSolution rsln_rho_v_y(&mesh, RHO_INIT * V2_INIT); - ConstantSolution rsln_e(&mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA)); + MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_INIT)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); + MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); // Initialize weak formulation. Hermes::vector solid_wall_markers; @@ -180,12 +177,12 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, (P_INIT == 0)); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA, RHO_INIT, P_INIT); + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); + MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA, RHO_INIT, P_INIT)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); @@ -199,34 +196,10 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - bool loaded_now = false; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time() + time_step; - iteration = (continuity.get_num()) * EVERY_NTH_STEP + 1; - loaded_now = true; - } - - DiscreteProblemLinear dp(&wf, Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); LinearSolver solver(&dp); - if(P_INIT == 0 && CAND_LIST == H2D_H_ANISO) - dp.set_fvm(); - - Hermes::vector*> spaces_to_delete; - // Time stepping loop. for(; t < T_END && iteration < 25; t += time_step) { @@ -241,14 +214,14 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); REFINEMENT_COUNT = 0; - space_rho.unrefine_all_mesh_elements(true); + space_rho->unrefine_all_mesh_elements(true); - space_rho.adjust_element_order(-1, P_INIT); - space_rho_v_x.adjust_element_order(-1, P_INIT); - space_rho_v_y.adjust_element_order(-1, P_INIT); - space_e.adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); - Space::assign_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + Space::assign_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); } } @@ -263,20 +236,20 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh and setup reference space. int order_increase = (CAND_LIST == H2D_HP_ANISO ? 1 : 0); - Mesh::ReferenceMeshCreator refMeshCreatorFlow(&mesh); - Mesh* ref_mesh = refMeshCreatorFlow.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, ref_mesh, order_increase); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, ref_mesh, order_increase); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, ref_mesh, order_increase); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, ref_mesh, order_increase); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector*> ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector*> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) @@ -286,42 +259,19 @@ int main(int argc, char* argv[]) ndofs_prev = Space::get_num_dofs(ref_spaces_const); - // Project the previous time level solution onto the new fine mesh. - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); - if(loaded_now) - { - loaded_now = false; - - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector *>(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); - } - else - { + // Project the previous time level solution onto the new fine mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; - ogProjection.project_global(ref_spaces_const, Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector()); - if(iteration > 1) - { - for(int i = 0; i < spaces_to_delete.size(); i++) - { - if(i == 0) - delete spaces_to_delete[i]->get_mesh(); - delete spaces_to_delete[i]; - } - } - } - - spaces_to_delete.clear(); - for(int i = 0; i < ref_spaces.size(); i++) - spaces_to_delete.push_back(ref_spaces[i]); + ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); solver.set_spaces(ref_spaces_const); wf.set_current_time_step(time_step); @@ -330,48 +280,47 @@ int main(int argc, char* argv[]) if(!SHOCK_CAPTURING) Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces_const, - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces_const, true); - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter.limit_according_to_detector(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); + flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - flux_limiter.get_limited_solutions(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)); + flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection ogProjection; - ogProjection.project_global(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), - Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), + Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), - Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)) * 100; + Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (Space::get_num_dofs(ref_spaces) > NDOF_STOP || err_est_rel_total < THRESHOLD) { done = true; } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -386,28 +335,25 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - //pressure.reinit(); - //entropy.reinit(); + Mach_number->reinit(); + //pressure->reinit(); + //entropy->reinit(); //pressure_view.show(&pressure); - Mach_number_view.show(&Mach_number); - //pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + Mach_number_view.show(Mach_number); space_view.show(ref_space_rho); - space_view.save_numbered_screenshot("Space-%u.bmp", iteration - 1, true); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); - Mach_number.reinit(); + pressure->reinit(); + Mach_number->reinit(); Linearizer lin; char filename[40]; //sprintf(filename, "Pressure-%i.vtk", iteration - 1); //lin.save_solution_vtk(&pressure, filename, "Pressure", false); sprintf(filename, "Mach number-%i.vtk", iteration - 1); - lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false); + lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); sprintf(filename, "Mesh-%i.vtk", iteration - 1); orderizer.save_mesh_vtk(ref_space_rho, filename); sprintf(filename, "Space-%i.vtk", iteration - 1); @@ -422,10 +368,10 @@ int main(int argc, char* argv[]) // Copy the solutions into the previous time level ones. - prev_rho.copy(&rsln_rho); - prev_rho_v_x.copy(&rsln_rho_v_x); - prev_rho_v_y.copy(&rsln_rho_v_y); - prev_e.copy(&rsln_e); + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); } if(HERMES_VISUALIZATION) diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index 85e555b..6109818 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -12,7 +12,7 @@ using namespace Hermes::Hermes2D::Views; // // Equations: Compressible Euler equations, perfect gas state equation. // -// Domain: A rectangular channel, see channel.mesh. +// Domain: A rectangular channel, see channel.mesh-> // // BC: Solid walls, inlet / outlet. In this case there are two inlets (the left, and the upper wall). // @@ -43,9 +43,6 @@ double DISCONTINUITY_DETECTOR_PARAM = 1.0; const double NU_1 = 0.1; const double NU_2 = 0.1; -// For saving/loading of solution. -bool REUSE_SOLUTION = false; - // Initial polynomial degree. const int P_INIT = 1; // Number of initial uniform mesh refinements. @@ -94,28 +91,28 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { // Load the mesh. - Mesh mesh; + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("channel.mesh", &mesh); + mloader.load("channel.mesh", mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(0, true); + mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); - L2Space space_rho_v_x(&mesh, P_INIT); - L2Space space_rho_v_y(&mesh, P_INIT); - L2Space space_e(&mesh, P_INIT); - L2Space space_stabilization(&mesh, 0); - int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. - ConstantSolution prev_rho(&mesh, RHO_INIT); - ConstantSolution prev_rho_v_x(&mesh, RHO_INIT * V1_INIT); - ConstantSolution prev_rho_v_y(&mesh, RHO_INIT * V2_INIT); - ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA)); + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_INIT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); // Initialize weak formulation. Hermes::vector solid_wall_markers; @@ -130,12 +127,12 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, (P_INIT == 0)); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); + ScalarView pressure_view("Pressure", new WinGeom(700, 400, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 700, 600, 300)); ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); @@ -146,39 +143,17 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Look for a saved solution on the disk. - CalculationContinuity continuity(CalculationContinuity::onlyTime); - int iteration = 0; double t = 0; - - if(REUSE_SOLUTION && continuity.have_record_available()) - { - continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); - space_rho.copy(spaceVector[0], &mesh); - space_rho_v_x.copy(spaceVector[1], &mesh); - space_rho_v_y.copy(spaceVector[2], &mesh); - space_e.copy(spaceVector[3], &mesh); - continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)); - continuity.get_last_record()->load_time_step_length(time_step); - t = continuity.get_last_record()->get_time(); - iteration = continuity.get_num(); - } - - EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - wf.set_stabilization(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, NU_1, NU_2); + wf.set_stabilization(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, NU_1, NU_2); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); + DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); LinearSolver solver(&dp); solver.output_matrix(); solver.output_rhs(); - // If the FE problem is in fact a FV problem. - if(P_INIT == 0) - dp.set_fvm(); + int iteration = 0.; + double t = 0.0; // Time stepping loop. for(; t < 6.0; t += time_step) @@ -196,28 +171,28 @@ int main(int argc, char* argv[]) solver.solve(); if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) { - Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } - CFL.calculate_semi_implicit(Hermes::vector *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); + CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); // Visualization. if((iteration - 1) % EVERY_NTH_STEP == 0) @@ -225,25 +200,23 @@ int main(int argc, char* argv[]) // Hermes visualization. if(HERMES_VISUALIZATION) { - Mach_number.reinit(); - pressure.reinit(); - pressure_view.show(&pressure); - Mach_number_view.show(&Mach_number); - pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true); - Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true); + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure); + Mach_number_view.show(Mach_number); } // Output solution in VTK format. if(VTK_VISUALIZATION) { - pressure.reinit(); - Mach_number.reinit(); + pressure->reinit(); + Mach_number->reinit(); Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); Linearizer lin_mach; sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); } } } From f0575c42becda1319df397a0764fff787e59f122 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 14 Mar 2013 10:50:17 +0100 Subject: [PATCH 06/64] Update of examples. --- 2d-advanced/euler/forward-step-adapt/main.cpp | 9 ++------- 2d-advanced/euler/forward-step/main.cpp | 4 ++-- 2d-advanced/euler/heating-flow-coupling/main.cpp | 2 -- 2d-advanced/euler/reflected-shock-adapt/main.cpp | 2 ++ 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index 8957a03..d737870 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -179,6 +179,8 @@ int main(int argc, char* argv[]) CFLCalculation CFL(CFL_NUMBER, KAPPA); // Time stepping loop. + double t = 0.0; + int iteration = 0; for(; t < 14.5; t += time_step) { if(t > 0.3) @@ -372,13 +374,6 @@ int main(int argc, char* argv[]) sprintf(filename, "Mesh-%i.vtk", iteration); ord.save_mesh_vtk(ref_space_rho, filename); } - - // Save the progress. - if(iteration > 1) - { - continuity.add_record(t, Hermes::vector(mesh, mesh, mesh, mesh), Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), time_step); - } } // Clean up. diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index fe36652..1f5a723 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -89,8 +89,8 @@ int main(int argc, char* argv[]) // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("ffs.mesh", &mesh); - mesh.refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); + mloader.load("ffs.mesh", mesh); + mesh->refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 4c3a5f7..701f20c 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -83,8 +83,6 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - Hermes2DApi.set_integral_param_value(numThreads, 1); - // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index 130d8b3..eeb4e68 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -201,6 +201,8 @@ int main(int argc, char* argv[]) LinearSolver solver(&dp); // Time stepping loop. + double t = 0.0; + int iteration = 0; for(; t < T_END && iteration < 25; t += time_step) { CFL.set_number(CFL_NUMBER + (t/4.0) * 1.0); From 6acefc78adfba6297eae2e1561a50b3d3bfb5fa7 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 14 Mar 2013 16:24:35 +0100 Subject: [PATCH 07/64] Work on examples. --- 1d/layer-boundary/main.cpp | 24 ++++---- 1d/moving-front/main.cpp | 32 +++++----- 1d/poisson/main.cpp | 10 ++-- 1d/system/main.cpp | 24 ++++---- 2d-advanced/acoustics/apartment/main.cpp | 24 ++++---- 2d-advanced/acoustics/horn-axisym/main.cpp | 26 ++++---- .../linear-advection-dg-adapt/main.cpp | 20 +++---- .../linear-advection-diffusion/main.cpp | 26 ++++---- .../elasticity-linear/bracket/main.cpp | 20 +++---- 2d-advanced/elasticity-linear/crack/main.cpp | 18 +++--- .../heat-and-moisture-adapt/main.cpp | 24 ++++---- .../main.cpp | 36 +++++------ 2d-advanced/helmholtz/waveguide/main.cpp | 12 ++-- 2d-advanced/maxwell/magnetostatics/main.cpp | 14 ++--- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 18 +++--- 2d-advanced/maxwell/microwave-oven/main.cpp | 28 ++++----- .../maxwell/resonator-time-domain-I/main.cpp | 16 ++--- .../resonator-time-domain-II-ie/main.cpp | 18 +++--- .../resonator-time-domain-II-rk/main.cpp | 18 +++--- .../local-projection-test/main.cpp | 12 ++-- 2d-advanced/navier-stokes/bearing/main.cpp | 28 ++++----- .../circular-obstacle-adapt/main.cpp | 54 ++++++++--------- .../navier-stokes/circular-obstacle/main.cpp | 34 +++++------ .../navier-stokes/driven-cavity/main.cpp | 26 ++++---- .../navier-stokes/ns-heat-subdomains/main.cpp | 22 +++---- .../navier-stokes/rayleigh-benard/main.cpp | 32 +++++----- .../np-poisson-timedep-adapt/main.cpp | 46 +++++++------- 2d-advanced/neutronics/saphir/main.cpp | 24 ++++---- 2d-advanced/richards/basic-ie-newton/main.cpp | 14 ++--- 2d-advanced/richards/basic-ie-picard/main.cpp | 14 ++--- .../richards/basic-rk-newton-adapt/main.cpp | 26 ++++---- 2d-advanced/richards/basic-rk-newton/main.cpp | 14 ++--- .../richards/capillary-barrier-adapt/main.cpp | 60 +++++++++---------- .../richards/capillary-barrier-rk/main.cpp | 16 ++--- .../gross-pitaevski-adapt/main.cpp | 32 +++++----- .../schroedinger/gross-pitaevski/main.cpp | 14 ++--- 2d-advanced/wave-equation/wave-1/main.cpp | 18 +++--- 2d-benchmarks-general/layer-boundary/main.cpp | 22 +++---- 2d-benchmarks-general/layer-interior/main.cpp | 24 ++++---- 2d-benchmarks-general/lshape/main.cpp | 22 +++---- .../moving-front-space-adapt/main.cpp | 32 +++++----- 2d-benchmarks-general/nonsym-check/main.cpp | 20 +++---- 2d-benchmarks-general/smooth-aniso-x/main.cpp | 20 +++---- 2d-benchmarks-general/smooth-aniso-y/main.cpp | 20 +++---- 2d-benchmarks-general/smooth-iso/main.cpp | 22 +++---- .../01-analytic-solution/main.cpp | 24 ++++---- .../02-reentrant-corner/main.cpp | 26 ++++---- .../03-linear-elasticity/main.cpp | 16 ++--- .../04-exponential-peak/main.cpp | 22 +++---- 2d-benchmarks-nist/05-battery/main.cpp | 24 ++++---- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 22 +++---- .../07-boundary-line-singularity/main.cpp | 22 +++---- 2d-benchmarks-nist/08-oscillatory/main.cpp | 22 +++---- 2d-benchmarks-nist/09-wave-front/main.cpp | 24 ++++---- .../10-interior-line-singularity/main.cpp | 22 +++---- 2d-benchmarks-nist/11-kellogg/main.cpp | 20 +++---- .../12-multiple-difficulties/main.cpp | 20 +++---- 57 files changed, 670 insertions(+), 670 deletions(-) diff --git a/1d/layer-boundary/main.cpp b/1d/layer-boundary/main.cpp index 21a53fb..d556c12 100644 --- a/1d/layer-boundary/main.cpp +++ b/1d/layer-boundary/main.cpp @@ -65,20 +65,20 @@ const double K = 1e2; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH1DXML mloader; - mloader.load("domain.xml", &mesh); + mloader.load("domain.xml", mesh); // Perform initial mesh refinement. // Split elements vertically. int refinement_type = 2; - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(refinement_type); - mesh.refine_towards_boundary("Left", INIT_REF_NUM_BDY); - mesh.refine_towards_boundary("Right", INIT_REF_NUM_BDY); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(refinement_type); + mesh->refine_towards_boundary("Left", INIT_REF_NUM_BDY); + mesh->refine_towards_boundary("Right", INIT_REF_NUM_BDY); // Define exact solution. - CustomExactSolution exact_sln(&mesh, K); + CustomExactSolution exact_sln(mesh, K); // Define right side vector. CustomFunction f(K); @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -123,7 +123,7 @@ int main(int argc, char* argv[]) int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. int refinement_type = 0; - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -195,7 +195,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/1d/moving-front/main.cpp b/1d/moving-front/main.cpp index d412ebd..57a30cf 100644 --- a/1d/moving-front/main.cpp +++ b/1d/moving-front/main.cpp @@ -72,7 +72,7 @@ const int NDOF_STOP = 1000; MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Newton's method -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH1DXML mloader; try @@ -129,18 +129,18 @@ int main(int argc, char* argv[]) // Perform initial mesh refinements. int refinement_type = 2; // Split elements vertically. - for(int i = 0; i < INIT_REF_NUM; i++) basemesh.refine_all_elements(refinement_type, true); - mesh.copy(&basemesh); + for(int i = 0; i < INIT_REF_NUM; i++) basemesh->refine_all_elements(refinement_type, true); + mesh->copy(&basemesh); // Exact solution. - CustomExactSolution exact_sln(&mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); + CustomExactSolution exact_sln(mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); // Initialize boundary conditions. DefaultEssentialBCConst bc_essential(Hermes::vector("Left", "Right"), 0); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof_coarse = space.get_num_dofs(); // Initialize the weak formulation @@ -148,8 +148,8 @@ int main(int argc, char* argv[]) CustomWeakFormPoisson wf(new Hermes::Hermes1DFunction(-1.0), &f); // Previous and next time level solution. - ZeroSolution sln_time_prev(&mesh); - Solution sln_time_new(&mesh); + ZeroSolution sln_time_prev(mesh); + Solution sln_time_new(mesh); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -173,13 +173,13 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; - case 2: mesh.unrefine_all_elements(); + case 2: mesh->unrefine_all_elements(); space.set_uniform_order(P_INIT); break; - case 3: mesh.unrefine_all_elements(); + case 3: mesh->unrefine_all_elements(); space.adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); @@ -201,7 +201,7 @@ int main(int argc, char* argv[]) int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. int refinement_type = 0; - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -232,7 +232,7 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); } - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(&space, &sln_time_new, &sln_coarse); @@ -246,11 +246,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (space.get_num_dofs() >= NDOF_STOP) @@ -270,7 +270,7 @@ int main(int argc, char* argv[]) } while (done == false); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution, time %g", current_time); sview.set_title(title); diff --git a/1d/poisson/main.cpp b/1d/poisson/main.cpp index 226e29f..488b0a0 100644 --- a/1d/poisson/main.cpp +++ b/1d/poisson/main.cpp @@ -38,15 +38,15 @@ const double FIXED_BDY_TEMP = 20.0; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH1DXML mloader; - mloader.load("domain.xml", &mesh); + mloader.load("domain.xml", mesh); // Perform initial mesh refinements (optional). // Split elements vertically. int refinement_type = 2; - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(refinement_type); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(refinement_type); // Initialize the weak formulation. CustomWeakFormPoisson wf("Al", new Hermes::Hermes1DFunction(LAMBDA_AL), "Cu", @@ -59,7 +59,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); diff --git a/1d/system/main.cpp b/1d/system/main.cpp index 89d0ab2..e7212ca 100644 --- a/1d/system/main.cpp +++ b/1d/system/main.cpp @@ -39,7 +39,7 @@ const int P_INIT_V = 1; // Number of initial boundary refinements const int INIT_REF_BDY = 5; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh. +// MULTI = false ... use single-mesh-> // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -93,28 +93,28 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. + // Load the mesh-> Mesh u_mesh, v_mesh; MeshReaderH1DXML mloader; mloader.load("domain.xml", &u_mesh); - u_mesh.refine_all_elements(); + u_mesh->refine_all_elements(); if (MULTI == false) { - u_mesh.refine_towards_boundary("Left", INIT_REF_BDY); + u_mesh->refine_towards_boundary("Left", INIT_REF_BDY); // Minus one for the sake of mesh symmetry. - if (INIT_REF_BDY > 1) u_mesh.refine_towards_boundary("Right", INIT_REF_BDY - 1); + if (INIT_REF_BDY > 1) u_mesh->refine_towards_boundary("Right", INIT_REF_BDY - 1); } // Create initial mesh (master mesh). - v_mesh.copy(&u_mesh); + v_mesh->copy(&u_mesh); // Initial mesh refinements in the v_mesh towards the boundary. if (MULTI == true) { - v_mesh.refine_towards_boundary("Left", INIT_REF_BDY); + v_mesh->refine_towards_boundary("Left", INIT_REF_BDY); // Minus one for the sake of mesh symmetry. - if (INIT_REF_BDY > 1) v_mesh.refine_towards_boundary("Right", INIT_REF_BDY - 1); + if (INIT_REF_BDY > 1) v_mesh->refine_towards_boundary("Right", INIT_REF_BDY - 1); } #ifdef WITH_EXACT_SOLUTION @@ -192,7 +192,7 @@ int main(int argc, char* argv[]) int ndof_ref = Space::get_num_dofs(ref_spaces_const); // Initialize reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem dp(&wf, ref_spaces_const); NewtonSolver newton(&dp); @@ -216,7 +216,7 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector *>(&u_ref_sln, &v_ref_sln)); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solutions on coarse meshes."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u_space, &v_space), Hermes::vector *>(&u_ref_sln, &v_ref_sln), @@ -287,12 +287,12 @@ int main(int argc, char* argv[]) graph_cpu_exact.save("conv_cpu_exact.dat"); #endif - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index de34518..3f63747 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -75,24 +75,24 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); //MeshView mv("Initial mesh", new WinGeom(0, 0, 400, 400)); - //mv.show(&mesh); + //mv.show(mesh); //View::wait(HERMES_WAIT_KEYPRESS); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions. DefaultEssentialBCConst > bc_essential("Source", P_SOURCE); EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(&mesh, &bcs, P_INIT); + H1Space > space(mesh, &bcs, P_INIT); int ndof = Space >::get_num_dofs(&space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -131,7 +131,7 @@ int main(int argc, char* argv[]) int ndof_ref = Space >::get_num_dofs(ref_space); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem > dp(&wf, ref_space); // Time measurement. @@ -151,8 +151,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the Solution > sln. Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // Time measurement. @@ -181,11 +181,11 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } if (Space >::get_num_dofs(&space) >= NDOF_STOP) done = true; diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index db96271..880592d 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -8,7 +8,7 @@ // // PDE: -div(1/rho grad p) - omega**2 / (rho c**2) * p = 0. // -// Domain: Axisymmetric geometry of a horn, see mesh file domain.mesh. +// Domain: Axisymmetric geometry of a horn, see mesh file domain.mesh-> // // BC: Prescribed pressure on the bottom edge, // zero Neumann on the walls and on the axis of symmetry, @@ -75,24 +75,24 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); //MeshView mv("Initial mesh", new WinGeom(0, 0, 400, 400)); - //mv.show(&mesh); + //mv.show(mesh); //View::wait(HERMES_WAIT_KEYPRESS); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions. DefaultEssentialBCConst > bc_essential("Source", P_SOURCE); EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(&mesh, &bcs, P_INIT); + H1Space > space(mesh, &bcs, P_INIT); int ndof = Space >::get_num_dofs(&space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); @@ -125,7 +125,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) int ndof_ref = Space >::get_num_dofs(ref_space); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem > dp(&wf, ref_space); // Time measurement. @@ -153,8 +153,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the Solution > sln. Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // Time measurement. @@ -183,11 +183,11 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } if (Space >::get_num_dofs(&space) >= NDOF_STOP) done = true; diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index 297df73..041b32e 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -59,16 +59,16 @@ const char* preconditioner = "jacobi"; int main(int argc, char* args[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinement. - for (int i=0; irefine_all_elements(); // Create an L2 space. - L2Space space(&mesh, P_INIT); + L2Space space(mesh, P_INIT); // Initialize refinement selector. L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -79,7 +79,7 @@ int main(int argc, char* args[]) // DOF and CPU convergence graphs. SimpleGraph graph_dof_est, graph_cpu_est; - // Display the mesh. + // Display the mesh-> OrderView oview("Coarse mesh", new WinGeom(0, 0, 440, 350)); oview.show(&space); @@ -87,7 +87,7 @@ int main(int argc, char* args[]) Solution ref_sln; // Initialize the weak formulation. - CustomWeakForm wf("Bdy_bottom_left", &mesh); + CustomWeakForm wf("Bdy_bottom_left", mesh); ScalarView view1("Solution", new WinGeom(900, 0, 450, 350)); view1.fix_scale_width(60); @@ -100,7 +100,7 @@ int main(int argc, char* args[]) { // Construct globally refined reference mesh // and setup reference space. - Mesh::ReferenceMeshCreator ref_mesh_creator(&mesh); + Mesh::ReferenceMeshCreator ref_mesh_creator(mesh); Mesh* ref_mesh = ref_mesh_creator.create_ref_mesh(); Space::ReferenceSpaceCreator ref_space_creator(&space, ref_mesh); Space* ref_space = ref_space_creator.create_ref_space(); @@ -117,7 +117,7 @@ int main(int argc, char* args[]) { std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln, HERMES_L2_NORM); @@ -137,7 +137,7 @@ int main(int argc, char* args[]) graph_dof_est.add_values(Space::get_num_dofs(&space), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); - // If err_est_rel too large, adapt the mesh. + // If err_est_rel too large, adapt the mesh-> if(err_est_rel < ERR_STOP) done = true; else { diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 2e7cf13..e79d63b 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -70,15 +70,15 @@ const double B1 = 1., B2 = 1.; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); - // mloader.load("square_tri.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinement. - for (int i=0; irefine_all_elements(); + mesh->refine_towards_boundary("Layer", INIT_REF_NUM_BDY); // Initialize the weak formulation. WeakFormLinearAdvectionDiffusion wf(STABILIZATION_ON, SHOCK_CAPTURING_ON, B1, B2, EPSILON); @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(Hermes::vector *>(&bc_rest, &bc_layer)); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); WinGeom* sln_win_geom = new WinGeom(0, 0, 440, 350); WinGeom* mesh_win_geom = new WinGeom(450, 0, 400, 350); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem* dp = new DiscreteProblem(&wf, ref_space); dp->assemble(matrix, rhs); @@ -146,8 +146,8 @@ int main(int argc, char* argv[]) if(solver->solve()) Solution::vector_to_solution(solver->get_sln_vector(), ref_space, &ref_sln); else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // Time measurement. @@ -178,11 +178,11 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); // Increase the counter of performed adaptivity steps. diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 1fbaf61..2b4ade9 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -21,7 +21,7 @@ // Initial polynomial degree of all mesh elements. const int P_INIT = 2; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh. +// MULTI = false ... use single-mesh-> // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -86,18 +86,18 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. + // Load the mesh-> Mesh u1_mesh, u2_mesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &u1_mesh); // Initial mesh refinements. - u1_mesh.refine_element_id(1); - u1_mesh.refine_element_id(4); + u1_mesh->refine_element_id(1); + u1_mesh->refine_element_id(4); // Create initial mesh for the vertical displacement component. // This also initializes the multimesh hp-FEM. - u2_mesh.copy(&u1_mesh); + u2_mesh->copy(&u1_mesh); // Initialize boundary conditions. DefaultEssentialBCConst zero_disp("bdy_right", 0.0); @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Perform Newton's iteration. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); try { newton.set_newton_max_iter(NEWTON_MAX_ITER); @@ -190,8 +190,8 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector *>(&u1_sln_ref, &u2_sln_ref)); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u1_space, &u2_space), Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), Hermes::vector *>(&u1_sln, &u2_sln)); @@ -247,12 +247,12 @@ int main(int argc, char* argv[]) graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); } diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index d6f7070..9a43296 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -25,7 +25,7 @@ const int INIT_REF_NUM = 0; const int P_INIT_U1 = 2; // Initial polynomial degree of mesh elements (v-displacement). const int P_INIT_U2 = 2; -// true = use multi-mesh, false = use single-mesh. +// true = use multi-mesh, false = use single-mesh-> // Note: in the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -89,17 +89,17 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. + // Load the mesh-> Mesh u1_mesh, u2_mesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &u1_mesh); // Perform initial uniform mesh refinement. - for (int i=0; i < INIT_REF_NUM; i++) u1_mesh.refine_all_elements(); + for (int i=0; i < INIT_REF_NUM; i++) u1_mesh->refine_all_elements(); // Create initial mesh for the vertical displacement component. // This also initializes the multimesh hp-FEM. - u2_mesh.copy(&u1_mesh); + u2_mesh->copy(&u1_mesh); // Initialize boundary conditions. DefaultEssentialBCConst zero_disp("bdy left", 0.0); @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Perform Newton's iteration. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); try { newton.set_newton_max_iter(NEWTON_MAX_ITER); @@ -192,8 +192,8 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector *>(&u1_sln_ref, &u2_sln_ref)); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u1_space, &u2_space), Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), Hermes::vector *>(&u1_sln, &u2_sln)); @@ -248,12 +248,12 @@ int main(int argc, char* argv[]) graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); } diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index 4b5ee74..8b429aa 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -19,7 +19,7 @@ const double W_SCALING_FACTOR = 100.; // Initial polynomial degrees. const int P_INIT = 2; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh. +// MULTI = false ... use single-mesh-> // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -67,7 +67,7 @@ const int NDOF_STOP = 100000; MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Newton's method -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 50; @@ -132,15 +132,15 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh basemesh, T_mesh, w_mesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &basemesh); // Create temperature and moisture meshes. // This also initializes the multimesh hp-FEM. - T_mesh.copy(&basemesh); - w_mesh.copy(&basemesh); + T_mesh->copy(&basemesh); + w_mesh->copy(&basemesh); // Initialize boundary conditions. EssentialBCNonConst temp_reactor("bdy_react", REACTOR_START_TIME, T_INITIAL, T_REACTOR_MAX); @@ -203,20 +203,20 @@ int main(int argc, char* argv[]) if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: T_mesh.copy(&basemesh); - w_mesh.copy(&basemesh); + case 1: T_mesh->copy(&basemesh); + w_mesh->copy(&basemesh); T_space.set_uniform_order(P_INIT); w_space.set_uniform_order(P_INIT); break; - case 2: T_mesh.unrefine_all_elements(); + case 2: T_mesh->unrefine_all_elements(); if(MULTI) - w_mesh.unrefine_all_elements(); + w_mesh->unrefine_all_elements(); T_space.set_uniform_order(P_INIT); w_space.set_uniform_order(P_INIT); break; - case 3: T_mesh.unrefine_all_elements(); + case 3: T_mesh->unrefine_all_elements(); if(MULTI) - w_mesh.unrefine_all_elements(); + w_mesh->unrefine_all_elements(); T_space.adjust_element_order(-1, -1, P_INIT, P_INIT); w_space.adjust_element_order(-1, -1, P_INIT, P_INIT); break; @@ -306,7 +306,7 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space::get_num_dofs(Hermes::vector *>(&T_space, &w_space)) >= NDOF_STOP) diff --git a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp index 281741c..3142b54 100644 --- a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp +++ b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp @@ -95,9 +95,9 @@ const double TIME_STEP_INC_RATIO = 1.1; const double TIME_STEP_DEC_RATIO = 0.8; // Newton's method. -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_COARSE = 0.001; -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_FINE = 0.005; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 100; @@ -156,27 +156,27 @@ int main(int argc, char* argv[]) ADAPTIVE_TIME_STEP_ON = false; } - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("wall.mesh", &basemesh); - mesh.copy(&basemesh); + mesh->copy(&basemesh); // Perform initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary(BDY_RIGHT, 2); - mesh.refine_towards_boundary(BDY_FIRE, INIT_REF_NUM_BDY); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary(BDY_RIGHT, 2); + mesh->refine_towards_boundary(BDY_FIRE, INIT_REF_NUM_BDY); // Initialize essential boundary conditions (none). EssentialBCs bcs; // Initialize an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = Space::get_num_dofs(&space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. - ConstantSolution sln_prev_time(&mesh, TEMP_INIT); + ConstantSolution sln_prev_time(mesh, TEMP_INIT); // Initialize the weak formulation. double current_time = 0; @@ -217,7 +217,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; case 2: space.unrefine_all_mesh_elements(); @@ -237,18 +237,18 @@ int main(int argc, char* argv[]) // Spatial adaptivity loop. Note: sln_prev_time must not be // changed during spatial adaptivity. Solution ref_sln; - Solution time_error_fn(&mesh); + Solution time_error_fn(mesh); bool done = false; int as = 1; double err_est; do { // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); Space* ref_space = refSpaceCreator.create_ref_space(); - // Initialize Runge-Kutta time stepping on the reference mesh. + // Initialize Runge-Kutta time stepping on the reference mesh-> RungeKutta runge_kutta(&wf, ref_space, &bt); try @@ -267,7 +267,7 @@ int main(int argc, char* argv[]) return -1; } - // Runge-Kutta step on the fine mesh. + // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, tau = %g s, stages: %d).", current_time, time_step, bt.get_size()); bool verbose = true; @@ -341,7 +341,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Solution sln; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); ogProjection.project_global(&space, &ref_sln, &sln); @@ -363,11 +363,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_rel_space); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space::get_num_dofs(&space) >= NDOF_STOP) @@ -384,7 +384,7 @@ int main(int argc, char* argv[]) } while (done == false); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution, time %g s", current_time); sln_view.set_title(title); diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index f04b046..e87c012 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -63,14 +63,14 @@ const double h = 0.1; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Perform uniform mesh refinement. // 2 is for vertical split. - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(2); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(2); // Initialize boundary conditions DefaultEssentialBCConst bc1("Bdy_perfect", 0.0); @@ -80,8 +80,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs_im(Hermes::vector *>(&bc1, &bc3)); // Create an H1 space with default shapeset. - H1Space e_r_space(&mesh, &bcs, P_INIT); - H1Space e_i_space(&mesh, &bcs_im, P_INIT); + H1Space e_r_space(mesh, &bcs, P_INIT); + H1Space e_i_space(mesh, &bcs_im, P_INIT); int ndof = Space::get_num_dofs(&e_r_space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 5c5b90e..6623980 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -69,20 +69,20 @@ int main(int argc, char* argv[]) plot_derivative = true; mu_inv_iron.plot("spline_der.dat", interval_extension, plot_derivative); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("actuator.mesh", &mesh); + mloader.load("actuator.mesh", mesh); // Perform initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions. DefaultEssentialBCConst bc_essential(BDY_DIRICHLET, 0.0); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, &space); // Initialize the solution. - ConstantSolution sln(&mesh, INIT_COND); + ConstantSolution sln(mesh, INIT_COND); // Project the initial condition on the FE space to obtain initial // coefficient vector for the Newton's method. @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) // Cleanup. delete [] coeff_vec; - // Visualise the solution and mesh. + // Visualise the solution and mesh-> ScalarView s_view1("Vector potential", new WinGeom(0, 0, 350, 450)); FilterVectorPotential vector_potential(Hermes::vector *>(&sln, &sln), Hermes::vector(H2D_FN_VAL, H2D_FN_VAL)); diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 3e1146c..9a6c86d 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh E_mesh, H_mesh, P_mesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &E_mesh); @@ -159,9 +159,9 @@ int main(int argc, char* argv[]) // Perform initial mesh refinemets. for (int i = 0; i < INIT_REF_NUM; i++) { - E_mesh.refine_all_elements(); - H_mesh.refine_all_elements(); - P_mesh.refine_all_elements(); + E_mesh->refine_all_elements(); + H_mesh->refine_all_elements(); + P_mesh->refine_all_elements(); } // Initialize solutions. @@ -183,7 +183,7 @@ int main(int argc, char* argv[]) HcurlSpace E_space(&E_mesh, &bcs, P_INIT); H1Space H_space(&H_mesh, NULL, P_INIT); - //L2Space H_space(&mesh, P_INIT); + //L2Space H_space(mesh, P_INIT); HcurlSpace P_space(&P_mesh, &bcs, P_INIT); Hermes::vector *> spaces = Hermes::vector *>(&E_space, &H_space, &P_space); @@ -314,8 +314,8 @@ int main(int argc, char* argv[]) P2_view.set_title(title); P2_view.show(&P_time_new, H2D_FN_VAL_1); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&E_space, &H_space, &P_space), Hermes::vector*>(&E_time_new, &H_time_new, &P_time_new), Hermes::vector*>(&E_time_new_coarse, &H_time_new_coarse, &P_time_new_coarse)); @@ -329,7 +329,7 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("Error estimate: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP || as > ADAPTIVITY_STEPS - 1) { if(err_est_rel_total < ERR_STOP) @@ -340,7 +340,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index ba579d2..70ba5e1 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -36,7 +36,7 @@ const int INIT_REF_NUM = 0; // is for Whitney elements. const int P_INIT = 2; // if ALIGN_MESH == true, curvilinear elements aligned with the -// circular load are used, otherwise one uses a non-aligned mesh. +// circular load are used, otherwise one uses a non-aligned mesh-> const bool ALIGN_MESH = false; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. @@ -96,16 +96,16 @@ const std::string BDY_CURRENT = "b1"; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; if (ALIGN_MESH) - mloader.load("oven_load_circle.mesh", &mesh); + mloader.load("oven_load_circle.mesh", mesh); else - mloader.load("oven_load_square.mesh", &mesh); + mloader.load("oven_load_square.mesh", mesh); // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions DefaultEssentialBCConst > bc_essential(BDY_PERFECT_CONDUCTOR, std::complex(0.0, 0.0)); @@ -113,12 +113,12 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an Hcurl space with default shapeset. - HcurlSpace > space(&mesh, &bcs, P_INIT); + HcurlSpace > space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. - CustomWeakForm wf(e_0, mu_0, mu_r, kappa, omega, J, ALIGN_MESH, &mesh, BDY_CURRENT); + CustomWeakForm wf(e_0, mu_0, mu_r, kappa, omega, J, ALIGN_MESH, mesh, BDY_CURRENT); // Initialize coarse and reference mesh solution. Solution > sln, ref_sln; @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) int ndof_ref = Space >::get_num_dofs(ref_space); // Initialize reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); DiscreteProblem > dp(&wf, ref_space); // Time measurement. @@ -174,8 +174,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the Solution > sln. Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // View the coarse mesh solution and polynomial orders. @@ -214,11 +214,11 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } if (space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp index 552ac14..0689c93 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp @@ -59,17 +59,17 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_sln(&mesh); - ZeroSolution B_sln(&mesh); + CustomInitialConditionWave E_sln(mesh); + ZeroSolution B_sln(mesh); Hermes::vector*> slns(&E_sln, &B_sln); // Initialize the weak formulation. @@ -81,8 +81,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs_B; // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(&mesh, &bcs_E, P_INIT); - H1Space B_space(&mesh, &bcs_B, P_INIT); + HcurlSpace E_space(mesh, &bcs_E, P_INIT); + H1Space B_space(mesh, &bcs_B, P_INIT); Hermes::vector *> spaces(&E_space, &B_space); Hermes::vector *> spaces_mutable(&E_space, &B_space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(spaces)); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index db1c86e..a0f1cc7 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -20,7 +20,7 @@ // \frac{E^{n+1} - E^{n}}{tau} - F^{n+1} = 0, // \frac{F^{n+1} - F^{n}}{tau} + SPEED_OF_LIGHT**2 * curl curl E^{n+1} = 0. // -// Domain: Square (-pi/2, pi/2) x (-pi/2, pi/2)... See mesh file domain.mesh. +// Domain: Square (-pi/2, pi/2) x (-pi/2, pi/2)... See mesh file domain.mesh-> // // BC: E \times \nu = 0 on the boundary (perfect conductor), // F \times \nu = 0 on the boundary (E \times \nu = 0 => \partial E / \partial t \times \nu = 0). @@ -51,17 +51,17 @@ const double C_SQUARED = 1; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_sln(&mesh); - ZeroSolutionVector F_sln(&mesh); + CustomInitialConditionWave E_sln(mesh); + ZeroSolutionVector F_sln(mesh); Hermes::vector*> slns(&E_sln, &F_sln); // Initialize the weak formulation. @@ -72,8 +72,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(&mesh, &bcs, P_INIT); - HcurlSpace F_space(&mesh, &bcs, P_INIT); + HcurlSpace E_space(mesh, &bcs, P_INIT); + HcurlSpace F_space(mesh, &bcs, P_INIT); Hermes::vector *> spaces = Hermes::vector *>(&E_space, &F_space); int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp index 8ff8e05..c009db7 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp @@ -20,7 +20,7 @@ // \frac{\partial E}{\partial t} = F, // \frac{\partial F}{\partial t} = -SPEED_OF_LIGHT**2 * curl curl E. // -// Domain: Square (-pi/2, pi/2) x (-pi/2, pi/2)... See mesh file domain.mesh. +// Domain: Square (-pi/2, pi/2) x (-pi/2, pi/2)... See mesh file domain.mesh-> // // BC: E \times \nu = 0 on the boundary (perfect conductor), // F \times \nu = 0 on the boundary (E \times \nu = 0 => \partial E / \partial t \times \nu = 0). @@ -75,17 +75,17 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_time_prev(&mesh); - ZeroSolutionVector F_time_prev(&mesh); + CustomInitialConditionWave E_time_prev(mesh); + ZeroSolutionVector F_time_prev(mesh); Hermes::vector*> slns_time_prev(&E_time_prev, &F_time_prev); Solution E_time_new, F_time_new; Hermes::vector*> slns_time_new(&E_time_new, &F_time_new); @@ -98,8 +98,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(&mesh, &bcs, P_INIT); - HcurlSpace F_space(&mesh, &bcs, P_INIT); + HcurlSpace E_space(mesh, &bcs, P_INIT); + HcurlSpace F_space(mesh, &bcs, P_INIT); Hermes::vector *> spaces(&E_space, &F_space); int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); diff --git a/2d-advanced/miscellaneous/local-projection-test/main.cpp b/2d-advanced/miscellaneous/local-projection-test/main.cpp index 42c9840..f4bee7f 100644 --- a/2d-advanced/miscellaneous/local-projection-test/main.cpp +++ b/2d-advanced/miscellaneous/local-projection-test/main.cpp @@ -51,24 +51,24 @@ const double FIXED_BDY_TEMP = 20.0; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); if (USE_XML_FORMAT == true) { MeshReaderH2DXML mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); - mloader.load("domain.xml", &mesh); + mloader.load("domain.xml", mesh); } else { MeshReaderH2D mloader; Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); } // Perform initial mesh refinements (optional). for (int i = 0; i < INIT_REF_NUM; i++) - mesh.refine_all_elements(); + mesh->refine_all_elements(); // Initialize the weak formulation. CustomWeakFormPoisson wf("Aluminum", new Hermes1DFunction(LAMBDA_AL), @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 6f0a36a..835dd59 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -102,18 +102,18 @@ int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain-excentric.mesh", &mesh); - //mloader.load("domain-concentric.mesh", &mesh); + mloader.load("domain-excentric.mesh", mesh); + //mloader.load("domain-concentric.mesh", mesh); // Initial mesh refinements. - for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i=0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Use 'true' for anisotropic refinements. - mesh.refine_towards_boundary("Inner", INIT_BDY_REF_NUM_INNER, false); + mesh->refine_towards_boundary("Inner", INIT_BDY_REF_NUM_INNER, false); // Use 'false' for isotropic refinements. - mesh.refine_towards_boundary("Outer", INIT_BDY_REF_NUM_OUTER, false); + mesh->refine_towards_boundary("Outer", INIT_BDY_REF_NUM_OUTER, false); // Initialize boundary conditions. EssentialBCNonConstX bc_inner_vel_x(std::string("Inner"), VEL, STARTUP_TIME); @@ -123,12 +123,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_y(Hermes::vector *>(&bc_inner_vel_y, &bc_outer_vel)); // Spaces for velocity components and pressure. - H1Space xvel_space(&mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh, P_INIT_PRESSURE); + L2Space p_space(mesh, P_INIT_PRESSURE); #else - H1Space p_space(&mesh, P_INIT_PRESSURE); + H1Space p_space(mesh, P_INIT_PRESSURE); #endif Hermes::vector*> spaces(&xvel_space, &yvel_space, &p_space); Hermes::vector*> spaces_const(&xvel_space, &yvel_space, &p_space); @@ -147,9 +147,9 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(&mesh); - ZeroSolution yvel_prev_time(&mesh); - ZeroSolution p_prev_time(&mesh); + ZeroSolution xvel_prev_time(mesh); + ZeroSolution yvel_prev_time(mesh); + ZeroSolution p_prev_time(mesh); Hermes::vector*> slns = Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time); diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 589a630..72b4c93 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -93,7 +93,7 @@ const double STARTUP_TIME = 1.0; const double TAU = 0.01; // Time interval length. const double T_FINAL = 30000.0; -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 0.05; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; @@ -142,20 +142,20 @@ void mag(int n, double* a, double* dadx, double* dady, int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &basemesh); // Initial mesh refinements. - //mesh.refine_all_elements(); - basemesh.refine_towards_boundary(BDY_OBSTACLE, 1, false); + //mesh->refine_all_elements(); + basemesh->refine_towards_boundary(BDY_OBSTACLE, 1, false); // '4' is the number of levels. - basemesh.refine_towards_boundary(BDY_TOP, 1, true); + basemesh->refine_towards_boundary(BDY_TOP, 1, true); // 'true' stands for anisotropic refinements. - basemesh.refine_towards_boundary(BDY_BOTTOM, 1, true); + basemesh->refine_towards_boundary(BDY_BOTTOM, 1, true); - mesh.copy(&basemesh); + mesh->copy(&basemesh); // Initialize boundary conditions. EssentialBCNonConst bc_left_vel_x(BDY_LEFT, VEL_INLET, H, STARTUP_TIME); @@ -165,12 +165,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_y(&bc_vel_y); // Spaces for velocity components and pressure. - H1Space xvel_space(&mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh, P_INIT_PRESSURE); + L2Space p_space(mesh, P_INIT_PRESSURE); #else - H1Space p_space(&mesh, P_INIT_PRESSURE); + H1Space p_space(mesh, P_INIT_PRESSURE); #endif Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space); @@ -190,14 +190,14 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); Solution xvel_ref_sln, yvel_ref_sln, p_ref_sln; - // Define initial conditions on the coarse mesh. - ZeroSolution xvel_prev_time(&mesh); - ZeroSolution yvel_prev_time(&mesh); - ZeroSolution p_prev_time(&mesh); + // Define initial conditions on the coarse mesh-> + ZeroSolution xvel_prev_time(mesh); + ZeroSolution yvel_prev_time(mesh); + ZeroSolution p_prev_time(mesh); - ZeroSolution xvel_sln(&mesh); - ZeroSolution yvel_sln(&mesh); - ZeroSolution p_sln(&mesh); + ZeroSolution xvel_sln(mesh); + ZeroSolution yvel_sln(mesh); + ZeroSolution p_sln(mesh); // Initialize weak formulation. WeakForm* wf; @@ -232,7 +232,7 @@ int main(int argc, char* argv[]) // Periodic global derefinements. if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - mesh.copy(&basemesh); + mesh->copy(&basemesh); xvel_space.set_uniform_order(P_INIT_VEL); yvel_space.set_uniform_order(P_INIT_VEL); p_space.set_uniform_order(P_INIT_PRESSURE); @@ -254,7 +254,7 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh // and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorX(&xvel_space, ref_mesh); @@ -267,16 +267,16 @@ int main(int argc, char* argv[]) Hermes::vector*> ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); Hermes::vector*> ref_spaces_const(ref_xvel_space, ref_yvel_space, ref_p_space); - // Calculate initial coefficient vector for Newton on the fine mesh. + // Calculate initial coefficient vector for Newton on the fine mesh-> double* coeff_vec = new double[Space::get_num_dofs(ref_spaces_const)]; if (ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProj; ogProj.project_global(ref_spaces_const, Hermes::vector*>(&xvel_sln, &yvel_sln, &p_sln), coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProj; ogProj.project_global(ref_spaces_const, Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time), coeff_vec); } @@ -300,8 +300,8 @@ int main(int argc, char* argv[]) // Update previous time level solutions. Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector*>(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProj; ogProj.project_global(Hermes::vector*>(&xvel_space, &yvel_space, &p_space), Hermes::vector*>(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln), Hermes::vector*>(&xvel_sln, &yvel_sln, &p_sln), @@ -320,11 +320,11 @@ int main(int argc, char* argv[]) Space::get_num_dofs(Hermes::vector*>(&xvel_space, &yvel_space, &p_space)), Space::get_num_dofs(ref_spaces_const), err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 8464959..09b89ea 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -81,22 +81,22 @@ double current_time = 0; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Initial mesh refinements. - mesh.refine_all_elements(); - mesh.refine_all_elements(); - mesh.refine_towards_boundary(BDY_OBSTACLE, 2, false); + mesh->refine_all_elements(); + mesh->refine_all_elements(); + mesh->refine_towards_boundary(BDY_OBSTACLE, 2, false); // 'true' stands for anisotropic refinements. - mesh.refine_towards_boundary(BDY_TOP, 2, true); - mesh.refine_towards_boundary(BDY_BOTTOM, 2, true); + mesh->refine_towards_boundary(BDY_TOP, 2, true); + mesh->refine_towards_boundary(BDY_BOTTOM, 2, true); - // Show mesh. + // Show mesh-> MeshView mv; - mv.show(&mesh); + mv.show(mesh); Hermes::Mixins::Loggable::Static::info("Close mesh window to continue."); // Initialize boundary conditions. @@ -107,12 +107,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_y(&bc_vel_y); // Spaces for velocity components and pressure. - H1Space xvel_space(&mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh, P_INIT_PRESSURE); + L2Space p_space(mesh, P_INIT_PRESSURE); #else - H1Space p_space(&mesh, P_INIT_PRESSURE); + H1Space p_space(mesh, P_INIT_PRESSURE); #endif Hermes::vector* > spaces(&xvel_space, &yvel_space, &p_space); Hermes::vector* > spaces_const(&xvel_space, &yvel_space, &p_space); @@ -131,9 +131,9 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting zero initial conditions."); - ZeroSolution xvel_prev_time(&mesh); - ZeroSolution yvel_prev_time(&mesh); - ZeroSolution p_prev_time(&mesh); + ZeroSolution xvel_prev_time(mesh); + ZeroSolution yvel_prev_time(mesh); + ZeroSolution p_prev_time(mesh); Hermes::vector* > slns_prev_time = Hermes::vector* >(&xvel_prev_time, &yvel_prev_time, &p_prev_time); // Initialize weak formulation. diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index 581e6e0..e514cf7 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -95,16 +95,16 @@ int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); - //mloader.load("domain-concentric.mesh", &mesh); + //mloader.load("domain-concentric.mesh", mesh); // Initial mesh refinements. - for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary(Hermes::vector("Bdy-1", "Bdy-2", "Bdy-3", "Bdy-4"), + for (int i=0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary(Hermes::vector("Bdy-1", "Bdy-2", "Bdy-3", "Bdy-4"), INIT_BDY_REF_NUM_INNER, false); // True for anisotropic refinement. // Initialize boundary conditions. @@ -114,12 +114,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_y(&bc_vel_y); // Spaces for velocity components and pressure. - H1Space xvel_space(&mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh, P_INIT_PRESSURE); + L2Space p_space(mesh, P_INIT_PRESSURE); #else - H1Space p_space(&mesh, P_INIT_PRESSURE); + H1Space p_space(mesh, P_INIT_PRESSURE); #endif Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space); @@ -137,9 +137,9 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(&mesh); - ZeroSolution yvel_prev_time(&mesh); - ZeroSolution p_prev_time(&mesh); + ZeroSolution xvel_prev_time(mesh); + ZeroSolution yvel_prev_time(mesh); + ZeroSolution p_prev_time(mesh); Hermes::vector*> slns_prev_time = Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time); diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index 7780455..d186770 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -77,9 +77,9 @@ bool SIMPLE_TEMPERATURE_ADVECTION = false; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> Mesh mesh_whole_domain, mesh_with_hole; - Hermes::vector meshes (&mesh_whole_domain, &mesh_with_hole); + Hermes::vector meshes (mesh_whole_domain, mesh_with_hole); MeshReaderH2DXML mloader; mloader.load("domain.xml", meshes); @@ -103,8 +103,8 @@ int main(int argc, char* argv[]) /* View both meshes. */ MeshView m1("Mesh for temperature"), m2("Mesh for fluid"); - m1.show(&mesh_whole_domain); - m2.show(&mesh_with_hole); + m1.show(mesh_whole_domain); + m2.show(mesh_with_hole); // Initialize boundary conditions. EssentialBCNonConst bc_inlet_vel_x("Inlet", VEL_INLET, H, STARTUP_TIME); @@ -117,14 +117,14 @@ int main(int argc, char* argv[]) EssentialBCs bcs_temperature(&bc_temperature); // Spaces for velocity components, pressure and temperature. - H1Space xvel_space(&mesh_with_hole, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh_with_hole, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh_with_hole, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh_with_hole, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh_with_hole, P_INIT_PRESSURE); + L2Space p_space(mesh_with_hole, P_INIT_PRESSURE); #else - H1Space p_space(&mesh_with_hole, &bcs_pressure, P_INIT_PRESSURE); + H1Space p_space(mesh_with_hole, &bcs_pressure, P_INIT_PRESSURE); #endif - H1Space temperature_space(&mesh_whole_domain, &bcs_temperature, P_INIT_TEMPERATURE); + H1Space temperature_space(mesh_whole_domain, &bcs_temperature, P_INIT_TEMPERATURE); Hermes::vector *> all_spaces(&xvel_space, &yvel_space, &p_space, &temperature_space); Hermes::vector *> all_spaces_const(&xvel_space, @@ -148,8 +148,8 @@ int main(int argc, char* argv[]) // Initial conditions and such. //Hermes::Mixins::Loggable::Static::Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(&mesh_with_hole), yvel_prev_time(&mesh_with_hole), p_prev_time(&mesh_with_hole); - CustomInitialConditionTemperature temperature_init_cond(&mesh_whole_domain, HOLE_MID_X, HOLE_MID_Y, + ZeroSolution xvel_prev_time(mesh_with_hole), yvel_prev_time(mesh_with_hole), p_prev_time(mesh_with_hole); + CustomInitialConditionTemperature temperature_init_cond(mesh_whole_domain, HOLE_MID_X, HOLE_MID_Y, 0.5*OBSTACLE_DIAMETER, TEMPERATURE_INIT_FLUID, TEMPERATURE_INIT_GRAPHITE); Solution temperature_prev_time; Hermes::vector *> all_solutions = Hermes::vector *>(&xvel_prev_time, diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 3bce7c0..6dd86a2 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -23,7 +23,7 @@ // zero Neumann on vetrical edges, // Newton (heat loss) (1 / Pr) * du/dn = ALPHA_AIR * (TEMP_EXT - u) on the top edge. // -// Geometry: Rectangle (0, Lx) x (0, Ly)... see the file domain.mesh. +// Geometry: Rectangle (0, Lx) x (0, Ly)... see the file domain.mesh-> // // The following parameters can be changed: @@ -71,15 +71,15 @@ const double ALPHA_AIR = 5.0; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Initial mesh refinements. - for (int i=0; i < 3; i++) mesh.refine_all_elements(2); - for (int i=0; i < 3; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary(HERMES_ANY, 2); + for (int i=0; i < 3; i++) mesh->refine_all_elements(2); + for (int i=0; i < 3; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary(HERMES_ANY, 2); // Initialize boundary conditions. DefaultEssentialBCConst zero_vel_bc(Hermes::vector("Bottom", "Right", "Top", "Left"), 0.0); @@ -89,14 +89,14 @@ int main(int argc, char* argv[]) EssentialBCs bcs_temp(&bc_temp_bottom); // Spaces for velocity components and pressure. - H1Space xvel_space(&mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(&mesh, &bcs_vel_y, P_INIT_VEL); + H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); + H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); #ifdef PRESSURE_IN_L2 - L2Space p_space(&mesh, P_INIT_PRESSURE); + L2Space p_space(mesh, P_INIT_PRESSURE); #else - H1Space p_space(&mesh, P_INIT_PRESSURE); + H1Space p_space(mesh, P_INIT_PRESSURE); #endif - H1Space t_space(&mesh, &bcs_temp, P_INIT_TEMP); + H1Space t_space(mesh, &bcs_temp, P_INIT_TEMP); Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space, &t_space); // Calculate and report the number of degrees of freedom. @@ -114,10 +114,10 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(&mesh); - ZeroSolution yvel_prev_time(&mesh); - ZeroSolution p_prev_time(&mesh); - ConstantSolution t_prev_time(&mesh, TEMP_INIT); + ZeroSolution xvel_prev_time(mesh); + ZeroSolution yvel_prev_time(mesh); + ZeroSolution p_prev_time(mesh); + ConstantSolution t_prev_time(mesh, TEMP_INIT); Hermes::vector*> slns = Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time, &t_prev_time); diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index 632d118..f0c9607 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -105,9 +105,9 @@ const bool MULTIMESH = true; // 1 for implicit Euler, 2 for Crank-Nicolson. const int TIME_DISCR = 2; -// Stopping criterion for Newton on coarse mesh. +// Stopping criterion for Newton on coarse mesh-> const double NEWTON_TOL_COARSE = 0.01; -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_FINE = 0.05; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 100; @@ -195,7 +195,7 @@ int main (int argc, char* argv[]) { mloader.load("small.mesh", &basemesh); if (SCALED) { - bool ret = basemesh.rescale(l, l); + bool ret = basemesh->rescale(l, l); if (ret) { Hermes::Mixins::Loggable::Static::info("SCALED mesh is used"); } else { @@ -203,13 +203,13 @@ int main (int argc, char* argv[]) { } } - // When nonadaptive solution, refine the mesh. - basemesh.refine_towards_boundary(BDY_TOP, REF_INIT); - basemesh.refine_towards_boundary(BDY_BOT, REF_INIT - 1); - basemesh.refine_all_elements(1); - basemesh.refine_all_elements(1); - C_mesh.copy(&basemesh); - phi_mesh.copy(&basemesh); + // When nonadaptive solution, refine the mesh-> + basemesh->refine_towards_boundary(BDY_TOP, REF_INIT); + basemesh->refine_towards_boundary(BDY_BOT, REF_INIT - 1); + basemesh->refine_all_elements(1); + basemesh->refine_all_elements(1); + C_mesh->copy(&basemesh); + phi_mesh->copy(&basemesh); DefaultEssentialBCConst bc_phi_voltage(BDY_TOP, scaleVoltage(VOLTAGE)); DefaultEssentialBCConst bc_phi_zero(BDY_BOT, scaleVoltage(0.0)); @@ -224,7 +224,7 @@ int main (int argc, char* argv[]) { Solution C_sln, C_ref_sln; Solution phi_sln, phi_ref_sln; - // Assign initial condition to mesh. + // Assign initial condition to mesh-> ConstantSolution C_prev_time(&C_mesh, scaleConc(C0)); ConstantSolution phi_prev_time(MULTIMESH ? &phi_mesh : &C_mesh, 0.0); @@ -277,7 +277,7 @@ int main (int argc, char* argv[]) { phiview.show(&phi_prev_time); phiordview.show(&phi_space); - // Newton's loop on the coarse mesh. + // Newton's loop on the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Solving on initial coarse mesh"); try { @@ -300,7 +300,7 @@ int main (int argc, char* argv[]) { Cview.show(&C_sln); phiview.show(&phi_sln); - // Cleanup after the Newton loop on the coarse mesh. + // Cleanup after the Newton loop on the coarse mesh-> delete solver_coarse; delete[] coeff_vec_coarse; @@ -316,10 +316,10 @@ int main (int argc, char* argv[]) { if (pid.get_timestep_number() > 1 && pid.get_timestep_number() % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - C_mesh.copy(&basemesh); + C_mesh->copy(&basemesh); if (MULTIMESH) { - phi_mesh.copy(&basemesh); + phi_mesh->copy(&basemesh); } C_space.set_uniform_order(P_INIT); phi_space.set_uniform_order(P_INIT); @@ -356,15 +356,15 @@ int main (int argc, char* argv[]) { NewtonSolver* solver = new NewtonSolver(dp); - // Calculate initial coefficient vector for Newton on the fine mesh. + // Calculate initial coefficient vector for Newton on the fine mesh-> if (as == 1 && pid.get_timestep_number() == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector *>(&C_sln, &phi_sln), coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector *>(&C_ref_sln, &phi_ref_sln), coeff_vec); @@ -376,7 +376,7 @@ int main (int argc, char* argv[]) { delete phi_ref_sln.get_mesh(); } - // Newton's loop on the fine mesh. + // Newton's loop on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Solving on fine mesh:"); try { @@ -395,7 +395,7 @@ int main (int argc, char* argv[]) { Hermes::vector *>(&C_ref_sln, &phi_ref_sln)); // Projecting reference solution onto the coarse mesh - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&C_space, &phi_space), Hermes::vector *>(&C_ref_sln, &phi_ref_sln), Hermes::vector *>(&C_sln, &phi_sln), @@ -420,11 +420,11 @@ int main (int argc, char* argv[]) { Space::get_num_dofs(Hermes::vector *>(&C_space, &phi_space)), Space::get_num_dofs(ref_spaces_const), err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -435,7 +435,7 @@ int main (int argc, char* argv[]) { else as++; } - // Visualize the solution and mesh. + // Visualize the solution and mesh-> Hermes::Mixins::Loggable::Static::info("Visualization procedures: C"); char title[100]; sprintf(title, "Solution[C], step# %d, step size %g, time %g, phys time %g", diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index 54ab49a..d63f550 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -113,20 +113,20 @@ double SIGMA_A_5 = SIGMA_T_5 - SIGMA_S_5; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Perform initial uniform mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set essential boundary conditions. DefaultEssentialBCConst bc_essential(Hermes::vector("right", "top"), 0.0); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Associate element markers (corresponding to physical regions) // with material properties (diffusion coefficient, absorption @@ -169,7 +169,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined mesh and setup fine mesh space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. - Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on fine mesh->"); DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); @@ -197,14 +197,14 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // Time measurement. cpu_time.tick(); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> sview.show(&sln); oview.show(&space); @@ -232,12 +232,12 @@ int main(int argc, char* argv[]) // Skip the time spent to save the convergence graphs. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); // Increase the counter of performed adaptivity steps. diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index 40c8f33..4734283 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -67,26 +67,26 @@ const double DAMPING_COEFF = 1.0; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Initial mesh refinements. - for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Top", INIT_REF_NUM_BDY); + for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY); // Initialize boundary conditions. CustomEssentialBCNonConst bc_essential(Hermes::vector("Bottom", "Right", "Top", "Left")); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(&mesh); + ZeroSolution h_time_prev(mesh); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index 81282c8..f15c8cd 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -65,14 +65,14 @@ const int PICARD_MAX_ITER = 100; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Initial mesh refinements. - for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Top", INIT_REF_NUM_BDY); + for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY); // Initialize boundary conditions. CustomEssentialBCNonConst bc_essential(Hermes::vector("Bottom", @@ -80,12 +80,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(&mesh), h_iter_prev(&mesh); + ZeroSolution h_time_prev(mesh), h_iter_prev(mesh); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index e16b959..cf8ff1f 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -124,27 +124,27 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("square.mesh", &basemesh); - mesh.copy(&basemesh); + mesh->copy(&basemesh); // Initial mesh refinements. - for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Top", INIT_REF_NUM_BDY); + for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY); // Initialize boundary conditions. CustomEssentialBCNonConst bc_essential(Hermes::vector("Bottom", "Right", "Top", "Left")); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof_coarse = Space::get_num_dofs(&space); Hermes::Mixins::Loggable::Static::info("ndof_coarse = %d.", ndof_coarse); // Zero initial solution. This is why we use H_OFFSET. - ZeroSolution h_time_prev(&mesh), h_time_new(&mesh); + ZeroSolution h_time_prev(mesh), h_time_new(mesh); // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; @@ -185,10 +185,10 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; - case 2: mesh.unrefine_all_elements(); + case 2: mesh->unrefine_all_elements(); space.set_uniform_order(P_INIT); break; case 3: space.unrefine_all_mesh_elements(); @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -239,7 +239,7 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); } - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(&space, &h_time_new, &sln_coarse); @@ -256,11 +256,11 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space::get_num_dofs(&space) >= NDOF_STOP) @@ -285,7 +285,7 @@ int main(int argc, char* argv[]) graph_cpu.add_values(current_time, cpu_time.accumulated()); graph_cpu.save("conv_cpu_est.dat"); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution, time %g", current_time); view.set_title(title); diff --git a/2d-advanced/richards/basic-rk-newton/main.cpp b/2d-advanced/richards/basic-rk-newton/main.cpp index a01006b..81eb9a1 100644 --- a/2d-advanced/richards/basic-rk-newton/main.cpp +++ b/2d-advanced/richards/basic-rk-newton/main.cpp @@ -87,26 +87,26 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Initial mesh refinements. - for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Top", INIT_REF_NUM_BDY); + for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY); // Initialize boundary conditions. CustomEssentialBCNonConst bc_essential(Hermes::vector("Bottom", "Right", "Top", "Left")); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(&mesh), h_time_new(&mesh); + ZeroSolution h_time_prev(mesh), h_time_new(mesh); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index eac2340..d79dde4 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -106,11 +106,11 @@ enum CONSTITUTIVE_RELATIONS { CONSTITUTIVE_RELATIONS constitutive_relations_type = CONSTITUTIVE_GENUCHTEN; // Newton's and Picard's methods. -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. int NEWTON_MAX_ITER = 10; -// Stopping criterion for Picard on fine mesh. +// Stopping criterion for Picard on fine mesh-> const double PICARD_TOL = 1e-2; // Maximum allowed number of Picard iterations. int PICARD_MAX_ITER = 23; @@ -224,22 +224,22 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load(mesh_file.c_str(), &basemesh); // Perform initial mesh refinements. - mesh.copy(&basemesh); - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(0, true); - mesh.refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY_TOP, true, true); + mesh->copy(&basemesh); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(0, true); + mesh->refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY_TOP, true, true); // Initialize boundary conditions. RichardsEssentialBC bc_essential(BDY_TOP, H_ELEVATION, PULSE_END_TIME, H_INIT, STARTUP_TIME); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = Space::get_num_dofs(&space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); @@ -248,25 +248,25 @@ int main(int argc, char* argv[]) // Solutions for the time stepping and the Newton's method. Solution sln, ref_sln; - InitialSolutionRichards sln_prev_time(&mesh, H_INIT); - InitialSolutionRichards sln_prev_iter(&mesh, H_INIT); + InitialSolutionRichards sln_prev_time(mesh, H_INIT); + InitialSolutionRichards sln_prev_iter(mesh, H_INIT); // Initialize the weak formulation. WeakForm* wf; if (ITERATIVE_METHOD == 1) { if (TIME_INTEGRATION == 1) { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Newton's method (implicit Euler in time)."); - wf = new WeakFormRichardsNewtonEuler(&constitutive_relations, time_step, &sln_prev_time, &mesh); + wf = new WeakFormRichardsNewtonEuler(&constitutive_relations, time_step, &sln_prev_time, mesh); } else { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Newton's method (Crank-Nicolson in time)."); - wf = new WeakFormRichardsNewtonCrankNicolson(&constitutive_relations, time_step, &sln_prev_time, &mesh); + wf = new WeakFormRichardsNewtonCrankNicolson(&constitutive_relations, time_step, &sln_prev_time, mesh); } } else { if (TIME_INTEGRATION == 1) { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Picard's method (implicit Euler in time)."); - wf = new WeakFormRichardsPicardEuler(&constitutive_relations, time_step, &sln_prev_iter, &sln_prev_time, &mesh); + wf = new WeakFormRichardsPicardEuler(&constitutive_relations, time_step, &sln_prev_iter, &sln_prev_time, mesh); } else { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Picard's method (Crank-Nicolson in time)."); @@ -278,14 +278,14 @@ int main(int argc, char* argv[]) SimpleGraph graph_time_err_est, graph_time_err_exact, graph_time_dof, graph_time_cpu, graph_time_step; - // Visualize the projection and mesh. + // Visualize the projection and mesh-> ScalarView view("Initial condition", new WinGeom(0, 0, 630, 350)); view.fix_scale_width(50); OrderView ordview("Initial mesh", new WinGeom(640, 0, 600, 350)); view.show(&sln_prev_time); ordview.show(&space); //MeshView mview("Mesh", new WinGeom(840, 0, 600, 350)); - //mview.show(&mesh); + //mview.show(mesh); //View::wait(); // Time stepping loop. @@ -302,13 +302,13 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; - case 2: mesh.unrefine_all_elements(); + case 2: mesh->unrefine_all_elements(); space.set_uniform_order(P_INIT); break; - case 3: mesh.unrefine_all_elements(); + case 3: mesh->unrefine_all_elements(); //space.adjust_element_order(-1, P_INIT); space.adjust_element_order(-1, -1, P_INIT, P_INIT); break; @@ -329,7 +329,7 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh // and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -341,13 +341,13 @@ int main(int argc, char* argv[]) if(ITERATIVE_METHOD == 1) { double* coeff_vec = new double[ref_space->get_num_dofs()]; - // Calculate initial coefficient vector for Newton on the fine mesh. + // Calculate initial coefficient vector for Newton on the fine mesh-> if (as == 1 && ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_space, &sln_prev_time, coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_space, &ref_sln, coeff_vec); if(as > 1) delete ref_sln.get_mesh(); @@ -356,7 +356,7 @@ int main(int argc, char* argv[]) // Initialize the FE problem. DiscreteProblem dp(wf, ref_space); - // Perform Newton's iteration on the reference mesh. If necessary, + // Perform Newton's iteration on the reference mesh-> If necessary, // reduce time step to make it converge, but then restore time step // size to its original value. Hermes::Mixins::Loggable::Static::info("Performing Newton's iteration (tau = %g days):", time_step); @@ -411,17 +411,17 @@ int main(int argc, char* argv[]) delete [] coeff_vec; } else { - // Calculate initial condition for Picard on the fine mesh. + // Calculate initial condition for Picard on the fine mesh-> if (as == 1 && ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_space, &sln_prev_time, &sln_prev_iter); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_space, &ref_sln, &sln_prev_iter); } - // Perform Picard iteration on the reference mesh. If necessary, + // Perform Picard iteration on the reference mesh-> If necessary, // reduce time step to make it converge, but then restore time step // size to its original value. Hermes::Mixins::Loggable::Static::info("Performing Picard's iteration (tau = %g days):", time_step); @@ -462,7 +462,7 @@ int main(int argc, char* argv[]) /*** ADAPTIVITY ***/ - // Project the fine mesh solution on the coarse mesh. + // Project the fine mesh solution on the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error calculation."); if(space.get_mesh() == NULL) throw Hermes::Exceptions::Exception("it is NULL"); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -478,10 +478,10 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, space_err_est_rel: %g%%", Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_est_rel); - // If space_err_est too large, adapt the mesh. + // If space_err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space::get_num_dofs(&space) >= NDOF_STOP) { done = true; @@ -505,7 +505,7 @@ int main(int argc, char* argv[]) graph_time_step.add_values(current_time, time_step); graph_time_step.save("time_step_history.dat"); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution, time %g days", current_time); view.set_title(title); diff --git a/2d-advanced/richards/capillary-barrier-rk/main.cpp b/2d-advanced/richards/capillary-barrier-rk/main.cpp index f891c37..768c7e7 100644 --- a/2d-advanced/richards/capillary-barrier-rk/main.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/main.cpp @@ -80,7 +80,7 @@ CONSTITUTIVE_RELATIONS constitutive_relations_type = CONSTITUTIVE_GENUCHTEN; ButcherTableType butcher_table_type = Implicit_SDIRK_CASH_3_23_embedded; // Newton's method. -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. int NEWTON_MAX_ITER = 10; @@ -196,27 +196,27 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load(mesh_file, &basemesh); // Perform initial mesh refinements. - mesh.copy(&basemesh); - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Top", INIT_REF_NUM_BDY_TOP); + mesh->copy(&basemesh); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY_TOP); // Initialize boundary conditions. RichardsEssentialBC bc_essential("Top", H_ELEVATION, PULSE_END_TIME, H_INIT, STARTUP_TIME); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. - ZeroSolution h_time_prev(&mesh), h_time_new(&mesh), time_error_fn(&mesh); + ZeroSolution h_time_prev(mesh), h_time_new(mesh), time_error_fn(mesh); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); @@ -228,7 +228,7 @@ int main(int argc, char* argv[]) // Initialize the weak formulation. CustomWeakFormRichardsRK wf(&constitutive_relations); - // Visualize the projection and mesh. + // Visualize the projection and mesh-> ScalarView sview("Initial condition", new WinGeom(0, 0, 400, 350)); sview.fix_scale_width(50); sview.show(&h_time_prev); diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp index 03cdf39..f4e8e6f 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp @@ -89,9 +89,9 @@ const double TIME_STEP_INC_RATIO = 1.1; const double TIME_STEP_DEC_RATIO = 0.8; // Newton's method. -// Stopping criterion for Newton on coarse mesh. +// Stopping criterion for Newton on coarse mesh-> const double NEWTON_TOL_COARSE = 0.01; -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_FINE = 0.05; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 50; @@ -137,17 +137,17 @@ int main(int argc, char* argv[]) ADAPTIVE_TIME_STEP_ON = false; } - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("square.mesh", &basemesh); - mesh.copy(&basemesh); + mesh->copy(&basemesh); // Initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Convert initial condition into a Solution >. - CustomInitialCondition psi_time_prev(&mesh); + CustomInitialCondition psi_time_prev(mesh); // Initialize the weak formulation. double current_time = 0; @@ -160,7 +160,7 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(&mesh, &bcs, P_INIT); + H1Space > space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; case 2: space.unrefine_all_mesh_elements(); @@ -230,24 +230,24 @@ int main(int argc, char* argv[]) // changed during spatial adaptivity. Solution > ref_sln; Solution >* time_error_fn; - if (bt.is_embedded() == true) time_error_fn = new Solution >(&mesh); + if (bt.is_embedded() == true) time_error_fn = new Solution >(mesh); else time_error_fn = NULL; bool done = false; int as = 1; double err_est; do { // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); Space >* ref_space = refSpaceCreator.create_ref_space(); - // Initialize discrete problem on reference mesh. + // Initialize discrete problem on reference mesh-> DiscreteProblem >* ref_dp = new DiscreteProblem >(&wf, ref_space); RungeKutta > runge_kutta(&wf, ref_space, &bt); - // Runge-Kutta step on the fine mesh. + // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, time step = %g s, stages: %d).", current_time, time_step, bt.get_size()); bool verbose = true; @@ -319,7 +319,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Solution > sln; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -342,11 +342,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", Space >::get_num_dofs(&space), Space >::get_num_dofs(ref_space), err_rel_space); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (Space >::get_num_dofs(&space) >= NDOF_STOP) @@ -371,7 +371,7 @@ int main(int argc, char* argv[]) // Clean up. if (time_error_fn != NULL) delete time_error_fn; - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution - real part, Time %3.2f s", current_time); sview_real.set_title(title); diff --git a/2d-advanced/schroedinger/gross-pitaevski/main.cpp b/2d-advanced/schroedinger/gross-pitaevski/main.cpp index d03dce4..8d91348 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/main.cpp @@ -69,17 +69,17 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Convert initial condition into a Solution >. - CustomInitialCondition psi_time_prev(&mesh); - Solution > psi_time_new(&mesh); + CustomInitialCondition psi_time_prev(mesh); + Solution > psi_time_new(mesh); // Initialize the weak formulation. double current_time = 0; @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(&mesh, &bcs, P_INIT); + H1Space > space(mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); diff --git a/2d-advanced/wave-equation/wave-1/main.cpp b/2d-advanced/wave-equation/wave-1/main.cpp index 5f68c4c..27136df 100644 --- a/2d-advanced/wave-equation/wave-1/main.cpp +++ b/2d-advanced/wave-equation/wave-1/main.cpp @@ -63,20 +63,20 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Refine towards boundary. - mesh.refine_towards_boundary("Bdy", 1, true); + mesh->refine_towards_boundary("Bdy", 1, true); // Refine once towards vertex #4. - mesh.refine_towards_vertex(4, 1); + mesh->refine_towards_vertex(4, 1); // Initialize solutions. - CustomInitialConditionWave u_sln(&mesh); - ZeroSolution v_sln(&mesh); + CustomInitialConditionWave u_sln(mesh); + ZeroSolution v_sln(mesh); Hermes::vector*> slns(&u_sln, &v_sln); // Initialize the weak formulation. @@ -87,8 +87,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - H1Space u_space(&mesh, &bcs, P_INIT); - H1Space v_space(&mesh, &bcs, P_INIT); + H1Space u_space(mesh, &bcs, P_INIT); + H1Space v_space(mesh, &bcs, P_INIT); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector*>(&u_space, &v_space))); // Initialize views. diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index f38cd6d..3e883f1 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -66,17 +66,17 @@ const double K = 1e2; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &mesh); + mloader.load("square.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); - mesh.refine_towards_boundary("Bdy", INIT_REF_NUM_BDY); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + mesh->refine_towards_boundary("Bdy", INIT_REF_NUM_BDY); // Define exact solution. - CustomExactSolution exact_sln(&mesh, K); + CustomExactSolution exact_sln(mesh, K); // Define right side vector. CustomFunction f(K); @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -116,7 +116,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -150,7 +150,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index 8388462..07b63d8 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -14,7 +14,7 @@ using namespace RefinementSelectors; // // Known exact solution. // -// Domain: unit square (0, 1) x (0, 1), see the file square.mesh. +// Domain: unit square (0, 1) x (0, 1), see the file square.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -66,19 +66,19 @@ double slope = 60; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Triangles. - // mloader.load("square_tri.mesh", &mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Define exact solution. - CustomExactSolution exact_sln(&mesh, slope); + CustomExactSolution exact_sln(mesh, slope); // Define custom function f. CustomFunction f(slope); @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -192,7 +192,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index e6ccfde..542138d 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -61,17 +61,17 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("lshape.mesh", &mesh); + mloader.load("lshape.mesh", mesh); // Perform initial mesh refinement. - for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); - //mesh.refine_towards_vertex(3, 5); + for (int i=0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + //mesh->refine_towards_vertex(3, 5); // Define exact solution. - CustomExactSolution exact_sln(&mesh); + CustomExactSolution exact_sln(mesh); // Initialize the weak formulation. DefaultWeakFormLaplace wf; @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -118,7 +118,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index 4304af7..03ff037 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -73,7 +73,7 @@ const int NDOF_STOP = 60000; MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Newton's method -// Stopping criterion for Newton on fine mesh. +// Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; @@ -115,24 +115,24 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh. + // Load the mesh-> Mesh mesh, basemesh; MeshReaderH2D mloader; mloader.load("domain.mesh", &basemesh); // Perform initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) basemesh.refine_all_elements(0, true); - mesh.copy(&basemesh); + for(int i = 0; i < INIT_REF_NUM; i++) basemesh->refine_all_elements(0, true); + mesh->copy(&basemesh); // Exact solution. - CustomExactSolution exact_sln(&mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); + CustomExactSolution exact_sln(mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); // Initialize boundary conditions. DefaultEssentialBCConst bc_essential("Bdy", 0); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); int ndof_coarse = space.get_num_dofs(); // Initialize the weak formulation @@ -140,8 +140,8 @@ int main(int argc, char* argv[]) CustomWeakFormPoisson wf(HERMES_ANY, new Hermes::Hermes1DFunction(-1.0), &f); // Previous and next time level solution. - ZeroSolution sln_time_prev(&mesh); - Solution sln_time_new(&mesh); + ZeroSolution sln_time_prev(mesh); + Solution sln_time_new(mesh); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -165,13 +165,13 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh.copy(&basemesh); + case 1: mesh->copy(&basemesh); space.set_uniform_order(P_INIT); break; - case 2: mesh.unrefine_all_elements(); + case 2: mesh->unrefine_all_elements(); space.set_uniform_order(P_INIT); break; - case 3: mesh.unrefine_all_elements(); + case 3: mesh->unrefine_all_elements(); space.adjust_element_order(-1, -1, P_INIT, P_INIT); break; } @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -216,7 +216,7 @@ int main(int argc, char* argv[]) e.print_msg(); } - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; @@ -231,11 +231,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); if (space.get_num_dofs() >= NDOF_STOP) @@ -255,7 +255,7 @@ int main(int argc, char* argv[]) } while (done == false); - // Visualize the solution and mesh. + // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution, time %g", current_time); sview.set_title(title); diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index 860ef56..6169c35 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -12,7 +12,7 @@ using namespace RefinementSelectors; // // Known exact solution u(x,y) = sin(x). // -// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh. +// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh-> // // BC: Zero Dirichlet on left edge, zero Neumann on top and bottom edges, // nonzero Neumann on the right edge (all matching exact solution). @@ -59,13 +59,13 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(&mesh); + CustomExactSolution exact_sln(mesh); // Initialize the weak formulation. CustomWeakForm wf("Right"); @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -137,7 +137,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -175,7 +175,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 19eea05..8b73518 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -12,7 +12,7 @@ using namespace RefinementSelectors; // // Known exact solution, see functions fn() and fndd(). // -// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh. +// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh-> // // BC: Dirichlet and Neumann, given by exact solution. // @@ -58,13 +58,13 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(&mesh); + CustomExactSolution exact_sln(mesh); // Initialize the weak formulation. CustomWeakFormPoisson wf("Right"); @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -101,7 +101,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index 024cc6a..b5949e9 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -12,7 +12,7 @@ using namespace RefinementSelectors; // // Known exact solution, see functions fn() and fndd(). // -// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh. +// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh-> // // BC: Dirichlet and Neumann, given by exact solution. // @@ -58,13 +58,13 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &mesh); + mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(&mesh); + CustomExactSolution exact_sln(mesh); // Initialize the weak formulation. CustomWeakFormPoisson wf("Top"); @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -101,7 +101,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index 50ae4e5..3a4c22c 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -14,7 +14,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // // Known exact solution, see class CustomExactSolution in definitions.cpp. // -// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh. +// Domain: square domain (0, pi) x (0, pi), mesh file square_quad.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -60,19 +60,19 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Avoid zero ndof situation. if (P_INIT == 1) { if (is_hp(CAND_LIST)) P_INIT++; - else mesh.refine_element_id(0, 0); + else mesh->refine_element_id(0, 0); } // Define exact solution. - CustomExactSolution exact_sln(&mesh); + CustomExactSolution exact_sln(mesh); // Initialize the weak formulation. Hermes1DFunction lambda(1.0); @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -146,7 +146,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 263ed24..f95e1f1 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -13,7 +13,7 @@ using namespace RefinementSelectors; // Known exact solution; pow(2, 4*p) * pow(x, p) * pow(1-x, p) * pow(y, p) * pow(1-y, p). // See functions fn() and fndd() in "exact_solution.cpp". // -// Domain: unit square (0, 1)x(0, 1), see the file square.mesh. +// Domain: unit square (0, 1)x(0, 1), see the file square.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -65,19 +65,19 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Triangles. - // mloader.load("square_tri.mesh", &mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, EXACT_SOL_P); + CustomExactSolution exact_sln(mesh, EXACT_SOL_P); // Define right-hand side. CustomRightHandSide f(EXACT_SOL_P); @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -118,7 +118,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -128,7 +128,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 93e5959..4af2fa8 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -71,29 +71,29 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; double alpha = 0, omega = 0; switch (PARAM) { case 0: - mloader.load("geom0.mesh", &mesh); + mloader.load("geom0.mesh", mesh); omega = ((5.0 * M_PI)/ 4.0); alpha = (M_PI/ omega); break; case 1: - mloader.load("geom1.mesh", &mesh); + mloader.load("geom1.mesh", mesh); omega = ((3.0 * M_PI)/ 2.0); alpha = (M_PI/ omega); break; case 2: - mloader.load("geom2.mesh", &mesh); + mloader.load("geom2.mesh", mesh); omega = ((7.0 * M_PI)/ 4.0); alpha = (M_PI/ omega); break; - case 3: mloader.load("geom3.mesh", &mesh); + case 3: mloader.load("geom3.mesh", mesh); omega = (2.0 * M_PI); alpha = (M_PI/omega); break; @@ -101,10 +101,10 @@ int main(int argc, char* argv[]) } // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha); + CustomExactSolution exact_sln(mesh, alpha); // Initialize weak formulation. Hermes1DFunction lambda(1.0); @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -215,7 +215,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index f5af09d..ef50d63 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -105,18 +105,18 @@ const double nu = 0.3; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> Mesh u_mesh, v_mesh; MeshReaderH2D mloader; mloader.load("elasticity.mesh", &u_mesh); // Create initial mesh (master mesh). - v_mesh.copy(&u_mesh); + v_mesh->copy(&u_mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) { - u_mesh.refine_all_elements(); - v_mesh.refine_all_elements(); + u_mesh->refine_all_elements(); + v_mesh->refine_all_elements(); } // Set exact solution for each displacement component. @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_spaces_const); @@ -214,7 +214,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector*>(&u_space, &v_space), Hermes::vector*>(&u_ref_sln, &v_ref_sln), @@ -271,12 +271,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index f97593a..967a16a 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -67,19 +67,19 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Triangles. - // mloader.load("square_tri.mesh", &mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; irefine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha, x_loc, y_loc); + CustomExactSolution exact_sln(mesh, alpha, x_loc, y_loc); // Define right-hand side. CustomRightHandSide f(alpha, x_loc, y_loc); @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -193,7 +193,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index fd0a59a..eb347bd 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -65,20 +65,20 @@ MatrixSolverType matrix_solver = SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("battery.mesh", &mesh); + mloader.load("battery.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Create an H1 space with default shapeset. - H1Space space(&mesh, P_INIT); + H1Space space(mesh, P_INIT); // Initialize weak formulation. CustomWeakFormPoisson wf("e1", "e2", "e3", "e4", "e5", - "Bdy_left", "Bdy_top", "Bdy_right", "Bdy_bottom", &mesh); + "Bdy_left", "Bdy_top", "Bdy_right", "Bdy_bottom", mesh); // Initialize coarse and fine mesh solution. Solution sln, ref_sln; @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined mesh and setup fine mesh space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -116,7 +116,7 @@ int main(int argc, char* argv[]) int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. - Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on fine mesh->"); DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); @@ -136,8 +136,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); // Time measurement. @@ -198,12 +198,12 @@ int main(int argc, char* argv[]) // Skip the time spent to save the convergence graphs. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. + // If err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); // Increase the counter of performed adaptivity steps. diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 0910a22..97ae4bf 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -15,7 +15,7 @@ using namespace RefinementSelectors; // // Known exact solution, see the class CustomExactSolution. // -// Domain: square (-1, 1) x (-1, 1), see the file square.mesh. +// Domain: square (-1, 1) x (-1, 1), see the file square.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -65,16 +65,16 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, epsilon); + CustomExactSolution exact_sln(mesh, epsilon); // Define right-hand side. CustomRightHandSide f(epsilon); @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index d5bb04a..63c76f2 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -65,19 +65,19 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Triangles. - // mloader.load("square_tri.mesh", &mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha); + CustomExactSolution exact_sln(mesh, alpha); // Define right-hand side. CustomRightHandSide f(alpha); @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -118,7 +118,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -128,7 +128,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index fc325d4..48ff30a 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -15,7 +15,7 @@ using namespace RefinementSelectors; // // Known exact solution, see functions fn() and fndd(). // -// Domain: unit square (0, 1) x (0, 1), see the file square.mesh. +// Domain: unit square (0, 1) x (0, 1), see the file square.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -65,16 +65,16 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha); + CustomExactSolution exact_sln(mesh, alpha); // Define right-hand side. CustomRightHandSide f(alpha); @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index a3af706..d5ddd7e 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -14,7 +14,7 @@ using namespace RefinementSelectors; // Known exact solution: atan(alpha * (sqrt(pow(x - x_loc, 2) + pow(y - y_loc, 2)) - r_zero)) // See the class CustomExactSolution::value in "definitions.cpp" // -// Domain: unit square (0, 1) x (0, 1), see the file square_quad.mesh or square_tri.mesh. +// Domain: unit square (0, 1) x (0, 1), see the file square_quad.mesh or square_tri.mesh-> // // BC: Dirichlet, given by exact solution. // @@ -109,19 +109,19 @@ int main(int argc, char* argv[]) break; } - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Triangles. - // mloader.load("square_tri.mesh", &mesh); + // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha, x_loc, y_loc, r_zero); + CustomExactSolution exact_sln(mesh, alpha, x_loc, y_loc, r_zero); // Define right-hand side. CustomRightHandSide rhs(alpha, x_loc, y_loc, r_zero); @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -163,7 +163,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -198,7 +198,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -236,7 +236,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 1406d28..577ec60 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -16,7 +16,7 @@ using namespace RefinementSelectors; // Exact solution: u(x,y) = cos(K*y) for x < 0, // u(x,y) = cos(K*y) + pow(x, alpha) for x > 0 where alpha > 0. // -// Domain: square, see the file singpert.mesh. +// Domain: square, see the file singpert.mesh-> // // BC: Dirichlet given by the exact solution. // @@ -67,16 +67,16 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, K, alpha); + CustomExactSolution exact_sln(mesh, K, alpha); // Define right-hand side. CustomRightHandSide f(K, alpha); @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index b2175db..01b9e86 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -71,16 +71,16 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square_quad.mesh", &mesh); + mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, SIGMA, TAU, RHO); + CustomExactSolution exact_sln(mesh, SIGMA, TAU, RHO); // Initialize weak formulation. CustomWeakFormPoisson wf("Mat_0", R, "Mat_1"); @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -152,7 +152,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 59fe5db..9bb3362 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -71,16 +71,16 @@ Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; int main(int argc, char* argv[]) { - // Load the mesh. - Mesh mesh; + // Load the mesh-> + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("lshape.mesh", &mesh); + mloader.load("lshape.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(&mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); + CustomExactSolution exact_sln(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); // Define right-hand side. CustomRightHandSide f(alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space space(mesh, &bcs, P_INIT); // Initialize approximate solution. Solution sln; @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator(&mesh); + Mesh::ReferenceMeshCreator refMeshCreator(mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); @@ -131,7 +131,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -156,7 +156,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); @@ -194,7 +194,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) done = true; From 96adbafb8dd40a3d6c68df80e2753ed19561f195 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 14 Mar 2013 16:24:51 +0100 Subject: [PATCH 08/64] Work on Euler. --- 2d-advanced/euler/euler_util.cpp | 8 +-- 2d-advanced/euler/forms_explicit.cpp | 2 +- 2d-advanced/euler/forward-step-adapt/main.cpp | 8 +-- 2d-advanced/euler/forward-step/main.cpp | 2 +- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 8 +-- 2d-advanced/euler/gamm-channel/main.cpp | 2 +- .../CMakeLists.txt | 2 +- .../heating-flow-coupling-adapt/main.cpp | 56 ++++++++++--------- .../heating-flow-coupling/CMakeLists.txt | 2 +- .../euler/heating-flow-coupling/main.cpp | 2 +- .../heating-induced-vortex-adapt/main.cpp | 8 +-- .../euler/heating-induced-vortex/main.cpp | 2 +- .../euler/reflected-shock-adapt/main.cpp | 8 +-- 2d-advanced/euler/reflected-shock/main.cpp | 2 +- 14 files changed, 58 insertions(+), 54 deletions(-) diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index def3fdd..c10df4a 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -35,7 +35,7 @@ CFLCalculation::CFLCalculation(double CFL_number, double kappa) : CFL_number(CFL void CFLCalculation::calculate(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const { - // Create spaces of constant functions over the given mesh. + // Create spaces of constant functions over the given mesh-> SpaceSharedPtr constant_rho_space(new L2Space (mesh, 0)); SpaceSharedPtr constant_rho_v_x_space(new L2Space (mesh, 0)); SpaceSharedPtr constant_rho_v_y_space(new L2Space (mesh, 0)); @@ -75,7 +75,7 @@ void CFLCalculation::calculate(Hermes::vector > so void CFLCalculation::calculate_semi_implicit(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) const { - // Create spaces of constant functions over the given mesh. + // Create spaces of constant functions over the given mesh-> SpaceSharedPtr constant_rho_space(new L2Space(mesh, 0)); SpaceSharedPtr constant_rho_v_x_space(new L2Space(mesh, 0)); SpaceSharedPtr constant_rho_v_y_space(new L2Space(mesh, 0)); @@ -153,7 +153,7 @@ void CFLCalculation::calculate_semi_implicit(Hermes::vector > solutions, MeshSharedPtr mesh, double & time_step) { - // Create spaces of constant functions over the given mesh. + // Create spaces of constant functions over the given mesh-> SpaceSharedPtr constant_rho_space(new L2Space(mesh, 0)); SpaceSharedPtr constant_rho_v_x_space(new L2Space(mesh, 0)); SpaceSharedPtr constant_rho_v_y_space(new L2Space(mesh, 0)); diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index 99481d4..86b70a6 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -1028,7 +1028,7 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW double rho = ext[0]->val[point_i]; result += wt[point_i] * u->val[point_i] * v->val[point_i] * rho * c_p / this->wf->get_current_time_step(); result += wt[point_i] * (u->dx[point_i] * v->dx[point_i] + u->dy[point_i] * v->dy[point_i]) * lambda; - result += (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i] * c_p; + result += wt[point_i] * (ext[1]->val[point_i] * u->dx[point_i] + ext[2]->val[point_i] * u->dy[point_i]) * v->val[point_i] * c_p; } return result; } diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index d737870..7bc3b71 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -113,7 +113,7 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh), base_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("ffs.mesh", base_mesh); @@ -304,8 +304,8 @@ int main(int argc, char* argv[]) std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -337,7 +337,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index 1f5a723..5fdec24 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -86,7 +86,7 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("ffs.mesh", mesh); diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 590b778..98d4faf 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -130,7 +130,7 @@ const std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("GAMM-channel.mesh", mesh); @@ -307,8 +307,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -331,7 +331,7 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index d81bdc3..275d78b 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -78,7 +78,7 @@ std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("GAMM-channel.mesh", mesh); diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt b/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt index 40ae1a3..8ddfd85 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt +++ b/2d-advanced/euler/heating-flow-coupling-adapt/CMakeLists.txt @@ -1,4 +1,4 @@ project(heating-flow-coupling-adapt) -add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp) +add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp ../coupling.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index a142651..ce2d8a8 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -1,6 +1,7 @@ #define HERMES_REPORT_INFO #define HERMES_REPORT_FILE "application.log" #include "hermes2d.h" +#include "../coupling.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -19,7 +20,7 @@ const unsigned int EVERY_NTH_STEP = 1; // Initial polynomial degree. const int P_INIT_FLOW = 0; const int P_INIT_HEAT = 1; -// Number of initial uniform mesh refinements. +// Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // Shock capturing. @@ -96,9 +97,7 @@ double ERR_STOP = 5.0; int main(int argc, char* argv[]) { - Hermes2DApi.set_integral_param_value(numThreads, 1); - - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -108,8 +107,8 @@ int main(int argc, char* argv[]) mesh->refine_all_elements(0, true); mesh_heat->copy(mesh); - mesh_heat->refine_towards_boundary("Inlet", 3, false); - mesh->refine_all_elements(0, true); + //mesh_heat->refine_towards_boundary("Inlet", 3, false); + //mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); @@ -179,8 +178,7 @@ int main(int argc, char* argv[]) ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, LAMBDA); // Initialize refinement selector. - L2ProjBasedSelector l2_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); - l2_selector.set_error_weights(1.0, 1.0, 1.0); + H1ProjBasedSelector l2_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); H1ProjBasedSelector h1_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); // Look for a saved solution on the disk. @@ -301,17 +299,30 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity_flow = new Adapt(flow_spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - Adapt* adaptivity_heat = new Adapt(space_temp, HERMES_H1_NORM); - double error_flow = adaptivity_flow->calc_err_est(flow_slns, rflow_slns) * 100; - double error_heat = adaptivity_heat->calc_err_est(sln_temp, rsln_temp) * 100; + Adapt* adaptivity = new Adapt(spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); + adaptivity->set_error_form(new CouplingErrorFormVelocity(velX, C_P)); + adaptivity->set_error_form(new CouplingErrorFormVelocity(velY, C_P)); + adaptivity->set_norm_form(new CouplingErrorFormVelocity(velX, C_P)); + adaptivity->set_norm_form(new CouplingErrorFormVelocity(velY, C_P)); + + adaptivity->set_error_form(new CouplingErrorFormTemperature(velX, C_P)); + adaptivity->set_error_form(new CouplingErrorFormTemperature(velY, C_P)); + adaptivity->set_norm_form(new CouplingErrorFormTemperature(velX, C_P)); + adaptivity->set_norm_form(new CouplingErrorFormTemperature(velY, C_P)); + Hermes::vector component_errors; + double error_value = adaptivity->calc_err_est(slns, rslns, &component_errors) * 100; + + std::cout << std::endl; + for(int k = 0; k < 5; k ++) + std::cout << k << ':' << component_errors[k] << std::endl; + std::cout << std::endl; CFL.calculate_semi_implicit(rflow_slns, ref_mesh_flow, time_step); @@ -323,24 +334,18 @@ int main(int argc, char* argv[]) time_step = util_time_step; // Report results. - Hermes::Mixins::Loggable::Static::info("Error-flow: %g%%, error-heat: %g%%.", error_flow, error_heat); + Hermes::Mixins::Loggable::Static::info("Error: %g%%.", error_value); // If err_est too large, adapt the mesh-> - if (error_flow < ERR_STOP) + if (error_value < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting flow mesh->"); - done = adaptivity_flow->adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector), + Hermes::Mixins::Loggable::Static::info("Adapting coarse space."); + done = adaptivity->adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector, &h1_selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } - if(error_heat >= ERR_STOP) - { - Hermes::Mixins::Loggable::Static::info("Adapting heat mesh->"); - done = adaptivity_heat->adapt(&h1_selector, THRESHOLD, STRATEGY, MESH_REGULARITY) & done; - } - as++; // Visualization. @@ -368,8 +373,7 @@ int main(int argc, char* argv[]) } } - delete adaptivity_flow; - delete adaptivity_heat; + delete adaptivity; } while (!done); diff --git a/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt b/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt index 242fb66..e8ac975 100644 --- a/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt +++ b/2d-advanced/euler/heating-flow-coupling/CMakeLists.txt @@ -1,4 +1,4 @@ project(heating-flow-coupling) -add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp) +add_executable(${PROJECT_NAME} main.cpp ../euler_util.cpp ../numerical_flux.cpp ../coupling.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 701f20c..ee7ae36 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -83,7 +83,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 9f9c89c..1c78499 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -134,7 +134,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -293,8 +293,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -317,7 +317,7 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index dd52a62..90389bc 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -73,7 +73,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index eeb4e68..c401de8 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -131,7 +131,7 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("channel.mesh", mesh); @@ -296,8 +296,8 @@ int main(int argc, char* argv[]) flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index 6109818..b1025f7 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -90,7 +90,7 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("channel.mesh", mesh); From f1ed11e270a718116194726c43d7d017e492d317 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 25 Mar 2013 10:29:34 +0100 Subject: [PATCH 09/64] Make ns-heat-subdomains compile with shared pointers. --- .../ns-heat-subdomains/definitions.cpp | 8 +-- .../ns-heat-subdomains/definitions.h | 10 +-- .../navier-stokes/ns-heat-subdomains/main.cpp | 64 ++++++++----------- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp index bbd8a03..7e3268c 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp @@ -2,7 +2,7 @@ /* Custom initial condition for temperature*/ -CustomInitialConditionTemperature::CustomInitialConditionTemperature(const Mesh *mesh, double mid_x, double mid_y, double radius, double temp_fluid, double temp_graphite) +CustomInitialConditionTemperature::CustomInitialConditionTemperature(MeshSharedPtr mesh, double mid_x, double mid_y, double radius, double temp_fluid, double temp_graphite) : ExactSolutionScalar(mesh), mid_x(mid_x), mid_y(mid_y), radius(radius), temp_fluid(temp_fluid), temp_graphite(temp_graphite) {} double CustomInitialConditionTemperature::value(double x, double y) const @@ -31,14 +31,14 @@ MeshFunction* CustomInitialConditionTemperature::clone() const /* Weak forms */ -CustomWeakFormHeatAndFlow::CustomWeakFormHeatAndFlow(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time, Solution* T_prev_time, double heat_source, double specific_heat_graphite, +CustomWeakFormHeatAndFlow::CustomWeakFormHeatAndFlow(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time, MeshFunctionSharedPtr T_prev_time, double heat_source, double specific_heat_graphite, double specific_heat_fluid, double rho_graphite, double rho_fluid, double thermal_conductivity_graphite, double thermal_conductivity_fluid, bool simple_temp_advection) : WeakForm(4), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { // For passing to forms. - Hermes::vector*> ext(x_vel_previous_time, y_vel_previous_time); + Hermes::vector > ext(x_vel_previous_time, y_vel_previous_time); // Jacobian - flow part. add_matrix_form(new BilinearFormSymVel(0, 0, Stokes, Reynolds, time_step)); diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h index 3c90504..9ee67bd 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h @@ -20,7 +20,7 @@ const double HOLE_MID_Y = 0.5; class CustomInitialConditionTemperature : public ExactSolutionScalar { public: - CustomInitialConditionTemperature(const Mesh *mesh, double mid_x, double mid_y, double radius, double temp_fluid, double temp_graphite); + CustomInitialConditionTemperature(MeshSharedPtr mesh, double mid_x, double mid_y, double radius, double temp_fluid, double temp_graphite); virtual double value(double x, double y) const; @@ -39,8 +39,8 @@ class CustomInitialConditionTemperature : public ExactSolutionScalar class CustomWeakFormHeatAndFlow : public WeakForm { public: - CustomWeakFormHeatAndFlow(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time, Solution* T_prev_time, double heat_source, double specific_heat_graphite, + CustomWeakFormHeatAndFlow(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time, MeshFunctionSharedPtr T_prev_time, double heat_source, double specific_heat_graphite, double specific_heat_fluid, double rho_graphite, double rho_fluid, double thermal_conductivity_graphite, double thermal_conductivity_fluid, bool simple_temp_advection); @@ -672,8 +672,8 @@ class CustomWeakFormHeatAndFlow : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class EssentialBCNonConst : public EssentialBoundaryCondition diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index d186770..ac7d06a 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -78,8 +78,8 @@ bool SIMPLE_TEMPERATURE_ADVECTION = false; int main(int argc, char* argv[]) { // Load the mesh-> - Mesh mesh_whole_domain, mesh_with_hole; - Hermes::vector meshes (mesh_whole_domain, mesh_with_hole); + MeshSharedPtr mesh_whole_domain(new Mesh), mesh_with_hole(new Mesh); + Hermes::vector meshes (mesh_whole_domain, mesh_with_hole); MeshReaderH2DXML mloader; mloader.load("domain.xml", meshes); @@ -101,11 +101,6 @@ int main(int argc, char* argv[]) for(unsigned int meshes_i = 0; meshes_i < meshes.size(); meshes_i++) meshes[meshes_i]->refine_towards_boundary("Outer Wall", INIT_REF_NUM_BDY_WALL); - /* View both meshes. */ - MeshView m1("Mesh for temperature"), m2("Mesh for fluid"); - m1.show(mesh_whole_domain); - m2.show(mesh_with_hole); - // Initialize boundary conditions. EssentialBCNonConst bc_inlet_vel_x("Inlet", VEL_INLET, H, STARTUP_TIME); DefaultEssentialBCConst bc_other_vel_x(Hermes::vector("Outer Wall", "Inner Wall"), 0.0); @@ -117,23 +112,19 @@ int main(int argc, char* argv[]) EssentialBCs bcs_temperature(&bc_temperature); // Spaces for velocity components, pressure and temperature. - H1Space xvel_space(mesh_with_hole, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh_with_hole, &bcs_vel_y, P_INIT_VEL); + SpaceSharedPtr xvel_space(new H1Space(mesh_with_hole, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh_with_hole, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh_with_hole, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh_with_hole, P_INIT_PRESSURE)); #else - H1Space p_space(mesh_with_hole, &bcs_pressure, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh_with_hole, &bcs_pressure, P_INIT_PRESSURE)); #endif - H1Space temperature_space(mesh_whole_domain, &bcs_temperature, P_INIT_TEMPERATURE); - Hermes::vector *> all_spaces(&xvel_space, - &yvel_space, &p_space, &temperature_space); - Hermes::vector *> all_spaces_const(&xvel_space, - &yvel_space, &p_space, &temperature_space); + SpaceSharedPtr temperature_space(new H1Space (mesh_whole_domain, &bcs_temperature, P_INIT_TEMPERATURE)); + Hermes::vector > all_spaces(xvel_space, yvel_space, p_space, temperature_space); // Calculate and report the number of degrees of freedom. - int ndof = Space::get_num_dofs(Hermes::vector *>(&xvel_space, - &yvel_space, &p_space, &temperature_space)); - //Hermes::Mixins::Loggable::Static::Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); + int ndof = Space::get_num_dofs(Hermes::vector >(xvel_space, + yvel_space, p_space, temperature_space)); // Define projection norms. ProjNormType vel_proj_norm = HERMES_H1_NORM; @@ -148,14 +139,14 @@ int main(int argc, char* argv[]) // Initial conditions and such. //Hermes::Mixins::Loggable::Static::Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(mesh_with_hole), yvel_prev_time(mesh_with_hole), p_prev_time(mesh_with_hole); - CustomInitialConditionTemperature temperature_init_cond(mesh_whole_domain, HOLE_MID_X, HOLE_MID_Y, - 0.5*OBSTACLE_DIAMETER, TEMPERATURE_INIT_FLUID, TEMPERATURE_INIT_GRAPHITE); - Solution temperature_prev_time; - Hermes::vector *> all_solutions = Hermes::vector *>(&xvel_prev_time, - &yvel_prev_time, &p_prev_time, &temperature_prev_time); - Hermes::vector *> all_meshfns = Hermes::vector *>(&xvel_prev_time, - &yvel_prev_time, &p_prev_time, &temperature_init_cond); + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh_with_hole)), yvel_prev_time(new ZeroSolution(mesh_with_hole)), p_prev_time(new ZeroSolution(mesh_with_hole)); + MeshFunctionSharedPtr temperature_init_cond(new CustomInitialConditionTemperature (mesh_whole_domain, HOLE_MID_X, HOLE_MID_Y, + 0.5*OBSTACLE_DIAMETER, TEMPERATURE_INIT_FLUID, TEMPERATURE_INIT_GRAPHITE)); + MeshFunctionSharedPtr temperature_prev_time(new Solution); + Hermes::vector > initial_solutions = Hermes::vector >(xvel_prev_time, + yvel_prev_time, p_prev_time, temperature_init_cond); + Hermes::vector > all_solutions = Hermes::vector >(xvel_prev_time, + yvel_prev_time, p_prev_time, temperature_prev_time); // Project all initial conditions on their FE spaces to obtain aninitial // coefficient vector for the Newton's method. We use local projection @@ -166,23 +157,23 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Projecting initial condition to obtain initial vector for the Newton's method."); OGProjection ogProjection; - ogProjection.project_global(all_spaces, all_meshfns, coeff_vec, all_proj_norms); + ogProjection.project_global(all_spaces, initial_solutions, coeff_vec, all_proj_norms); // Translate the solution vector back to Solutions. This is needed to replace // the discontinuous initial condition for temperature_prev_time with its projection. - Solution::vector_to_solutions(coeff_vec, all_spaces_const, all_solutions); + Solution::vector_to_solutions(coeff_vec, all_spaces, all_solutions); // Calculate Reynolds number. double reynolds_number = VEL_INLET * OBSTACLE_DIAMETER / KINEMATIC_VISCOSITY_FLUID; //Hermes::Mixins::Loggable::Static::Hermes::Mixins::Loggable::Static::info("RE = %g", reynolds_number); // Initialize weak formulation. - CustomWeakFormHeatAndFlow wf(STOKES, reynolds_number, time_step, &xvel_prev_time, &yvel_prev_time, &temperature_prev_time, + CustomWeakFormHeatAndFlow wf(STOKES, reynolds_number, time_step, xvel_prev_time, yvel_prev_time, temperature_prev_time, HEAT_SOURCE_GRAPHITE, SPECIFIC_HEAT_GRAPHITE, SPECIFIC_HEAT_FLUID, RHO_GRAPHITE, RHO_FLUID, THERMAL_CONDUCTIVITY_GRAPHITE, THERMAL_CONDUCTIVITY_FLUID, SIMPLE_TEMPERATURE_ADVECTION); // Initialize the FE problem. - DiscreteProblem dp(&wf, all_spaces_const); + DiscreteProblem dp(&wf, all_spaces); // Initialize the Newton solver. NewtonSolver newton(&dp); @@ -212,8 +203,7 @@ int main(int argc, char* argv[]) if (current_time <= STARTUP_TIME) { //Hermes::Mixins::Loggable::Static::Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector *>(&xvel_space, &yvel_space, &p_space, - &temperature_space), current_time); + Space::update_essential_bc_values(all_spaces, current_time); } // Perform Newton's iteration. @@ -230,9 +220,7 @@ int main(int argc, char* argv[]) e.print_msg(); }; { - Hermes::vector *> tmp(&xvel_prev_time, &yvel_prev_time, &p_prev_time, &temperature_prev_time); - Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector *>(&xvel_space, - &yvel_space, &p_space, &temperature_space), tmp); + Solution::vector_to_solutions(newton.get_sln_vector(), all_spaces, all_solutions); } // Show the solution at the end of time step. @@ -241,10 +229,10 @@ int main(int argc, char* argv[]) //vview.show(&xvel_prev_time, &yvel_prev_time); sprintf(title, "Pressure [Pa], time %g s", current_time); pview.set_title(title); - pview.show(&p_prev_time); + pview.show(p_prev_time); sprintf(title, "Temperature [C], time %g s", current_time); tempview.set_title(title); - tempview.show(&temperature_prev_time, Views::HERMES_EPS_HIGH); + tempview.show(temperature_prev_time, Views::HERMES_EPS_HIGH); } delete [] coeff_vec; From 7eb1db2d1b44719597ea055a4105d619cff26769 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 25 Mar 2013 10:46:44 +0100 Subject: [PATCH 10/64] Add missing files. --- 2d-advanced/euler/coupling.cpp | 102 +++++++++++++++++++++++++++++++++ 2d-advanced/euler/coupling.h | 41 +++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 2d-advanced/euler/coupling.cpp create mode 100644 2d-advanced/euler/coupling.h diff --git a/2d-advanced/euler/coupling.cpp b/2d-advanced/euler/coupling.cpp new file mode 100644 index 0000000..28b33b1 --- /dev/null +++ b/2d-advanced/euler/coupling.cpp @@ -0,0 +1,102 @@ +#include "coupling.h" + +CouplingErrorFormVelocity::CouplingErrorFormVelocity(VelocityComponent component, double c_p) + : Adapt::MatrixFormVolError(component, 4), component(component), c_p(c_p) +{ +} + +double CouplingErrorFormVelocity::value(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const +{ + double result = 0.; + if(component == velX) + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dx[point_i] * c_p; + } + } + else + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dy[point_i] * c_p; + } + } + return result; +} + +Ord CouplingErrorFormVelocity::ord(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + if(component == velX) + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dx[point_i] * c_p; + } + } + else + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dy[point_i] * c_p; + } + } + return result; +} + +MatrixFormVol* CouplingErrorFormVelocity::clone() const +{ + return new CouplingErrorFormVelocity(*this); +} + +CouplingErrorFormTemperature::CouplingErrorFormTemperature(VelocityComponent component, double c_p) + : Adapt::MatrixFormVolError(4, component), component(component), c_p(c_p) +{ +} + +double CouplingErrorFormTemperature::value(int n, double *wt, Func *u_ext[], Func *sln_j, Func *sln_i, Geom *e, Func* *ext) const +{ + double result = 0.; + if(component == velX) + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dx[point_i] * c_p; + } + } + else + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dy[point_i] * c_p; + } + } + return result; +} + +Ord CouplingErrorFormTemperature::ord(int n, double *wt, Func *u_ext[], Func *sln_j, + Func *sln_i, Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + if(component == velX) + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dx[point_i] * c_p; + } + } + else + { + for (int point_i = 0; point_i < n; point_i++) + { + result += wt[point_i] * sln_i->val[point_i] * sln_j->dy[point_i] * c_p; + } + } + return result; +} + +MatrixFormVol* CouplingErrorFormTemperature::clone() const +{ + return new CouplingErrorFormTemperature(*this); +} \ No newline at end of file diff --git a/2d-advanced/euler/coupling.h b/2d-advanced/euler/coupling.h new file mode 100644 index 0000000..7359ed1 --- /dev/null +++ b/2d-advanced/euler/coupling.h @@ -0,0 +1,41 @@ +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; + +enum VelocityComponent + { + velX = 1, + velY = 2 + }; + +class CouplingErrorFormVelocity : public Adapt::MatrixFormVolError +{ +public: + CouplingErrorFormVelocity(VelocityComponent component, double c_p); + + virtual double value(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const; + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const; + + MatrixFormVol* clone() const; + + VelocityComponent component; + double c_p; +}; + +class CouplingErrorFormTemperature : public Adapt::MatrixFormVolError +{ +public: + CouplingErrorFormTemperature(VelocityComponent component, double c_p); + + virtual double value(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const; + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *sln_i, Func *sln_j, Geom *e, Func* *ext) const; + + MatrixFormVol* clone() const; + + VelocityComponent component; + double c_p; +}; + From 944006d52cb34459bb756a9a8865163576deb12f Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 3 Apr 2013 15:27:42 +0200 Subject: [PATCH 11/64] Progress on Euler. --- 2d-advanced/euler/euler_util.h | 8 +++--- 2d-advanced/euler/forms_explicit.cpp | 39 +++------------------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index b8c106c..cbdf9e2 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -201,7 +201,7 @@ class MachNumberFilter : public Hermes::Hermes2D::SimpleFilter for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); MachNumberFilter* filter = new MachNumberFilter(slns, this->kappa); - filter->setDeleteSolutions(); + return filter; } @@ -225,7 +225,7 @@ class PressureFilter : public Hermes::Hermes2D::SimpleFilter for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); PressureFilter* filter = new PressureFilter(slns, this->kappa); - filter->setDeleteSolutions(); + return filter; } protected: @@ -250,7 +250,7 @@ class VelocityFilter : public Hermes::Hermes2D::SimpleFilter slns.push_back(this->sln[i]->clone()); VelocityFilter* filter = new VelocityFilter(slns); - filter->setDeleteSolutions(); + return filter; } protected: @@ -270,7 +270,7 @@ class EntropyFilter : public Hermes::Hermes2D::SimpleFilter for(int i = 0; i < this->num; i++) slns.push_back(this->sln[i]->clone()); EntropyFilter* filter = new EntropyFilter(slns, this->kappa, rho_ext, p_ext); - filter->setDeleteSolutions(); + return filter; } protected: diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index 86b70a6..159b9ac 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -976,20 +976,18 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW { public: MeshFunctionSharedPtr prev_temp; - double lambda, c_p, heat_flux; + double lambda, c_p; EulerEquationsWeakFormSemiImplicitCoupledWithHeat(double kappa, double rho_ext, double v1_ext, double v2_ext, double pressure_ext, Hermes::vector solid_wall_markers, Hermes::vector inlet_markers, Hermes::vector outlet_markers, - MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, MeshFunctionSharedPtr prev_temp, double lambda, double c_p, double heat_flux): EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, - prev_density_vel_x, prev_density_vel_y, prev_energy, false, 5), prev_temp(prev_temp), lambda(lambda), c_p(c_p), heat_flux(heat_flux) + MeshFunctionSharedPtr prev_density, MeshFunctionSharedPtr prev_density_vel_x, MeshFunctionSharedPtr prev_density_vel_y, MeshFunctionSharedPtr prev_energy, MeshFunctionSharedPtr prev_temp, double lambda, double c_p): EulerEquationsWeakFormSemiImplicit(kappa, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_density, + prev_density_vel_x, prev_density_vel_y, prev_energy, false, 5), prev_temp(prev_temp), lambda(lambda), c_p(c_p) { add_matrix_form(new HeatBilinearFormTime(4, c_p, lambda)); add_vector_form(new HeatLinearFormTime(4, c_p)); - //this->add_vector_form_surf(new HeatLinearSurfForm(4, inlet_markers, heat_flux, lambda)); - this->ext.push_back(prev_temp); } @@ -997,7 +995,7 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW { EulerEquationsWeakFormSemiImplicitCoupledWithHeat* wf; wf = new EulerEquationsWeakFormSemiImplicitCoupledWithHeat(this->kappa, this->rho_ext[0], this->v1_ext[0], this->v2_ext[0], this->pressure_ext[0], - this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->prev_temp, this->lambda, this->c_p, this->heat_flux); + this->solid_wall_markers, this->inlet_markers, this->outlet_markers, this->prev_density, this->prev_density_vel_x, this->prev_density_vel_y, this->prev_energy, this->prev_temp, this->lambda, this->c_p); wf->ext.clear(); @@ -1078,33 +1076,4 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW double c_p; }; - - class HeatLinearSurfForm : public VectorFormSurf - { - public: - HeatLinearSurfForm(int i, Hermes::vector areas, double heat_flux, double lambda) - : VectorFormSurf(i), heat_flux(heat_flux), lambda(lambda) - { - this->set_areas(areas); - } - - double value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - double result = 0.; - for (int point_i = 0; point_i < n; point_i++) - result += wt[i] * v->val[point_i]; - return result * heat_flux * lambda; - } - - Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, - Func* *ext) const - { - return wt[0] * v->val[0]; - } - - VectorFormSurf* clone() const { return new HeatLinearSurfForm(*this); } - - double heat_flux, lambda; - }; }; \ No newline at end of file From 00714eefec078db7bdadec05e385ba5a31e017de Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 11 Apr 2013 08:15:50 +0200 Subject: [PATCH 12/64] Updates wrt. new devel. --- 2d-advanced/euler/forward-step/main.cpp | 3 +- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 49 +++++++++---------- 2d-advanced/euler/gamm-channel/main.cpp | 16 ++++-- .../heating-flow-coupling-adapt/main.cpp | 4 +- .../euler/heating-flow-coupling/main.cpp | 40 ++++++++------- .../euler/reflected-shock-adapt/main.cpp | 2 +- 2d-advanced/euler/reflected-shock/main.cpp | 2 +- 7 files changed, 65 insertions(+), 51 deletions(-) diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index 5fdec24..b700b75 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -143,7 +143,8 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + Hermes::vector > spaces (space_rho, space_rho_v_x, space_rho_v_y, space_e); + DiscreteProblem dp(&wf, spaces); DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); LinearSolver solver(&dp); diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 98d4faf..f5cd34c 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -33,7 +33,7 @@ enum shockCapturingType KUZMIN, KRIVODONOVA }; -bool SHOCK_CAPTURING = true; +bool SHOCK_CAPTURING = false; shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; @@ -44,7 +44,7 @@ const double NU_2 = 0.1; // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; +const int INIT_REF_NUM = 2; // CFL value. double CFL_NUMBER = 0.5; // Initial time step. @@ -52,7 +52,7 @@ double time_step_n = 1E-6; // Adaptivity. // Every UNREF_FREQth time step the mesh is unrefined. -const int UNREF_FREQ = 5; +const int UNREF_FREQ = 10; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since @@ -94,11 +94,11 @@ const int MESH_REGULARITY = -1; const double CONV_EXP = 1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 0.5; // Adaptivity process stops when the number of degrees of freedom grows over // this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 10000; +const int NDOF_STOP = 100000; // Matrix solver for orthogonal projections: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, // SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. @@ -106,7 +106,7 @@ MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Equation parameters. // Exterior pressure (dimensionless). -const double P_EXT = 2.5; +const double P_EXT = 2.5; // Inlet density (dimensionless). const double RHO_EXT = 1.0; // Inlet x-velocity (dimensionless). @@ -145,7 +145,8 @@ int main(int argc, char* argv[]) SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize solutions, set initial conditions. @@ -203,6 +204,7 @@ int main(int argc, char* argv[]) space_rho_v_x->adjust_element_order(-1, P_INIT); space_rho_v_y->adjust_element_order(-1, P_INIT); space_e->adjust_element_order(-1, P_INIT); + Space::assign_dofs(spaces); } // Adaptivity loop: @@ -228,28 +230,23 @@ int main(int argc, char* argv[]) Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); SpaceSharedPtr refspace_stabilization(new L2Space(ref_space_rho->get_mesh(), 0)); if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); else selector.set_error_weights(1.0, 1.0, 1.0); - ndofs_prev = Space::get_num_dofs(ref_spaces_const); + ndofs_prev = Space::get_num_dofs(ref_spaces); // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); + OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); - - // Report NDOFs. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); - + // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); Hermes::vector inlet_markers; @@ -257,14 +254,16 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem dp(&wf, ref_spaces_const); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Space::assign_dofs(ref_spaces); + DiscreteProblem dp(&wf, ref_spaces); + dp.set_linear(); DiscreteProblem dp_stabilization(&wf_stabilization, refspace_stabilization); bool* discreteIndicator = NULL; @@ -285,15 +284,15 @@ int main(int argc, char* argv[]) { if(!SHOCK_CAPTURING) { - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, + Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } else { if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), ref_spaces_const); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), ref_spaces); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); @@ -321,7 +320,7 @@ int main(int argc, char* argv[]) double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step_n); + CFL.calculate(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step_n); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index 275d78b..026091a 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -44,11 +44,11 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 0; +const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 3; // CFL value. -double CFL_NUMBER = 0.1; +double CFL_NUMBER = 0.75; // Initial time step. double time_step = 1E-6; @@ -135,7 +135,11 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + Space::assign_dofs(spaces); + DiscreteProblem dp(&wf, spaces); + dp.set_linear(); + DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); // Time stepping loop. @@ -152,6 +156,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); dp.assemble(matrix, rhs); + FILE* fm = fopen("matrix", "w"); + matrix->dump(fm, "A"); + FILE* fv = fopen("vector", "w"); + rhs->dump(fv, "b"); + fclose(fm); + fclose(fv); // Solve the matrix problem. Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index ce2d8a8..6e5b95e 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -192,10 +192,10 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P, HEAT_FLUX); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, cspaces); + DiscreteProblem dp(&wf, cspaces); // Time stepping loop. for(; t < 10.0; t += time_step) diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index ee7ae36..546d7c3 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -20,7 +20,7 @@ const unsigned int EVERY_NTH_STEP = 1; const int P_INIT_FLOW = 1; const int P_INIT_HEAT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 1; // Shock capturing. enum shockCapturingType @@ -28,7 +28,7 @@ enum shockCapturingType KUZMIN, KRIVODONOVA }; -bool SHOCK_CAPTURING = true; +bool SHOCK_CAPTURING = false; shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; @@ -53,11 +53,9 @@ const double V2_EXT = 0.0; // Kappa. const double KAPPA = 1.4; // Lambda. -const double LAMBDA = 1e3; +const double LAMBDA = 1e2; // heat_capacity. -const double C_P = 1e2; -// heat flux through the inlet. -const double HEAT_FLUX = 1e-3; +const double C_P = 1e-2; // CFL value. const double CFL_NUMBER = 0.1; @@ -83,18 +81,21 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); + mesh_heat->copy(mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) + { mesh->refine_all_elements(0, true); - - mesh_heat->copy(mesh); - mesh_heat->refine_towards_boundary("Inlet", 3, false); - mesh->refine_all_elements(0, true); + mesh_heat->refine_all_elements(0, true); + } + mesh->refine_all_elements(0, true); + mesh_heat->refine_towards_boundary("Inlet"); + mesh_heat->refine_towards_boundary("Inlet"); // Initialize boundary condition types and spaces with default shapesets. Hermes2D::DefaultEssentialBCConst bc_temp_zero("Solid", 0.0); @@ -122,10 +123,10 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr vel_x(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_x))); MeshFunctionSharedPtr vel_y(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_y))); - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); - VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); - ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); - ScalarView temperature_view("Temperature", new WinGeom(900, 700, 800, 600)); + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 400, 300)); + VectorView velocity_view("Velocity", new WinGeom(0, 400, 400, 300)); + ScalarView density_view("Density", new WinGeom(500, 0, 400, 300)); + ScalarView temperature_view("Temperature", new WinGeom(500, 400, 400, 300)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(); @@ -148,13 +149,16 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; EulerEquationsWeakFormSemiImplicitCoupledWithHeat wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P, HEAT_FLUX); + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp, LAMBDA, C_P); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e, space_temp); + Space::assign_dofs(spaces); + DiscreteProblem dp(&wf, spaces); + dp.set_linear(); // Time stepping loop. - for(; t < 10.0; t += time_step) + for(; ; t += time_step) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index c401de8..bdb58d8 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, + DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); LinearSolver solver(&dp); diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index b1025f7..ea1a6cf 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) wf.set_stabilization(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, NU_1, NU_2); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); + DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); LinearSolver solver(&dp); solver.output_matrix(); solver.output_rhs(); From f9729249703cfb3e3c3b5a4b6fe7da7d81d6f1f6 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 11 Apr 2013 12:51:23 +0200 Subject: [PATCH 13/64] Use LinearSolver class in GAMM channel. --- 2d-advanced/euler/gamm-channel/main.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index 026091a..d19f319 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -114,10 +114,7 @@ int main(int argc, char* argv[]) ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); // Set up the solver, matrix, and rhs according to the solver selection. - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); @@ -137,8 +134,8 @@ int main(int argc, char* argv[]) // Initialize the FE problem. Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); Space::assign_dofs(spaces); - DiscreteProblem dp(&wf, spaces); - dp.set_linear(); + + LinearSolver solver(&wf, spaces); DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); @@ -155,32 +152,24 @@ int main(int argc, char* argv[]) // Assemble the stiffness matrix and rhs. Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - dp.assemble(matrix, rhs); - FILE* fm = fopen("matrix", "w"); - matrix->dump(fm, "A"); - FILE* fv = fopen("vector", "w"); - rhs->dump(fv, "b"); - fclose(fm); - fclose(fv); - // Solve the matrix problem. Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); try { - solver->solve(); + solver.solve(); if(!SHOCK_CAPTURING) { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); } else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); if(SHOCK_CAPTURING_TYPE == KUZMIN) From 087d84aa47f5167250b05e189aebc1e27793c8b9 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sat, 13 Apr 2013 12:58:40 +0200 Subject: [PATCH 14/64] Progress on porting of the code to new devel. --- 1d/layer-boundary/definitions.cpp | 2 +- 1d/layer-boundary/definitions.h | 2 +- 1d/layer-boundary/main.cpp | 40 +++--- 1d/moving-front/definitions.h | 2 +- 1d/moving-front/main.cpp | 65 ++++----- 1d/poisson/main.cpp | 20 +-- 1d/system/definitions.cpp | 4 +- 1d/system/definitions.h | 4 +- 1d/system/main.cpp | 97 +++++++------ 2d-advanced/acoustics/apartment/main.cpp | 47 +++---- 2d-advanced/acoustics/horn-axisym/main.cpp | 49 ++++--- .../linear-advection-dg-adapt/main.cpp | 38 +++--- .../linear-advection-diffusion/main.cpp | 34 ++--- .../elasticity-linear/bracket/main.cpp | 104 +++++++------- 2d-advanced/elasticity-linear/crack/main.cpp | 94 ++++++------- .../euler/euler-coupled-adapt/main.cpp | 6 +- 2d-advanced/euler/euler-coupled/main.cpp | 6 +- 2d-advanced/euler/euler_util.cpp | 2 +- 2d-advanced/euler/euler_util.h | 2 +- 2d-advanced/euler/forms_explicit.cpp | 8 +- 2d-advanced/euler/forward-step-adapt/main.cpp | 32 ++--- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 20 +-- .../heating-flow-coupling-adapt/main.cpp | 8 +- .../euler/heating-flow-coupling/main.cpp | 2 +- .../heating-induced-vortex-adapt/main.cpp | 36 ++--- .../euler/joukowski-profile-adapt/main.cpp | 6 +- 2d-advanced/euler/joukowski-profile/main.cpp | 6 +- .../euler/reflected-shock-adapt/main.cpp | 36 ++--- .../heat-and-moisture-adapt/main.cpp | 102 +++++++------- .../main.cpp | 92 ++++++------- 2d-advanced/helmholtz/waveguide/main.cpp | 24 ++-- .../maxwell/magnetostatics/definitions.cpp | 8 +- .../maxwell/magnetostatics/definitions.h | 4 +- 2d-advanced/maxwell/magnetostatics/main.cpp | 30 ++-- .../maxwell/maxwell-debye-rk/definitions.h | 6 +- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 129 ++++++++---------- .../maxwell/microwave-oven/definitions.cpp | 2 +- .../maxwell/microwave-oven/definitions.h | 2 +- 2d-advanced/maxwell/microwave-oven/main.cpp | 50 +++---- .../resonator-time-domain-I/definitions.h | 2 +- .../maxwell/resonator-time-domain-I/main.cpp | 16 +-- .../definitions.cpp | 2 +- .../resonator-time-domain-II-ie/definitions.h | 4 +- .../resonator-time-domain-II-ie/main.cpp | 20 +-- .../resonator-time-domain-II-rk/definitions.h | 2 +- .../resonator-time-domain-II-rk/main.cpp | 26 ++-- .../local-projection-test/main.cpp | 22 +-- .../navier-stokes/bearing/definitions.cpp | 16 +-- .../navier-stokes/bearing/definitions.h | 16 +-- 2d-advanced/navier-stokes/bearing/main.cpp | 41 +++--- .../circular-obstacle-adapt/definitions.cpp | 20 +-- .../circular-obstacle-adapt/definitions.h | 16 +-- .../circular-obstacle-adapt/main.cpp | 88 ++++++------ .../circular-obstacle/definitions.cpp | 16 +-- .../circular-obstacle/definitions.h | 16 +-- .../navier-stokes/circular-obstacle/main.cpp | 24 ++-- .../driven-cavity/definitions.cpp | 4 +- .../navier-stokes/driven-cavity/definitions.h | 8 +- .../navier-stokes/driven-cavity/main.cpp | 20 +-- .../navier-stokes/ns-heat-subdomains/main.cpp | 2 +- .../rayleigh-benard/definitions.cpp | 10 +- .../navier-stokes/rayleigh-benard/main.cpp | 18 +-- .../np-poisson-timedep-adapt/definitions.cpp | 4 +- .../np-poisson-timedep-adapt/main.cpp | 128 ++++++++--------- .../timestep_controller.h | 6 +- .../neutronics/4-group-adapt/definitions.cpp | 2 +- .../neutronics/4-group-adapt/definitions.h | 8 +- 2d-advanced/neutronics/4-group-adapt/main.cpp | 2 +- .../neutronics/4-group/definitions.cpp | 2 +- 2d-advanced/neutronics/4-group/main.cpp | 2 +- 2d-advanced/neutronics/saphir/main.cpp | 34 ++--- .../richards/basic-ie-newton/definitions.cpp | 2 +- .../richards/basic-ie-newton/definitions.h | 2 +- 2d-advanced/richards/basic-ie-newton/main.cpp | 22 +-- .../richards/basic-ie-picard/definitions.cpp | 6 +- .../richards/basic-ie-picard/definitions.h | 2 +- 2d-advanced/richards/basic-ie-picard/main.cpp | 19 +-- .../richards/basic-rk-newton-adapt/main.cpp | 60 ++++---- 2d-advanced/richards/basic-rk-newton/main.cpp | 16 +-- .../capillary-barrier-adapt/definitions.h | 10 +- .../richards/capillary-barrier-adapt/main.cpp | 107 +++++++-------- .../richards/capillary-barrier-rk/main.cpp | 36 ++--- .../gross-pitaevski-adapt/definitions.h | 2 +- .../gross-pitaevski-adapt/main.cpp | 82 +++++------ .../gross-pitaevski/definitions.h | 2 +- .../schroedinger/gross-pitaevski/main.cpp | 14 +- .../wave-equation/wave-1/definitions.cpp | 4 +- .../wave-equation/wave-1/definitions.h | 4 +- 2d-advanced/wave-equation/wave-1/main.cpp | 16 +-- .../layer-boundary/definitions.cpp | 2 +- .../layer-boundary/definitions.h | 2 +- 2d-benchmarks-general/layer-boundary/main.cpp | 42 +++--- .../layer-interior/definitions.h | 2 +- 2d-benchmarks-general/layer-interior/main.cpp | 38 +++--- 2d-benchmarks-general/lshape/main.cpp | 38 +++--- .../moving-front-space-adapt/definitions.h | 2 +- .../moving-front-space-adapt/main.cpp | 58 ++++---- .../nonsym-check/definitions.cpp | 6 +- 2d-benchmarks-general/nonsym-check/main.cpp | 38 +++--- .../smooth-aniso-x/definitions.h | 2 +- 2d-benchmarks-general/smooth-aniso-x/main.cpp | 38 +++--- .../smooth-aniso-y/definitions.h | 2 +- 2d-benchmarks-general/smooth-aniso-y/main.cpp | 38 +++--- 2d-benchmarks-general/smooth-iso/main.cpp | 38 +++--- .../01-analytic-solution/definitions.h | 2 +- .../01-analytic-solution/main.cpp | 38 +++--- .../02-reentrant-corner/definitions.h | 2 +- .../02-reentrant-corner/main.cpp | 38 +++--- .../03-linear-elasticity/definitions.h | 4 +- .../03-linear-elasticity/main.cpp | 88 ++++++------ .../04-exponential-peak/definitions.h | 2 +- .../04-exponential-peak/main.cpp | 38 +++--- 2d-benchmarks-nist/05-battery/main.cpp | 38 +++--- .../06-boundary-layer/definitions.h | 2 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 38 +++--- .../definitions.h | 2 +- .../07-boundary-line-singularity/main.cpp | 38 +++--- .../08-oscillatory/definitions.h | 2 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 38 +++--- .../09-wave-front-kelly-dealii/definitions.h | 2 +- .../09-wave-front-kelly/definitions.h | 2 +- .../09-wave-front/definitions.h | 2 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 38 +++--- .../definitions.cpp | 2 +- .../definitions.h | 2 +- .../10-interior-line-singularity/main.cpp | 38 +++--- 2d-benchmarks-nist/11-kellogg/definitions.h | 2 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 38 +++--- .../12-multiple-difficulties/definitions.h | 2 +- .../12-multiple-difficulties/main.cpp | 38 +++--- 130 files changed, 1524 insertions(+), 1582 deletions(-) diff --git a/1d/layer-boundary/definitions.cpp b/1d/layer-boundary/definitions.cpp index d8300e5..6384257 100644 --- a/1d/layer-boundary/definitions.cpp +++ b/1d/layer-boundary/definitions.cpp @@ -15,7 +15,7 @@ double CustomExactFunction::dduhat_dxx(double x) return -K*K * (exp(K*x) + exp(-K*x)) / (exp(K) + exp(-K)); } -CustomExactSolution::CustomExactSolution(const Mesh* mesh, double K) : ExactSolutionScalar(mesh) +CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh, double K) : ExactSolutionScalar(mesh) { cef = new CustomExactFunction(K); } diff --git a/1d/layer-boundary/definitions.h b/1d/layer-boundary/definitions.h index 8dcc1a6..a230b30 100644 --- a/1d/layer-boundary/definitions.h +++ b/1d/layer-boundary/definitions.h @@ -25,7 +25,7 @@ class CustomExactFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh, double K); + CustomExactSolution(MeshSharedPtr mesh, double K); virtual double value (double x, double y) const; diff --git a/1d/layer-boundary/main.cpp b/1d/layer-boundary/main.cpp index d556c12..7c34b3a 100644 --- a/1d/layer-boundary/main.cpp +++ b/1d/layer-boundary/main.cpp @@ -91,10 +91,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -118,16 +118,16 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. int refinement_type = 0; Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -152,27 +152,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -180,15 +180,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -197,7 +197,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -208,10 +208,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - if(done == false) - delete ref_space->get_mesh(); - delete ref_space; } while (done == false); diff --git a/1d/moving-front/definitions.h b/1d/moving-front/definitions.h index 7035c5d..b1d4f70 100644 --- a/1d/moving-front/definitions.h +++ b/1d/moving-front/definitions.h @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double x0, double x1, double y0, double y1, + CustomExactSolution(MeshSharedPtr mesh, double x0, double x1, double y0, double y1, double* t_ptr, double s, double c) : ExactSolutionScalar(mesh), x0(x0), x1(x1), y0(y0), y1(y1), t_ptr(t_ptr), s(s), c(c) {}; diff --git a/1d/moving-front/main.cpp b/1d/moving-front/main.cpp index 57a30cf..673fe9d 100644 --- a/1d/moving-front/main.cpp +++ b/1d/moving-front/main.cpp @@ -115,11 +115,11 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH1DXML mloader; try { - mloader.load("domain.xml", &basemesh); + mloader.load("domain.xml", basemesh); } catch(Hermes::Exceptions::MeshLoadFailureException& e) { @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) // Perform initial mesh refinements. int refinement_type = 2; // Split elements vertically. for(int i = 0; i < INIT_REF_NUM; i++) basemesh->refine_all_elements(refinement_type, true); - mesh->copy(&basemesh); + mesh->copy(basemesh); // Exact solution. CustomExactSolution exact_sln(mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); @@ -140,8 +140,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof_coarse = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof_coarse = space->get_num_dofs(); // Initialize the weak formulation CustomFunction f(x_0, x_1, y_0, y_1, s, c); @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) // Previous and next time level solution. ZeroSolution sln_time_prev(mesh); - Solution sln_time_new(mesh); + MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -158,8 +158,8 @@ int main(int argc, char* argv[]) char title[100]; Views::ScalarView sview("Initial condition", new Views::WinGeom(0, 0, 1200, 200)); Views::OrderView oview("Initial mesh", new Views::WinGeom(0, 260, 1200, 200)); - sview.show(&sln_time_prev); - oview.show(&space); + sview.show(sln_time_prev); + oview.show(space); // Graph for dof history. SimpleGraph dof_history_graph; @@ -173,20 +173,20 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; case 2: mesh->unrefine_all_elements(); - space.set_uniform_order(P_INIT); + space->set_uniform_order(P_INIT); break; case 3: mesh->unrefine_all_elements(); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - space.assign_dofs(); - ndof_coarse = space.get_num_dofs(); + space->assign_dofs(); + ndof_coarse = space->get_num_dofs(); } // Spatial adaptivity loop. Note: sln_time_prev must not be changed @@ -196,16 +196,16 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. int refinement_type = 0; Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); // Initialize Runge-Kutta time stepping. @@ -222,9 +222,9 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); - runge_kutta.rk_time_step_newton(&sln_time_prev, &sln_time_new); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); + runge_kutta.rk_time_step_newton(sln_time_prev, sln_time_new); } catch(Exceptions::Exception& e) { @@ -235,16 +235,16 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse mesh-> Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - OGProjection ogProjection; ogProjection.project_global(&space, &sln_time_new, &sln_coarse); + OGProjection ogProjection; ogProjection.project_global(space, sln_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(&space); - double err_est_rel_total = adaptivity->calc_err_est(&sln_coarse, &sln_time_new) * 100; + Adapt* adaptivity = new Adapt(space); + double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, sln_time_new) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", - space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); + space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; @@ -253,7 +253,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (space.get_num_dofs() >= NDOF_STOP) + if (space->get_num_dofs() >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -262,11 +262,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; - if(!done) - { - delete sln_time_new.get_mesh(); - delete ref_space; - } } while (done == false); @@ -275,15 +270,15 @@ int main(int argc, char* argv[]) sprintf(title, "Solution, time %g", current_time); sview.set_title(title); sview.show_mesh(false); - sview.show(&sln_time_new); + sview.show(sln_time_new); sprintf(title, "Mesh, time %g", current_time); oview.set_title(title); - oview.show(&space); + oview.show(space); // Copy last reference solution into sln_time_prev. - sln_time_prev.copy(&sln_time_new); + sln_time_prev.copy(sln_time_new); - dof_history_graph.add_values(current_time, space.get_num_dofs()); + dof_history_graph.add_values(current_time, space->get_num_dofs()); dof_history_graph.save("dof_history.dat"); // Increase current time and counter of time steps. diff --git a/1d/poisson/main.cpp b/1d/poisson/main.cpp index 488b0a0..b335884 100644 --- a/1d/poisson/main.cpp +++ b/1d/poisson/main.cpp @@ -59,19 +59,19 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Show the mesh and poly degrees. Views::OrderView oview("Mesh", new Views::WinGeom(0, 0, 900, 250)); - if (HERMES_VISUALIZATION) oview.show(&space); + if (HERMES_VISUALIZATION) oview.show(space); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Perform Newton's iteration and translate the resulting coefficient vector into a Solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); NewtonSolver newton(&dp); try { @@ -82,7 +82,7 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - Solution::vector_to_solution(newton.get_sln_vector(), &space, &sln); + Solution::vector_to_solution(newton.get_sln_vector(), space, sln); // Get info about time spent during assembling in its respective parts. //dp.get_all_profiling_output(std::cout); @@ -93,12 +93,12 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Views::Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(sln, "sln->vtk", "Temperature", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Output mesh and element orders in VTK format. Views::Orderizer ord; - ord.save_orders_vtk(&space, "ord.vtk"); + ord.save_orders_vtk(space, "ord.vtk"); Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", "ord.vtk"); } @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) // tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default), // HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows // considerably with more accurate representation, so use it wisely. - view.show(&sln, Views::HERMES_EPS_HIGH); + view.show(sln, Views::HERMES_EPS_HIGH); Views::View::wait(); } diff --git a/1d/system/definitions.cpp b/1d/system/definitions.cpp index e07e552..7fcbccc 100644 --- a/1d/system/definitions.cpp +++ b/1d/system/definitions.cpp @@ -85,7 +85,7 @@ CustomRightHandSide2::~CustomRightHandSide2() } -ExactSolutionFitzHughNagumo1::ExactSolutionFitzHughNagumo1(const Mesh* mesh) +ExactSolutionFitzHughNagumo1::ExactSolutionFitzHughNagumo1(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { cef1 = new CustomExactFunction1(); @@ -118,7 +118,7 @@ MeshFunction* ExactSolutionFitzHughNagumo1::clone() const } -ExactSolutionFitzHughNagumo2::ExactSolutionFitzHughNagumo2(const Mesh* mesh, double K) +ExactSolutionFitzHughNagumo2::ExactSolutionFitzHughNagumo2(MeshSharedPtr mesh,double K) : ExactSolutionScalar(mesh), K(K) { cef2 = new CustomExactFunction2(K); diff --git a/1d/system/definitions.h b/1d/system/definitions.h index bf5d832..d3c4b21 100644 --- a/1d/system/definitions.h +++ b/1d/system/definitions.h @@ -69,7 +69,7 @@ class CustomRightHandSide2: public Hermes::Hermes2DFunction class ExactSolutionFitzHughNagumo1 : public ExactSolutionScalar { public: - ExactSolutionFitzHughNagumo1(const Mesh* mesh); + ExactSolutionFitzHughNagumo1(MeshSharedPtr mesh); virtual double value(double x, double y) const; @@ -86,7 +86,7 @@ class ExactSolutionFitzHughNagumo1 : public ExactSolutionScalar class ExactSolutionFitzHughNagumo2 : public ExactSolutionScalar { public: - ExactSolutionFitzHughNagumo2(const Mesh* mesh, double K); + ExactSolutionFitzHughNagumo2(MeshSharedPtr mesh, double K); virtual double value(double x, double y) const; diff --git a/1d/system/main.cpp b/1d/system/main.cpp index e7212ca..1d54518 100644 --- a/1d/system/main.cpp +++ b/1d/system/main.cpp @@ -94,9 +94,9 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Load the mesh-> - Mesh u_mesh, v_mesh; + MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh); MeshReaderH1DXML mloader; - mloader.load("domain.xml", &u_mesh); + mloader.load("domain.xml", u_mesh); u_mesh->refine_all_elements(); if (MULTI == false) @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) } // Create initial mesh (master mesh). - v_mesh->copy(&u_mesh); + v_mesh->copy(u_mesh); // Initial mesh refinements in the v_mesh towards the boundary. if (MULTI == true) @@ -119,8 +119,8 @@ int main(int argc, char* argv[]) #ifdef WITH_EXACT_SOLUTION // Set exact solutions. - ExactSolutionFitzHughNagumo1 exact_u(&u_mesh); - ExactSolutionFitzHughNagumo2 exact_v(&v_mesh, K); + MeshFunctionSharedPtr exact_u(new ExactSolutionFitzHughNagumo1(u_mesh)); + MeshFunctionSharedPtr exact_v(new ExactSolutionFitzHughNagumo2(v_mesh, K)); #endif // Define right-hand sides. @@ -137,11 +137,11 @@ int main(int argc, char* argv[]) EssentialBCs bcs_v(&bc_v); // Create H1 spaces with default shapeset for both displacement components. - H1Space u_space(&u_mesh, &bcs_u, P_INIT_U); - H1Space v_space(MULTI ? &v_mesh : &u_mesh, &bcs_v, P_INIT_V); + SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); + SpaceSharedPtr v_space(new H1Space(MULTI ? v_mesh : u_mesh, &bcs_v, P_INIT_V)); // Initialize coarse and reference mesh solutions. - Solution u_sln, v_sln, u_ref_sln, v_ref_sln; + MeshFunctionSharedPtr u_sln(new Solution), v_sln(new Solution), u_ref_sln(new Solution), v_ref_sln(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -167,33 +167,33 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. int refinement_type = 0; - Mesh::ReferenceMeshCreator refMeshCreator1(&u_mesh); - Mesh* ref_u_mesh = refMeshCreator1.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreator1(u_mesh); + MeshSharedPtr ref_u_mesh = refMeshCreator1.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator1(&u_space, ref_u_mesh); - Space* ref_u_space = refSpaceCreator1.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator1(u_space, ref_u_mesh); + SpaceSharedPtr ref_u_space = refSpaceCreator1.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreator2(&v_mesh); - Mesh* ref_v_mesh = refMeshCreator2.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreator2(v_mesh); + MeshSharedPtr ref_v_mesh = refMeshCreator2.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator2(&v_space, ref_v_mesh); - Space* ref_v_space = refSpaceCreator2.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator2(v_space, ref_v_mesh); + SpaceSharedPtr ref_v_space = refSpaceCreator2.create_ref_space(); - Hermes::vector *> ref_spaces(ref_u_space, ref_v_space); - Hermes::vector *> ref_spaces_const(ref_u_space, ref_v_space); + Hermes::vector > ref_spaces(ref_u_space, ref_v_space); + Hermes::vector > ref_spaces(ref_u_space, ref_v_space); - int ndof_ref = Space::get_num_dofs(ref_spaces_const); + int ndof_ref = Space::get_num_dofs(ref_spaces); // Initialize reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); newton.set_verbose_output(true); @@ -212,39 +212,39 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, - Hermes::vector *>(&u_ref_sln, &v_ref_sln)); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, + Hermes::vector >(u_ref_sln, v_ref_sln)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solutions on coarse meshes."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u_space, &v_space), - Hermes::vector *>(&u_ref_sln, &v_ref_sln), - Hermes::vector *>(&u_sln, &v_sln)); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u_space, v_space), + Hermes::vector >(u_ref_sln, v_ref_sln), + Hermes::vector >(u_sln, v_sln)); cpu_time.tick(); // View the coarse mesh solution and polynomial orders. - s_view_0.show(&u_ref_sln); - o_view_0.show(&u_space); - s_view_1.show(&v_ref_sln); - o_view_1.show(&v_space); + s_view_0.show(u_ref_sln); + o_view_0.show(u_space); + s_view_1.show(v_ref_sln); + o_view_1.show(v_space); // Calculate element errors. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&u_space, &v_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(u_space, v_space)); // Calculate error estimate for each solution component and the total error estimate. Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector *>(&u_sln, &v_sln), - Hermes::vector *>(&u_ref_sln, &v_ref_sln), &err_est_rel) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u_sln, v_sln), + Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100; #ifdef WITH_EXACT_SOLUTION // Calculate exact error for each solution component and the total exact error. Hermes::vector err_exact_rel; bool solutions_for_adapt = false; - double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector *>(&u_sln, &v_sln), - Hermes::vector *>(&exact_u, &exact_v), &err_exact_rel, solutions_for_adapt) * 100; + double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector >(u_sln, v_sln), + Hermes::vector >(exact_u, exact_v), &err_exact_rel, solutions_for_adapt) * 100; #endif // Time measurement. @@ -253,34 +253,34 @@ int main(int argc, char* argv[]) // Report results. #ifdef WITH_EXACT_SOLUTION Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", - u_space.get_num_dofs(), ref_u_space->get_num_dofs()); + u_space->get_num_dofs(), ref_u_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%, err_exact_rel[0]: %g%%", err_est_rel[0]*100, err_exact_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", - v_space.get_num_dofs(), ref_v_space->get_num_dofs()); + v_space->get_num_dofs(), ref_v_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%, err_exact_rel[1]: %g%%", err_est_rel[1]*100, err_exact_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", - Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), - Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(u_space, v_space)), + Space::get_num_dofs(ref_spaces)); Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%, err_est_exact_total: %g%%", err_est_rel_total, err_exact_rel_total); #else - Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", u_space.get_num_dofs(), u_ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", u_space->get_num_dofs(), u_ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%", err_est_rel[0]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", v_space.get_num_dofs(), v_ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", v_space->get_num_dofs(), v_ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%", err_est_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", - Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), + Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(*ref_spaces)); Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%", err_est_rel_total); #endif // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), + graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u_space, v_space)), err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); #ifdef WITH_EXACT_SOLUTION - graph_dof_exact.add_values(Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), + graph_dof_exact.add_values(Space::get_num_dofs(Hermes::vector >(u_space, v_space)), err_exact_rel_total); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(cpu_time.accumulated(), err_exact_rel_total); @@ -296,16 +296,11 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } - if (Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)) + if (Space::get_num_dofs(Hermes::vector >(u_space, v_space)) >= NDOF_STOP) done = true; // Clean up. delete adaptivity; - for(unsigned int i = 0; i < ref_spaces.size(); i++) - { - delete (ref_spaces)[i]->get_mesh(); - delete (ref_spaces)[i]; - } // Increase counter. as++; diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index 3f63747..26ce65b 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -92,15 +92,15 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(mesh, &bcs, P_INIT); - int ndof = Space >::get_num_dofs(&space); + SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + int ndof = Space >::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormAcoustics wf("Wall", RHO, SOUND_SPEED, OMEGA); // Initialize coarse and reference mesh solution. - Solution > sln, ref_sln; + MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinement selector. H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -121,12 +121,12 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space >* ref_space = refSpaceCreator.create_ref_space(); + Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = Space >::get_num_dofs(ref_space); @@ -148,35 +148,35 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln. - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + // Translate the resulting coefficient vector into the Solution > sln-> + Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); // View the coarse mesh solution and polynomial orders. - RealFilter acoustic_pressure(&sln); - sview.show(&acoustic_pressure); - oview.show(&space); + RealFilter acoustic_pressure(sln); + sview.show(acoustic_pressure); + oview.show(space); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt >* adaptivity = new Adapt >(&space); - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt >* adaptivity = new Adapt >(space); + double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(&space), Space >::get_num_dofs(ref_space), err_est_rel); + Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(&space), err_est_rel); + graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); @@ -188,12 +188,9 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } - if (Space >::get_num_dofs(&space) >= NDOF_STOP) done = true; + if (Space >::get_num_dofs(space) >= NDOF_STOP) done = true; delete adaptivity; - if(!done) - delete ref_space->get_mesh(); - delete ref_space; // Increase counter. as++; @@ -205,14 +202,14 @@ int main(int argc, char* argv[]) // Show the reference solution - the final result. sview.set_title("Fine mesh solution magnitude"); - RealFilter ref_mag(&ref_sln); - sview.show(&ref_mag); + RealFilter ref_mag(ref_sln); + sview.show(ref_mag); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_mag, "sln.vtk", "Acoustic pressure", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(&ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index 880592d..167d1b0 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -92,15 +92,15 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(mesh, &bcs, P_INIT); - int ndof = Space >::get_num_dofs(&space); + SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + int ndof = Space >::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormAcoustics wf("Outlet", RHO, SOUND_SPEED, OMEGA); // Initialize coarse and reference mesh solution. - Solution > sln, ref_sln; + MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinement selector. H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -124,12 +124,12 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space >* ref_space = refSpaceCreator.create_ref_space(); + Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = Space >::get_num_dofs(ref_space); // Assemble the reference problem. @@ -150,35 +150,35 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln. - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + // Translate the resulting coefficient vector into the Solution > sln-> + Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); // View the coarse mesh solution and polynomial orders. - RealFilter mag(&ref_sln); - sview_real.show(&mag); - oview.show(&space); + MeshFunctionSharedPtr mag(new RealFilter(ref_sln)); + sview_real.show(mag); + oview.show(space); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt >* adaptivity = new Adapt >(&space); - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt >* adaptivity = new Adapt >(space); + double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(&space), Space >::get_num_dofs(ref_space), err_est_rel); + Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(&space), err_est_rel); + graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); @@ -190,12 +190,9 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } - if (Space >::get_num_dofs(&space) >= NDOF_STOP) done = true; + if (Space >::get_num_dofs(space) >= NDOF_STOP) done = true; delete adaptivity; - if (done == false) - delete ref_space->get_mesh(); - delete ref_space; // Increase counter. as++; @@ -205,15 +202,15 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); // Show the reference solution - the final result. - RealFilter ref_mag(&ref_sln); - sview_real.show(&ref_mag); - oview.show(&space); + MeshFunctionSharedPtr ref_mag(new RealFilter(ref_sln)); + sview_real.show(ref_mag); + oview.show(space); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_mag, "sln.vtk", "Acoustic pressure", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(&ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index 041b32e..5bdfb1e 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -67,8 +67,8 @@ int main(int argc, char* args[]) // Perform initial mesh refinement. for (int i=0; irefine_all_elements(); - // Create an L2 space. - L2Space space(mesh, P_INIT); + // Create an L2 space-> + L2Space space(mesh, P_INIT)); // Initialize refinement selector. L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -81,10 +81,10 @@ int main(int argc, char* args[]) // Display the mesh-> OrderView oview("Coarse mesh", new WinGeom(0, 0, 440, 350)); - oview.show(&space); + oview.show(space); - Solution sln; - Solution ref_sln; + MeshFunctionSharedPtr sln(new Solution()); + MeshFunctionSharedPtr ref_sln(new Solution()); // Initialize the weak formulation. CustomWeakForm wf("Bdy_bottom_left", mesh); @@ -93,17 +93,17 @@ int main(int argc, char* args[]) view1.fix_scale_width(60); // Initialize linear solver. - Hermes::Hermes2D::LinearSolver linear_solver(&wf, &space); + Hermes::Hermes2D::LinearSolver linear_solver(&wf, space); int as = 1; bool done = false; do { // Construct globally refined reference mesh - // and setup reference space. + // and setup reference space-> Mesh::ReferenceMeshCreator ref_mesh_creator(mesh); - Mesh* ref_mesh = ref_mesh_creator.create_ref_mesh(); - Space::ReferenceSpaceCreator ref_space_creator(&space, ref_mesh); - Space* ref_space = ref_space_creator.create_ref_space(); + MeshSharedPtr ref_mesh = ref_mesh_creator.create_ref_mesh(); + Space::ReferenceSpaceCreator ref_space_creator(space, ref_mesh); + SpaceSharedPtr ref_space = ref_space_creator.create_ref_space(); linear_solver.set_space(ref_space); @@ -111,7 +111,7 @@ int main(int argc, char* args[]) try { linear_solver.solve(); - Solution::vector_to_solution(linear_solver.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(linear_solver.get_sln_vector(), ref_space, ref_sln); } catch(std::exception& e) { @@ -119,22 +119,22 @@ int main(int argc, char* args[]) } // Project the fine mesh solution onto the coarse mesh-> OGProjection ogProjection; - ogProjection.project_global(&space, &ref_sln, &sln, HERMES_L2_NORM); + ogProjection.project_global(space, ref_sln, sln, HERMES_L2_NORM); - ValFilter val_filter(&ref_sln, 0.0, 1.0); + ValFilter val_filter(ref_sln, 0.0, 1.0); // View the coarse mesh solution. - view1.show(&val_filter); - oview.show(&space); + view1.show(val_filter); + oview.show(space); // Calculate element errors and total error estimate. - Adapt* adaptivity = new Adapt(&space); - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt* adaptivity = new Adapt(space); + double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; std::cout << "Error: " << err_est_rel << "%." << std::endl; // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(&space), err_est_rel); + graph_dof_est.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); // If err_est_rel too large, adapt the mesh-> @@ -143,7 +143,7 @@ int main(int argc, char* args[]) { done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if(Space::get_num_dofs(&space) >= NDOF_STOP) + if(Space::get_num_dofs(space) >= NDOF_STOP) { done = true; break; diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index e79d63b..134a5ee 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -90,13 +90,13 @@ int main(int argc, char* argv[]) EssentialBCs bcs(Hermes::vector *>(&bc_rest, &bc_layer)); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); WinGeom* sln_win_geom = new WinGeom(0, 0, 440, 350); WinGeom* mesh_win_geom = new WinGeom(450, 0, 400, 350); // Initialize coarse and reference mesh solution. - Solution sln, ref_sln; + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -121,12 +121,12 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); // Initialize matrix solver. SparseMatrix* matrix = create_matrix(); @@ -143,37 +143,37 @@ int main(int argc, char* argv[]) // Solve the linear system of the reference problem. // If successful, obtain the solution. - if(solver->solve()) Solution::vector_to_solution(solver->get_sln_vector(), ref_space, &ref_sln); + if(solver->solve()) Solution::vector_to_solution(solver->get_sln_vector(), ref_space, ref_sln); else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(&space); - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt* adaptivity = new Adapt(space); + double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space::get_num_dofs(&space), err_est_rel); + graph_dof.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) // Increase the counter of performed adaptivity steps. if (done == false) as++; } - if (Space::get_num_dofs(&space) >= NDOF_STOP) done = true; + if (Space::get_num_dofs(space) >= NDOF_STOP) done = true; // Clean up. delete solver; @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) delete rhs; delete adaptivity; if(done == false) delete ref_space->get_mesh(); - delete ref_space; + delete dp; } @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) // Show the reference solution - the final result. sview.set_title("Fine mesh solution"); sview.show_mesh(false); - sview.show(&ref_sln); + sview.show(ref_sln); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 2b4ade9..ece0d29 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -87,9 +87,9 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Load the mesh-> - Mesh u1_mesh, u2_mesh; + MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &u1_mesh); + mloader.load("domain.mesh", u1_mesh); // Initial mesh refinements. u1_mesh->refine_element_id(1); @@ -97,27 +97,27 @@ int main(int argc, char* argv[]) // Create initial mesh for the vertical displacement component. // This also initializes the multimesh hp-FEM. - u2_mesh->copy(&u1_mesh); + u2_mesh->copy(u1_mesh); // Initialize boundary conditions. DefaultEssentialBCConst zero_disp("bdy_right", 0.0); EssentialBCs bcs(&zero_disp); // Create x- and y- displacement space using the default H1 shapeset. - H1Space u1_space(&u1_mesh, &bcs, P_INIT); - H1Space u2_space(&u2_mesh, &bcs, P_INIT); - Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space))); + H1Space u1_space(u1_mesh, &bcs, P_INIT)); + H1Space u2_space(u2_mesh, &bcs, P_INIT)); + Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); // Initialize the weak formulation. // NOTE; These weak forms are identical to those in example P01-linear/08-system. CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy_top", f0, f1); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector *>(&u1_space, &u2_space)); + DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); // Initialize coarse and reference mesh solutions. - Solution u1_sln, u2_sln; - Solution u1_sln_ref, u2_sln_ref; + MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); + MeshFunctionSharedPtru1_sln_ref(new Solution), u2_sln_ref(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -141,26 +141,26 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator1(&u1_mesh); - Mesh* ref_u1_mesh = refMeshCreator1.create_ref_mesh(); + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator1(u1_mesh); + MeshSharedPtr ref_u1_mesh = refMeshCreator1.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator1(&u1_space, ref_u1_mesh); - Space* ref_u1_space = refSpaceCreator1.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator1(u1_space, ref_u1_mesh); + SpaceSharedPtr ref_u1_space = refSpaceCreator1.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreator2(&u2_mesh); - Mesh* ref_u2_mesh = refMeshCreator2.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreator2(u2_mesh); + MeshSharedPtr ref_u2_mesh = refMeshCreator2.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator2(&u2_space, ref_u2_mesh); - Space* ref_u2_space = refSpaceCreator2.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); + SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); - Hermes::vector *> ref_spaces(ref_u1_space, ref_u2_space); - Hermes::vector *> ref_spaces_const(ref_u1_space, ref_u2_space); + Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); + Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); - int ndof_ref = Space::get_num_dofs(ref_spaces_const); + int ndof_ref = Space::get_num_dofs(ref_spaces); // Initialize the FE problem. - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); // Initialize Newton solver. NewtonSolver newton(&dp); @@ -173,8 +173,8 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -186,33 +186,33 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref)); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, + Hermes::vector >(u1_sln_ref, u2_sln_ref)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u1_space, &u2_space), - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), - Hermes::vector *>(&u1_sln, &u2_sln)); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), + Hermes::vector >(u1_sln_ref, u2_sln_ref), + Hermes::vector >(u1_sln, u2_sln)); // View the coarse mesh solution and polynomial orders. - s_view_0.show(&u1_sln); - o_view_0.show(&u1_space); - s_view_1.show(&u2_sln); - o_view_1.show(&u2_space); + s_view_0.show(u1_sln); + o_view_0.show(u1_space); + s_view_1.show(u2_sln); + o_view_1.show(u2_space); // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector *>(&u1_sln, &u2_sln), lambda, mu); + VonMisesFilter stress(Hermes::vector >(u1_sln, u2_sln), lambda, mu); ValFilter limited_stress(&stress, 0.0, 2e5); - mises_view.show(&limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, &u1_sln, &u2_sln, 0); + mises_view.show(limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 0); // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Initialize adaptivity. - Adapt* adaptivity = new Adapt(Hermes::vector *>(&u1_space, &u2_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(u1_space, u2_space)); /* // Register custom forms for error calculation. @@ -225,23 +225,23 @@ int main(int argc, char* argv[]) // Calculate error estimate for each solution component and the total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector *>(&u1_sln, &u2_sln), - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), &err_est_rel) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u1_sln, u2_sln), + Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; // Time measurement. cpu_time.tick(); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d, err_est_rel[0]: %g%%", - u1_space.Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); + u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d, err_est_rel[1]: %g%%", - u2_space.Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); + u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", - Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)), - Space::get_num_dofs(ref_spaces_const), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)), + graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); @@ -256,16 +256,10 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); } - if (Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)) >= NDOF_STOP) done = true; + if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; // Clean up. delete adaptivity; - if(done == false) - for(unsigned int i = 0; i < ref_spaces.size(); i++) - { - delete (ref_spaces)[i]->get_mesh(); - delete (ref_spaces)[i]; - } // Increase counter. as++; @@ -276,15 +270,15 @@ int main(int argc, char* argv[]) // Show the reference solution - the final result. s_view_0.set_title("Fine mesh solution (x-displacement)"); - s_view_0.show(&u1_sln_ref); + s_view_0.show(u1_sln_ref); s_view_1.set_title("Fine mesh solution (y-displacement)"); - s_view_1.show(&u2_sln_ref); + s_view_1.show(u2_sln_ref); // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), lambda, mu); + VonMisesFilter stress(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu); ValFilter limited_stress(&stress, 0.0, 2e5); - mises_view.show(&limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, &u1_sln_ref, &u2_sln_ref, 0); + mises_view.show(limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 0); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 9a43296..834c38a 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -90,32 +90,32 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Load the mesh-> - Mesh u1_mesh, u2_mesh; + MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &u1_mesh); + mloader.load("domain.mesh", u1_mesh); // Perform initial uniform mesh refinement. for (int i=0; i < INIT_REF_NUM; i++) u1_mesh->refine_all_elements(); // Create initial mesh for the vertical displacement component. // This also initializes the multimesh hp-FEM. - u2_mesh->copy(&u1_mesh); + u2_mesh->copy(u1_mesh); // Initialize boundary conditions. DefaultEssentialBCConst zero_disp("bdy left", 0.0); EssentialBCs bcs(&zero_disp); // Create x- and y- displacement space using the default H1 shapeset. - H1Space u1_space(&u1_mesh, &bcs, P_INIT_U1); - H1Space u2_space(&u2_mesh, &bcs, P_INIT_U2); - Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space))); + SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT_U1)); + SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT_U2)); + Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); // Initialize the weak formulation. // NOTE; These weak forms are identical to those in example P01-linear/08-system. CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy_top", f0, f1); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector *>(&u1_space, &u2_space)); + DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); // Initialize coarse and reference mesh solutions. Solution u1_sln, u2_sln; @@ -143,26 +143,26 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreator1(&u1_mesh); - Mesh* ref_u1_mesh = refMeshCreator1.create_ref_mesh(); + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator1(u1_mesh); + MeshSharedPtr ref_u1_mesh = refMeshCreator1.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator1(&u1_space, ref_u1_mesh); - Space* ref_u1_space = refSpaceCreator1.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator1(u1_space, ref_u1_mesh); + SpaceSharedPtr ref_u1_space = refSpaceCreator1.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreator2(&u2_mesh); - Mesh* ref_u2_mesh = refMeshCreator2.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreator2(u2_mesh); + MeshSharedPtr ref_u2_mesh = refMeshCreator2.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator2(&u2_space, ref_u2_mesh); - Space* ref_u2_space = refSpaceCreator2.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); + SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); - Hermes::vector *> ref_spaces(ref_u1_space, ref_u2_space); - Hermes::vector *> ref_spaces_const(ref_u1_space, ref_u2_space); + Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); + Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); - int ndof_ref = Space::get_num_dofs(ref_spaces_const); + int ndof_ref = Space::get_num_dofs(ref_spaces); // Initialize the FE problem. - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); // Initialize Newton solver. NewtonSolver newton(&dp); @@ -175,8 +175,8 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -188,32 +188,32 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref)); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, + Hermes::vector >(u1_sln_ref, u2_sln_ref)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&u1_space, &u2_space), - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), - Hermes::vector *>(&u1_sln, &u2_sln)); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), + Hermes::vector >(u1_sln_ref, u2_sln_ref), + Hermes::vector >(u1_sln, u2_sln)); // View the coarse mesh solution and polynomial orders. - s_view_0.show(&u1_sln); - o_view_0.show(&u1_space); - s_view_1.show(&u2_sln); - o_view_1.show(&u2_space); + s_view_0.show(u1_sln); + o_view_0.show(u1_space); + s_view_1.show(u2_sln); + o_view_1.show(u2_space); // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector *>(&u1_sln, &u2_sln), lambda, mu); - mises_view.show(&stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, &u1_sln, &u2_sln, 1e3); + VonMisesFilter stress(Hermes::vector >(u1_sln, u2_sln), lambda, mu); + mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 1e3); // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Initialize adaptivity. - Adapt* adaptivity = new Adapt(Hermes::vector *>(&u1_space, &u2_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(u1_space, u2_space)); /* // Register custom forms for error calculation. @@ -226,23 +226,23 @@ int main(int argc, char* argv[]) // Calculate error estimate for each solution component and the total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector *>(&u1_sln, &u2_sln), - Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), &err_est_rel) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u1_sln, u2_sln), + Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; // Time measurement. cpu_time.tick(); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d, err_est_rel[0]: %g%%", - u1_space.Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); + u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d, err_est_rel[1]: %g%%", - u2_space.Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); + u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", - Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)), - Space::get_num_dofs(ref_spaces_const), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)), + graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); @@ -257,7 +257,7 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); } - if (Space::get_num_dofs(Hermes::vector *>(&u1_space, &u2_space)) >= NDOF_STOP) done = true; + if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; // Clean up. delete adaptivity; @@ -277,14 +277,14 @@ int main(int argc, char* argv[]) // Show the reference solution - the final result. s_view_0.set_title("Fine mesh solution (x-displacement)"); - s_view_0.show(&u1_sln_ref); + s_view_0.show(u1_sln_ref); s_view_1.set_title("Fine mesh solution (y-displacement)"); - s_view_1.show(&u2_sln_ref); + s_view_1.show(u2_sln_ref); // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector *>(&u1_sln_ref, &u2_sln_ref), lambda, mu); - mises_view.show(&stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, &u1_sln_ref, &u2_sln_ref, 1e3); + VonMisesFilter stress(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu); + mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 1e3); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/euler/euler-coupled-adapt/main.cpp b/2d-advanced/euler/euler-coupled-adapt/main.cpp index fe0831b..1595bdf 100644 --- a/2d-advanced/euler/euler-coupled-adapt/main.cpp +++ b/2d-advanced/euler/euler-coupled-adapt/main.cpp @@ -231,9 +231,9 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho_stabilization); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); + MachNumberFilter Mach_number(Hermes::vector >(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), KAPPA); + PressureFilter pressure(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + EntropyFilter entropy(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 400)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 400)); diff --git a/2d-advanced/euler/euler-coupled/main.cpp b/2d-advanced/euler/euler-coupled/main.cpp index 73b9df1..1d2e9c8 100644 --- a/2d-advanced/euler/euler-coupled/main.cpp +++ b/2d-advanced/euler/euler-coupled/main.cpp @@ -179,9 +179,9 @@ int main(int argc, char* argv[]) bool* discreteIndicator = NULL; // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); + MachNumberFilter Mach_number(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + PressureFilter pressure(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + EntropyFilter entropy(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 400)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 400)); diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index c10df4a..9dcac7c 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -215,7 +215,7 @@ DiscontinuityDetector::DiscontinuityDetector(Hermes::vector > solutions) : spaces(spaces), solutions(solutions) { for(int i = 0; i < solutions.size(); i++) - this->solutionsInternal.push_back((Solution*)solutions[i].get()); + this->solutionsInternal.push_back((MeshFunctionSharedPtr )solutions[i].get()); }; DiscontinuityDetector::~DiscontinuityDetector() diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index cbdf9e2..5fd60bb 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -71,7 +71,7 @@ class DiscontinuityDetector /// Members. Hermes::vector > spaces; Hermes::vector > solutions; - Hermes::vector*> solutionsInternal; + Hermes::vector > solutionsInternal; std::set discontinuous_element_ids; std::set > oscillatory_element_idsRho; std::set > oscillatory_element_idsRhoVX; diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index 159b9ac..d7541fa 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -264,8 +264,8 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm for(unsigned int i = 0; i < this->ext.size(); i++) { - Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) + MeshFunctionSharedPtr ext = static_cast >(this->ext[i]->clone()); + if((static_cast >(this->ext[i].get()))->get_type() == HERMES_SLN) ext->set_type(HERMES_SLN); wf->ext.push_back(ext); } @@ -1001,8 +1001,8 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW for(unsigned int i = 0; i < this->ext.size(); i++) { - Solution* ext = static_cast*>(this->ext[i]->clone()); - if((static_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) + MeshFunctionSharedPtr ext = static_cast >(this->ext[i]->clone()); + if((static_cast >(this->ext[i].get()))->get_type() == HERMES_SLN) ext->set_type(HERMES_SLN); wf->ext.push_back(ext); } diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index 7bc3b71..183ef0e 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -208,10 +208,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT)); + space_rho_v_x->adjust_element_order(-1, P_INIT)); + space_rho_v_y->adjust_element_order(-1, P_INIT)); + space_e->adjust_element_order(-1, P_INIT)); } Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -227,23 +227,23 @@ int main(int argc, char* argv[]) Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); else selector.set_error_weights(1.0, 1.0, 1.0); - ndofs_prev = Space::get_num_dofs(ref_spaces_const); + ndofs_prev = Space::get_num_dofs(ref_spaces); // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; - ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); - FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), ref_spaces_const, true); + FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), ref_spaces, true); flux_limiterLoading.limitOscillations = true; @@ -261,11 +261,11 @@ int main(int argc, char* argv[]) // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); @@ -286,11 +286,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solved."); if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, + Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const, true); + FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces, true); flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); @@ -304,8 +304,8 @@ int main(int argc, char* argv[]) std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -337,7 +337,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index f5cd34c..76d762a 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -200,10 +200,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT)); + space_rho_v_x->adjust_element_order(-1, P_INIT)); + space_rho_v_y->adjust_element_order(-1, P_INIT)); + space_e->adjust_element_order(-1, P_INIT)); Space::assign_dofs(spaces); } @@ -215,7 +215,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -243,7 +243,7 @@ int main(int argc, char* argv[]) ndofs_prev = Space::get_num_dofs(ref_spaces); // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); @@ -260,7 +260,7 @@ int main(int argc, char* argv[]) // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); Space::assign_dofs(ref_spaces); DiscreteProblem dp(&wf, ref_spaces); dp.set_linear(); @@ -306,8 +306,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -330,7 +330,7 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index 6e5b95e..bfee262 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -229,7 +229,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -299,8 +299,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); // Calculate element errors and total error estimate. @@ -341,7 +341,7 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse space."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse space->"); done = adaptivity->adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector, &h1_selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 546d7c3..27283af 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -81,7 +81,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. + // Load the mesh-> MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 1c78499..4e24cb1 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -209,10 +209,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT)); + space_rho_v_x->adjust_element_order(-1, P_INIT)); + space_rho_v_y->adjust_element_order(-1, P_INIT)); + space_e->adjust_element_order(-1, P_INIT)); } // Adaptivity loop: @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -239,30 +239,30 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); else selector.set_error_weights(1.0, 1.0, 1.0); - ndofs_prev = Space::get_num_dofs(ref_spaces_const); + ndofs_prev = Space::get_num_dofs(ref_spaces); // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); @@ -276,11 +276,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); if(solver->solve()) if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, + Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces_const); + FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces); flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); @@ -293,8 +293,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -307,17 +307,17 @@ int main(int argc, char* argv[]) double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); // If err_est too large, adapt the mesh-> - if (err_est_rel_total < ERR_STOP && Space::get_num_dofs(ref_spaces_const) > NDOFS_MIN) + if (err_est_rel_total < ERR_STOP && Space::get_num_dofs(ref_spaces) > NDOFS_MIN) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); diff --git a/2d-advanced/euler/joukowski-profile-adapt/main.cpp b/2d-advanced/euler/joukowski-profile-adapt/main.cpp index 64c388f..265788a 100644 --- a/2d-advanced/euler/joukowski-profile-adapt/main.cpp +++ b/2d-advanced/euler/joukowski-profile-adapt/main.cpp @@ -174,9 +174,9 @@ int main(int argc, char* argv[]) inlet_markers, outlet_markers, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); + MachNumberFilter Mach_number(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + PressureFilter pressure(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + EntropyFilter entropy(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); diff --git a/2d-advanced/euler/joukowski-profile/main.cpp b/2d-advanced/euler/joukowski-profile/main.cpp index 371ea66..3e1a6b5 100644 --- a/2d-advanced/euler/joukowski-profile/main.cpp +++ b/2d-advanced/euler/joukowski-profile/main.cpp @@ -113,9 +113,9 @@ int main(int argc, char* argv[]) ConstantSolution prev_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); // Filters for visualization of Mach number, pressure and entropy. - MachNumberFilter Mach_number(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - PressureFilter pressure(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); - EntropyFilter entropy(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); + MachNumberFilter Mach_number(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + PressureFilter pressure(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); + EntropyFilter entropy(Hermes::vector >(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index bdb58d8..c138023 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -218,10 +218,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); + space_rho->adjust_element_order(-1, P_INIT)); + space_rho_v_x->adjust_element_order(-1, P_INIT)); + space_rho_v_y->adjust_element_order(-1, P_INIT)); + space_e->adjust_element_order(-1, P_INIT)); Space::assign_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); } @@ -235,7 +235,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> int order_increase = (CAND_LIST == H2D_HP_ANISO ? 1 : 0); Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -251,41 +251,41 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector > ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); else selector.set_error_weights(1.0, 1.0, 1.0); - ndofs_prev = Space::get_num_dofs(ref_spaces_const); + ndofs_prev = Space::get_num_dofs(ref_spaces); // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; - ogProjection.project_global(ref_spaces_const, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), + ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces_const)); + space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - solver.set_spaces(ref_spaces_const); + solver.set_spaces(ref_spaces); wf.set_current_time_step(time_step); solver.solve(); if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces_const, + Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); else { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces_const, true); + FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces, true); flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); @@ -296,8 +296,8 @@ int main(int argc, char* argv[]) flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -310,7 +310,7 @@ int main(int argc, char* argv[]) double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces_const)[0]->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); REFINEMENT_COUNT++; done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -340,7 +340,7 @@ int main(int argc, char* argv[]) Mach_number->reinit(); //pressure->reinit(); //entropy->reinit(); - //pressure_view.show(&pressure); + //pressure_view.show(pressure); Mach_number_view.show(Mach_number); space_view.show(ref_space_rho); diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index 8b429aa..80bccec 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -135,20 +135,20 @@ int main(int argc, char* argv[]) // Load the mesh-> Mesh basemesh, T_mesh, w_mesh; MeshReaderH2D mloader; - mloader.load("domain.mesh", &basemesh); + mloader.load("domain.mesh", basemesh); // Create temperature and moisture meshes. // This also initializes the multimesh hp-FEM. - T_mesh->copy(&basemesh); - w_mesh->copy(&basemesh); + T_mesh->copy(basemesh); + w_mesh->copy(basemesh); // Initialize boundary conditions. EssentialBCNonConst temp_reactor("bdy_react", REACTOR_START_TIME, T_INITIAL, T_REACTOR_MAX); EssentialBCs bcs_T(&temp_reactor); // Create H1 spaces with default shapesets. - H1Space T_space(&T_mesh, &bcs_T, P_INIT); - H1Space w_space(MULTI ? &w_mesh : &T_mesh, P_INIT); + H1Space T_space(T_mesh, &bcs_T, P_INIT)); + H1Space w_space(MULTI ? &w_mesh : &T_mesh, P_INIT)); // Define constant initial conditions. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); @@ -180,10 +180,10 @@ int main(int argc, char* argv[]) OrderView w_order_view("Moisture mesh", w_mesh_win_geom); // Show initial conditions. - T_sln_view.show(&T_time_prev); - w_sln_view.show(&w_time_prev); - T_order_view.show(&T_space); - w_order_view.show(&w_space); + T_sln_view.show(T_time_prev); + w_sln_view.show(w_time_prev); + T_order_view.show(T_space); + w_order_view.show(w_space); // Time stepping loop: int ts = 1; @@ -196,34 +196,34 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. if (current_time <= REACTOR_START_TIME) { Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector*>(&T_space, &w_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(&T_space, &w_space), current_time); } // Uniform mesh derefinement. if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: T_mesh->copy(&basemesh); - w_mesh->copy(&basemesh); - T_space.set_uniform_order(P_INIT); - w_space.set_uniform_order(P_INIT); + case 1: T_mesh->copy(basemesh); + w_mesh->copy(basemesh); + T_space->set_uniform_order(P_INIT); + w_space->set_uniform_order(P_INIT); break; case 2: T_mesh->unrefine_all_elements(); if(MULTI) w_mesh->unrefine_all_elements(); - T_space.set_uniform_order(P_INIT); - w_space.set_uniform_order(P_INIT); + T_space->set_uniform_order(P_INIT); + w_space->set_uniform_order(P_INIT); break; case 3: T_mesh->unrefine_all_elements(); if(MULTI) w_mesh->unrefine_all_elements(); - T_space.adjust_element_order(-1, -1, P_INIT, P_INIT); - w_space.adjust_element_order(-1, -1, P_INIT, P_INIT); + T_space->adjust_element_order(-1, -1, P_INIT, P_INIT); + w_space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - T_space.assign_dofs(); - w_space.assign_dofs(); + T_space->assign_dofs(); + w_space->assign_dofs(); } // Spatial adaptivity loop. Note: T_time_prev and w_time_prev must not be changed during @@ -233,27 +233,26 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreatorU(&T_mesh); - Mesh* ref_T_mesh = refMeshCreatorU.create_ref_mesh(); + MeshSharedPtr ref_T_mesh = refMeshCreatorU.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorT(&T_space, ref_T_mesh); - Space* ref_T_space = refSpaceCreatorT.create_ref_space(); + SpaceSharedPtr ref_T_space = refSpaceCreatorT.create_ref_space(); Mesh::ReferenceMeshCreator refMeshCreatorW(&w_mesh); - Mesh* ref_w_mesh = refMeshCreatorW.create_ref_mesh(); + MeshSharedPtr ref_w_mesh = refMeshCreatorW.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorW(&w_space, ref_w_mesh); - Space* ref_w_space = refSpaceCreatorW.create_ref_space(); + SpaceSharedPtr ref_w_space = refSpaceCreatorW.create_ref_space(); - Hermes::vector*> ref_spaces(ref_T_space, ref_w_space); - Hermes::vector*> ref_spaces_const(ref_T_space, ref_w_space); + Hermes::vector > ref_spaces(ref_T_space, ref_w_space); // Initialize discrete problem on reference meshes. - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, ref_spaces_const, &bt); + RungeKutta runge_kutta(&wf, ref_spaces, &bt); // Perform one Runge-Kutta time step according to the selected Butcher's table. Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step (t = %g s, tau = %g s, stages: %d).", @@ -262,10 +261,10 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); - runge_kutta.rk_time_step_newton(Hermes::vector *>(&T_time_prev, &w_time_prev), - Hermes::vector *>(&T_time_new, &w_time_new)); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); + runge_kutta.rk_time_step_newton(Hermes::vector >(&T_time_prev, &w_time_prev), + Hermes::vector >(&T_time_new, &w_time_new)); } catch(Exceptions::Exception& e) { @@ -275,13 +274,13 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse meshes. Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solutions on coarse meshes for error estimation."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&T_space, &w_space), - Hermes::vector *>(&T_time_new, &w_time_new), - Hermes::vector *>(&T_coarse, &w_coarse), + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&T_space, &w_space), + Hermes::vector >(&T_time_new, &w_time_new), + Hermes::vector >(&T_coarse, &w_coarse), matrix_solver); // Initialize an instance of the Adapt class and register custom error forms. - Adapt* adaptivity = new Adapt(Hermes::vector *>(&T_space, &w_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(&T_space, &w_space)); CustomErrorForm cef_0_0(d_TT, c_TT); CustomErrorForm cef_0_1(d_Tw, c_TT); CustomErrorForm cef_1_0(d_wT, c_ww); @@ -293,13 +292,13 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector *>(&T_coarse, &w_coarse), - Hermes::vector *>(&T_time_new, &w_time_new)) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&T_coarse, &w_coarse), + Hermes::vector >(&T_time_new, &w_time_new)) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector *>(&T_space, &w_space)), - Space::get_num_dofs(ref_spaces_const), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(&T_space, &w_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the meshes. if (err_est_rel_total < ERR_STOP) @@ -309,7 +308,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(Hermes::vector *>(&T_space, &w_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(&T_space, &w_space)) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -318,13 +317,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; - if(!done) - { - delete ref_T_space; - delete ref_w_space; - delete T_time_new.get_mesh(); - delete w_time_new.get_mesh(); - } } while (done == false); @@ -335,16 +327,16 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Temperature, t = %g days", current_time/3600./24); T_sln_view.set_title(title); - T_sln_view.show(&T_coarse); + T_sln_view.show(T_coarse); sprintf(title, "Moisture (scaled), t = %g days", current_time/3600./24); w_sln_view.set_title(title); - w_sln_view.show(&w_coarse); - T_order_view.show(&T_space); - w_order_view.show(&w_space); + w_sln_view.show(w_coarse); + T_order_view.show(T_space); + w_order_view.show(w_space); // Save fine mesh solutions for the next time step. - T_time_prev.copy(&T_time_new); - w_time_prev.copy(&w_time_new); + T_time_prev->copy(T_time_new); + w_time_prev->copy(w_time_new); ts++; } diff --git a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp index 3142b54..821753d 100644 --- a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp +++ b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp @@ -157,10 +157,10 @@ int main(int argc, char* argv[]) } // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load("wall.mesh", &basemesh); - mesh->copy(&basemesh); + mloader.load("wall.mesh", basemesh); + mesh->copy(basemesh); // Perform initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); @@ -171,8 +171,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs; // Initialize an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = Space::get_num_dofs(&space); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = Space::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) RHO, HEATCAP, TEMP_EXT_AIR, TEMP_INIT, ¤t_time); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -197,8 +197,8 @@ int main(int argc, char* argv[]) time_error_view.fix_scale_width(40); ScalarView space_error_view("Spatial error", new WinGeom(0, 1220, 1500, 360)); space_error_view.fix_scale_width(40); - sln_view.show(&sln_prev_time); - ordview.show(&space); + sln_view.show(sln_prev_time); + ordview.show(space); // Graph for time step history. SimpleGraph time_step_graph; @@ -217,53 +217,53 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; - case 2: space.unrefine_all_mesh_elements(); - space.set_uniform_order(P_INIT); + case 2: space->unrefine_all_mesh_elements(); + space->set_uniform_order(P_INIT); break; - case 3: space.unrefine_all_mesh_elements(); - //space.adjust_element_order(-1, P_INIT); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + case 3: space->unrefine_all_mesh_elements(); + //space->adjust_element_order(-1, P_INIT)); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - space.assign_dofs(); - ndof = Space::get_num_dofs(&space); + space->assign_dofs(); + ndof = Space::get_num_dofs(space); } // Spatial adaptivity loop. Note: sln_prev_time must not be // changed during spatial adaptivity. - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); Solution time_error_fn(mesh); bool done = false; int as = 1; double err_est; do { - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); // Initialize Runge-Kutta time stepping on the reference mesh-> RungeKutta runge_kutta(&wf, ref_space, &bt); try { - ogProjection.project_global(ref_space, &sln_prev_time, - &sln_prev_time); + ogProjection.project_global(ref_space, sln_prev_time, + sln_prev_time); if(ts > 1) - delete sln_prev_time.get_mesh(); + delete sln_prev_time->get_mesh(); } catch(Exceptions::Exception& e) { std::cout << e.what() << std::endl; Hermes::Mixins::Loggable::Static::error("Projection failed."); delete ref_space->get_mesh(); - delete ref_space; + return -1; } @@ -277,16 +277,16 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL_FINE); - runge_kutta.rk_time_step_newton(&sln_prev_time, &ref_sln, bt.is_embedded() ? &time_error_fn : NULL); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL_FINE); + runge_kutta.rk_time_step_newton(sln_prev_time, ref_sln, bt.is_embedded() ? &time_error_fn : NULL); } catch(Exceptions::Exception& e) { std::cout << e.what() << std::endl; Hermes::Mixins::Loggable::Static::error("Runge-Kutta time step failed"); delete ref_space->get_mesh(); - delete ref_space; + return -1; } @@ -303,10 +303,10 @@ int main(int argc, char* argv[]) sprintf(title, "Temporal error est, spatial adaptivity step %d", as); time_error_view.set_title(title); //time_error_view.show_mesh(false); - time_error_view.show(&time_error_fn); + time_error_view.show(time_error_fn); rel_err_time = Global::calc_norm(&time_error_fn, HERMES_H1_NORM) - / Global::calc_norm(&ref_sln, HERMES_H1_NORM) * 100; + / Global::calc_norm(ref_sln, HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } @@ -342,26 +342,26 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); // Project the fine mesh solution onto the coarse mesh-> - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - ogProjection.project_global(&space, &ref_sln, &sln); + ogProjection.project_global(space, ref_sln, sln); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); - DiffFilter space_error_fn(Hermes::vector*>(&ref_sln, &sln)); + DiffFilter space_error_fn(Hermes::vector >(ref_sln, sln)); space_error_view.set_title(title); //space_error_view.show_mesh(false); - AbsFilter abs_sef(&space_error_fn); - space_error_view.show(&abs_sef); + AbsFilter abs_sef(space_error_fn); + space_error_view.show(abs_sef); // Calculate element errors and spatial error estimate. Hermes::Mixins::Loggable::Static::info("Calculating spatial error estimate."); - Adapt* adaptivity = new Adapt(&space); - double err_rel_space = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt* adaptivity = new Adapt(space); + double err_rel_space = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", - Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_rel_space); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; @@ -370,7 +370,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(&space) >= NDOF_STOP) + if (Space::get_num_dofs(space) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -379,7 +379,7 @@ int main(int argc, char* argv[]) // Clean up. if(!done) - delete ref_space; + delete adaptivity; } while (done == false); @@ -389,13 +389,13 @@ int main(int argc, char* argv[]) sprintf(title, "Solution, time %g s", current_time); sln_view.set_title(title); //sln_view.show_mesh(false); - sln_view.show(&ref_sln); + sln_view.show(ref_sln); sprintf(title, "Mesh, time %g s", current_time); ordview.set_title(title); - ordview.show(&space); + ordview.show(space); - // Copy last reference solution into sln_prev_time. - sln_prev_time.copy(&ref_sln); + // Copy last reference solution into sln_prev_time + sln_prev_timecopy(ref_sln); // Increase current time and counter of time steps. current_time += time_step; diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index e87c012..c6c5206 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -80,28 +80,28 @@ int main(int argc, char* argv[]) EssentialBCs bcs_im(Hermes::vector *>(&bc1, &bc3)); // Create an H1 space with default shapeset. - H1Space e_r_space(mesh, &bcs, P_INIT); - H1Space e_i_space(mesh, &bcs_im, P_INIT); - int ndof = Space::get_num_dofs(&e_r_space); + SpaceSharedPtr e_r_space(new H1Space (mesh, &bcs, P_INIT)); + SpaceSharedPtr e_i_space(new H1Space(mesh, &bcs_im, P_INIT)); + int ndof = Space::get_num_dofs(e_r_space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. WeakFormHelmholtz wf(eps, mu, omega, sigma, beta, E0, h); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector*>(&e_r_space, &e_i_space)); + DiscreteProblem dp(&wf, Hermes::vector >(e_r_space, e_i_space)); // Initialize the solutions. - Solution e_r_sln, e_i_sln; + MeshFunctionSharedPtr e_r_sln(new Solution), e_i_sln(new Solution); // Initial coefficient vector for the Newton's method. - ndof = Space::get_num_dofs(Hermes::vector*>(&e_r_space, &e_i_space)); + ndof = Space::get_num_dofs(Hermes::vector >(e_r_space, e_i_space)); Hermes::Hermes2D::NewtonSolver newton(&dp); try { - newton.set_newton_tol(NEWTON_TOL); - newton.set_newton_max_iter(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -111,16 +111,16 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into Solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector*>(&e_r_space, &e_i_space), - Hermes::vector*>(&e_r_sln, &e_i_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector >(e_r_space, e_i_space), + Hermes::vector >(e_r_sln, e_i_sln)); // Visualize the solution. ScalarView viewEr("Er [V/m]", new WinGeom(0, 0, 800, 400)); - viewEr.show(&e_r_sln); + viewEr.show(e_r_sln); // viewEr.save_screenshot("real_part.bmp"); ScalarView viewEi("Ei [V/m]", new WinGeom(0, 450, 800, 400)); - viewEi.show(&e_i_sln); + viewEi.show(e_i_sln); // viewEi.save_screenshot("imaginary_part.bmp"); // Wait for the view to be closed. diff --git a/2d-advanced/maxwell/magnetostatics/definitions.cpp b/2d-advanced/maxwell/magnetostatics/definitions.cpp index 658f2c1..c34d852 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.cpp +++ b/2d-advanced/maxwell/magnetostatics/definitions.cpp @@ -34,7 +34,7 @@ void FilterVectorPotential::filter_fn(int n, Hermes::vector values, dou MeshFunction* FilterVectorPotential::clone() const { - Hermes::vector*> fns; + Hermes::vector > fns; Hermes::vector items; for(int i = 0; i < this->num; i++) { @@ -44,12 +44,12 @@ MeshFunction* FilterVectorPotential::clone() const return new FilterVectorPotential(fns, items); } -FilterVectorPotential::FilterVectorPotential(Hermes::vector*> solutions, Hermes::vector items) +FilterVectorPotential::FilterVectorPotential(Hermes::vector > solutions, Hermes::vector items) : MagFilter(solutions, items) { } -FilterFluxDensity::FilterFluxDensity(Hermes::vector*> solutions) +FilterFluxDensity::FilterFluxDensity(Hermes::vector > solutions) : Filter(solutions) { } @@ -61,7 +61,7 @@ Func* FilterFluxDensity::get_pt_value(double x, double y, Element* e) MeshFunction* FilterFluxDensity::clone() const { - Hermes::vector*> fns; + Hermes::vector > fns; for(int i = 0; i < this->num; i++) fns.push_back(this->sln[i]->clone()); return new FilterFluxDensity(fns); diff --git a/2d-advanced/maxwell/magnetostatics/definitions.h b/2d-advanced/maxwell/magnetostatics/definitions.h index 6dcb19c..0aa4f42 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.h +++ b/2d-advanced/maxwell/magnetostatics/definitions.h @@ -23,7 +23,7 @@ class CustomWeakFormMagnetostatics : public WeakForm class FilterVectorPotential : public Hermes::Hermes2D::MagFilter { public: - FilterVectorPotential(Hermes::vector*> solutions, Hermes::vector items); + FilterVectorPotential(Hermes::vector > solutions, Hermes::vector items); virtual MeshFunction* clone() const; protected: @@ -33,7 +33,7 @@ class FilterVectorPotential : public Hermes::Hermes2D::MagFilter class FilterFluxDensity : public Hermes::Hermes2D::Filter { public: - FilterFluxDensity(Hermes::vector*> solutions); + FilterFluxDensity(Hermes::vector > solutions); virtual Func* get_pt_value(double x, double y, Element* e = NULL); virtual MeshFunction* clone() const; diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 6623980..56249ec 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -82,8 +82,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Initialize the weak formulation @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) MAT_COPPER, MU_VACUUM, CURRENT_DENSITY, order_inc); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Initialize the solution. ConstantSolution sln(mesh, INIT_COND); @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) // coefficient vector for the Newton's method. Hermes::Mixins::Loggable::Static::info("Projecting to obtain initial vector for the Newton's method."); double* coeff_vec = new double[ndof] ; - OGProjection ogProjection; ogProjection.project_global(&space, &sln, coeff_vec); + OGProjection ogProjection; ogProjection.project_global(space, sln, coeff_vec); // Perform Newton's iteration. Hermes::Hermes2D::NewtonSolver newton(&dp); @@ -111,8 +111,8 @@ int main(int argc, char* argv[]) newton.set_verbose_output(verbose); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) @@ -121,32 +121,32 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solution(newton.get_sln_vector(), &space, &sln); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solution(newton.get_sln_vector(), space, sln); // Cleanup. delete [] coeff_vec; // Visualise the solution and mesh-> ScalarView s_view1("Vector potential", new WinGeom(0, 0, 350, 450)); - FilterVectorPotential vector_potential(Hermes::vector *>(&sln, &sln), + FilterVectorPotential vector_potential(Hermes::vector >(sln, sln), Hermes::vector(H2D_FN_VAL, H2D_FN_VAL)); s_view1.show_mesh(false); - s_view1.show(&vector_potential); + s_view1.show(vector_potential); ScalarView s_view2("Flux density", new WinGeom(360, 0, 350, 450)); - FilterFluxDensity flux_density(Hermes::vector *>(&sln, &sln)); + FilterFluxDensity flux_density(Hermes::vector >(sln, sln)); s_view2.show_mesh(false); - s_view2.show(&flux_density); + s_view2.show(flux_density); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&flux_density, "sln.vtk", "Flux density", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(&flux_density, "sln->vtk", "Flux density", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); OrderView o_view("Mesh", new WinGeom(720, 0, 350, 450)); - o_view.show(&space); + o_view.show(space); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/maxwell/maxwell-debye-rk/definitions.h b/2d-advanced/maxwell/maxwell-debye-rk/definitions.h index 427ae6d..b6dbc94 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/definitions.h +++ b/2d-advanced/maxwell/maxwell-debye-rk/definitions.h @@ -16,7 +16,7 @@ double alpha(double omega, double k); class CustomInitialConditionE : public ExactSolutionVector { public: - CustomInitialConditionE(const Mesh* mesh, double time, double omega, double k_x, double k_y) + CustomInitialConditionE(MeshSharedPtr mesh,double time, double omega, double k_x, double k_y) : ExactSolutionVector(mesh), time(time), omega(omega), k_x(k_x), k_y(k_y) {}; virtual Scalar2 value (double x, double y) const; @@ -34,7 +34,7 @@ class CustomInitialConditionE : public ExactSolutionVector class CustomInitialConditionH : public ExactSolutionScalar { public: - CustomInitialConditionH(const Mesh* mesh, double time, double omega, double k_x, double k_y) + CustomInitialConditionH(MeshSharedPtr mesh,double time, double omega, double k_x, double k_y) : ExactSolutionScalar(mesh), time(time), omega(omega), k_x(k_x), k_y(k_y) {}; virtual double value (double x, double y) const; @@ -52,7 +52,7 @@ class CustomInitialConditionH : public ExactSolutionScalar class CustomInitialConditionP : public ExactSolutionVector { public: - CustomInitialConditionP(const Mesh* mesh, double time, double omega, double k_x, double k_y) + CustomInitialConditionP(MeshSharedPtr mesh,double time, double omega, double k_x, double k_y) : ExactSolutionVector(mesh), time(time), omega(omega), k_x(k_x), k_y(k_y) {}; virtual Scalar2 value (double x, double y) const; diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 9a6c86d..4b6cc1c 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -107,9 +107,9 @@ const int ADAPTIVITY_STEPS = 5; const int NDOF_STOP = 6200; // Problem parameters. -// Permeability of free space. +// Permeability of free space-> const double MU_0 = 1.0; -// Permittivity of free space. +// Permittivity of free space-> const double EPS_0 = 1.0; // Permittivity at infinite frequency. const double EPS_INF = 1.0; @@ -150,11 +150,11 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh E_mesh, H_mesh, P_mesh; + MeshSharedPtr E_mesh(new Mesh), H_mesh(new Mesh), P_mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &E_mesh); - mloader.load("domain.mesh", &H_mesh); - mloader.load("domain.mesh", &P_mesh); + mloader.load("domain.mesh", E_mesh); + mloader.load("domain.mesh", H_mesh); + mloader.load("domain.mesh", P_mesh); // Perform initial mesh refinemets. for (int i = 0; i < INIT_REF_NUM; i++) @@ -166,13 +166,13 @@ int main(int argc, char* argv[]) // Initialize solutions. double current_time = 0; - CustomInitialConditionE E_time_prev(&E_mesh, current_time, OMEGA, K_x, K_y); - CustomInitialConditionH H_time_prev(&H_mesh, current_time, OMEGA, K_x, K_y); - CustomInitialConditionP P_time_prev(&P_mesh, current_time, OMEGA, K_x, K_y); - Hermes::vector*> slns_time_prev(&E_time_prev, &H_time_prev, &P_time_prev); - Solution E_time_new(&E_mesh), H_time_new(&H_mesh), P_time_new(&P_mesh); - Solution E_time_new_coarse, H_time_new_coarse, P_time_new_coarse; - Hermes::vector*> slns_time_new(&E_time_new, &H_time_new, &P_time_new); + MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionE(&E_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr H_time_prev(new CustomInitialConditionH(&H_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr P_time_prev(new CustomInitialConditionP(&P_mesh, current_time, OMEGA, K_x, K_y)); + Hermes::vector > slns_time_prev(&E_time_prev, &H_time_prev, &P_time_prev); + MeshFunctionSharedPtr E_time_new(new Solution(E_mesh)), H_time_new(new Solution(H_mesh)), P_time_new(new Solution(P_mesh)); + MeshFunctionSharedPtr E_time_new_coarse(new Solution(E_mesh)), H_time_new_coarse(new Solution(H_mesh)), P_time_new_coarse(new Solution(P_mesh)); + Hermes::vector > slns_time_new(&E_time_new, &H_time_new, &P_time_new); // Initialize the weak formulation. const CustomWeakFormMD wf(OMEGA, K_x, K_y, MU_0, EPS_0, EPS_INF, EPS_Q, TAU); @@ -181,13 +181,12 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_essential("Bdy", 0.0); EssentialBCs bcs(&bc_essential); - HcurlSpace E_space(&E_mesh, &bcs, P_INIT); - H1Space H_space(&H_mesh, NULL, P_INIT); - //L2Space H_space(mesh, P_INIT); - HcurlSpace P_space(&P_mesh, &bcs, P_INIT); + SpaceSharedPtr E_space(new HcurlSpace (E_mesh, &bcs, P_INIT)); + SpaceSharedPtr H_space(new H1Space (H_mesh, NULL, P_INIT)); + //L2Space H_space(mesh, P_INIT)); + SpaceSharedPtr P_space(new HcurlSpace(P_mesh, &bcs, P_INIT)); - Hermes::vector *> spaces = Hermes::vector *>(&E_space, &H_space, &P_space); - Hermes::vector *> spaces_const = Hermes::vector *>(&E_space, &H_space, &P_space); + Hermes::vector > spaces = Hermes::vector >(E_space, H_space, P_space); // Initialize views. ScalarView E1_view("Solution E1", new WinGeom(0, 0, 400, 350)); @@ -205,26 +204,26 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "E1 - Initial Condition"); E1_view.set_title(title); - E1_view.show(&E_time_prev, H2D_FN_VAL_0); + E1_view.show(E_time_prev, H2D_FN_VAL_0); sprintf(title, "E2 - Initial Condition"); E2_view.set_title(title); - E2_view.show(&E_time_prev, H2D_FN_VAL_1); + E2_view.show(E_time_prev, H2D_FN_VAL_1); sprintf(title, "H - Initial Condition"); H_view.set_title(title); - H_view.show(&H_time_prev); + H_view.show(H_time_prev); sprintf(title, "P1 - Initial Condition"); P1_view.set_title(title); - P1_view.show(&P_time_prev, H2D_FN_VAL_0); + P1_view.show(P_time_prev, H2D_FN_VAL_0); sprintf(title, "P2 - Initial Condition"); P2_view.set_title(title); - P2_view.show(&P_time_prev, H2D_FN_VAL_1); + P2_view.show(P_time_prev, H2D_FN_VAL_1); // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, spaces_const, &bt); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); + RungeKutta runge_kutta(&wf, spaces, &bt); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); runge_kutta.set_verbose_output(true); // Initialize refinement selector. @@ -245,13 +244,13 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); REFINEMENT_COUNT = 0; - E_space.unrefine_all_mesh_elements(true); - H_space.unrefine_all_mesh_elements(true); - P_space.unrefine_all_mesh_elements(true); + E_space->unrefine_all_mesh_elements(true); + H_space->unrefine_all_mesh_elements(true); + P_space->unrefine_all_mesh_elements(true); - E_space.adjust_element_order(-1, P_INIT); - H_space.adjust_element_order(-1, P_INIT); - P_space.adjust_element_order(-1, P_INIT); + E_space->adjust_element_order(-1, P_INIT)); + H_space->adjust_element_order(-1, P_INIT)); + P_space->adjust_element_order(-1, P_INIT)); } // Adaptivity loop: @@ -261,29 +260,29 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorE(&E_mesh); Mesh::ReferenceMeshCreator refMeshCreatorH(&H_mesh); Mesh::ReferenceMeshCreator refMeshCreatorP(&P_mesh); - Mesh* ref_mesh_E = refMeshCreatorE.create_ref_mesh(); - Mesh* ref_mesh_H = refMeshCreatorH.create_ref_mesh(); - Mesh* ref_mesh_P = refMeshCreatorP.create_ref_mesh(); + MeshSharedPtr ref_mesh_E = refMeshCreatorE.create_ref_mesh(); + MeshSharedPtr ref_mesh_H = refMeshCreatorH.create_ref_mesh(); + MeshSharedPtr ref_mesh_P = refMeshCreatorP.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorE(&E_space, ref_mesh_E, order_increase); - Space* ref_space_E = refSpaceCreatorE.create_ref_space(); + SpaceSharedPtr ref_space_E = refSpaceCreatorE.create_ref_space(); Space::ReferenceSpaceCreator refSpaceCreatorH(&H_space, ref_mesh_H, order_increase); - Space* ref_space_H = refSpaceCreatorH.create_ref_space(); + SpaceSharedPtr ref_space_H = refSpaceCreatorH.create_ref_space(); Space::ReferenceSpaceCreator refSpaceCreatorP(&P_space, ref_mesh_P, order_increase); - Space* ref_space_P = refSpaceCreatorP.create_ref_space(); + SpaceSharedPtr ref_space_P = refSpaceCreatorP.create_ref_space(); - int ndof = Space::get_num_dofs(Hermes::vector*>(ref_space_E, ref_space_H, ref_space_P)); + int ndof = Space::get_num_dofs(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); try { - runge_kutta.set_spaces(Hermes::vector*>(ref_space_E, ref_space_H, ref_space_P)); + runge_kutta.set_spaces(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new); @@ -298,33 +297,33 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "E1, t = %g", current_time + time_step); E1_view.set_title(title); - E1_view.show(&E_time_new, H2D_FN_VAL_0); + E1_view.show(E_time_new, H2D_FN_VAL_0); sprintf(title, "E2, t = %g", current_time + time_step); E2_view.set_title(title); - E2_view.show(&E_time_new, H2D_FN_VAL_1); + E2_view.show(E_time_new, H2D_FN_VAL_1); sprintf(title, "H, t = %g", current_time + time_step); H_view.set_title(title); - H_view.show(&H_time_new); + H_view.show(H_time_new); sprintf(title, "P1, t = %g", current_time + time_step); P1_view.set_title(title); - P1_view.show(&P_time_new, H2D_FN_VAL_0); + P1_view.show(P_time_new, H2D_FN_VAL_0); sprintf(title, "P2, t = %g", current_time + time_step); P2_view.set_title(title); - P2_view.show(&P_time_new, H2D_FN_VAL_1); + P2_view.show(P_time_new, H2D_FN_VAL_1); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&E_space, &H_space, - &P_space), Hermes::vector*>(&E_time_new, &H_time_new, &P_time_new), Hermes::vector*>(&E_time_new_coarse, &H_time_new_coarse, &P_time_new_coarse)); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(E_space, H_space, + P_space), Hermes::vector >(E_time_new, H_time_new, P_time_new), Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&E_space, &H_space, &P_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(E_space, H_space, P_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&E_time_new_coarse, &H_time_new_coarse, &P_time_new_coarse), - Hermes::vector*>(&E_time_new, &H_time_new, &P_time_new)) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse), + Hermes::vector >(E_time_new, H_time_new, P_time_new)) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("Error estimate: %g%%", err_est_rel_total); @@ -345,34 +344,18 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector), THRESHOLD, STRATEGY, MESH_REGULARITY); - delete ref_mesh_E; - delete ref_mesh_H; - delete ref_mesh_P; - if(!done) as++; } - - delete ref_space_E; - delete ref_space_H; - delete ref_space_P; delete adaptivity; - } while(!done); + } + while(!done); //View::wait(); - - // Update solutions. - if(ts > 1) - { - delete E_time_prev.get_mesh(); - delete H_time_prev.get_mesh(); - delete P_time_prev.get_mesh(); - } - - E_time_prev.copy(&E_time_new); - H_time_prev.copy(&H_time_new); - P_time_prev.copy(&P_time_new); + E_time_prev->copy(E_time_new); + H_time_prev->copy(H_time_new); + P_time_prev->copy(P_time_new); // Update time. current_time += time_step; diff --git a/2d-advanced/maxwell/microwave-oven/definitions.cpp b/2d-advanced/maxwell/microwave-oven/definitions.cpp index 7dc3d45..a2be726 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.cpp +++ b/2d-advanced/maxwell/microwave-oven/definitions.cpp @@ -183,7 +183,7 @@ Ord CustomVectorFormSurf::ord(int n, double *wt, Func *u_ext[], Func * CustomWeakForm::CustomWeakForm(double e_0, double mu_0, double mu_r, double kappa, double omega, - double J, bool align_mesh, Mesh* mesh, std::string current_bdy) : WeakForm >(1), marker(mesh->get_element_markers_conversion().get_internal_marker("e1").marker) + double J, bool align_mesh, MeshSharedPtr mesh, std::string current_bdy) : WeakForm >(1), marker(mesh->get_element_markers_conversion().get_internal_marker("e1").marker) { // Jacobian forms - volumetric. add_matrix_form(new CustomMatrixForm(0, 0, e_0, mu_0, mu_r, kappa, omega, J, align_mesh)); diff --git a/2d-advanced/maxwell/microwave-oven/definitions.h b/2d-advanced/maxwell/microwave-oven/definitions.h index 87c65d0..6d6e3c7 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.h +++ b/2d-advanced/maxwell/microwave-oven/definitions.h @@ -112,7 +112,7 @@ class CustomWeakForm : public WeakForm > { public: CustomWeakForm(double e_0, double mu_0, double mu_r, double kappa, double omega, - double J, bool align_mesh, Mesh* mesh, std::string current_bdy); + double J, bool align_mesh, MeshSharedPtr mesh, std::string current_bdy); int get_marker(); private: diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 70ba5e1..a6a7299 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -113,15 +113,15 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an Hcurl space with default shapeset. - HcurlSpace > space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + HcurlSpace > space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakForm wf(e_0, mu_0, mu_r, kappa, omega, J, ALIGN_MESH, mesh, BDY_CURRENT); // Initialize coarse and reference mesh solution. - Solution > sln, ref_sln; + MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinements selector. HcurlProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -143,12 +143,12 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space >* ref_space = refSpaceCreator.create_ref_space(); + Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = Space >::get_num_dofs(ref_space); // Initialize reference problem. @@ -162,8 +162,8 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::NewtonSolver > newton(&dp); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -171,45 +171,45 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln. - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + // Translate the resulting coefficient vector into the Solution > sln-> + Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // View the coarse mesh solution and polynomial orders. - RealFilter real(&sln); + RealFilter real(sln); MagFilter magn(&real); ValFilter limited_magn(&magn, 0.0, 4e3); char title[100]; sprintf(title, "Electric field, adaptivity step %d", as); eview.set_title(title); //eview.set_min_max_range(0.0, 4e3); - eview.show(&limited_magn); + eview.show(limited_magn); sprintf(title, "Polynomial orders, adaptivity step %d", as); oview.set_title(title); - oview.show(&space); + oview.show(space); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt >* adaptivity = new Adapt >(&space); + Adapt >* adaptivity = new Adapt >(space); // Set custom error form and calculate error estimate. CustomErrorForm cef(kappa); adaptivity->set_error_form(0, 0, &cef); - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(&space), + Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(&space), err_est_rel); + graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); @@ -221,13 +221,13 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); } - if (space.get_num_dofs() >= NDOF_STOP) done = true; + if (space->get_num_dofs() >= NDOF_STOP) done = true; delete adaptivity; if(!done) { delete ref_space->get_mesh(); - delete ref_space; + } // Increase counter. @@ -237,17 +237,17 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - RealFilter ref_real(&sln); + RealFilter ref_real(sln); MagFilter ref_magn(&ref_real); ValFilter ref_limited_magn(&ref_magn, 0.0, 4e3); eview.set_title("Fine mesh solution - magnitude"); - eview.show(&ref_limited_magn); + eview.show(ref_limited_magn); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_limited_magn, "sln.vtk", "Magnitude of E", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(&ref_limited_magn, "sln->vtk", "Magnitude of E", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/maxwell/resonator-time-domain-I/definitions.h b/2d-advanced/maxwell/resonator-time-domain-I/definitions.h index 3d224f6..e7552b2 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/definitions.h +++ b/2d-advanced/maxwell/resonator-time-domain-I/definitions.h @@ -12,7 +12,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomInitialConditionWave : public ExactSolutionVector { public: - CustomInitialConditionWave(const Mesh* mesh) : ExactSolutionVector(mesh) {}; + CustomInitialConditionWave(MeshSharedPtr mesh) : ExactSolutionVector(mesh) {}; virtual Scalar2 value (double x, double y) const; diff --git a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp index 0689c93..5c837d8 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp @@ -70,7 +70,7 @@ int main(int argc, char* argv[]) // Initialize solutions. CustomInitialConditionWave E_sln(mesh); ZeroSolution B_sln(mesh); - Hermes::vector*> slns(&E_sln, &B_sln); + Hermes::vector > slns(&E_sln, &B_sln); // Initialize the weak formulation. CustomWeakFormWave wf(C_SQUARED); @@ -81,10 +81,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs_B; // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs_E, P_INIT); - H1Space B_space(mesh, &bcs_B, P_INIT); - Hermes::vector *> spaces(&E_space, &B_space); - Hermes::vector *> spaces_mutable(&E_space, &B_space); + HcurlSpace E_space(mesh, &bcs_E, P_INIT)); + H1Space B_space(mesh, &bcs_B, P_INIT)); + Hermes::vector > spaces(&E_space, &B_space); + Hermes::vector > spaces_mutable(&E_space, &B_space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(spaces)); // Initialize views. @@ -124,13 +124,13 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "E1, t = %g", current_time); E1_view.set_title(title); - E1_view.show(&E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + E1_view.show(E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); sprintf(title, "E2, t = %g", current_time); E2_view.set_title(title); - E2_view.show(&E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); + E2_view.show(E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); sprintf(title, "B, t = %g", current_time); B_view.set_title(title); - B_view.show(&B_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + B_view.show(B_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); // Update time. current_time += time_step; diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp index c689252..1f4394a 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp @@ -1,6 +1,6 @@ #include "definitions.h" -CustomWeakFormWaveIE::CustomWeakFormWaveIE(double tau, double c_squared, Solution* E_prev_sln, Solution* F_prev_sln) : WeakForm(2) +CustomWeakFormWaveIE::CustomWeakFormWaveIE(double tau, double c_squared, MeshFunctionSharedPtr E_prev_sln, MeshFunctionSharedPtr F_prev_sln) : WeakForm(2) { // Jacobian. add_matrix_form(new MatrixFormVolWave_0_0(tau)); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.h b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.h index 6aea5ec..75c2f55 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.h +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.h @@ -13,7 +13,7 @@ class CustomWeakFormWaveIE : public WeakForm { public: - CustomWeakFormWaveIE(double tau, double c_squared, Solution* E_prev_sln, Solution* F_prev_sln); + CustomWeakFormWaveIE(double tau, double c_squared, MeshFunctionSharedPtr E_prev_sln, MeshFunctionSharedPtr F_prev_sln); private: class MatrixFormVolWave_0_0 : public MatrixFormVol @@ -112,7 +112,7 @@ class CustomWeakFormWaveIE : public WeakForm class CustomInitialConditionWave : public ExactSolutionVector { public: - CustomInitialConditionWave(const Mesh* mesh) : ExactSolutionVector(mesh) {}; + CustomInitialConditionWave(MeshSharedPtr mesh) : ExactSolutionVector(mesh) {}; virtual Scalar2 value (double x, double y) const; diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index a0f1cc7..b9e413f 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) // Initialize solutions. CustomInitialConditionWave E_sln(mesh); ZeroSolutionVector F_sln(mesh); - Hermes::vector*> slns(&E_sln, &F_sln); + Hermes::vector > slns(&E_sln, &F_sln); // Initialize the weak formulation. CustomWeakFormWaveIE wf(time_step, C_SQUARED, &E_sln, &F_sln); @@ -72,9 +72,9 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs, P_INIT); - HcurlSpace F_space(mesh, &bcs, P_INIT); - Hermes::vector *> spaces = Hermes::vector *>(&E_space, &F_space); + HcurlSpace E_space(mesh, &bcs, P_INIT)); + HcurlSpace F_space(mesh, &bcs, P_INIT)); + Hermes::vector > spaces = Hermes::vector >(&E_space, &F_space); int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); @@ -112,8 +112,8 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve_keep_jacobian(coeff_vec); } catch(Hermes::Exceptions::Exception e) @@ -129,17 +129,17 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "E1, t = %g", current_time + time_step); E1_view.set_title(title); - E1_view.show(&E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + E1_view.show(E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); sprintf(title, "E2, t = %g", current_time + time_step); E2_view.set_title(title); - E2_view.show(&E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); + E2_view.show(E_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); sprintf(title, "F1, t = %g", current_time + time_step); F1_view.set_title(title); - F1_view.show(&F_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + F1_view.show(F_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_0); sprintf(title, "F2, t = %g", current_time + time_step); F2_view.set_title(title); - F2_view.show(&F_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); + F2_view.show(F_sln, HERMES_EPS_NORMAL, H2D_FN_VAL_1); //View::wait(); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.h b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.h index 943ddc8..e66de5f 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.h +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.h @@ -12,7 +12,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomInitialConditionWave : public ExactSolutionVector { public: - CustomInitialConditionWave(const Mesh* mesh) : ExactSolutionVector(mesh) {}; + CustomInitialConditionWave(MeshSharedPtr mesh) : ExactSolutionVector(mesh) {}; virtual Scalar2 value (double x, double y) const; diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp index c009db7..286f850 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp @@ -86,9 +86,9 @@ int main(int argc, char* argv[]) // Initialize solutions. CustomInitialConditionWave E_time_prev(mesh); ZeroSolutionVector F_time_prev(mesh); - Hermes::vector*> slns_time_prev(&E_time_prev, &F_time_prev); + Hermes::vector > slns_time_prev(&E_time_prev, &F_time_prev); Solution E_time_new, F_time_new; - Hermes::vector*> slns_time_new(&E_time_new, &F_time_new); + Hermes::vector > slns_time_new(&E_time_new, &F_time_new); // Initialize the weak formulation. CustomWeakFormWaveRK wf(C_SQUARED); @@ -98,9 +98,9 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs, P_INIT); - HcurlSpace F_space(mesh, &bcs, P_INIT); - Hermes::vector *> spaces(&E_space, &F_space); + HcurlSpace E_space(mesh, &bcs, P_INIT)); + HcurlSpace F_space(mesh, &bcs, P_INIT)); + Hermes::vector > spaces(&E_space, &F_space); int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); @@ -128,8 +128,8 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new); } catch(Exceptions::Exception& e) @@ -142,23 +142,23 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "E1, t = %g", current_time + time_step); E1_view.set_title(title); - E1_view.show(&E_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + E1_view.show(E_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_0); sprintf(title, "E2, t = %g", current_time + time_step); E2_view.set_title(title); - E2_view.show(&E_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_1); + E2_view.show(E_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_1); sprintf(title, "F1, t = %g", current_time + time_step); F1_view.set_title(title); - F1_view.show(&F_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_0); + F1_view.show(F_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_0); sprintf(title, "F2, t = %g", current_time + time_step); F2_view.set_title(title); - F2_view.show(&F_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_1); + F2_view.show(F_time_new, HERMES_EPS_NORMAL, H2D_FN_VAL_1); //View::wait(); // Update solutions. - E_time_prev.copy(&E_time_new); - F_time_prev.copy(&F_time_new); + E_time_prev->copy(E_time_new); + F_time_prev->copy(F_time_new); // Update time. current_time += time_step; diff --git a/2d-advanced/miscellaneous/local-projection-test/main.cpp b/2d-advanced/miscellaneous/local-projection-test/main.cpp index f4bee7f..5a6282e 100644 --- a/2d-advanced/miscellaneous/local-projection-test/main.cpp +++ b/2d-advanced/miscellaneous/local-projection-test/main.cpp @@ -81,12 +81,12 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Initialize Newton solver. NewtonSolver newton(&dp); @@ -103,13 +103,13 @@ int main(int argc, char* argv[]) } // Translate the resulting coefficient vector into a Solution. - Solution sln; - Solution::vector_to_solution(newton.get_sln_vector(), &space, &sln); + MeshFunctionSharedPtr sln(new Solution()); + Solution::vector_to_solution(newton.get_sln_vector(), space, sln); Solution sln_proj; - LocalProjection::project_local(&space, &sln, &sln_proj, HERMES_H1_NORM); + LocalProjection::project_local(space, sln, sln_proj, HERMES_H1_NORM); ScalarView view1("Projection", new WinGeom(0, 0, 440, 350)); - view1.show(&sln_proj); + view1.show(sln_proj); View::wait(); // VTK output. @@ -118,12 +118,12 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + lin.save_solution_vtk(sln, "sln->vtk", "Temperature", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Output mesh and element orders in VTK format. Orderizer ord; - ord.save_orders_vtk(&space, "ord.vtk"); + ord.save_orders_vtk(space, "ord.vtk"); Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", "ord.vtk"); } @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) // tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default), // HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows // considerably with more accurate representation, so use it wisely. - view.show(&sln); + view.show(sln); View::wait(); } diff --git a/2d-advanced/navier-stokes/bearing/definitions.cpp b/2d-advanced/navier-stokes/bearing/definitions.cpp index 8094ec3..f774dfa 100644 --- a/2d-advanced/navier-stokes/bearing/definitions.cpp +++ b/2d-advanced/navier-stokes/bearing/definitions.cpp @@ -1,7 +1,7 @@ #include "definitions.h" -WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { @@ -11,10 +11,10 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double add_matrix_form(sym_form_1); BilinearFormNonsymVel* nonsym_vel_form_0 = new BilinearFormNonsymVel(0, 0, Stokes); - nonsym_vel_form_0->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_0->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_0); BilinearFormNonsymVel* nonsym_vel_form_1 = new BilinearFormNonsymVel(1, 1, Stokes); - nonsym_vel_form_1->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_1->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_1); // Pressure term in the first velocity equation. @@ -24,14 +24,14 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double VectorFormVolVel* vector_vel_form_x = new VectorFormVolVel(0, Stokes, time_step); - Hermes::vector*> ext_vel_x; + Hermes::vector > ext_vel_x; ext_vel_x.push_back(x_vel_previous_time); vector_vel_form_x->set_ext(ext_vel_x); VectorFormVolVel* vector_vel_form_y = new VectorFormVolVel(1, Stokes, time_step); - Hermes::vector*> ext_vel_y; + Hermes::vector > ext_vel_y; ext_vel_y.push_back(y_vel_previous_time); vector_vel_form_y->set_ext(ext_vel_y); @@ -154,8 +154,8 @@ VectorFormVol* WeakFormNSSimpleLinearization::VectorFormVolVel::clone() return new VectorFormVolVel(*this); } -WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { diff --git a/2d-advanced/navier-stokes/bearing/definitions.h b/2d-advanced/navier-stokes/bearing/definitions.h index 5d80a87..985c566 100644 --- a/2d-advanced/navier-stokes/bearing/definitions.h +++ b/2d-advanced/navier-stokes/bearing/definitions.h @@ -11,8 +11,8 @@ using namespace Hermes::Hermes2D::WeakFormsH1; class WeakFormNSSimpleLinearization : public WeakForm { public: - WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -99,15 +99,15 @@ class WeakFormNSSimpleLinearization : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class WeakFormNSNewton : public WeakForm { public: - WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -276,8 +276,8 @@ class WeakFormNSNewton : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; /* Essential boundary conditions */ diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 835dd59..029cbf1 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -73,7 +73,7 @@ double integrate_over_wall(MeshFunction* meshfn, int marker) double integral = 0.0; Element* e; - const Mesh* mesh = meshfn->get_mesh(); + MeshSharedPtr mesh,= meshfn->get_mesh(); for_all_active_elements(e, mesh) { @@ -123,18 +123,17 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_y(Hermes::vector *>(&bc_inner_vel_y, &bc_outer_vel)); // Spaces for velocity components and pressure. - H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); + SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else - H1Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - Hermes::vector*> spaces(&xvel_space, &yvel_space, &p_space); - Hermes::vector*> spaces_const(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(&xvel_space, &yvel_space, &p_space); // Calculate and report the number of degrees of freedom. - int ndof = Space::get_num_dofs(spaces_const); + int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. @@ -147,15 +146,15 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(mesh); - ZeroSolution yvel_prev_time(mesh); - ZeroSolution p_prev_time(mesh); + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution (mesh)); + MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution (mesh)); + MeshFunctionSharedPtr p_prev_time(new ZeroSolution (mesh)); - Hermes::vector*> slns = Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, - &p_prev_time); + Hermes::vector > slns = Hermes::vector >(xvel_prev_time, yvel_prev_time, + p_prev_time); // Initialize weak formulation. - WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, &xvel_prev_time, &yvel_prev_time); + WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 600, 500)); @@ -173,7 +172,7 @@ int main(int argc, char* argv[]) { // Initialize the FE problem. - DiscreteProblem dp(wf, spaces_const); + DiscreteProblem dp(wf, spaces); Hermes::Hermes2D::NewtonSolver newton(&dp); @@ -182,14 +181,14 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector*>(&xvel_space, &yvel_space, &p_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space, p_space), current_time); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -199,15 +198,15 @@ int main(int argc, char* argv[]) }; // Update previous time level solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), spaces_const, slns); + Solution::vector_to_solutions(newton.get_sln_vector(), spaces, slns); // Show the solution at the end of time step. sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); - vview.show(&xvel_prev_time, &yvel_prev_time); + vview.show(xvel_prev_time, yvel_prev_time); sprintf(title, "Pressure, time %g", current_time); pview.set_title(title); - pview.show(&p_prev_time); + pview.show(p_prev_time); } // Wait for all views to be closed. diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.cpp index 01b812b..1390ab2 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.cpp @@ -1,7 +1,7 @@ #include "definitions.h" -WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { @@ -11,10 +11,10 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double add_matrix_form(sym_form_1); BilinearFormNonsymVel* nonsym_vel_form_0 = new BilinearFormNonsymVel(0, 0, Stokes); - nonsym_vel_form_0->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_0->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_0); BilinearFormNonsymVel* nonsym_vel_form_1 = new BilinearFormNonsymVel(1, 1, Stokes); - nonsym_vel_form_1->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_1->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_1); BilinearFormNonsymXVelPressure* nonsym_velx_pressure_form = new BilinearFormNonsymXVelPressure(0, 2); @@ -25,14 +25,14 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double VectorFormVolVel* vector_vel_form_x = new VectorFormVolVel(0, Stokes, time_step); - Hermes::vector*> ext_vel_x; + Hermes::vector > ext_vel_x; ext_vel_x.push_back(x_vel_previous_time); vector_vel_form_x->set_ext(ext_vel_x); VectorFormVolVel* vector_vel_form_y = new VectorFormVolVel(1, Stokes, time_step); - Hermes::vector*> ext_vel_y; + Hermes::vector > ext_vel_y; ext_vel_y.push_back(y_vel_previous_time); vector_vel_form_y->set_ext(ext_vel_y); @@ -179,8 +179,8 @@ Ord WeakFormNSSimpleLinearization::VectorFormVolVel::ord(int n, double *wt, Func return result; } -WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { @@ -205,10 +205,10 @@ WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_ste add_matrix_form(nonsym_vely_pressure_form); VectorFormNS_0* F_0 = new VectorFormNS_0(0, Stokes, Reynolds, time_step); - F_0->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + F_0->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_vector_form(F_0); VectorFormNS_1* F_1 = new VectorFormNS_1(1, Stokes, Reynolds, time_step); - F_1->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + F_1->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_vector_form(F_1); VectorFormNS_2* F_2 = new VectorFormNS_2(2); add_vector_form(F_2); diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.h b/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.h index afaf70f..77511d3 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.h +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/definitions.h @@ -10,8 +10,8 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class WeakFormNSSimpleLinearization : public WeakForm { public: - WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -95,15 +95,15 @@ class WeakFormNSSimpleLinearization : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class WeakFormNSNewton : public WeakForm { public: - WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -290,8 +290,8 @@ class WeakFormNSNewton : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class EssentialBCNonConst : public EssentialBoundaryCondition diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 72b4c93..c865436 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -143,9 +143,9 @@ void mag(int n, double* a, double* dadx, double* dady, int main(int argc, char* argv[]) { // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &basemesh); + mloader.load("domain.mesh", basemesh); // Initial mesh refinements. //mesh->refine_all_elements(); @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) // 'true' stands for anisotropic refinements. basemesh->refine_towards_boundary(BDY_BOTTOM, 1, true); - mesh->copy(&basemesh); + mesh->copy(basemesh); // Initialize boundary conditions. EssentialBCNonConst bc_left_vel_x(BDY_LEFT, VEL_INLET, H, STARTUP_TIME); @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) #else H1Space p_space(mesh, P_INIT_PRESSURE); #endif - Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -201,7 +201,7 @@ int main(int argc, char* argv[]) // Initialize weak formulation. WeakForm* wf; - wf = new WeakFormNSNewton(STOKES, RE, TAU, &xvel_prev_time, &yvel_prev_time); + wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. DiscreteProblem dp(wf, spaces); @@ -227,19 +227,19 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector*>(&xvel_space, &yvel_space, &p_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(&xvel_space, &yvel_space, &p_space), current_time); // Periodic global derefinements. if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - mesh->copy(&basemesh); - xvel_space.set_uniform_order(P_INIT_VEL); - yvel_space.set_uniform_order(P_INIT_VEL); - p_space.set_uniform_order(P_INIT_PRESSURE); - - xvel_space.assign_dofs(); - yvel_space.assign_dofs(); - p_space.assign_dofs(); + mesh->copy(basemesh); + xvel_space->set_uniform_order(P_INIT_VEL); + yvel_space->set_uniform_order(P_INIT_VEL); + p_space->set_uniform_order(P_INIT_PRESSURE); + + xvel_space->assign_dofs(); + yvel_space->assign_dofs(); + p_space->assign_dofs(); } DiscreteProblem dp(wf, spaces); @@ -253,31 +253,31 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); // Construct globally refined reference mesh - // and setup reference space. + // and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorX(&xvel_space, ref_mesh); - Space* ref_xvel_space = refSpaceCreatorX.create_ref_space(); + SpaceSharedPtr ref_xvel_space = refSpaceCreatorX.create_ref_space(); Space::ReferenceSpaceCreator refSpaceCreatorY(&yvel_space, ref_mesh); - Space* ref_yvel_space = refSpaceCreatorY.create_ref_space(); + SpaceSharedPtr ref_yvel_space = refSpaceCreatorY.create_ref_space(); Space::ReferenceSpaceCreator refSpaceCreatorP(&p_space, ref_mesh); - Space* ref_p_space = refSpaceCreatorP.create_ref_space(); + SpaceSharedPtr ref_p_space = refSpaceCreatorP.create_ref_space(); - Hermes::vector*> ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); - Hermes::vector*> ref_spaces_const(ref_xvel_space, ref_yvel_space, ref_p_space); + Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); + Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); // Calculate initial coefficient vector for Newton on the fine mesh-> - double* coeff_vec = new double[Space::get_num_dofs(ref_spaces_const)]; + double* coeff_vec = new double[Space::get_num_dofs(ref_spaces)]; if (ts == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); - OGProjection ogProj; ogProj.project_global(ref_spaces_const, Hermes::vector*>(&xvel_sln, &yvel_sln, &p_sln), + OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), coeff_vec); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); - OGProjection ogProj; ogProj.project_global(ref_spaces_const, Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time), + OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time), coeff_vec); } @@ -285,9 +285,9 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); try { - newton.set_spaces(ref_spaces_const); - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_spaces(ref_spaces); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); if(as == 2) newton.output_matrix(); newton.solve(coeff_vec); @@ -298,27 +298,27 @@ int main(int argc, char* argv[]) }; // Update previous time level solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector*>(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProj; ogProj.project_global(Hermes::vector*>(&xvel_space, &yvel_space, &p_space), - Hermes::vector*>(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln), - Hermes::vector*>(&xvel_sln, &yvel_sln, &p_sln), + OGProjection ogProj; ogProj.project_global(Hermes::vector >(&xvel_space, &yvel_space, &p_space), + Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln), + Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - //Adapt* adaptivity = new Adapt(ref_spaces_const); - Adapt* adaptivity = new Adapt(Hermes::vector*>(&xvel_space, &yvel_space, &p_space)); + //Adapt* adaptivity = new Adapt(ref_spaces); + Adapt* adaptivity = new Adapt(Hermes::vector >(&xvel_space, &yvel_space, &p_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&xvel_sln, &yvel_sln, &p_sln), - Hermes::vector*>(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)) * 100.; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), + Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)) * 100.; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector*>(&xvel_space, &yvel_space, &p_space)), - Space::get_num_dofs(ref_spaces_const), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; @@ -328,7 +328,7 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(Hermes::vector*>(&xvel_space, &yvel_space, &p_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -346,20 +346,20 @@ int main(int argc, char* argv[]) while (done == false); // Copy new time level reference solution into prev_time. - xvel_prev_time.copy(&xvel_ref_sln); - yvel_prev_time.copy(&yvel_ref_sln); - p_prev_time.copy(&p_ref_sln); + xvel_prev_time->copy(xvel_ref_sln); + yvel_prev_time->copy(yvel_ref_sln); + p_prev_time->copy(p_ref_sln); // Show the solution at the end of time step. sprintf(title, "Velocity, time %g", TIME); vview.set_title(title); - vview.show(&xvel_prev_time, &yvel_prev_time, HERMES_EPS_LOW); + vview.show(xvel_prev_time, yvel_prev_time, HERMES_EPS_LOW); sprintf(title, "Pressure, time %g", TIME); pview.set_title(title); - pview.show(&p_prev_time); + pview.show(p_prev_time); } - ndof = Space::get_num_dofs(Hermes::vector*>(&xvel_space, &yvel_space, &p_space)); + ndof = Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Wait for all views to be closed. diff --git a/2d-advanced/navier-stokes/circular-obstacle/definitions.cpp b/2d-advanced/navier-stokes/circular-obstacle/definitions.cpp index 05ff665..7b890fa 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/definitions.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/definitions.cpp @@ -1,7 +1,7 @@ #include "definitions.h" -WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { @@ -11,10 +11,10 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double add_matrix_form(sym_form_1); BilinearFormNonsymVel* nonsym_vel_form_0 = new BilinearFormNonsymVel(0, 0, Stokes); - nonsym_vel_form_0->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_0->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_0); BilinearFormNonsymVel* nonsym_vel_form_1 = new BilinearFormNonsymVel(1, 1, Stokes); - nonsym_vel_form_1->set_ext(Hermes::vector*>(x_vel_previous_time, y_vel_previous_time)); + nonsym_vel_form_1->set_ext(Hermes::vector >(x_vel_previous_time, y_vel_previous_time)); add_matrix_form(nonsym_vel_form_1); // Pressure term in the first velocity equation. @@ -24,14 +24,14 @@ WeakFormNSSimpleLinearization::WeakFormNSSimpleLinearization(bool Stokes, double VectorFormVolVel* vector_vel_form_x = new VectorFormVolVel(0, Stokes, time_step); - Hermes::vector*> ext_vel_x; + Hermes::vector > ext_vel_x; ext_vel_x.push_back(x_vel_previous_time); vector_vel_form_x->set_ext(ext_vel_x); VectorFormVolVel* vector_vel_form_y = new VectorFormVolVel(1, Stokes, time_step); - Hermes::vector*> ext_vel_y; + Hermes::vector > ext_vel_y; ext_vel_y.push_back(y_vel_previous_time); vector_vel_form_y->set_ext(ext_vel_y); @@ -154,8 +154,8 @@ VectorFormVol* WeakFormNSSimpleLinearization::VectorFormVolVel::clone() return new VectorFormVolVel(*this); } -WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { diff --git a/2d-advanced/navier-stokes/circular-obstacle/definitions.h b/2d-advanced/navier-stokes/circular-obstacle/definitions.h index faab26b..2068a18 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/definitions.h +++ b/2d-advanced/navier-stokes/circular-obstacle/definitions.h @@ -11,8 +11,8 @@ using namespace Hermes::Hermes2D::WeakFormsH1; class WeakFormNSSimpleLinearization : public WeakForm { public: - WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSSimpleLinearization(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -99,15 +99,15 @@ class WeakFormNSSimpleLinearization : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class WeakFormNSNewton : public WeakForm { public: - WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -276,8 +276,8 @@ class WeakFormNSNewton : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; class EssentialBCNonConst : public EssentialBoundaryCondition diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 09b89ea..48a9f71 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -115,10 +115,10 @@ int main(int argc, char* argv[]) H1Space p_space(mesh, P_INIT_PRESSURE); #endif Hermes::vector* > spaces(&xvel_space, &yvel_space, &p_space); - Hermes::vector* > spaces_const(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(&xvel_space, &yvel_space, &p_space); // Calculate and report the number of degrees of freedom. - int ndof = Space::get_num_dofs(spaces_const); + int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. @@ -134,14 +134,14 @@ int main(int argc, char* argv[]) ZeroSolution xvel_prev_time(mesh); ZeroSolution yvel_prev_time(mesh); ZeroSolution p_prev_time(mesh); - Hermes::vector* > slns_prev_time = Hermes::vector* >(&xvel_prev_time, &yvel_prev_time, &p_prev_time); + Hermes::vector > slns_prev_time = Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); // Initialize weak formulation. WeakForm* wf; - wf = new WeakFormNSNewton(STOKES, RE, TAU, &xvel_prev_time, &yvel_prev_time); + wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. - DiscreteProblem dp(wf, spaces_const); + DiscreteProblem dp(wf, spaces); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 750, 240)); @@ -169,8 +169,8 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. Hermes::Hermes2D::NewtonSolver newton(&dp); Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); try { newton.solve(); @@ -181,7 +181,7 @@ int main(int argc, char* argv[]) }; // Update previous time level solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), spaces_const, slns_prev_time); + Solution::vector_to_solutions(newton.get_sln_vector(), spaces, slns_prev_time); // Visualization. // Hermes visualization. @@ -190,23 +190,23 @@ int main(int argc, char* argv[]) // Show the solution at the end of time step. sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); - vview.show(&xvel_prev_time, &yvel_prev_time, HERMES_EPS_LOW); + vview.show(xvel_prev_time, yvel_prev_time, HERMES_EPS_LOW); sprintf(title, "Pressure, time %g", current_time); pview.set_title(title); - pview.show(&p_prev_time); + pview.show(p_prev_time); } // Output solution in VTK format. if(VTK_VISUALIZATION) { Linearizer lin; - Hermes::vector* > slns_prev_time0 = Hermes::vector* >(&xvel_prev_time, &yvel_prev_time); + Hermes::vector* > slns_prev_time0 = Hermes::vector* >(xvel_prev_time, yvel_prev_time); MagFilter mag(slns_prev_time0, Hermes::vector(H2D_FN_VAL, H2D_FN_VAL)); std::stringstream ss_vel; ss_vel << "Velocity-" << ts << ".vtk"; lin.save_solution_vtk(&mag, ss_vel.str().c_str(), "VelocityMagnitude"); std::stringstream ss_pres; ss_pres << "Pressure-" << ts << ".vtk"; - lin.save_solution_vtk(&p_prev_time, ss_pres.str().c_str(), "Pressure"); + lin.save_solution_vtk(p_prev_time, ss_pres.str().c_str(), "Pressure"); } } diff --git a/2d-advanced/navier-stokes/driven-cavity/definitions.cpp b/2d-advanced/navier-stokes/driven-cavity/definitions.cpp index 01d78fc..514f595 100644 --- a/2d-advanced/navier-stokes/driven-cavity/definitions.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/definitions.cpp @@ -1,7 +1,7 @@ #include "definitions.h" -WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time) : WeakForm(3), Stokes(Stokes), +WeakFormNSNewton::WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time) : WeakForm(3), Stokes(Stokes), Reynolds(Reynolds), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time) { diff --git a/2d-advanced/navier-stokes/driven-cavity/definitions.h b/2d-advanced/navier-stokes/driven-cavity/definitions.h index a35b45f..8e0679d 100644 --- a/2d-advanced/navier-stokes/driven-cavity/definitions.h +++ b/2d-advanced/navier-stokes/driven-cavity/definitions.h @@ -10,8 +10,8 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class WeakFormNSNewton : public WeakForm { public: - WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time); + WeakFormNSNewton(bool Stokes, double Reynolds, double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time); class BilinearFormSymVel : public MatrixFormVol { @@ -181,8 +181,8 @@ class WeakFormNSNewton : public WeakForm bool Stokes; double Reynolds; double time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; }; /* Essential boundary conditions */ diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index e514cf7..a8d6701 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -66,7 +66,7 @@ double integrate_over_wall(MeshFunction* meshfn, int marker) double integral = 0.0; Element* e; - const Mesh* mesh = meshfn->get_mesh(); + MeshSharedPtr mesh,= meshfn->get_mesh(); for_all_active_elements(e, mesh) { @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) #else H1Space p_space(mesh, P_INIT_PRESSURE); #endif - Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -140,11 +140,11 @@ int main(int argc, char* argv[]) ZeroSolution xvel_prev_time(mesh); ZeroSolution yvel_prev_time(mesh); ZeroSolution p_prev_time(mesh); - Hermes::vector*> slns_prev_time = - Hermes::vector*>(&xvel_prev_time, &yvel_prev_time, &p_prev_time); + Hermes::vector > slns_prev_time = + Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); // Initialize weak formulation. - WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, &xvel_prev_time, &yvel_prev_time); + WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. DiscreteProblem dp(wf, spaces); @@ -168,15 +168,15 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector*>(&xvel_space, &yvel_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(&xvel_space, &yvel_space), current_time); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); Hermes::Hermes2D::NewtonSolver newton(&dp); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -191,10 +191,10 @@ int main(int argc, char* argv[]) // Show the solution at the end of time step. sprintf(title, "Pressure, time %g", current_time); pview.set_title(title); - pview.show(&p_prev_time); + pview.show(p_prev_time); sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); - vview.show(&xvel_prev_time, &yvel_prev_time, HERMES_EPS_LOW*10); + vview.show(xvel_prev_time, yvel_prev_time, HERMES_EPS_LOW*10); } diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index ac7d06a..7235591 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -226,7 +226,7 @@ int main(int argc, char* argv[]) // Show the solution at the end of time step. sprintf(title, "Velocity [m/s], time %g s", current_time); vview.set_title(title); - //vview.show(&xvel_prev_time, &yvel_prev_time); + //vview.show(xvel_prev_time, yvel_prev_time); sprintf(title, "Pressure [Pa], time %g s", current_time); pview.set_title(title); pview.show(p_prev_time); diff --git a/2d-advanced/navier-stokes/rayleigh-benard/definitions.cpp b/2d-advanced/navier-stokes/rayleigh-benard/definitions.cpp index 08adb91..e1c7226 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/definitions.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/definitions.cpp @@ -6,8 +6,8 @@ class WeakFormRayleighBenard : public WeakForm { public: WeakFormRayleighBenard(double Pr, double Ra, std::string bdy_top, double temp_ext, double alpha_air, - double time_step, Solution* x_vel_previous_time, - Solution* y_vel_previous_time, Solution* temp_previous_time) + double time_step, MeshFunctionSharedPtr x_vel_previous_time, + MeshFunctionSharedPtr y_vel_previous_time, MeshFunctionSharedPtr temp_previous_time) : WeakForm(4), Pr(Pr), Ra(Ra), time_step(time_step), x_vel_previous_time(x_vel_previous_time), y_vel_previous_time(y_vel_previous_time), temp_previous_time(temp_previous_time) { /* Jacobian terms - first velocity equation */ @@ -526,8 +526,8 @@ class WeakFormRayleighBenard : public WeakForm }; protected: double Pr, Ra, time_step; - Solution* x_vel_previous_time; - Solution* y_vel_previous_time; - Solution* temp_previous_time; + MeshFunctionSharedPtr x_vel_previous_time; + MeshFunctionSharedPtr y_vel_previous_time; + MeshFunctionSharedPtr temp_previous_time; }; diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 6dd86a2..43050d5 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) H1Space p_space(mesh, P_INIT_PRESSURE); #endif H1Space t_space(mesh, &bcs_temp, P_INIT_TEMP); - Hermes::vector*> spaces = Hermes::vector*>(&xvel_space, &yvel_space, &p_space, &t_space); + Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space, &t_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -118,12 +118,12 @@ int main(int argc, char* argv[]) ZeroSolution yvel_prev_time(mesh); ZeroSolution p_prev_time(mesh); ConstantSolution t_prev_time(mesh, TEMP_INIT); - Hermes::vector*> slns = Hermes::vector*>(&xvel_prev_time, - &yvel_prev_time, &p_prev_time, &t_prev_time); + Hermes::vector > slns = Hermes::vector >(xvel_prev_time, + yvel_prev_time, p_prev_time, &t_prev_time); // Initialize weak formulation. WeakForm* wf = new WeakFormRayleighBenard(Pr, Ra, "Top", TEMP_EXT, ALPHA_AIR, time_step, - &xvel_prev_time, &yvel_prev_time, &t_prev_time); + xvel_prev_time, yvel_prev_time, &t_prev_time); // Initialize the FE problem. DiscreteProblem dp(wf, spaces); @@ -158,8 +158,8 @@ int main(int argc, char* argv[]) newton.set_verbose_output(true); try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) @@ -174,11 +174,11 @@ int main(int argc, char* argv[]) // Show the solution at the end of time step. sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); - vview.show(&xvel_prev_time, &yvel_prev_time); + vview.show(xvel_prev_time, yvel_prev_time); sprintf(title, "Pressure, time %g", current_time); pview.set_title(title); - pview.show(&p_prev_time); - tview.show(&t_prev_time); + pview.show(p_prev_time); + tview.show(t_prev_time); // Update current time. current_time += time_step; diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp index 643ebaf..cc01328 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp @@ -8,7 +8,7 @@ class ScaledWeakFormPNPCranic : public WeakForm { ScaledWeakFormPNPCranic::Residual* vector_form = new ScaledWeakFormPNPCranic::Residual(i, tau, epsilon); if(i == 0) { - vector_form->set_ext(Hermes::vector*>(C_prev_time, phi_prev_time)); + vector_form->set_ext(Hermes::vector >(C_prev_time, phi_prev_time)); } add_vector_form(vector_form); for(unsigned int j = 0; j < 2; j++) @@ -159,7 +159,7 @@ class WeakFormPNPCranic : public WeakForm { WeakFormPNPCranic::Residual* vector_form = new WeakFormPNPCranic::Residual(i, tau, C0, K, L, D); if(i == 0) { - vector_form->set_ext(Hermes::vector*>(C_prev_time, phi_prev_time)); + vector_form->set_ext(Hermes::vector >(C_prev_time, phi_prev_time)); } add_vector_form(vector_form); for(unsigned int j = 0; j < 2; j++) diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index f0c9607..71f58f3 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -192,7 +192,7 @@ int main (int argc, char* argv[]) { // Load the mesh file. Mesh C_mesh, phi_mesh, basemesh; MeshReaderH2D mloader; - mloader.load("small.mesh", &basemesh); + mloader.load("small.mesh", basemesh); if (SCALED) { bool ret = basemesh->rescale(l, l); @@ -208,8 +208,8 @@ int main (int argc, char* argv[]) { basemesh->refine_towards_boundary(BDY_BOT, REF_INIT - 1); basemesh->refine_all_elements(1); basemesh->refine_all_elements(1); - C_mesh->copy(&basemesh); - phi_mesh->copy(&basemesh); + C_mesh->copy(basemesh); + phi_mesh->copy(basemesh); DefaultEssentialBCConst bc_phi_voltage(BDY_TOP, scaleVoltage(VOLTAGE)); DefaultEssentialBCConst bc_phi_zero(BDY_BOT, scaleVoltage(0.0)); @@ -218,8 +218,8 @@ int main (int argc, char* argv[]) { Hermes::vector* >(&bc_phi_voltage, &bc_phi_zero)); // Spaces for concentration and the voltage. - H1Space C_space(&C_mesh, P_INIT); - H1Space phi_space(MULTIMESH ? &phi_mesh : &C_mesh, &bcs_phi, P_INIT); + H1Space C_space(C_mesh, P_INIT)); + H1Space phi_space(MULTIMESH ? &phi_mesh : &C_mesh, &bcs_phi, P_INIT)); Solution C_sln, C_ref_sln; Solution phi_sln, phi_ref_sln; @@ -248,18 +248,18 @@ int main (int argc, char* argv[]) { wf = new WeakFormPNPEuler(TAU, C0, K, L, D, &C_prev_time); } - DiscreteProblem dp_coarse(wf, Hermes::vector *>(&C_space, &phi_space)); + DiscreteProblem dp_coarse(wf, Hermes::vector >(&C_space, &phi_space)); NewtonSolver* solver_coarse = new NewtonSolver(&dp_coarse); // Project the initial condition on the FE space to obtain initial // coefficient vector for the Newton's method. Hermes::Mixins::Loggable::Static::info("Projecting to obtain initial vector for the Newton's method."); - int ndof = Space::get_num_dofs(Hermes::vector*>(&C_space, &phi_space)); + int ndof = Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)); double* coeff_vec_coarse = new double[ndof] ; - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&C_space, &phi_space), - Hermes::vector *>(&C_prev_time, &phi_prev_time), + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&C_space, &phi_space), + Hermes::vector >(&C_prev_time, &phi_prev_time), coeff_vec_coarse); // Create a selector which will select optimal candidate. @@ -272,17 +272,17 @@ int main (int argc, char* argv[]) { OrderView Cordview("C order", new WinGeom(0, 300, 600, 600)); OrderView phiordview("Phi order", new WinGeom(600, 300, 600, 600)); - Cview.show(&C_prev_time); - Cordview.show(&C_space); - phiview.show(&phi_prev_time); - phiordview.show(&phi_space); + Cview.show(C_prev_time); + Cordview.show(C_space); + phiview.show(phi_prev_time); + phiordview.show(phi_space); // Newton's loop on the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Solving on initial coarse mesh"); try { - solver_coarse->set_newton_max_iter(NEWTON_MAX_ITER); - solver_coarse->set_newton_tol(NEWTON_TOL_COARSE); + solver_coarse->set_max_allowed_iterations(NEWTON_MAX_ITER); + solver_coarse->set_tolerance(NEWTON_TOL_COARSE); solver_coarse->solve(coeff_vec_coarse); } catch(Hermes::Exceptions::Exception e) @@ -293,12 +293,12 @@ int main (int argc, char* argv[]) { //View::wait(HERMES_WAIT_KEYPRESS); - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solutions(solver_coarse->get_sln_vector(), Hermes::vector *>(&C_space, &phi_space), - Hermes::vector *>(&C_sln, &phi_sln)); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solutions(solver_coarse->get_sln_vector(), Hermes::vector >(&C_space, &phi_space), + Hermes::vector >(&C_sln, &phi_sln)); - Cview.show(&C_sln); - phiview.show(&phi_sln); + Cview.show(C_sln); + phiview.show(phi_sln); // Cleanup after the Newton loop on the coarse mesh-> delete solver_coarse; @@ -316,13 +316,13 @@ int main (int argc, char* argv[]) { if (pid.get_timestep_number() > 1 && pid.get_timestep_number() % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - C_mesh->copy(&basemesh); + C_mesh->copy(basemesh); if (MULTIMESH) { - phi_mesh->copy(&basemesh); + phi_mesh->copy(basemesh); } - C_space.set_uniform_order(P_INIT); - phi_space.set_uniform_order(P_INIT); + C_space->set_uniform_order(P_INIT); + phi_space->set_uniform_order(P_INIT); } @@ -333,24 +333,24 @@ int main (int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", pid.get_timestep_number(), as); // Construct globally refined reference mesh - // and setup reference space. + // and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreatorC(&C_mesh); - Mesh* ref_C_mesh = refMeshCreatorC.create_ref_mesh(); + MeshSharedPtr ref_C_mesh = refMeshCreatorC.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorC(&C_space, ref_C_mesh); - Space* ref_C_space = refSpaceCreatorC.create_ref_space(); + SpaceSharedPtr ref_C_space = refSpaceCreatorC.create_ref_space(); Mesh::ReferenceMeshCreator refMeshCreatorPhi(&phi_mesh); - Mesh* ref_phi_mesh = refMeshCreatorPhi.create_ref_mesh(); + MeshSharedPtr ref_phi_mesh = refMeshCreatorPhi.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorPhi(&phi_space, ref_phi_mesh); - Space* ref_phi_space = refSpaceCreatorPhi.create_ref_space(); + SpaceSharedPtr ref_phi_space = refSpaceCreatorPhi.create_ref_space(); - Hermes::vector*> ref_spaces(ref_C_space, ref_phi_space); - Hermes::vector*> ref_spaces_const(ref_C_space, ref_phi_space); + Hermes::vector > ref_spaces(ref_C_space, ref_phi_space); + Hermes::vector > ref_spaces(ref_C_space, ref_phi_space); - DiscreteProblem* dp = new DiscreteProblem(wf, ref_spaces_const); - int ndof_ref = Space::get_num_dofs(ref_spaces_const); + DiscreteProblem* dp = new DiscreteProblem(wf, ref_spaces); + int ndof_ref = Space::get_num_dofs(ref_spaces); double* coeff_vec = new double[ndof_ref]; @@ -359,29 +359,29 @@ int main (int argc, char* argv[]) { // Calculate initial coefficient vector for Newton on the fine mesh-> if (as == 1 && pid.get_timestep_number() == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, - Hermes::vector *>(&C_sln, &phi_sln), + OGProjection ogProjection; ogProjection.project_global(ref_spaces, + Hermes::vector >(&C_sln, &phi_sln), coeff_vec); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces_const, - Hermes::vector *>(&C_ref_sln, &phi_ref_sln), + OGProjection ogProjection; ogProjection.project_global(ref_spaces, + Hermes::vector >(&C_ref_sln, &phi_ref_sln), coeff_vec); } if (as > 1) { // Now deallocate the previous mesh Hermes::Mixins::Loggable::Static::info("Delallocating the previous mesh"); - delete C_ref_sln.get_mesh(); - delete phi_ref_sln.get_mesh(); + delete C_ref_sln->get_mesh(); + delete phi_ref_sln->get_mesh(); } // Newton's loop on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Solving on fine mesh:"); try { - solver->set_newton_max_iter(NEWTON_MAX_ITER); - solver->set_newton_tol(NEWTON_TOL_FINE); + solver->set_max_allowed_iterations(NEWTON_MAX_ITER); + solver->set_tolerance(NEWTON_TOL_FINE); solver->solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) @@ -390,35 +390,35 @@ int main (int argc, char* argv[]) { throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Store the result in ref_sln. - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, - Hermes::vector *>(&C_ref_sln, &phi_ref_sln)); + // Store the result in ref_sln-> + Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, + Hermes::vector >(&C_ref_sln, &phi_ref_sln)); // Projecting reference solution onto the coarse mesh Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector *>(&C_space, &phi_space), - Hermes::vector *>(&C_ref_sln, &phi_ref_sln), - Hermes::vector *>(&C_sln, &phi_sln), + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&C_space, &phi_space), + Hermes::vector >(&C_ref_sln, &phi_ref_sln), + Hermes::vector >(&C_sln, &phi_sln), matrix_solver); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector *>(&C_space, &phi_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(&C_space, &phi_space)); Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector *>(&C_sln, &phi_sln), - Hermes::vector *>(&C_ref_sln, &phi_ref_sln), &err_est_rel) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&C_sln, &phi_sln), + Hermes::vector >(&C_ref_sln, &phi_ref_sln), &err_est_rel) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", - C_space.get_num_dofs(), ref_C_space->get_num_dofs()); + C_space->get_num_dofs(), ref_C_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%", err_est_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", - phi_space.get_num_dofs(), ref_phi_space->get_num_dofs()); + phi_space->get_num_dofs(), ref_phi_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%", err_est_rel[1]*100); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector *>(&C_space, &phi_space)), - Space::get_num_dofs(ref_spaces_const), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; @@ -430,7 +430,7 @@ int main (int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adapted..."); - if (Space::get_num_dofs(Hermes::vector *>(&C_space, &phi_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)) >= NDOF_STOP) done = true; else as++; } @@ -441,21 +441,21 @@ int main (int argc, char* argv[]) { sprintf(title, "Solution[C], step# %d, step size %g, time %g, phys time %g", pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); Cview.set_title(title); - Cview.show(&C_ref_sln); + Cview.show(C_ref_sln); sprintf(title, "Mesh[C], step# %d, step size %g, time %g, phys time %g", pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); Cordview.set_title(title); - Cordview.show(&C_space); + Cordview.show(C_space); Hermes::Mixins::Loggable::Static::info("Visualization procedures: phi"); sprintf(title, "Solution[phi], step# %d, step size %g, time %g, phys time %g", pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); phiview.set_title(title); - phiview.show(&phi_ref_sln); + phiview.show(phi_ref_sln); sprintf(title, "Mesh[phi], step# %d, step size %g, time %g, phys time %g", pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); phiordview.set_title(title); - phiordview.show(&phi_space); + phiordview.show(phi_space); //View::wait(HERMES_WAIT_KEYPRESS); // Clean up. @@ -468,13 +468,13 @@ int main (int argc, char* argv[]) { } while (done == false); - pid.end_step(Hermes::vector*> (&C_ref_sln, &phi_ref_sln), - Hermes::vector*> (&C_prev_time, &phi_prev_time)); + pid.end_step(Hermes::vector > (&C_ref_sln, &phi_ref_sln), + Hermes::vector > (&C_prev_time, &phi_prev_time)); // TODO! Time step reduction when necessary. - // Copy last reference solution into sln_prev_time. - C_prev_time.copy(&C_ref_sln); - phi_prev_time.copy(&phi_ref_sln); + // Copy last reference solution into sln_prev_time + C_prev_time->copy(C_ref_sln); + phi_prev_time->copy(phi_ref_sln); } while (pid.has_next()); diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h index f0d6ab7..57c5501 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h @@ -22,7 +22,7 @@ class PidTimestepController { double get_time() {return time;}; // true if next time step can be run, false if the time step must be re-run with smaller time step. - bool end_step(Hermes::vector*> solutions, Hermes::vector *> prev_solutions); + bool end_step(Hermes::vector > solutions, Hermes::vector > prev_solutions); void begin_step(); bool has_next(); @@ -64,8 +64,8 @@ void PidTimestepController::begin_step() { Hermes::Mixins::Loggable::Static::info("begin_step processed, new step number: %i and cumulative time: %g", step_number, time); } -bool PidTimestepController::end_step(Hermes::vector *> solutions, - Hermes::vector *> prev_solutions) { +bool PidTimestepController::end_step(Hermes::vector > solutions, + Hermes::vector > prev_solutions) { if (pid) { diff --git a/2d-advanced/neutronics/4-group-adapt/definitions.cpp b/2d-advanced/neutronics/4-group-adapt/definitions.cpp index 48a95f7..60e90c0 100644 --- a/2d-advanced/neutronics/4-group-adapt/definitions.cpp +++ b/2d-advanced/neutronics/4-group-adapt/definitions.cpp @@ -5,7 +5,7 @@ #include "definitions.h" CustomWeakForm::CustomWeakForm(const MaterialPropertyMaps& matprop, - Hermes::vector*>& iterates, + Hermes::vector >& iterates, double init_keff, std::string bdy_vacuum) : DefaultWeakFormSourceIteration(matprop, const_cast(iterates[0]->get_mesh()), iterates, init_keff, HERMES_AXISYM_Y) { diff --git a/2d-advanced/neutronics/4-group-adapt/definitions.h b/2d-advanced/neutronics/4-group-adapt/definitions.h index efde188..9bf4c86 100644 --- a/2d-advanced/neutronics/4-group-adapt/definitions.h +++ b/2d-advanced/neutronics/4-group-adapt/definitions.h @@ -14,12 +14,12 @@ class CustomWeakForm : public DefaultWeakFormSourceIteration { public: CustomWeakForm(const MaterialPropertyMaps& matprop, - Hermes::vector*>& iterates, + Hermes::vector >& iterates, double init_keff, std::string bdy_vacuum); }; // Integral over the active core. -double integrate(MeshFunction* sln, Mesh* mesh, std::string area); +double integrate(MeshFunction* sln, MeshSharedPtr mesh, std::string area); int get_num_of_neg(MeshFunction *sln); // Jacobian matrix (same as stiffness matrix since projections are linear). @@ -147,6 +147,6 @@ class ErrorForm : public Adapt::MatrixFormVolError /// \return number of iterations needed for convergence within the specified tolerance. /// int power_iteration(const MaterialPropertyMaps& matprop, - const Hermes::vector*>& spaces, DefaultWeakFormSourceIteration* wf, - const Hermes::vector *>& solution, const std::string& fission_region, + const Hermes::vector >& spaces, DefaultWeakFormSourceIteration* wf, + const Hermes::vector >& solution, const std::string& fission_region, double tol, Hermes::MatrixSolverType matrix_solver); diff --git a/2d-advanced/neutronics/4-group-adapt/main.cpp b/2d-advanced/neutronics/4-group-adapt/main.cpp index 2c72e13..3656699 100644 --- a/2d-advanced/neutronics/4-group-adapt/main.cpp +++ b/2d-advanced/neutronics/4-group-adapt/main.cpp @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) // Create pointers to solutions on coarse and fine meshes and from the latest power iteration, respectively. Hermes::vector*> coarse_solutions, fine_solutions; - Hermes::vector*> power_iterates; + Hermes::vector > power_iterates; // Initialize all the new solution variables. for (unsigned int g = 0; g < matprop.get_G(); g++) diff --git a/2d-advanced/neutronics/4-group/definitions.cpp b/2d-advanced/neutronics/4-group/definitions.cpp index 36edd0c..cab97d4 100644 --- a/2d-advanced/neutronics/4-group/definitions.cpp +++ b/2d-advanced/neutronics/4-group/definitions.cpp @@ -3,7 +3,7 @@ #include "definitions.h" CustomWeakForm::CustomWeakForm( const Hermes::Hermes2D::WeakFormsNeutronics::Multigroup::MaterialProperties::Diffusion::MaterialPropertyMaps& matprop, - Hermes::vector*>& iterates, + Hermes::vector >& iterates, double init_keff, std::string bdy_vacuum ) : Hermes::Hermes2D::WeakFormsNeutronics::Multigroup::CompleteWeakForms::Diffusion::DefaultWeakFormSourceIteration(matprop, const_cast(iterates[0]->get_mesh()), iterates, init_keff, HERMES_AXISYM_Y) { diff --git a/2d-advanced/neutronics/4-group/main.cpp b/2d-advanced/neutronics/4-group/main.cpp index c02258e..e4f404e 100644 --- a/2d-advanced/neutronics/4-group/main.cpp +++ b/2d-advanced/neutronics/4-group/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); ConstantSolution iter1(&mesh, 1.00), iter2(&mesh, 1.00), iter3(&mesh, 1.00), iter4(&mesh, 1.00); - Hermes::vector*> iterates(&iter1, &iter2, &iter3, &iter4); + Hermes::vector > iterates(&iter1, &iter2, &iter3, &iter4); // Create H1 spaces with default shapesets. H1Space space1(&mesh, P_INIT_1); diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index d63f550..7b53697 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Associate element markers (corresponding to physical regions) // with material properties (diffusion coefficient, absorption @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) wf(regions, D_map, Sigma_a_map, Sources_map); // Initialize coarse and reference mesh solution. - Solution sln, ref_sln; + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -168,12 +168,12 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // Construct globally refined mesh and setup fine mesh space. + // Construct globally refined mesh and setup fine mesh space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. @@ -195,38 +195,38 @@ int main(int argc, char* argv[]) } // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); // Visualize the solution and mesh-> - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Skip visualization time. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(&space); + Adapt adaptivity(space); bool solutions_for_adapt = true; - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln, solutions_for_adapt, + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); + space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); // Add entry to DOF and CPU convergence graphs. cpu_time.tick(); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - graph_dof.add_values(space.get_num_dofs(), err_est_rel); + graph_dof.add_values(space->get_num_dofs(), err_est_rel); graph_dof.save("conv_dof_est.dat"); // Skip the time spent to save the convergence graphs. @@ -244,14 +244,14 @@ int main(int argc, char* argv[]) if (done == false) as++; } - if (space.get_num_dofs() >= NDOF_STOP) + if (space->get_num_dofs() >= NDOF_STOP) done = true; // Keep the mesh from final step to allow further work with the final fine mesh solution. if(done == false) { delete ref_space->get_mesh(); - delete ref_space; + } } while (done == false); @@ -261,7 +261,7 @@ int main(int argc, char* argv[]) // Show the fine mesh solution - final result. sview.set_title("Fine mesh solution"); sview.show_mesh(false); - sview.show(&ref_sln); + sview.show(ref_sln); // Wait for all views to be closed. Views::View::wait(); diff --git a/2d-advanced/richards/basic-ie-newton/definitions.cpp b/2d-advanced/richards/basic-ie-newton/definitions.cpp index 5baa89d..3a12e5e 100644 --- a/2d-advanced/richards/basic-ie-newton/definitions.cpp +++ b/2d-advanced/richards/basic-ie-newton/definitions.cpp @@ -22,7 +22,7 @@ double CustomEssentialBCNonConst::value(double x, double y, double n_x, double n /* Custom weak forms */ -CustomWeakFormRichardsIE::CustomWeakFormRichardsIE(double time_step, Solution* h_time_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) +CustomWeakFormRichardsIE::CustomWeakFormRichardsIE(double time_step, MeshFunctionSharedPtr h_time_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) { // Jacobian volumetric part. CustomJacobianFormVol* jac_form_vol = new CustomJacobianFormVol(0, 0, time_step); diff --git a/2d-advanced/richards/basic-ie-newton/definitions.h b/2d-advanced/richards/basic-ie-newton/definitions.h index cd70271..c91649b 100644 --- a/2d-advanced/richards/basic-ie-newton/definitions.h +++ b/2d-advanced/richards/basic-ie-newton/definitions.h @@ -28,7 +28,7 @@ class CustomEssentialBCNonConst : public EssentialBoundaryCondition class CustomWeakFormRichardsIE : public WeakForm { public: - CustomWeakFormRichardsIE(double time_step, Solution* h_time_prev, ConstitutiveRelations* constitutive); + CustomWeakFormRichardsIE(double time_step, MeshFunctionSharedPtr h_time_prev, ConstitutiveRelations* constitutive); private: diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index 4734283..e887435 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -81,19 +81,19 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(mesh); + MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); view.fix_scale_width(80); // Visualize the initial condition. - view.show(&h_time_prev); + view.show(h_time_prev); // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; @@ -104,10 +104,10 @@ int main(int argc, char* argv[]) // Initialize the weak formulation. double current_time = 0; - CustomWeakFormRichardsIE wf(time_step, &h_time_prev, constitutive_relations); + CustomWeakFormRichardsIE wf(time_step, h_time_prev, constitutive_relations); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Initialize Newton solver. NewtonSolver newton(&dp); @@ -122,8 +122,8 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -132,14 +132,14 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution sln. - Solution::vector_to_solution(newton.get_sln_vector(), &space, &h_time_prev); + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solution(newton.get_sln_vector(), space, &h_time_prev); // Visualize the solution. char title[100]; sprintf(title, "Time %g s", current_time); view.set_title(title); - view.show(&h_time_prev); + view.show(h_time_prev); // Increase current time and time step counter. current_time += time_step; diff --git a/2d-advanced/richards/basic-ie-picard/definitions.cpp b/2d-advanced/richards/basic-ie-picard/definitions.cpp index 076d559..5aa4c78 100644 --- a/2d-advanced/richards/basic-ie-picard/definitions.cpp +++ b/2d-advanced/richards/basic-ie-picard/definitions.cpp @@ -22,16 +22,16 @@ double CustomEssentialBCNonConst::value(double x, double y, double n_x, double n /* Custom weak forms */ -CustomWeakFormRichardsIEPicard::CustomWeakFormRichardsIEPicard(double time_step, Solution* h_time_prev, Solution* h_iter_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) +CustomWeakFormRichardsIEPicard::CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, MeshFunctionSharedPtr h_iter_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) { // Jacobian. CustomJacobian* matrix_form = new CustomJacobian(0, 0, time_step); - matrix_form->set_ext(Hermes::vector*>(h_time_prev, h_iter_prev)); + matrix_form->set_ext(Hermes::vector >(h_time_prev, h_iter_prev)); add_matrix_form(matrix_form); // Residual. CustomResidual* vector_form = new CustomResidual(0, time_step); - vector_form->set_ext(Hermes::vector*>(h_time_prev, h_iter_prev)); + vector_form->set_ext(Hermes::vector >(h_time_prev, h_iter_prev)); add_vector_form(vector_form); } diff --git a/2d-advanced/richards/basic-ie-picard/definitions.h b/2d-advanced/richards/basic-ie-picard/definitions.h index c5578d6..58f4d81 100644 --- a/2d-advanced/richards/basic-ie-picard/definitions.h +++ b/2d-advanced/richards/basic-ie-picard/definitions.h @@ -28,7 +28,7 @@ class CustomEssentialBCNonConst : public EssentialBoundaryCondition class CustomWeakFormRichardsIEPicard : public WeakForm { public: - CustomWeakFormRichardsIEPicard(double time_step, Solution* h_time_prev, Solution* h_iter_prev, ConstitutiveRelations* constitutive); + CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, MeshFunctionSharedPtr h_iter_prev, ConstitutiveRelations* constitutive); private: diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index f15c8cd..d2fa08a 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -80,8 +80,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) view.fix_scale_width(80); // Visualize the initial condition. - view.show(&h_time_prev); + view.show(h_time_prev); // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; @@ -106,7 +106,8 @@ int main(int argc, char* argv[]) CustomWeakFormRichardsIEPicard wf(time_step, &h_time_prev, &h_iter_prev, constitutive_relations); // Initialize the FE problem. - DiscreteProblemLinear dp(&wf, &space); + DiscreteProblem dp(&wf, space); + dp.set_linear(); // Initialize the Picard solver. PicardSolver picard(&dp); @@ -119,8 +120,8 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f s", ts, current_time); // Perform the Picard's iteration (Anderson acceleration on by default). - picard.set_picard_tol(PICARD_TOL); - picard.set_picard_max_iter(PICARD_MAX_ITER); + picard.set_tolerance(PICARD_TOL); + picard.set_max_allowed_iterations(PICARD_MAX_ITER); picard.set_num_last_vector_used(PICARD_NUM_LAST_ITER_USED); picard.set_anderson_beta(PICARD_ANDERSON_BETA); @@ -134,7 +135,7 @@ int main(int argc, char* argv[]) } // Translate the coefficient vector into a Solution. - Solution::vector_to_solution(picard.get_sln_vector(), &space, &h_iter_prev); + Solution::vector_to_solution(picard.get_sln_vector(), space, &h_iter_prev); // Increase current time and time step counter. current_time += time_step; @@ -144,10 +145,10 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Time %g s", current_time); view.set_title(title); - view.show(&h_iter_prev); + view.show(h_iter_prev); // Save the next time level solution. - h_time_prev.copy(&h_iter_prev); + h_time_prev->copy(h_iter_prev); } while (current_time < T_FINAL); diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index cf8ff1f..a6b4d63 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -125,10 +125,10 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &basemesh); - mesh->copy(&basemesh); + mloader.load("square.mesh", basemesh); + mesh->copy(basemesh); // Initial mesh refinements. for(int i = 0; i < INIT_GLOB_REF_NUM; i++) mesh->refine_all_elements(); @@ -139,8 +139,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof_coarse = Space::get_num_dofs(&space); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof_coarse = Space::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof_coarse = %d.", ndof_coarse); // Zero initial solution. This is why we use H_OFFSET. @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) CustomWeakFormRichardsRK wf(constitutive_relations); // Initialize the FE problem. - DiscreteProblem dp(&wf, &space); + DiscreteProblem dp(&wf, space); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -166,8 +166,8 @@ int main(int argc, char* argv[]) char title[100]; ScalarView view("Initial condition", new WinGeom(0, 0, 440, 350)); OrderView ordview("Initial mesh", new WinGeom(445, 0, 440, 350)); - view.show(&h_time_prev); - ordview.show(&space); + view.show(h_time_prev); + ordview.show(space); // DOF and CPU convergence graphs initialization. SimpleGraph graph_dof, graph_cpu; @@ -185,20 +185,20 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; case 2: mesh->unrefine_all_elements(); - space.set_uniform_order(P_INIT); + space->set_uniform_order(P_INIT); break; - case 3: space.unrefine_all_mesh_elements(); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + case 3: space->unrefine_all_mesh_elements(); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - space.assign_dofs(); - ndof_coarse = Space::get_num_dofs(&space); + space->assign_dofs(); + ndof_coarse = Space::get_num_dofs(space); } // Spatial adaptivity loop. Note: h_time_prev must not be changed @@ -208,12 +208,12 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = Space::get_num_dofs(ref_space); // Time measurement. @@ -229,8 +229,8 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); runge_kutta.rk_time_step_newton(&h_time_prev, &h_time_new); } catch(Exceptions::Exception& e) @@ -242,16 +242,16 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse mesh-> Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - OGProjection ogProjection; ogProjection.project_global(&space, &h_time_new, &sln_coarse); + OGProjection ogProjection; ogProjection.project_global(space, &h_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(&space); - double err_est_rel_total = adaptivity->calc_err_est(&sln_coarse, &h_time_new) * 100; + Adapt* adaptivity = new Adapt(space); + double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, &h_time_new) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", - Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_est_rel_total); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel_total); // Time measurement. cpu_time.tick(); @@ -263,7 +263,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(&space) >= NDOF_STOP) + if (Space::get_num_dofs(space) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -280,7 +280,7 @@ int main(int argc, char* argv[]) while (done == false); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(current_time, Space::get_num_dofs(&space)); + graph_dof.add_values(current_time, Space::get_num_dofs(space)); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(current_time, cpu_time.accumulated()); graph_cpu.save("conv_cpu_est.dat"); @@ -290,15 +290,15 @@ int main(int argc, char* argv[]) sprintf(title, "Solution, time %g", current_time); view.set_title(title); view.show_mesh(false); - view.show(&h_time_new); + view.show(h_time_new); sprintf(title, "Mesh, time %g", current_time); ordview.set_title(title); - ordview.show(&space); + ordview.show(space); // Copy last reference solution into h_time_prev. if(ts > 1) delete h_time_prev.get_mesh(); - h_time_prev.copy(&h_time_new); + h_time_prev->copy(h_time_new); // Increase current time and counter of time steps. current_time += time_step; diff --git a/2d-advanced/richards/basic-rk-newton/main.cpp b/2d-advanced/richards/basic-rk-newton/main.cpp index 81eb9a1..1b0618e 100644 --- a/2d-advanced/richards/basic-rk-newton/main.cpp +++ b/2d-advanced/richards/basic-rk-newton/main.cpp @@ -101,8 +101,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) view.fix_scale_width(80); // Visualize the initial condition. - view.show(&h_time_prev); + view.show(h_time_prev); // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) CustomWeakFormRichardsRK wf(constitutive_relations); // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, &space, &bt); + RungeKutta runge_kutta(&wf, space, &bt); // Time stepping: double current_time = 0; @@ -142,8 +142,8 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); runge_kutta.rk_time_step_newton(&h_time_prev, &h_time_new); } catch(Exceptions::Exception& e) @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) } // Copy solution for the new time step. - h_time_prev.copy(&h_time_new); + h_time_prev->copy(h_time_new); // Increase current time. current_time += time_step; @@ -162,7 +162,7 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Time %3.2f s", current_time); view.set_title(title); - view.show(&h_time_prev); + view.show(h_time_prev); // Increase time step counter. ts++; diff --git a/2d-advanced/richards/capillary-barrier-adapt/definitions.h b/2d-advanced/richards/capillary-barrier-adapt/definitions.h index 88ea869..b8de597 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/definitions.h +++ b/2d-advanced/richards/capillary-barrier-adapt/definitions.h @@ -16,7 +16,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class InitialSolutionRichards : public ExactSolutionScalar { public: - InitialSolutionRichards(const Mesh* mesh, double constant) + InitialSolutionRichards(MeshSharedPtr mesh,double constant) : ExactSolutionScalar(mesh), constant(constant) {}; virtual double value (double x, double y) const { @@ -44,7 +44,7 @@ class InitialSolutionRichards : public ExactSolutionScalar class ExactSolutionPoisson : public ExactSolutionScalar { public: - ExactSolutionPoisson(const Mesh* mesh) : ExactSolutionScalar(mesh) {}; + ExactSolutionPoisson(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) {}; virtual double value (double x, double y) const { return x*x +y*y; @@ -70,7 +70,7 @@ class ExactSolutionPoisson : public ExactSolutionScalar class WeakFormRichardsNewtonEuler : public WeakForm { public: - WeakFormRichardsNewtonEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, Solution* prev_time_sln, Mesh* mesh) + WeakFormRichardsNewtonEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) : WeakForm(1), mesh(mesh), relations(relations) { JacobianFormNewtonEuler* jac_form = new JacobianFormNewtonEuler(0, 0, relations, tau); jac_form->set_ext(prev_time_sln); @@ -198,7 +198,7 @@ class WeakFormRichardsNewtonEuler : public WeakForm class WeakFormRichardsNewtonCrankNicolson : public WeakForm { public: - WeakFormRichardsNewtonCrankNicolson(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, Solution* prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { + WeakFormRichardsNewtonCrankNicolson(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { JacobianFormNewtonCrankNicolson* jac_form = new JacobianFormNewtonCrankNicolson(0, 0, relations, tau); jac_form->set_ext(prev_time_sln); add_matrix_form(jac_form); @@ -321,7 +321,7 @@ class WeakFormRichardsNewtonCrankNicolson : public WeakForm class WeakFormRichardsPicardEuler : public WeakForm { public: - WeakFormRichardsPicardEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, Solution* prev_picard_sln, Solution* prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { + WeakFormRichardsPicardEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_picard_sln, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { JacobianFormPicardEuler* jac_form = new JacobianFormPicardEuler(0, 0, relations, tau); jac_form->set_ext(prev_picard_sln); add_matrix_form(jac_form); diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index d79dde4..4e29586 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -225,12 +225,12 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load(mesh_file.c_str(), &basemesh); + mloader.load(mesh_file.c_str(), basemesh); // Perform initial mesh refinements. - mesh->copy(&basemesh); + mesh->copy(basemesh); for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(0, true); mesh->refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY_TOP, true, true); @@ -239,34 +239,34 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = Space::get_num_dofs(&space); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = Space::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Create a selector which will select optimal candidate. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); // Solutions for the time stepping and the Newton's method. - Solution sln, ref_sln; - InitialSolutionRichards sln_prev_time(mesh, H_INIT); - InitialSolutionRichards sln_prev_iter(mesh, H_INIT); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); + MeshFunctionSharedPtr sln_prev_time(new InitialSolutionRichards(mesh, H_INIT)); + MeshFunctionSharedPtr sln_prev_iter(new InitialSolutionRichards(mesh, H_INIT)); // Initialize the weak formulation. WeakForm* wf; if (ITERATIVE_METHOD == 1) { if (TIME_INTEGRATION == 1) { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Newton's method (implicit Euler in time)."); - wf = new WeakFormRichardsNewtonEuler(&constitutive_relations, time_step, &sln_prev_time, mesh); + wf = new WeakFormRichardsNewtonEuler(&constitutive_relations, time_step, sln_prev_time, mesh); } else { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Newton's method (Crank-Nicolson in time)."); - wf = new WeakFormRichardsNewtonCrankNicolson(&constitutive_relations, time_step, &sln_prev_time, mesh); + wf = new WeakFormRichardsNewtonCrankNicolson(&constitutive_relations, time_step, sln_prev_time, mesh); } } else { if (TIME_INTEGRATION == 1) { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Picard's method (implicit Euler in time)."); - wf = new WeakFormRichardsPicardEuler(&constitutive_relations, time_step, &sln_prev_iter, &sln_prev_time, mesh); + wf = new WeakFormRichardsPicardEuler(&constitutive_relations, time_step, sln_prev_iter, sln_prev_time, mesh); } else { Hermes::Mixins::Loggable::Static::info("Creating weak formulation for the Picard's method (Crank-Nicolson in time)."); @@ -282,8 +282,8 @@ int main(int argc, char* argv[]) ScalarView view("Initial condition", new WinGeom(0, 0, 630, 350)); view.fix_scale_width(50); OrderView ordview("Initial mesh", new WinGeom(640, 0, 600, 350)); - view.show(&sln_prev_time); - ordview.show(&space); + view.show(sln_prev_time); + ordview.show(space); //MeshView mview("Mesh", new WinGeom(840, 0, 600, 350)); //mview.show(mesh); //View::wait(); @@ -302,21 +302,21 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; case 2: mesh->unrefine_all_elements(); - space.set_uniform_order(P_INIT); + space->set_uniform_order(P_INIT); break; case 3: mesh->unrefine_all_elements(); - //space.adjust_element_order(-1, P_INIT); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + //space->adjust_element_order(-1, P_INIT)); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - space.assign_dofs(); - ndof = Space::get_num_dofs(&space); + space->assign_dofs(); + ndof = Space::get_num_dofs(space); } // Spatial adaptivity loop. Note: sln_prev_time must not be touched during adaptivity. @@ -328,12 +328,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Time step %d, time step lenght %g, time %g (days), adaptivity step %d:", ts, time_step, current_time, as); // Construct globally refined reference mesh - // and setup reference space. + // and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); ndof = Space::get_num_dofs(ref_space); // Next we need to calculate the reference solution. @@ -344,13 +344,13 @@ int main(int argc, char* argv[]) // Calculate initial coefficient vector for Newton on the fine mesh-> if (as == 1 && ts == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_space, &sln_prev_time, coeff_vec); + OGProjection ogProjection; ogProjection.project_global(ref_space, sln_prev_time, coeff_vec); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_space, &ref_sln, coeff_vec); + OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, coeff_vec); if(as > 1) - delete ref_sln.get_mesh(); + delete ref_sln->get_mesh(); } // Initialize the FE problem. @@ -377,8 +377,8 @@ int main(int argc, char* argv[]) { try { - newton.set_newton_max_iter(NEWTON_MAX_ITER); - newton.set_newton_tol(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(coeff_vec); newton_converged = true; } @@ -405,7 +405,7 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector // into the desired reference solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Cleanup. delete [] coeff_vec; @@ -414,11 +414,11 @@ int main(int argc, char* argv[]) // Calculate initial condition for Picard on the fine mesh-> if (as == 1 && ts == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_space, &sln_prev_time, &sln_prev_iter); + OGProjection ogProjection; ogProjection.project_global(ref_space, sln_prev_time, sln_prev_iter); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_space, &ref_sln, &sln_prev_iter); + OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, sln_prev_iter); } // Perform Picard iteration on the reference mesh-> If necessary, @@ -429,19 +429,18 @@ int main(int argc, char* argv[]) bc_essential.set_current_time(current_time); - DiscreteProblemLinear dp(wf, ref_space); + DiscreteProblem dp(wf, ref_space); + dp.set_linear(); PicardSolver picard(&dp); picard.set_verbose_output(verbose); - picard.set_picard_max_iter(PICARD_MAX_ITER); - picard.set_picard_tol(PICARD_TOL); + picard.set_max_allowed_iterations(PICARD_MAX_ITER); + picard.set_tolerance(PICARD_TOL); while(true) { try { - picard.solve(&sln_prev_iter); - Solution::vector_to_solution(picard.get_sln_vector(), ref_space, &ref_sln); - if(ts > 1) - delete sln_prev_time.get_mesh(); + picard.solve(sln_prev_iter); + Solution::vector_to_solution(picard.get_sln_vector(), ref_space, ref_sln); break; } catch(std::exception& e) @@ -449,7 +448,7 @@ int main(int argc, char* argv[]) std::cout << e.what(); // Restore solution from the beginning of time step. - sln_prev_iter.copy(&sln_prev_time); + sln_prev_iter->copy(sln_prev_time); // Reducing time step to 50%. Hermes::Mixins::Loggable::Static::info("Reducing time step size from %g to %g days for the rest of this time step", time_step, time_step * time_step_inc); time_step *= time_step_dec; @@ -464,26 +463,26 @@ int main(int argc, char* argv[]) // Project the fine mesh solution on the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error calculation."); - if(space.get_mesh() == NULL) throw Hermes::Exceptions::Exception("it is NULL"); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + if(space->get_mesh() == NULL) throw Hermes::Exceptions::Exception("it is NULL"); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(&space); + Adapt* adaptivity = new Adapt(space); // Calculate error estimate wrt. fine mesh solution. - err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, space_err_est_rel: %g%%", - Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // If space_err_est too large, adapt the mesh-> if (err_est_rel < ERR_STOP) done = true; else { Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(&space) >= NDOF_STOP) { + if (Space::get_num_dofs(space) >= NDOF_STOP) { done = true; break; } @@ -491,14 +490,14 @@ int main(int argc, char* argv[]) } delete adaptivity; - delete ref_space; + } while (!done); // Add entries to graphs. graph_time_err_est.add_values(current_time, err_est_rel); graph_time_err_est.save("time_error_est.dat"); - graph_time_dof.add_values(current_time, Space::get_num_dofs(&space)); + graph_time_dof.add_values(current_time, Space::get_num_dofs(space)); graph_time_dof.save("time_dof.dat"); graph_time_cpu.add_values(current_time, cpu_time.accumulated()); graph_time_cpu.save("time_cpu.dat"); @@ -509,22 +508,20 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Solution, time %g days", current_time); view.set_title(title); - view.show(&sln); + view.show(sln); sprintf(title, "Mesh, time %g days", current_time); ordview.set_title(title); - ordview.show(&space); + ordview.show(space); // Save complete Solution. char* filename = new char[100]; sprintf(filename, "outputs/tsln_%f.dat", current_time); - sln.save(filename); + sln->save(filename); Hermes::Mixins::Loggable::Static::info("Solution at time %g saved to file %s.", current_time, filename); - // Copy new reference level solution into sln_prev_time. + // Copy new reference level solution into sln_prev_time // This starts new time step. - if(ts > 1) - delete sln_prev_time.get_mesh(); - sln_prev_time.copy(&ref_sln); + sln_prev_timecopy(ref_sln); // Updating time step. Note that time_step might have been reduced during adaptivity. current_time += time_step; diff --git a/2d-advanced/richards/capillary-barrier-rk/main.cpp b/2d-advanced/richards/capillary-barrier-rk/main.cpp index 768c7e7..b875b34 100644 --- a/2d-advanced/richards/capillary-barrier-rk/main.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/main.cpp @@ -197,12 +197,12 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load(mesh_file, &basemesh); + mloader.load(mesh_file, basemesh); // Perform initial mesh refinements. - mesh->copy(&basemesh); + mesh->copy(basemesh); for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); mesh->refine_towards_boundary("Top", INIT_REF_NUM_BDY_TOP); @@ -211,8 +211,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) view.fix_scale_width(80); // Visualize the initial condition. - view.show(&h_time_prev); + view.show(h_time_prev); // Initialize the weak formulation. CustomWeakFormRichardsRK wf(&constitutive_relations); @@ -231,19 +231,19 @@ int main(int argc, char* argv[]) // Visualize the projection and mesh-> ScalarView sview("Initial condition", new WinGeom(0, 0, 400, 350)); sview.fix_scale_width(50); - sview.show(&h_time_prev); + sview.show(h_time_prev); ScalarView eview("Temporal error", new WinGeom(405, 0, 400, 350)); eview.fix_scale_width(50); - eview.show(&time_error_fn); + eview.show(time_error_fn); OrderView oview("Initial mesh", new WinGeom(810, 0, 350, 350)); - oview.show(&space); + oview.show(space); // Graph for time step history. SimpleGraph time_step_graph; Hermes::Mixins::Loggable::Static::info("Time step history will be saved to file time_step_history.dat."); // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, &space, &bt); + RungeKutta runge_kutta(&wf, space, &bt); // Time stepping: double current_time = 0; @@ -252,7 +252,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f s", ts, current_time); - Space::update_essential_bc_values(&space, current_time); + Space::update_essential_bc_values(space, current_time); // Perform one Runge-Kutta time step according to the selected Butcher's table. Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step (t = %g s, time step = %g s, stages: %d).", @@ -261,8 +261,8 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL); runge_kutta.rk_time_step_newton(&h_time_prev, &h_time_new, &time_error_fn); } @@ -277,13 +277,13 @@ int main(int argc, char* argv[]) } // Copy solution for the new time step. - h_time_prev.copy(&h_time_new); + h_time_prev->copy(h_time_new); // Show error function. char title[100]; sprintf(title, "Temporal error, t = %g", current_time); eview.set_title(title); - eview.show(&time_error_fn); + eview.show(time_error_fn); // Calculate relative time stepping error and decide whether the // time step can be accepted. If not, then the time step size is @@ -314,8 +314,8 @@ int main(int argc, char* argv[]) // Show the new time level solution. sprintf(title, "Solution, t = %g", current_time); sview.set_title(title); - sview.show(&h_time_new); - oview.show(&space); + sview.show(h_time_new); + oview.show(space); // Save complete Solution. char filename[100]; @@ -324,7 +324,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solution at time %g saved to file %s.", current_time, filename); // Save solution for the next time step. - h_time_prev.copy(&h_time_new); + h_time_prev->copy(h_time_new); // Increase time step counter. ts++; diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h index 50908cb..cd993ab 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h @@ -11,7 +11,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomInitialCondition : public ExactSolutionScalar > { public: - CustomInitialCondition(const Mesh* mesh) : ExactSolutionScalar >(mesh) {}; + CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar >(mesh) {}; virtual void derivatives (double x, double y, std::complex & dx, std::complex & dy) const; diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp index f4e8e6f..6bcd99e 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp @@ -138,10 +138,10 @@ int main(int argc, char* argv[]) } // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load("square.mesh", &basemesh); - mesh->copy(&basemesh); + mloader.load("square.mesh", basemesh); + mesh->copy(basemesh); // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); @@ -160,12 +160,12 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. - DiscreteProblem > dp(&wf, &space); + DiscreteProblem > dp(&wf, space); // Create a refinement selector. H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -189,9 +189,9 @@ int main(int argc, char* argv[]) space_error_view.fix_scale_width(50); RealFilter real(&psi_time_prev); ImagFilter imag(&psi_time_prev); - sview_real.show(&real); - sview_imag.show(&imag); - ord_view.show(&space); + sview_real.show(real); + sview_imag.show(imag); + ord_view.show(space); // Graph for time step history. SimpleGraph time_step_graph; @@ -210,19 +210,19 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; - case 2: space.unrefine_all_mesh_elements(); - space.set_uniform_order(P_INIT); + case 2: space->unrefine_all_mesh_elements(); + space->set_uniform_order(P_INIT); break; - case 3: space.unrefine_all_mesh_elements(); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + case 3: space->unrefine_all_mesh_elements(); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - ndof = Space >::get_num_dofs(&space); + ndof = Space >::get_num_dofs(space); } Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -235,12 +235,12 @@ int main(int argc, char* argv[]) bool done = false; int as = 1; double err_est; do { - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space >* ref_space = refSpaceCreator.create_ref_space(); + Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); // Initialize discrete problem on reference mesh-> DiscreteProblem >* ref_dp = new DiscreteProblem >(&wf, ref_space); @@ -256,9 +256,9 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.set_newton_max_iter(NEWTON_MAX_ITER); - runge_kutta.set_newton_tol(NEWTON_TOL_FINE); - runge_kutta.rk_time_step_newton(&psi_time_prev, &ref_sln, time_error_fn); + runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); + runge_kutta.set_tolerance(NEWTON_TOL_FINE); + runge_kutta.rk_time_step_newton(&psi_time_prev, ref_sln, time_error_fn); } catch(Exceptions::Exception& e) { @@ -280,10 +280,10 @@ int main(int argc, char* argv[]) time_error_view.show_mesh(false); RealFilter abs_time(time_error_fn); AbsFilter abs_tef(&abs_time); - time_error_view.show(&abs_tef); + time_error_view.show(abs_tef); rel_err_time = Global >::calc_norm(time_error_fn, HERMES_H1_NORM) / - Global >::calc_norm(&ref_sln, HERMES_H1_NORM) * 100; + Global >::calc_norm(ref_sln, HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } @@ -293,7 +293,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Decreasing time step from %g to %g s and restarting time step.", time_step, time_step * TIME_STEP_DEC_RATIO); time_step *= TIME_STEP_DEC_RATIO; - delete ref_space; + delete ref_dp; continue; } @@ -301,7 +301,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%% is below lower limit %g%%", rel_err_time, TIME_ERR_TOL_LOWER); Hermes::Mixins::Loggable::Static::info("Increasing time step from %g to %g s.", time_step, time_step * TIME_STEP_INC_RATIO); time_step *= TIME_STEP_INC_RATIO; - delete ref_space; + delete ref_dp; continue; } @@ -322,25 +322,25 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse mesh-> Solution > sln; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - OGProjection > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); - DiffFilter >* space_error_fn = new DiffFilter >(Hermes::vector >*>(&ref_sln, &sln)); + DiffFilter >* space_error_fn = new DiffFilter >(Hermes::vector >*>(ref_sln, sln)); space_error_view.set_title(title); space_error_view.show_mesh(false); RealFilter abs_space(space_error_fn); AbsFilter abs_sef(&abs_space); - space_error_view.show(&abs_sef); + space_error_view.show(abs_sef); // Calculate element errors and spatial error estimate. Hermes::Mixins::Loggable::Static::info("Calculating spatial error estimate."); - Adapt >* adaptivity = new Adapt >(&space); - double err_rel_space = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + Adapt >* adaptivity = new Adapt >(space); + double err_rel_space = adaptivity->calc_err_est(sln, ref_sln) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", - Space >::get_num_dofs(&space), Space >::get_num_dofs(ref_space), err_rel_space); + Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; @@ -349,7 +349,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space >::get_num_dofs(&space) >= NDOF_STOP) + if (Space >::get_num_dofs(space) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -361,7 +361,7 @@ int main(int argc, char* argv[]) if(!done) { delete ref_space->get_mesh(); - delete ref_space; + } delete ref_dp; delete space_error_fn; @@ -377,16 +377,16 @@ int main(int argc, char* argv[]) sview_real.set_title(title); sprintf(title, "Solution - imaginary part, Time %3.2f s", current_time); sview_imag.set_title(title); - RealFilter real(&ref_sln); - ImagFilter imag(&ref_sln); - sview_real.show(&real); - sview_imag.show(&imag); + RealFilter real(ref_sln); + ImagFilter imag(ref_sln); + sview_real.show(real); + sview_imag.show(imag); sprintf(title, "Mesh, time %g s", current_time); ord_view.set_title(title); - ord_view.show(&space); + ord_view.show(space); // Copy last reference solution into psi_time_prev. - psi_time_prev.copy(&ref_sln); + psi_time_prev->copy(ref_sln); // Increase current time and counter of time steps. current_time += time_step; diff --git a/2d-advanced/schroedinger/gross-pitaevski/definitions.h b/2d-advanced/schroedinger/gross-pitaevski/definitions.h index be5d912..cac8a82 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski/definitions.h @@ -13,7 +13,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomInitialCondition : public ExactSolutionScalar > { public: - CustomInitialCondition(const Mesh* mesh) : ExactSolutionScalar >(mesh) {}; + CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar >(mesh) {}; virtual void derivatives (double x, double y, std::complex & dx, std::complex & dy) const; diff --git a/2d-advanced/schroedinger/gross-pitaevski/main.cpp b/2d-advanced/schroedinger/gross-pitaevski/main.cpp index 8d91348..85d9927 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/main.cpp @@ -91,12 +91,12 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space > space(mesh, &bcs, P_INIT); - int ndof = space.get_num_dofs(); + SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. - DiscreteProblem > dp(&wf, &space); + DiscreteProblem > dp(&wf, space); // Initialize views. ScalarView sview_real("Solution - real part", new WinGeom(0, 0, 600, 500)); @@ -105,7 +105,7 @@ int main(int argc, char* argv[]) sview_imag.fix_scale_width(80); // Initialize Runge-Kutta time stepping. - RungeKutta > runge_kutta(&wf, &space, &bt); + RungeKutta > runge_kutta(&wf, space, &bt); // Time stepping: int ts = 1; @@ -136,11 +136,11 @@ int main(int argc, char* argv[]) sview_imag.set_title(title); RealFilter real(&psi_time_new); ImagFilter imag(&psi_time_new); - sview_real.show(&real); - sview_imag.show(&imag); + sview_real.show(real); + sview_imag.show(imag); // Copy solution for the new time step. - psi_time_prev.copy(&psi_time_new); + psi_time_prev->copy(psi_time_new); // Increase current time and time step counter. current_time += time_step; diff --git a/2d-advanced/wave-equation/wave-1/definitions.cpp b/2d-advanced/wave-equation/wave-1/definitions.cpp index 2ae8cb4..d1a5801 100644 --- a/2d-advanced/wave-equation/wave-1/definitions.cpp +++ b/2d-advanced/wave-equation/wave-1/definitions.cpp @@ -21,8 +21,8 @@ MeshFunction* CustomInitialConditionWave::clone() const return new CustomInitialConditionWave(this->mesh); } -CustomWeakFormWave::CustomWeakFormWave(double tau, double c_squared, Solution* u_prev_sln, - Solution* v_prev_sln) : WeakForm(2) +CustomWeakFormWave::CustomWeakFormWave(double tau, double c_squared, MeshFunctionSharedPtr u_prev_sln, + MeshFunctionSharedPtr v_prev_sln) : WeakForm(2) { // Volumetric matrix forms. add_matrix_form(new WeakFormsH1::DefaultMatrixFormVol(0, 1, HERMES_ANY, new Hermes2DFunction(1.0), HERMES_NONSYM)); diff --git a/2d-advanced/wave-equation/wave-1/definitions.h b/2d-advanced/wave-equation/wave-1/definitions.h index a90e58d..7989e75 100644 --- a/2d-advanced/wave-equation/wave-1/definitions.h +++ b/2d-advanced/wave-equation/wave-1/definitions.h @@ -12,7 +12,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomInitialConditionWave : public ExactSolutionScalar { public: - CustomInitialConditionWave(const Mesh* mesh) : ExactSolutionScalar(mesh) {}; + CustomInitialConditionWave(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) {}; virtual double value (double x, double y) const; @@ -29,7 +29,7 @@ class CustomWeakFormWave : public WeakForm { public: - CustomWeakFormWave(double tau, double c_squared, Solution* u_prev_sln, Solution* v_prev_sln); + CustomWeakFormWave(double tau, double c_squared, MeshFunctionSharedPtr u_prev_sln, MeshFunctionSharedPtr v_prev_sln); private: class VectorFormVolWave_0 : public VectorFormVol diff --git a/2d-advanced/wave-equation/wave-1/main.cpp b/2d-advanced/wave-equation/wave-1/main.cpp index 27136df..aaa59ba 100644 --- a/2d-advanced/wave-equation/wave-1/main.cpp +++ b/2d-advanced/wave-equation/wave-1/main.cpp @@ -77,19 +77,19 @@ int main(int argc, char* argv[]) // Initialize solutions. CustomInitialConditionWave u_sln(mesh); ZeroSolution v_sln(mesh); - Hermes::vector*> slns(&u_sln, &v_sln); + Hermes::vector > slns(u_sln, v_sln); // Initialize the weak formulation. - CustomWeakFormWave wf(time_step, C_SQUARED, &u_sln, &v_sln); + CustomWeakFormWave wf(time_step, C_SQUARED, u_sln, v_sln); // Initialize boundary conditions DefaultEssentialBCConst bc_essential("Bdy", 0.0); EssentialBCs bcs(&bc_essential); // Create x- and y- displacement space using the default H1 shapeset. - H1Space u_space(mesh, &bcs, P_INIT); - H1Space v_space(mesh, &bcs, P_INIT); - Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector*>(&u_space, &v_space))); + H1Space u_space(mesh, &bcs, P_INIT)); + H1Space v_space(mesh, &bcs, P_INIT)); + Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u_space, v_space))); // Initialize views. ScalarView u_view("Solution u", new WinGeom(0, 0, 500, 400)); @@ -100,7 +100,7 @@ int main(int argc, char* argv[]) v_view.fix_scale_width(50); // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, Hermes::vector*>(&u_space, &v_space), &bt); + RungeKutta runge_kutta(&wf, Hermes::vector >(u_space, v_space), &bt); // Time stepping loop. double current_time = 0; int ts = 1; @@ -128,10 +128,10 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Solution u, t = %g", current_time); u_view.set_title(title); - u_view.show(&u_sln); + u_view.show(u_sln); sprintf(title, "Solution v, t = %g", current_time); v_view.set_title(title); - v_view.show(&v_sln); + v_view.show(v_sln); // Update time. current_time += time_step; diff --git a/2d-benchmarks-general/layer-boundary/definitions.cpp b/2d-benchmarks-general/layer-boundary/definitions.cpp index e083dd5..e529c17 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.cpp +++ b/2d-benchmarks-general/layer-boundary/definitions.cpp @@ -15,7 +15,7 @@ double CustomExactFunction::dduhat_dxx(double x) return -K*K * (exp(K*x) + exp(-K*x)) / (exp(K) + exp(-K)); } -CustomExactSolution::CustomExactSolution(const Mesh* mesh, double K) : ExactSolutionScalar(mesh) +CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh,double K) : ExactSolutionScalar(mesh) { cef = new CustomExactFunction(K); } diff --git a/2d-benchmarks-general/layer-boundary/definitions.h b/2d-benchmarks-general/layer-boundary/definitions.h index 8dcc1a6..a230b30 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.h +++ b/2d-benchmarks-general/layer-boundary/definitions.h @@ -25,7 +25,7 @@ class CustomExactFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh, double K); + CustomExactSolution(MeshSharedPtr mesh, double K); virtual double value (double x, double y) const; diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index 3e883f1..972dede 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -89,10 +89,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -115,12 +115,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -145,27 +145,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -173,15 +173,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -199,11 +199,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); // Increase the counter of adaptivity steps. - if (done == false) as++; - - if(done == false) - delete ref_space->get_mesh(); - delete ref_space; + as++; } while (done == false); diff --git a/2d-benchmarks-general/layer-interior/definitions.h b/2d-benchmarks-general/layer-interior/definitions.h index b907918..94b5b08 100644 --- a/2d-benchmarks-general/layer-interior/definitions.h +++ b/2d-benchmarks-general/layer-interior/definitions.h @@ -10,7 +10,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double slope) + CustomExactSolution(MeshSharedPtr mesh, double slope) : ExactSolutionScalar(mesh), slope(slope) {}; virtual double value (double x, double y) const; diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index 07b63d8..733c096 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -92,10 +92,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -119,12 +119,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -149,27 +149,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -177,15 +177,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -194,7 +194,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -208,7 +208,7 @@ int main(int argc, char* argv[]) if(done == false) delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index 542138d..e9c038c 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -81,10 +81,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -107,12 +107,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -137,27 +137,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -165,15 +165,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -182,7 +182,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) if(done == false) delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-general/moving-front-space-adapt/definitions.h b/2d-benchmarks-general/moving-front-space-adapt/definitions.h index ee42284..f8be419 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/definitions.h +++ b/2d-benchmarks-general/moving-front-space-adapt/definitions.h @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double x0, double x1, double y0, double y1, + CustomExactSolution(MeshSharedPtr mesh, double x0, double x1, double y0, double y1, double* t_ptr, double s, double c) : ExactSolutionScalar(mesh), x0(x0), x1(x1), y0(y0), y1(y1), t_ptr(t_ptr), s(s), c(c) {}; diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index 03ff037..7e2da51 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -116,13 +116,13 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh mesh, basemesh; + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; - mloader.load("domain.mesh", &basemesh); + mloader.load("domain.mesh", basemesh); // Perform initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) basemesh->refine_all_elements(0, true); - mesh->copy(&basemesh); + mesh->copy(basemesh); // Exact solution. CustomExactSolution exact_sln(mesh, x_0, x_1, y_0, y_1, ¤t_time, s, c); @@ -132,8 +132,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); - int ndof_coarse = space.get_num_dofs(); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + int ndof_coarse = space->get_num_dofs(); // Initialize the weak formulation CustomFunction f(x_0, x_1, y_0, y_1, s, c); @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) // Previous and next time level solution. ZeroSolution sln_time_prev(mesh); - Solution sln_time_new(mesh); + MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -150,8 +150,8 @@ int main(int argc, char* argv[]) char title[100]; Views::ScalarView sview("Initial condition", new Views::WinGeom(0, 0, 440, 350)); Views::OrderView oview("Initial mesh", new Views::WinGeom(445, 0, 410, 350)); - sview.show(&sln_time_prev); - oview.show(&space); + sview.show(sln_time_prev); + oview.show(space); // Graph for dof history. SimpleGraph dof_history_graph; @@ -165,19 +165,19 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(&basemesh); - space.set_uniform_order(P_INIT); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); break; case 2: mesh->unrefine_all_elements(); - space.set_uniform_order(P_INIT); + space->set_uniform_order(P_INIT); break; case 3: mesh->unrefine_all_elements(); - space.adjust_element_order(-1, -1, P_INIT, P_INIT); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; } - space.assign_dofs(); - ndof_coarse = space.get_num_dofs(); + space->assign_dofs(); + ndof_coarse = space->get_num_dofs(); } // Spatial adaptivity loop. Note: sln_time_prev must not be changed @@ -187,12 +187,12 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); // Initialize Runge-Kutta time stepping. @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.rk_time_step_newton(&sln_time_prev, &sln_time_new); + runge_kutta.rk_time_step_newton(sln_time_prev, sln_time_new); } catch(Exceptions::Exception& e) { @@ -220,16 +220,16 @@ int main(int argc, char* argv[]) Solution sln_coarse; Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; - ogProjection.project_global(&space, &sln_time_new, &sln_coarse); + ogProjection.project_global(space, sln_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(&space); - double err_est_rel_total = adaptivity->calc_err_est(&sln_coarse, &sln_time_new) * 100; + Adapt* adaptivity = new Adapt(space); + double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, sln_time_new) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", - space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); + space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; @@ -238,7 +238,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (space.get_num_dofs() >= NDOF_STOP) + if (space->get_num_dofs() >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -249,7 +249,7 @@ int main(int argc, char* argv[]) delete adaptivity; if(!done) { - delete ref_space; + delete sln_time_new.get_mesh(); } } @@ -260,16 +260,16 @@ int main(int argc, char* argv[]) sprintf(title, "Solution, time %g", current_time); sview.set_title(title); sview.show_mesh(false); - sview.show(&sln_time_new); + sview.show(sln_time_new); sprintf(title, "Mesh, time %g", current_time); oview.set_title(title); - oview.show(&space); + oview.show(space); // Copy last reference solution into sln_time_prev. - sln_time_prev.copy(&sln_time_new); + sln_time_prev.copy(sln_time_new); // Add entry to DOF convergence graph. - dof_history_graph.add_values(current_time, space.get_num_dofs()); + dof_history_graph.add_values(current_time, space->get_num_dofs()); dof_history_graph.save("dof_history.dat"); // Increase current time and counter of time steps. diff --git a/2d-benchmarks-general/nonsym-check/definitions.cpp b/2d-benchmarks-general/nonsym-check/definitions.cpp index f978ac7..855a8e2 100644 --- a/2d-benchmarks-general/nonsym-check/definitions.cpp +++ b/2d-benchmarks-general/nonsym-check/definitions.cpp @@ -16,7 +16,7 @@ Ord CustomExactSolution::ord(Ord x, Ord y) const return Ord(20); } -MeshFunction* CustomExactSolution::clone() const +MeshFunction* CustomExactSolution::clone() const { return new CustomExactSolution(*this); } @@ -37,7 +37,7 @@ Ord CustomJacobian::ord(int n, double *wt, Func *u_ext[], Func *u, Fun return Ord(20); } -MatrixFormVol* CustomJacobian::clone() const +MatrixFormVol* CustomJacobian::clone() const { return new CustomJacobian(*this); } @@ -57,7 +57,7 @@ Ord CustomResidual::ord(int n, double *wt, Func *u_ext[], Func *v, return Ord(20); } -VectorFormVol* CustomResidual::clone() const +VectorFormVol* CustomResidual::clone() const { return new CustomResidual(*this); } diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index 6169c35..4a54174 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -75,10 +75,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -102,12 +102,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -132,27 +132,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -160,15 +160,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) if(done == false) delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-general/smooth-aniso-x/definitions.h b/2d-benchmarks-general/smooth-aniso-x/definitions.h index 4237e16..129ff11 100644 --- a/2d-benchmarks-general/smooth-aniso-x/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-x/definitions.h @@ -10,7 +10,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh) : ExactSolutionScalar(mesh) + CustomExactSolution(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { } diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 8b73518..9c73c16 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -74,10 +74,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -100,12 +100,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -119,7 +119,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -130,27 +130,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -158,15 +158,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -175,7 +175,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-general/smooth-aniso-y/definitions.h b/2d-benchmarks-general/smooth-aniso-y/definitions.h index e07560c..101cb3a 100644 --- a/2d-benchmarks-general/smooth-aniso-y/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-y/definitions.h @@ -10,7 +10,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh) : ExactSolutionScalar(mesh) + CustomExactSolution(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { } diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index b5949e9..93a2693 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -74,10 +74,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -100,12 +100,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -119,7 +119,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -130,27 +130,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -158,15 +158,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -175,7 +175,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index 3a4c22c..e9a8d5f 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -84,10 +84,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -110,12 +110,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -141,27 +141,27 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -169,15 +169,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -199,7 +199,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.h b/2d-benchmarks-nist/01-analytic-solution/definitions.h index b8b862a..1d89cce 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.h +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.h @@ -24,7 +24,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double poly_deg) + CustomExactSolution(MeshSharedPtr mesh, double poly_deg) : ExactSolutionScalar(mesh), poly_deg(poly_deg) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index f95e1f1..e2c9a91 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -91,10 +91,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -117,12 +117,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -148,27 +148,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -176,15 +176,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -193,7 +193,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/02-reentrant-corner/definitions.h b/2d-benchmarks-nist/02-reentrant-corner/definitions.h index 7fa1f7e..aca029c 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/definitions.h +++ b/2d-benchmarks-nist/02-reentrant-corner/definitions.h @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D::Views; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha) + CustomExactSolution(MeshSharedPtr mesh, double alpha) : ExactSolutionScalar(mesh), alpha(alpha) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 4af2fa8..463e298 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -115,10 +115,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -141,12 +141,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -160,7 +160,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -172,27 +172,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -200,15 +200,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -217,7 +217,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -230,7 +230,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/03-linear-elasticity/definitions.h b/2d-benchmarks-nist/03-linear-elasticity/definitions.h index 94329ab..be6a70c 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/definitions.h +++ b/2d-benchmarks-nist/03-linear-elasticity/definitions.h @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D::Views; class CustomExactSolutionU : public ExactSolutionScalar { public: - CustomExactSolutionU(const Mesh* mesh, double E, double nu, double lambda, double Q) + CustomExactSolutionU(MeshSharedPtr mesh, double E, double nu, double lambda, double Q) : ExactSolutionScalar(mesh), E(E), nu(nu), lambda(lambda), Q(Q) {}; double get_angle(double y, double x) const; @@ -91,7 +91,7 @@ class CustomExactSolutionU : public ExactSolutionScalar class CustomExactSolutionV : public ExactSolutionScalar { public: - CustomExactSolutionV(const Mesh* mesh, double E, double nu, double lambda, double Q) + CustomExactSolutionV(MeshSharedPtr mesh, double E, double nu, double lambda, double Q) : ExactSolutionScalar(mesh), E(E), nu(nu), lambda(lambda), Q(Q) {}; double get_angle(double y, double x) const; diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index ef50d63..0d90bec 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -106,12 +106,12 @@ const double nu = 0.3; int main(int argc, char* argv[]) { // Load the mesh-> - Mesh u_mesh, v_mesh; + MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh); MeshReaderH2D mloader; - mloader.load("elasticity.mesh", &u_mesh); + mloader.load("elasticity.mesh", u_mesh); // Create initial mesh (master mesh). - v_mesh->copy(&u_mesh); + v_mesh->copy(u_mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) { @@ -120,8 +120,8 @@ int main(int argc, char* argv[]) } // Set exact solution for each displacement component. - CustomExactSolutionU exact_u(&u_mesh, E, nu, lambda, Q); - CustomExactSolutionV exact_v(&v_mesh, E, nu, lambda, Q); + CustomExactSolutionU exact_u(u_mesh, E, nu, lambda, Q); + CustomExactSolutionV exact_v(v_mesh, E, nu, lambda, Q); // Initialize the weak formulation. // NOTE: We pass all four parameters (temporarily) @@ -130,14 +130,14 @@ int main(int argc, char* argv[]) CustomWeakFormElasticityNIST wf(E, nu, mu, lambda); // Initialize boundary conditions. - DefaultEssentialBCNonConst bc_u("Bdy", &exact_u); + DefaultEssentialBCNonConst bc_u("Bdy", exact_u); EssentialBCs bcs_u(&bc_u); - DefaultEssentialBCNonConst bc_v("Bdy", &exact_v); + DefaultEssentialBCNonConst bc_v("Bdy", exact_v); EssentialBCs bcs_v(&bc_v); // Create H1 spaces with default shapeset for both displacement components. - H1Space u_space(&u_mesh, &bcs_u, P_INIT_U); - H1Space v_space(&v_mesh, &bcs_v, P_INIT_V); +SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); + H1Space v_space(v_mesh, &bcs_v, P_INIT_V); // Initialize approximate solution. Solution u_sln, v_sln; @@ -167,23 +167,23 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. - Mesh::ReferenceMeshCreator refMeshCreatorU(&u_mesh); - Mesh* ref_u_mesh = refMeshCreatorU.create_ref_mesh(); + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreatorU(u_mesh); + MeshSharedPtr ref_u_mesh = refMeshCreatorU.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorU(&u_space, ref_u_mesh); - Space* ref_u_space = refSpaceCreatorU.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorU(u_space, ref_u_mesh); + SpaceSharedPtr ref_u_space = refSpaceCreatorU.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreatorV(&u_mesh); - Mesh* ref_v_mesh = refMeshCreatorV.create_ref_mesh(); + Mesh::ReferenceMeshCreator refMeshCreatorV(u_mesh); + MeshSharedPtr ref_v_mesh = refMeshCreatorV.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorV(&v_space, ref_v_mesh); - Space* ref_v_space = refSpaceCreatorV.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorV(v_space, ref_v_mesh); + SpaceSharedPtr ref_v_space = refSpaceCreatorV.create_ref_space(); - Hermes::vector*> ref_spaces(ref_u_space, ref_v_space); - Hermes::vector*> ref_spaces_const(ref_u_space, ref_v_space); + Hermes::vector > ref_spaces(ref_u_space, ref_v_space); + Hermes::vector > ref_spaces(ref_u_space, ref_v_space); - int ndof_ref = Space::get_num_dofs(ref_spaces_const); + int ndof_ref = Space::get_num_dofs(ref_spaces); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); @@ -191,11 +191,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); //newton.set_verbose_output(false); - newton.set_newton_tol(NEWTON_TOLERANCE); + newton.set_tolerance(NEWTON_TOLERANCE); Solution u_ref_sln, v_ref_sln; try @@ -209,28 +209,28 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces_const, Hermes::vector*>(&u_ref_sln, &v_ref_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u_ref_sln, v_ref_sln)); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector*>(&u_space, &v_space), - Hermes::vector*>(&u_ref_sln, &v_ref_sln), - Hermes::vector*>(&u_sln, &v_sln)); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u_space, v_space), + Hermes::vector >(u_ref_sln, v_ref_sln), + Hermes::vector >(u_sln, v_sln)); // Calculate element errors and total error estimate. Hermes::vector err_est_rel; - Adapt* adaptivity = new Adapt(Hermes::vector*>(&u_space, &v_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&u_sln, &v_sln), - Hermes::vector*>(&u_ref_sln, &v_ref_sln), &err_est_rel) * 100.; + Adapt* adaptivity = new Adapt(Hermes::vector >(u_space, v_space)); + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u_sln, v_sln), + Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100.; // Calculate exact error for each solution component and the total exact error. Hermes::vector err_exact_rel; bool solutions_for_adapt = false; - double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector*>(&u_sln, &v_sln), - Hermes::vector*>(&exact_u, &exact_v), + double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector >(u_sln, v_sln), + Hermes::vector >(exact_u, exact_v), &err_exact_rel, solutions_for_adapt) * 100.; cpu_time.tick(); @@ -238,13 +238,13 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[u]: %d, ndof_fine[u]: %d", - u_space.Space::get_num_dofs(), Space::get_num_dofs(ref_u_space)); + u_space->Space::get_num_dofs(), Space::get_num_dofs(ref_u_space)); Hermes::Mixins::Loggable::Static::info("err_est_rel[u]: %g%%, err_exact_rel[u]: %g%%", err_est_rel[0]*100, err_exact_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[v]: %d, ndof_fine[v]: %d", - v_space.Space::get_num_dofs(), Space::get_num_dofs(ref_v_space)); + v_space->Space::get_num_dofs(), Space::get_num_dofs(ref_v_space)); Hermes::Mixins::Loggable::Static::info("err_est_rel[v]: %g%%, err_exact_rel[v]: %g%%", err_est_rel[1]*100, err_exact_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", - Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), Space::get_num_dofs(ref_spaces_const)); + Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(ref_spaces)); Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%, err_est_exact_total: %g%%", err_est_rel_total, err_exact_rel_total); // Time measurement. @@ -252,19 +252,19 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - s_view_u.show(&u_sln); - o_view_u.show(&u_space); - s_view_v.show(&v_sln); - o_view_v.show(&v_space); - VonMisesFilter stress(Hermes::vector *>(&u_sln, &v_sln), lambda, mu); - mises_view.show(&stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, &u_sln, &v_sln, 0.03); + s_view_u.show(u_sln); + o_view_u.show(u_space); + s_view_v.show(v_sln); + o_view_v.show(v_space); + VonMisesFilter stress(Hermes::vector >(u_sln, v_sln), lambda, mu); + mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u_sln, v_sln, 0.03); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), err_est_rel_total); + graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u_space, v_space)), err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)), err_exact_rel_total); + graph_dof_exact.add_values(Space::get_num_dofs(Hermes::vector >(u_space, v_space)), err_exact_rel_total); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(cpu_time.accumulated(), err_exact_rel_total); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -280,7 +280,7 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); } - if (Space::get_num_dofs(Hermes::vector *>(&u_space, &v_space)) >= NDOF_STOP) done = true; + if (Space::get_num_dofs(Hermes::vector >(u_space, v_space)) >= NDOF_STOP) done = true; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.h b/2d-benchmarks-nist/04-exponential-peak/definitions.h index 98e3dfb..7a47879 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.h +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.h @@ -26,7 +26,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha, double x_loc, double y_loc) + CustomExactSolution(MeshSharedPtr mesh, double alpha, double x_loc, double y_loc) : ExactSolutionScalar(mesh), alpha(alpha), x_loc(x_loc), y_loc(y_loc) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 967a16a..eb037d9 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -93,10 +93,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -119,12 +119,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -150,27 +150,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -178,15 +178,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -195,7 +195,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -208,7 +208,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index eb347bd..2770075 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -74,14 +74,14 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Create an H1 space with default shapeset. - H1Space space(mesh, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, P_INIT)); // Initialize weak formulation. CustomWeakFormPoisson wf("e1", "e2", "e3", "e4", "e5", "Bdy_left", "Bdy_top", "Bdy_right", "Bdy_bottom", mesh); // Initialize coarse and fine mesh solution. - Solution sln, ref_sln; + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -107,12 +107,12 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // Construct globally refined mesh and setup fine mesh space. + // Construct globally refined mesh and setup fine mesh space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. @@ -134,11 +134,11 @@ int main(int argc, char* argv[]) } // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); @@ -150,21 +150,21 @@ int main(int argc, char* argv[]) Views::Linearizer lin; char* title = new char[100]; sprintf(title, "sln-%d.vtk", as); - lin.save_solution_vtk(&sln, title, "Potential", false); + lin.save_solution_vtk(sln, title, "Potential", false); Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", title); // Output mesh and element orders in VTK format. Views::Orderizer ord; sprintf(title, "ord-%d.vtk", as); - ord.save_orders_vtk(&space, title); + ord.save_orders_vtk(space, title); Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", title); } // View the coarse mesh solution and polynomial orders. if (HERMES_VISUALIZATION) { - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); } // Skip visualization time. @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(&space); + Adapt adaptivity(space); bool solutions_for_adapt = true; // In the following function, the Boolean parameter "solutions_for_adapt" determines whether // the calculated errors are intended for use with adaptivity (this may not be the case, for example, @@ -181,18 +181,18 @@ int main(int argc, char* argv[]) // absolute or relative. Its default value is error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL. // In subsequent examples and benchmarks, these two parameters will be often used with // their default values, and thus they will not be present in the code explicitly. - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln, solutions_for_adapt, + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - space.get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); + space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); // Add entry to DOF and CPU convergence graphs. cpu_time.tick(); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - graph_dof.add_values(space.get_num_dofs(), err_est_rel); + graph_dof.add_values(space->get_num_dofs(), err_est_rel); graph_dof.save("conv_dof_est.dat"); // Skip the time spent to save the convergence graphs. @@ -210,14 +210,14 @@ int main(int argc, char* argv[]) if (done == false) as++; } - if (space.get_num_dofs() >= NDOF_STOP) + if (space->get_num_dofs() >= NDOF_STOP) done = true; // Keep the mesh from final step to allow further work with the final fine mesh solution. if(done == false) { delete ref_space->get_mesh(); - delete ref_space; + } } while (done == false); @@ -227,7 +227,7 @@ int main(int argc, char* argv[]) // Show the fine mesh solution - final result. sview.set_title("Fine mesh solution"); sview.show_mesh(false); - sview.show(&ref_sln); + sview.show(ref_sln); // Wait for all views to be closed. Views::View::wait(); diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index fa5b709..374dfc0 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -24,7 +24,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double epsilon) + CustomExactSolution(MeshSharedPtr mesh, double epsilon) : ExactSolutionScalar(mesh), epsilon(epsilon) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 97ae4bf..5509d4f 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -87,10 +87,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -113,12 +113,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -144,27 +144,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -172,15 +172,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -189,7 +189,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -202,7 +202,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h index 864f4a2..aeac608 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h +++ b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h @@ -24,7 +24,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha) + CustomExactSolution(MeshSharedPtr mesh, double alpha) : ExactSolutionScalar(mesh), alpha(alpha) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 63c76f2..2e7e888 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -91,10 +91,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -117,12 +117,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -148,27 +148,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -176,15 +176,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -193,7 +193,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.h b/2d-benchmarks-nist/08-oscillatory/definitions.h index abb81d2..72bf196 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.h +++ b/2d-benchmarks-nist/08-oscillatory/definitions.h @@ -24,7 +24,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha) + CustomExactSolution(MeshSharedPtr mesh, double alpha) : ExactSolutionScalar(mesh), alpha(alpha) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 48ff30a..f7f8099 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -87,10 +87,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -113,12 +113,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -144,27 +144,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -172,15 +172,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -189,7 +189,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -202,7 +202,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h index bffe8e6..f1fb5c7 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h @@ -62,7 +62,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh, double alpha, double x_loc, double y_loc, double r_zero) + CustomExactSolution(MeshSharedPtr mesh, double alpha, double x_loc, double y_loc, double r_zero) : ExactSolutionScalar(mesh), alpha(alpha), x_loc(x_loc), y_loc(y_loc), r_zero(r_zero) { }; diff --git a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h index 36c51b9..3aa5e8c 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h @@ -61,7 +61,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(const Mesh* mesh, double alpha, double x_loc, double y_loc, double r_zero) + CustomExactSolution(MeshSharedPtr mesh, double alpha, double x_loc, double y_loc, double r_zero) : ExactSolutionScalar(mesh), alpha(alpha), x_loc(x_loc), y_loc(y_loc), r_zero(r_zero) { }; diff --git a/2d-benchmarks-nist/09-wave-front/definitions.h b/2d-benchmarks-nist/09-wave-front/definitions.h index 6ee09dc..7fd5052 100644 --- a/2d-benchmarks-nist/09-wave-front/definitions.h +++ b/2d-benchmarks-nist/09-wave-front/definitions.h @@ -62,7 +62,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha, double x_loc, double y_loc, double r_zero) + CustomExactSolution(MeshSharedPtr mesh, double alpha, double x_loc, double y_loc, double r_zero) : ExactSolutionScalar(mesh), alpha(alpha), x_loc(x_loc), y_loc(y_loc), r_zero(r_zero) { }; diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index d5ddd7e..f80bf52 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -136,10 +136,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -162,12 +162,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -181,7 +181,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -193,27 +193,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -221,15 +221,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -238,7 +238,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -251,7 +251,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp b/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp index 15abd8a..65752cb 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp @@ -29,7 +29,7 @@ Ord CustomRightHandSide::value(Ord x, Ord y) const return Ord(16); } -CustomExactSolution::CustomExactSolution(Mesh* mesh, double k, double alpha) : ExactSolutionScalar(mesh), k(k), alpha(alpha) +CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh, double k, double alpha) : ExactSolutionScalar(mesh), k(k), alpha(alpha) { cef = new CustomExactFunction(k, alpha); } diff --git a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h index f68f246..16dbda7 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h +++ b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h @@ -39,7 +39,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double k, double alpha); + CustomExactSolution(MeshSharedPtr mesh, double k, double alpha); virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 577ec60..c66fc8b 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -90,10 +90,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -116,12 +116,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -147,27 +147,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -175,15 +175,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -192,7 +192,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -205,7 +205,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/11-kellogg/definitions.h b/2d-benchmarks-nist/11-kellogg/definitions.h index 2251a26..729bafb 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.h +++ b/2d-benchmarks-nist/11-kellogg/definitions.h @@ -9,7 +9,7 @@ using namespace Hermes::Hermes2D::Views; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double sigma, double tau, double rho) + CustomExactSolution(MeshSharedPtr mesh, double sigma, double tau, double rho) : ExactSolutionScalar(mesh), sigma(sigma), tau(tau), rho(rho) {}; virtual double value(double x, double y) const; diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index 01b9e86..4bba8ec 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -90,10 +90,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -116,12 +116,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -147,27 +147,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -175,15 +175,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -192,7 +192,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -205,7 +205,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h index 933bd2b..bd0beb3 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h +++ b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h @@ -34,7 +34,7 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh, double alpha_w, double alpha_p, double x_w, double y_w, + CustomExactSolution(MeshSharedPtr mesh, double alpha_w, double alpha_p, double x_w, double y_w, double r_0, double omega_c, double epsilon, double x_p, double y_p) : ExactSolutionScalar(mesh), alpha_w(alpha_w), alpha_p(alpha_p), x_w(x_w), y_w(y_w), r_0(r_0), omega_c(omega_c), epsilon(epsilon), x_p(x_p), y_p(y_p) {}; diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 9bb3362..c551b2f 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -94,10 +94,10 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - H1Space space(mesh, &bcs, P_INIT); + SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - Solution sln; + MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -120,12 +120,12 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); - Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); - Space* ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); @@ -139,7 +139,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - Solution ref_sln; + MeshFunctionSharedPtr ref_sln(new Solution()); try { newton.solve(); @@ -151,27 +151,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(&space, &ref_sln, &sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(&space); - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln) * 100; + Adapt adaptivity(space); + double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(&sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space.get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); // Time measurement. @@ -179,15 +179,15 @@ int main(int argc, char* argv[]) double accum_time = cpu_time.accumulated(); // View the coarse mesh solution and polynomial orders. - sview.show(&sln); - oview.show(&space); + sview.show(sln); + oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space.get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space.get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space.get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) as++; delete ref_space->get_mesh(); - delete ref_space; + } while (done == false); From cac4abd5c246ca1dfc6790f5b2fa25c7146c374c Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sat, 13 Apr 2013 22:04:55 +0200 Subject: [PATCH 15/64] Finish - all examples build on windows. --- 1d/layer-boundary/main.cpp | 4 +- 1d/moving-front/main.cpp | 8 +- 1d/system/main.cpp | 6 +- 2d-advanced/acoustics/apartment/main.cpp | 6 +- 2d-advanced/acoustics/horn-axisym/main.cpp | 2 +- .../linear-advection-dg-adapt/definitions.cpp | 2 +- .../linear-advection-dg-adapt/definitions.h | 4 +- .../linear-advection-dg-adapt/main.cpp | 5 +- .../linear-advection-diffusion/main.cpp | 2 - .../elasticity-linear/bracket/main.cpp | 39 ++-- 2d-advanced/elasticity-linear/crack/main.cpp | 19 +- .../euler/euler-coupled-adapt/main.cpp | 38 ++-- 2d-advanced/euler/euler-coupled/main.cpp | 12 +- 2d-advanced/euler/forward-step-adapt/main.cpp | 8 +- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 8 +- .../heating-induced-vortex-adapt/main.cpp | 11 +- .../euler/joukowski-profile-adapt/main.cpp | 36 ++-- 2d-advanced/euler/joukowski-profile/main.cpp | 12 +- .../euler/reflected-shock-adapt/main.cpp | 11 +- .../heat-and-moisture-adapt/main.cpp | 101 +++++----- .../main.cpp | 67 +++---- 2d-advanced/maxwell/magnetostatics/main.cpp | 13 +- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 30 +-- 2d-advanced/maxwell/microwave-oven/main.cpp | 33 ++-- .../maxwell/resonator-time-domain-I/main.cpp | 22 +-- .../resonator-time-domain-II-ie/main.cpp | 20 +- .../resonator-time-domain-II-rk/main.cpp | 29 +-- .../local-projection-test/main.cpp | 2 +- 2d-advanced/navier-stokes/bearing/main.cpp | 9 +- .../circular-obstacle-adapt/main.cpp | 72 ++++--- .../navier-stokes/circular-obstacle/main.cpp | 29 ++- .../navier-stokes/driven-cavity/main.cpp | 25 ++- .../navier-stokes/rayleigh-benard/main.cpp | 29 ++- .../np-poisson-timedep-adapt/definitions.cpp | 6 +- .../np-poisson-timedep-adapt/main.cpp | 186 +++++++++--------- .../timestep_controller.h | 2 +- .../neutronics/4-group-adapt/definitions.cpp | 6 +- 2d-advanced/neutronics/4-group-adapt/main.cpp | 16 +- .../neutronics/4-group/definitions.cpp | 2 +- 2d-advanced/neutronics/4-group/definitions.h | 2 +- 2d-advanced/neutronics/4-group/main.cpp | 8 +- 2d-advanced/neutronics/iron-water/main.cpp | 14 +- 2d-advanced/neutronics/saphir/main.cpp | 7 - 2d-advanced/richards/basic-ie-newton/main.cpp | 2 +- 2d-advanced/richards/basic-ie-picard/main.cpp | 6 +- .../richards/basic-rk-newton-adapt/main.cpp | 16 +- 2d-advanced/richards/basic-rk-newton/main.cpp | 4 +- .../capillary-barrier-adapt/definitions.h | 12 +- .../richards/capillary-barrier-adapt/main.cpp | 8 +- .../richards/capillary-barrier-rk/main.cpp | 9 +- 2d-advanced/richards/seepage-adapt/main.cpp | 36 ++-- .../gross-pitaevski-adapt/main.cpp | 97 +++++---- .../schroedinger/gross-pitaevski/main.cpp | 10 +- 2d-advanced/wave-equation/wave-1/main.cpp | 9 +- 2d-benchmarks-general/layer-boundary/main.cpp | 4 +- 2d-benchmarks-general/layer-interior/main.cpp | 10 +- 2d-benchmarks-general/lshape/definitions.h | 2 +- 2d-benchmarks-general/lshape/main.cpp | 10 +- .../moving-front-space-adapt/main.cpp | 13 +- .../nonsym-check/definitions.h | 2 +- 2d-benchmarks-general/nonsym-check/main.cpp | 34 ++-- 2d-benchmarks-general/smooth-aniso-x/main.cpp | 7 +- 2d-benchmarks-general/smooth-aniso-y/main.cpp | 7 +- .../smooth-iso/definitions.h | 2 +- 2d-benchmarks-general/smooth-iso/main.cpp | 7 +- .../01-analytic-solution/main.cpp | 9 +- .../02-reentrant-corner/main.cpp | 9 +- .../03-linear-elasticity/main.cpp | 87 ++++---- .../04-exponential-peak/main.cpp | 9 +- 2d-benchmarks-nist/05-battery/definitions.cpp | 2 +- 2d-benchmarks-nist/05-battery/definitions.h | 12 +- 2d-benchmarks-nist/05-battery/main.cpp | 7 - 2d-benchmarks-nist/06-boundary-layer/main.cpp | 9 +- .../07-boundary-line-singularity/main.cpp | 9 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 9 +- .../09-wave-front-kelly-dealii/main.cpp | 4 +- .../09-wave-front-kelly/main.cpp | 4 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 9 +- .../10-interior-line-singularity/main.cpp | 9 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 9 +- .../12-multiple-difficulties/main.cpp | 9 +- 81 files changed, 675 insertions(+), 801 deletions(-) diff --git a/1d/layer-boundary/main.cpp b/1d/layer-boundary/main.cpp index 7c34b3a..27f2881 100644 --- a/1d/layer-boundary/main.cpp +++ b/1d/layer-boundary/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) mesh->refine_towards_boundary("Right", INIT_REF_NUM_BDY); // Define exact solution. - CustomExactSolution exact_sln(mesh, K); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, K)); // Define right side vector. CustomFunction f(K); @@ -166,7 +166,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/1d/moving-front/main.cpp b/1d/moving-front/main.cpp index 673fe9d..07128b7 100644 --- a/1d/moving-front/main.cpp +++ b/1d/moving-front/main.cpp @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) CustomWeakFormPoisson wf(new Hermes::Hermes1DFunction(-1.0), &f); // Previous and next time level solution. - ZeroSolution sln_time_prev(mesh); + MeshFunctionSharedPtr sln_time_prev(new ZeroSolution(mesh)); MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. @@ -233,7 +233,7 @@ int main(int argc, char* argv[]) } // Project the fine mesh solution onto the coarse mesh-> - Solution sln_coarse; + MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(space, sln_time_new, sln_coarse); @@ -275,8 +275,8 @@ int main(int argc, char* argv[]) oview.set_title(title); oview.show(space); - // Copy last reference solution into sln_time_prev. - sln_time_prev.copy(sln_time_new); + // Copy last reference solution into sln_time_prev-> + sln_time_prev->copy(sln_time_new); dof_history_graph.add_values(current_time, space->get_num_dofs()); dof_history_graph.save("dof_history.dat"); diff --git a/1d/system/main.cpp b/1d/system/main.cpp index 1d54518..41137d0 100644 --- a/1d/system/main.cpp +++ b/1d/system/main.cpp @@ -137,8 +137,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs_v(&bc_v); // Create H1 spaces with default shapeset for both displacement components. - SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); - SpaceSharedPtr v_space(new H1Space(MULTI ? v_mesh : u_mesh, &bcs_v, P_INIT_V)); + SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); + SpaceSharedPtr v_space(new H1Space(MULTI ? v_mesh : u_mesh, &bcs_v, P_INIT_V)); // Initialize coarse and reference mesh solutions. MeshFunctionSharedPtr u_sln(new Solution), v_sln(new Solution), u_ref_sln(new Solution), v_ref_sln(new Solution); @@ -186,8 +186,6 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_v_space = refSpaceCreator2.create_ref_space(); Hermes::vector > ref_spaces(ref_u_space, ref_v_space); - Hermes::vector > ref_spaces(ref_u_space, ref_v_space); - int ndof_ref = Space::get_num_dofs(ref_spaces); diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index 26ce65b..2ec0672 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -159,7 +159,7 @@ int main(int argc, char* argv[]) cpu_time.tick(); // View the coarse mesh solution and polynomial orders. - RealFilter acoustic_pressure(sln); + MeshFunctionSharedPtr acoustic_pressure(new RealFilter(sln)); sview.show(acoustic_pressure); oview.show(space); @@ -202,13 +202,13 @@ int main(int argc, char* argv[]) // Show the reference solution - the final result. sview.set_title("Fine mesh solution magnitude"); - RealFilter ref_mag(ref_sln); + MeshFunctionSharedPtr ref_mag(new RealFilter(ref_sln)); sview.show(ref_mag); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); + lin.save_solution_vtk(ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index 167d1b0..1964591 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -209,7 +209,7 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); + lin.save_solution_vtk(ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.cpp index 4948692..dd042ad 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.cpp @@ -1,6 +1,6 @@ #include "definitions.h" -CustomWeakForm::CustomWeakForm(std::string left_bottom_bnd_part, Mesh* mesh) : WeakForm(1), mesh(mesh) +CustomWeakForm::CustomWeakForm(std::string left_bottom_bnd_part, MeshSharedPtr mesh) : WeakForm(1), mesh(mesh) { add_matrix_form(new CustomMatrixFormVol(0, 0)); add_vector_form(new CustomVectorFormVol(0)); diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.h b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.h index f4800b4..a2df549 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.h +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/definitions.h @@ -10,7 +10,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomWeakForm : public WeakForm { public: - CustomWeakForm(std::string left_bottom_bnd_part, Mesh* mesh); + CustomWeakForm(std::string left_bottom_bnd_part, MeshSharedPtr mesh); WeakForm* clone() const; private: @@ -110,5 +110,5 @@ class CustomWeakForm : public WeakForm Ord upwind_flux(Ord u_cent, Ord u_neib, Ord a_dot_n) const; - Mesh* mesh; + MeshSharedPtr mesh; }; diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index 5bdfb1e..c409ab6 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char* args[]) for (int i=0; irefine_all_elements(); // Create an L2 space-> - L2Space space(mesh, P_INIT)); + SpaceSharedPtr space(new L2Space(mesh, P_INIT)); // Initialize refinement selector. L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -121,7 +121,7 @@ int main(int argc, char* args[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln, HERMES_L2_NORM); - ValFilter val_filter(ref_sln, 0.0, 1.0); + MeshFunctionSharedPtr val_filter(new ValFilter(ref_sln, 0.0, 1.0)); // View the coarse mesh solution. view1.show(val_filter); @@ -153,7 +153,6 @@ int main(int argc, char* args[]) // Clean up. delete adaptivity; - as++; } while (done == false); diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 134a5ee..62fdb52 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -195,10 +195,8 @@ int main(int argc, char* argv[]) delete matrix; delete rhs; delete adaptivity; - if(done == false) delete ref_space->get_mesh(); delete dp; - } while (done == false); diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index ece0d29..6b76b8d 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -104,8 +104,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&zero_disp); // Create x- and y- displacement space using the default H1 shapeset. - H1Space u1_space(u1_mesh, &bcs, P_INIT)); - H1Space u2_space(u2_mesh, &bcs, P_INIT)); + SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT)); + SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT)); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); // Initialize the weak formulation. @@ -154,7 +154,6 @@ int main(int argc, char* argv[]) Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); - Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); int ndof_ref = Space::get_num_dofs(ref_spaces); @@ -182,20 +181,20 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); } - + // Time measurement. cpu_time.tick(); // Translate the resulting coefficient vector into the Solution sln-> Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, - Hermes::vector >(u1_sln_ref, u2_sln_ref)); + Hermes::vector >(u1_sln_ref, u2_sln_ref)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), - Hermes::vector >(u1_sln_ref, u2_sln_ref), - Hermes::vector >(u1_sln, u2_sln)); - + Hermes::vector >(u1_sln_ref, u2_sln_ref), + Hermes::vector >(u1_sln, u2_sln)); + // View the coarse mesh solution and polynomial orders. s_view_0.show(u1_sln); o_view_0.show(u1_space); @@ -204,8 +203,8 @@ int main(int argc, char* argv[]) // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector >(u1_sln, u2_sln), lambda, mu); - ValFilter limited_stress(&stress, 0.0, 2e5); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln, u2_sln), lambda, mu)); + MeshFunctionSharedPtr limited_stress(new ValFilter(stress, 0.0, 2e5)); mises_view.show(limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 0); // Skip visualization time. @@ -226,23 +225,23 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); Hermes::vector err_est_rel; double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u1_sln, u2_sln), - Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; + Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; // Time measurement. cpu_time.tick(); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d, err_est_rel[0]: %g%%", - u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); + u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d, err_est_rel[1]: %g%%", - u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); + u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", - Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), - Space::get_num_dofs(ref_spaces), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // Add entry to DOF and CPU convergence graphs. graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), - err_est_rel_total); + err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); @@ -254,13 +253,13 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); + MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); } if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; // Clean up. delete adaptivity; - + // Increase counter. as++; } @@ -276,8 +275,8 @@ int main(int argc, char* argv[]) // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu); - ValFilter limited_stress(&stress, 0.0, 2e5); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu)); + MeshFunctionSharedPtr limited_stress(new ValFilter(stress, 0.0, 2e5)); mises_view.show(limited_stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 0); // Wait for all views to be closed. diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 834c38a..0c34e8d 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -106,8 +106,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs(&zero_disp); // Create x- and y- displacement space using the default H1 shapeset. - SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT_U1)); - SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT_U2)); + SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT_U1)); + SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT_U2)); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); // Initialize the weak formulation. @@ -118,8 +118,8 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); // Initialize coarse and reference mesh solutions. - Solution u1_sln, u2_sln; - Solution u1_sln_ref, u2_sln_ref; + MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); + MeshFunctionSharedPtr u1_sln_ref(new Solution), u2_sln_ref(new Solution); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -156,7 +156,6 @@ int main(int argc, char* argv[]) Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); - Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); int ndof_ref = Space::get_num_dofs(ref_spaces); @@ -206,7 +205,7 @@ int main(int argc, char* argv[]) // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector >(u1_sln, u2_sln), lambda, mu); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln, u2_sln), lambda, mu)); mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 1e3); // Skip visualization time. @@ -261,12 +260,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; - if(done == false) - for(unsigned int i = 0; i < ref_spaces.size(); i++) - { - delete (ref_spaces)[i]->get_mesh(); - delete (ref_spaces)[i]; - } // Increase counter. as++; @@ -283,7 +276,7 @@ int main(int argc, char* argv[]) // For von Mises stress Filter. double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - VonMisesFilter stress(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu)); mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 1e3); // Wait for all views to be closed. diff --git a/2d-advanced/euler/euler-coupled-adapt/main.cpp b/2d-advanced/euler/euler-coupled-adapt/main.cpp index 1595bdf..e4c65bf 100644 --- a/2d-advanced/euler/euler-coupled-adapt/main.cpp +++ b/2d-advanced/euler/euler-coupled-adapt/main.cpp @@ -183,13 +183,13 @@ int main(int argc, char* argv[]) bcs_concentration.add_boundary_condition(new ConcentrationTimedepEssentialBC(BDY_SOLID_WALL_TOP, 0.0, CONCENTRATION_EXT_STARTUP_TIME)); bcs_concentration.add_boundary_condition(new ConcentrationTimedepEssentialBC(BDY_INLET, 0.0, CONCENTRATION_EXT_STARTUP_TIME)); - L2Spacespace_rho(&mesh_flow, P_INIT_FLOW); +SpaceSharedPtrspace_rho(&mesh_flow, P_INIT_FLOW); L2Spacespace_rho_v_x(&mesh_flow, P_INIT_FLOW); L2Spacespace_rho_v_y(&mesh_flow, P_INIT_FLOW); L2Spacespace_e(&mesh_flow, P_INIT_FLOW); // Space for concentration. - H1Space space_c(&mesh_concentration, &bcs_concentration, P_INIT_CONCENTRATION); + H1Space space_c(new L2Space(&mesh_concentration, &bcs_concentration, P_INIT_CONCENTRATION)); int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -307,15 +307,15 @@ int main(int argc, char* argv[]) Mesh* ref_mesh_concentration = refMeshCreatorConcentration.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, &mesh_flow); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); +SpaceSharedPtr* ref_space_rho = refSpaceCreatorRho.create_ref_space(new Space()); Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, &mesh_flow); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); +SpaceSharedPtr* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(new Space()); Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, &mesh_flow); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); +SpaceSharedPtr* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(new Space()); Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, &mesh_flow); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); +SpaceSharedPtr* ref_space_e = refSpaceCreatorE.create_ref_space(new Space()); Space::ReferenceSpaceCreator refSpaceCreatorConcentration(&space_c, &mesh_concentration); - Space* ref_space_c = refSpaceCreatorConcentration.create_ref_space(); +SpaceSharedPtr* ref_space_c = refSpaceCreatorConcentration.create_ref_space(); char filename[40]; sprintf(filename, "Flow-mesh-%i-%i.xml", iteration - 1, as - 1); @@ -327,7 +327,7 @@ int main(int argc, char* argv[]) ref_space_stabilization->set_uniform_order(0); if(CAND_LIST_FLOW != H2D_HP_ANISO) - ref_space_c->adjust_element_order(+1, P_INIT_CONCENTRATION); + ref_space_c->adjust_element_order(new Space(+1, P_INIT_CONCENTRATION)); Hermes::vector *> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e, ref_space_c); @@ -342,7 +342,7 @@ int main(int argc, char* argv[]) // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e, &space_c)), Space::get_num_dofs(ref_spaces_const)); + space_rho_v_y, &space_e, &space_c)), Space::get_num_dofs(ref_spaces_const)); // Very important, set the meshes for the flow as the same. ref_space_rho_v_x->get_mesh()->set_seq(ref_space_rho->get_mesh()->get_seq()); @@ -356,8 +356,8 @@ int main(int argc, char* argv[]) LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Initialize the FE problem. - DiscreteProblem dp(wf, ref_spaces_const); - DiscreteProblem dp_stabilization(&wf_stabilization, ref_space_stabilization); + DiscreteProblem dp(&wf, ref_spaces_const); + DiscreteProblem dp_stabilization(wf_stabilization, ref_space_stabilization); bool* discreteIndicator = NULL; if(SEMI_IMPLICIT) @@ -399,10 +399,10 @@ int main(int argc, char* argv[]) { Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces_const, Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e, &rsln_c)); - } +SpaceSharedPtr*> flow_spaces(new } else { - Hermes::vector*> flow_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + Hermes::vector(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); double* flow_solution_vector = new double[Space::get_num_dofs(flow_spaces)]; @@ -423,11 +423,11 @@ int main(int argc, char* argv[]) char filenamea[40]; Linearizer lin_mach; sprintf(filenamea, "Mach number-3D-%i-%i.vtk", iteration - 1, as); - lin_mach.save_solution_vtk(&Mach_number, filenamea, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filenamea, "MachNumber", true); Linearizer lin_concentration; sprintf(filenamea, "Concentration-%i-%i.vtk", iteration - 1, as); - lin_concentration.save_solution_vtk(&prev_c, filenamea, "Concentration", true); + lin_concentration.save_solution_vtk(prev_c, filenamea, "Concentration", true); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); @@ -438,17 +438,17 @@ int main(int argc, char* argv[]) util_time_step = time_step_n; if(SEMI_IMPLICIT) - CFL.calculate_semi_implicit(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), const_cast(rsln_rho.get_mesh()), util_time_step); + CFL.calculate_semi_implicit(Hermes::vector*>(rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), const_cast(rsln_rho.get_mesh()), util_time_step); else - CFL.calculate(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), const_cast(rsln_rho.get_mesh()), util_time_step); + CFL.calculate(Hermes::vector*>(rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), const_cast(rsln_rho.get_mesh()), util_time_step); time_step_after_adaptivity = util_time_step; - ADES.calculate(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y), const_cast(rsln_rho.get_mesh()), util_time_step); + ADES.calculate(Hermes::vector*>(rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y), const_cast(rsln_rho.get_mesh()), util_time_step); if(time_step_after_adaptivity > util_time_step) time_step_after_adaptivity = util_time_step; - ADES.calculate(Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y), const_cast(rsln_c.get_mesh()), util_time_step); + ADES.calculate(Hermes::vector*>(rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y), const_cast(rsln_c.get_mesh()), util_time_step); if(time_step_after_adaptivity > util_time_step) time_step_after_adaptivity = util_time_step; diff --git a/2d-advanced/euler/euler-coupled/main.cpp b/2d-advanced/euler/euler-coupled/main.cpp index 1d2e9c8..c576711 100644 --- a/2d-advanced/euler/euler-coupled/main.cpp +++ b/2d-advanced/euler/euler-coupled/main.cpp @@ -132,14 +132,14 @@ int main(int argc, char* argv[]) bcs_concentration.add_boundary_condition(new ConcentrationTimedepEssentialBC(BDY_SOLID_WALL_TOP, 0.0, CONCENTRATION_EXT_STARTUP_TIME)); bcs_concentration.add_boundary_condition(new ConcentrationTimedepEssentialBC(BDY_INLET, 0.0, CONCENTRATION_EXT_STARTUP_TIME)); - L2Spacespace_rho(&mesh_flow, P_FLOW); +SpaceSharedPtrspace_rho(&mesh_flow, P_FLOW); L2Spacespace_rho_v_x(&mesh_flow, P_FLOW); L2Spacespace_rho_v_y(&mesh_flow, P_FLOW); L2Spacespace_e(&mesh_flow, P_FLOW); L2Space space_stabilization(&mesh_flow, 0); // Space for concentration. - H1Space space_c(&mesh_concentration, &bcs_concentration, P_CONCENTRATION); + H1Space space_c(new L2Space(&mesh_concentration, &bcs_concentration, P_CONCENTRATION)); int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -174,7 +174,7 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormStabilization wf_stabilization(&prev_rho); // Initialize the FE problem. - DiscreteProblem dp(wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c)); + DiscreteProblem dp(&wf, Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c)); DiscreteProblem dp_stabilization(&wf_stabilization, &space_stabilization); bool* discreteIndicator = NULL; @@ -316,13 +316,13 @@ int main(int argc, char* argv[]) Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); Linearizer lin_mach; sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); Linearizer lin_concentration; sprintf(filename, "Concentration-%i.vtk", iteration - 1); - lin_concentration.save_solution_vtk(&prev_c, filename, "Concentration", true); + lin_concentration.save_solution_vtk(prev_c, filename, "Concentration", true); } } diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index 183ef0e..c25baee 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -208,10 +208,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT)); - space_rho_v_x->adjust_element_order(-1, P_INIT)); - space_rho_v_y->adjust_element_order(-1, P_INIT)); - space_e->adjust_element_order(-1, P_INIT)); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); } Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 76d762a..d2add37 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -200,10 +200,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT)); - space_rho_v_x->adjust_element_order(-1, P_INIT)); - space_rho_v_y->adjust_element_order(-1, P_INIT)); - space_e->adjust_element_order(-1, P_INIT)); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); Space::assign_dofs(spaces); } diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 4e24cb1..7f6139f 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -209,10 +209,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT)); - space_rho_v_x->adjust_element_order(-1, P_INIT)); - space_rho_v_y->adjust_element_order(-1, P_INIT)); - space_e->adjust_element_order(-1, P_INIT)); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); } // Adaptivity loop: @@ -239,7 +239,6 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces) == ndofs_prev) @@ -313,7 +312,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); // If err_est too large, adapt the mesh-> - if (err_est_rel_total < ERR_STOP && Space::get_num_dofs(ref_spaces) > NDOFS_MIN) + if (err_est_rel_total < ERR_STOP & Space::get_num_dofs(ref_spaces) > NDOFS_MIN) done = true; else { diff --git a/2d-advanced/euler/joukowski-profile-adapt/main.cpp b/2d-advanced/euler/joukowski-profile-adapt/main.cpp index 265788a..8555be1 100644 --- a/2d-advanced/euler/joukowski-profile-adapt/main.cpp +++ b/2d-advanced/euler/joukowski-profile-adapt/main.cpp @@ -139,11 +139,11 @@ int main(int argc, char* argv[]) m.show(&mesh); m.wait_for_close(); - // Initialize boundary condition types and spaces with default shapesets. - L2Spacespace_rho(&mesh, P_INIT); +SpaceSharedPtrspace_rho(&mesh, P_INIT); L2Spacespace_rho_v_x(&mesh, P_INIT); L2Spacespace_rho_v_y(&mesh, P_INIT); - L2Spacespace_e(&mesh, P_INIT); + L2Spacespace_e(new // Initialize boundary condition types and spaces with default shapesets. + L2Space(&mesh, P_INIT)); int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); Hermes::Mixins::Loggable::Static::info("Initial coarse ndof: %d", ndof); @@ -198,7 +198,7 @@ int main(int argc, char* argv[]) if(REUSE_SOLUTION && continuity.have_record_available()) { continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); +SpaceSharedPtr *> spaceVector = continuity.get_last_record()->load_spaces(new Hermes::vector(Hermes::vector(&mesh, &mesh, &mesh, &mesh))); space_rho.copy(spaceVector[0], &mesh); space_rho_v_x.copy(spaceVector[1], &mesh); space_rho_v_y.copy(spaceVector[2], &mesh); @@ -243,16 +243,16 @@ int main(int argc, char* argv[]) Mesh::ReferenceMeshCreator refMeshCreatorFlow(&mesh); Mesh* ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorRho(&space_rho, ref_mesh_flow, order_increase); - Space* ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(&space_rho_v_x, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(&space_rho_v_y, ref_mesh_flow, order_increase); - Space* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&space_e, ref_mesh_flow, order_increase); - Space* ref_space_e = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); +SpaceSharedPtr* ref_space_rho = refSpaceCreatorRho.create_ref_space(new Space()); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); +SpaceSharedPtr* ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(new Space()); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); +SpaceSharedPtr* ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(new Space()); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); +SpaceSharedPtr* ref_space_e = refSpaceCreatorE.create_ref_space(new Space()); - Hermes::vector*> ref_spaces_const(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); +SpaceSharedPtr*> ref_spaces_const(new Hermes::vector(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces_const) == ndofs_prev) @@ -269,7 +269,7 @@ int main(int argc, char* argv[]) loaded_now = false; continuity.get_last_record()->load_solutions(Hermes::vector*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), - Hermes::vector *>(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e)); +SpaceSharedPtr *>(new Hermes::vector(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e))); } else { @@ -280,7 +280,7 @@ int main(int argc, char* argv[]) // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", Space::get_num_dofs(Hermes::vector *>(&space_rho, &space_rho_v_x, - &space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); + space_rho_v_y, &space_e)), Space::get_num_dofs(ref_spaces_const)); // Assemble the reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); @@ -331,7 +331,7 @@ int main(int argc, char* argv[]) double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), Hermes::vector*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)) * 100; - CFL.calculate_semi_implicit(Hermes::vector *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), ref_space_rho->get_mesh(), time_step); + CFL.calculate_semi_implicit(Hermes::vector *>(rsln_rho, rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), ref_space_rho->get_mesh(), time_step); // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); @@ -379,9 +379,9 @@ int main(int argc, char* argv[]) Linearizer lin; char filename[40]; sprintf(filename, "Pressure-%i.vtk", iteration - 1); - lin.save_solution_vtk(&pressure, filename, "Pressure", false); + lin.save_solution_vtk(pressure, filename, "Pressure", false); sprintf(filename, "Mach number-%i.vtk", iteration - 1); - lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false); + lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); } } diff --git a/2d-advanced/euler/joukowski-profile/main.cpp b/2d-advanced/euler/joukowski-profile/main.cpp index 3e1a6b5..247b4a1 100644 --- a/2d-advanced/euler/joukowski-profile/main.cpp +++ b/2d-advanced/euler/joukowski-profile/main.cpp @@ -97,12 +97,12 @@ int main(int argc, char* argv[]) mesh.refine_towards_boundary(BDY_SOLID_WALL_PROFILE, INIT_REF_NUM_BOUNDARY_ANISO); mesh.refine_towards_vertex(0, INIT_REF_NUM_VERTEX); - // Initialize boundary condition types and spaces with default shapesets. - L2Space space_rho(&mesh, P_INIT); +SpaceSharedPtr space_rho(&mesh, P_INIT); L2Space space_rho_v_x(&mesh, P_INIT); L2Space space_rho_v_y(&mesh, P_INIT); L2Space space_e(&mesh, P_INIT); - L2Space space_stabilization(&mesh, 0); + L2Space space_stabilization(new // Initialize boundary condition types and spaces with default shapesets. + L2Space(&mesh, 0)); int ndof = Space::get_num_dofs(Hermes::vector*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) if(REUSE_SOLUTION && continuity.have_record_available()) { continuity.get_last_record()->load_mesh(&mesh); - Hermes::vector *> spaceVector = continuity.get_last_record()->load_spaces(Hermes::vector(&mesh, &mesh, &mesh, &mesh)); +SpaceSharedPtr *> spaceVector = continuity.get_last_record()->load_spaces(new Hermes::vector(Hermes::vector(&mesh, &mesh, &mesh, &mesh))); space_rho.copy(spaceVector[0], &mesh); space_rho_v_x.copy(spaceVector[1], &mesh); space_rho_v_y.copy(spaceVector[2], &mesh); @@ -263,10 +263,10 @@ int main(int argc, char* argv[]) Linearizer lin_pressure; char filename[40]; sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(&pressure, filename, "Pressure", true); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); Linearizer lin_mach; sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(&Mach_number, filename, "MachNumber", true); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); } } } diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index c138023..ba04351 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -218,10 +218,10 @@ int main(int argc, char* argv[]) space_rho->unrefine_all_mesh_elements(true); - space_rho->adjust_element_order(-1, P_INIT)); - space_rho_v_x->adjust_element_order(-1, P_INIT)); - space_rho_v_y->adjust_element_order(-1, P_INIT)); - space_e->adjust_element_order(-1, P_INIT)); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); Space::assign_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); } @@ -251,7 +251,6 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); if(ndofs_prev != 0) if(Space::get_num_dofs(ref_spaces) == ndofs_prev) @@ -353,7 +352,7 @@ int main(int argc, char* argv[]) Linearizer lin; char filename[40]; //sprintf(filename, "Pressure-%i.vtk", iteration - 1); - //lin.save_solution_vtk(&pressure, filename, "Pressure", false); + //lin.save_solution_vtk(pressure, filename, "Pressure", false); sprintf(filename, "Mach number-%i.vtk", iteration - 1); lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); sprintf(filename, "Mesh-%i.vtk", iteration - 1); diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index 80bccec..99e5c0e 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); // Load the mesh-> - Mesh basemesh, T_mesh, w_mesh; + MeshSharedPtr basemesh(new Mesh), T_mesh(new Mesh), w_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", basemesh); @@ -146,23 +146,22 @@ int main(int argc, char* argv[]) EssentialBCNonConst temp_reactor("bdy_react", REACTOR_START_TIME, T_INITIAL, T_REACTOR_MAX); EssentialBCs bcs_T(&temp_reactor); - // Create H1 spaces with default shapesets. - H1Space T_space(T_mesh, &bcs_T, P_INIT)); - H1Space w_space(MULTI ? &w_mesh : &T_mesh, P_INIT)); + SpaceSharedPtr T_space(new H1Space(T_mesh, &bcs_T, P_INIT)); + SpaceSharedPtr w_space(new H1Space(MULTI ? w_mesh : T_mesh, P_INIT)); // Define constant initial conditions. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ConstantSolution T_time_prev(&T_mesh, T_INITIAL); - ConstantSolution w_time_prev(&w_mesh, W_INITIAL); - Solution T_time_new(&T_mesh); - Solution w_time_new(&w_mesh); - + MeshFunctionSharedPtr T_time_prev(new ConstantSolution(T_mesh, T_INITIAL)); + MeshFunctionSharedPtr w_time_prev(new ConstantSolution(w_mesh, W_INITIAL)); + MeshFunctionSharedPtr T_time_new(new Solution(T_mesh)); + MeshFunctionSharedPtr w_time_new(new Solution(w_mesh)); + // Solutions. - Solution T_coarse, w_coarse; + MeshFunctionSharedPtr T_coarse(new Solution), w_coarse(new Solution); // Initialize the weak formulation. - const CustomWeakFormHeatMoistureRK wf(c_TT, c_ww, d_TT, d_Tw, d_wT, d_ww, - k_TT, k_ww, T_EXTERIOR, W_EXTERIOR, "bdy_ext"); + CustomWeakFormHeatMoistureRK wf(c_TT, c_ww, d_TT, d_Tw, d_wT, d_ww, + k_TT, k_ww, T_EXTERIOR, W_EXTERIOR, "bdy_ext"); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -190,37 +189,37 @@ int main(int argc, char* argv[]) while (current_time < SIMULATION_TIME) { Hermes::Mixins::Loggable::Static::info("Simulation time = %g s (%d h, %d d, %d y)", - current_time, (int) current_time / 3600, - (int) current_time / (3600*24), (int) current_time / (3600*24*364)); + current_time, (int) current_time / 3600, + (int) current_time / (3600*24), (int) current_time / (3600*24*364)); // Update time-dependent essential BCs. if (current_time <= REACTOR_START_TIME) { Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(&T_space, &w_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(T_space, w_space), current_time); } // Uniform mesh derefinement. if (ts > 1 && ts % UNREF_FREQ == 0) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: T_mesh->copy(basemesh); - w_mesh->copy(basemesh); - T_space->set_uniform_order(P_INIT); - w_space->set_uniform_order(P_INIT); - break; - case 2: T_mesh->unrefine_all_elements(); - if(MULTI) - w_mesh->unrefine_all_elements(); - T_space->set_uniform_order(P_INIT); - w_space->set_uniform_order(P_INIT); - break; - case 3: T_mesh->unrefine_all_elements(); - if(MULTI) - w_mesh->unrefine_all_elements(); - T_space->adjust_element_order(-1, -1, P_INIT, P_INIT); - w_space->adjust_element_order(-1, -1, P_INIT, P_INIT); - break; - default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); + case 1: T_mesh->copy(basemesh); + w_mesh->copy(basemesh); + T_space->set_uniform_order(P_INIT); + w_space->set_uniform_order(P_INIT); + break; + case 2: T_mesh->unrefine_all_elements(); + if(MULTI) + w_mesh->unrefine_all_elements(); + T_space->set_uniform_order(P_INIT); + w_space->set_uniform_order(P_INIT); + break; + case 3: T_mesh->unrefine_all_elements(); + if(MULTI) + w_mesh->unrefine_all_elements(); + T_space->adjust_element_order(-1, -1, P_INIT, P_INIT); + w_space->adjust_element_order(-1, -1, P_INIT, P_INIT); + break; + default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } T_space->assign_dofs(); w_space->assign_dofs(); @@ -234,16 +233,16 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreatorU(&T_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorU(T_mesh); MeshSharedPtr ref_T_mesh = refMeshCreatorU.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorT(&T_space, ref_T_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorT(T_space, ref_T_mesh); SpaceSharedPtr ref_T_space = refSpaceCreatorT.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreatorW(&w_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorW(w_mesh); MeshSharedPtr ref_w_mesh = refMeshCreatorW.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorW(&w_space, ref_w_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorW(w_space, ref_w_mesh); SpaceSharedPtr ref_w_space = refSpaceCreatorW.create_ref_space(); Hermes::vector > ref_spaces(ref_T_space, ref_w_space); @@ -256,15 +255,15 @@ int main(int argc, char* argv[]) // Perform one Runge-Kutta time step according to the selected Butcher's table. Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step (t = %g s, tau = %g s, stages: %d).", - current_time, time_step, bt.get_size()); + current_time, time_step, bt.get_size()); try { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL); - runge_kutta.rk_time_step_newton(Hermes::vector >(&T_time_prev, &w_time_prev), - Hermes::vector >(&T_time_new, &w_time_new)); + runge_kutta.rk_time_step_newton(Hermes::vector >(T_time_prev, w_time_prev), + Hermes::vector >(T_time_new, w_time_new)); } catch(Exceptions::Exception& e) { @@ -274,13 +273,13 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse meshes. Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solutions on coarse meshes for error estimation."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&T_space, &w_space), - Hermes::vector >(&T_time_new, &w_time_new), - Hermes::vector >(&T_coarse, &w_coarse), - matrix_solver); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(T_space, w_space), + Hermes::vector >(T_time_new, w_time_new), + Hermes::vector >(T_coarse, w_coarse), + matrix_solver); // Initialize an instance of the Adapt class and register custom error forms. - Adapt* adaptivity = new Adapt(Hermes::vector >(&T_space, &w_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(T_space, w_space)); CustomErrorForm cef_0_0(d_TT, c_TT); CustomErrorForm cef_0_1(d_Tw, c_TT); CustomErrorForm cef_1_0(d_wT, c_ww); @@ -292,13 +291,13 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&T_coarse, &w_coarse), - Hermes::vector >(&T_time_new, &w_time_new)) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(T_coarse, w_coarse), + Hermes::vector >(T_time_new, w_time_new)) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector >(&T_space, &w_space)), - Space::get_num_dofs(ref_spaces), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(T_space, w_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the meshes. if (err_est_rel_total < ERR_STOP) @@ -308,13 +307,13 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(Hermes::vector >(&T_space, &w_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(T_space, w_space)) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. as++; } - + // Clean up. delete adaptivity; } diff --git a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp index 821753d..1387398 100644 --- a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp +++ b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp @@ -176,12 +176,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. - ConstantSolution sln_prev_time(mesh, TEMP_INIT); + MeshFunctionSharedPtr sln_prev_time(new ConstantSolution (mesh, TEMP_INIT)); // Initialize the weak formulation. double current_time = 0; CustomWeakFormHeatRK wf(BDY_FIRE, BDY_AIR, ALPHA_FIRE, ALPHA_AIR, - RHO, HEATCAP, TEMP_EXT_AIR, TEMP_INIT, ¤t_time); + RHO, HEATCAP, TEMP_EXT_AIR, TEMP_INIT, ¤t_time); // Initialize the FE problem. DiscreteProblem dp(&wf, space); @@ -203,7 +203,7 @@ int main(int argc, char* argv[]) // Graph for time step history. SimpleGraph time_step_graph; if (ADAPTIVE_TIME_STEP_ON) Hermes::Mixins::Loggable::Static::info("Time step history will be saved to file time_step_history.dat."); - + // Class for projections. OGProjection ogProjection; @@ -217,17 +217,17 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - break; - case 2: space->unrefine_all_mesh_elements(); - space->set_uniform_order(P_INIT); - break; - case 3: space->unrefine_all_mesh_elements(); - //space->adjust_element_order(-1, P_INIT)); - space->adjust_element_order(-1, -1, P_INIT, P_INIT); - break; - default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + break; + case 2: space->unrefine_all_mesh_elements(); + space->set_uniform_order(P_INIT); + break; + case 3: space->unrefine_all_mesh_elements(); + //space->adjust_element_order(-1, P_INIT); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); + break; + default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } space->assign_dofs(); @@ -237,7 +237,7 @@ int main(int argc, char* argv[]) // Spatial adaptivity loop. Note: sln_prev_time must not be // changed during spatial adaptivity. MeshFunctionSharedPtr ref_sln(new Solution()); - Solution time_error_fn(mesh); + MeshFunctionSharedPtr time_error_fn(new Solution(mesh)); bool done = false; int as = 1; double err_est; do { @@ -254,22 +254,19 @@ int main(int argc, char* argv[]) try { ogProjection.project_global(ref_space, sln_prev_time, - sln_prev_time); - if(ts > 1) - delete sln_prev_time->get_mesh(); + sln_prev_time); } catch(Exceptions::Exception& e) { std::cout << e.what() << std::endl; Hermes::Mixins::Loggable::Static::error("Projection failed."); - delete ref_space->get_mesh(); - + return -1; } // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, tau = %g s, stages: %d).", - current_time, time_step, bt.get_size()); + current_time, time_step, bt.get_size()); bool verbose = true; bool jacobian_changed = false; @@ -279,19 +276,18 @@ int main(int argc, char* argv[]) runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL_FINE); - runge_kutta.rk_time_step_newton(sln_prev_time, ref_sln, bt.is_embedded() ? &time_error_fn : NULL); + runge_kutta.rk_time_step_newton(sln_prev_time, ref_sln, bt.is_embedded() ? time_error_fn : NULL); } catch(Exceptions::Exception& e) { std::cout << e.what() << std::endl; Hermes::Mixins::Loggable::Static::error("Runge-Kutta time step failed"); - delete ref_space->get_mesh(); - + return -1; } /* If ADAPTIVE_TIME_STEP_ON == true, estimate temporal error. - If too large or too small, then adjust it and restart the time step. */ + If too large or too small, then adjust it and restart the time step. */ double rel_err_time = 0; if (bt.is_embedded() == true) @@ -305,8 +301,8 @@ int main(int argc, char* argv[]) //time_error_view.show_mesh(false); time_error_view.show(time_error_fn); - rel_err_time = Global::calc_norm(&time_error_fn, HERMES_H1_NORM) - / Global::calc_norm(ref_sln, HERMES_H1_NORM) * 100; + rel_err_time = Global::calc_norm(time_error_fn.get(), HERMES_H1_NORM) + / Global::calc_norm(ref_sln.get(), HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } @@ -316,7 +312,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("rel_err_time %g%% is above upper limit %g%%", rel_err_time, TIME_ERR_TOL_UPPER); Hermes::Mixins::Loggable::Static::info("Decreasing tau from %g to %g s and restarting time step.", - time_step, time_step * TIME_STEP_DEC_RATIO); + time_step, time_step * TIME_STEP_DEC_RATIO); time_step *= TIME_STEP_DEC_RATIO; continue; } @@ -348,10 +344,11 @@ int main(int argc, char* argv[]) // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); - DiffFilter space_error_fn(Hermes::vector >(ref_sln, sln)); + MeshFunctionSharedPtr space_error_fn(new DiffFilter(Hermes::vector >(ref_sln, sln))); space_error_view.set_title(title); //space_error_view.show_mesh(false); - AbsFilter abs_sef(space_error_fn); + MeshFunctionSharedPtr abs_sef(new AbsFilter(space_error_fn)); + space_error_view.show(abs_sef); // Calculate element errors and spatial error estimate. @@ -361,7 +358,7 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", - Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_rel_space); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; @@ -376,11 +373,11 @@ int main(int argc, char* argv[]) // Increase the counter of performed adaptivity steps. as++; } - + // Clean up. if(!done) - - delete adaptivity; + + delete adaptivity; } while (done == false); @@ -395,7 +392,7 @@ int main(int argc, char* argv[]) ordview.show(space); // Copy last reference solution into sln_prev_time - sln_prev_timecopy(ref_sln); + sln_prev_time->copy(ref_sln); // Increase current time and counter of time steps. current_time += time_step; diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 56249ec..39f837a 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -97,13 +97,14 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, space); // Initialize the solution. - ConstantSolution sln(mesh, INIT_COND); + MeshFunctionSharedPtr sln(new ConstantSolution(mesh, INIT_COND)); // Project the initial condition on the FE space to obtain initial // coefficient vector for the Newton's method. Hermes::Mixins::Loggable::Static::info("Projecting to obtain initial vector for the Newton's method."); double* coeff_vec = new double[ndof] ; - OGProjection ogProjection; ogProjection.project_global(space, sln, coeff_vec); + OGProjection ogProjection; + ogProjection.project_global(space, sln, coeff_vec); // Perform Newton's iteration. Hermes::Hermes2D::NewtonSolver newton(&dp); @@ -129,20 +130,20 @@ int main(int argc, char* argv[]) // Visualise the solution and mesh-> ScalarView s_view1("Vector potential", new WinGeom(0, 0, 350, 450)); - FilterVectorPotential vector_potential(Hermes::vector >(sln, sln), - Hermes::vector(H2D_FN_VAL, H2D_FN_VAL)); + MeshFunctionSharedPtr vector_potential(new FilterVectorPotential(Hermes::vector >(sln, sln), + Hermes::vector(H2D_FN_VAL, H2D_FN_VAL))); s_view1.show_mesh(false); s_view1.show(vector_potential); ScalarView s_view2("Flux density", new WinGeom(360, 0, 350, 450)); - FilterFluxDensity flux_density(Hermes::vector >(sln, sln)); + MeshFunctionSharedPtr flux_density(new FilterFluxDensity(Hermes::vector >(sln, sln))); s_view2.show_mesh(false); s_view2.show(flux_density); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&flux_density, "sln->vtk", "Flux density", mode_3D); + lin.save_solution_vtk(flux_density, "sln->vtk", "Flux density", mode_3D); Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); OrderView o_view("Mesh", new WinGeom(720, 0, 350, 450)); diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 4b6cc1c..c7042bc 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -166,16 +166,16 @@ int main(int argc, char* argv[]) // Initialize solutions. double current_time = 0; - MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionE(&E_mesh, current_time, OMEGA, K_x, K_y)); - MeshFunctionSharedPtr H_time_prev(new CustomInitialConditionH(&H_mesh, current_time, OMEGA, K_x, K_y)); - MeshFunctionSharedPtr P_time_prev(new CustomInitialConditionP(&P_mesh, current_time, OMEGA, K_x, K_y)); - Hermes::vector > slns_time_prev(&E_time_prev, &H_time_prev, &P_time_prev); + MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionE(E_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr H_time_prev(new CustomInitialConditionH(H_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr P_time_prev(new CustomInitialConditionP(P_mesh, current_time, OMEGA, K_x, K_y)); + Hermes::vector > slns_time_prev(E_time_prev, H_time_prev, P_time_prev); MeshFunctionSharedPtr E_time_new(new Solution(E_mesh)), H_time_new(new Solution(H_mesh)), P_time_new(new Solution(P_mesh)); MeshFunctionSharedPtr E_time_new_coarse(new Solution(E_mesh)), H_time_new_coarse(new Solution(H_mesh)), P_time_new_coarse(new Solution(P_mesh)); - Hermes::vector > slns_time_new(&E_time_new, &H_time_new, &P_time_new); + Hermes::vector > slns_time_new(E_time_new, H_time_new, P_time_new); // Initialize the weak formulation. - const CustomWeakFormMD wf(OMEGA, K_x, K_y, MU_0, EPS_0, EPS_INF, EPS_Q, TAU); + CustomWeakFormMD wf(OMEGA, K_x, K_y, MU_0, EPS_0, EPS_INF, EPS_Q, TAU); // Initialize boundary conditions DefaultEssentialBCConst bc_essential("Bdy", 0.0); @@ -248,9 +248,9 @@ int main(int argc, char* argv[]) H_space->unrefine_all_mesh_elements(true); P_space->unrefine_all_mesh_elements(true); - E_space->adjust_element_order(-1, P_INIT)); - H_space->adjust_element_order(-1, P_INIT)); - P_space->adjust_element_order(-1, P_INIT)); + E_space->adjust_element_order(-1, P_INIT); + H_space->adjust_element_order(-1, P_INIT); + P_space->adjust_element_order(-1, P_INIT); } // Adaptivity loop: @@ -263,18 +263,18 @@ int main(int argc, char* argv[]) // Construct globally refined reference mesh and setup reference space-> int order_increase = 1; - Mesh::ReferenceMeshCreator refMeshCreatorE(&E_mesh); - Mesh::ReferenceMeshCreator refMeshCreatorH(&H_mesh); - Mesh::ReferenceMeshCreator refMeshCreatorP(&P_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorE(E_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorH(H_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorP(P_mesh); MeshSharedPtr ref_mesh_E = refMeshCreatorE.create_ref_mesh(); MeshSharedPtr ref_mesh_H = refMeshCreatorH.create_ref_mesh(); MeshSharedPtr ref_mesh_P = refMeshCreatorP.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorE(&E_space, ref_mesh_E, order_increase); + Space::ReferenceSpaceCreator refSpaceCreatorE(E_space, ref_mesh_E, order_increase); SpaceSharedPtr ref_space_E = refSpaceCreatorE.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorH(&H_space, ref_mesh_H, order_increase); + Space::ReferenceSpaceCreator refSpaceCreatorH(H_space, ref_mesh_H, order_increase); SpaceSharedPtr ref_space_H = refSpaceCreatorH.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorP(&P_space, ref_mesh_P, order_increase); + Space::ReferenceSpaceCreator refSpaceCreatorP(P_space, ref_mesh_P, order_increase); SpaceSharedPtr ref_space_P = refSpaceCreatorP.create_ref_space(); int ndof = Space::get_num_dofs(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index a6a7299..613e358 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) EssentialBCs > bcs(&bc_essential); // Create an Hcurl space with default shapeset. - HcurlSpace > space(mesh, &bcs, P_INIT)); + SpaceSharedPtr > space(new HcurlSpace > (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); @@ -129,10 +129,10 @@ int main(int argc, char* argv[]) // Initialize views. ScalarView eview("Electric field", new WinGeom(0, 0, 580, 400)); OrderView oview("Polynomial orders", new WinGeom(590, 0, 550, 400)); - + // DOF and CPU convergence graphs initialization. SimpleGraph graph_dof, graph_cpu; - + // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); @@ -173,15 +173,15 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the Solution > sln-> Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); - + // View the coarse mesh solution and polynomial orders. - RealFilter real(sln); - MagFilter magn(&real); - ValFilter limited_magn(&magn, 0.0, 4e3); + MeshFunctionSharedPtr real(new RealFilter(sln)); + MeshFunctionSharedPtr magn(new MagFilter(real)); + MeshFunctionSharedPtr limited_magn(new ValFilter(magn, 0.0, 4e3)); char title[100]; sprintf(title, "Electric field, adaptivity step %d", as); eview.set_title(title); @@ -224,29 +224,24 @@ int main(int argc, char* argv[]) if (space->get_num_dofs() >= NDOF_STOP) done = true; delete adaptivity; - if(!done) - { - delete ref_space->get_mesh(); - - } - + // Increase counter. as++; } while (done == false); - + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - RealFilter ref_real(sln); - MagFilter ref_magn(&ref_real); - ValFilter ref_limited_magn(&ref_magn, 0.0, 4e3); + MeshFunctionSharedPtr ref_real(new RealFilter(sln)); + MeshFunctionSharedPtr ref_magn(new MagFilter(ref_real)); + MeshFunctionSharedPtr ref_limited_magn(new ValFilter(ref_magn, 0.0, 4e3)); eview.set_title("Fine mesh solution - magnitude"); eview.show(ref_limited_magn); // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(&ref_limited_magn, "sln->vtk", "Magnitude of E", mode_3D); + lin.save_solution_vtk(ref_limited_magn, "sln->vtk", "Magnitude of E", mode_3D); Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); // Wait for all views to be closed. diff --git a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp index 5c837d8..4a8b34b 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp @@ -68,23 +68,23 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_sln(mesh); - ZeroSolution B_sln(mesh); - Hermes::vector > slns(&E_sln, &B_sln); + MeshFunctionSharedPtr E_sln(new CustomInitialConditionWave(mesh)); + MeshFunctionSharedPtr B_sln(new ZeroSolution(mesh)); + Hermes::vector > slns(E_sln, B_sln); // Initialize the weak formulation. CustomWeakFormWave wf(C_SQUARED); - + // Initialize boundary conditions DefaultEssentialBCConst bc_essential("Perfect conductor", 0.0); EssentialBCs bcs_E(&bc_essential); + SpaceSharedPtr E_space(new HcurlSpace(mesh, &bcs_E, P_INIT)); EssentialBCs bcs_B; // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs_E, P_INIT)); - H1Space B_space(mesh, &bcs_B, P_INIT)); - Hermes::vector > spaces(&E_space, &B_space); - Hermes::vector > spaces_mutable(&E_space, &B_space); + SpaceSharedPtr B_space(new HcurlSpace(mesh, &bcs_B, P_INIT)); + Hermes::vector > spaces(E_space, B_space); + Hermes::vector > spaces_mutable(E_space, B_space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(spaces)); // Initialize views. @@ -104,10 +104,10 @@ int main(int argc, char* argv[]) { // Perform one Runge-Kutta time step according to the selected Butcher's table. Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step (t = %g s, time_step = %g s, stages: %d).", - current_time, time_step, bt.get_size()); + current_time, time_step, bt.get_size()); bool jacobian_changed = false; bool verbose = true; - + try { runge_kutta.set_time(current_time); @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) // Update time. current_time += time_step; - + } while (current_time < T_FINAL); // Wait for the view to be closed. diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index b9e413f..a8f6f8b 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -60,21 +60,21 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_sln(mesh); - ZeroSolutionVector F_sln(mesh); - Hermes::vector > slns(&E_sln, &F_sln); + MeshFunctionSharedPtr E_sln(new CustomInitialConditionWave(mesh)); + MeshFunctionSharedPtr F_sln(new ZeroSolutionVector(mesh)); + Hermes::vector > slns(E_sln, F_sln); // Initialize the weak formulation. - CustomWeakFormWaveIE wf(time_step, C_SQUARED, &E_sln, &F_sln); - + CustomWeakFormWaveIE wf(time_step, C_SQUARED, E_sln, F_sln); + // Initialize boundary conditions DefaultEssentialBCConst bc_essential("Perfect conductor", 0.0); EssentialBCs bcs(&bc_essential); - // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs, P_INIT)); - HcurlSpace F_space(mesh, &bcs, P_INIT)); - Hermes::vector > spaces = Hermes::vector >(&E_space, &F_space); + SpaceSharedPtr E_space(new HcurlSpace(mesh, &bcs, P_INIT)); + SpaceSharedPtr F_space(new HcurlSpace(mesh, &bcs, P_INIT)); + + Hermes::vector > spaces = Hermes::vector >(E_space, F_space); int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); newton.set_tolerance(NEWTON_TOL); - newton.solve_keep_jacobian(coeff_vec); + newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) { diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp index 286f850..81a890b 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp @@ -84,23 +84,28 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize solutions. - CustomInitialConditionWave E_time_prev(mesh); - ZeroSolutionVector F_time_prev(mesh); - Hermes::vector > slns_time_prev(&E_time_prev, &F_time_prev); - Solution E_time_new, F_time_new; - Hermes::vector > slns_time_new(&E_time_new, &F_time_new); + MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionWave(mesh)); + MeshFunctionSharedPtr F_time_prev(new ZeroSolutionVector(mesh)); + + Hermes::vector > slns_time_prev(E_time_prev, F_time_prev); + + MeshFunctionSharedPtr E_time_new(new Solution); + + MeshFunctionSharedPtr F_time_new(new Solution); + + Hermes::vector > slns_time_new(E_time_new, F_time_new); // Initialize the weak formulation. CustomWeakFormWaveRK wf(C_SQUARED); - + // Initialize boundary conditions DefaultEssentialBCConst bc_essential("Perfect conductor", 0.0); EssentialBCs bcs(&bc_essential); - // Create x- and y- displacement space using the default H1 shapeset. - HcurlSpace E_space(mesh, &bcs, P_INIT)); - HcurlSpace F_space(mesh, &bcs, P_INIT)); - Hermes::vector > spaces(&E_space, &F_space); + SpaceSharedPtr E_space(new HcurlSpace(mesh, &bcs, P_INIT)); + SpaceSharedPtr F_space(new HcurlSpace(mesh, &bcs, P_INIT)); + Hermes::vector > spaces(E_space, F_space); + int ndof = HcurlSpace::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); @@ -123,7 +128,7 @@ int main(int argc, char* argv[]) { // Perform one Runge-Kutta time step according to the selected Butcher's table. Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step (t = %g s, time_step = %g s, stages: %d).", - current_time, time_step, bt.get_size()); + current_time, time_step, bt.get_size()); try { runge_kutta.set_time(current_time); @@ -162,7 +167,7 @@ int main(int argc, char* argv[]) // Update time. current_time += time_step; - + } while (current_time < T_FINAL); // Wait for the view to be closed. diff --git a/2d-advanced/miscellaneous/local-projection-test/main.cpp b/2d-advanced/miscellaneous/local-projection-test/main.cpp index 5a6282e..781120c 100644 --- a/2d-advanced/miscellaneous/local-projection-test/main.cpp +++ b/2d-advanced/miscellaneous/local-projection-test/main.cpp @@ -106,7 +106,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); Solution::vector_to_solution(newton.get_sln_vector(), space, sln); - Solution sln_proj; + MeshFunctionSharedPtr sln_proj(new Solution); LocalProjection::project_local(space, sln, sln_proj, HERMES_H1_NORM); ScalarView view1("Projection", new WinGeom(0, 0, 440, 350)); view1.show(sln_proj); diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 029cbf1..d80cdc4 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -73,7 +73,7 @@ double integrate_over_wall(MeshFunction* meshfn, int marker) double integral = 0.0; Element* e; - MeshSharedPtr mesh,= meshfn->get_mesh(); + MeshSharedPtr mesh = meshfn->get_mesh(); for_all_active_elements(e, mesh) { @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) #else SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - Hermes::vector > spaces(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(xvel_space, yvel_space, p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) p_prev_time); // Initialize weak formulation. - WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); + WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 600, 500)); @@ -170,9 +170,8 @@ int main(int argc, char* argv[]) int num_time_steps = T_FINAL / TAU; for (int ts = 1; ts <= num_time_steps; ts++) { - // Initialize the FE problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); Hermes::Hermes2D::NewtonSolver newton(&dp); diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index c865436..19574eb 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -164,15 +164,14 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_vel_y(Hermes::vector(BDY_LEFT, BDY_BOTTOM, BDY_TOP, BDY_OBSTACLE), 0.0); EssentialBCs bcs_vel_y(&bc_vel_y); - // Spaces for velocity components and pressure. - H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); +SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); +SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else - H1Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(xvel_space, yvel_space, p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -188,23 +187,25 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - Solution xvel_ref_sln, yvel_ref_sln, p_ref_sln; - // Define initial conditions on the coarse mesh-> - ZeroSolution xvel_prev_time(mesh); - ZeroSolution yvel_prev_time(mesh); - ZeroSolution p_prev_time(mesh); + // Define initial conditions on the + MeshFunctionSharedPtr xvel_ref_sln(new Solution()); + MeshFunctionSharedPtr yvel_ref_sln(new Solution()); + MeshFunctionSharedPtr p_ref_sln(new Solution()); + + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); - ZeroSolution xvel_sln(mesh); - ZeroSolution yvel_sln(mesh); - ZeroSolution p_sln(mesh); + MeshFunctionSharedPtr xvel_sln(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_sln(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_sln(new ZeroSolution(mesh)); // Initialize weak formulation. - WeakForm* wf; - wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); + WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -227,7 +228,7 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(&xvel_space, &yvel_space, &p_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space, p_space), current_time); // Periodic global derefinements. if (ts > 1 && ts % UNREF_FREQ == 0) { @@ -242,7 +243,7 @@ int main(int argc, char* argv[]) p_space->assign_dofs(); } - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); Hermes::Hermes2D::NewtonSolver newton(&dp); // Spatial adaptivity loop. Note: xvel_prev_time, yvel_prev_time and pvel_prev_time @@ -257,14 +258,13 @@ int main(int argc, char* argv[]) Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorX(&xvel_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorX(xvel_space, ref_mesh); SpaceSharedPtr ref_xvel_space = refSpaceCreatorX.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorY(&yvel_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorY(yvel_space, ref_mesh); SpaceSharedPtr ref_yvel_space = refSpaceCreatorY.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorP(&p_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorP(p_space, ref_mesh); SpaceSharedPtr ref_p_space = refSpaceCreatorP.create_ref_space(); - Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); // Calculate initial coefficient vector for Newton on the fine mesh-> @@ -272,7 +272,7 @@ int main(int argc, char* argv[]) if (ts == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); - OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), + OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_sln, yvel_sln, p_sln), coeff_vec); } else { @@ -298,26 +298,26 @@ int main(int argc, char* argv[]) }; // Update previous time level solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProj; ogProj.project_global(Hermes::vector >(&xvel_space, &yvel_space, &p_space), - Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln), - Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), + OGProjection ogProj; ogProj.project_global(Hermes::vector >(xvel_space, yvel_space, p_space), + Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), + Hermes::vector >(xvel_sln, yvel_sln, p_sln), Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); //Adapt* adaptivity = new Adapt(ref_spaces); - Adapt* adaptivity = new Adapt(Hermes::vector >(&xvel_space, &yvel_space, &p_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(xvel_space, yvel_space, p_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&xvel_sln, &yvel_sln, &p_sln), - Hermes::vector >(&xvel_ref_sln, &yvel_ref_sln, &p_ref_sln)) * 100.; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(xvel_sln, yvel_sln, p_sln), + Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)) * 100.; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)), + Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the mesh-> @@ -328,7 +328,7 @@ int main(int argc, char* argv[]) done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)) >= NDOF_STOP) done = true; else // Increase the counter of performed adaptivity steps. @@ -338,10 +338,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; delete [] coeff_vec; - - delete ref_xvel_space; - delete ref_yvel_space; - delete ref_p_space; } while (done == false); @@ -359,7 +355,7 @@ int main(int argc, char* argv[]) pview.show(p_prev_time); } - ndof = Space::get_num_dofs(Hermes::vector >(&xvel_space, &yvel_space, &p_space)); + ndof = Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Wait for all views to be closed. diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 48a9f71..6a78a0e 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -106,16 +106,14 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_vel_y(Hermes::vector(BDY_LEFT, BDY_BOTTOM, BDY_TOP, BDY_OBSTACLE), 0.0); EssentialBCs bcs_vel_y(&bc_vel_y); - // Spaces for velocity components and pressure. - H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); + SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else - H1Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - Hermes::vector* > spaces(&xvel_space, &yvel_space, &p_space); - Hermes::vector > spaces(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(xvel_space, yvel_space, p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -131,17 +129,16 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting zero initial conditions."); - ZeroSolution xvel_prev_time(mesh); - ZeroSolution yvel_prev_time(mesh); - ZeroSolution p_prev_time(mesh); + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); Hermes::vector > slns_prev_time = Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); // Initialize weak formulation. - WeakForm* wf; - wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); + WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 750, 240)); @@ -199,11 +196,11 @@ int main(int argc, char* argv[]) if(VTK_VISUALIZATION) { Linearizer lin; - Hermes::vector* > slns_prev_time0 = Hermes::vector* >(xvel_prev_time, yvel_prev_time); - MagFilter mag(slns_prev_time0, Hermes::vector(H2D_FN_VAL, H2D_FN_VAL)); + Hermes::vector > slns_prev_time = Hermes::vector >(xvel_prev_time, yvel_prev_time); + MeshFunctionSharedPtr mag(new MagFilter(slns_prev_time, Hermes::vector(H2D_FN_VAL, H2D_FN_VAL))); std::stringstream ss_vel; ss_vel << "Velocity-" << ts << ".vtk"; - lin.save_solution_vtk(&mag, ss_vel.str().c_str(), "VelocityMagnitude"); + lin.save_solution_vtk(mag, ss_vel.str().c_str(), "VelocityMagnitude"); std::stringstream ss_pres; ss_pres << "Pressure-" << ts << ".vtk"; lin.save_solution_vtk(p_prev_time, ss_pres.str().c_str(), "Pressure"); diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index a8d6701..ca78e5b 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -66,7 +66,7 @@ double integrate_over_wall(MeshFunction* meshfn, int marker) double integral = 0.0; Element* e; - MeshSharedPtr mesh,= meshfn->get_mesh(); + MeshSharedPtr mesh = meshfn->get_mesh(); for_all_active_elements(e, mesh) { @@ -113,15 +113,14 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_x(&bc_vel_x); EssentialBCs bcs_vel_y(&bc_vel_y); - // Spaces for velocity components and pressure. - H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); +SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); +SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else - H1Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space); + Hermes::vector > spaces(xvel_space, yvel_space, p_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -137,17 +136,17 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(mesh); - ZeroSolution yvel_prev_time(mesh); - ZeroSolution p_prev_time(mesh); + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); Hermes::vector > slns_prev_time = Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); // Initialize weak formulation. - WeakForm* wf = new WeakFormNSNewton(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); + WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 600, 500)); @@ -168,7 +167,7 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(&xvel_space, &yvel_space), current_time); + Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space), current_time); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 43050d5..5429b52 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -88,16 +88,15 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_temp_bottom("Bottom", TEMP_BOTTOM); EssentialBCs bcs_temp(&bc_temp_bottom); - // Spaces for velocity components and pressure. - H1Space xvel_space(mesh, &bcs_vel_x, P_INIT_VEL); - H1Space yvel_space(mesh, &bcs_vel_y, P_INIT_VEL); +SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 - L2Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else - H1Space p_space(mesh, P_INIT_PRESSURE); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif - H1Space t_space(mesh, &bcs_temp, P_INIT_TEMP); - Hermes::vector > spaces = Hermes::vector >(&xvel_space, &yvel_space, &p_space, &t_space); + SpaceSharedPtr t_space(new H1Space(mesh, &bcs_temp, P_INIT_TEMP)); + Hermes::vector > spaces(xvel_space, yvel_space, p_space, t_space); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -114,19 +113,19 @@ int main(int argc, char* argv[]) // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); - ZeroSolution xvel_prev_time(mesh); - ZeroSolution yvel_prev_time(mesh); - ZeroSolution p_prev_time(mesh); - ConstantSolution t_prev_time(mesh, TEMP_INIT); + MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); + MeshFunctionSharedPtr t_prev_time(new ConstantSolution(mesh, TEMP_INIT)); Hermes::vector > slns = Hermes::vector >(xvel_prev_time, - yvel_prev_time, p_prev_time, &t_prev_time); + yvel_prev_time, p_prev_time, t_prev_time); // Initialize weak formulation. - WeakForm* wf = new WeakFormRayleighBenard(Pr, Ra, "Top", TEMP_EXT, ALPHA_AIR, time_step, - xvel_prev_time, yvel_prev_time, &t_prev_time); + WeakFormRayleighBenard wf(Pr, Ra, "Top", TEMP_EXT, ALPHA_AIR, time_step, + xvel_prev_time, yvel_prev_time, t_prev_time); // Initialize the FE problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); // Initialize views. VectorView vview("velocity", new WinGeom(0, 0, 1000, 200)); diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp index cc01328..e4d080d 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/definitions.cpp @@ -3,7 +3,7 @@ class ScaledWeakFormPNPCranic : public WeakForm { public: ScaledWeakFormPNPCranic(double* tau, double epsilon, - Solution* C_prev_time, Solution* phi_prev_time) : WeakForm(2) { + MeshFunctionSharedPtr C_prev_time, MeshFunctionSharedPtr phi_prev_time) : WeakForm(2) { for(unsigned int i = 0; i < 2; i++) { ScaledWeakFormPNPCranic::Residual* vector_form = new ScaledWeakFormPNPCranic::Residual(i, tau, epsilon); @@ -154,7 +154,7 @@ class WeakFormPNPCranic : public WeakForm { public: WeakFormPNPCranic(double* tau, double C0, double K, double L, double D, - Solution* C_prev_time, Solution* phi_prev_time) : WeakForm(2) { + MeshFunctionSharedPtr C_prev_time, MeshFunctionSharedPtr phi_prev_time) : WeakForm(2) { for(unsigned int i = 0; i < 2; i++) { WeakFormPNPCranic::Residual* vector_form = new WeakFormPNPCranic::Residual(i, tau, C0, K, L, D); @@ -313,7 +313,7 @@ class WeakFormPNPCranic : public WeakForm { class WeakFormPNPEuler : public WeakForm { public: - WeakFormPNPEuler(double* tau, double C0, double K, double L, double D, Solution* C_prev_time) + WeakFormPNPEuler(double* tau, double C0, double K, double L, double D, MeshFunctionSharedPtr C_prev_time) : WeakForm(2) { for(unsigned int i = 0; i < 2; i++) { WeakFormPNPEuler::Residual* vector_form = diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index 71f58f3..f499b4d 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -5,45 +5,45 @@ #include "timestep_controller.h" /** \addtogroup e_newton_np_timedep_adapt_system Newton Time-dependant System with Adaptivity - \{ - \brief This example shows how to combine the automatic adaptivity with the Newton's method for a nonlinear time-dependent PDE system. - - This example shows how to combine the automatic adaptivity with the - Newton's method for a nonlinear time-dependent PDE system. - The time discretization is done using implicit Euler or - Crank Nicholson method (see parameter TIME_DISCR). - The following PDE's are solved: - Nernst-Planck (describes the diffusion and migration of charged particles): - \f[dC/dt - D*div[grad(C)] - K*C*div[grad(\phi)]=0,\f] - where D and K are constants and C is the cation concentration variable, - phi is the voltage variable in the Poisson equation: - \f[ - div[grad(\phi)] = L*(C - C_0),\f] - where \f$C_0\f$, and L are constant (anion concentration). \f$C_0\f$ is constant - anion concentration in the domain and L is material parameter. - So, the equation variables are phi and C and the system describes the - migration/diffusion of charged particles due to applied voltage. - The simulation domain looks as follows: - \verbatim - Top - +----------+ - | | - Side| |Side - | | - +----------+ - Bottom - \endverbatim - For the Nernst-Planck equation, all the boundaries are natural i.e. Neumann. - Which basically means that the normal derivative is 0: - \f[ BC: -D*dC/dn - K*C*d\phi/dn = 0 \f] - For Poisson equation, boundary 1 has a natural boundary condition - (electric field derivative is 0). - The voltage is applied to the boundaries 2 and 3 (Dirichlet boundaries) - It is possible to adjust system paramter VOLT_BOUNDARY to apply - Neumann boundary condition to 2 (instead of Dirichlet). But by default: - - BC 2: \f$\phi = VOLTAGE\f$ - - BC 3: \f$\phi = 0\f$ - - BC 1: \f$\frac{d\phi}{dn} = 0\f$ - */ +\{ +\brief This example shows how to combine the automatic adaptivity with the Newton's method for a nonlinear time-dependent PDE system. + +This example shows how to combine the automatic adaptivity with the +Newton's method for a nonlinear time-dependent PDE system. +The time discretization is done using implicit Euler or +Crank Nicholson method (see parameter TIME_DISCR). +The following PDE's are solved: +Nernst-Planck (describes the diffusion and migration of charged particles): +\f[dC/dt - D*div[grad(C)] - K*C*div[grad(\phi)]=0,\f] +where D and K are constants and C is the cation concentration variable, +phi is the voltage variable in the Poisson equation: +\f[ - div[grad(\phi)] = L*(C - C_0),\f] +where \f$C_0\f$, and L are constant (anion concentration). \f$C_0\f$ is constant +anion concentration in the domain and L is material parameter. +So, the equation variables are phi and C and the system describes the +migration/diffusion of charged particles due to applied voltage. +The simulation domain looks as follows: +\verbatim +Top ++----------+ +| | +Side| |Side +| | ++----------+ +Bottom +\endverbatim +For the Nernst-Planck equation, all the boundaries are natural i.e. Neumann. +Which basically means that the normal derivative is 0: +\f[ BC: -D*dC/dn - K*C*d\phi/dn = 0 \f] +For Poisson equation, boundary 1 has a natural boundary condition +(electric field derivative is 0). +The voltage is applied to the boundaries 2 and 3 (Dirichlet boundaries) +It is possible to adjust system paramter VOLT_BOUNDARY to apply +Neumann boundary condition to 2 (instead of Dirichlet). But by default: +- BC 2: \f$\phi = VOLTAGE\f$ +- BC 3: \f$\phi = 0\f$ +- BC 1: \f$\frac{d\phi}{dn} = 0\f$ +*/ // Parameters to tweak the amount of output to the console. #define NOSCREENSHOT @@ -190,10 +190,10 @@ int main (int argc, char* argv[]) { // Load the mesh file. - Mesh C_mesh, phi_mesh, basemesh; + MeshSharedPtr C_mesh(new Mesh), phi_mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("small.mesh", basemesh); - + if (SCALED) { bool ret = basemesh->rescale(l, l); if (ret) { @@ -215,18 +215,17 @@ int main (int argc, char* argv[]) { DefaultEssentialBCConst bc_phi_zero(BDY_BOT, scaleVoltage(0.0)); EssentialBCs bcs_phi( - Hermes::vector* >(&bc_phi_voltage, &bc_phi_zero)); + Hermes::vector* >(&bc_phi_voltage, &bc_phi_zero)); - // Spaces for concentration and the voltage. - H1Space C_space(C_mesh, P_INIT)); - H1Space phi_space(MULTIMESH ? &phi_mesh : &C_mesh, &bcs_phi, P_INIT)); + SpaceSharedPtr C_space(new H1Space(C_mesh, P_INIT)); + SpaceSharedPtr phi_space(new H1Space(MULTIMESH ? phi_mesh : C_mesh, &bcs_phi, P_INIT)); - Solution C_sln, C_ref_sln; - Solution phi_sln, phi_ref_sln; + MeshFunctionSharedPtr C_sln(new Solution), C_ref_sln(new Solution); + MeshFunctionSharedPtr phi_sln(new Solution), phi_ref_sln(new Solution); // Assign initial condition to mesh-> - ConstantSolution C_prev_time(&C_mesh, scaleConc(C0)); - ConstantSolution phi_prev_time(MULTIMESH ? &phi_mesh : &C_mesh, 0.0); + MeshFunctionSharedPtr C_prev_time(new ConstantSolution(C_mesh, scaleConc(C0))); + MeshFunctionSharedPtr phi_prev_time(new ConstantSolution(MULTIMESH ? phi_mesh : C_mesh, 0.0)); // XXX not necessary probably if (SCALED) { @@ -237,30 +236,30 @@ int main (int argc, char* argv[]) { WeakForm *wf; if (TIME_DISCR == 2) { if (SCALED) { - wf = new ScaledWeakFormPNPCranic(TAU, epsilon, &C_prev_time, &phi_prev_time); + wf = new ScaledWeakFormPNPCranic(TAU, epsilon, C_prev_time, phi_prev_time); Hermes::Mixins::Loggable::Static::info("Scaled weak form, with time step %g and epsilon %g", *TAU, epsilon); } else { - wf = new WeakFormPNPCranic(TAU, C0, K, L, D, &C_prev_time, &phi_prev_time); + wf = new WeakFormPNPCranic(TAU, C0, K, L, D, C_prev_time, phi_prev_time); } } else { if (SCALED) throw Hermes::Exceptions::Exception("Forward Euler is not implemented for scaled problem"); - wf = new WeakFormPNPEuler(TAU, C0, K, L, D, &C_prev_time); + wf = new WeakFormPNPEuler(TAU, C0, K, L, D, C_prev_time); } - DiscreteProblem dp_coarse(wf, Hermes::vector >(&C_space, &phi_space)); + DiscreteProblem dp_coarse(wf, Hermes::vector >(C_space, phi_space)); NewtonSolver* solver_coarse = new NewtonSolver(&dp_coarse); // Project the initial condition on the FE space to obtain initial // coefficient vector for the Newton's method. Hermes::Mixins::Loggable::Static::info("Projecting to obtain initial vector for the Newton's method."); - int ndof = Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)); + int ndof = Space::get_num_dofs(Hermes::vector >(C_space, phi_space)); double* coeff_vec_coarse = new double[ndof] ; - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&C_space, &phi_space), - Hermes::vector >(&C_prev_time, &phi_prev_time), - coeff_vec_coarse); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(C_space, phi_space), + Hermes::vector >(C_prev_time, phi_prev_time), + coeff_vec_coarse); // Create a selector which will select optimal candidate. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -294,8 +293,8 @@ int main (int argc, char* argv[]) { //View::wait(HERMES_WAIT_KEYPRESS); // Translate the resulting coefficient vector into the Solution sln-> - Solution::vector_to_solutions(solver_coarse->get_sln_vector(), Hermes::vector >(&C_space, &phi_space), - Hermes::vector >(&C_sln, &phi_sln)); + Solution::vector_to_solutions(solver_coarse->get_sln_vector(), Hermes::vector >(C_space, phi_space), + Hermes::vector >(C_sln, phi_sln)); Cview.show(C_sln); phiview.show(phi_sln); @@ -303,7 +302,7 @@ int main (int argc, char* argv[]) { // Cleanup after the Newton loop on the coarse mesh-> delete solver_coarse; delete[] coeff_vec_coarse; - + // Time stepping loop. PidTimestepController pid(scaleTime(T_FINAL), true, scaleTime(INIT_TAU)); TAU = pid.timestep; @@ -334,19 +333,18 @@ int main (int argc, char* argv[]) { // Construct globally refined reference mesh // and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreatorC(&C_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorC(C_mesh); MeshSharedPtr ref_C_mesh = refMeshCreatorC.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorC(&C_space, ref_C_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorC(C_space, ref_C_mesh); SpaceSharedPtr ref_C_space = refSpaceCreatorC.create_ref_space(); - Mesh::ReferenceMeshCreator refMeshCreatorPhi(&phi_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorPhi(phi_mesh); MeshSharedPtr ref_phi_mesh = refMeshCreatorPhi.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorPhi(&phi_space, ref_phi_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorPhi(phi_space, ref_phi_mesh); SpaceSharedPtr ref_phi_space = refSpaceCreatorPhi.create_ref_space(); - Hermes::vector > ref_spaces(ref_C_space, ref_phi_space); Hermes::vector > ref_spaces(ref_C_space, ref_phi_space); DiscreteProblem* dp = new DiscreteProblem(wf, ref_spaces); @@ -360,20 +358,14 @@ int main (int argc, char* argv[]) { if (as == 1 && pid.get_timestep_number() == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, - Hermes::vector >(&C_sln, &phi_sln), - coeff_vec); + Hermes::vector >(C_sln, phi_sln), + coeff_vec); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, - Hermes::vector >(&C_ref_sln, &phi_ref_sln), - coeff_vec); - } - if (as > 1) { - // Now deallocate the previous mesh - Hermes::Mixins::Loggable::Static::info("Delallocating the previous mesh"); - delete C_ref_sln->get_mesh(); - delete phi_ref_sln->get_mesh(); + Hermes::vector >(C_ref_sln, phi_ref_sln), + coeff_vec); } // Newton's loop on the fine mesh-> @@ -392,33 +384,33 @@ int main (int argc, char* argv[]) { // Store the result in ref_sln-> Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, - Hermes::vector >(&C_ref_sln, &phi_ref_sln)); + Hermes::vector >(C_ref_sln, phi_ref_sln)); // Projecting reference solution onto the coarse mesh Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(&C_space, &phi_space), - Hermes::vector >(&C_ref_sln, &phi_ref_sln), - Hermes::vector >(&C_sln, &phi_sln), - matrix_solver); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(C_space, phi_space), + Hermes::vector >(C_ref_sln, phi_ref_sln), + Hermes::vector >(C_sln, phi_sln), + matrix_solver); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(&C_space, &phi_space)); + Adapt* adaptivity = new Adapt(Hermes::vector >(C_space, phi_space)); Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(&C_sln, &phi_sln), - Hermes::vector >(&C_ref_sln, &phi_ref_sln), &err_est_rel) * 100; + double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(C_sln, phi_sln), + Hermes::vector >(C_ref_sln, phi_ref_sln), &err_est_rel) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", - C_space->get_num_dofs(), ref_C_space->get_num_dofs()); + C_space->get_num_dofs(), ref_C_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%", err_est_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", - phi_space->get_num_dofs(), ref_phi_space->get_num_dofs()); + phi_space->get_num_dofs(), ref_phi_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%", err_est_rel[1]*100); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)), - Space::get_num_dofs(ref_spaces), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(C_space, phi_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); // If err_est too large, adapt the mesh-> if (err_est_rel_total < ERR_STOP) done = true; @@ -427,10 +419,10 @@ int main (int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - + Hermes::Mixins::Loggable::Static::info("Adapted..."); - if (Space::get_num_dofs(Hermes::vector >(&C_space, &phi_space)) >= NDOF_STOP) + if (Space::get_num_dofs(Hermes::vector >(C_space, phi_space)) >= NDOF_STOP) done = true; else as++; } @@ -439,21 +431,21 @@ int main (int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Visualization procedures: C"); char title[100]; sprintf(title, "Solution[C], step# %d, step size %g, time %g, phys time %g", - pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); + pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); Cview.set_title(title); Cview.show(C_ref_sln); sprintf(title, "Mesh[C], step# %d, step size %g, time %g, phys time %g", - pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); + pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); Cordview.set_title(title); Cordview.show(C_space); - + Hermes::Mixins::Loggable::Static::info("Visualization procedures: phi"); sprintf(title, "Solution[phi], step# %d, step size %g, time %g, phys time %g", - pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); + pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); phiview.set_title(title); phiview.show(phi_ref_sln); sprintf(title, "Mesh[phi], step# %d, step size %g, time %g, phys time %g", - pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); + pid.get_timestep_number(), *TAU, pid.get_time(), physTime(pid.get_time())); phiordview.set_title(title); phiordview.show(phi_space); //View::wait(HERMES_WAIT_KEYPRESS); @@ -461,15 +453,13 @@ int main (int argc, char* argv[]) { // Clean up. delete solver; delete adaptivity; - delete ref_C_space; - delete ref_phi_space; delete dp; delete [] coeff_vec; } while (done == false); - pid.end_step(Hermes::vector > (&C_ref_sln, &phi_ref_sln), - Hermes::vector > (&C_prev_time, &phi_prev_time)); + pid.end_step(Hermes::vector > (C_ref_sln, phi_ref_sln), + Hermes::vector > (C_prev_time, phi_prev_time)); // TODO! Time step reduction when necessary. // Copy last reference solution into sln_prev_time diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h index 57c5501..da5ab25 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h @@ -82,7 +82,7 @@ bool PidTimestepController::end_step(Hermes::vector::calc_rel_error(solutions[i], prev_solutions[i], HERMES_H1_NORM); + double rel_error = Global::calc_rel_error(solutions[i].get(), prev_solutions[i].get(), HERMES_H1_NORM); max_rel_error = (rel_error > max_rel_error) ? rel_error : max_rel_error; Hermes::Mixins::Loggable::Static::info("Solution[%i]: rel error %g, largest relative error %g", diff --git a/2d-advanced/neutronics/4-group-adapt/definitions.cpp b/2d-advanced/neutronics/4-group-adapt/definitions.cpp index 60e90c0..a7959cc 100644 --- a/2d-advanced/neutronics/4-group-adapt/definitions.cpp +++ b/2d-advanced/neutronics/4-group-adapt/definitions.cpp @@ -56,7 +56,7 @@ double integrate(MeshFunction* sln, std::string area) double integral = 0.0; Element* e; - Mesh* mesh = const_cast(sln->get_mesh()); + MeshSharedPtr mesh = const_cast(sln->get_mesh()); int marker = mesh->get_element_markers_conversion().get_internal_marker(area).marker; for_all_active_elements(e, mesh) @@ -86,7 +86,7 @@ int get_num_of_neg(MeshFunction *sln) Quad2D* quad = &g_quad_2d_std; sln->set_quad_2d(quad); Element* e; - const Mesh* mesh = sln->get_mesh(); + const MeshSharedPtr mesh = sln->get_mesh(); int n = 0; @@ -122,7 +122,7 @@ int power_iteration(const MaterialPropertyMaps& matprop, int G = spaces.size(); // Initialize the discrete problem. - DiscreteProblem dp(wf, spaces); + DiscreteProblem dp(&wf, spaces); int ndof = Space::get_num_dofs(spaces); // The following variables will store pointers to solutions obtained at each iteration and will be needed for diff --git a/2d-advanced/neutronics/4-group-adapt/main.cpp b/2d-advanced/neutronics/4-group-adapt/main.cpp index 3656699..8e8543f 100644 --- a/2d-advanced/neutronics/4-group-adapt/main.cpp +++ b/2d-advanced/neutronics/4-group-adapt/main.cpp @@ -149,16 +149,16 @@ int main(int argc, char* argv[]) { coarse_solutions.push_back(new Solution()); fine_solutions.push_back(new Solution()); - power_iterates.push_back(new ConstantSolution(meshes[g], 1.0)); + power_iterates.push_back(new ConstantSolution(meshes[g], 1.0));SpaceSharedPtr space1(meshes[0], P_INIT[0]); + H1Space space2(meshes[1], P_INIT[1]); + H1Space space3(meshes[2], P_INIT[2]); + H1Space space4(new } // Create the approximation spaces with the default shapeset. - H1Space space1(meshes[0], P_INIT[0]); - H1Space space2(meshes[1], P_INIT[1]); - H1Space space3(meshes[2], P_INIT[2]); - H1Space space4(meshes[3], P_INIT[3]); - Hermes::vector*> const_spaces(&space1, &space2, &space3, &space4); - Hermes::vector*> spaces(&space1, &space2, &space3, &space4); + H1Space(meshes[3], P_INIT[3])); +SpaceSharedPtr*> const_spaces(new Hermes::vector(&space1, &space2, &space3, &space4)); +SpaceSharedPtr*> spaces(&space1, &space2, &space3, &space4); // Initialize the weak formulation. CustomWeakForm wf(matprop, power_iterates, k_eff, bdy_vacuum); @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) OrderView oview1("Mesh for group 1", new WinGeom(1300, 500, 340, 500)); OrderView oview2("Mesh for group 2", new WinGeom(1650, 500, 340, 500)); OrderView oview3("Mesh for group 3", new WinGeom(2000, 500, 340, 500)); - OrderView oview4("Mesh for group 4", new WinGeom(2350, 500, 340, 500)); + OrderView oview4("Mesh for group 4", new WinGeom(new Hermes::vector(2350, 500, 340, 500))); */ Hermes::vector sviews(&view1, &view2, &view3, &view4); diff --git a/2d-advanced/neutronics/4-group/definitions.cpp b/2d-advanced/neutronics/4-group/definitions.cpp index cab97d4..41478e6 100644 --- a/2d-advanced/neutronics/4-group/definitions.cpp +++ b/2d-advanced/neutronics/4-group/definitions.cpp @@ -22,7 +22,7 @@ double integrate(MeshFunction* sln, std::string area) double integral = 0.0; Element* e; - Mesh* mesh = const_cast(sln->get_mesh()); + MeshSharedPtr mesh = const_cast(sln->get_mesh()); int marker = mesh->get_element_markers_conversion().get_internal_marker(area).marker; for_all_active_elements(e, mesh) diff --git a/2d-advanced/neutronics/4-group/definitions.h b/2d-advanced/neutronics/4-group/definitions.h index cb41db2..046bcb4 100644 --- a/2d-advanced/neutronics/4-group/definitions.h +++ b/2d-advanced/neutronics/4-group/definitions.h @@ -16,7 +16,7 @@ class CustomWeakForm : public DefaultWeakFormSourceIteration public: CustomWeakForm( const Hermes::Hermes2D::WeakFormsNeutronics::Multigroup::MaterialProperties::Diffusion::MaterialPropertyMaps& matprop, - Hermes::vector* >& iterates, + Hermes::vector >& iterates, double init_keff, std::string bdy_vacuum); }; diff --git a/2d-advanced/neutronics/4-group/main.cpp b/2d-advanced/neutronics/4-group/main.cpp index e4f404e..ffd5a70 100644 --- a/2d-advanced/neutronics/4-group/main.cpp +++ b/2d-advanced/neutronics/4-group/main.cpp @@ -78,12 +78,12 @@ int main(int argc, char* argv[]) Hermes::vector > iterates(&iter1, &iter2, &iter3, &iter4); - // Create H1 spaces with default shapesets. - H1Space space1(&mesh, P_INIT_1); +SpaceSharedPtr space1(&mesh, P_INIT_1); H1Space space2(&mesh, P_INIT_2); H1Space space3(&mesh, P_INIT_3); - H1Space space4(&mesh, P_INIT_4); - Hermes::vector* > spaces(&space1, &space2, &space3, &space4); + H1Space space4(new // Create H1 spaces with default shapesets. + H1Space(&mesh, P_INIT_4)); +SpaceSharedPtr* > spaces(new Hermes::vector(&space1, &space2, &space3, &space4)); int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); diff --git a/2d-advanced/neutronics/iron-water/main.cpp b/2d-advanced/neutronics/iron-water/main.cpp index 73e4994..f56ed3f 100644 --- a/2d-advanced/neutronics/iron-water/main.cpp +++ b/2d-advanced/neutronics/iron-water/main.cpp @@ -108,9 +108,9 @@ int main(int argc, char* argv[]) // Set essential boundary conditions. DefaultEssentialBCConst bc_essential(ZERO_FLUX_BOUNDARY, 0.0); EssentialBCs bcs(&bc_essential); - +SpaceSharedPtr space(new // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); + H1Space(&mesh, &bcs, P_INIT)); // Initialize coarse and fine mesh solution. Solution sln, ref_sln; @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) Mesh::ReferenceMeshCreator refMeshCreator(&mesh); Mesh* ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(&space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); Space* ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); @@ -171,12 +171,12 @@ int main(int argc, char* argv[]) } // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); OGProjection ogProjection; - ogProjection.project_global(&space, &ref_sln, &sln); + ogProjection.project_global(space, &ref_sln, &sln); // Visualize the solution and mesh. sview.show(&sln); @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt adaptivity(&space); bool solutions_for_adapt = true; - double err_est_rel = adaptivity.calc_err_est(&sln, &ref_sln, solutions_for_adapt, + double err_est_rel = adaptivity.calc_err_est(sln, &ref_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100; // Report results. @@ -218,7 +218,7 @@ int main(int argc, char* argv[]) // Show the fine mesh solution - final result. sview.set_title("Fine mesh solution"); sview.show_mesh(false); - sview.show(&ref_sln); + sview.show(ref_sln); // Wait for all views to be closed. Views::View::wait(); diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index 7b53697..4a5c1a1 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -246,13 +246,6 @@ int main(int argc, char* argv[]) } if (space->get_num_dofs() >= NDOF_STOP) done = true; - - // Keep the mesh from final step to allow further work with the final fine mesh solution. - if(done == false) - { - delete ref_space->get_mesh(); - - } } while (done == false); diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index e887435..0bbab5d 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the Solution sln-> - Solution::vector_to_solution(newton.get_sln_vector(), space, &h_time_prev); + Solution::vector_to_solution(newton.get_sln_vector(), space, h_time_prev); // Visualize the solution. char title[100]; diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index d2fa08a..57c3134 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(mesh), h_iter_prev(mesh); + MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)), h_iter_prev(new ZeroSolution(mesh)); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) // Initialize the weak formulation. double current_time = 0; - CustomWeakFormRichardsIEPicard wf(time_step, &h_time_prev, &h_iter_prev, constitutive_relations); + CustomWeakFormRichardsIEPicard wf(time_step, h_time_prev, h_iter_prev, constitutive_relations); // Initialize the FE problem. DiscreteProblem dp(&wf, space); @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) } // Translate the coefficient vector into a Solution. - Solution::vector_to_solution(picard.get_sln_vector(), space, &h_iter_prev); + Solution::vector_to_solution(picard.get_sln_vector(), space, h_iter_prev); // Increase current time and time step counter. current_time += time_step; diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index a6b4d63..94185e8 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof_coarse = %d.", ndof_coarse); // Zero initial solution. This is why we use H_OFFSET. - ZeroSolution h_time_prev(mesh), h_time_new(mesh); + MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)), h_time_new(new ZeroSolution(mesh)); // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; @@ -231,7 +231,7 @@ int main(int argc, char* argv[]) runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL); - runge_kutta.rk_time_step_newton(&h_time_prev, &h_time_new); + runge_kutta.rk_time_step_newton(h_time_prev, h_time_new); } catch(Exceptions::Exception& e) { @@ -240,14 +240,14 @@ int main(int argc, char* argv[]) } // Project the fine mesh solution onto the coarse mesh-> - Solution sln_coarse; + MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - OGProjection ogProjection; ogProjection.project_global(space, &h_time_new, sln_coarse); + OGProjection ogProjection; ogProjection.project_global(space, h_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt* adaptivity = new Adapt(space); - double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, &h_time_new) * 100; + double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, h_time_new) * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", @@ -272,10 +272,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; - if(!done) - { - delete h_time_new.get_mesh(); - } } while (done == false); @@ -296,8 +292,6 @@ int main(int argc, char* argv[]) ordview.show(space); // Copy last reference solution into h_time_prev. - if(ts > 1) - delete h_time_prev.get_mesh(); h_time_prev->copy(h_time_new); // Increase current time and counter of time steps. diff --git a/2d-advanced/richards/basic-rk-newton/main.cpp b/2d-advanced/richards/basic-rk-newton/main.cpp index 1b0618e..228d401 100644 --- a/2d-advanced/richards/basic-rk-newton/main.cpp +++ b/2d-advanced/richards/basic-rk-newton/main.cpp @@ -106,7 +106,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - ZeroSolution h_time_prev(mesh), h_time_new(mesh); + MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)), h_time_new(new ZeroSolution(mesh)); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL); - runge_kutta.rk_time_step_newton(&h_time_prev, &h_time_new); + runge_kutta.rk_time_step_newton(h_time_prev, h_time_new); } catch(Exceptions::Exception& e) { diff --git a/2d-advanced/richards/capillary-barrier-adapt/definitions.h b/2d-advanced/richards/capillary-barrier-adapt/definitions.h index b8de597..ef77b69 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/definitions.h +++ b/2d-advanced/richards/capillary-barrier-adapt/definitions.h @@ -70,7 +70,7 @@ class ExactSolutionPoisson : public ExactSolutionScalar class WeakFormRichardsNewtonEuler : public WeakForm { public: - WeakFormRichardsNewtonEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) + WeakFormRichardsNewtonEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, MeshSharedPtr mesh) : WeakForm(1), mesh(mesh), relations(relations) { JacobianFormNewtonEuler* jac_form = new JacobianFormNewtonEuler(0, 0, relations, tau); jac_form->set_ext(prev_time_sln); @@ -182,7 +182,7 @@ class WeakFormRichardsNewtonEuler : public WeakForm ConstitutiveRelationsGenuchtenWithLayer* relations; }; - Mesh* mesh; + MeshSharedPtr mesh; ConstitutiveRelationsGenuchtenWithLayer* relations; @@ -198,7 +198,7 @@ class WeakFormRichardsNewtonEuler : public WeakForm class WeakFormRichardsNewtonCrankNicolson : public WeakForm { public: - WeakFormRichardsNewtonCrankNicolson(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { + WeakFormRichardsNewtonCrankNicolson(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_time_sln, MeshSharedPtr mesh) : WeakForm(1), relations(relations), mesh(mesh) { JacobianFormNewtonCrankNicolson* jac_form = new JacobianFormNewtonCrankNicolson(0, 0, relations, tau); jac_form->set_ext(prev_time_sln); add_matrix_form(jac_form); @@ -305,7 +305,7 @@ class WeakFormRichardsNewtonCrankNicolson : public WeakForm ConstitutiveRelationsGenuchtenWithLayer* relations; }; - Mesh* mesh; + MeshSharedPtr mesh; ConstitutiveRelationsGenuchtenWithLayer* relations; @@ -321,7 +321,7 @@ class WeakFormRichardsNewtonCrankNicolson : public WeakForm class WeakFormRichardsPicardEuler : public WeakForm { public: - WeakFormRichardsPicardEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_picard_sln, MeshFunctionSharedPtr prev_time_sln, Mesh* mesh) : WeakForm(1), relations(relations), mesh(mesh) { + WeakFormRichardsPicardEuler(ConstitutiveRelationsGenuchtenWithLayer* relations, double tau, MeshFunctionSharedPtr prev_picard_sln, MeshFunctionSharedPtr prev_time_sln, MeshSharedPtr mesh) : WeakForm(1), relations(relations), mesh(mesh) { JacobianFormPicardEuler* jac_form = new JacobianFormPicardEuler(0, 0, relations, tau); jac_form->set_ext(prev_picard_sln); add_matrix_form(jac_form); @@ -410,7 +410,7 @@ class WeakFormRichardsPicardEuler : public WeakForm ConstitutiveRelationsGenuchtenWithLayer* relations; }; - Mesh* mesh; + MeshSharedPtr mesh; ConstitutiveRelationsGenuchtenWithLayer* relations; diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 4e29586..19f6cc3 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -309,7 +309,7 @@ int main(int argc, char* argv[]) space->set_uniform_order(P_INIT); break; case 3: mesh->unrefine_all_elements(); - //space->adjust_element_order(-1, P_INIT)); + //space->adjust_element_order(-1, P_INIT); space->adjust_element_order(-1, -1, P_INIT, P_INIT); break; default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); @@ -349,8 +349,6 @@ int main(int argc, char* argv[]) else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, coeff_vec); - if(as > 1) - delete ref_sln->get_mesh(); } // Initialize the FE problem. @@ -516,12 +514,10 @@ int main(int argc, char* argv[]) // Save complete Solution. char* filename = new char[100]; sprintf(filename, "outputs/tsln_%f.dat", current_time); - sln->save(filename); - Hermes::Mixins::Loggable::Static::info("Solution at time %g saved to file %s.", current_time, filename); // Copy new reference level solution into sln_prev_time // This starts new time step. - sln_prev_timecopy(ref_sln); + sln_prev_time->copy(ref_sln); // Updating time step. Note that time_step might have been reduced during adaptivity. current_time += time_step; diff --git a/2d-advanced/richards/capillary-barrier-rk/main.cpp b/2d-advanced/richards/capillary-barrier-rk/main.cpp index b875b34..26448fe 100644 --- a/2d-advanced/richards/capillary-barrier-rk/main.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/main.cpp @@ -216,7 +216,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Convert initial condition into a Solution. - ZeroSolution h_time_prev(mesh), h_time_new(mesh), time_error_fn(mesh); + MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)), h_time_new(new ZeroSolution(mesh)), time_error_fn(new ZeroSolution(mesh)); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); @@ -263,8 +263,7 @@ int main(int argc, char* argv[]) runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL); - runge_kutta.rk_time_step_newton(&h_time_prev, - &h_time_new, &time_error_fn); + runge_kutta.rk_time_step_newton(h_time_prev, h_time_new, time_error_fn); } catch(Exceptions::Exception& e) { @@ -290,7 +289,7 @@ int main(int argc, char* argv[]) // reduced and the entire time step repeated. If yes, then another // check is run, and if the relative error is very low, time step // is increased. - double rel_err_time = Global::calc_norm(&time_error_fn, HERMES_H1_NORM) / Global::calc_norm(&h_time_new, HERMES_H1_NORM) * 100; + double rel_err_time = Global::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / Global::calc_norm(h_time_new.get(), HERMES_H1_NORM) * 100; Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%%", rel_err_time); if (rel_err_time > time_tol_upper) { Hermes::Mixins::Loggable::Static::info("rel_err_time above upper limit %g%% -> decreasing time step from %g to %g days and repeating time step.", @@ -320,8 +319,6 @@ int main(int argc, char* argv[]) // Save complete Solution. char filename[100]; sprintf(filename, "outputs/tsln_%f.dat", current_time); - h_time_new.save(filename); - Hermes::Mixins::Loggable::Static::info("Solution at time %g saved to file %s.", current_time, filename); // Save solution for the next time step. h_time_prev->copy(h_time_new); diff --git a/2d-advanced/richards/seepage-adapt/main.cpp b/2d-advanced/richards/seepage-adapt/main.cpp index bdb68f2..e1c3be7 100644 --- a/2d-advanced/richards/seepage-adapt/main.cpp +++ b/2d-advanced/richards/seepage-adapt/main.cpp @@ -167,13 +167,12 @@ int main(int argc, char* argv[]) BCValues bc_values(&TIME); bc_values.add_timedep_function(BDY_3, essential_bc_values); - // Create an H1 space with default shapeset. - H1Space space(&mesh, &bc_types, &bc_values, P_INIT); +SpaceSharedPtr space(new // Create an H1 space with default shapeset. + H1Space(&mesh, &bc_types, &bc_values, P_INIT)); int ndof = Space::get_num_dofs(&space); info("ndof = %d.", ndof); - // Create an H1 space for the initial coarse mesh solution. - H1Space init_space(&basemesh, &bc_types, &bc_values, P_INIT); +SpaceSharedPtr init_space(&basemesh, &bc_types, &bc_values, P_INIT); // Create a selector which will select optimal candidate. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -190,24 +189,25 @@ int main(int argc, char* argv[]) view_init->fix_scale_width(80); // Adapt mesh to represent initial condition with given accuracy. - info("Mesh adaptivity to an exact function:"); + info(new // Create an H1 space for the initial coarse mesh solution. + H1Space("Mesh adaptivity to an exact function:")); int as = 1; bool done = false; do { // Setup space for the reference solution. - Space*rspace = Space::construct_refined_space(&init_space); + Space*rspace = Space::construct_refined_space(init_space); // Assign the function f() to the fine mesh. ref_sln.set_exact(rspace->get_mesh(), init_cond); // Project the function f() on the coarse mesh. - OGProjection::project_global(&init_space, &ref_sln, &sln_prev_time, matrix_solver); + OGProjection::project_global(init_space, ref_sln, &sln_prev_time, matrix_solver); // Calculate element errors and total error estimate. - Adapt adaptivity(&init_space); - double err_est_rel = adaptivity.calc_err_est(&sln_prev_time, &ref_sln) * 100; + Adapt adaptivity(init_space); + double err_est_rel = adaptivity.calc_err_est(sln_prev_time, &ref_sln) * 100; - info("Step %d, ndof %d, proj_error %g%%", as, Space::get_num_dofs(&init_space), err_est_rel); + info("Step %d, ndof %d, proj_error %g%%", as, Space::get_num_dofs(init_space), err_est_rel); // If err_est_rel too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; @@ -215,13 +215,13 @@ int main(int argc, char* argv[]) double to_be_processed = 0; done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY, to_be_processed); - if (Space::get_num_dofs(&init_space) >= NDOF_STOP) done = true; + if (Space::get_num_dofs(init_space) >= NDOF_STOP) done = true; view_init->show(&sln_prev_time); char title_init[100]; sprintf(title_init, "Initial mesh, step %d", as); ordview_init->set_title(title_init); - ordview_init->show(&init_space); + ordview_init->show(init_space); } as++; } @@ -319,7 +319,7 @@ int main(int argc, char* argv[]) } else { info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh."); - OGProjection::project_global(ref_space, &ref_sln, coeff_vec, matrix_solver); + OGProjection::project_global(ref_space, ref_sln, coeff_vec, matrix_solver); delete ref_sln.get_mesh(); } @@ -334,22 +334,22 @@ int main(int argc, char* argv[]) NEWTON_TOL, NEWTON_MAX_ITER, verbose)) error("Newton's iteration failed."); // Translate the resulting coefficient vector into the actual solutions. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln); + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution on the coarse mesh. info("Projecting fine mesh solution on coarse mesh for error calculation."); - OGProjection::project_global(&space, &ref_sln, &sln, matrix_solver); + OGProjection::project_global(space, &ref_sln, &sln, matrix_solver); // Calculate element errors. info("Calculating error estimate."); Adapt* adaptivity = new Adapt(&space, HERMES_H1_NORM); // Calculate error estimate wrt. fine mesh solution. - double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100; + double err_est_rel = adaptivity->calc_err_est(sln, &ref_sln) * 100; // Report results. info("ndof_coarse: %d, ndof_fine: %d, space_err_est_rel: %g%%", - Space::get_num_dofs(&space), Space::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // Add entries to convergence graphs. graph_time_err_est.add_values(ts*TAU, err_est_rel); @@ -388,7 +388,7 @@ int main(int argc, char* argv[]) ordview.show(&space); // Copy new time level solution into sln_prev_time. - sln_prev_time.copy(&ref_sln); + sln_prev_time.copy(ref_sln); } // Wait for all views to be closed. diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp index 6bcd99e..9e31194 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Convert initial condition into a Solution >. - CustomInitialCondition psi_time_prev(mesh); + MeshFunctionSharedPtr > psi_time_prev(new CustomInitialCondition(mesh)); // Initialize the weak formulation. double current_time = 0; @@ -163,7 +163,7 @@ int main(int argc, char* argv[]) SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); - + // Initialize the FE problem. DiscreteProblem > dp(&wf, space); @@ -187,8 +187,10 @@ int main(int argc, char* argv[]) time_error_view.fix_scale_width(60); ScalarView space_error_view("Spatial error", new WinGeom(445, 400, 440, 350)); space_error_view.fix_scale_width(50); - RealFilter real(&psi_time_prev); - ImagFilter imag(&psi_time_prev); + MeshFunctionSharedPtr real(new RealFilter(psi_time_prev)); + + MeshFunctionSharedPtr imag(new ImagFilter(psi_time_prev)); + sview_real.show(real); sview_imag.show(imag); ord_view.show(space); @@ -196,12 +198,12 @@ int main(int argc, char* argv[]) // Graph for time step history. SimpleGraph time_step_graph; if (ADAPTIVE_TIME_STEP_ON) Hermes::Mixins::Loggable::Static::info("Time step history will be saved to file time_step_history.dat."); - + // Time stepping: int num_time_steps = (int)(T_FINAL/time_step + 0.5); for(int ts = 1; ts <= num_time_steps; ts++) - // Time stepping loop. - double current_time = 0.0; int ts = 1; + // Time stepping loop. + double current_time = 0.0; int ts = 1; do { Hermes::Mixins::Loggable::Static::info("Begin time step %d.", ts); @@ -210,16 +212,16 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); switch (UNREF_METHOD) { - case 1: mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - break; - case 2: space->unrefine_all_mesh_elements(); - space->set_uniform_order(P_INIT); - break; - case 3: space->unrefine_all_mesh_elements(); - space->adjust_element_order(-1, -1, P_INIT, P_INIT); - break; - default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); + case 1: mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + break; + case 2: space->unrefine_all_mesh_elements(); + space->set_uniform_order(P_INIT); + break; + case 3: space->unrefine_all_mesh_elements(); + space->adjust_element_order(-1, -1, P_INIT, P_INIT); + break; + default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } ndof = Space >::get_num_dofs(space); @@ -228,11 +230,10 @@ int main(int argc, char* argv[]) // Spatial adaptivity loop. Note: psi_time_prev must not be // changed during spatial adaptivity. - Solution > ref_sln; - Solution >* time_error_fn; - if (bt.is_embedded() == true) time_error_fn = new Solution >(mesh); - else time_error_fn = NULL; - bool done = false; int as = 1; + MeshFunctionSharedPtr > ref_sln(new Solution >()); + MeshFunctionSharedPtr > time_error_fn(new Solution >); + bool done = false; + int as = 1; double err_est; do { // Construct globally refined reference mesh and setup reference space-> @@ -244,12 +245,12 @@ int main(int argc, char* argv[]) // Initialize discrete problem on reference mesh-> DiscreteProblem >* ref_dp = new DiscreteProblem >(&wf, ref_space); - + RungeKutta > runge_kutta(&wf, ref_space, &bt); // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, time step = %g s, stages: %d).", - current_time, time_step, bt.get_size()); + current_time, time_step, bt.get_size()); bool verbose = true; try @@ -258,7 +259,7 @@ int main(int argc, char* argv[]) runge_kutta.set_time_step(time_step); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); runge_kutta.set_tolerance(NEWTON_TOL_FINE); - runge_kutta.rk_time_step_newton(&psi_time_prev, ref_sln, time_error_fn); + runge_kutta.rk_time_step_newton(psi_time_prev, ref_sln, time_error_fn); } catch(Exceptions::Exception& e) { @@ -267,7 +268,7 @@ int main(int argc, char* argv[]) } /* If ADAPTIVE_TIME_STEP_ON == true, estimate temporal error. - If too large or too small, then adjust it and restart the time step. */ + If too large or too small, then adjust it and restart the time step. */ double rel_err_time = 0; if (bt.is_embedded() == true) { @@ -278,12 +279,14 @@ int main(int argc, char* argv[]) sprintf(title, "Temporal error est, spatial adaptivity step %d", as); time_error_view.set_title(title); time_error_view.show_mesh(false); - RealFilter abs_time(time_error_fn); - AbsFilter abs_tef(&abs_time); + MeshFunctionSharedPtr abs_time(new RealFilter(time_error_fn)); + + MeshFunctionSharedPtr abs_tef(new AbsFilter(abs_time)); + time_error_view.show(abs_tef); - rel_err_time = Global >::calc_norm(time_error_fn, HERMES_H1_NORM) / - Global >::calc_norm(ref_sln, HERMES_H1_NORM) * 100; + rel_err_time = Global >::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / + Global >::calc_norm(ref_sln.get(), HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } @@ -291,9 +294,9 @@ int main(int argc, char* argv[]) if (rel_err_time > TIME_ERR_TOL_UPPER) { Hermes::Mixins::Loggable::Static::info("rel_err_time %g%% is above upper limit %g%%", rel_err_time, TIME_ERR_TOL_UPPER); Hermes::Mixins::Loggable::Static::info("Decreasing time step from %g to %g s and restarting time step.", - time_step, time_step * TIME_STEP_DEC_RATIO); + time_step, time_step * TIME_STEP_DEC_RATIO); time_step *= TIME_STEP_DEC_RATIO; - + delete ref_dp; continue; } @@ -301,7 +304,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%% is below lower limit %g%%", rel_err_time, TIME_ERR_TOL_LOWER); Hermes::Mixins::Loggable::Static::info("Increasing time step from %g to %g s.", time_step, time_step * TIME_STEP_INC_RATIO); time_step *= TIME_STEP_INC_RATIO; - + delete ref_dp; continue; } @@ -320,17 +323,20 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); // Project the fine mesh solution onto the coarse mesh-> - Solution > sln; + MeshFunctionSharedPtr > sln(new Solution >); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); - DiffFilter >* space_error_fn = new DiffFilter >(Hermes::vector >*>(ref_sln, sln)); + MeshFunctionSharedPtr > space_error_fn(new DiffFilter >(Hermes::vector > >(ref_sln, sln))); + space_error_view.set_title(title); space_error_view.show_mesh(false); - RealFilter abs_space(space_error_fn); - AbsFilter abs_sef(&abs_space); + + MeshFunctionSharedPtr abs_space(new RealFilter(space_error_fn)); + MeshFunctionSharedPtr abs_sef(new AbsFilter(abs_space)); + space_error_view.show(abs_sef); // Calculate element errors and spatial error estimate. @@ -340,7 +346,7 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", - Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_rel_space); + Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_rel_space); // If err_est too large, adapt the mesh-> if (err_rel_space < SPACE_ERR_TOL) done = true; @@ -355,30 +361,21 @@ int main(int argc, char* argv[]) // Increase the counter of performed adaptivity steps. as++; } - + // Clean up. delete adaptivity; - if(!done) - { - delete ref_space->get_mesh(); - - } delete ref_dp; - delete space_error_fn; } while (done == false); - // Clean up. - if (time_error_fn != NULL) delete time_error_fn; - // Visualize the solution and mesh-> char title[100]; sprintf(title, "Solution - real part, Time %3.2f s", current_time); sview_real.set_title(title); sprintf(title, "Solution - imaginary part, Time %3.2f s", current_time); sview_imag.set_title(title); - RealFilter real(ref_sln); - ImagFilter imag(ref_sln); + MeshFunctionSharedPtr real(new RealFilter(ref_sln)); + MeshFunctionSharedPtr imag(new ImagFilter(ref_sln)); sview_real.show(real); sview_imag.show(imag); sprintf(title, "Mesh, time %g s", current_time); diff --git a/2d-advanced/schroedinger/gross-pitaevski/main.cpp b/2d-advanced/schroedinger/gross-pitaevski/main.cpp index 85d9927..32150b7 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/main.cpp @@ -78,8 +78,8 @@ int main(int argc, char* argv[]) for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Convert initial condition into a Solution >. - CustomInitialCondition psi_time_prev(mesh); - Solution > psi_time_new(mesh); + MeshFunctionSharedPtr > psi_time_prev(new CustomInitialCondition(mesh)); + MeshFunctionSharedPtr > psi_time_new(new Solution >(mesh)); // Initialize the weak formulation. double current_time = 0; @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.rk_time_step_newton(&psi_time_prev, &psi_time_new); + runge_kutta.rk_time_step_newton(psi_time_prev, psi_time_new); } catch(Exceptions::Exception& e) { @@ -134,8 +134,8 @@ int main(int argc, char* argv[]) sview_real.set_title(title); sprintf(title, "Solution - imaginary part, Time %3.2f s", current_time); sview_imag.set_title(title); - RealFilter real(&psi_time_new); - ImagFilter imag(&psi_time_new); + MeshFunctionSharedPtr real(new RealFilter(psi_time_new)); + MeshFunctionSharedPtr imag(new ImagFilter(psi_time_new)); sview_real.show(real); sview_imag.show(imag); diff --git a/2d-advanced/wave-equation/wave-1/main.cpp b/2d-advanced/wave-equation/wave-1/main.cpp index aaa59ba..2f7062c 100644 --- a/2d-advanced/wave-equation/wave-1/main.cpp +++ b/2d-advanced/wave-equation/wave-1/main.cpp @@ -75,8 +75,8 @@ int main(int argc, char* argv[]) mesh->refine_towards_vertex(4, 1); // Initialize solutions. - CustomInitialConditionWave u_sln(mesh); - ZeroSolution v_sln(mesh); + MeshFunctionSharedPtr u_sln(new CustomInitialConditionWave(mesh)); + MeshFunctionSharedPtr v_sln(new ZeroSolution(mesh)); Hermes::vector > slns(u_sln, v_sln); // Initialize the weak formulation. @@ -86,9 +86,8 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_essential("Bdy", 0.0); EssentialBCs bcs(&bc_essential); - // Create x- and y- displacement space using the default H1 shapeset. - H1Space u_space(mesh, &bcs, P_INIT)); - H1Space v_space(mesh, &bcs, P_INIT)); + SpaceSharedPtr u_space(new H1Space(mesh, &bcs, P_INIT)); + SpaceSharedPtr v_space(new H1Space(mesh, &bcs, P_INIT)); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u_space, v_space))); // Initialize views. diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index 972dede..b814676 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) mesh->refine_towards_boundary("Bdy", INIT_REF_NUM_BDY); // Define exact solution. - CustomExactSolution exact_sln(mesh, K); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, K)); // Define right side vector. CustomFunction f(K); @@ -159,7 +159,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index 733c096..1867f44 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Define exact solution. - CustomExactSolution exact_sln(mesh, slope); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, slope)); // Define custom function f. CustomFunction f(slope); @@ -88,7 +88,7 @@ int main(int argc, char* argv[]) DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -163,7 +163,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -205,10 +205,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - if(done == false) - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-general/lshape/definitions.h b/2d-benchmarks-general/lshape/definitions.h index 3d26e83..3ea548b 100644 --- a/2d-benchmarks-general/lshape/definitions.h +++ b/2d-benchmarks-general/lshape/definitions.h @@ -9,7 +9,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh) : ExactSolutionScalar(mesh) + CustomExactSolution(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { } diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index e9c038c..e663767 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -71,13 +71,13 @@ int main(int argc, char* argv[]) //mesh->refine_towards_vertex(3, 5); // Define exact solution. - CustomExactSolution exact_sln(mesh); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh)); // Initialize the weak formulation. DefaultWeakFormLaplace wf; // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -151,7 +151,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -193,10 +193,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - if(done == false) - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index 7e2da51..fc01673 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) CustomWeakFormPoisson wf(HERMES_ANY, new Hermes::Hermes1DFunction(-1.0), &f); // Previous and next time level solution. - ZeroSolution sln_time_prev(mesh); + MeshFunctionSharedPtr sln_time_prev(new ZeroSolution(mesh)); MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. @@ -217,7 +217,7 @@ int main(int argc, char* argv[]) } // Project the fine mesh solution onto the coarse mesh-> - Solution sln_coarse; + MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(space, sln_time_new, sln_coarse); @@ -247,11 +247,6 @@ int main(int argc, char* argv[]) // Clean up. delete adaptivity; - if(!done) - { - - delete sln_time_new.get_mesh(); - } } while (done == false); @@ -265,8 +260,8 @@ int main(int argc, char* argv[]) oview.set_title(title); oview.show(space); - // Copy last reference solution into sln_time_prev. - sln_time_prev.copy(sln_time_new); + // Copy last reference solution into sln_time_prev-> + sln_time_prev->copy(sln_time_new); // Add entry to DOF convergence graph. dof_history_graph.add_values(current_time, space->get_num_dofs()); diff --git a/2d-benchmarks-general/nonsym-check/definitions.h b/2d-benchmarks-general/nonsym-check/definitions.h index 6b88cf1..758cbf4 100644 --- a/2d-benchmarks-general/nonsym-check/definitions.h +++ b/2d-benchmarks-general/nonsym-check/definitions.h @@ -9,7 +9,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh) : ExactSolutionScalar(mesh) + CustomExactSolution(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { } diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index 4a54174..70553bf 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char* argv[]) mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(mesh); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh)); // Initialize the weak formulation. CustomWeakForm wf("Right"); @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); // Assemble the discrete problem. @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) NewtonSolver newton(&dp); //newton.set_verbose_output(false); - + MeshFunctionSharedPtr ref_sln(new Solution()); try { @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); @@ -146,11 +146,11 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - + // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); double accum_time = cpu_time.accumulated(); - + // View the coarse mesh solution and polynomial orders. sview.show(sln); oview.show(space); @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(accum_time, err_exact_rel); graph_cpu_exact.save("conv_cpu_exact.dat"); - + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized @@ -181,22 +181,18 @@ int main(int argc, char* argv[]) done = true; else done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - + // Increase the counter of adaptivity steps. if (done == false) as++; - - if(done == false) - delete ref_space->get_mesh(); - - } - while (done == false); + } + while (done == false); - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - // Wait for all views to be closed. - Views::View::wait(); + // Wait for all views to be closed. + Views::View::wait(); } diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 9c73c16..907486d 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(mesh); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh)); // Initialize the weak formulation. CustomWeakFormPoisson wf("Right"); @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -186,9 +186,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index 93a2693..78a5547 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) mloader.load("domain.mesh", mesh); // Define exact solution. - CustomExactSolution exact_sln(mesh); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh)); // Initialize the weak formulation. CustomWeakFormPoisson wf("Top"); @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -186,9 +186,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-general/smooth-iso/definitions.h b/2d-benchmarks-general/smooth-iso/definitions.h index 5ba558d..32d57d3 100644 --- a/2d-benchmarks-general/smooth-iso/definitions.h +++ b/2d-benchmarks-general/smooth-iso/definitions.h @@ -9,7 +9,7 @@ using Hermes::Ord; class CustomExactSolution : public ExactSolutionScalar { public: - CustomExactSolution(Mesh* mesh) : ExactSolutionScalar(mesh) + CustomExactSolution(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) { } diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index e9a8d5f..c6c7e9d 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) } // Define exact solution. - CustomExactSolution exact_sln(mesh); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh)); // Initialize the weak formulation. Hermes1DFunction lambda(1.0); @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -197,9 +197,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index e2c9a91..080d765 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, EXACT_SOL_P); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, EXACT_SOL_P)); // Define right-hand side. CustomRightHandSide f(EXACT_SOL_P); @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -162,7 +162,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -204,9 +204,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 463e298..3f45e7b 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -104,14 +104,14 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); // Initialize weak formulation. Hermes1DFunction lambda(1.0); WeakFormsH1::DefaultWeakFormLaplace wf(HERMES_ANY, &lambda); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -228,9 +228,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 0d90bec..68d4005 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -88,19 +88,19 @@ const double E = 1.0; // Poisson ratio. const double nu = 0.3; #ifdef MODE_1 - // lambda for mode-1 solution. - const double lambda = 0.5444837367825; - // mu for mode-1 solution (mu is the same as G) - const double mu = E / (2 * (1 + nu)); - // Q for mode-1 solution. - const double Q = 0.5430755788367; +// lambda for mode-1 solution. +const double lambda = 0.5444837367825; +// mu for mode-1 solution (mu is the same as G) +const double mu = E / (2 * (1 + nu)); +// Q for mode-1 solution. +const double Q = 0.5430755788367; #else - // lambda for mode-2 solution. - const double lambda = 0.9085291898461; - // mu for mode-2 solution (mu is the same as G). - const double mu = E / (2 * (1 + nu)); - // Q for mode-2 solution. - const double Q = -0.2189232362488; +// lambda for mode-2 solution. +const double lambda = 0.9085291898461; +// mu for mode-2 solution (mu is the same as G). +const double mu = E / (2 * (1 + nu)); +// Q for mode-2 solution. +const double Q = -0.2189232362488; #endif int main(int argc, char* argv[]) @@ -118,10 +118,10 @@ int main(int argc, char* argv[]) u_mesh->refine_all_elements(); v_mesh->refine_all_elements(); } - + // Set exact solution for each displacement component. - CustomExactSolutionU exact_u(u_mesh, E, nu, lambda, Q); - CustomExactSolutionV exact_v(v_mesh, E, nu, lambda, Q); + MeshFunctionSharedPtr exact_u(new CustomExactSolutionU(u_mesh, E, nu, lambda, Q)); + MeshFunctionSharedPtr exact_v(new CustomExactSolutionV(v_mesh, E, nu, lambda, Q)); // Initialize the weak formulation. // NOTE: We pass all four parameters (temporarily) @@ -136,12 +136,15 @@ int main(int argc, char* argv[]) EssentialBCs bcs_v(&bc_v); // Create H1 spaces with default shapeset for both displacement components. -SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); - H1Space v_space(v_mesh, &bcs_v, P_INIT_V); + SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); + SpaceSharedPtr v_space(new H1Space(v_mesh, &bcs_v, P_INIT_V)); // Initialize approximate solution. - Solution u_sln, v_sln; - + MeshFunctionSharedPtr u_sln(new Solution()); + MeshFunctionSharedPtr u_ref_sln(new Solution()); + MeshFunctionSharedPtr v_sln(new Solution()); + MeshFunctionSharedPtr v_ref_sln(new Solution()); + // Initialize refinement selector. H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); @@ -180,24 +183,22 @@ SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); Space::ReferenceSpaceCreator refSpaceCreatorV(v_space, ref_v_mesh); SpaceSharedPtr ref_v_space = refSpaceCreatorV.create_ref_space(); - Hermes::vector > ref_spaces(ref_u_space, ref_v_space); Hermes::vector > ref_spaces(ref_u_space, ref_v_space); int ndof_ref = Space::get_num_dofs(ref_spaces); Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - + // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_spaces); - + NewtonSolver newton(&dp); //newton.set_verbose_output(false); newton.set_tolerance(NEWTON_TOLERANCE); - - Solution u_ref_sln, v_ref_sln; + try { newton.solve(); @@ -210,41 +211,41 @@ SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u_ref_sln, v_ref_sln)); - + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - + // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u_space, v_space), - Hermes::vector >(u_ref_sln, v_ref_sln), - Hermes::vector >(u_sln, v_sln)); + Hermes::vector >(u_ref_sln, v_ref_sln), + Hermes::vector >(u_sln, v_sln)); // Calculate element errors and total error estimate. Hermes::vector err_est_rel; Adapt* adaptivity = new Adapt(Hermes::vector >(u_space, v_space)); double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100.; + Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100.; // Calculate exact error for each solution component and the total exact error. Hermes::vector err_exact_rel; bool solutions_for_adapt = false; double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(exact_u, exact_v), - &err_exact_rel, solutions_for_adapt) * 100.; + Hermes::vector >(exact_u, exact_v), + &err_exact_rel, solutions_for_adapt) * 100.; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - + // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse[u]: %d, ndof_fine[u]: %d", - u_space->Space::get_num_dofs(), Space::get_num_dofs(ref_u_space)); + u_space->Space::get_num_dofs(), Space::get_num_dofs(ref_u_space)); Hermes::Mixins::Loggable::Static::info("err_est_rel[u]: %g%%, err_exact_rel[u]: %g%%", err_est_rel[0]*100, err_exact_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[v]: %d, ndof_fine[v]: %d", - v_space->Space::get_num_dofs(), Space::get_num_dofs(ref_v_space)); + v_space->Space::get_num_dofs(), Space::get_num_dofs(ref_v_space)); Hermes::Mixins::Loggable::Static::info("err_est_rel[v]: %g%%, err_exact_rel[v]: %g%%", err_est_rel[1]*100, err_exact_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", - Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(ref_spaces)); + Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(ref_spaces)); Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%, err_est_exact_total: %g%%", err_est_rel_total, err_exact_rel_total); // Time measurement. @@ -256,7 +257,7 @@ SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); o_view_u.show(u_space); s_view_v.show(v_sln); o_view_v.show(v_space); - VonMisesFilter stress(Hermes::vector >(u_sln, v_sln), lambda, mu); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u_sln, v_sln), lambda, mu)); mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u_sln, v_sln, 0.03); // Add entry to DOF and CPU convergence graphs. @@ -268,7 +269,7 @@ SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); graph_dof_exact.save("conv_dof_exact.dat"); graph_cpu_exact.add_values(cpu_time.accumulated(), err_exact_rel_total); graph_cpu_exact.save("conv_cpu_exact.dat"); - + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // If err_est too large, adapt the mesh-> @@ -278,23 +279,21 @@ SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); { Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); + THRESHOLD, STRATEGY, MESH_REGULARITY); } if (Space::get_num_dofs(Hermes::vector >(u_space, v_space)) >= NDOF_STOP) done = true; - + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - + // Increase the counter of adaptivity steps. if (done == false) as++; delete adaptivity; - delete ref_u_space; - delete ref_v_space; } while (done == false); - + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); // Wait for all views to be closed. diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index eb037d9..dda14fa 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char* argv[]) for (int i = 0; irefine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha, x_loc, y_loc); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha, x_loc, y_loc)); // Define right-hand side. CustomRightHandSide f(alpha, x_loc, y_loc); @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -164,7 +164,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -206,9 +206,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/05-battery/definitions.cpp b/2d-benchmarks-nist/05-battery/definitions.cpp index 2f6845e..b1214d3 100644 --- a/2d-benchmarks-nist/05-battery/definitions.cpp +++ b/2d-benchmarks-nist/05-battery/definitions.cpp @@ -325,7 +325,7 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om std::string omega_3, std::string omega_4, std::string omega_5, std::string bdy_left, std::string bdy_top, std::string bdy_right, - std::string bdy_bottom, Mesh* mesh) : WeakForm(1), + std::string bdy_bottom, MeshSharedPtr mesh) : WeakForm(1), omega_1(omega_1), omega_2(omega_2), omega_3(omega_3), omega_4(omega_4), omega_5(omega_5), mesh(mesh), diff --git a/2d-benchmarks-nist/05-battery/definitions.h b/2d-benchmarks-nist/05-battery/definitions.h index 9792e97..3e2f407 100644 --- a/2d-benchmarks-nist/05-battery/definitions.h +++ b/2d-benchmarks-nist/05-battery/definitions.h @@ -10,7 +10,7 @@ using namespace Hermes::Hermes2D::RefinementSelectors; class CustomMatrixFormVol : public MatrixFormVol { public: - CustomMatrixFormVol(int i, int j, Mesh* mesh) + CustomMatrixFormVol(int i, int j, MeshSharedPtr mesh) : MatrixFormVol(i, j), mesh(mesh) {}; template @@ -25,13 +25,13 @@ class CustomMatrixFormVol : public MatrixFormVol MatrixFormVol* clone() const; - Mesh* mesh; + MeshSharedPtr mesh; }; class CustomVectorFormVol : public VectorFormVol { public: - CustomVectorFormVol(int i, Mesh* mesh) : VectorFormVol(i), mesh(mesh) {}; + CustomVectorFormVol(int i, MeshSharedPtr mesh) : VectorFormVol(i), mesh(mesh) {}; template Scalar vector_form(int n, double *wt, Func *u_ext[], @@ -45,7 +45,7 @@ class CustomVectorFormVol : public VectorFormVol VectorFormVol* clone() const; - Mesh* mesh; + MeshSharedPtr mesh; }; class CustomMatrixFormSurf : public MatrixFormSurf @@ -94,9 +94,9 @@ class CustomWeakFormPoisson : public WeakForm std::string omega_3, std::string omega_4, std::string omega_5, std::string bdy_left, std::string bdy_top, std::string bdy_right, - std::string bdy_bottom, Mesh* mesh); + std::string bdy_bottom, MeshSharedPtr mesh); - Mesh* mesh; + MeshSharedPtr mesh; const std::string omega_1; const std::string omega_2; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 2770075..243b4f2 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -212,13 +212,6 @@ int main(int argc, char* argv[]) } if (space->get_num_dofs() >= NDOF_STOP) done = true; - - // Keep the mesh from final step to allow further work with the final fine mesh solution. - if(done == false) - { - delete ref_space->get_mesh(); - - } } while (done == false); diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 5509d4f..49ab860 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, epsilon); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, epsilon)); // Define right-hand side. CustomRightHandSide f(epsilon); @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) CustomWeakForm wf(&f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -200,9 +200,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 2e7e888..425e97c 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); // Define right-hand side. CustomRightHandSide f(alpha); @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -162,7 +162,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -204,9 +204,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index f7f8099..eadd8e2 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); // Define right-hand side. CustomRightHandSide f(alpha); @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) CustomWeakForm wf(&f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -200,9 +200,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/09-wave-front-kelly-dealii/main.cpp b/2d-benchmarks-nist/09-wave-front-kelly-dealii/main.cpp index de83daf..d10e61c 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly-dealii/main.cpp +++ b/2d-benchmarks-nist/09-wave-front-kelly-dealii/main.cpp @@ -221,8 +221,8 @@ int main(int argc, char* argv[]) DefaultEssentialBCNonConst bc("Bdy", &exact); EssentialBCs bcs(&bc); - // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); +SpaceSharedPtr space(new // Create an H1 space with default shapeset. + H1Space(&mesh, &bcs, P_INIT)); // Initialize approximate solution. Solution sln; diff --git a/2d-benchmarks-nist/09-wave-front-kelly/main.cpp b/2d-benchmarks-nist/09-wave-front-kelly/main.cpp index aae5f59..98c68d2 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly/main.cpp +++ b/2d-benchmarks-nist/09-wave-front-kelly/main.cpp @@ -133,8 +133,8 @@ int main(int argc, char* argv[]) DefaultEssentialBCNonConst bc("Bdy", &exact); EssentialBCs bcs(&bc); - // Create an H1 space with default shapeset. - H1Space space(&mesh, &bcs, P_INIT); +SpaceSharedPtr space(new // Create an H1 space with default shapeset. + H1Space(&mesh, &bcs, P_INIT)); // Initialize approximate solution. Solution sln; diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index f80bf52..254a263 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha, x_loc, y_loc, r_zero); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha, x_loc, y_loc, r_zero)); // Define right-hand side. CustomRightHandSide rhs(alpha, x_loc, y_loc, r_zero); @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) // WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, HERMES_ONE, &rhs); // Initialize boundary conditions. - DefaultEssentialBCNonConst bc("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc("Bdy", exact_sln); EssentialBCs bcs(&bc); // Create an H1 space with default shapeset. @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -249,9 +249,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index c66fc8b..418035c 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, K, alpha); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, K, alpha)); // Define right-hand side. CustomRightHandSide f(K, alpha); @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy_dirichlet_rest", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy_dirichlet_rest", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -161,7 +161,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -203,9 +203,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index 4bba8ec..d76348d 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -80,13 +80,13 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, SIGMA, TAU, RHO); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, SIGMA, TAU, RHO)); // Initialize weak formulation. CustomWeakFormPoisson wf("Mat_0", R, "Mat_1"); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -161,7 +161,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -203,9 +203,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index c551b2f..ecbe46b 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. - CustomExactSolution exact_sln(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p)); // Define right-hand side. CustomRightHandSide f(alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions - DefaultEssentialBCNonConst bc_essential("Bdy", &exact_sln); + DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. @@ -165,7 +165,7 @@ int main(int argc, char* argv[]) double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln, &exact_sln, HERMES_H1_NORM) * 100; + double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -207,9 +207,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete ref_space->get_mesh(); - } while (done == false); From 10352450efc87b3531d0b03e8f324a6d955da37d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sat, 13 Apr 2013 22:06:37 +0200 Subject: [PATCH 16/64] A fix in Euler. --- 2d-advanced/euler/euler_util.cpp | 2 +- 2d-advanced/euler/euler_util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index 9dcac7c..c10df4a 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -215,7 +215,7 @@ DiscontinuityDetector::DiscontinuityDetector(Hermes::vector > solutions) : spaces(spaces), solutions(solutions) { for(int i = 0; i < solutions.size(); i++) - this->solutionsInternal.push_back((MeshFunctionSharedPtr )solutions[i].get()); + this->solutionsInternal.push_back((Solution*)solutions[i].get()); }; DiscontinuityDetector::~DiscontinuityDetector() diff --git a/2d-advanced/euler/euler_util.h b/2d-advanced/euler/euler_util.h index 5fd60bb..cbdf9e2 100644 --- a/2d-advanced/euler/euler_util.h +++ b/2d-advanced/euler/euler_util.h @@ -71,7 +71,7 @@ class DiscontinuityDetector /// Members. Hermes::vector > spaces; Hermes::vector > solutions; - Hermes::vector > solutionsInternal; + Hermes::vector*> solutionsInternal; std::set discontinuous_element_ids; std::set > oscillatory_element_idsRho; std::set > oscillatory_element_idsRhoVX; From f5e41e5b927516e51ba320765809fda470078ccc Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 14 Apr 2013 16:30:21 +0200 Subject: [PATCH 17/64] Few fixes. --- .../linear-advection-diffusion/definitions.cpp | 6 ++---- .../linear-advection-diffusion/main.cpp | 4 ++-- 2d-advanced/navier-stokes/circular-obstacle/main.cpp | 11 ++++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/definitions.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/definitions.cpp index c47c38c..29d78b0 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/definitions.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/definitions.cpp @@ -26,17 +26,15 @@ Scalar WeakFormLinearAdvectionDiffusion::MatrixFormVolAdvectionDiffusion::matrix (Hermes::sqrt(Hermes::pow(u->dx[i], 2) + Hermes::pow(u->dy[i], 2)) + 1.e-8); } +#ifdef H2D_SECOND_DERIVATIVES_ENABLED if(static_cast(wf)->stabilization_on) { -#ifdef H2D_SECOND_DERIVATIVES_ENABLED double b_norm = Hermes::sqrt(b1*b1 + b2*b2); Real tau = 1. / Hermes::sqrt(9*Hermes::pow(4*epsilon/Hermes::pow(h_e, 2), 2) + Hermes::pow(2*b_norm/h_e, 2)); result += wt[i] * tau * (-b1 * v->dx[i] - b2 * v->dy[i] + epsilon * v->laplace[i]) * (-b1 * u->dx[i] - b2 * u->dy[i] + epsilon * u->laplace[i]); -#else - throw Hermes::Exceptions::Exception("Define H2D_SECOND_DERIVATIVES_ENABLED in h2d_common.h if you want to use second derivatives of shape functions in weak forms."); -#endif } +#endif } return result; } diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 62fdb52..2313c34 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -22,14 +22,14 @@ const int P_INIT = 1; // Stabilization on/off (assumes that H2D_SECOND_DERIVATIVES_ENABLED is defined). const bool STABILIZATION_ON = false; // Shock capturing on/off. -const bool SHOCK_CAPTURING_ON = false; +const bool SHOCK_CAPTURING_ON = true; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 2; // Number of initial uniform mesh refinements in the boundary layer region. const int INIT_REF_NUM_BDY = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.9; +const double THRESHOLD = 0.3; // Adaptive strategy: // STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total // error is processed. If more elements have similar errors, refine diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 6a78a0e..d1c341d 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -139,7 +139,12 @@ int main(int argc, char* argv[]) // Initialize the FE problem. DiscreteProblem dp(&wf, spaces); - + Hermes::Hermes2D::NewtonSolver newton(&dp); + Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); + newton.set_jacobian_constant(); + // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 750, 240)); ScalarView pview("pressure [Pa]", new WinGeom(0, 290, 750, 240)); @@ -164,10 +169,6 @@ int main(int argc, char* argv[]) } // Perform Newton's iteration. - Hermes::Hermes2D::NewtonSolver newton(&dp); - Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); try { newton.solve(); From a59be18bf955e2c6f2e6fe47267eb4193a8463a3 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 14 Apr 2013 17:37:28 +0200 Subject: [PATCH 18/64] Add TCMalloc. --- CMakeLists.txt | 2 ++ cmake/FindTCMALLOC.cmake | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 cmake/FindTCMALLOC.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e78b959..afca520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ project(hermes_examples) include_directories("${PTHREAD_ROOT}/include") find_package(PTHREAD REQUIRED) + find_package(TCMALLOC REQUIRED) + include_directories(${TCMALLOC_INCLUDE_DIR}) if(WITH_TRILINOS) find_package(TRILINOS REQUIRED) diff --git a/cmake/FindTCMALLOC.cmake b/cmake/FindTCMALLOC.cmake new file mode 100644 index 0000000..8d330cd --- /dev/null +++ b/cmake/FindTCMALLOC.cmake @@ -0,0 +1,16 @@ +# +# TCMALLOC +# FROM http://code.google.com/p/google-perftools/ +# + +SET(MY_TCMALLOC_LIB_DIRS ${TCMALLOC_ROOT}/lib) +SET(MY_TCMALLOC_INC_DIRS ${TCMALLOC_ROOT}/include) + +FIND_PATH(TCMALLOC_INCLUDE_DIR tcmalloc.h ${MY_TCMALLOC_INC_DIRS} /usr/local/include/google /usr/include/google) + +FIND_LIBRARY(TCMALLOC_LIBRARY NAMES tcmalloc_minimal tcmalloc_minimal_debug libtcmalloc_minimal libtcmalloc_minimal-debug PATHS ${MY_TCMALLOC_LIB_DIRS} /usr/lib /usr/local/lib) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( TCMALLOC "TCMALLOC could not be found." + TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR +) \ No newline at end of file From 943f812cbeb3b5a468595dd407c6e59e8c3fd32d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 23 Apr 2013 21:58:49 +0200 Subject: [PATCH 19/64] Work on NIST examples for FEMTEC. --- .../01-analytic-solution/definitions.h | 4 +- .../01-analytic-solution/main.cpp | 76 +++++------- .../02-reentrant-corner/definitions.h | 3 + .../02-reentrant-corner/main.cpp | 76 +++++------- .../03-linear-elasticity/definitions.h | 1 + .../03-linear-elasticity/main.cpp | 110 ++++++------------ .../04-exponential-peak/definitions.h | 3 + .../04-exponential-peak/main.cpp | 84 +++++-------- 2d-benchmarks-nist/05-battery/definitions.h | 1 + 2d-benchmarks-nist/05-battery/main.cpp | 90 +++++--------- .../06-boundary-layer/definitions.h | 3 + 2d-benchmarks-nist/06-boundary-layer/main.cpp | 76 +++++------- .../definitions.h | 3 + .../07-boundary-line-singularity/main.cpp | 76 +++++------- .../08-oscillatory/definitions.h | 3 + 2d-benchmarks-nist/08-oscillatory/main.cpp | 76 +++++------- .../09-wave-front-kelly-dealii/definitions.h | 1 + .../09-wave-front-kelly/definitions.h | 1 + .../09-wave-front/definitions.h | 3 + 2d-benchmarks-nist/09-wave-front/main.cpp | 76 +++++------- .../definitions.h | 3 + .../10-interior-line-singularity/main.cpp | 76 +++++------- 2d-benchmarks-nist/11-kellogg/definitions.h | 3 + 2d-benchmarks-nist/11-kellogg/main.cpp | 72 +++++------- .../12-multiple-difficulties/definitions.h | 3 + .../12-multiple-difficulties/main.cpp | 64 ++++------ 2d-benchmarks-nist/NIST-util.h | 33 ++++++ CMakeLists.txt | 2 + cmake/CommonTargetProperties.cmake | 2 +- cmake/FindHERMES.cmake | 6 +- cmake/FindHERMES_COMMON.cmake | 8 +- 31 files changed, 440 insertions(+), 598 deletions(-) create mode 100644 2d-benchmarks-nist/NIST-util.h diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.h b/2d-benchmarks-nist/01-analytic-solution/definitions.h index 1d89cce..511775f 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.h +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -31,7 +32,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, poly_deg); } double poly_deg; }; diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 080d765..2355e28 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -24,44 +24,26 @@ using namespace RefinementSelectors; double EXACT_SOL_P = 10; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 0.5; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.01; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -97,7 +79,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -134,7 +116,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -153,16 +135,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -193,10 +177,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/02-reentrant-corner/definitions.h b/2d-benchmarks-nist/02-reentrant-corner/definitions.h index aca029c..56010b1 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/definitions.h +++ b/2d-benchmarks-nist/02-reentrant-corner/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -20,6 +21,8 @@ class CustomExactSolution : public ExactSolutionScalar double get_angle(double y, double x) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha); } + double alpha; }; diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 3f45e7b..e633a73 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -30,44 +30,26 @@ using namespace RefinementSelectors; int PARAM = 1; // Initial polynomial degree of mesh elements. -const int P_INIT = 3; +const int P_INIT = 3; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.1; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -121,7 +103,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -158,7 +140,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -177,16 +159,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -217,10 +201,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/03-linear-elasticity/definitions.h b/2d-benchmarks-nist/03-linear-elasticity/definitions.h index be6a70c..66bef8e 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/definitions.h +++ b/2d-benchmarks-nist/03-linear-elasticity/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 68d4005..aaafaff 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -43,43 +43,24 @@ const int P_INIT_U = 2; // Initial polynomial degree for v. const int P_INIT_V = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -const double NEWTON_TOLERANCE = 1E-3; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; // Problem parameters. @@ -138,15 +119,19 @@ int main(int argc, char* argv[]) // Create H1 spaces with default shapeset for both displacement components. SpaceSharedPtr u_space(new H1Space(u_mesh, &bcs_u, P_INIT_U)); SpaceSharedPtr v_space(new H1Space(v_mesh, &bcs_v, P_INIT_V)); + Hermes::vector >spaces(u_space, v_space); // Initialize approximate solution. MeshFunctionSharedPtr u_sln(new Solution()); MeshFunctionSharedPtr u_ref_sln(new Solution()); MeshFunctionSharedPtr v_sln(new Solution()); MeshFunctionSharedPtr v_ref_sln(new Solution()); + Hermes::vector >slns(u_sln, v_sln); + Hermes::vector >ref_slns(u_ref_sln, v_ref_sln); + Hermes::vector >exact_slns(exact_u, exact_v); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView s_view_u("Solution for u", new WinGeom(0, 0, 440, 350)); @@ -196,9 +181,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); - newton.set_tolerance(NEWTON_TOLERANCE); - + try { newton.solve(); @@ -210,44 +193,27 @@ int main(int argc, char* argv[]) }; // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u_ref_sln, v_ref_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, ref_slns); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u_space, v_space), - Hermes::vector >(u_ref_sln, v_ref_sln), - Hermes::vector >(u_sln, v_sln)); + OGProjection ogProjection; ogProjection.project_global(spaces, ref_slns, slns); // Calculate element errors and total error estimate. - Hermes::vector err_est_rel; - Adapt* adaptivity = new Adapt(Hermes::vector >(u_space, v_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100.; - - // Calculate exact error for each solution component and the total exact error. - Hermes::vector err_exact_rel; - bool solutions_for_adapt = false; - double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(exact_u, exact_v), - &err_exact_rel, solutions_for_adapt) * 100.; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 2); + error_calculator.calculate_errors(slns, exact_slns); + double err_exact_rel_total = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(slns, ref_slns); + double err_est_rel_total = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(spaces, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse[u]: %d, ndof_fine[u]: %d", - u_space->Space::get_num_dofs(), Space::get_num_dofs(ref_u_space)); - Hermes::Mixins::Loggable::Static::info("err_est_rel[u]: %g%%, err_exact_rel[u]: %g%%", err_est_rel[0]*100, err_exact_rel[0]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse[v]: %d, ndof_fine[v]: %d", - v_space->Space::get_num_dofs(), Space::get_num_dofs(ref_v_space)); - Hermes::Mixins::Loggable::Static::info("err_est_rel[v]: %g%%, err_exact_rel[v]: %g%%", err_est_rel[1]*100, err_exact_rel[1]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", - Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(ref_spaces)); - Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%, err_est_exact_total: %g%%", err_est_rel_total, err_exact_rel_total); - // Time measurement. cpu_time.tick(); double accum_time = cpu_time.accumulated(); @@ -277,11 +243,9 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector)); } - if (Space::get_num_dofs(Hermes::vector >(u_space, v_space)) >= NDOF_STOP) done = true; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); @@ -289,8 +253,6 @@ int main(int argc, char* argv[]) // Increase the counter of adaptivity steps. if (done == false) as++; - - delete adaptivity; } while (done == false); diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.h b/2d-benchmarks-nist/04-exponential-peak/definitions.h index 7a47879..ca557f2 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.h +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -35,6 +36,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc); } + double alpha; double x_loc; double y_loc; diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index dda14fa..4964da3 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -26,44 +26,20 @@ double x_loc = 0.5; double y_loc = 0.5; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 0.5; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.01; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; int main(int argc, char* argv[]) { @@ -76,7 +52,8 @@ int main(int argc, char* argv[]) // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinements. - for (int i = 0; irefine_all_elements(); + for (int i = 0; irefine_all_elements(); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha, x_loc, y_loc)); @@ -99,7 +76,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -113,6 +90,11 @@ int main(int argc, char* argv[]) // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + MeshFunctionSharedPtr ref_sln(new Solution()); + // Adaptivity loop: int as = 1; bool done = false; do @@ -132,13 +114,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - //newton.set_verbose_output(false); - - MeshFunctionSharedPtr ref_sln(new Solution()); + newton.set_space(ref_space); try { newton.solve(); @@ -155,16 +131,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -195,10 +173,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/05-battery/definitions.h b/2d-benchmarks-nist/05-battery/definitions.h index 3e2f407..f0d9dc1 100644 --- a/2d-benchmarks-nist/05-battery/definitions.h +++ b/2d-benchmarks-nist/05-battery/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 243b4f2..a12e5cb 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -19,49 +19,27 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -// Set to "false" to suppress Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = true; -// Set to "true" to enable VTK output. -const bool VTK_VISUALIZATION = false; // Initial polynomial degree of mesh elements. const int P_INIT = 2; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -// More adaptive strategies can be created in adapt_ortho_h1.cpp. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, H2D_HP_ANISO_H -// H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// This parameter influences the selection of candidates in hp-adaptivity. -// Default value is 1.0. -const double CONV_EXP = 0.3; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -84,7 +62,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 320, 600)); @@ -116,7 +94,7 @@ int main(int argc, char* argv[]) int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. - Hermes::Mixins::Loggable::Static::info("Solving on fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); @@ -136,8 +114,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. @@ -172,21 +150,13 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(space); - bool solutions_for_adapt = true; - // In the following function, the Boolean parameter "solutions_for_adapt" determines whether - // the calculated errors are intended for use with adaptivity (this may not be the case, for example, - // when error wrt. an exact solution is calculated). The default value is solutions_for_adapt = true, - // The last parameter "error_flags" determine whether the total and element errors are treated as - // absolute or relative. Its default value is error_flags = HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL. - // In subsequent examples and benchmarks, these two parameters will be often used with - // their default values, and thus they will not be present in the code explicitly. - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln, solutions_for_adapt, - HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, ref_sln); + Adapt adaptivity(space, &error_calculator); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); // Add entry to DOF and CPU convergence graphs. cpu_time.tick(); @@ -203,15 +173,13 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); // Increase the counter of performed adaptivity steps. if (done == false) as++; } - if (space->get_num_dofs() >= NDOF_STOP) - done = true; } while (done == false); diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index 374dfc0..b57d906 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -33,6 +34,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, epsilon); } + double epsilon; }; diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 49ab860..118d233 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -24,44 +24,26 @@ using namespace RefinementSelectors; const double epsilon = 1e-1; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-3; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -93,7 +75,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -130,7 +112,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -149,16 +131,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -189,10 +173,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h index aeac608..5f69a8e 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h +++ b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -33,5 +34,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha); } + double alpha; }; diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 425e97c..3fea851 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -24,44 +24,26 @@ using namespace RefinementSelectors; double alpha = 0.6; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 0.5; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.5; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -97,7 +79,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -134,7 +116,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -153,16 +135,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -193,10 +177,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.h b/2d-benchmarks-nist/08-oscillatory/definitions.h index 72bf196..9f87d6d 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.h +++ b/2d-benchmarks-nist/08-oscillatory/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -33,6 +34,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha); } + double alpha; }; diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index eadd8e2..f8c776b 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -24,44 +24,26 @@ using namespace RefinementSelectors; const double alpha = 1/(10*M_PI); // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.5; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -93,7 +75,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -130,7 +112,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -149,16 +131,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -189,10 +173,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h index f1fb5c7..250bca3 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes::Hermes2D; using namespace WeakFormsH1; diff --git a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h index 3aa5e8c..84aa567 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes::Hermes2D; using namespace WeakFormsH1; diff --git a/2d-benchmarks-nist/09-wave-front/definitions.h b/2d-benchmarks-nist/09-wave-front/definitions.h index 7fd5052..5577d46 100644 --- a/2d-benchmarks-nist/09-wave-front/definitions.h +++ b/2d-benchmarks-nist/09-wave-front/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes::Hermes2D; using namespace WeakFormsH1; @@ -73,5 +74,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives (double x, double y, double& dx, double& dy) const; virtual Ord ord (Ord x, Ord y) const { return Ord(Ord::get_max_order()); } + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc, r_zero); } + double alpha, x_loc, y_loc, r_zero; }; \ No newline at end of file diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index 254a263..490f336 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -30,44 +30,26 @@ using namespace RefinementSelectors; int PARAM = 3; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.5; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -142,7 +124,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -179,7 +161,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -198,16 +180,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -238,10 +222,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h index 16dbda7..24cee72 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h +++ b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -51,6 +52,8 @@ class CustomExactSolution : public ExactSolutionScalar CustomExactFunction* cef; + MeshFunction* clone() const { return new CustomExactSolution(mesh, k, alpha); } + double k; double alpha; }; diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 418035c..689f8ef 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -26,44 +26,26 @@ const double K = M_PI/2; const double alpha = 2.01; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-3; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const int INIT_REF_NUM = 0; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -96,7 +78,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -133,7 +115,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -152,16 +134,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -192,10 +176,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/11-kellogg/definitions.h b/2d-benchmarks-nist/11-kellogg/definitions.h index 729bafb..fe72848 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.h +++ b/2d-benchmarks-nist/11-kellogg/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -18,6 +19,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (Ord x, Ord y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, sigma, tau, rho); } + double sigma; double tau; double rho; diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index d76348d..d468a89 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -30,44 +30,26 @@ const double RHO = M_PI/4.; const double SIGMA = -14.92256510455152; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. +const int INIT_REF_NUM = 1; +// This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 5.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -96,7 +78,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -133,7 +115,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -152,16 +134,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -192,10 +176,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h index bd0beb3..c9d1036 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h +++ b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h @@ -1,4 +1,5 @@ #include "hermes2d.h" +#include "../NIST-util.h" using namespace Hermes; using namespace Hermes::Hermes2D; @@ -47,6 +48,8 @@ class CustomExactSolution : public ExactSolutionScalar double get_angle(double y, double x) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); } + double alpha_w; double alpha_p; double x_w; diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index ecbe46b..63fe09d 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -33,41 +33,23 @@ const double epsilon = 1.0 / 100.0; const int P_INIT = 3; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. +// This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. +// This is a stopping criterion for Adaptivity. +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; + +// Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). +// Stopping criterion for adaptivity. const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; + +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -100,7 +82,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -137,7 +119,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); - //newton.set_verbose_output(false); + MeshFunctionSharedPtr ref_sln(new Solution()); try @@ -156,16 +138,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + Adapt adaptivity(space, &error_calculator); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -196,10 +180,10 @@ int main(int argc, char* argv[]) // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h new file mode 100644 index 0000000..86b8aa0 --- /dev/null +++ b/2d-benchmarks-nist/NIST-util.h @@ -0,0 +1,33 @@ +#include "hermes2d.h" + +using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::Views; +using namespace Hermes::Hermes2D::RefinementSelectors; + +class MySelector : public H1ProjBasedSelector +{ +public: + MySelector(CandList cand_list) : H1ProjBasedSelector(cand_list) + { + } +private: + void evaluate_cands_score(Hermes::vector& candidates, Element* e) + { + //calculate score of candidates + Cand& unrefined = candidates[0]; + const int num_cands = (int)candidates.size(); + unrefined.score = 0; + + for (int i = 1; i < num_cands; i++) + { + Cand& cand = candidates[i]; + if(cand.error < unrefined.error) + { + double delta_dof = cand.dofs - unrefined.dofs; + candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; + } + else + candidates[i].score = 0; + } + } +}; \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index afca520..87766d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_HOME_DIRECTORY}/cmake/cxx_flag_overrides.cmake) project(hermes_examples) cmake_minimum_required(VERSION 2.6) + + set(HERMES_EXAMPLES_DEBUG YES) set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake) include(CommonTargetProperties) diff --git a/cmake/CommonTargetProperties.cmake b/cmake/CommonTargetProperties.cmake index 86eaca2..e40f791 100644 --- a/cmake/CommonTargetProperties.cmake +++ b/cmake/CommonTargetProperties.cmake @@ -2,7 +2,7 @@ macro(SET_COMMON_TARGET_PROPERTIES TRGT HERMES_VERSION) set(HERMES_VERSION ${HERMES_VERSION}) - find_package(HERMES REQUIRED) + find_package(HERMES REQUIRED) if (COMPILE_FLAGS) set_target_properties(${TRGT} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS}) diff --git a/cmake/FindHERMES.cmake b/cmake/FindHERMES.cmake index c76bff3..5412d27 100644 --- a/cmake/FindHERMES.cmake +++ b/cmake/FindHERMES.cmake @@ -1,7 +1,11 @@ INCLUDE(FindPackageHandleStandardArgs) if(${HERMES_VERSION} STREQUAL "HERMES2D") - FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d hermes2d-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) +IF(HERMES_EXAMPLES_DEBUG) + FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) +ELSE(HERMES_EXAMPLES_DEBUG) + FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) +ENDIF(HERMES_EXAMPLES_DEBUG) FIND_PATH(HERMES_INCLUDE hermes2d.h ${HERMES2D_INCLUDE_PATH} /usr/lib /usr/local/lib) FIND_PACKAGE_HANDLE_STANDARD_ARGS(HERMES DEFAULT_MSG HERMES_LIBRARY HERMES_INCLUDE) endif(${HERMES_VERSION} STREQUAL "HERMES2D") diff --git a/cmake/FindHERMES_COMMON.cmake b/cmake/FindHERMES_COMMON.cmake index bbd4de2..1cc133c 100644 --- a/cmake/FindHERMES_COMMON.cmake +++ b/cmake/FindHERMES_COMMON.cmake @@ -1,4 +1,10 @@ INCLUDE(FindPackageHandleStandardArgs) -FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common hermes_common-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) + +IF(HERMES_EXAMPLES_DEBUG) + FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) +ELSE(HERMES_EXAMPLES_DEBUG) + FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) +ENDIF(HERMES_EXAMPLES_DEBUG) + FIND_PATH(HERMES_COMMON_INCLUDE hermes_common.h ${HERMES_COMMON_INCLUDE_PATH} /usr/include /usr/local/include) FIND_PACKAGE_HANDLE_STANDARD_ARGS(HERMES_COMMON DEFAULT_MSG HERMES_COMMON_LIBRARY HERMES_COMMON_INCLUDE) From c6bf5d6a5d2d96b67c99ff9fe103feea4785f98e Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 25 Apr 2013 13:49:52 +0200 Subject: [PATCH 20/64] Work on NIST. --- .../01-analytic-solution/main.cpp | 10 ++++++---- .../02-reentrant-corner/main.cpp | 10 ++++++---- .../03-linear-elasticity/main.cpp | 12 ++++++----- .../04-exponential-peak/main.cpp | 10 ++++++---- 2d-benchmarks-nist/05-battery/main.cpp | 11 ++++++---- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 10 ++++++---- .../07-boundary-line-singularity/main.cpp | 10 ++++++---- 2d-benchmarks-nist/08-oscillatory/main.cpp | 10 ++++++---- .../09-wave-front-kelly/main.cpp | 1 + 2d-benchmarks-nist/09-wave-front/main.cpp | 10 ++++++---- .../10-interior-line-singularity/main.cpp | 10 ++++++---- 2d-benchmarks-nist/11-kellogg/main.cpp | 10 ++++++---- .../12-multiple-difficulties/main.cpp | 20 ++++++++++--------- 13 files changed, 80 insertions(+), 54 deletions(-) diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 2355e28..10828ca 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -38,6 +38,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -47,7 +48,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. @@ -110,7 +111,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -140,13 +141,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -175,7 +177,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index e633a73..1ffa2bd 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -44,6 +44,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -53,7 +54,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; @@ -134,7 +135,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -164,13 +165,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -199,7 +201,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index aaafaff..1beee54 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -45,7 +45,7 @@ const int P_INIT_V = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; +const double THRESHOLD = 0.6; // This is a stopping criterion for Adaptivity. const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; @@ -55,6 +55,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -86,7 +87,7 @@ const double Q = -0.2189232362488; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("elasticity.mesh", u_mesh); @@ -175,7 +176,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_spaces); @@ -203,13 +204,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(spaces, ref_slns, slns); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 2); + DefaultErrorCalculator error_calculator(errorType, 2); error_calculator.calculate_errors(slns, exact_slns); double err_exact_rel_total = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(slns, ref_slns); double err_est_rel_total = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(spaces, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -238,7 +240,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 4964da3..48d5931 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -40,10 +40,11 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. @@ -112,7 +113,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); newton.set_space(ref_space); try @@ -136,13 +137,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -171,7 +173,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index a12e5cb..4a89c43 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -34,6 +34,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -43,7 +44,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("battery.mesh", mesh); @@ -150,11 +151,13 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, ref_sln); - Adapt adaptivity(space, &error_calculator); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); @@ -168,7 +171,7 @@ int main(int argc, char* argv[]) // Skip the time spent to save the convergence graphs. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 118d233..9799558 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -38,6 +38,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -47,7 +48,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -106,7 +107,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -136,13 +137,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -171,7 +173,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 3fea851..b3b6125 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -38,6 +38,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -47,7 +48,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. @@ -110,7 +111,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -140,13 +141,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -175,7 +177,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index f8c776b..47d5ca6 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -38,6 +38,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -47,7 +48,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -106,7 +107,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -136,13 +137,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -171,7 +173,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/09-wave-front-kelly/main.cpp b/2d-benchmarks-nist/09-wave-front-kelly/main.cpp index 98c68d2..28dc316 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly/main.cpp +++ b/2d-benchmarks-nist/09-wave-front-kelly/main.cpp @@ -186,6 +186,7 @@ SpaceSharedPtr space(new // Create an H1 space with default shapeset. // Calculate element errors and total error estimate. Hermes::Hermes2D::BasicKellyAdapt adaptivity(&space); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); if (USE_ENERGY_NORM_NORMALIZATION) adaptivity.set_error_form(new EnergyErrorForm(&wf)); diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index 490f336..1545889 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -44,6 +44,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -91,7 +92,7 @@ int main(int argc, char* argv[]) break; } - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. @@ -155,7 +156,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -185,13 +186,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -220,7 +222,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 689f8ef..5d21e99 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -40,6 +40,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -49,7 +50,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -109,7 +110,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -139,13 +140,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -174,7 +176,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index d468a89..ff44d24 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -44,6 +44,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -53,7 +54,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -109,7 +110,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -139,13 +140,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -174,7 +176,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 63fe09d..b461b31 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -30,20 +30,21 @@ const double alpha_p = 1000.0; const double epsilon = 1.0 / 100.0; // Initial polynomial degree of mesh elements. -const int P_INIT = 3; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; +const int INIT_REF_NUM = 0; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; +const double THRESHOLD = 0.8; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionLevels; // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; +const CandList CAND_LIST = H2D_HP_ANISO; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -53,7 +54,7 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("lshape.mesh", mesh); @@ -113,7 +114,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -143,13 +144,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(RelativeErrorToGlobalNorm, 1); + DefaultErrorCalculator error_calculator(errorType, 1); error_calculator.calculate_errors(sln, exact_sln); double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -178,7 +180,7 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP) done = true; From 42a894c56b09d0965d16d5b6caead638959211a9 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 25 Apr 2013 20:32:48 +0200 Subject: [PATCH 21/64] Changes in examples. --- .../01-analytic-solution/CMakeLists.txt | 2 +- .../02-reentrant-corner/CMakeLists.txt | 2 +- .../03-linear-elasticity/CMakeLists.txt | 2 +- .../03-linear-elasticity/main.cpp | 1 + .../04-exponential-peak/CMakeLists.txt | 2 +- .../04-exponential-peak/definitions.cpp | 2 +- .../04-exponential-peak/main.cpp | 140 ++++++------------ 2d-benchmarks-nist/05-battery/CMakeLists.txt | 2 +- .../06-boundary-layer/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- .../08-oscillatory/CMakeLists.txt | 2 +- .../09-wave-front/CMakeLists.txt | 2 +- .../CMakeLists.txt | 2 +- 2d-benchmarks-nist/11-kellogg/CMakeLists.txt | 2 +- .../12-multiple-difficulties/CMakeLists.txt | 2 +- 2d-benchmarks-nist/NIST-util.cpp | 89 +++++++++++ 2d-benchmarks-nist/NIST-util.h | 27 +++- 17 files changed, 172 insertions(+), 111 deletions(-) create mode 100644 2d-benchmarks-nist/NIST-util.cpp diff --git a/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt b/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt index 8230b32..377166a 100644 --- a/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt +++ b/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-01) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt b/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt index 8c7a365..f843522 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt +++ b/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-02) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt b/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt index e6c5d3a..2835760 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt +++ b/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-03) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 1beee54..fcb9bdb 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -182,6 +182,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); + newton.set_tolerance(1e-4); try { diff --git a/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt b/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt index 223c146..02497f8 100644 --- a/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt +++ b/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-04) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp index f4a3e6c..7f745aa 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp @@ -4,7 +4,7 @@ double CustomRightHandSide::value(double x, double y) const { double a_P = (-alpha * Hermes::pow((x - x_loc), 2) - alpha * Hermes::pow((y - y_loc), 2)); - return (4 * exp(a_P) * alpha * (alpha * (x - x_loc) * (x - x_loc) + return -(4 * exp(a_P) * alpha * (alpha * (x - x_loc) * (x - x_loc) + alpha * (y - y_loc) * (y - y_loc) - 1)); } diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 48d5931..275a39d 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -21,7 +21,7 @@ using namespace RefinementSelectors; // This problem has and exponential peak in the interior of the domain. // (x_loc, y_loc) is the location of the peak, and alpha determines the strenghth of the peak. -double alpha = 1000; +double alpha = 10; double x_loc = 0.5; double y_loc = 0.5; @@ -30,22 +30,22 @@ const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; +const double THRESHOLD = 0.75; // This is a stopping criterion for Adaptivity. const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; +const CandList CAND_LIST = H2D_HP_ANISO; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-2; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; int main(int argc, char* argv[]) { // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. mloader.load("square_quad.mesh", mesh); @@ -56,6 +56,8 @@ int main(int argc, char* argv[]) for (int i = 0; irefine_all_elements(); + basemesh->copy(mesh); + // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha, x_loc, y_loc)); @@ -63,8 +65,7 @@ int main(int argc, char* argv[]) CustomRightHandSide f(alpha, x_loc, y_loc); // Initialize weak formulation. - Hermes1DFunction lambda(1.0); - WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); + WeakFormsH1::DefaultWeakFormPoissonLinear wf(HERMES_ANY, &f); // Initialize boundary conditions DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); @@ -81,9 +82,9 @@ int main(int argc, char* argv[]) // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.show_mesh(false); - sview.fix_scale_width(50); - Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); + sview.set_3d_mode(true); + sview.fix_scale_width(); + Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); // DOF and CPU convergence graphs. SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; @@ -92,104 +93,49 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; // Assemble the discrete problem. - NewtonSolver newton; + LinearSolver newton; newton.set_weak_formulation(&wf); MeshFunctionSharedPtr ref_sln(new Solution()); - // Adaptivity loop: - int as = 1; bool done = false; - do + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + + int period = 5; + int number_of_steps = 100; + + for(int iteration = 0; iteration < number_of_steps; iteration++) { - cpu_time.tick(); + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + double position = period - std::abs((iteration % (2*period)) - period); + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow(position / period, 4.0))); - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); + alpha = 10. + factor * 1000.; + Hermes::Mixins::Loggable::Static::info("Iteration: %i, Position: %g, Factor: %g, Alpha: %g%.", iteration, position, factor, alpha); - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); - cpu_time.tick(); - - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - newton.set_space(ref_space); - try + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + + int as = 1; + while (!adaptive_step_single_space(mesh, exact_sln, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est,graph_dof_exact,graph_cpu_exact, error_calculator, adaptivity,as, ERR_STOP)) { - newton.solve(); + Linearizer lin; + char* filename = new char[1000]; + sprintf(filename, "Solution-%i.vtk", iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", true); + Orderizer ord; + sprintf(filename, "Orders-%i.vtk", iteration); + ord.save_orders_vtk(space, filename); + sprintf(filename, "Mesh-%i.vtk", iteration); + ord.save_mesh_vtk(space, filename); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - - // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); - - // View the coarse mesh solution and polynomial orders. - sview.show(sln); - oview.show(space); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_exact_rel < ERR_STOP) - done = true; - else - done = adaptivity.adapt(&selector); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - - // Increase the counter of adaptivity steps. - if (done == false) - as++; + std::cout << std::endl << "------------------------------------------------" << std::endl; } - while (done == false); - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); // Wait for all views to be closed. Views::View::wait(); diff --git a/2d-benchmarks-nist/05-battery/CMakeLists.txt b/2d-benchmarks-nist/05-battery/CMakeLists.txt index d428095..a9584dd 100644 --- a/2d-benchmarks-nist/05-battery/CMakeLists.txt +++ b/2d-benchmarks-nist/05-battery/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-05) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt b/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt index 3037101..c857f90 100644 --- a/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt +++ b/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-06) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt b/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt index d030885..d377387 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt +++ b/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-07) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt b/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt index a59b81a..5894ecc 100644 --- a/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt +++ b/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-08) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/09-wave-front/CMakeLists.txt b/2d-benchmarks-nist/09-wave-front/CMakeLists.txt index 2756abc..f185515 100644 --- a/2d-benchmarks-nist/09-wave-front/CMakeLists.txt +++ b/2d-benchmarks-nist/09-wave-front/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-09) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt b/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt index 13369dc..01b2897 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt +++ b/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-10) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/11-kellogg/CMakeLists.txt b/2d-benchmarks-nist/11-kellogg/CMakeLists.txt index a78331d..52ab58b 100644 --- a/2d-benchmarks-nist/11-kellogg/CMakeLists.txt +++ b/2d-benchmarks-nist/11-kellogg/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-11) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt b/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt index b1ffeac..cf12b3e 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt +++ b/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-12) -add_executable(${PROJECT_NAME} main.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp new file mode 100644 index 0000000..7d07656 --- /dev/null +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -0,0 +1,89 @@ +#include "NIST-util.h" + +bool adaptive_step_single_space( + MeshSharedPtr& mesh, + MeshFunctionSharedPtr& exact_sln, + SpaceSharedPtr& space, + MeshFunctionSharedPtr& sln, + MySelector& selector, + MeshFunctionSharedPtr& ref_sln, + Hermes::Mixins::TimeMeasurable& cpu_time, + LinearSolver& newton, + Views::ScalarView& sview, + Views::OrderView & oview, + SimpleGraph graph_dof_est, + SimpleGraph graph_cpu_est, + SimpleGraph graph_dof_exact, + SimpleGraph graph_cpu_exact, + ErrorCalculator& error_calculator, + Adapt& adaptivity, + int& as, + double ERR_STOP + ) +{ + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as++, ndof_ref); + cpu_time.tick(); + + newton.set_space(ref_space); + newton.solve(); + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection::project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + cpu_time.tick(); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(ref_sln); + oview.show(ref_space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_est_rel < ERR_STOP) + return true; + else + return adaptivity.adapt(&selector); + + } \ No newline at end of file diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index 86b8aa0..6f0370f 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -1,3 +1,6 @@ +#ifndef __NIST_UTIL_H +#define __NIST_UTIL_H + #include "hermes2d.h" using namespace Hermes::Hermes2D; @@ -30,4 +33,26 @@ class MySelector : public H1ProjBasedSelector candidates[i].score = 0; } } -}; \ No newline at end of file +}; + +bool adaptive_step_single_space( + MeshSharedPtr& mesh, + MeshFunctionSharedPtr& exact_sln, + SpaceSharedPtr& space, + MeshFunctionSharedPtr& sln, + MySelector& selector, + MeshFunctionSharedPtr& ref_sln, + Hermes::Mixins::TimeMeasurable& cpu_time, + LinearSolver& newton, + Views::ScalarView& sview, + Views::OrderView & oview, + SimpleGraph graph_dof_est, + SimpleGraph graph_cpu_est, + SimpleGraph graph_dof_exact, + SimpleGraph graph_cpu_exact, + ErrorCalculator& error_calculator, + Adapt& adaptivity, + int& as, + double ERR_STOP + ); +#endif \ No newline at end of file From 27243bbc5b97edf9930b71dc5af6be2269f6dff6 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 25 Apr 2013 23:17:38 +0200 Subject: [PATCH 22/64] Work on NIST benchmarks for FEMTEC. --- .../01-analytic-solution/main.cpp | 2 +- .../02-reentrant-corner/main.cpp | 2 +- .../03-linear-elasticity/main.cpp | 2 +- .../04-exponential-peak/main.cpp | 4 +- 2d-benchmarks-nist/05-battery/definitions.cpp | 14 ++ 2d-benchmarks-nist/05-battery/main.cpp | 156 +++++------------- .../06-boundary-layer/definitions.cpp | 4 +- .../06-boundary-layer/definitions.h | 6 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 147 ++++++----------- .../07-boundary-line-singularity/main.cpp | 2 +- .../08-oscillatory/definitions.cpp | 4 +- .../08-oscillatory/definitions.h | 6 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 132 +++++---------- 2d-benchmarks-nist/09-wave-front/main.cpp | 2 +- .../10-interior-line-singularity/main.cpp | 2 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 2 +- .../12-multiple-difficulties/main.cpp | 2 +- 2d-benchmarks-nist/NIST-util.cpp | 40 +++-- 2d-benchmarks-nist/NIST-util.h | 10 +- 19 files changed, 194 insertions(+), 345 deletions(-) diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 10828ca..74cf34e 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -37,7 +37,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 1ffa2bd..445227a 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -43,7 +43,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index fcb9bdb..4bc2a3d 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -54,7 +54,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 275a39d..d1391fd 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -76,6 +76,7 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); + MeshFunctionSharedPtr ref_sln(new Solution()); // Initialize refinement selector. MySelector selector(CAND_LIST); @@ -95,7 +96,6 @@ int main(int argc, char* argv[]) // Assemble the discrete problem. LinearSolver newton; newton.set_weak_formulation(&wf); - MeshFunctionSharedPtr ref_sln(new Solution()); // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) ((CustomExactSolution*)exact_sln.get())->alpha = alpha; int as = 1; - while (!adaptive_step_single_space(mesh, exact_sln, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est,graph_dof_exact,graph_cpu_exact, error_calculator, adaptivity,as, ERR_STOP)) + while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity, as, ERR_STOP, exact_sln, graph_dof_exact, graph_cpu_exact)) { Linearizer lin; char* filename = new char[1000]; diff --git a/2d-benchmarks-nist/05-battery/definitions.cpp b/2d-benchmarks-nist/05-battery/definitions.cpp index b1214d3..0dd26ef 100644 --- a/2d-benchmarks-nist/05-battery/definitions.cpp +++ b/2d-benchmarks-nist/05-battery/definitions.cpp @@ -330,6 +330,7 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om omega_1(omega_1), omega_2(omega_2), omega_3(omega_3), omega_4(omega_4), omega_5(omega_5), mesh(mesh), + /* p_1(25.0), p_2(7.0), p_3(5.0), @@ -341,6 +342,19 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om q_3(0.0001), q_4(0.2), q_5(0.05), + */ + + p_1(1.0), + p_2(1.0), + p_3(1.0), + p_4(1.0), + p_5(1.0), + + q_1(1.0), + q_2(1.0), + q_3(1.0), + q_4(1.0), + q_5(1.00), f_1(0.0), f_2(1.0), diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 4a89c43..d602a10 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -20,7 +20,7 @@ using namespace RefinementSelectors; // The following parameters can be changed: // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. @@ -33,7 +33,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance @@ -45,13 +45,18 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("battery.mesh", mesh); + MeshView m; + m.show(mesh); + View::wait(); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + basemesh->copy(mesh); + // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, P_INIT)); @@ -71,127 +76,56 @@ int main(int argc, char* argv[]) sview.show_mesh(false); OrderView oview("Polynomial orders", new WinGeom(330, 0, 300, 600)); - // DOF and CPU convergence graphs initialization. - SimpleGraph graph_dof, graph_cpu; - + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; + // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; - // Adaptivity loop: - int as = 1; bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - // Time measurement. - cpu_time.tick(); - - // Construct globally refined mesh and setup fine mesh space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - // Initialize fine mesh problem. - Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - newton.set_verbose_output(true); + int period = 5; + int number_of_steps = 100; + for(int iteration = 0; iteration < number_of_steps; iteration++) + { + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); - // Perform Newton's iteration. - try - { - newton.solve(); - } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - } + double position = period - std::abs((iteration % (2*period)) - period); + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow(position / period, 4.0))); - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + /* + alpha = 10. + factor * 1000.; + Hermes::Mixins::Loggable::Static::info("Iteration: %i, Position: %g, Factor: %g, Alpha: %g%.", iteration, position, factor, alpha); - // Time measurement. - cpu_time.tick(); + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + */ - // VTK output. - if (VTK_VISUALIZATION) + int as = 1; + while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) { - // Output solution in VTK format. - Views::Linearizer lin; - char* title = new char[100]; - sprintf(title, "sln-%d.vtk", as); - lin.save_solution_vtk(sln, title, "Potential", false); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", title); - - // Output mesh and element orders in VTK format. - Views::Orderizer ord; - sprintf(title, "ord-%d.vtk", as); - ord.save_orders_vtk(space, title); - Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", title); + Linearizer lin; + char* filename = new char[1000]; + sprintf(filename, "Solution-%i.vtk", iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", true); + Orderizer ord; + sprintf(filename, "Orders-%i.vtk", iteration); + ord.save_orders_vtk(space, filename); + sprintf(filename, "Mesh-%i.vtk", iteration); + ord.save_mesh_vtk(space, filename); } - - // View the coarse mesh solution and polynomial orders. - if (HERMES_VISUALIZATION) - { - sview.show(sln); - oview.show(space); - } - - // Skip visualization time. - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); - - // Add entry to DOF and CPU convergence graphs. - cpu_time.tick(); - graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); - graph_cpu.save("conv_cpu_est.dat"); - graph_dof.add_values(space->get_num_dofs(), err_est_rel); - graph_dof.save("conv_dof_est.dat"); - // Skip the time spent to save the convergence graphs. - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. - if (err_est_rel < ERR_STOP) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - done = adaptivity.adapt(&selector); - - // Increase the counter of performed adaptivity steps. - if (done == false) - as++; - } + std::cout << std::endl << "------------------------------------------------" << std::endl; } - while (done == false); - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Show the fine mesh solution - final result. - sview.set_title("Fine mesh solution"); - sview.show_mesh(false); - sview.show(ref_sln); // Wait for all views to be closed. Views::View::wait(); diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp index 9c8d3db..a50d79f 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp @@ -39,7 +39,7 @@ Ord CustomExactSolution::ord (Ord x, Ord y) const CustomWeakForm::CustomWeakForm(CustomRightHandSide* f) : WeakForm(1) { // Jacobian. - add_matrix_form(new CustomMatrixFormVol(0, 0, f->epsilon)); + add_matrix_form(new CustomMatrixFormVol(0, 0, f)); // Residual. add_vector_form(new CustomVectorFormVol(0, f)); } @@ -51,7 +51,7 @@ Scalar CustomWeakForm::CustomMatrixFormVol::matrix_form(int n, double *wt, Func< Scalar val = Scalar(0); for (int i = 0; i < n; i++) { - val += wt[i] * epsilon * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]); + val += wt[i] * f->epsilon * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]); val += wt[i] * (2*u->dx[i] + u->dy[i]) * v->val[i]; } diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index b57d906..e1a122d 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -50,8 +50,8 @@ class CustomWeakForm : public WeakForm class CustomMatrixFormVol : public MatrixFormVol { public: - CustomMatrixFormVol(int i, int j, double epsilon) - : MatrixFormVol(i, j), epsilon(epsilon) {}; + CustomMatrixFormVol(int i, int j, CustomRightHandSide* f) + : MatrixFormVol(i, j), f(f) {}; template Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, @@ -65,7 +65,7 @@ class CustomWeakForm : public WeakForm MatrixFormVol* clone() const; - double epsilon; + CustomRightHandSide* f; }; class CustomVectorFormVol : public VectorFormVol diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 9799558..7b58338 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -21,23 +21,23 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -const double epsilon = 1e-1; +double epsilon = 1e1; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; +const double THRESHOLD = 0.8; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionCumulative; // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; +const CandList CAND_LIST = H2D_HP_ANISO; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-3; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance @@ -49,13 +49,15 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + basemesh->copy(mesh); + // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, epsilon)); @@ -73,7 +75,7 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution()); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. MySelector selector(CAND_LIST); @@ -90,104 +92,51 @@ int main(int argc, char* argv[]) // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; - // Adaptivity loop: - int as = 1; bool done = false; - do - { - cpu_time.tick(); + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); + int number_of_steps = 14; + for(int iteration = 0; iteration < number_of_steps; iteration++) + { + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + if(iteration < number_of_steps / 2) + epsilon = epsilon / 2.; + else if(iteration >= number_of_steps / 2 && iteration < number_of_steps) + epsilon = epsilon * 2.; + else if(iteration >= number_of_steps && iteration < number_of_steps * 3/2) + epsilon = epsilon / 2.; + else + epsilon = epsilon * 2.; - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); - cpu_time.tick(); - - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - - - MeshFunctionSharedPtr ref_sln(new Solution()); - try + Hermes::Mixins::Loggable::Static::info("Iteration: %i, Epsilon: %g.", iteration, epsilon); + f.epsilon = epsilon; + ((CustomExactSolution*)exact_sln.get())->epsilon = epsilon; + + int as = 1; + while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) { - newton.solve(); + Linearizer lin; + char* filename = new char[1000]; + sprintf(filename, "Solution-%i.vtk", iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", true); + Orderizer ord; + sprintf(filename, "Orders-%i.vtk", iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%i.vtk", iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - - // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); - - // View the coarse mesh solution and polynomial orders. - sview.show(sln); - oview.show(space); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_exact_rel < ERR_STOP) - done = true; - else - done = adaptivity.adapt(&selector); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - // Increase the counter of adaptivity steps. - if (done == false) - as++; + std::cout << std::endl << "------------------------------------------------" << std::endl; } - while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index b3b6125..0693efb 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -37,7 +37,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.cpp b/2d-benchmarks-nist/08-oscillatory/definitions.cpp index 987e0a7..b5de5de 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.cpp +++ b/2d-benchmarks-nist/08-oscillatory/definitions.cpp @@ -48,7 +48,7 @@ Ord CustomExactSolution::ord (Ord x, Ord y) const CustomWeakForm::CustomWeakForm(CustomRightHandSide* f) : WeakForm(1) { // Jacobian. - add_matrix_form(new CustomMatrixFormVol(0, 0, f->alpha)); + add_matrix_form(new CustomMatrixFormVol(0, 0, f)); // Residual. add_vector_form(new CustomVectorFormVol(0, f)); } @@ -63,7 +63,7 @@ Scalar CustomWeakForm::CustomMatrixFormVol::matrix_form(int n, double *wt, Func< Scalar x = e->x[i]; Scalar y = e->y[i]; Scalar r = Hermes::sqrt(x*x + y*y); - Scalar h = 1/(alpha + r); + Scalar h = 1/(f->alpha + r); Scalar grad_u_grad_v = u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]; val += wt[i] * (grad_u_grad_v - Hermes::pow(h, 4) * u->val[i] * v->val[i]); } diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.h b/2d-benchmarks-nist/08-oscillatory/definitions.h index 9f87d6d..dc7ba52 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.h +++ b/2d-benchmarks-nist/08-oscillatory/definitions.h @@ -50,8 +50,8 @@ class CustomWeakForm : public WeakForm class CustomMatrixFormVol : public MatrixFormVol { public: - CustomMatrixFormVol(int i, int j, double alpha) - : MatrixFormVol(i, j), alpha(alpha) {}; + CustomMatrixFormVol(int i, int j, CustomRightHandSide* f) + : MatrixFormVol(i, j), f(f) {}; template Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, @@ -65,7 +65,7 @@ class CustomWeakForm : public WeakForm MatrixFormVol* clone() const; - double alpha; + CustomRightHandSide* f; }; class CustomVectorFormVol : public VectorFormVol diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 47d5ca6..cbd6ef2 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -21,7 +21,7 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -const double alpha = 1/(10*M_PI); +double alpha = 2. / M_PI; // Initial polynomial degree of mesh elements. const int P_INIT = 2; @@ -37,7 +37,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance @@ -49,12 +49,13 @@ bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + basemesh->copy(mesh); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); @@ -73,7 +74,7 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution()); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. MySelector selector(CAND_LIST); @@ -90,104 +91,47 @@ int main(int argc, char* argv[]) // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; - // Adaptivity loop: - int as = 1; bool done = false; - do + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + + int number_of_steps = 20; + for(int iteration = 0; iteration < number_of_steps; iteration++) { - cpu_time.tick(); + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + if(iteration < number_of_steps / 2) + alpha = alpha / std::sqrt(2.); + else + alpha = alpha * std::sqrt(2.); - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); + Hermes::Mixins::Loggable::Static::info("Iteration: %i, Alpha: %g.", iteration, alpha); + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); - cpu_time.tick(); - - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - - - MeshFunctionSharedPtr ref_sln(new Solution()); - try + int as = 1; + while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) { - newton.solve(); + Linearizer lin; + char* filename = new char[1000]; + sprintf(filename, "Solution-%i.vtk", iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false); + Orderizer ord; + sprintf(filename, "Orders-%i.vtk", iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%i.vtk", iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - - // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); - - // View the coarse mesh solution and polynomial orders. - sview.show(sln); - oview.show(space); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_exact_rel < ERR_STOP) - done = true; - else - done = adaptivity.adapt(&selector); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - // Increase the counter of adaptivity steps. - if (done == false) - as++; + std::cout << std::endl << "------------------------------------------------" << std::endl; } - while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index 1545889..db0b462 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -43,7 +43,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 5d21e99..3f37a40 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -39,7 +39,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index ff44d24..cbb165d 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -43,7 +43,7 @@ const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index b461b31..01d3711 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -43,7 +43,7 @@ const CandList CAND_LIST = H2D_HP_ANISO; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index 7d07656..ec87b7f 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -2,23 +2,23 @@ bool adaptive_step_single_space( MeshSharedPtr& mesh, - MeshFunctionSharedPtr& exact_sln, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, MySelector& selector, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, - LinearSolver& newton, + Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, SimpleGraph graph_dof_est, SimpleGraph graph_cpu_est, - SimpleGraph graph_dof_exact, - SimpleGraph graph_cpu_exact, ErrorCalculator& error_calculator, Adapt& adaptivity, int& as, - double ERR_STOP + double ERR_STOP, + MeshFunctionSharedPtr& exact_sln, + SimpleGraph graph_dof_exact, + SimpleGraph graph_cpu_exact ) { cpu_time.tick(); @@ -34,11 +34,11 @@ bool adaptive_step_single_space( Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as++, ndof_ref); cpu_time.tick(); - newton.set_space(ref_space); - newton.solve(); + solver.set_space(ref_space); + solver.solve(); // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + Solution::vector_to_solution(solver.get_sln_vector(), ref_space, ref_sln); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); @@ -48,8 +48,12 @@ bool adaptive_step_single_space( OGProjection::project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + double err_exact_rel; + if(exact_sln) + { + error_calculator.calculate_errors(sln, exact_sln); + err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + } error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; @@ -57,7 +61,9 @@ bool adaptive_step_single_space( // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%.", err_est_rel); + if(exact_sln) + Hermes::Mixins::Loggable::Static::info("err_exact_rel: %g%%.", err_exact_rel); // Time measurement. cpu_time.tick(); @@ -72,11 +78,13 @@ bool adaptive_step_single_space( graph_dof_est.save("conv_dof_est.dat"); graph_cpu_est.add_values(accum_time, err_est_rel); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - + if(exact_sln) + { + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + } cpu_time.tick(); // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index 6f0370f..32d3e7f 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -37,22 +37,22 @@ class MySelector : public H1ProjBasedSelector bool adaptive_step_single_space( MeshSharedPtr& mesh, - MeshFunctionSharedPtr& exact_sln, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, MySelector& selector, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, - LinearSolver& newton, + Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, SimpleGraph graph_dof_est, SimpleGraph graph_cpu_est, - SimpleGraph graph_dof_exact, - SimpleGraph graph_cpu_exact, ErrorCalculator& error_calculator, Adapt& adaptivity, int& as, - double ERR_STOP + double ERR_STOP, + MeshFunctionSharedPtr& exact_sln = MeshFunctionSharedPtr(), + SimpleGraph graph_dof_exact = SimpleGraph(), + SimpleGraph graph_cpu_exact = SimpleGraph() ); #endif \ No newline at end of file From 7ed458316dc8ee423e1ae59a083cd71aa5cb7cf1 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Fri, 26 Apr 2013 16:41:28 +0200 Subject: [PATCH 23/64] Progress on NIST benchmarks. --- .../01-analytic-solution/main.cpp | 7 +- .../02-reentrant-corner/main.cpp | 7 +- .../03-linear-elasticity/main.cpp | 7 +- .../04-exponential-peak/main.cpp | 5 +- 2d-benchmarks-nist/05-battery/main.cpp | 4 +- .../06-boundary-layer/definitions.h | 22 +-- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 7 +- .../07-boundary-line-singularity/main.cpp | 7 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 12 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 7 +- .../10-interior-line-singularity/main.cpp | 7 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 7 +- .../12-multiple-difficulties/main.cpp | 141 +++++------------- 13 files changed, 62 insertions(+), 178 deletions(-) diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 74cf34e..2b25173 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -43,8 +43,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -194,8 +192,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 445227a..8801ffa 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -49,8 +49,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -218,8 +216,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 4bc2a3d..200b47f 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -60,8 +60,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; // Problem parameters. @@ -260,8 +258,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index d1391fd..2a2c393 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -136,8 +136,5 @@ int main(int argc, char* argv[]) std::cout << std::endl << "------------------------------------------------" << std::endl; } - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index d602a10..9cb3efb 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -39,8 +39,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -127,7 +125,7 @@ int main(int argc, char* argv[]) std::cout << std::endl << "------------------------------------------------" << std::endl; } - // Wait for all views to be closed. + Views::View::wait(); return 0; diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index e1a122d..ace9481 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -22,21 +22,23 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction /* Exact solution */ -class CustomExactSolution : public ExactSolutionScalar +class CustomBC : public EssentialBoundaryCondition { public: - CustomExactSolution(MeshSharedPtr mesh, double epsilon) - : ExactSolutionScalar(mesh), epsilon(epsilon) {}; - - virtual double value(double x, double y) const; - - virtual void derivatives(double x, double y, double& dx, double& dy) const; + CustomBC(Hermes::vector markers, double amplitude = 1., double frequency = 1000.) + : EssentialBoundaryCondition(markers), amplitude(amplitude), frequency(frequency) + { + }; - virtual Ord ord (Ord x, Ord y) const; + inline typename EssentialBoundaryCondition::EssentialBCValueType get_value_type() const { return EssentialBoundaryCondition::BC_FUNCTION; } - MeshFunction* clone() const { return new CustomExactSolution(mesh, epsilon); } + virtual double value(double x, double y, double n_x, double n_y, double t_x, double t_y) const + { + return this->amplitude * std::sin(2 * M_PI * this->frequency * this->current_time); + } - double epsilon; + double amplitude; + double frequency; }; /* Weak forms */ diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 7b58338..eb6ca69 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -43,8 +43,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -139,8 +137,5 @@ int main(int argc, char* argv[]) } Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 0693efb..39bbff8 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -43,8 +43,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -194,8 +192,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index cbd6ef2..736c137 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -43,9 +43,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; - int main(int argc, char* argv[]) { // Load the mesh. @@ -75,7 +72,7 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); - + // Initialize refinement selector. MySelector selector(CAND_LIST); @@ -129,13 +126,10 @@ int main(int argc, char* argv[]) sprintf(filename, "Mesh-%i.vtk", iteration); ord.save_mesh_vtk(newton.get_space(0), filename); } - + std::cout << std::endl << "------------------------------------------------" << std::endl; } - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - // Wait for all views to be closed. - Views::View::wait(); + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); return 0; } diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index db0b462..f7724d3 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -49,8 +49,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -239,8 +237,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 3f37a40..7b7941f 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -45,8 +45,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -193,8 +191,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index cbb165d..c802c68 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -49,8 +49,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -193,8 +191,5 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Wait for all views to be closed. - Views::View::wait(); - return 0; +return 0; } diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 01d3711..f951576 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -49,18 +49,16 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; -bool HERMES_VISUALIZATION = false; -bool VTK_VISUALIZATION = false; - int main(int argc, char* argv[]) { // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("lshape.mesh", mesh); // Perform initial mesh refinement. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + basemesh->copy(mesh); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p)); @@ -80,8 +78,8 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution()); - + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); + // Initialize refinement selector. MySelector selector(CAND_LIST); @@ -98,107 +96,42 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; // Adaptivity loop: - int as = 1; bool done = false; - do + NewtonSolver newton; + newton.set_weak_formulation(&wf); + + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + + int number_of_steps = 20; + for(int iteration = 0; iteration < number_of_steps; iteration++) { - cpu_time.tick(); - - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); - - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); - cpu_time.tick(); - - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - - - MeshFunctionSharedPtr ref_sln(new Solution()); - try + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + /* + Hermes::Mixins::Loggable::Static::info("Iteration: %i, Alpha: %g.", iteration, alpha); + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + */ + + int as = 1; + while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) { - newton.solve(); + Linearizer lin; + char* filename = new char[1000]; + sprintf(filename, "Solution-%i.vtk", iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false); + Orderizer ord; + sprintf(filename, "Orders-%i.vtk", iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%i.vtk", iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - - // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); - - // View the coarse mesh solution and polynomial orders. - sview.show(sln); - oview.show(space); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_exact_rel < ERR_STOP) - done = true; - else - done = adaptivity.adapt(&selector); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - - // Increase the counter of adaptivity steps. - if (done == false) - as++; - } - while (done == false); - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - // Wait for all views to be closed. - Views::View::wait(); + std::cout << std::endl << "------------------------------------------------" << std::endl; + } return 0; } From 0ff52a2a87c915ed599f1f2f6adb45278442f943 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 2 May 2013 01:25:29 +0200 Subject: [PATCH 24/64] Progress on NIST. --- .../04-exponential-peak/main.cpp | 218 +++++++++++++--- 2d-benchmarks-nist/05-battery/definitions.cpp | 20 +- 2d-benchmarks-nist/05-battery/definitions.h | 52 ++-- 2d-benchmarks-nist/05-battery/main.cpp | 242 ++++++++++++++---- 2d-benchmarks-nist/NIST-util.cpp | 99 +++---- 2d-benchmarks-nist/NIST-util.h | 53 +++- 6 files changed, 495 insertions(+), 189 deletions(-) diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 2a2c393..e11ac04 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -26,24 +26,36 @@ double x_loc = 0.5; double y_loc = 0.5; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.75; +double THRESHOLD = 0.5; // This is a stopping criterion for Adaptivity. const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +CandList CAND_LIST = H2D_H_ISO; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-2; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; int main(int argc, char* argv[]) { + const char* THRESHOLD_STRING = "Custom"; + + if(argc > 2) + { + CAND_LIST = CandList(atoi(argv[1])); + THRESHOLD = threshold_values[atoi(argv[2])]; + THRESHOLD_STRING = thresholds[atoi(argv[2])]; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + + double ERR_STOP = 1.; + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; @@ -77,21 +89,16 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); MeshFunctionSharedPtr ref_sln(new Solution()); - + // Initialize refinement selector. MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.set_3d_mode(true); - sview.fix_scale_width(); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; // Assemble the discrete problem. LinearSolver newton; @@ -102,39 +109,166 @@ int main(int argc, char* argv[]) Adapt adaptivity(space, &error_calculator); adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - int period = 5; - int number_of_steps = 100; + sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; + + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); - for(int iteration = 0; iteration < number_of_steps; iteration++) + int iterations_count = 8; + int error_levels_count = 5; + double error_stop = ERR_STOP; + + for(int iteration = 0; iteration < iterations_count; iteration++) { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); + for(int error_level = 0; error_level < error_levels_count; error_level++) + { + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); - double position = period - std::abs((iteration % (2*period)) - period); - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow(position / period, 4.0))); + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); + alpha = 10. + factor * 2000.; + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); + + logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Alpha: %g%.", iteration, error_level, error_stop, factor, alpha); - alpha = 10. + factor * 1000.; - Hermes::Mixins::Loggable::Static::info("Iteration: %i, Position: %g, Factor: %g, Alpha: %g%.", iteration, position, factor, alpha); + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached; + + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + selector, + is_p(CAND_LIST) ? 1 : 0, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached, + exact_sln)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + } + } + catch(std::exception& e) + { + data.close(); + return -1; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - int as = 1; - while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity, as, ERR_STOP, exact_sln, graph_dof_exact, graph_cpu_exact)) - { - Linearizer lin; - char* filename = new char[1000]; - sprintf(filename, "Solution-%i.vtk", iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", true); - Orderizer ord; - sprintf(filename, "Orders-%i.vtk", iteration); - ord.save_orders_vtk(space, filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(space, filename); } - - std::cout << std::endl << "------------------------------------------------" << std::endl; } -return 0; -} + + data.close(); + return 0; +} \ No newline at end of file diff --git a/2d-benchmarks-nist/05-battery/definitions.cpp b/2d-benchmarks-nist/05-battery/definitions.cpp index 0dd26ef..3ab3235 100644 --- a/2d-benchmarks-nist/05-battery/definitions.cpp +++ b/2d-benchmarks-nist/05-battery/definitions.cpp @@ -330,7 +330,6 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om omega_1(omega_1), omega_2(omega_2), omega_3(omega_3), omega_4(omega_4), omega_5(omega_5), mesh(mesh), - /* p_1(25.0), p_2(7.0), p_3(5.0), @@ -342,19 +341,6 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om q_3(0.0001), q_4(0.2), q_5(0.05), - */ - - p_1(1.0), - p_2(1.0), - p_3(1.0), - p_4(1.0), - p_5(1.0), - - q_1(1.0), - q_2(1.0), - q_3(1.0), - q_4(1.0), - q_5(1.00), f_1(0.0), f_2(1.0), @@ -394,9 +380,5 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om WeakForm* CustomWeakFormPoisson::clone() const { - return new CustomWeakFormPoisson(this->omega_1, this->omega_2, - this->omega_3, this->omega_4, - this->omega_5, this->bdy_left, - this->bdy_top, this->bdy_right, - this->bdy_bottom, this->mesh); + return new CustomWeakFormPoisson(*this); } \ No newline at end of file diff --git a/2d-benchmarks-nist/05-battery/definitions.h b/2d-benchmarks-nist/05-battery/definitions.h index f0d9dc1..f3b2580 100644 --- a/2d-benchmarks-nist/05-battery/definitions.h +++ b/2d-benchmarks-nist/05-battery/definitions.h @@ -105,23 +105,23 @@ class CustomWeakFormPoisson : public WeakForm const std::string omega_4; const std::string omega_5; - const double p_1; - const double p_2; - const double p_3; - const double p_4; - const double p_5; - - const double q_1; - const double q_2; - const double q_3; - const double q_4; - const double q_5; - - const double f_1; - const double f_2; - const double f_3; - const double f_4; - const double f_5; + double p_1; + double p_2; + double p_3; + double p_4; + double p_5; + + double q_1; + double q_2; + double q_3; + double q_4; + double q_5; + + double f_1; + double f_2; + double f_3; + double f_4; + double f_5; // Boundary markers. const std::string bdy_left; @@ -130,15 +130,15 @@ class CustomWeakFormPoisson : public WeakForm const std::string bdy_bottom; // Boundary condition coefficients for the four sides. - const double c_left; - const double c_top; - const double c_right; - const double c_bottom; - - const double g_n_left; - const double g_n_top; - const double g_n_right; - const double g_n_bottom; + double c_left; + double c_top; + double c_right; + double c_bottom; + + double g_n_left; + double g_n_top; + double g_n_right; + double g_n_bottom; virtual WeakForm* clone() const; }; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 9cb3efb..ca6ad0c 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -24,31 +24,41 @@ const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; +double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; +CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; - int main(int argc, char* argv[]) { + const char* THRESHOLD_STRING = "Custom"; + + if(argc > 2) + { + CAND_LIST = CandList(atoi(argv[1])); + THRESHOLD = threshold_values[atoi(argv[2])]; + THRESHOLD_STRING = thresholds[atoi(argv[2])]; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + + double ERR_STOP = 1.; + + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("battery.mesh", mesh); MeshView m; m.show(mesh); - View::wait(); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); @@ -70,15 +80,10 @@ int main(int argc, char* argv[]) // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 320, 600)); - sview.fix_scale_width(50); - sview.show_mesh(false); OrderView oview("Polynomial orders", new WinGeom(330, 0, 300, 600)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; // Assemble the discrete problem. NewtonSolver newton; @@ -89,45 +94,188 @@ int main(int argc, char* argv[]) Adapt adaptivity(space, &error_calculator); adaptivity.set_strategy(stoppingCriterion, THRESHOLD); - int period = 5; - int number_of_steps = 100; - for(int iteration = 0; iteration < number_of_steps; iteration++) + sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; + + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); + + int iterations_count = 8; + int error_levels_count = 5; + double error_stop = ERR_STOP; + + for(int iteration = 0; iteration < iterations_count; iteration++) { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); + for(int error_level = 0; error_level < error_levels_count; error_level++) + { + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); - double position = period - std::abs((iteration % (2*period)) - period); - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow(position / period, 4.0))); + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - /* - alpha = 10. + factor * 1000.; - Hermes::Mixins::Loggable::Static::info("Iteration: %i, Position: %g, Factor: %g, Alpha: %g%.", iteration, position, factor, alpha); + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - */ + wf.p_1 = (25.0) * factor * factor; + wf.p_2 = (7.0) * factor; + wf.p_3 = (5.0) * factor; + wf.p_4 = (0.2) * factor; + wf.p_5 = (0.05) * factor; + + wf.q_1 = 25. - (25.0) * factor; + wf.q_2 = 0.8 - (0.8) * factor; + wf.q_3 = 0.0001 - (0.0001) * factor; + wf.q_4 = 0.2 - (0.2) * factor; + wf.q_5 = 0.05 - (0.05) * factor; + + /* + wf.c_left = factor; + wf.c_top = factor + 1.; + wf.c_right = factor + 2.; + wf.c_bottom = factor + 3.; + + wf.g_n_left(0.0), + wf.g_n_top(3.0), + wf.g_n_right(2.0), + wf.g_n_bottom(1.0) + */ + + newton.set_weak_formulation(&wf); + + logger.info("Iteration: %i-%i, Error level: %g, Factor: %g.", iteration, error_level, error_stop, factor); + + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; + + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached = 0; + + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + selector, + is_p(CAND_LIST) ? 1 : 0, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + } + } + catch(std::exception& e) + { + data.close(); + return -1; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - int as = 1; - while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) - { - Linearizer lin; - char* filename = new char[1000]; - sprintf(filename, "Solution-%i.vtk", iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", true); - Orderizer ord; - sprintf(filename, "Orders-%i.vtk", iteration); - ord.save_orders_vtk(space, filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(space, filename); } - - std::cout << std::endl << "------------------------------------------------" << std::endl; } - - Views::View::wait(); - + data.close(); return 0; -} - +} \ No newline at end of file diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index ec87b7f..507693b 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -1,50 +1,55 @@ #include "NIST-util.h" +const char* thresholds[4] = { "Low", "Medium", "High" }; +const double threshold_values[4] = { 0.1, 0.5, 0.95 }; + bool adaptive_step_single_space( + Hermes::Mixins::Loggable* logger, MeshSharedPtr& mesh, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, - MySelector& selector, + Selector& selector, + unsigned int order_increase, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, - SimpleGraph graph_dof_est, - SimpleGraph graph_cpu_est, ErrorCalculator& error_calculator, Adapt& adaptivity, int& as, - double ERR_STOP, - MeshFunctionSharedPtr& exact_sln, - SimpleGraph graph_dof_exact, - SimpleGraph graph_cpu_exact + double error_stop, + double& error_reached, + int& dof_reached, + int& cache_searches, + int& cache_record_found, + int& cache_record_found_reinit, + int& cache_record_not_found, + double& exact_error_reached, + MeshFunctionSharedPtr& exact_sln ) { - cpu_time.tick(); - + try + { // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh, order_increase); SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = ref_space->get_num_dofs(); - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as++, ndof_ref); - cpu_time.tick(); - + logger->info("---- Adaptivity step %d (%d DOF):", as++, ndof_ref); + + solver.set_report_cache_hits_and_misses(); solver.set_space(ref_space); solver.solve(); // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(solver.get_sln_vector(), ref_space, ref_sln); - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + logger->info("Calculating error estimate and exact error."); OGProjection::project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. @@ -57,41 +62,39 @@ bool adaptive_step_single_space( error_calculator.calculate_errors(sln, ref_sln); double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + // Report results - skip time. cpu_time.tick(); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%.", err_est_rel); - if(exact_sln) - Hermes::Mixins::Loggable::Static::info("err_exact_rel: %g%%.", err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); + { + logger->info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + logger->info("err_est_rel: %g%%.", err_est_rel); + if(exact_sln) + logger->info("err_exact_rel: %g%%.", err_exact_rel); - // View the coarse mesh solution and polynomial orders. - sview.show(ref_sln); - oview.show(ref_space); + // View the coarse mesh solution and polynomial orders. + // sview.show(ref_sln); + // oview.show(ref_space); - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - if(exact_sln) - { - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); + error_reached = err_est_rel; + if(exact_sln) + exact_error_reached = err_exact_rel; + dof_reached = ndof_ref; + solver.get_cache_hits_and_misses(cache_searches, cache_record_found, cache_record_found_reinit, cache_record_not_found); } - cpu_time.tick(); + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_est_rel < ERR_STOP) + if (err_est_rel < error_stop) + { return true; + } else - return adaptivity.adapt(&selector); - - } \ No newline at end of file + { + adaptivity.adapt(&selector); + return false; + } + } + catch(std::exception& e) + { + std::cout << e.what(); + return true; + } +} \ No newline at end of file diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index 32d3e7f..cf9806b 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -7,6 +7,9 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +extern const char* thresholds[4]; +extern const double threshold_values[4]; + class MySelector : public H1ProjBasedSelector { public: @@ -33,26 +36,62 @@ class MySelector : public H1ProjBasedSelector candidates[i].score = 0; } } + + Hermes::vector create_candidates(Element* e, int quad_order) + { + Hermes::vector candidates; + + if(this->cand_list == H2D_NONE) + { + + // Get the current order range. + int current_min_order, current_max_order; + this->get_current_order_range(e, current_min_order, current_max_order); + + int order_h = H2D_GET_H_ORDER(quad_order), order_v = H2D_GET_V_ORDER(quad_order); + + if(current_max_order < std::max(order_h, order_v)) + current_max_order = std::max(order_h, order_v); + + int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); + int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); + + candidates.push_back(Cand(H2D_REFINEMENT_P, quad_order)); + candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); + candidates.push_back(Cand(H2D_REFINEMENT_H, quad_order, quad_order, quad_order, quad_order)); + + return candidates; + } + else + { + return H1ProjBasedSelector::create_candidates(e, quad_order); + } + } }; bool adaptive_step_single_space( + Hermes::Mixins::Loggable* logger, MeshSharedPtr& mesh, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, - MySelector& selector, + Selector& selector, + unsigned int order_increase, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, - SimpleGraph graph_dof_est, - SimpleGraph graph_cpu_est, ErrorCalculator& error_calculator, Adapt& adaptivity, int& as, - double ERR_STOP, - MeshFunctionSharedPtr& exact_sln = MeshFunctionSharedPtr(), - SimpleGraph graph_dof_exact = SimpleGraph(), - SimpleGraph graph_cpu_exact = SimpleGraph() + double error_stop, + double& error_reached, + int& dof_reached, + int& cache_searches, + int& cache_record_found, + int& cache_record_found_reinit, + int& cache_record_not_found, + double& exact_error_reached, + MeshFunctionSharedPtr& exact_sln = MeshFunctionSharedPtr() ); #endif \ No newline at end of file From c70a6d6de65e27f03ba2905889da5429cd20fa3a Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 5 May 2013 17:07:25 +0200 Subject: [PATCH 25/64] Progress. --- .../01-analytic-solution/main.cpp | 4 +- .../02-reentrant-corner/main.cpp | 4 +- .../03-linear-elasticity/main.cpp | 4 +- .../04-exponential-peak/main.cpp | 99 +++--- 2d-benchmarks-nist/05-battery/main.cpp | 4 +- .../06-boundary-layer/definitions.h | 22 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 308 ++++++++++++++---- .../07-boundary-line-singularity/main.cpp | 4 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 4 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 4 +- .../10-interior-line-singularity/main.cpp | 4 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 4 +- .../12-multiple-difficulties/main.cpp | 2 +- 2d-benchmarks-nist/NIST-util.cpp | 42 ++- 2d-benchmarks-nist/NIST-util.h | 209 ++++++++++-- 15 files changed, 541 insertions(+), 177 deletions(-) diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 2b25173..7858760 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -30,7 +30,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -146,7 +146,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index 8801ffa..a373b27 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -36,7 +36,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 200b47f..4fa2db5 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -47,7 +47,7 @@ const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.6; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) double err_est_rel_total = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(spaces, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index e11ac04..f87a3ba 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -29,33 +29,31 @@ double y_loc = 0.5; const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; -// This is a quantitative parameter of Adaptivity. -double THRESHOLD = 0.5; -// This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; - -// Predefined list of element refinement candidates. -CandList CAND_LIST = H2D_H_ISO; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. + +// Error stop type. const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +// Maximum allowed level of hanging node s. +const int MESH_REGULARITY = -1; + +// Error stop value (in percent). +double ERR_STOP = 0.1; int main(int argc, char* argv[]) { - const char* THRESHOLD_STRING = "Custom"; - + Selector* refinement_selector; + AdaptivityStoppingCriterion* stoppingCriterion; + char* resultStringIdentification; if(argc > 2) + resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); + else { - CAND_LIST = CandList(atoi(argv[1])); - THRESHOLD = threshold_values[atoi(argv[2])]; - THRESHOLD_STRING = thresholds[atoi(argv[2])]; + refinement_selector = new MySelector(hXORpSelectionBasedOnError); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); + resultStringIdentification = "Custom"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); - - double ERR_STOP = 1.; - + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; @@ -67,7 +65,6 @@ int main(int argc, char* argv[]) // Perform initial mesh refinements. for (int i = 0; irefine_all_elements(); - basemesh->copy(mesh); // Set exact solution. @@ -90,9 +87,6 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); MeshFunctionSharedPtr ref_sln(new Solution()); - // Initialize refinement selector. - MySelector selector(CAND_LIST); - // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); @@ -101,20 +95,22 @@ int main(int argc, char* argv[]) char* filename = new char[1000]; // Assemble the discrete problem. - LinearSolver newton; - newton.set_weak_formulation(&wf); + LinearSolver linear_solver; + linear_solver.set_weak_formulation(&wf); + linear_solver.set_UMFPACK_output(true, false); // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); - sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + sprintf(filename, "%s.csv", resultStringIdentification); std::ofstream data(filename); data.precision(10); data.setf( std::ios::fixed, std::ios::floatfield ); data << "Iteration" << ';' << + "ErrorLevel" << ';' << "CPUTime" << ';' << "AdaptivitySteps" << ';' << "dof_reached" << ';' << @@ -123,6 +119,9 @@ int main(int argc, char* argv[]) "total_cache_record_found" << ';' << "total_cache_record_found_reinit" << ';' << "total_cache_record_not_found" << ';' << + "max_FactorizationSize" << ';' << + "total_PeakMemoryUsage" << ';' << + "total_Flops" << ';' << "error_stop" << ';' << "error_reached" << ';' << "exact_error_reached" << @@ -131,7 +130,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable logger; logger.set_verbose_output(true); - int iterations_count = 8; + int iterations_count = 10; int error_levels_count = 5; double error_stop = ERR_STOP; @@ -144,7 +143,7 @@ int main(int argc, char* argv[]) space->assign_dofs(); double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - alpha = 10. + factor * 2000.; + alpha = 10. + factor * 5000.; f.alpha = alpha; ((CustomExactSolution*)exact_sln.get())->alpha = alpha; @@ -158,18 +157,24 @@ int main(int argc, char* argv[]) int total_cache_record_found = 0; int total_cache_record_found_reinit = 0; int total_cache_record_not_found = 0; + double total_PeakMemoryUsage = 0; + double total_Flops = 0; // Max. int as = 1; int dof_reached; double error_reached; double exact_error_reached; + double max_FactorizationSize = 0; // One step. int cache_searches; int cache_record_found; int cache_record_found_reinit; int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; @@ -184,11 +189,11 @@ int main(int argc, char* argv[]) mesh, space, sln, - selector, - is_p(CAND_LIST) ? 1 : 0, + refinement_selector, + 1, ref_sln, cpu_time, - newton, + linear_solver, sview, oview, error_calculator, @@ -202,6 +207,9 @@ int main(int argc, char* argv[]) cache_record_found_reinit, cache_record_not_found, exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops, exact_sln)) { dof_cumulative += dof_reached; @@ -210,6 +218,10 @@ int main(int argc, char* argv[]) total_cache_record_found += cache_record_found; total_cache_record_found_reinit += cache_record_found_reinit; total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; } } catch(std::exception& e) @@ -225,19 +237,24 @@ int main(int argc, char* argv[]) total_cache_record_found_reinit += cache_record_found_reinit; total_cache_record_not_found += cache_record_not_found; + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + cpu_time.tick(); { - sprintf(filename, "Solution-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%s-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(linear_solver.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(linear_solver.get_space(0), filename); } cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); data << iteration << ';' << + error_level << ';' << cpu_time.accumulated() << ';' << as - 1 << ';' << dof_reached << ';' << @@ -246,6 +263,9 @@ int main(int argc, char* argv[]) total_cache_record_found << ';' << total_cache_record_found_reinit << ';' << total_cache_record_not_found << ';' << + max_FactorizationSize << ';' << + total_PeakMemoryUsage << ';' << + total_Flops << ';' << error_stop << ';' << error_reached << ';' << exact_error_reached << @@ -262,6 +282,11 @@ int main(int argc, char* argv[]) std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; + std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; + std::cout << "total_Flops: " << total_Flops << std::endl; + + std::cout << "error_stop: " << error_stop << std::endl; std::cout << "error_reached: " << error_reached << std::endl; std::cout << "exact_error_reached: " << exact_error_reached << std::endl; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index ca6ad0c..da22f5d 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -26,7 +26,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. CandList CAND_LIST = H2D_HP_ANISO_H; @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); std::ofstream data(filename); diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index ace9481..e1a122d 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -22,23 +22,21 @@ class CustomRightHandSide : public Hermes::Hermes2DFunction /* Exact solution */ -class CustomBC : public EssentialBoundaryCondition +class CustomExactSolution : public ExactSolutionScalar { public: - CustomBC(Hermes::vector markers, double amplitude = 1., double frequency = 1000.) - : EssentialBoundaryCondition(markers), amplitude(amplitude), frequency(frequency) - { - }; + CustomExactSolution(MeshSharedPtr mesh, double epsilon) + : ExactSolutionScalar(mesh), epsilon(epsilon) {}; - inline typename EssentialBoundaryCondition::EssentialBCValueType get_value_type() const { return EssentialBoundaryCondition::BC_FUNCTION; } + virtual double value(double x, double y) const; - virtual double value(double x, double y, double n_x, double n_y, double t_x, double t_y) const - { - return this->amplitude * std::sin(2 * M_PI * this->frequency * this->current_time); - } + virtual void derivatives(double x, double y, double& dx, double& dy) const; - double amplitude; - double frequency; + virtual Ord ord (Ord x, Ord y) const; + + MeshFunction* clone() const { return new CustomExactSolution(mesh, epsilon); } + + double epsilon; }; /* Weak forms */ diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index eb6ca69..1ede963 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -24,36 +24,42 @@ using namespace RefinementSelectors; double epsilon = 1e1; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; -// This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.8; -// This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionCumulative; - -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e-3; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Newton tolerance -const double NEWTON_TOLERANCE = 1e-6; +// Error stop type. +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +// Maximum allowed level of hanging node s. +const int MESH_REGULARITY = -1; +// Error stop value (in percent). +double ERR_STOP = 0.1; int main(int argc, char* argv[]) { + Selector* refinement_selector; + AdaptivityStoppingCriterion* stoppingCriterion; + char* resultStringIdentification; + if(argc > 2) + resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); + else + { + refinement_selector = new MySelector(hXORpSelectionBasedOnError); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); + resultStringIdentification = "Custom"; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); - + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); basemesh->copy(mesh); // Set exact solution. @@ -75,67 +81,231 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); - // Initialize refinement selector. - MySelector selector(CAND_LIST); - // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.show_mesh(false); - sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); + + sprintf(filename, "%s.csv", resultStringIdentification); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "ErrorLevel" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "max_FactorizationSize" << ';' << + "total_PeakMemoryUsage" << ';' << + "total_Flops" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; + + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); - int number_of_steps = 14; - for(int iteration = 0; iteration < number_of_steps; iteration++) + int iterations_count = 10; + int error_levels_count = 5; + double error_stop = ERR_STOP; + + for(int iteration = 0; iteration < iterations_count; iteration++) { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - if(iteration < number_of_steps / 2) - epsilon = epsilon / 2.; - else if(iteration >= number_of_steps / 2 && iteration < number_of_steps) - epsilon = epsilon * 2.; - else if(iteration >= number_of_steps && iteration < number_of_steps * 3/2) - epsilon = epsilon / 2.; - else - epsilon = epsilon * 2.; - - Hermes::Mixins::Loggable::Static::info("Iteration: %i, Epsilon: %g.", iteration, epsilon); - f.epsilon = epsilon; - ((CustomExactSolution*)exact_sln.get())->epsilon = epsilon; - - int as = 1; - while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) + for(int error_level = 0; error_level < error_levels_count; error_level++) { - Linearizer lin; - char* filename = new char[1000]; - sprintf(filename, "Solution-%i.vtk", iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", true); - Orderizer ord; - sprintf(filename, "Orders-%i.vtk", iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + newton.set_UMFPACK_output(true, false); + + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); + epsilon = 10. / std::pow(2, (iteration + 2)); + f.epsilon = epsilon; + ((CustomExactSolution*)exact_sln.get())->epsilon = epsilon; + + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); + + logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Epsilon: %g%.", iteration, error_level, error_stop, factor, epsilon); + + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; + double total_PeakMemoryUsage = 0; + double total_Flops = 0; + + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached; + double max_FactorizationSize = 0; + + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + refinement_selector, + 1, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops, + exact_sln)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + } + } + catch(std::exception& e) + { + logger.info(e.what()); + data << + iteration << ';' << + error_level << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << + std::endl; + continue; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + error_level << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + max_FactorizationSize << ';' << + total_PeakMemoryUsage << ';' << + total_Flops << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; + std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; + std::cout << "total_Flops: " << total_Flops << std::endl; + + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; + } - - std::cout << std::endl << "------------------------------------------------" << std::endl; } - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; -} + + data.close(); + return 0; +} \ No newline at end of file diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index 39bbff8..b51939d 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -30,7 +30,7 @@ const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -146,7 +146,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 736c137..9d78d46 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -30,7 +30,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); int number_of_steps = 20; for(int iteration = 0; iteration < number_of_steps; iteration++) diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index f7724d3..35ca366 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -36,7 +36,7 @@ const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 7b7941f..9110227 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -32,7 +32,7 @@ const int INIT_REF_NUM = 0; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index c802c68..e210fb5 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -36,7 +36,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionSingleElement; +AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) double err_est_rel = error_calculator.get_total_error_squared() * 100.0; Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index f951576..3f10a8d 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion, THRESHOLD); + adaptivity.set_strategy(stoppingCriterion); int number_of_steps = 20; for(int iteration = 0; iteration < number_of_steps; iteration++) diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index 507693b..53de722 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -1,14 +1,41 @@ #include "NIST-util.h" -const char* thresholds[4] = { "Low", "Medium", "High" }; -const double threshold_values[4] = { 0.1, 0.5, 0.95 }; +const char* thresholds[7] = { "Lowest", "Low", "Lower", "Medium", "High", "Higher", "Highest" }; +const double threshold_values[7] = { 0.05, 0.2, 0.4, 0.5, 0.6, 0.8, 0.95 }; +extern const char* strategies[6] = { + "noSelectionH", + "noSelectionHP", + "hXORpError", + "hORpDOFs", + "isoHPDOFs", + "anisoHPDOFs" +}; + +char* process_arguments_main_comparison(int argc, char* argv[], Selector*& selector, AdaptivityStoppingCriterion*& stoppingCriterion) +{ + assert(argc > 2); + + char* toReturn = new char[1000]; + + int selectorIndex = atoi(argv[1]); + + selector = new MySelector((hpAdaptivityStrategy)selectorIndex); + + int stoppingCriterionIndex = atoi(argv[2]); + + stoppingCriterion = new AdaptStoppingCriterionSingleElement(threshold_values[stoppingCriterionIndex]); + + sprintf(toReturn, "%s-%s", strategies[selectorIndex], thresholds[stoppingCriterionIndex]); + + return toReturn; +} bool adaptive_step_single_space( Hermes::Mixins::Loggable* logger, MeshSharedPtr& mesh, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, - Selector& selector, + Selector* selector, unsigned int order_increase, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, @@ -26,6 +53,9 @@ bool adaptive_step_single_space( int& cache_record_found_reinit, int& cache_record_not_found, double& exact_error_reached, + double& FactorizationSize, + double& PeakMemoryUsage, + double& Flops, MeshFunctionSharedPtr& exact_sln ) { @@ -44,6 +74,9 @@ bool adaptive_step_single_space( solver.set_report_cache_hits_and_misses(); solver.set_space(ref_space); solver.solve(); + FactorizationSize = solver.get_UMFPACK_reporting_data(Solver::FactorizationSize); + PeakMemoryUsage = solver.get_UMFPACK_reporting_data(Solver::PeakMemoryUsage); + Flops = solver.get_UMFPACK_reporting_data(Solver::Flops); // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(solver.get_sln_vector(), ref_space, ref_sln); @@ -88,13 +121,14 @@ bool adaptive_step_single_space( } else { - adaptivity.adapt(&selector); + adaptivity.adapt(selector); return false; } } catch(std::exception& e) { std::cout << e.what(); + throw; return true; } } \ No newline at end of file diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index cf9806b..f9c0edf 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -7,74 +7,208 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; -extern const char* thresholds[4]; -extern const double threshold_values[4]; +extern const char* thresholds[7]; +extern const double threshold_values[7]; + +enum hpAdaptivityStrategy +{ + noSelectionH = 0, + noSelectionHP = 1, + hXORpSelectionBasedOnError = 2, + hORpSelectionBasedOnDOFs = 3, + isoHPSelectionBasedOnDOFs = 4, + anisoHPSelectionBasedOnDOFs = 5 +}; +extern const char* strategies[6]; class MySelector : public H1ProjBasedSelector { public: - MySelector(CandList cand_list) : H1ProjBasedSelector(cand_list) + MySelector(hpAdaptivityStrategy strategy) : H1ProjBasedSelector(cand_list), strategy(strategy) { } private: - void evaluate_cands_score(Hermes::vector& candidates, Element* e) + bool select_refinement(Element* element, int order, MeshFunction* rsln, ElementToRefine& refinement) { - //calculate score of candidates - Cand& unrefined = candidates[0]; - const int num_cands = (int)candidates.size(); - unrefined.score = 0; - - for (int i = 1; i < num_cands; i++) + switch(strategy) { - Cand& cand = candidates[i]; - if(cand.error < unrefined.error) + case(noSelectionH): { - double delta_dof = cand.dofs - unrefined.dofs; - candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; + refinement.split = H2D_REFINEMENT_H; + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = + order; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); + return true; } - else - candidates[i].score = 0; + break; + case(noSelectionHP): + { + int max_allowed_order = this->max_order; + if(this->max_order == H2DRS_DEFAULT_ORDER) + max_allowed_order = H2DRS_MAX_ORDER; + int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); + int increased_order_h = std::min(max_allowed_order, order_h + 1), increased_order_v = std::min(max_allowed_order, order_v + 1); + int increased_order; + if(element->is_triangle()) + increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_h); + else + increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_v); + + refinement.split = H2D_REFINEMENT_H; + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = + increased_order; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); + return true; + } + case(hXORpSelectionBasedOnError): + { + //make an uniform order in a case of a triangle + int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); + + int current_min_order, current_max_order; + this->get_current_order_range(element, current_min_order, current_max_order); + + if(current_max_order < std::max(order_h, order_v)) + current_max_order = std::max(order_h, order_v); + + int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); + int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); + + //build candidates. + Hermes::vector candidates; + candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); + candidates.push_back(Cand(H2D_REFINEMENT_H, order, order, order, order)); + Cand* best_candidate = (candidates[0].error > candidates[1].error) ? &candidates[0] : &candidates[1]; + Cand* best_candidates_specific_type[4]; + best_candidates_specific_type[H2D_REFINEMENT_P] = &candidates[0]; + best_candidates_specific_type[H2D_REFINEMENT_H] = &candidates[1]; + best_candidates_specific_type[2] = NULL; + best_candidates_specific_type[3] = NULL; + + //copy result to output + refinement.split = best_candidate->split; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, best_candidate->p); + for(int i = 0; i < 4; i++) + if(best_candidates_specific_type[i] != NULL) + ElementToRefine::copy_orders(refinement.best_refinement_polynomial_order_type[i], best_candidates_specific_type[i]->p); + + ElementToRefine::copy_errors(refinement.errors, best_candidate->errors); + + //modify orders in a case of a triangle such that order_v is zero + if(element->is_triangle()) + for(int i = 0; i < H2D_MAX_ELEMENT_SONS; i++) + refinement.refinement_polynomial_order[i] = H2D_MAKE_QUAD_ORDER(H2D_GET_H_ORDER(refinement.refinement_polynomial_order[i]), 0); + + return true; + } + default: + H1ProjBasedSelector::select_refinement(element, order, rsln, refinement); + return true; + break; } } - + Hermes::vector create_candidates(Element* e, int quad_order) { Hermes::vector candidates; - if(this->cand_list == H2D_NONE) - { - - // Get the current order range. - int current_min_order, current_max_order; - this->get_current_order_range(e, current_min_order, current_max_order); + // Get the current order range. + int current_min_order, current_max_order; + this->get_current_order_range(e, current_min_order, current_max_order); - int order_h = H2D_GET_H_ORDER(quad_order), order_v = H2D_GET_V_ORDER(quad_order); + int order_h = H2D_GET_H_ORDER(quad_order), order_v = H2D_GET_V_ORDER(quad_order); - if(current_max_order < std::max(order_h, order_v)) - current_max_order = std::max(order_h, order_v); + if(current_max_order < std::max(order_h, order_v)) + current_max_order = std::max(order_h, order_v); - int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); - int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); + int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); + int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); - candidates.push_back(Cand(H2D_REFINEMENT_P, quad_order)); - candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); - candidates.push_back(Cand(H2D_REFINEMENT_H, quad_order, quad_order, quad_order, quad_order)); - - return candidates; + switch(strategy) + { + case(hORpSelectionBasedOnDOFs): + { + candidates.push_back(Cand(H2D_REFINEMENT_P, quad_order)); + } + case(hXORpSelectionBasedOnError): + { + candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); + candidates.push_back(Cand(H2D_REFINEMENT_H, quad_order, quad_order, quad_order, quad_order)); + return candidates; + } + break; + case(isoHPSelectionBasedOnDOFs): + { + this->cand_list = H2D_HP_ISO; + return H1ProjBasedSelector::create_candidates(e, quad_order); + } + break; + case(anisoHPSelectionBasedOnDOFs): + { + this->cand_list = H2D_HP_ANISO; + return H1ProjBasedSelector::create_candidates(e, quad_order); + } + break; } - else + } + + void evaluate_cands_score(Hermes::vector& candidates, Element* e) + { + switch(strategy) { - return H1ProjBasedSelector::create_candidates(e, quad_order); + case(hXORpSelectionBasedOnError): + { + if(candidates[0].error > candidates[1].error) + { + candidates[0].score = 0.0; + candidates[1].score = 1.0; + } + else + { + candidates[1].score = 0.0; + candidates[0].score = 1.0; + } + } + break; + default: + { + //calculate score of candidates + Cand& unrefined = candidates[0]; + const int num_cands = (int)candidates.size(); + unrefined.score = 0; + + for (int i = 1; i < num_cands; i++) + { + Cand& cand = candidates[i]; + if(cand.error < unrefined.error) + { + double delta_dof = cand.dofs - unrefined.dofs; + candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; + } + else + candidates[i].score = 0; + } + } } } + + int strategy; }; +char* process_arguments_main_comparison(int argc, char* argv[], Selector*& selector, AdaptivityStoppingCriterion*& stoppingCriterion); + bool adaptive_step_single_space( Hermes::Mixins::Loggable* logger, MeshSharedPtr& mesh, SpaceSharedPtr& space, MeshFunctionSharedPtr& sln, - Selector& selector, + Selector* selector, unsigned int order_increase, MeshFunctionSharedPtr& ref_sln, Hermes::Mixins::TimeMeasurable& cpu_time, @@ -92,6 +226,9 @@ bool adaptive_step_single_space( int& cache_record_found_reinit, int& cache_record_not_found, double& exact_error_reached, + double& FactorizationSize, + double& PeakMemoryUsage, + double& Flops, MeshFunctionSharedPtr& exact_sln = MeshFunctionSharedPtr() ); #endif \ No newline at end of file From 68a0211eb4f22da25035794a2f398d2790b35fc3 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 5 May 2013 19:28:48 +0200 Subject: [PATCH 26/64] Make 07 and 08 work. --- .../07-boundary-line-singularity/main.cpp | 352 +++++++++++------- 2d-benchmarks-nist/08-oscillatory/main.cpp | 292 ++++++++++++--- 2 files changed, 461 insertions(+), 183 deletions(-) diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index b51939d..c35793a 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -24,30 +24,36 @@ using namespace RefinementSelectors; double alpha = 0.6; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; -// This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +const int INIT_REF_NUM = 1; -// Newton tolerance -const double NEWTON_TOLERANCE = 1e-6; +// Error stop type. +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +// Maximum allowed level of hanging node s. +const int MESH_REGULARITY = -1; +// Error stop value (in percent). +double ERR_STOP = 0.1; int main(int argc, char* argv[]) { + Selector* refinement_selector; + AdaptivityStoppingCriterion* stoppingCriterion; + char* resultStringIdentification; + if(argc > 2) + resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); + else + { + refinement_selector = new MySelector(hXORpSelectionBasedOnError); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); + resultStringIdentification = "Custom"; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + // Load the mesh. - MeshSharedPtr mesh(new Mesh); + MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. mloader.load("square_quad.mesh", mesh); @@ -55,7 +61,9 @@ int main(int argc, char* argv[]) // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); + basemesh->copy(mesh); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); @@ -76,121 +84,215 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); + MeshFunctionSharedPtr ref_sln(new Solution()); - // Initialize refinement selector. - MySelector selector(CAND_LIST); - // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.show_mesh(false); - sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; + // Adaptivity loop. + DefaultErrorCalculator error_calculator(errorType, 1); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(stoppingCriterion); - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; + sprintf(filename, "%s.csv", resultStringIdentification); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "ErrorLevel" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "max_FactorizationSize" << ';' << + "total_PeakMemoryUsage" << ';' << + "total_Flops" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; - // Adaptivity loop: - int as = 1; bool done = false; - do + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); + + int iterations_count = 10; + int error_levels_count = 5; + double error_stop = ERR_STOP; + + for(int iteration = 0; iteration < iterations_count; iteration++) { - cpu_time.tick(); - - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator(mesh); - MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = ref_space->get_num_dofs(); - - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); - cpu_time.tick(); - - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - // Assemble the discrete problem. - DiscreteProblem dp(&wf, ref_space); - - NewtonSolver newton(&dp); - - - MeshFunctionSharedPtr ref_sln(new Solution()); - try + for(int error_level = 0; error_level < error_levels_count; error_level++) { - newton.solve(); + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + newton.set_UMFPACK_output(true, false); + + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); + alpha = 10. + factor * 5000.; + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); + + logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Alpha: %g%.", iteration, error_level, error_stop, factor, alpha); + + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; + double total_PeakMemoryUsage = 0; + double total_Flops = 0; + + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached; + double max_FactorizationSize = 0; + + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + refinement_selector, + 1, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops, + exact_sln)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + } + } + catch(std::exception& e) + { + data.close(); + return -1; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + error_level << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + max_FactorizationSize << ';' << + total_PeakMemoryUsage << ';' << + total_Flops << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; + std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; + std::cout << "total_Flops: " << total_Flops << std::endl; + + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; + } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into the instance of Solution. - Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - - // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); - - // Time measurement. - cpu_time.tick(); - double accum_time = cpu_time.accumulated(); - - // View the coarse mesh solution and polynomial orders. - sview.show(sln); - oview.show(space); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); - graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); - graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); - graph_cpu_exact.save("conv_cpu_exact.dat"); - - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized - // after ending due to this criterion. - if (err_exact_rel < ERR_STOP) - done = true; - else - done = adaptivity.adapt(&selector); - - cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); - - // Increase the counter of adaptivity steps. - if (done == false) - as++; } - while (done == false); - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; -} + + data.close(); + return 0; +} \ No newline at end of file diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 9d78d46..828072a 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -24,34 +24,42 @@ using namespace RefinementSelectors; double alpha = 2. / M_PI; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; -// This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; + +// Error stop type. const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +// Maximum allowed level of hanging node s. +const int MESH_REGULARITY = -1; -// Newton tolerance -const double NEWTON_TOLERANCE = 1e-6; +// Error stop value (in percent). +double ERR_STOP = 1.0; int main(int argc, char* argv[]) { + Selector* refinement_selector; + AdaptivityStoppingCriterion* stoppingCriterion; + char* resultStringIdentification; + if(argc > 2) + resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); + else + { + refinement_selector = new MySelector(hXORpSelectionBasedOnError); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); + resultStringIdentification = "Custom"; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); basemesh->copy(mesh); // Set exact solution. @@ -72,64 +80,232 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); - - // Initialize refinement selector. - MySelector selector(CAND_LIST); - + // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.show_mesh(false); - sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); adaptivity.set_strategy(stoppingCriterion); - int number_of_steps = 20; - for(int iteration = 0; iteration < number_of_steps; iteration++) - { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); + sprintf(filename, "%s.csv", resultStringIdentification); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "ErrorLevel" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "max_FactorizationSize" << ';' << + "total_PeakMemoryUsage" << ';' << + "total_Flops" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; - if(iteration < number_of_steps / 2) - alpha = alpha / std::sqrt(2.); - else - alpha = alpha * std::sqrt(2.); + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); - Hermes::Mixins::Loggable::Static::info("Iteration: %i, Alpha: %g.", iteration, alpha); - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + int iterations_count = 10; + int error_levels_count = 5; + double error_stop = ERR_STOP; - int as = 1; - while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) + for(int iteration = 0; iteration < iterations_count; iteration++) + { + for(int error_level = 0; error_level < error_levels_count; error_level++) { - Linearizer lin; - char* filename = new char[1000]; - sprintf(filename, "Solution-%i.vtk", iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false); - Orderizer ord; - sprintf(filename, "Orders-%i.vtk", iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + newton.set_UMFPACK_output(true, false); + + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + alpha = (1. / M_PI) * std::pow(0.75, iteration); + f.alpha = alpha; + ((CustomExactSolution*)exact_sln.get())->alpha = alpha; + + error_stop = ERR_STOP / std::pow(2.0, (double)error_level); + + logger.info("Iteration: %i-%i, Error level: %g, Alpha: %g%.", iteration, error_level, error_stop, alpha); + + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; + double total_PeakMemoryUsage = 0; + double total_Flops = 0; + + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached; + double max_FactorizationSize = 0; - std::cout << std::endl << "------------------------------------------------" << std::endl; + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + refinement_selector, + 1, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops, + exact_sln)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + } + } + catch(std::exception& e) + { + logger.info(e.what()); + data << + iteration << ';' << + error_level << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << + std::endl; + continue; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + error_level << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + max_FactorizationSize << ';' << + total_PeakMemoryUsage << ';' << + total_Flops << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; + std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; + std::cout << "total_Flops: " << total_Flops << std::endl; + + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; + + } } - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + data.close(); return 0; } + From e8601849121e7ba5f4a5898bac2eb8b7146e6b96 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 6 May 2013 00:21:45 +0200 Subject: [PATCH 27/64] Add h-reference decision. Is this okay? --- 2d-benchmarks-nist/08-oscillatory/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 828072a..837a521 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -183,7 +183,7 @@ int main(int argc, char* argv[]) space, sln, refinement_selector, - 1, + (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, ref_sln, cpu_time, newton, From f285662abae6ff30b53747e0920f9993098092b8 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 6 May 2013 15:01:37 +0200 Subject: [PATCH 28/64] NIST-12 works. --- .../12-multiple-difficulties/lshape.mesh | 8 +- .../12-multiple-difficulties/main.cpp | 300 ++++++++++++++---- 2 files changed, 242 insertions(+), 66 deletions(-) diff --git a/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh b/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh index 61d3ac9..0f898f2 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh +++ b/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh @@ -17,12 +17,12 @@ elements = [ boundaries = [ [ 2, 1, "Bdy" ], - [ 3, 2, "Bdy" ], + [ 3, 2, "a" ], [ 1, 0, "Bdy" ], - [ 4, 3, "Bdy" ], - [ 5, 4, "Bdy" ], + [ 4, 3, "a" ], + [ 5, 4, "a" ], [ 0, 7, "Bdy" ], - [ 6, 5, "Bdy" ], + [ 6, 5, "a" ], [ 7, 6, "Bdy" ] ] diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 3f10a8d..8f974e2 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -21,43 +21,51 @@ using namespace RefinementSelectors; const double omega_c = 3.0 * M_PI / 2.0; const double x_w = 0.0; -const double y_w = -3.0 / 4.0; -const double r_0 = 3.0 / 4.0; +const double y_w = -1.0 / 4.0; +const double r_0 = 1.0 / 4.0; const double alpha_w = 200.0; -const double x_p = -Hermes::sqrt(5.0) / 4.0; -const double y_p = -1.0 / 4.0; -const double alpha_p = 1000.0; +const double x_p = 3.0 / 4.0; +const double y_p = 2.0 / 4.0; +const double alpha_p = 100.0; const double epsilon = 1.0 / 100.0; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; -// This is a quantitative parameter of Adaptivity. -const double THRESHOLD = 0.8; -// This is a stopping criterion for Adaptivity. -const AdaptivityStoppingCriterion stoppingCriterion = AdaptStoppingCriterionLevels; - -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const int INIT_REF_NUM = 0; + +// Error stop type. const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +// Maximum allowed level of hanging node s. +const int MESH_REGULARITY = -1; -// Newton tolerance -const double NEWTON_TOLERANCE = 1e-6; +// Error stop value (in percent). +double ERR_STOP = 10.0; int main(int argc, char* argv[]) { + Selector* refinement_selector; + AdaptivityStoppingCriterion* stoppingCriterion; + char* resultStringIdentification; + if(argc > 2) + resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); + else + { + refinement_selector = new MySelector(hXORpSelectionBasedOnError); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); + resultStringIdentification = "Custom"; + } + + sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("lshape.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); basemesh->copy(mesh); // Set exact solution. @@ -80,58 +88,226 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); - // Initialize refinement selector. - MySelector selector(CAND_LIST); - // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - sview.show_mesh(false); - sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Adaptivity loop: - NewtonSolver newton; - newton.set_weak_formulation(&wf); + Linearizer lin; + Orderizer ord; + char* filename = new char[1000]; // Adaptivity loop. DefaultErrorCalculator error_calculator(errorType, 1); Adapt adaptivity(space, &error_calculator); adaptivity.set_strategy(stoppingCriterion); - int number_of_steps = 20; - for(int iteration = 0; iteration < number_of_steps; iteration++) + sprintf(filename, "%s.csv", resultStringIdentification); + std::ofstream data(filename); + data.precision(10); + data.setf( std::ios::fixed, std::ios::floatfield ); + data << + "Iteration" << ';' << + "ErrorLevel" << ';' << + "CPUTime" << ';' << + "AdaptivitySteps" << ';' << + "dof_reached" << ';' << + "dof_cumulative" << ';' << + "total_cache_searches" << ';' << + "total_cache_record_found" << ';' << + "total_cache_record_found_reinit" << ';' << + "total_cache_record_not_found" << ';' << + "max_FactorizationSize" << ';' << + "total_PeakMemoryUsage" << ';' << + "total_Flops" << ';' << + "error_stop" << ';' << + "error_reached" << ';' << + "exact_error_reached" << + std::endl; + + Hermes::Mixins::Loggable logger; + logger.set_verbose_output(true); + + int iterations_count = 10; + int error_levels_count = 5; + double error_stop = ERR_STOP; + + for(int iteration = 0; iteration < iterations_count; iteration++) { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - /* - Hermes::Mixins::Loggable::Static::info("Iteration: %i, Alpha: %g.", iteration, alpha); - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - */ - - int as = 1; - while (!adaptive_step_single_space(mesh, space, sln, selector, ref_sln, cpu_time,newton,sview,oview,graph_dof_est,graph_cpu_est, error_calculator, adaptivity,as, ERR_STOP)) + for(int error_level = 0; error_level < error_levels_count; error_level++) { - Linearizer lin; - char* filename = new char[1000]; - sprintf(filename, "Solution-%i.vtk", iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false); - Orderizer ord; - sprintf(filename, "Orders-%i.vtk", iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + newton.set_UMFPACK_output(true, false); + + mesh->copy(basemesh); + space->set_uniform_order(P_INIT); + space->assign_dofs(); + + error_stop = ERR_STOP / std::pow(2.0, (double)error_level); + + logger.info("Iteration: %i-%i, Error level: %g%%.", iteration, error_level, error_stop); + + // Cumulative. + int dof_cumulative = 0; + int total_cache_searches = 0; + int total_cache_record_found = 0; + int total_cache_record_found_reinit = 0; + int total_cache_record_not_found = 0; + double total_PeakMemoryUsage = 0; + double total_Flops = 0; + + // Max. + int as = 1; + int dof_reached; + double error_reached; + double exact_error_reached; + double max_FactorizationSize = 0; - std::cout << std::endl << "------------------------------------------------" << std::endl; + // One step. + int cache_searches; + int cache_record_found; + int cache_record_found_reinit; + int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Tick. + cpu_time.tick(); + + try + { + while (!adaptive_step_single_space( + &logger, + mesh, + space, + sln, + refinement_selector, + 1, + ref_sln, + cpu_time, + newton, + sview, + oview, + error_calculator, + adaptivity, + as, + error_stop, + error_reached, + dof_reached, + cache_searches, + cache_record_found, + cache_record_found_reinit, + cache_record_not_found, + exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops, + exact_sln)) + { + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + } + } + catch(std::exception& e) + { + logger.info(e.what()); + data << + iteration << ';' << + error_level << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << + std::endl; + continue; + } + + dof_cumulative += dof_reached; + + total_cache_searches += cache_searches; + total_cache_record_found += cache_record_found; + total_cache_record_found_reinit += cache_record_found_reinit; + total_cache_record_not_found += cache_record_not_found; + + max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); + total_PeakMemoryUsage += PeakMemoryUsage; + total_Flops += Flops; + + cpu_time.tick(); + { + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + data << + iteration << ';' << + error_level << ';' << + cpu_time.accumulated() << ';' << + as - 1 << ';' << + dof_reached << ';' << + dof_cumulative << ';' << + total_cache_searches << ';' << + total_cache_record_found << ';' << + total_cache_record_found_reinit << ';' << + total_cache_record_not_found << ';' << + max_FactorizationSize << ';' << + total_PeakMemoryUsage << ';' << + total_Flops << ';' << + error_stop << ';' << + error_reached << ';' << + exact_error_reached << + std::endl; + + std::cout << std::endl << "Results:" << std::endl; + std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; + std::cout << "Adaptivity steps: " << as - 1 << std::endl; + std::cout << "dof_reached: " << dof_reached << std::endl; + std::cout << "dof_cumulative: " << dof_cumulative << std::endl; + + std::cout << "total_cache_searches: " << total_cache_searches << std::endl; + std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; + std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; + std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; + + std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; + std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; + std::cout << "total_Flops: " << total_Flops << std::endl; + + + std::cout << "error_stop: " << error_stop << std::endl; + std::cout << "error_reached: " << error_reached << std::endl; + std::cout << "exact_error_reached: " << exact_error_reached << std::endl; + + } } + + data.close(); return 0; -} +} \ No newline at end of file From 4507b9fbb0c714396365f168e61bd5b0bd548073 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 6 May 2013 15:01:57 +0200 Subject: [PATCH 29/64] Fix hXORpSelectionBasedOnError strategy. --- 2d-benchmarks-nist/NIST-util.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index f9c0edf..308891f 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -26,6 +26,10 @@ class MySelector : public H1ProjBasedSelector public: MySelector(hpAdaptivityStrategy strategy) : H1ProjBasedSelector(cand_list), strategy(strategy) { + if(strategy == hXORpSelectionBasedOnError) + { + //this->set_error_weights(1.0,1.0,1.0); + } } private: bool select_refinement(Element* element, int order, MeshFunction* rsln, ElementToRefine& refinement) @@ -84,7 +88,10 @@ class MySelector : public H1ProjBasedSelector Hermes::vector candidates; candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); candidates.push_back(Cand(H2D_REFINEMENT_H, order, order, order, order)); - Cand* best_candidate = (candidates[0].error > candidates[1].error) ? &candidates[0] : &candidates[1]; + + this->evaluate_cands_error(candidates, element, rsln); + + Cand* best_candidate = (candidates[0].error < candidates[1].error) ? &candidates[0] : &candidates[1]; Cand* best_candidates_specific_type[4]; best_candidates_specific_type[H2D_REFINEMENT_P] = &candidates[0]; best_candidates_specific_type[H2D_REFINEMENT_H] = &candidates[1]; From 0be7993ff1053072abb422fae9c16f97a1e05c26 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 8 May 2013 19:23:14 +0200 Subject: [PATCH 30/64] Update. --- .../04-exponential-peak/main.cpp | 26 ++++++++- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 4 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 8 +-- .../12-multiple-difficulties/main.cpp | 58 +++++++++++++------ 2d-benchmarks-nist/NIST-util.cpp | 6 +- 5 files changed, 73 insertions(+), 29 deletions(-) diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index f87a3ba..0c76a2a 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) space, sln, refinement_selector, - 1, + (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, ref_sln, cpu_time, linear_solver, @@ -226,8 +226,26 @@ int main(int argc, char* argv[]) } catch(std::exception& e) { - data.close(); - return -1; + logger.info(e.what()); + data << + iteration << ';' << + error_level << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << ';' << + -1. << + std::endl; + continue; } dof_cumulative += dof_reached; @@ -243,12 +261,14 @@ int main(int argc, char* argv[]) cpu_time.tick(); { + /* sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); ord.save_orders_vtk(linear_solver.get_space(0), filename); sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); ord.save_mesh_vtk(linear_solver.get_space(0), filename); + */ } cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 1ede963..18f7ac4 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) space, sln, refinement_selector, - 1, + (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, ref_sln, cpu_time, newton, @@ -255,12 +255,14 @@ int main(int argc, char* argv[]) cpu_time.tick(); { + /* sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); ord.save_orders_vtk(newton.get_space(0), filename); sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); ord.save_mesh_vtk(newton.get_space(0), filename); + */ } cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 837a521..260a62a 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -45,9 +45,9 @@ int main(int argc, char* argv[]) resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); else { - refinement_selector = new MySelector(hXORpSelectionBasedOnError); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); - resultStringIdentification = "Custom"; + refinement_selector = new MySelector(noSelectionH); + stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.4); + resultStringIdentification = "noSelectionH-Lower"; } sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) f.alpha = alpha; ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - error_stop = ERR_STOP / std::pow(2.0, (double)error_level); + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); logger.info("Iteration: %i-%i, Error level: %g, Alpha: %g%.", iteration, error_level, error_stop, alpha); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 8f974e2..41998a8 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -19,18 +19,18 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -const double omega_c = 3.0 * M_PI / 2.0; -const double x_w = 0.0; -const double y_w = -1.0 / 4.0; -const double r_0 = 1.0 / 4.0; -const double alpha_w = 200.0; -const double x_p = 3.0 / 4.0; -const double y_p = 2.0 / 4.0; -const double alpha_p = 100.0; -const double epsilon = 1.0 / 100.0; +double omega_c = 3.0 * M_PI / 2.0; +double x_w = 0.0; +double y_w = -1.0 / 4.0; +double r_0 = 1.0 / 4.0; +double alpha_w = 200.0; +double x_p = 3.0 / 4.0; +double y_p = 2.0 / 4.0; +double alpha_p = 100.0; +double epsilon = 1.0 / 100.0; // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 0; @@ -40,7 +40,7 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; const int MESH_REGULARITY = -1; // Error stop value (in percent). -double ERR_STOP = 10.0; +double ERR_STOP = 5.0; int main(int argc, char* argv[]) { @@ -58,6 +58,9 @@ int main(int argc, char* argv[]) sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + if(argc > 2 && atoi(argv[1]) == 0) + P_INIT = 2; + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; @@ -143,6 +146,23 @@ int main(int argc, char* argv[]) space->set_uniform_order(P_INIT); space->assign_dofs(); + x_w = 0.0 - (iteration / 9.) * 0.05; + y_w = (-1.0 / 4.0) - (iteration / 9.) * 0.5; + r_0 = (1.0 / 4.0) + (iteration / 9.) * 0.5; + x_p = (3.0 / 4.0) + ((-Hermes::sqrt(5.0) / 4.0) - (3.0 / 4.0)) * (iteration / 9.); + y_p = (2.0 / 4.0) - (iteration / 9.) * 0.75; + + f.x_w = x_w; + ((CustomExactSolution*)exact_sln.get())->x_w = x_w; + f.y_w = y_w; + ((CustomExactSolution*)exact_sln.get())->y_w = y_w; + f.r_0 = r_0; + ((CustomExactSolution*)exact_sln.get())->r_0 = r_0; + f.x_p = x_p; + ((CustomExactSolution*)exact_sln.get())->x_p = x_p; + f.y_p = y_p; + ((CustomExactSolution*)exact_sln.get())->y_p = y_p; + error_stop = ERR_STOP / std::pow(2.0, (double)error_level); logger.info("Iteration: %i-%i, Error level: %g%%.", iteration, error_level, error_stop); @@ -186,7 +206,7 @@ int main(int argc, char* argv[]) space, sln, refinement_selector, - 1, + (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, ref_sln, cpu_time, newton, @@ -257,12 +277,14 @@ int main(int argc, char* argv[]) cpu_time.tick(); { - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); + { + sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); + sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_orders_vtk(newton.get_space(0), filename); + sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); + ord.save_mesh_vtk(newton.get_space(0), filename); + } } cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index 53de722..4cb4df5 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -1,6 +1,6 @@ #include "NIST-util.h" -const char* thresholds[7] = { "Lowest", "Low", "Lower", "Medium", "High", "Higher", "Highest" }; +const char* thresholds[7] = { "Lowest", "Lower", "Low", "Medium", "High", "Higher", "Highest" }; const double threshold_values[7] = { 0.05, 0.2, 0.4, 0.5, 0.6, 0.8, 0.95 }; extern const char* strategies[6] = { "noSelectionH", @@ -104,8 +104,8 @@ bool adaptive_step_single_space( logger->info("err_exact_rel: %g%%.", err_exact_rel); // View the coarse mesh solution and polynomial orders. - // sview.show(ref_sln); - // oview.show(ref_space); + // sview.show(ref_sln); + // oview.show(ref_space); error_reached = err_est_rel; if(exact_sln) From 22b2fe8e86eb5320798117491246f1d87c460610 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sat, 18 May 2013 20:05:44 +0200 Subject: [PATCH 31/64] Progress on code cleaning. --- 2d-advanced/acoustics/apartment/main.cpp | 2 +- 2d-advanced/acoustics/horn-axisym/main.cpp | 2 +- .../linear-advection-dg-adapt/main.cpp | 2 +- .../linear-advection-diffusion/main.cpp | 2 +- .../elasticity-linear/bracket/main.cpp | 2 +- 2d-advanced/elasticity-linear/crack/main.cpp | 2 +- 2d-advanced/euler/coupling.cpp | 4 ++-- 2d-advanced/euler/coupling.h | 4 ++-- 2d-advanced/euler/forms_explicit.cpp | 20 +++++++++++++------ 2d-advanced/euler/forward-step-adapt/main.cpp | 6 +++--- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 6 +++--- .../heating-flow-coupling-adapt/main.cpp | 6 +++--- .../heating-induced-vortex-adapt/main.cpp | 6 +++--- .../euler/reflected-shock-adapt/main.cpp | 6 +++--- .../heat-and-moisture-adapt/main.cpp | 2 +- .../main.cpp | 2 +- .../maxwell/maxwell-debye-rk/definitions.cpp | 9 +++++++++ 2d-advanced/maxwell/microwave-oven/main.cpp | 2 +- .../definitions.cpp | 9 +++++++++ .../definitions.cpp | 9 +++++++++ 2d-advanced/navier-stokes/bearing/main.cpp | 6 +++--- .../circular-obstacle-adapt/main.cpp | 10 +++++----- .../navier-stokes/circular-obstacle/main.cpp | 6 +++--- .../navier-stokes/driven-cavity/main.cpp | 6 +++--- .../navier-stokes/ns-heat-subdomains/main.cpp | 10 +++++----- .../navier-stokes/rayleigh-benard/main.cpp | 10 +++++----- .../np-poisson-timedep-adapt/main.cpp | 2 +- 2d-advanced/neutronics/saphir/main.cpp | 2 +- .../richards/basic-rk-newton-adapt/main.cpp | 2 +- .../richards/capillary-barrier-adapt/main.cpp | 2 +- .../gross-pitaevski-adapt/main.cpp | 2 +- 2d-benchmarks-general/layer-boundary/main.cpp | 2 +- 2d-benchmarks-general/layer-interior/main.cpp | 2 +- 2d-benchmarks-general/lshape/main.cpp | 2 +- .../moving-front-space-adapt/main.cpp | 2 +- 2d-benchmarks-general/nonsym-check/main.cpp | 2 +- 2d-benchmarks-general/smooth-aniso-x/main.cpp | 2 +- 2d-benchmarks-general/smooth-aniso-y/main.cpp | 2 +- 2d-benchmarks-general/smooth-iso/main.cpp | 2 +- .../12-multiple-difficulties/main.cpp | 17 ++-------------- 40 files changed, 108 insertions(+), 86 deletions(-) diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index 2ec0672..e7c9db3 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinement selector. - H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector > selector(CAND_LIST); // Initialize views. ScalarView sview("Acoustic pressure", new WinGeom(0, 0, 600, 350)); diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index 1964591..9451ecc 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinement selector. - H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector > selector(CAND_LIST); // Initialize views. ScalarView sview_real("Solution - real part", new WinGeom(0, 0, 330, 350)); diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index c409ab6..5254239 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char* args[]) SpaceSharedPtr space(new L2Space(mesh, P_INIT)); // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + L2ProjBasedSelector selector(CAND_LIST); // Disable weighting of refinement candidates. selector.set_error_weights(1, 1, 1); diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 2313c34..6160124 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -99,7 +99,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 440, 350)); diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 6b76b8d..629c34f 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtru1_sln_ref(new Solution), u2_sln_ref(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView s_view_0("Solution (x-displacement)", new WinGeom(0, 0, 500, 350)); diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 0c34e8d..f4caed2 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr u1_sln_ref(new Solution), u2_sln_ref(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView s_view_0("Solution (x-displacement)", new WinGeom(0, 0, 700, 350)); diff --git a/2d-advanced/euler/coupling.cpp b/2d-advanced/euler/coupling.cpp index 28b33b1..d6ea4f6 100644 --- a/2d-advanced/euler/coupling.cpp +++ b/2d-advanced/euler/coupling.cpp @@ -1,7 +1,7 @@ #include "coupling.h" CouplingErrorFormVelocity::CouplingErrorFormVelocity(VelocityComponent component, double c_p) - : Adapt::MatrixFormVolError(component, 4), component(component), c_p(c_p) + : MatrixFormVol(component, 4), component(component), c_p(c_p) { } @@ -51,7 +51,7 @@ MatrixFormVol* CouplingErrorFormVelocity::clone() const } CouplingErrorFormTemperature::CouplingErrorFormTemperature(VelocityComponent component, double c_p) - : Adapt::MatrixFormVolError(4, component), component(component), c_p(c_p) + : MatrixFormVol(4, component), component(component), c_p(c_p) { } diff --git a/2d-advanced/euler/coupling.h b/2d-advanced/euler/coupling.h index 7359ed1..0ef584a 100644 --- a/2d-advanced/euler/coupling.h +++ b/2d-advanced/euler/coupling.h @@ -9,7 +9,7 @@ enum VelocityComponent velY = 2 }; -class CouplingErrorFormVelocity : public Adapt::MatrixFormVolError +class CouplingErrorFormVelocity : public MatrixFormVol { public: CouplingErrorFormVelocity(VelocityComponent component, double c_p); @@ -24,7 +24,7 @@ class CouplingErrorFormVelocity : public Adapt::MatrixFormVolError double c_p; }; -class CouplingErrorFormTemperature : public Adapt::MatrixFormVolError +class CouplingErrorFormTemperature : public MatrixFormVol { public: CouplingErrorFormTemperature(VelocityComponent component, double c_p); diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index d7541fa..fc333b0 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -264,9 +264,13 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm for(unsigned int i = 0; i < this->ext.size(); i++) { - MeshFunctionSharedPtr ext = static_cast >(this->ext[i]->clone()); - if((static_cast >(this->ext[i].get()))->get_type() == HERMES_SLN) - ext->set_type(HERMES_SLN); + MeshFunctionSharedPtr ext = this->ext[i]->clone(); + + if(dynamic_cast*>(this->ext[i].get())) + { + if((dynamic_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) + dynamic_cast*>(ext.get())->set_type(HERMES_SLN); + } wf->ext.push_back(ext); } @@ -1001,9 +1005,13 @@ class EulerEquationsWeakFormSemiImplicitCoupledWithHeat : public EulerEquationsW for(unsigned int i = 0; i < this->ext.size(); i++) { - MeshFunctionSharedPtr ext = static_cast >(this->ext[i]->clone()); - if((static_cast >(this->ext[i].get()))->get_type() == HERMES_SLN) - ext->set_type(HERMES_SLN); + MeshFunctionSharedPtr ext = this->ext[i]->clone(); + + if(dynamic_cast*>(this->ext[i].get())) + { + if((dynamic_cast*>(this->ext[i].get()))->get_type() == HERMES_SLN) + dynamic_cast*>(ext.get())->set_type(HERMES_SLN); + } wf->ext.push_back(ext); } diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index c25baee..419b9ec 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -241,7 +241,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), ref_spaces, true); @@ -309,12 +309,12 @@ int main(int argc, char* argv[]) ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index d2add37..5fd68b6 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -245,7 +245,7 @@ int main(int argc, char* argv[]) // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); @@ -311,12 +311,12 @@ int main(int argc, char* argv[]) ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index bfee262..da7fa3a 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -256,7 +256,7 @@ int main(int argc, char* argv[]) // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(cref_spaces, prev_slns, prev_slns, Hermes::vector(), iteration > 1); + OGProjection ogProjection; ogProjection.project_global(cref_spaces, prev_slns, prev_slns, Hermes::vector(), iteration > 1); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", @@ -301,12 +301,12 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse mesh-> Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); + ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); + Adapt* adaptivity = new Adapt(spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); adaptivity->set_error_form(new CouplingErrorFormVelocity(velX, C_P)); adaptivity->set_error_form(new CouplingErrorFormVelocity(velY, C_P)); adaptivity->set_norm_form(new CouplingErrorFormVelocity(velX, C_P)); diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 7f6139f..8944374 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -251,7 +251,7 @@ int main(int argc, char* argv[]) // Project the previous time level solution onto the new fine mesh-> Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); // Report NDOFs. @@ -297,12 +297,12 @@ int main(int argc, char* argv[]) ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index ba04351..400751a 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -264,7 +264,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); + Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); // Report NDOFs. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", @@ -300,12 +300,12 @@ int main(int argc, char* argv[]) ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index 99e5c0e..dce5732 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -164,7 +164,7 @@ int main(int argc, char* argv[]) k_TT, k_ww, T_EXTERIOR, W_EXTERIOR, "bdy_ext"); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Geometry and position of visualization windows. WinGeom* T_sln_win_geom = new WinGeom(0, 0, 300, 450); diff --git a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp index 1387398..0d1fc5f 100644 --- a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp +++ b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, space); // Create a refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Visualize initial condition. char title[100]; diff --git a/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp b/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp index 8ab8b8d..cd879e1 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp @@ -1,5 +1,14 @@ #include "definitions.h" +template +static Scalar int_e_f(int n, double *wt, Func *u, Func *v) +{ + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i])); + return result; +} + /* Global function alpha */ double alpha(double omega, double k) diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 613e358..2432e9f 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); // Initialize refinements selector. - HcurlProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + HcurlProjBasedSelector > selector(CAND_LIST); // Initialize views. ScalarView eview("Electric field", new WinGeom(0, 0, 580, 400)); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp index 1f4394a..055c745 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp @@ -1,5 +1,14 @@ #include "definitions.h" +template +static Scalar int_e_f(int n, double *wt, Func *u, Func *v) +{ + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i])); + return result; +} + CustomWeakFormWaveIE::CustomWeakFormWaveIE(double tau, double c_squared, MeshFunctionSharedPtr E_prev_sln, MeshFunctionSharedPtr F_prev_sln) : WeakForm(2) { // Jacobian. diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp index 32076bd..f365567 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp @@ -1,5 +1,14 @@ #include "definitions.h" +template +static Scalar int_e_f(int n, double *wt, Func *u, Func *v) +{ + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i])); + return result; +} + Scalar2 CustomInitialConditionWave::value (double x, double y) const { return Scalar2(std::sin(x) * std::cos(y), -std::cos(x) * std::sin(y)); diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index d80cdc4..ba135f4 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -137,11 +137,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif // Solutions for the Newton's iteration and time stepping. diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 19574eb..f8b105a 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -178,11 +178,11 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif // Solutions for the Newton's iteration and time stepping. @@ -208,7 +208,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V DiscreteProblem dp(&wf, spaces); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 750, 240)); @@ -305,7 +305,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V OGProjection ogProj; ogProj.project_global(Hermes::vector >(xvel_space, yvel_space, p_space), Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); + Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index d1c341d..12e8a54 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -120,11 +120,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif // Solutions for the Newton's iteration and time stepping. diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index ca78e5b..66b531b 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -127,11 +127,11 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif // Solutions for the Newton's iteration and time stepping. diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index 7235591..23d2fe7 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -127,14 +127,14 @@ int main(int argc, char* argv[]) yvel_space, p_space, temperature_space)); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif - ProjNormType temperature_proj_norm = HERMES_H1_NORM; - Hermes::vector all_proj_norms = Hermes::vector(vel_proj_norm, + NormType temperature_proj_norm = HERMES_H1_NORM; + Hermes::vector all_proj_norms = Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm, temperature_proj_norm); // Initial conditions and such. diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 5429b52..9182860 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -103,13 +103,13 @@ SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_V Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Define projection norms. - ProjNormType vel_proj_norm = HERMES_H1_NORM; + NormType vel_proj_norm = HERMES_H1_NORM; #ifdef PRESSURE_IN_L2 - ProjNormType p_proj_norm = HERMES_L2_NORM; + NormType p_proj_norm = HERMES_L2_NORM; #else - ProjNormType p_proj_norm = HERMES_H1_NORM; + NormType p_proj_norm = HERMES_H1_NORM; #endif - ProjNormType t_proj_norm = HERMES_H1_NORM; + NormType t_proj_norm = HERMES_H1_NORM; // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); @@ -142,7 +142,7 @@ SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_V double* coeff_vec = new double[Space::get_num_dofs(spaces)]; Hermes::Mixins::Loggable::Static::info("Projecting initial condition to obtain initial vector for the Newton's method."); OGProjection ogProjection; ogProjection.project_global(spaces, slns, coeff_vec, - Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm, t_proj_norm)); + Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm, t_proj_norm)); Hermes::Hermes2D::NewtonSolver newton(&dp); // Time-stepping loop: diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index f499b4d..efa4af3 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -262,7 +262,7 @@ int main (int argc, char* argv[]) { coeff_vec_coarse); // Create a selector which will select optimal candidate. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Visualization windows. char title[1000]; diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index 4a5c1a1..57eed5a 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 440, 350)); diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index 94185e8..b15af10 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -160,7 +160,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, space); // Create a refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Visualize initial condition. char title[100]; diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 19f6cc3..7159620 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -244,7 +244,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Create a selector which will select optimal candidate. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Solutions for the time stepping and the Newton's method. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp index 9e31194..fb2c266 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) DiscreteProblem > dp(&wf, space); // Create a refinement selector. - H1ProjBasedSelector > selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector > selector(CAND_LIST); // Visualize initial condition. char title[100]; diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index b814676..7146f69 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index 1867f44..faa1f66 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index e663767..f2369a9 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index fc01673..507be8f 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Visualize initial condition. char title[100]; diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index 70553bf..595dfee 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 907486d..4d5e00b 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index 78a5547..5f22e55 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index c6c7e9d..3be9e90 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 41998a8..d752459 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -40,7 +40,7 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; const int MESH_REGULARITY = -1; // Error stop value (in percent). -double ERR_STOP = 5.0; +double ERR_STOP = 0.05; int main(int argc, char* argv[]) { @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) logger.set_verbose_output(true); int iterations_count = 10; - int error_levels_count = 5; + int error_levels_count = 1; double error_stop = ERR_STOP; for(int iteration = 0; iteration < iterations_count; iteration++) @@ -275,19 +275,6 @@ int main(int argc, char* argv[]) total_PeakMemoryUsage += PeakMemoryUsage; total_Flops += Flops; - cpu_time.tick(); - { - { - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - data << iteration << ';' << error_level << ';' << From b275bfae3d2535a9154c3c2e13bc5742902df45c Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 19 May 2013 07:53:52 -0700 Subject: [PATCH 32/64] Finish up. --- 2d-advanced/CMakeLists.txt | 5 +- 2d-advanced/acoustics/apartment/main.cpp | 5 + 2d-advanced/elasticity-linear/CMakeLists.txt | 1 - .../elasticity-linear/crack/definitions.cpp | 7 +- .../elasticity-linear/crack/definitions.h | 3 +- .../elasticity-linear/crack/domain.xml | 65 +++ 2d-advanced/elasticity-linear/crack/main.cpp | 337 ++++-------- 2d-advanced/euler/CMakeLists.txt | 17 +- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 497 ++++++++---------- 2d-advanced/euler/gamm-channel/main.cpp | 226 ++++---- .../helmholtz/waveguide/definitions.cpp | 8 +- 2d-advanced/helmholtz/waveguide/definitions.h | 28 +- 2d-advanced/helmholtz/waveguide/domain.mesh | 2 + 2d-advanced/helmholtz/waveguide/main.cpp | 102 ++-- 2d-advanced/maxwell/CMakeLists.txt | 7 +- 2d-advanced/maxwell/magnetostatics/main.cpp | 20 +- 2d-advanced/miscellaneous/CMakeLists.txt | 1 - .../local-projection-test/CMakeLists.txt | 4 - .../local-projection-test/definitions.cpp | 17 - .../local-projection-test/definitions.h | 16 - .../local-projection-test/domain.mesh | 44 -- .../local-projection-test/domain.xml | 45 -- .../local-projection-test/main.cpp | 145 ----- CMakeLists.txt | 23 +- 24 files changed, 608 insertions(+), 1017 deletions(-) create mode 100644 2d-advanced/elasticity-linear/crack/domain.xml delete mode 100644 2d-advanced/miscellaneous/CMakeLists.txt delete mode 100644 2d-advanced/miscellaneous/local-projection-test/CMakeLists.txt delete mode 100644 2d-advanced/miscellaneous/local-projection-test/definitions.cpp delete mode 100644 2d-advanced/miscellaneous/local-projection-test/definitions.h delete mode 100644 2d-advanced/miscellaneous/local-projection-test/domain.mesh delete mode 100644 2d-advanced/miscellaneous/local-projection-test/domain.xml delete mode 100644 2d-advanced/miscellaneous/local-projection-test/main.cpp diff --git a/2d-advanced/CMakeLists.txt b/2d-advanced/CMakeLists.txt index 69b994d..c5ef428 100644 --- a/2d-advanced/CMakeLists.txt +++ b/2d-advanced/CMakeLists.txt @@ -36,7 +36,4 @@ IF(WITH_schroedinger) ENDIF(WITH_schroedinger) IF(WITH_wave-equation) add_subdirectory(wave-equation) -ENDIF(WITH_wave-equation) -IF(WITH_miscellaneous) - add_subdirectory(miscellaneous) -ENDIF(WITH_miscellaneous) \ No newline at end of file +ENDIF(WITH_wave-equation) \ No newline at end of file diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index e7c9db3..f2a7cb8 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -165,6 +165,11 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + // Error calculation. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionCumulative stoppingCriterion(0.3); + Adapt >* adaptivity = new Adapt >(space); double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; diff --git a/2d-advanced/elasticity-linear/CMakeLists.txt b/2d-advanced/elasticity-linear/CMakeLists.txt index 4bbf1e7..7f833fd 100644 --- a/2d-advanced/elasticity-linear/CMakeLists.txt +++ b/2d-advanced/elasticity-linear/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(bracket) add_subdirectory(crack) \ No newline at end of file diff --git a/2d-advanced/elasticity-linear/crack/definitions.cpp b/2d-advanced/elasticity-linear/crack/definitions.cpp index 693dea2..4051e6c 100644 --- a/2d-advanced/elasticity-linear/crack/definitions.cpp +++ b/2d-advanced/elasticity-linear/crack/definitions.cpp @@ -6,10 +6,11 @@ CustomWeakFormLinearElasticity::CustomWeakFormLinearElasticity(double E, double double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); + // SINGLE-COMPONENT FORMS. USEFUL FOR MULTIMESH, DO NOT REMOVE. // Jacobian. - add_matrix_form(new DefaultJacobianElasticity_0_0(0, 0, HERMES_ANY, lambda, mu)); - add_matrix_form(new DefaultJacobianElasticity_0_1(0, 1, HERMES_ANY, lambda, mu)); - add_matrix_form(new DefaultJacobianElasticity_1_1(1, 1, HERMES_ANY, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_0_0(0, 0, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_0_1(0, 1, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_1_1(1, 1, lambda, mu)); // Residual - first equation. add_vector_form(new DefaultResidualElasticity_0_0(0, HERMES_ANY, lambda, mu)); diff --git a/2d-advanced/elasticity-linear/crack/definitions.h b/2d-advanced/elasticity-linear/crack/definitions.h index 8769418..bb4cf5e 100644 --- a/2d-advanced/elasticity-linear/crack/definitions.h +++ b/2d-advanced/elasticity-linear/crack/definitions.h @@ -5,7 +5,8 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::WeakFormsH1; using namespace Hermes::Hermes2D::WeakFormsElasticity; using namespace Hermes::Hermes2D::Views; -using namespace RefinementSelectors; + +//#define USE_MULTICOMPONENT_FORMS class CustomWeakFormLinearElasticity : public WeakForm { diff --git a/2d-advanced/elasticity-linear/crack/domain.xml b/2d-advanced/elasticity-linear/crack/domain.xml new file mode 100644 index 0000000..5124403 --- /dev/null +++ b/2d-advanced/elasticity-linear/crack/domain.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index f4caed2..5f4668c 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -2,284 +2,123 @@ #define HERMES_REPORT_FILE "application.log" #include "definitions.h" -// This example uses adaptive multimesh hp-FEM to solve a simple problem -// of linear elasticity. Note that since both displacement components -// have similar qualitative behavior, the advantage of the multimesh -// discretization is less striking than for example in the tutorial -// example P04-linear-adapt/02-system-adapt. +// This example explains how to create multiple spaces over a mesh and use them +// to solve a simple problem of linear elasticity. Note how Tuples are used, +// they replace variable-length argument lists. At the end, VonMises filter is +// used to visualize the stress. // -// PDE: Lame equations of linear elasticity. No external forces, the -// object is loaded with its own weight. +// PDE: Lame equations of linear elasticity. // -// BC: u_1 = u_2 = 0 on Gamma_1 (left edge) -// du_1/dn = du_2/dn = 0 elsewhere, including two horizontal -// cracks inside the domain. The width of the cracks -// is currently zero, it can be set in the mesh file -// via the parameter 'w'. +// BC: du_1/dn = f0 on Gamma_top (top edge), +// du_2/dn = f1 on Gamma_top (top edge), +// u_1 = 0 and u_2 = 0 on Gamma_bottom (bottom edge), +// du_1/dn = 0 on Gamma_rest (rest of boundary), +// du_2/dn = 0 on Gamma_rest (rest of boundary). // -// The following parameters can be changed: -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; -// Initial polynomial degree of mesh elements (u-displacement). -const int P_INIT_U1 = 2; -// Initial polynomial degree of mesh elements (v-displacement). -const int P_INIT_U2 = 2; -// true = use multi-mesh, false = use single-mesh-> -// Note: in the single mesh option, the meshes are -// forced to be geometrically the same but the -// polynomial degrees can still vary. -const bool MULTI = true; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD_MULTI = 0.35; -const double THRESHOLD_SINGLE = 0.7; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity. -const double ERR_STOP = 0.1; -// Adaptivity process stops when the number of degrees of freedom grows. -const int NDOF_STOP = 60000; -// Stopping criterion for the Newton's method. -const double NEWTON_TOL = 1e-6; -// Maximum allowed number of Newton iterations. -const int NEWTON_MAX_ITER = 100; +// Read original or XML mesh file. +const bool USE_XML_FORMAT = true; +// Initial polynomial degree of all elements. +const int P_INIT = 6; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, // SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Problem parameters. -// Young modulus for steel: 200 GPa. -const double E = 200e9; +// Young modulus (steel). +const double E = 200e9; // Poisson ratio. -const double nu = 0.3; +const double nu = 0.3; +// Density. +const double rho = 8000.0; // Gravitational acceleration. -const double g1 = -9.81; -// Material density in kg / m^3. -const double rho = 8000; -// Top surface force in x-direction. -const double f0 = 0; -// Top surface force in y-direction. -const double f1 = 0; +const double g1 = -9.81; +// Surface force in x-direction. +const double f0 = 0; +// Surface force in y-direction. +const double f1 = 8e4; int main(int argc, char* argv[]) { - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - cpu_time.tick(); - - // Load the mesh-> - MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("domain.mesh", u1_mesh); + #pragma region 1. Load mesh and initialize space. + // Load the mesh. + MeshSharedPtr mesh(new Mesh), mesh1(new Mesh); + if (USE_XML_FORMAT == true) + { + MeshReaderH2DXML mloader; + Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); + mloader.load("domain.xml", mesh); + } + else + { + MeshReaderH2D mloader; + Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); + mloader.load("domain.mesh", mesh); + } - // Perform initial uniform mesh refinement. - for (int i=0; i < INIT_REF_NUM; i++) u1_mesh->refine_all_elements(); + // Perform uniform mesh refinement. + mesh->refine_all_elements(); + mesh->refine_all_elements(); - // Create initial mesh for the vertical displacement component. - // This also initializes the multimesh hp-FEM. - u2_mesh->copy(u1_mesh); + // Initialize boundary conditions. + DefaultEssentialBCConst zero_disp("Bottom", 0.0); + EssentialBCs bcs(&zero_disp); - // Initialize boundary conditions. - DefaultEssentialBCConst zero_disp("bdy left", 0.0); - EssentialBCs bcs(&zero_disp); + // Create x- and y- displacement space using the default H1 shapeset. + SpaceSharedPtr u1_space(new H1Space(mesh, &bcs, P_INIT)); + SpaceSharedPtr u2_space(new H1Space(mesh, &bcs, P_INIT)); + int ndof = Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)); + Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); + #pragma endregion - // Create x- and y- displacement space using the default H1 shapeset. - SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT_U1)); - SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT_U2)); - Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); + // Show mesh. + OrderView oview("Mesh", new WinGeom(0, 0, 1210, 680)); + oview.show(u1_space); // Initialize the weak formulation. - // NOTE; These weak forms are identical to those in example P01-linear/08-system. - CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy_top", f0, f1); + CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "Top", f0, f1); // Initialize the FE problem. DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); - // Initialize coarse and reference mesh solutions. - MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); - MeshFunctionSharedPtr u1_sln_ref(new Solution), u2_sln_ref(new Solution); - - // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST); - - // Initialize views. - ScalarView s_view_0("Solution (x-displacement)", new WinGeom(0, 0, 700, 350)); - s_view_0.show_mesh(false); - ScalarView s_view_1("Solution (y-displacement)", new WinGeom(760, 0, 700, 350)); - s_view_1.show_mesh(false); - OrderView o_view_0("Mesh (x-displacement)", new WinGeom(410, 0, 700, 350)); - OrderView o_view_1("Mesh (y-displacement)", new WinGeom(1170, 0, 700, 350)); - ScalarView mises_view("Von Mises stress [Pa]", new WinGeom(0, 405, 700, 350)); - - // DOF and CPU convergence graphs. - SimpleGraph graph_dof_est, graph_cpu_est; - - // Adaptivity loop: - int as = 1; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - // Construct globally refined reference mesh and setup reference space-> - Mesh::ReferenceMeshCreator refMeshCreator1(u1_mesh); - MeshSharedPtr ref_u1_mesh = refMeshCreator1.create_ref_mesh(); + // Initialize Newton solver. + NewtonSolver newton(&dp); + newton.set_tolerance(1e-5); - Space::ReferenceSpaceCreator refSpaceCreator1(u1_space, ref_u1_mesh); - SpaceSharedPtr ref_u1_space = refSpaceCreator1.create_ref_space(); - - Mesh::ReferenceMeshCreator refMeshCreator2(u2_mesh); - MeshSharedPtr ref_u2_mesh = refMeshCreator2.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); - SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); - - Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); - - int ndof_ref = Space::get_num_dofs(ref_spaces); - - // Initialize the FE problem. - DiscreteProblem dp(&wf, ref_spaces); - - // Initialize Newton solver. - NewtonSolver newton(&dp); - newton.set_verbose_output(true); - - // Time measurement. - cpu_time.tick(); - - // Perform Newton's iteration. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + #pragma region 2. Perform Newton's loop and get the solution. try { - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); newton.solve(); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - } - - // Time measurement. - cpu_time.tick(); + catch(std::exception& e) { std::cout << e.what(); } - // Translate the resulting coefficient vector into the Solution sln-> - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, - Hermes::vector >(u1_sln_ref, u2_sln_ref)); - - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), - Hermes::vector >(u1_sln_ref, u2_sln_ref), - Hermes::vector >(u1_sln, u2_sln)); - - // View the coarse mesh solution and polynomial orders. - s_view_0.show(u1_sln); - o_view_0.show(u1_space); - s_view_1.show(u2_sln); - o_view_1.show(u2_space); - // For von Mises stress Filter. - double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); - double mu = E / (2*(1 + nu)); + // Translate the resulting coefficient vector into the Solution sln. + MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); + Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector >(u1_space, u2_space), + Hermes::vector >(u1_sln, u2_sln)); +#pragma endregion + + #pragma region 3. Filters for visualization + visualization setup. + // Visualize the solution. + ScalarView viewx("X-displacement", new WinGeom(0, 0, 600, 330)); + ScalarView viewy("Y-displacement", new WinGeom(0, 350, 600, 330)); + ScalarView view("Von Mises stress [Pa]", new WinGeom(610, 0, 600, 680)); + // First Lame constant. + double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); + // Second Lame constant. + double mu = E / (2*(1 + nu)); MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln, u2_sln), lambda, mu)); - mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 1e3); - - // Skip visualization time. - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - // Initialize adaptivity. - Adapt* adaptivity = new Adapt(Hermes::vector >(u1_space, u2_space)); - - /* - // Register custom forms for error calculation. - adaptivity->set_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); - adaptivity->set_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); - adaptivity->set_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); - adaptivity->set_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); - */ - - // Calculate error estimate for each solution component and the total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u1_sln, u2_sln), - Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; - - // Time measurement. - cpu_time.tick(); - - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d, err_est_rel[0]: %g%%", - u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d, err_est_rel[1]: %g%%", - u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", - Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), - Space::get_num_dofs(ref_spaces), err_est_rel_total); - - // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), - err_est_rel_total); - graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); - graph_cpu_est.save("conv_cpu_est.dat"); - - // If err_est too large, adapt the mesh-> - if (err_est_rel_total < ERR_STOP) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); - } - if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; - - // Clean up. - delete adaptivity; - - // Increase counter. - as++; - } - while (done == false); - - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - - // Show the reference solution - the final result. - s_view_0.set_title("Fine mesh solution (x-displacement)"); - s_view_0.show(u1_sln_ref); - s_view_1.set_title("Fine mesh solution (y-displacement)"); - s_view_1.show(u2_sln_ref); - // For von Mises stress Filter. - double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); - double mu = E / (2*(1 + nu)); - MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu)); - mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 1e3); - - // Wait for all views to be closed. + + viewx.show(u1_sln); + viewx.show_mesh(false); + viewy.show(u2_sln); + viewy.show_mesh(false); + view.show(stress, HERMES_EPS_LOW, H2D_FN_VAL_0, u1_sln, u2_sln, 1.5e5); +#pragma endregion + + // Wait for the view to be closed. View::wait(); + return 0; -} \ No newline at end of file +} + diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index e15d70e..7f84173 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -1,17 +1,2 @@ -add_subdirectory(forward-step) -add_subdirectory(forward-step-adapt) -add_subdirectory(reflected-shock) -add_subdirectory(reflected-shock-adapt) add_subdirectory(gamm-channel) -add_subdirectory(gamm-channel-adapt) -add_subdirectory(heating-induced-vortex) -add_subdirectory(heating-induced-vortex-adapt) -#add_subdirectory(joukowski-profile) -#add_subdirectory(joukowski-profile-adapt) - -# add_subdirectory(euler-coupled) -# add_subdirectory(euler-coupled-adapt) - - -add_subdirectory(heating-flow-coupling) -add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file +add_subdirectory(gamm-channel-adapt) \ No newline at end of file diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 5fd68b6..f7d1486 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -23,8 +23,6 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // Visualization. // Set to "true" to enable Hermes OpenGL visualization. const bool HERMES_VISUALIZATION = true; -// Set to "true" to enable VTK output. -const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; // Shock capturing. @@ -42,11 +40,11 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 0; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 0; // CFL value. -double CFL_NUMBER = 0.5; +double CFL_NUMBER = 0.9; // Initial time step. double time_step_n = 1E-6; @@ -57,44 +55,19 @@ const int UNREF_FREQ = 10; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since // last unrefinement. -int REFINEMENT_COUNT = 0; +int REFINEMENT_COUNT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies (see below). -const double THRESHOLD = 0.3; - -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; +const double THRESHOLD = 0.6; // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_HP_ANISO; - -// Maximum polynomial degree used. -1 for unlimited. -const int MAX_P_ORDER = -1; - -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; - -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; +CandList CAND_LIST = H2D_H_ISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.5; +const double ERR_STOP = 0.005; // Adaptivity process stops when the number of degrees of freedom grows over // this limit. This is mainly to prevent h-adaptivity to go on forever. @@ -130,266 +103,230 @@ const std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - // Load the mesh-> - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); - int ndof = Space::get_num_dofs(spaces); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - - // Initialize solutions, set initial conditions. - MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - - MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - - MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA, RHO_EXT, P_EXT)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); - ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); - ScalarView s2("prev_rho_v_x", new WinGeom(700, 0, 600, 300)); - ScalarView s3("prev_rho_v_y", new WinGeom(0, 400, 600, 300)); - ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); - - // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); - selector.set_error_weights(1.0, 1.0, 1.0); + #pragma region 1. Load mesh and initialize spaces. + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load("GAMM-channel.mesh", mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + #pragma endregion + + #pragma region 2. Initialize solutions, set initial conditions. + MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); + + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); + + MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + Hermes::vector > rslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e); + #pragma endregion + + #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(rslns, KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(rslns, KAPPA)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + pressure_view.show_contours(.1); + pressure_view.show_mesh(false); + ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); + Mach_number_view.show_contours(.02); + Mach_number_view.show_mesh(false); + VectorView velocity_view("Velocity", new WinGeom(0, 330, 600, 300)); + #pragma endregion + + #pragma region 4. Adaptivity setup. + // Initialize refinement selector. + L2ProjBasedSelector selector(CAND_LIST); + selector.set_error_weights(1.0, 1.0, 1.0); + + // Error calculation. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + Adapt adaptivity(spaces, &errorCalculator, &stoppingCriterion); + #pragma endregion // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Time stepping loop. - int iteration = 1; - double t = 0.0; - for(; t < 3.5; t += time_step_n) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Periodic global derefinements. - if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) + #pragma region 5. Initialize weak formulation and solver. + Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + outlet_markers.push_back(BDY_OUTLET); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); + + // Solver. + LinearSolver solver(&wf, spaces); + #pragma endregion + + #pragma region 6. Time stepping loop. + int iteration = 1; + for(double t = 0.0; t < 3.5; t += time_step_n) { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - REFINEMENT_COUNT = 0; + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - space_rho->unrefine_all_mesh_elements(true); + #pragma region 6.1. Periodic global derefinements. + if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) + { + Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); + REFINEMENT_COUNT = 0; - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); - Space::assign_dofs(spaces); - } + space_rho->unrefine_all_mesh_elements(true); - // Adaptivity loop: - int as = 1; - int ndofs_prev = 0; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - // Construct globally refined reference mesh and setup reference space-> - int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; - - Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); - MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); - SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - - SpaceSharedPtr refspace_stabilization(new L2Space(ref_space_rho->get_mesh(), 0)); - - if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces) == ndofs_prev) - selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); - else - selector.set_error_weights(1.0, 1.0, 1.0); - - ndofs_prev = Space::get_num_dofs(ref_spaces); - - // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); - - // Initialize weak formulation. - Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); - Hermes::vector inlet_markers; - inlet_markers.push_back(BDY_INLET); - Hermes::vector outlet_markers; - outlet_markers.push_back(BDY_OUTLET); - - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - - EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); - - - // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - Space::assign_dofs(ref_spaces); - DiscreteProblem dp(&wf, ref_spaces); - dp.set_linear(); - DiscreteProblem dp_stabilization(&wf_stabilization, refspace_stabilization); - bool* discreteIndicator = NULL; - - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); - Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - - // Set the current time step. - wf.set_current_time_step(time_step_n); - - FluxLimiter* flux_limiter; - dp.assemble(matrix, rhs); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) - { - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - } - else - { - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), ref_spaces); - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter->limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter->get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); + Space::assign_dofs(spaces); } - } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), - Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - - CFL.calculate(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step_n); - - // Report results. - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - - // If err_est too large, adapt the mesh-> - if (err_est_rel_total < ERR_STOP) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - - REFINEMENT_COUNT++; - if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)) >= NDOF_STOP) - done = true; - else - as++; - } - - // Visualization and saving on disk. - if(done && (iteration - 1) % EVERY_NTH_STEP == 0 && iteration > 1) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - entropy->reinit(); - pressure_view.show(pressure, 1); - entropy_production_view.show(entropy, 1); - Mach_number_view.show(Mach_number, 1); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) + #pragma endregion + + #pragma region 7. Adaptivity loop. + int as = 1; int ndofs_prev = 0; bool done = false; + do { - pressure->reinit(); - Mach_number->reinit(); - entropy->reinit(); - Linearizer lin; - char filename[40]; - sprintf(filename, "Pressure-%i.vtk", iteration - 1); - lin.save_solution_vtk(pressure, filename, "Pressure", false); - sprintf(filename, "Mach number-%i.vtk", iteration - 1); - lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); - sprintf(filename, "Entropy-%i.vtk", iteration - 1); - lin.save_solution_vtk(entropy, filename, "Entropy", false); + // Info. + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + // Set the current time step. + wf.set_current_time_step(time_step_n); + + #pragma region 7.1. Construct globally refined reference mesh and setup reference space. + int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; + + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + solver.set_spaces(ref_spaces); + + if(ndofs_prev != 0) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) + selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); + else + selector.set_error_weights(1.0, 1.0, 1.0); + + ndofs_prev = Space::get_num_dofs(ref_spaces); + + // Project the previous time level solution onto the new fine mesh + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); + OGProjection::project_global(ref_spaces, prev_slns, prev_slns); + #pragma endregion + + // Solve the problem. + solver.solve(); + + #pragma region *. Get the solution with optional shock capturing. + if(!SHOCK_CAPTURING) + Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, rslns); + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), ref_spaces); + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(spaces); + + flux_limiter->limit_according_to_detector(spaces); + + flux_limiter->get_limited_solutions(rslns); + } + #pragma endregion + + // Calculate time step according to CFL condition. + CFL.calculate(rslns, (ref_spaces)[0]->get_mesh(), time_step_n); + + #pragma region 7.2. Project to coarse mesh -> error estimation -> space adaptivity + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection::project_global(spaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + + // Calculate element errors and total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + errorCalculator.calculate_errors(slns, rslns); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + + // Report results. + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); + + // If err_est too large, adapt the mesh. + if (err_est_rel_total < ERR_STOP) + done = true; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector)); + + REFINEMENT_COUNT++; + if (Space::get_num_dofs(spaces) >= NDOF_STOP) + done = true; + else + as++; + } + #pragma endregion + + #pragma region 7.3. Visualization and saving on disk. + if(done && (iteration - 1) % EVERY_NTH_STEP == 0 && iteration > 2) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure, 1); + Mach_number_view.show(Mach_number, 1); + velocity_view.show(rsln_rho_v_x, rsln_rho_v_y); + } + } + #pragma endregion } - } - - // Clean up. - delete solver; - delete matrix; - delete rhs; - delete rhs_stabilization; - delete adaptivity; + while (done == false); + #pragma endregion + + // Copy the solutions into the previous time level ones. + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); } - while (done == false); - - // Copy the solutions into the previous time level ones. - prev_rho->copy(rsln_rho); - prev_rho_v_x->copy(rsln_rho_v_x); - prev_rho_v_y->copy(rsln_rho_v_y); - prev_e->copy(rsln_e); - } + #pragma endregion pressure_view.close(); - entropy_production_view.close(); Mach_number_view.close(); return 0; diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index d19f319..a03bc6d 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -7,18 +7,16 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; // This example solves the compressible Euler equations using a basic -// piecewise-constant finite volume method, or Discontinuous Galerkin -// method of higher order with no adaptivity. +// Discontinuous Galerkin method of higher order with no adaptivity. // // Equations: Compressible Euler equations, perfect gas state equation. // // Domain: GAMM channel, see mesh file GAMM-channel.mesh // -// BC: Solid walls, inlet, no outlet. +// BC: Solid walls, inlet, outlet. // // IC: Constant state identical to inlet. // -// The following parameters can be changed: // Visualization. // Set to "true" to enable Hermes OpenGL visualization. @@ -46,9 +44,9 @@ const double NU_2 = 0.1; // Initial polynomial degree. const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 3; +const int INIT_REF_NUM = 4; // CFL value. -double CFL_NUMBER = 0.75; +double CFL_NUMBER = 0.9; // Initial time step. double time_step = 1E-6; @@ -78,144 +76,136 @@ std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - // Load the mesh-> - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - - // Initialize solutions, set initial conditions. - MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); - ScalarView s2("prev_rho_v_x", new WinGeom(700, 0, 600, 300)); - ScalarView s3("prev_rho_v_y", new WinGeom(0, 400, 600, 300)); - ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); - - // Set up the solver, matrix, and rhs according to the solver selection. - Vector* rhs_stabilization = create_vector(); + #pragma region 1. Load mesh and initialize spaces. + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load("GAMM-channel.mesh", mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + #pragma endregion + + #pragma region 2. Initialize solutions, set initial conditions. + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); + #pragma endregion + + #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. + MeshFunctionSharedPtr Mach_number(new MachNumberFilter (prev_slns, KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(prev_slns, KAPPA)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + pressure_view.show_contours(.1); + pressure_view.show_mesh(false); + ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); + Mach_number_view.show_contours(.02); + Mach_number_view.show_mesh(false); + VectorView velocity_view("Velocity", new WinGeom(0, 330, 600, 300)); + #pragma endregion // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Initialize weak formulation. - Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); - Hermes::vector inlet_markers; - inlet_markers.push_back(BDY_INLET); - Hermes::vector outlet_markers; - outlet_markers.push_back(BDY_OUTLET); + #pragma region 4. Initialize weak formulation -> EF problem -> linear solver. + Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); + // Initialize the FE problem. + Space::assign_dofs(spaces); - // Initialize the FE problem. - Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); - Space::assign_dofs(spaces); - - LinearSolver solver(&wf, spaces); + LinearSolver solver(&wf, spaces); + #pragma endregion - DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); - - // Time stepping loop. - int iteration = 0; - double t = 0.0; - for(; t < 10.0; t += time_step) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Set the current time step. - wf.set_current_time_step(time_step); - - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - try + #pragma region 5.Time stepping loop. + int iteration = 0; + for(double t = 0.0; t < 10.0; t += time_step) { - solver.solve(); - if(!SHOCK_CAPTURING) + // Info. + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + + // Set the current time step. + wf.set_current_time_step(time_step); + + try { - Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } + // Solve. + solver.solve(); + + #pragma region *. Get the solution with optional shock capturing. + if(!SHOCK_CAPTURING) + Solution::vector_to_solutions(solver.get_sln_vector(), spaces, prev_slns); else { FluxLimiter* flux_limiter; if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), spaces, true); else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), spaces); if(SHOCK_CAPTURING_TYPE == KUZMIN) flux_limiter->limit_second_orders_according_to_detector(); flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); + flux_limiter->get_limited_solutions(prev_slns); } + #pragma endregion } - catch(std::exception& e) - { - std::cout << e.what(); - } + catch(std::exception& e) { std::cout << e.what(); } - CFL.calculate(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); + // Calculate time step according to CFL condition. + CFL.calculate(prev_slns, mesh, time_step); - // Visualization. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - pressure_view.show(pressure); - Mach_number_view.show(Mach_number); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Mach_number->reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); - Linearizer lin_mach; - sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); - } + #pragma region 5.1. Visualization + if((iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure); + Mach_number_view.show(Mach_number); + velocity_view.show(prev_rho_v_x, prev_rho_v_y); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure->reinit(); + Mach_number->reinit(); + Linearizer lin_pressure; + char filename[40]; + sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); + lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); + Linearizer lin_mach; + sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); + lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); + } + } + #pragma endregion } - } - - pressure_view.close(); - Mach_number_view.close(); + #pragma endregion + // Done. return 0; } diff --git a/2d-advanced/helmholtz/waveguide/definitions.cpp b/2d-advanced/helmholtz/waveguide/definitions.cpp index fa06c6c..f004f28 100644 --- a/2d-advanced/helmholtz/waveguide/definitions.cpp +++ b/2d-advanced/helmholtz/waveguide/definitions.cpp @@ -24,14 +24,14 @@ WeakFormHelmholtz::WeakFormHelmholtz(double eps, double mu, double omega, double add_matrix_form(new MatrixFormHelmholtzEquation_real_imag(0, 1, mu, omega, sigma)); add_matrix_form(new MatrixFormHelmholtzEquation_imag_real(1, 0, mu, omega, sigma)); add_matrix_form(new MatrixFormHelmholtzEquation_imag_imag(1, 1, eps, mu, omega)); - add_matrix_form_surf(new MatrixFormSurfHelmholtz_real_imag(0, 1, "Bdy_impedance", beta)); - add_matrix_form_surf(new MatrixFormSurfHelmholtz_imag_real(1, 0, "Bdy_impedance", beta)); + add_matrix_form_surf(new MatrixFormSurfHelmholtz_real_imag(0, 1, "0", beta)); + add_matrix_form_surf(new MatrixFormSurfHelmholtz_imag_real(1, 0, "0", beta)); // Residual. add_vector_form(new VectorFormHelmholtzEquation_real(0, eps, omega, mu, sigma)); add_vector_form(new VectorFormHelmholtzEquation_imag(1, eps, omega, mu, sigma)); - add_vector_form_surf(new VectorFormSurfHelmholtz_real(0, "Bdy_impedance", beta)); - add_vector_form_surf(new VectorFormSurfHelmholtz_imag(1, "Bdy_impedance", beta)); + add_vector_form_surf(new VectorFormSurfHelmholtz_real(0, "0", beta)); + add_vector_form_surf(new VectorFormSurfHelmholtz_imag(1, "0", beta)); } /* Jacobian forms */ diff --git a/2d-advanced/helmholtz/waveguide/definitions.h b/2d-advanced/helmholtz/waveguide/definitions.h index 2a87373..9a76f92 100644 --- a/2d-advanced/helmholtz/waveguide/definitions.h +++ b/2d-advanced/helmholtz/waveguide/definitions.h @@ -29,6 +29,24 @@ class WeakFormHelmholtz : public WeakForm public: WeakFormHelmholtz(double eps, double mu, double omega, double sigma, double beta, double E0, double h); + void set_parameters(double eps, double mu, double omega, double sigma, double beta, double E0, double h) + { + this->delete_all(); + + // Jacobian. + add_matrix_form(new MatrixFormHelmholtzEquation_real_real(0, 0, eps, omega, mu)); + add_matrix_form(new MatrixFormHelmholtzEquation_real_imag(0, 1, mu, omega, sigma)); + add_matrix_form(new MatrixFormHelmholtzEquation_imag_real(1, 0, mu, omega, sigma)); + add_matrix_form(new MatrixFormHelmholtzEquation_imag_imag(1, 1, eps, mu, omega)); + add_matrix_form_surf(new MatrixFormSurfHelmholtz_real_imag(0, 1, "0", beta)); + add_matrix_form_surf(new MatrixFormSurfHelmholtz_imag_real(1, 0, "0", beta)); + + // Residual. + add_vector_form(new VectorFormHelmholtzEquation_real(0, eps, omega, mu, sigma)); + add_vector_form(new VectorFormHelmholtzEquation_imag(1, eps, omega, mu, sigma)); + add_vector_form_surf(new VectorFormSurfHelmholtz_real(0, "0", beta)); + add_vector_form_surf(new VectorFormSurfHelmholtz_imag(1, "0", beta)); + } private: class MatrixFormHelmholtzEquation_real_real : public MatrixFormVol { @@ -47,7 +65,7 @@ class WeakFormHelmholtz : public WeakForm Func *v, Geom *e, Func* *ext) const; MatrixFormVol* clone() const; - private: + // Members. double eps; double omega; @@ -56,7 +74,7 @@ class WeakFormHelmholtz : public WeakForm class MatrixFormHelmholtzEquation_real_imag : public MatrixFormVol { - private: + // Members. double mu; double omega; @@ -80,7 +98,7 @@ class WeakFormHelmholtz : public WeakForm class MatrixFormHelmholtzEquation_imag_real : public MatrixFormVol { - private: + // Members. double mu; double omega; @@ -185,7 +203,7 @@ class WeakFormHelmholtz : public WeakForm Func *v, Geom *e, Func* *ext) const; VectorFormVol* clone() const; - private: + // Members. double eps; double omega; @@ -210,7 +228,7 @@ class WeakFormHelmholtz : public WeakForm Func *v, Geom *e, Func* *ext) const; VectorFormVol* clone() const; - private: + // Members. double eps; double omega; diff --git a/2d-advanced/helmholtz/waveguide/domain.mesh b/2d-advanced/helmholtz/waveguide/domain.mesh index d430e02..fd474b1 100644 --- a/2d-advanced/helmholtz/waveguide/domain.mesh +++ b/2d-advanced/helmholtz/waveguide/domain.mesh @@ -1,7 +1,9 @@ vertices = [ [ 0, -0.05 ], + [ 0.25, -0.05 ], [ 0.5, -0.05 ], [ 0.5, 0.05 ], + [ 0.25, 0.05 ], [ 0, 0.05 ] ] diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index c6c5206..d04ae31 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -26,7 +26,7 @@ // The following parameters can be changed: // Initial polynomial degree of all elements. -const int P_INIT = 6; +const int P_INIT = 4; // Number of initial mesh refinements. const int INIT_REF_NUM = 3; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, @@ -49,9 +49,9 @@ const double mur = 1.0; const double mu0 = 4*M_PI*1e-7; const double mu = mur * mu0; // Frequency MHz. -const double frequency = 3e9; +double frequency = 16e9; // Angular velocity. -const double omega = 2*M_PI * frequency; +double omega = 2*M_PI * frequency; // Conductivity Ohm/m. const double sigma = 0; // Propagation constant. @@ -59,23 +59,21 @@ const double beta = 54; // Input electric intensity. const double E0 = 100; // Height of waveguide. -const double h = 0.1; +const double h = 1.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("domain.mesh", mesh); + MeshReaderH2DXML mloader; + mloader.load("initial.xml", mesh); - // Perform uniform mesh refinement. - // 2 is for vertical split. - for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(2); + mesh->refine_all_elements(); // Initialize boundary conditions - DefaultEssentialBCConst bc1("Bdy_perfect", 0.0); - EssentialBCNonConst bc2("Bdy_left"); - DefaultEssentialBCConst bc3("Bdy_left", 0.0); + DefaultEssentialBCConst bc1(Hermes::vector("2", "3", "4", "5", "6", "7", "8", "9", "10", "11"), 0.0); + EssentialBCNonConst bc2("1"); + DefaultEssentialBCConst bc3("1", 0.0); EssentialBCs bcs(Hermes::vector *>(&bc1, &bc2)); EssentialBCs bcs_im(Hermes::vector *>(&bc1, &bc3)); @@ -83,10 +81,10 @@ int main(int argc, char* argv[]) SpaceSharedPtr e_r_space(new H1Space (mesh, &bcs, P_INIT)); SpaceSharedPtr e_i_space(new H1Space(mesh, &bcs_im, P_INIT)); int ndof = Space::get_num_dofs(e_r_space); - Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); - + // Initialize the weak formulation. WeakFormHelmholtz wf(eps, mu, omega, sigma, beta, E0, h); + wf.set_verbose_output(false); // Initialize the FE problem. DiscreteProblem dp(&wf, Hermes::vector >(e_r_space, e_i_space)); @@ -98,30 +96,60 @@ int main(int argc, char* argv[]) ndof = Space::get_num_dofs(Hermes::vector >(e_r_space, e_i_space)); Hermes::Hermes2D::NewtonSolver newton(&dp); - try + newton.set_tolerance(NEWTON_TOL); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + + ScalarView viewEr("Er [V/m]", new WinGeom(600, 0, 700, 200)); + viewEr.show_mesh(false); + viewEr.set_3d_mode(true); + ScalarView viewEi("Ei [V/m]", new WinGeom(600, 220, 700, 200)); + + ScalarView viewMagnitude("Magnitude of E [V/m]", new WinGeom(600, 440, 700, 200)); + viewMagnitude.show_mesh(false); + viewMagnitude.show_contours(50., 0.); + + while(true) { - newton.set_tolerance(NEWTON_TOL); - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.solve(); + std::cout << "Frequency: " << frequency << " Hz" << std::endl; + try + { + newton.solve(); + } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into Solutions. + Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector >(e_r_space, e_i_space), + Hermes::vector >(e_r_sln, e_i_sln)); + + // Visualize the solution. + viewEr.show(e_r_sln, 0.1); + // viewEr.save_screenshot("real_part.bmp"); + + viewEi.show(e_i_sln, 0.1); + // viewEi.save_screenshot("imaginary_part.bmp"); + + MeshFunctionSharedPtr magnitude(new MagFilter(Hermes::vector >(e_r_sln, e_i_sln))); + viewMagnitude.show(magnitude, HERMES_EPS_LOW); + + char* change_state = new char[1000]; + std::cout << "Done?"; + std::cin.getline(change_state, 1); + if(!strcmp(change_state, "y")) + break; + std::cout << std::endl; + std::cout << "Frequency change [1e9 Hz]: "; + double frequency_change; + std::cin >> frequency_change; + + frequency += 1e9 * frequency_change; + omega = 2*M_PI * frequency; + wf.set_parameters(eps, mu, omega, sigma, beta, E0, h); + newton.set_weak_formulation(&wf); } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - }; - - // Translate the resulting coefficient vector into Solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector >(e_r_space, e_i_space), - Hermes::vector >(e_r_sln, e_i_sln)); - - // Visualize the solution. - ScalarView viewEr("Er [V/m]", new WinGeom(0, 0, 800, 400)); - viewEr.show(e_r_sln); - // viewEr.save_screenshot("real_part.bmp"); - - ScalarView viewEi("Ei [V/m]", new WinGeom(0, 450, 800, 400)); - viewEi.show(e_i_sln); - // viewEi.save_screenshot("imaginary_part.bmp"); // Wait for the view to be closed. View::wait(); diff --git a/2d-advanced/maxwell/CMakeLists.txt b/2d-advanced/maxwell/CMakeLists.txt index dab3298..95f4a60 100644 --- a/2d-advanced/maxwell/CMakeLists.txt +++ b/2d-advanced/maxwell/CMakeLists.txt @@ -1,6 +1 @@ -add_subdirectory(microwave-oven) -add_subdirectory(resonator-time-domain-I) -add_subdirectory(resonator-time-domain-II-ie) -add_subdirectory(resonator-time-domain-II-rk) -add_subdirectory(magnetostatics) -add_subdirectory(maxwell-debye-rk) \ No newline at end of file +add_subdirectory(magnetostatics) \ No newline at end of file diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 39f837a..570534e 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -15,7 +15,7 @@ // The following parameters can be changed: // Initial polynomial degree. -const int P_INIT = 3; +const int P_INIT = 3; // Stopping criterion for the Newton's method. const double NEWTON_TOL = 1e-10; // Maximum allowed number of Newton iterations. @@ -23,7 +23,7 @@ const int NEWTON_MAX_ITER = 1000; // Number between 0 and 1 to damp Newton's iterations. const double NEWTON_DAMPING = 1.0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; +const int INIT_REF_NUM = 1; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, // SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. MatrixSolverType matrix_solver = SOLVER_UMFPACK; @@ -69,13 +69,14 @@ int main(int argc, char* argv[]) plot_derivative = true; mu_inv_iron.plot("spline_der.dat", interval_extension, plot_derivative); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("actuator.mesh", mesh); // Perform initial mesh refinements. - for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + for(int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); // Initialize boundary conditions. DefaultEssentialBCConst bc_essential(BDY_DIRICHLET, 0.0); @@ -108,8 +109,9 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. Hermes::Hermes2D::NewtonSolver newton(&dp); - bool verbose = true; - newton.set_verbose_output(verbose); + newton.set_manual_damping_coeff(0.1); + newton.set_sufficient_improvement_factor_jacobian(0.5); + newton.set_max_steps_with_reused_jacobian(5); try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); @@ -122,7 +124,7 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution sln-> + // Translate the resulting coefficient vector into the Solution sln. Solution::vector_to_solution(newton.get_sln_vector(), space, sln); // Cleanup. @@ -143,8 +145,8 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(flux_density, "sln->vtk", "Flux density", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); + lin.save_solution_vtk(flux_density, "sln.vtk", "Flux-density", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); OrderView o_view("Mesh", new WinGeom(720, 0, 350, 450)); o_view.show(space); diff --git a/2d-advanced/miscellaneous/CMakeLists.txt b/2d-advanced/miscellaneous/CMakeLists.txt deleted file mode 100644 index 4c64490..0000000 --- a/2d-advanced/miscellaneous/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(local-projection-test) diff --git a/2d-advanced/miscellaneous/local-projection-test/CMakeLists.txt b/2d-advanced/miscellaneous/local-projection-test/CMakeLists.txt deleted file mode 100644 index bbab248..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -project(local-projection-test) -add_executable(${PROJECT_NAME} definitions.cpp main.cpp) -set_common_target_properties(${PROJECT_NAME} "HERMES2D") - diff --git a/2d-advanced/miscellaneous/local-projection-test/definitions.cpp b/2d-advanced/miscellaneous/local-projection-test/definitions.cpp deleted file mode 100644 index caebb06..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/definitions.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "definitions.h" - -/* Weak forms */ - -CustomWeakFormPoisson::CustomWeakFormPoisson(std::string mat_al, Hermes1DFunction* lambda_al, - std::string mat_cu, Hermes1DFunction* lambda_cu, - Hermes2DFunction* src_term) : WeakForm(1) -{ - // Jacobian forms. - add_matrix_form(new DefaultJacobianDiffusion(0, 0, mat_al, lambda_al)); - add_matrix_form(new DefaultJacobianDiffusion(0, 0, mat_cu, lambda_cu)); - - // Residual forms. - add_vector_form(new DefaultResidualDiffusion(0, mat_al, lambda_al)); - add_vector_form(new DefaultResidualDiffusion(0, mat_cu, lambda_cu)); - add_vector_form(new DefaultVectorFormVol(0, HERMES_ANY, src_term)); -}; diff --git a/2d-advanced/miscellaneous/local-projection-test/definitions.h b/2d-advanced/miscellaneous/local-projection-test/definitions.h deleted file mode 100644 index 00de6f6..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/definitions.h +++ /dev/null @@ -1,16 +0,0 @@ -#include "hermes2d.h" - -using namespace Hermes; -using namespace Hermes::Hermes2D; -using namespace Hermes::Hermes2D::WeakFormsH1; -using namespace Hermes::Hermes2D::Views; - -/* Weak forms */ - -class CustomWeakFormPoisson : public WeakForm -{ -public: - CustomWeakFormPoisson(std::string mat_al, Hermes1DFunction* lambda_al, - std::string mat_cu, Hermes1DFunction* lambda_cu, - Hermes2DFunction* src_term); -}; diff --git a/2d-advanced/miscellaneous/local-projection-test/domain.mesh b/2d-advanced/miscellaneous/local-projection-test/domain.mesh deleted file mode 100644 index 2b2e274..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/domain.mesh +++ /dev/null @@ -1,44 +0,0 @@ -a = 1.0 -ma = -1.0 - -#b = sqrt(2)/2 -b = 0.70710678118654757 - -ab = 0.70710678118654757 - -vertices = [ - [ 0, ma], # vertex 0 - [ a, ma ], # vertex 1 - [ ma, 0 ], # vertex 2 - [ 0, 0 ], # vertex 3 - [ a, 0 ], # vertex 4 - [ ma, a ], # vertex 5 - [ 0, a ], # vertex 6 - [ ab, ab ] # vertex 7 -] - -elements = [ - [ 0, 1, 4, 3, "Copper" ], # quad 0 - [ 3, 4, 7, "Copper" ], # tri 1 - [ 3, 7, 6, "Aluminum" ], # tri 2 - [ 2, 3, 6, 5, "Aluminum" ] # quad 3 -] - -boundaries = [ - [ 0, 1, "Bottom" ], - [ 1, 4, "Outer" ], - [ 3, 0, "Inner" ], - [ 4, 7, "Outer" ], - [ 7, 6, "Outer" ], - [ 2, 3, "Inner" ], - [ 6, 5, "Outer" ], - [ 5, 2, "Left" ] -] - -curves = [ - [ 4, 7, 45 ], # circular arc with central angle of 45 degrees - [ 7, 6, 45 ] # circular arc with central angle of 45 degrees -] - - - diff --git a/2d-advanced/miscellaneous/local-projection-test/domain.xml b/2d-advanced/miscellaneous/local-projection-test/domain.xml deleted file mode 100644 index 2abc762..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/domain.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/2d-advanced/miscellaneous/local-projection-test/main.cpp b/2d-advanced/miscellaneous/local-projection-test/main.cpp deleted file mode 100644 index 781120c..0000000 --- a/2d-advanced/miscellaneous/local-projection-test/main.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#define HERMES_REPORT_ALL -#include "definitions.h" - -// This example shows how to solve a simple PDE that describes stationary -// heat transfer in an object consisting of two materials (aluminum and -// copper). The object is heated by constant volumetric heat sources -// (generated, for example, by a DC electric current). The temperature -// on the boundary is fixed. We will learn how to: -// -// - load the mesh, -// - perform initial refinements, -// - create a H1 space over the mesh, -// - define weak formulation, -// - select a matrix solver, -// - assemble and solve the matrix system, -// - output the solution and element orders in VTK format -// (to be visualized, e.g., using Paraview), -// - visualize the solution using Hermes' native OpenGL-based functionality. -// -// PDE: Poisson equation -div(LAMBDA grad u) - VOLUME_HEAT_SRC = 0. -// -// Boundary conditions: Dirichlet u(x, y) = FIXED_BDY_TEMP on the boundary. -// -// Geometry: L-Shape domain (see file domain.mesh). -// -// The following parameters can be changed: - -// Read the original or XML mesh file. -const bool USE_XML_FORMAT = false; -// Set to "false" to suppress Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = true; -// Set to "true" to enable VTK output. -const bool VTK_VISUALIZATION = false; -// Uniform polynomial degree of mesh elements. -const int P_INIT = 5; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; - -// Problem parameters. -// Thermal cond. of Al for temperatures around 20 deg Celsius. -const double LAMBDA_AL = 236.0; -// Thermal cond. of Cu for temperatures around 20 deg Celsius. -const double LAMBDA_CU = 386.0; -// Volume heat sources generated (for example) by electric current. -const double VOLUME_HEAT_SRC = 5e3; -// Fixed temperature on the boundary. -const double FIXED_BDY_TEMP = 20.0; - -int main(int argc, char* argv[]) -{ - // Load the mesh-> - MeshSharedPtr mesh(new Mesh); - if (USE_XML_FORMAT == true) - { - MeshReaderH2DXML mloader; - Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); - mloader.load("domain.xml", mesh); - } - else - { - MeshReaderH2D mloader; - Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); - mloader.load("domain.mesh", mesh); - } - - // Perform initial mesh refinements (optional). - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(); - - // Initialize the weak formulation. - CustomWeakFormPoisson wf("Aluminum", new Hermes1DFunction(LAMBDA_AL), - "Copper", new Hermes1DFunction(LAMBDA_CU), - new Hermes2DFunction(-VOLUME_HEAT_SRC)); - - // Initialize essential boundary conditions. - DefaultEssentialBCConst bc_essential( - Hermes::vector("Bottom", "Inner", "Outer", "Left"), FIXED_BDY_TEMP); - EssentialBCs bcs(&bc_essential); - - // Create an H1 space with default shapeset. - SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); - int ndof = space->get_num_dofs(); - Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); - - // Initialize the FE problem. - DiscreteProblem dp(&wf, space); - - // Initialize Newton solver. - NewtonSolver newton(&dp); - - // Perform Newton's iteration. - try - { - newton.solve(); - } - catch(Hermes::Exceptions::Exception e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Newton's iteration failed."); - } - - // Translate the resulting coefficient vector into a Solution. - MeshFunctionSharedPtr sln(new Solution()); - Solution::vector_to_solution(newton.get_sln_vector(), space, sln); - - MeshFunctionSharedPtr sln_proj(new Solution); - LocalProjection::project_local(space, sln, sln_proj, HERMES_H1_NORM); - ScalarView view1("Projection", new WinGeom(0, 0, 440, 350)); - view1.show(sln_proj); - View::wait(); - - // VTK output. - if (VTK_VISUALIZATION) - { - // Output solution in VTK format. - Linearizer lin; - bool mode_3D = true; - lin.save_solution_vtk(sln, "sln->vtk", "Temperature", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); - - // Output mesh and element orders in VTK format. - Orderizer ord; - ord.save_orders_vtk(space, "ord.vtk"); - Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", "ord.vtk"); - } - - // Visualize the solution. - if (HERMES_VISUALIZATION) - { - ScalarView view("Solution", new WinGeom(0, 0, 440, 350)); - // Hermes uses adaptive FEM to approximate higher-order FE solutions with linear - // triangles for OpenGL. The second parameter of View::show() sets the error - // tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default), - // HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows - // considerably with more accurate representation, so use it wisely. - view.show(sln); - View::wait(); - } - - return 0; -} - diff --git a/CMakeLists.txt b/CMakeLists.txt index 87766d7..b23f3ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,22 +30,21 @@ project(hermes_examples) # This can be changed in your CMake.vars file. SET(WITH_1d YES) SET(WITH_2d-advanced YES) - SET(WITH_acoustics YES) - SET(WITH_advection-diffusion-reaction YES) - SET(WITH_heat-transfer YES) + SET(WITH_acoustics NO) + SET(WITH_advection-diffusion-reaction NO) + SET(WITH_heat-transfer NO) SET(WITH_helmholtz YES) SET(WITH_euler YES) SET(WITH_elasticity-linear YES) SET(WITH_maxwell YES) - SET(WITH_navier-stokes YES) - SET(WITH_nernst-planck YES) - SET(WITH_neutronics YES) - SET(WITH_richards YES) - SET(WITH_schroedinger YES) - SET(WITH_wave-equation YES) - SET(WITH_miscellaneous YES) - SET(WITH_2d-benchmarks-general YES) - SET(WITH_2d-benchmarks-nist YES) + SET(WITH_navier-stokes NO) + SET(WITH_nernst-planck NO) + SET(WITH_neutronics NO) + SET(WITH_richards NO) + SET(WITH_schroedinger NO) + SET(WITH_wave-equation NO) + SET(WITH_2d-benchmarks-general NO) + SET(WITH_2d-benchmarks-nist NO) # Allow to override the default values in CMake.vars: include(CMake.vars OPTIONAL) From bf4ce9f884774f12315fd1896109863ba638ca13 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 23 May 2013 09:53:14 -0700 Subject: [PATCH 33/64] Finish for the conference. --- .../elasticity-linear/crack/definitions.cpp | 7 +- .../elasticity-linear/crack/definitions.h | 4 +- .../elasticity-linear/crack/domain.mesh | 10 +- 2d-advanced/elasticity-linear/crack/main.cpp | 338 +++++++++++++----- 2d-advanced/euler/euler_util.cpp | 4 +- 2d-advanced/helmholtz/waveguide/domain.xml | 45 +++ 2d-advanced/helmholtz/waveguide/initial.xml | 6 + 2d-advanced/helmholtz/waveguide/main.cpp | 1 - 2d-advanced/maxwell/CMakeLists.txt | 3 +- .../maxwell/magnetostatics/definitions.cpp | 2 +- .../maxwell/microwave-oven/definitions.cpp | 18 +- .../maxwell/microwave-oven/definitions.h | 31 +- 2d-advanced/maxwell/microwave-oven/main.cpp | 98 +++-- 13 files changed, 387 insertions(+), 180 deletions(-) create mode 100644 2d-advanced/helmholtz/waveguide/domain.xml create mode 100644 2d-advanced/helmholtz/waveguide/initial.xml diff --git a/2d-advanced/elasticity-linear/crack/definitions.cpp b/2d-advanced/elasticity-linear/crack/definitions.cpp index 4051e6c..693dea2 100644 --- a/2d-advanced/elasticity-linear/crack/definitions.cpp +++ b/2d-advanced/elasticity-linear/crack/definitions.cpp @@ -6,11 +6,10 @@ CustomWeakFormLinearElasticity::CustomWeakFormLinearElasticity(double E, double double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); double mu = E / (2*(1 + nu)); - // SINGLE-COMPONENT FORMS. USEFUL FOR MULTIMESH, DO NOT REMOVE. // Jacobian. - add_matrix_form(new DefaultJacobianElasticity_0_0(0, 0, lambda, mu)); - add_matrix_form(new DefaultJacobianElasticity_0_1(0, 1, lambda, mu)); - add_matrix_form(new DefaultJacobianElasticity_1_1(1, 1, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_0_0(0, 0, HERMES_ANY, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_0_1(0, 1, HERMES_ANY, lambda, mu)); + add_matrix_form(new DefaultJacobianElasticity_1_1(1, 1, HERMES_ANY, lambda, mu)); // Residual - first equation. add_vector_form(new DefaultResidualElasticity_0_0(0, HERMES_ANY, lambda, mu)); diff --git a/2d-advanced/elasticity-linear/crack/definitions.h b/2d-advanced/elasticity-linear/crack/definitions.h index bb4cf5e..f8fe40f 100644 --- a/2d-advanced/elasticity-linear/crack/definitions.h +++ b/2d-advanced/elasticity-linear/crack/definitions.h @@ -2,11 +2,11 @@ using namespace Hermes; using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::RefinementSelectors; using namespace Hermes::Hermes2D::WeakFormsH1; using namespace Hermes::Hermes2D::WeakFormsElasticity; using namespace Hermes::Hermes2D::Views; - -//#define USE_MULTICOMPONENT_FORMS +using namespace RefinementSelectors; class CustomWeakFormLinearElasticity : public WeakForm { diff --git a/2d-advanced/elasticity-linear/crack/domain.mesh b/2d-advanced/elasticity-linear/crack/domain.mesh index fd2eb5e..c2aa3d0 100644 --- a/2d-advanced/elasticity-linear/crack/domain.mesh +++ b/2d-advanced/elasticity-linear/crack/domain.mesh @@ -1,7 +1,7 @@ a = 0.25 # horizontal size of an element b = 0.1 # vertical size of an element -w = 0.001 # width of the cracks +w = 1.0 # width of the cracks a2 = 0.50 a3 = 0.75 @@ -12,10 +12,10 @@ a6 = 1.50 b2 = 0.2 b3 = 0.3 -bw1 = 0.0995 # b - w/2 -bw2 = 0.1005 # b + w/2 -bw3 = 0.1995 # b2 - w/2 -bw4 = 0.2005 # b2 + w/2 +bw1 = 0.095 # b - w/2 +bw2 = 0.105 # b + w/2 +bw3 = 0.195 # b2 - w/2 +bw4 = 0.205 # b2 + w/2 vertices = [ [ 0, 0 ], # vertex 0 diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 5f4668c..8f46b93 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -1,124 +1,282 @@ -#define HERMES_REPORT_ALL -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" -// This example explains how to create multiple spaces over a mesh and use them -// to solve a simple problem of linear elasticity. Note how Tuples are used, -// they replace variable-length argument lists. At the end, VonMises filter is -// used to visualize the stress. +// This example uses adaptive multimesh hp-FEM to solve a simple problem +// of linear elasticity. Note that since both displacement components +// have similar qualitative behavior, the advantage of the multimesh +// discretization is less striking. // -// PDE: Lame equations of linear elasticity. +// PDE: Lame equations of linear elasticity. No external forces, the +// object is loaded with its own weight. // -// BC: du_1/dn = f0 on Gamma_top (top edge), -// du_2/dn = f1 on Gamma_top (top edge), -// u_1 = 0 and u_2 = 0 on Gamma_bottom (bottom edge), -// du_1/dn = 0 on Gamma_rest (rest of boundary), -// du_2/dn = 0 on Gamma_rest (rest of boundary). +// BC: u_1 = u_2 = 0 on Gamma_1 (left edge) +// du_1/dn = du_2/dn = 0 elsewhere, including two horizontal +// cracks inside the domain. The width of the cracks +// is currently zero, it can be set in the mesh file +// via the parameter 'w'. // +// The following parameters can be changed: -// Read original or XML mesh file. -const bool USE_XML_FORMAT = true; -// Initial polynomial degree of all elements. -const int P_INIT = 6; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 0; +// Initial polynomial degree of mesh elements (u-displacement). +const int P_INIT_U1 = 2; +// Initial polynomial degree of mesh elements (v-displacement). +const int P_INIT_U2 = 2; +// true = use multi-mesh, false = use single-mesh-> +// Note: in the single mesh option, the meshes are +// forced to be geometrically the same but the +// polynomial degrees can still vary. +const bool MULTI = true; +// This is a quantitative parameter of the adapt(...) function and +// it has different meanings for various adaptive strategies. +const double THRESHOLD_MULTI = 0.35; +const double THRESHOLD_SINGLE = 0.7; +// Adaptive strategy: +// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total +// error is processed. If more elements have similar errors, refine +// all to keep the mesh symmetric. +// STRATEGY = 1 ... refine all elements whose error is larger +// than THRESHOLD times maximum element error. +// STRATEGY = 2 ... refine all elements whose error is larger +// than THRESHOLD. +const int STRATEGY = 0; +// Predefined list of element refinement candidates. Possible values are +// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, +// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. +const CandList CAND_LIST = H2D_HP_ANISO; +// Maximum allowed level of hanging nodes: +// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), +// MESH_REGULARITY = 1 ... at most one-level hanging nodes, +// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. +// Note that regular meshes are not supported, this is due to +// their notoriously bad performance. +const int MESH_REGULARITY = -1; +// This parameter influences the selection of +// candidates in hp-adaptivity. Default value is 1.0. +const double CONV_EXP = 1.0; +// Stopping criterion for adaptivity. +const double ERR_STOP = 0.0001; +// Adaptivity process stops when the number of degrees of freedom grows. +const int NDOF_STOP = 60000; +// Stopping criterion for the Newton's method. +const double NEWTON_TOL = 1e-6; +// Maximum allowed number of Newton iterations. +const int NEWTON_MAX_ITER = 100; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, // SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Problem parameters. -// Young modulus (steel). -const double E = 200e9; +// Young modulus for steel: 200 GPa. +const double E = 200e9; // Poisson ratio. -const double nu = 0.3; -// Density. -const double rho = 8000.0; +const double nu = 0.3; // Gravitational acceleration. -const double g1 = -9.81; -// Surface force in x-direction. -const double f0 = 0; -// Surface force in y-direction. -const double f1 = 8e4; +const double g1 = -9.81; +// Material density in kg / m^3. +const double rho = 8000; +// Top surface force in x-direction. +const double f0 = 0; +// Top surface force in y-direction. +const double f1 = 0; int main(int argc, char* argv[]) { - #pragma region 1. Load mesh and initialize space. - // Load the mesh. - MeshSharedPtr mesh(new Mesh), mesh1(new Mesh); - if (USE_XML_FORMAT == true) - { - MeshReaderH2DXML mloader; - Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); - mloader.load("domain.xml", mesh); - } - else - { - MeshReaderH2D mloader; - Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); - mloader.load("domain.mesh", mesh); - } + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + cpu_time.tick(); + + // Load the mesh-> + MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load("domain.mesh", u1_mesh); - // Perform uniform mesh refinement. - mesh->refine_all_elements(); - mesh->refine_all_elements(); + // Perform initial uniform mesh refinement. + for (int i=0; i < INIT_REF_NUM; i++) u1_mesh->refine_all_elements(); - // Initialize boundary conditions. - DefaultEssentialBCConst zero_disp("Bottom", 0.0); - EssentialBCs bcs(&zero_disp); + // Create initial mesh for the vertical displacement component. + // This also initializes the multimesh hp-FEM. + u2_mesh->copy(u1_mesh); - // Create x- and y- displacement space using the default H1 shapeset. - SpaceSharedPtr u1_space(new H1Space(mesh, &bcs, P_INIT)); - SpaceSharedPtr u2_space(new H1Space(mesh, &bcs, P_INIT)); - int ndof = Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)); - Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); - #pragma endregion + // Initialize boundary conditions. + DefaultEssentialBCConst zero_disp("bdy left", 0.0); + EssentialBCs bcs(&zero_disp); - // Show mesh. - OrderView oview("Mesh", new WinGeom(0, 0, 1210, 680)); - oview.show(u1_space); + // Create x- and y- displacement space using the default H1 shapeset. + SpaceSharedPtr u1_space(new H1Space(u1_mesh, &bcs, P_INIT_U1)); + SpaceSharedPtr u2_space(new H1Space(u2_mesh, &bcs, P_INIT_U2)); + Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space))); // Initialize the weak formulation. - CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "Top", f0, f1); + // NOTE; These weak forms are identical to those in example P01-linear/08-system. + CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy rest", f0, f1); // Initialize the FE problem. DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); - // Initialize Newton solver. - NewtonSolver newton(&dp); - newton.set_tolerance(1e-5); + // Initialize coarse and reference mesh solutions. + MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); + MeshFunctionSharedPtr u1_sln_ref(new Solution), u2_sln_ref(new Solution); + + // Initialize refinement selector. + // Error calculation. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); + + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement stoppingCriterion(0.75); + + // Adaptivity processor class. + Adapt adaptivity(Hermes::vector >(u1_space, u2_space), &errorCalculator, &stoppingCriterion); + + // Element refinement type refinement_selector. + H1ProjBasedSelector refinement_selector(CAND_LIST); + + // Initialize views. + ScalarView s_view_0("Solution (x-displacement)", new WinGeom(0, 0, 700, 150)); + s_view_0.show_mesh(false); + ScalarView s_view_1("Solution (y-displacement)", new WinGeom(0, 180, 700, 150)); + s_view_1.show_mesh(false); + OrderView o_view_0("Mesh (x-displacement)", new WinGeom(0, 360, 700, 150)); + OrderView o_view_1("Mesh (y-displacement)", new WinGeom(0, 540, 700, 150)); + ScalarView mises_view("Von Mises stress [Pa]", new WinGeom(300, 405, 700, 250)); + + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est; - #pragma region 2. Perform Newton's loop and get the solution. + // Adaptivity loop: + int as = 1; + bool done = false; + do + { + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + + // Construct globally refined reference mesh and setup reference space. + Mesh::ReferenceMeshCreator refMeshCreator1(u1_mesh); + MeshSharedPtr ref_u1_mesh = refMeshCreator1.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator1(u1_space, ref_u1_mesh); + SpaceSharedPtr ref_u1_space = refSpaceCreator1.create_ref_space(); + + Mesh::ReferenceMeshCreator refMeshCreator2(u2_mesh); + MeshSharedPtr ref_u2_mesh = refMeshCreator2.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator2(u2_space, ref_u2_mesh); + SpaceSharedPtr ref_u2_space = refSpaceCreator2.create_ref_space(); + + Hermes::vector > ref_spaces(ref_u1_space, ref_u2_space); + + int ndof_ref = Space::get_num_dofs(ref_spaces); + + // Initialize the FE problem. + DiscreteProblem dp(&wf, ref_spaces); + + // Initialize Newton solver. + NewtonSolver newton(&dp); + newton.set_verbose_output(true); + + // Time measurement. + cpu_time.tick(); + + // Perform Newton's iteration. + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); try { + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); newton.solve(); } - catch(std::exception& e) { std::cout << e.what(); } - - // Translate the resulting coefficient vector into the Solution sln. - MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); - Solution::vector_to_solutions(newton.get_sln_vector(), Hermes::vector >(u1_space, u2_space), - Hermes::vector >(u1_sln, u2_sln)); -#pragma endregion + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + } - #pragma region 3. Filters for visualization + visualization setup. - // Visualize the solution. - ScalarView viewx("X-displacement", new WinGeom(0, 0, 600, 330)); - ScalarView viewy("Y-displacement", new WinGeom(0, 350, 600, 330)); - ScalarView view("Von Mises stress [Pa]", new WinGeom(610, 0, 600, 680)); - // First Lame constant. - double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); - // Second Lame constant. - double mu = E / (2*(1 + nu)); + // Time measurement. + cpu_time.tick(); + + // Translate the resulting coefficient vector into the Solution sln-> + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, + Hermes::vector >(u1_sln_ref, u2_sln_ref)); + + // Project the fine mesh solution onto the coarse mesh-> + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), + Hermes::vector >(u1_sln_ref, u2_sln_ref), + Hermes::vector >(u1_sln, u2_sln)); + + // View the coarse mesh solution and polynomial orders. + s_view_0.show(u1_sln); + o_view_0.show(u1_space); + s_view_1.show(u2_sln); + o_view_1.show(u2_space); + // For von Mises stress Filter. + double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); + double mu = E / (2*(1 + nu)); MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln, u2_sln), lambda, mu)); - - viewx.show(u1_sln); - viewx.show_mesh(false); - viewy.show(u2_sln); - viewy.show_mesh(false); - view.show(stress, HERMES_EPS_LOW, H2D_FN_VAL_0, u1_sln, u2_sln, 1.5e5); -#pragma endregion - - // Wait for the view to be closed. - View::wait(); + mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln, u2_sln, 1e3); - return 0; -} + // Skip visualization time. + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + /* + // Register custom forms for error calculation. + adaptivity->set_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); + adaptivity->set_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); + adaptivity->set_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); + adaptivity->set_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); + */ + + // Calculate error estimate for each solution component and the total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + Hermes::vector err_est_rel; + errorCalculator.calculate_errors(Hermes::vector >(u1_sln, u2_sln), + Hermes::vector >(u1_sln_ref, u2_sln_ref)); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + + // Time measurement. + cpu_time.tick(); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", + Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), + err_est_rel_total); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); + graph_cpu_est.save("conv_cpu_est.dat"); + + // If err_est too large, adapt the mesh-> + if (err_est_rel_total < ERR_STOP) + done = true; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&refinement_selector, &refinement_selector)); + } + if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; + + // Increase counter. + as++; + } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + + // Show the reference solution - the final result. + s_view_0.set_title("Fine mesh solution (x-displacement)"); + s_view_0.show(u1_sln_ref); + s_view_1.set_title("Fine mesh solution (y-displacement)"); + s_view_1.show(u2_sln_ref); + // For von Mises stress Filter. + double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); + double mu = E / (2*(1 + nu)); + MeshFunctionSharedPtr stress(new VonMisesFilter(Hermes::vector >(u1_sln_ref, u2_sln_ref), lambda, mu)); + mises_view.show(stress, HERMES_EPS_NORMAL, H2D_FN_VAL_0, u1_sln_ref, u2_sln_ref, 1e3); + + // Wait for all views to be closed. + View::wait(); + return 0; +} \ No newline at end of file diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index c10df4a..ba6770c 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -228,7 +228,7 @@ KrivodonovaDiscontinuityDetector::KrivodonovaDiscontinuityDetector(Hermes::vecto unsigned int mesh0_seq = spaces[0]->get_mesh()->get_seq(); for(unsigned int i = 0; i < spaces.size(); i++) if(spaces[i]->get_mesh()->get_seq() != mesh0_seq) - throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh->"); + throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh."); mesh = spaces[0]->get_mesh(); }; @@ -504,7 +504,7 @@ KuzminDiscontinuityDetector::KuzminDiscontinuityDetector(Hermes::vectorget_mesh()->get_seq(); for(unsigned int i = 0; i < spaces.size(); i++) if(spaces[i]->get_mesh()->get_seq() != mesh0_seq) - throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh->"); + throw Hermes::Exceptions::Exception("So far DiscontinuityDetector works only for single mesh."); mesh = spaces[0]->get_mesh(); }; diff --git a/2d-advanced/helmholtz/waveguide/domain.xml b/2d-advanced/helmholtz/waveguide/domain.xml new file mode 100644 index 0000000..5b7596b --- /dev/null +++ b/2d-advanced/helmholtz/waveguide/domain.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/helmholtz/waveguide/initial.xml b/2d-advanced/helmholtz/waveguide/initial.xml new file mode 100644 index 0000000..05b1807 --- /dev/null +++ b/2d-advanced/helmholtz/waveguide/initial.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index d04ae31..d878187 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -101,7 +101,6 @@ int main(int argc, char* argv[]) ScalarView viewEr("Er [V/m]", new WinGeom(600, 0, 700, 200)); viewEr.show_mesh(false); - viewEr.set_3d_mode(true); ScalarView viewEi("Ei [V/m]", new WinGeom(600, 220, 700, 200)); ScalarView viewMagnitude("Magnitude of E [V/m]", new WinGeom(600, 440, 700, 200)); diff --git a/2d-advanced/maxwell/CMakeLists.txt b/2d-advanced/maxwell/CMakeLists.txt index 95f4a60..dc7929a 100644 --- a/2d-advanced/maxwell/CMakeLists.txt +++ b/2d-advanced/maxwell/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory(magnetostatics) \ No newline at end of file +add_subdirectory(magnetostatics) +add_subdirectory(microwave-oven) diff --git a/2d-advanced/maxwell/magnetostatics/definitions.cpp b/2d-advanced/maxwell/magnetostatics/definitions.cpp index c34d852..e17d9f6 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.cpp +++ b/2d-advanced/maxwell/magnetostatics/definitions.cpp @@ -28,7 +28,7 @@ void FilterVectorPotential::filter_fn(int n, Hermes::vector values, dou for(unsigned int j = 0; j < values.size(); j++) result[i] += sqr(values[j][i]); - result[i] = std::sqrt(result[i]) * e->x[i]; + result[i] = std::sqrt(result[i]); } } diff --git a/2d-advanced/maxwell/microwave-oven/definitions.cpp b/2d-advanced/maxwell/microwave-oven/definitions.cpp index a2be726..25e418e 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.cpp +++ b/2d-advanced/maxwell/microwave-oven/definitions.cpp @@ -31,8 +31,7 @@ Ord CustomMatrixForm::ord(int n, double *wt, Func *u_ext[], Func *u, F double CustomMatrixForm::gamma(int marker, double x, double y) const { - if (align_mesh && (static_cast(wf))->get_marker() == marker) return 0.03; - if (!align_mesh && in_load(x,y)) + if (in_load(x,y)) { double cx = -0.152994121; double cy = 0.030598824; double r = std::sqrt(sqr(cx - x) + sqr(cy - y)); @@ -55,8 +54,7 @@ MatrixFormVol >* CustomMatrixForm::clone() const double CustomMatrixForm::er(int marker, double x, double y) const { - if (align_mesh && (static_cast(wf))->get_marker() == marker) return 7.5; - if (!align_mesh && in_load(x,y)) + if (in_load(x,y)) { double cx = -0.152994121; double cy = 0.030598824; double r = std::sqrt(sqr(cx - x) + sqr(cy - y)); @@ -113,8 +111,7 @@ Ord CustomResidualForm::ord(int n, double *wt, Func *u_ext[], Func *v, double CustomResidualForm::gamma(int marker, double x, double y) const { - if (align_mesh && (static_cast(wf))->get_marker() == marker) return 0.03; - if (!align_mesh && in_load(x,y)) + if (in_load(x,y)) { double cx = -0.152994121; double cy = 0.030598824; double r = std::sqrt(sqr(cx - x) + sqr(cy - y)); @@ -137,8 +134,7 @@ CustomResidualForm::VectorFormVol >* CustomResidualForm::cl double CustomResidualForm::er(int marker, double x, double y) const { - if (align_mesh && (static_cast(wf))->get_marker() == marker) return 7.5; - if (!align_mesh && in_load(x,y)) + if (in_load(x,y)) { double cx = -0.152994121; double cy = 0.030598824; double r = std::sqrt(sqr(cx - x) + sqr(cy - y)); @@ -165,8 +161,12 @@ template Scalar CustomVectorFormSurf::vector_form_surf(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (v->val1[i]); + std::complex ii = std::complex(0.0, 1.0); - return ii * omega * J * int_v1(n, wt, v); // just second component of v, since J = (0, J) + return ii * omega * J * result; } std::complex CustomVectorFormSurf::value(int n, double *wt, Func > *u_ext[], diff --git a/2d-advanced/maxwell/microwave-oven/definitions.h b/2d-advanced/maxwell/microwave-oven/definitions.h index 6d6e3c7..3a05b24 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.h +++ b/2d-advanced/maxwell/microwave-oven/definitions.h @@ -6,6 +6,7 @@ using namespace Hermes; using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +using namespace Hermes::Hermes2D::WeakFormsHcurl; /* Weak forms */ @@ -121,35 +122,37 @@ class CustomWeakForm : public WeakForm > // Custom error form. -class CustomErrorForm : public Adapt >::MatrixFormVolError +class CustomErrorForm : public NormFormVol > { public: - CustomErrorForm(double kappa) : Adapt >::MatrixFormVolError(0, 0) + CustomErrorForm(double kappa) : NormFormVol >(0, 0) { kappa_squared = sqr(kappa); }; template - Scalar hcurl_form_kappa(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const + Scalar hcurl_form_kappa(int n, double *wt, Func *u, Func *v, Geom *e) const { - return int_curl_e_curl_f(n, wt, u, v) + kappa_squared * int_e_f(n, wt, u, v); + Scalar result = Scalar(0); + + for (int i = 0; i < n; i++) + { + result += wt[i] * (u->curl[i] * conj(v->curl[i])); + result += kappa_squared * wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i])); + } + + return result; } - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func > *u, - Func > *v, Geom *e, Func > **ext) const + virtual std::complex value(int n, double *wt, Func > *u, Func > *v, Geom *e) const { - return hcurl_form_kappa >(n, wt, u_ext, u, v, e, ext); + return hcurl_form_kappa >(n, wt, u, v, e); } - virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const + virtual Ord ord(int n, double *wt, Func *u, Func *v, Geom *e) const { - return hcurl_form_kappa(n, wt, u_ext, u, v, e, ext); + return hcurl_form_kappa(n, wt, u, v, e); } - virtual MatrixFormVol >* clone() const { return new CustomErrorForm(Hermes::sqrt(kappa_squared)); } - - double kappa_squared; }; diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 2432e9f..33a1cbb 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -34,22 +34,13 @@ const int INIT_REF_NUM = 0; // to the maximum poly order of the tangential component, and polynomials // of degree P_INIT + 1 are present in element interiors. P_INIT = 0 // is for Whitney elements. -const int P_INIT = 2; +const int P_INIT = 1; // if ALIGN_MESH == true, curvilinear elements aligned with the // circular load are used, otherwise one uses a non-aligned mesh-> const bool ALIGN_MESH = false; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adapt >ive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; +const double THRESHOLD = 0.6; // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. @@ -65,7 +56,7 @@ const int MESH_REGULARITY = -1; // candidates in hp-adaptivity. Default value is 1.0. const double CONV_EXP = 1.0; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; +const double ERR_STOP = 5e-2; // Adaptivity process stops when the number of degrees of freedom grows // over this limit. This is to prevent h-adaptivity to go on forever. const int NDOF_STOP = 60000; @@ -74,7 +65,7 @@ const int NDOF_STOP = 60000; MatrixSolverType matrix_solver = SOLVER_UMFPACK; // Newton's method. -const double NEWTON_TOL = 1e-6; +const double NEWTON_TOL = 1e-4; const int NEWTON_MAX_ITER = 100; // Problem parameters. @@ -94,9 +85,21 @@ const double J = 0.0000033333; const std::string BDY_PERFECT_CONDUCTOR = "b2"; const std::string BDY_CURRENT = "b1"; +class CustomErrorCalculator : public ErrorCalculator > +{ +public: + CustomErrorCalculator(CalculatedErrorType errorType) : ErrorCalculator >(errorType) + { + this->add_error_form(new CustomErrorForm (kappa)); + } + virtual ~CustomErrorCalculator() + { + } +}; + int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; if (ALIGN_MESH) @@ -105,7 +108,8 @@ int main(int argc, char* argv[]) mloader.load("oven_load_square.mesh", mesh); // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(); // Initialize boundary conditions DefaultEssentialBCConst > bc_essential(BDY_PERFECT_CONDUCTOR, std::complex(0.0, 0.0)); @@ -126,6 +130,15 @@ int main(int argc, char* argv[]) // Initialize refinements selector. HcurlProjBasedSelector > selector(CAND_LIST); + // Error calculation. + CustomErrorCalculator errorCalculator(RelativeErrorToGlobalNorm); + + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement > stoppingCriterion(THRESHOLD); + + // Adaptivity. + Adapt > adaptivity(space, &errorCalculator, &stoppingCriterion); + // Initialize views. ScalarView eview("Electric field", new WinGeom(0, 0, 580, 400)); OrderView oview("Polynomial orders", new WinGeom(590, 0, 550, 400)); @@ -137,6 +150,11 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); + Hermes::Hermes2D::NewtonSolver > newton(&wf, space); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL); + + // Newton's iteration. // Adaptivity loop: int as = 1; bool done = false; do @@ -152,18 +170,13 @@ int main(int argc, char* argv[]) int ndof_ref = Space >::get_num_dofs(ref_space); // Initialize reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem > dp(&wf, ref_space); - + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Time measurement. cpu_time.tick(); + newton.set_space(ref_space); - // Perform Newton's iteration. - Hermes::Hermes2D::NewtonSolver > newton(&dp); try { - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -174,37 +187,35 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the Solution > sln-> Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); // View the coarse mesh solution and polynomial orders. - MeshFunctionSharedPtr real(new RealFilter(sln)); + MeshFunctionSharedPtr real(new RealFilter(ref_sln)); MeshFunctionSharedPtr magn(new MagFilter(real)); MeshFunctionSharedPtr limited_magn(new ValFilter(magn, 0.0, 4e3)); char title[100]; sprintf(title, "Electric field, adaptivity step %d", as); eview.set_title(title); //eview.set_min_max_range(0.0, 4e3); - eview.show(limited_magn); + eview.show(limited_magn, HERMES_EPS_LOW); sprintf(title, "Polynomial orders, adaptivity step %d", as); oview.set_title(title); oview.show(space); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt >* adaptivity = new Adapt >(space); - // Set custom error form and calculate error estimate. - CustomErrorForm cef(kappa); - adaptivity->set_error_form(0, 0, &cef); - double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + // Calculate error estimate. + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); - + // Time measurement. cpu_time.tick(); @@ -214,17 +225,15 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); } if (space->get_num_dofs() >= NDOF_STOP) done = true; - delete adaptivity; - // Increase counter. as++; } @@ -232,20 +241,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - MeshFunctionSharedPtr ref_real(new RealFilter(sln)); - MeshFunctionSharedPtr ref_magn(new MagFilter(ref_real)); - MeshFunctionSharedPtr ref_limited_magn(new ValFilter(ref_magn, 0.0, 4e3)); - eview.set_title("Fine mesh solution - magnitude"); - eview.show(ref_limited_magn); - - // Output solution in VTK format. - Linearizer lin; - bool mode_3D = true; - lin.save_solution_vtk(ref_limited_magn, "sln->vtk", "Magnitude of E", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); - // Wait for all views to be closed. View::wait(); return 0; -} - +} \ No newline at end of file From 5744aed7be60083496ad1b68f6bf1cbde088b4a7 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 23 May 2013 10:06:05 -0700 Subject: [PATCH 34/64] Quick replacements in CMakeLists.txt --- .gitignore | 5 ++++- CMakeLists.txt | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0e35c6a..8912af5 100644 --- a/.gitignore +++ b/.gitignore @@ -80,4 +80,7 @@ Debug/ *.css *.tag *.sty -*.dvi \ No newline at end of file +*.dvi +*.vtk +*.m +doc/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b23f3ec..e698d8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,8 @@ project(hermes_examples) # set(MPI_LIBRARIES -lmpi) # set(MPI_INCLUDE_PATH /usr/include/openmpi - # By default all examples are turned on. - # This can be changed in your CMake.vars file. - SET(WITH_1d YES) + +SET(WITH_1d NO) SET(WITH_2d-advanced YES) SET(WITH_acoustics NO) SET(WITH_advection-diffusion-reaction NO) @@ -45,7 +44,7 @@ project(hermes_examples) SET(WITH_wave-equation NO) SET(WITH_2d-benchmarks-general NO) SET(WITH_2d-benchmarks-nist NO) - + # Allow to override the default values in CMake.vars: include(CMake.vars OPTIONAL) From 34a8999b68046c6283f5ed5791fcc8b739e2ef52 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 23 May 2013 10:09:21 -0700 Subject: [PATCH 35/64] Add umfpack (temporarily). --- CMakeLists.txt | 3 +++ cmake/FindUMFPACK.cmake | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 cmake/FindUMFPACK.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e698d8f..e3d36e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,9 @@ SET(WITH_1d NO) find_package(TCMALLOC REQUIRED) include_directories(${TCMALLOC_INCLUDE_DIR}) + find_package(UMFPACK REQUIRED) + include_directories(${UMFPACK_INCLUDE_DIRS}) + if(WITH_TRILINOS) find_package(TRILINOS REQUIRED) include_directories(${TRILINOS_INCLUDE_DIR}) diff --git a/cmake/FindUMFPACK.cmake b/cmake/FindUMFPACK.cmake new file mode 100644 index 0000000..86c77a6 --- /dev/null +++ b/cmake/FindUMFPACK.cmake @@ -0,0 +1,49 @@ +# +# UMFPACK +# + +# You can specify your own version of the library instead of the one provided by +# Femhub by specifying the environment variables MY_UMFPACK_LIB_DIRS and +# MY_UMFPACK_INC_DIRS. +IF ("$ENV{MY_UMFPACK_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_UMFPACK_INC_DIRS}" STREQUAL "") + # When linking the library to stand-alone Hermes, you may also specify the + # variables directly in CMake.vars + IF (NOT MY_UMFPACK_LIB_DIRS OR NOT MY_UMFPACK_INC_DIRS) + # Alternatively, you may simply specify UMFPACK_ROOT in CMake.vars. This is + # the traditional way used also in the spkg files from the hpfem/solvers + # repository and in the Hermes spkg. + SET(MY_UMFPACK_LIB_DIRS ${UMFPACK_ROOT}/lib) + SET(MY_UMFPACK_INC_DIRS ${UMFPACK_ROOT}/include) + ENDIF (NOT MY_UMFPACK_LIB_DIRS OR NOT MY_UMFPACK_INC_DIRS) +ELSE ("$ENV{MY_UMFPACK_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_UMFPACK_INC_DIRS}" STREQUAL "") + SET(MY_UMFPACK_LIB_DIRS $ENV{MY_UMFPACK_LIB_DIRS}) + SET(MY_UMFPACK_INC_DIRS $ENV{MY_UMFPACK_INC_DIRS}) +ENDIF ("$ENV{MY_UMFPACK_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_UMFPACK_INC_DIRS}" STREQUAL "") + +FIND_PATH(UMFPACK_INCLUDE_DIR umfpack.h ${MY_UMFPACK_INC_DIRS} NO_DEFAULT_PATH) +FIND_PATH(AMD_INCLUDE_DIR amd.h ${MY_UMFPACK_INC_DIRS} NO_DEFAULT_PATH) +FIND_PATH(UMFPACK_INCLUDE_DIR umfpack.h /usr/include /usr/include/umfpack /usr/local/include/UMFPACK /usr/include/suitesparse /opt/local/include/ufsparse) +FIND_PATH(AMD_INCLUDE_DIR amd.h /usr/include /usr/local/include/AMD /usr/include/suitesparse /opt/local/include/ufsparse) + +FIND_LIBRARY(UMFPACK_LIBRARY NAMES libumfpack umfpack PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) +FIND_LIBRARY(SSC_LIBRARY NAMES libsuitesparseconfig suitesparseconfig PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) +FIND_LIBRARY(AMD_LIBRARY NAMES libamd amd PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) +FIND_LIBRARY(UMFPACK_LIBRARY NAMES libumfpack umfpack PATHS /usr/lib /usr/local/lib/UMFPACK) +FIND_LIBRARY(SSC_LIBRARY NAMES libsuitesparseconfig suitesparseconfig PATHS /usr/lib /usr/local/lib/UMFPACK) +FIND_LIBRARY(AMD_LIBRARY NAMES libamd amd PATHS /usr/lib /usr/local/lib/AMD) + +if(${SSC_LIBRARY} STREQUAL "SSC_LIBRARY-NOTFOUND") + set(SSC_LIBRARY "") +endif(${SSC_LIBRARY} STREQUAL "SSC_LIBRARY-NOTFOUND") + +SET(UMFPACK_INCLUDE_DIRS ${UMFPACK_INCLUDE_DIR} ${AMD_INCLUDE_DIR}) +SET(UMFPACK_LIBRARIES ${UMFPACK_LIBRARY} ${SSC_LIBRARY} ${AMD_LIBRARY}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( UMFPACK + "UMFPACK could not be found. Please install it according to instructions at\n + < http://hpfem.org/hermes/doc/src/installation/matrix_solvers/umfpack.html >\n + and/or provide path to its root directory by setting variable UMFPACK_ROOT + in the CMake.vars file." + UMFPACK_LIBRARIES UMFPACK_INCLUDE_DIRS +) \ No newline at end of file From 7a9fff0bf809767df4f40de48fd1140ae6ec0d11 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 29 May 2013 16:07:06 +0200 Subject: [PATCH 36/64] Work on examples, add acoustics-wave-propagation. --- 1d/layer-boundary/main.cpp | 45 +- 1d/moving-front/main.cpp | 75 +- 1d/poisson/main.cpp | 4 +- 1d/system/main.cpp | 84 +- 2d-advanced/acoustics/CMakeLists.txt | 3 +- .../acoustics/apartment/definitions.cpp | 14 +- 2d-advanced/acoustics/apartment/definitions.h | 4 +- 2d-advanced/acoustics/apartment/main.cpp | 111 +-- .../acoustics/horn-axisym/definitions.cpp | 14 +- .../acoustics/horn-axisym/definitions.h | 4 +- 2d-advanced/acoustics/horn-axisym/main.cpp | 103 +-- .../acoustics/wave-propagation/acoustic.xml | 189 +++++ .../wave-propagation/definitions.cpp | 266 +++++++ .../acoustics/wave-propagation/definitions.h | 298 +++++++ .../acoustics/wave-propagation/domain.mesh | 1 + .../wave-propagation/domain_apartment.mesh | 752 ++++++++++++++++++ .../acoustics/wave-propagation/main.cpp | 95 +++ .../acoustics/wave-propagation/test.xml | 45 ++ .../test_acoustic_transient_planar.py | 69 ++ .../linear-advection-dg-adapt/main.cpp | 68 +- .../linear-advection-diffusion/main.cpp | 65 +- 2d-advanced/elasticity-linear/CMakeLists.txt | 1 + .../elasticity-linear/bracket/main.cpp | 91 +-- 2d-advanced/elasticity-linear/crack/main.cpp | 16 +- 2d-advanced/euler/CMakeLists.txt | 16 +- 2d-advanced/euler/forward-step-adapt/main.cpp | 71 +- 2d-advanced/euler/forward-step/main.cpp | 2 +- 2d-advanced/euler/gamm-channel/main.cpp | 2 +- .../heating-flow-coupling-adapt/main.cpp | 42 +- .../euler/heating-flow-coupling/main.cpp | 2 +- .../heating-induced-vortex-adapt/main.cpp | 24 +- .../euler/heating-induced-vortex/main.cpp | 2 +- .../euler/reflected-shock-adapt/main.cpp | 66 +- 2d-advanced/euler/reflected-shock/main.cpp | 2 +- .../heat-and-moisture-adapt/definitions.h | 4 +- .../heat-and-moisture-adapt/main.cpp | 81 +- .../main.cpp | 61 +- 2d-advanced/helmholtz/waveguide/main.cpp | 2 +- 2d-advanced/maxwell/CMakeLists.txt | 4 + 2d-advanced/maxwell/magnetostatics/main.cpp | 2 +- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 88 +- .../maxwell/microwave-oven/definitions.cpp | 18 +- .../maxwell/microwave-oven/definitions.h | 40 +- 2d-advanced/maxwell/microwave-oven/main.cpp | 42 +- .../maxwell/resonator-time-domain-I/main.cpp | 4 +- .../definitions.cpp | 9 + .../resonator-time-domain-II-ie/main.cpp | 4 +- .../definitions.cpp | 9 + .../resonator-time-domain-II-rk/main.cpp | 4 +- 2d-advanced/navier-stokes/bearing/main.cpp | 4 +- .../circular-obstacle-adapt/main.cpp | 70 +- .../navier-stokes/circular-obstacle/main.cpp | 4 +- .../navier-stokes/driven-cavity/main.cpp | 4 +- .../navier-stokes/ns-heat-subdomains/main.cpp | 4 +- .../navier-stokes/rayleigh-benard/main.cpp | 4 +- .../np-poisson-timedep-adapt/main.cpp | 86 +- .../timestep_controller.h | 4 +- 2d-advanced/neutronics/saphir/main.cpp | 65 +- 2d-advanced/richards/basic-ie-newton/main.cpp | 4 +- 2d-advanced/richards/basic-ie-picard/main.cpp | 4 +- .../richards/basic-rk-newton-adapt/main.cpp | 78 +- 2d-advanced/richards/basic-rk-newton/main.cpp | 4 +- .../capillary-barrier-adapt/extras.cpp | 2 +- .../richards/capillary-barrier-adapt/main.cpp | 68 +- .../richards/capillary-barrier-rk/extras.cpp | 2 +- .../richards/capillary-barrier-rk/main.cpp | 4 +- .../gross-pitaevski-adapt/definitions.cpp | 16 +- .../gross-pitaevski-adapt/definitions.h | 29 +- .../gross-pitaevski-adapt/main.cpp | 112 +-- .../gross-pitaevski/definitions.cpp | 16 +- .../gross-pitaevski/definitions.h | 29 +- .../schroedinger/gross-pitaevski/main.cpp | 20 +- 2d-advanced/wave-equation/wave-1/main.cpp | 4 +- 2d-benchmarks-general/layer-boundary/main.cpp | 73 +- 2d-benchmarks-general/layer-interior/main.cpp | 67 +- 2d-benchmarks-general/lshape/main.cpp | 69 +- .../moving-front-space-adapt/main.cpp | 71 +- 2d-benchmarks-general/nonsym-check/main.cpp | 67 +- 2d-benchmarks-general/smooth-aniso-x/main.cpp | 76 +- 2d-benchmarks-general/smooth-aniso-y/main.cpp | 68 +- 2d-benchmarks-general/smooth-iso/main.cpp | 68 +- .../01-analytic-solution/main.cpp | 19 +- .../02-reentrant-corner/main.cpp | 18 +- .../03-linear-elasticity/main.cpp | 32 +- .../04-exponential-peak/main.cpp | 8 +- 2d-benchmarks-nist/05-battery/main.cpp | 37 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 8 +- .../07-boundary-line-singularity/main.cpp | 8 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 8 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 32 +- .../10-interior-line-singularity/main.cpp | 34 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 34 +- .../12-multiple-difficulties/main.cpp | 8 +- 2d-benchmarks-nist/NIST-util.cpp | 12 +- 2d-benchmarks-nist/NIST-util.h | 2 +- CMakeLists.txt | 27 +- 96 files changed, 2777 insertions(+), 1724 deletions(-) create mode 100644 2d-advanced/acoustics/wave-propagation/acoustic.xml create mode 100644 2d-advanced/acoustics/wave-propagation/definitions.cpp create mode 100644 2d-advanced/acoustics/wave-propagation/definitions.h create mode 100644 2d-advanced/acoustics/wave-propagation/domain.mesh create mode 100644 2d-advanced/acoustics/wave-propagation/domain_apartment.mesh create mode 100644 2d-advanced/acoustics/wave-propagation/main.cpp create mode 100644 2d-advanced/acoustics/wave-propagation/test.xml create mode 100644 2d-advanced/acoustics/wave-propagation/test_acoustic_transient_planar.py diff --git a/1d/layer-boundary/main.cpp b/1d/layer-boundary/main.cpp index 27f2881..d26e95e 100644 --- a/1d/layer-boundary/main.cpp +++ b/1d/layer-boundary/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -24,18 +24,13 @@ const int P_INIT = 1; const int INIT_REF_NUM = 0; // Number of initial mesh refinements towards the boundary. const int INIT_REF_NUM_BDY = 5; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies (see below). -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; +/// This is a quantitative parameter of the adapt(...) function and +// it has different meanings for various adaptive strategies. +const double THRESHOLD = 0.5; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. @@ -65,7 +60,7 @@ const double K = 1e2; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH1DXML mloader; mloader.load("domain.xml", mesh); @@ -97,7 +92,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 600, 360)); @@ -118,7 +113,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. @@ -133,7 +128,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -157,17 +152,19 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; + Adapt adaptivity(space, &errorCalculator, &stoppingCriterion); + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -195,12 +192,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/1d/moving-front/main.cpp b/1d/moving-front/main.cpp index 07128b7..6b35048 100644 --- a/1d/moving-front/main.cpp +++ b/1d/moving-front/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -38,38 +38,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// fine mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 1000; -// Matrix solvers: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Newton's method // Stopping criterion for Newton on fine mesh-> @@ -114,7 +92,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH1DXML mloader; try @@ -152,7 +130,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln_time_new(new Solution(mesh)); // Create a refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Visualize initial condition. char title[100]; @@ -196,7 +174,7 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. @@ -232,36 +210,31 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); } - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(space, sln_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(space); - double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, sln_time_new) * 100; + adaptivity.set_space(space); + errorCalculator.calculate_errors(sln_coarse, sln_time_new); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (space->get_num_dofs() >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(&selector); + + // Increase the counter of performed adaptivity steps. + as++; } - - // Clean up. - delete adaptivity; } while (done == false); diff --git a/1d/poisson/main.cpp b/1d/poisson/main.cpp index b335884..7f1b920 100644 --- a/1d/poisson/main.cpp +++ b/1d/poisson/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace Hermes::Hermes2D; @@ -38,7 +38,7 @@ const double FIXED_BDY_TEMP = 20.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH1DXML mloader; mloader.load("domain.xml", mesh); diff --git a/1d/system/main.cpp b/1d/system/main.cpp index 41137d0..3269352 100644 --- a/1d/system/main.cpp +++ b/1d/system/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -39,7 +39,7 @@ const int P_INIT_V = 1; // Number of initial boundary refinements const int INIT_REF_BDY = 5; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh-> +// MULTI = false ... use single-mesh. // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -47,37 +47,16 @@ const bool MULTI = true; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.1; -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 1000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Problem parameters. const double D_u = 1; @@ -93,7 +72,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh); MeshReaderH1DXML mloader; mloader.load("domain.xml", u_mesh); @@ -144,7 +123,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr u_sln(new Solution), v_sln(new Solution), u_ref_sln(new Solution), v_ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. Views::ScalarView s_view_0("Solution[0]", new Views::WinGeom(0, 0, 440, 350)); @@ -167,7 +146,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. // FIXME: This should be increase in the x-direction only. int order_increase = 1; // FIXME: This should be '2' but that leads to a segfault. @@ -190,7 +169,7 @@ int main(int argc, char* argv[]) int ndof_ref = Space::get_num_dofs(ref_spaces); // Initialize reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); @@ -214,7 +193,7 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u_ref_sln, v_ref_sln)); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solutions on coarse meshes."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u_space, v_space), Hermes::vector >(u_ref_sln, v_ref_sln), @@ -230,21 +209,16 @@ int main(int argc, char* argv[]) // Calculate element errors. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - Adapt* adaptivity = new Adapt(Hermes::vector >(u_space, v_space)); + adaptivity.set_spaces(Hermes::vector >(u_space, v_space)); - // Calculate error estimate for each solution component and the total error estimate. - Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(u_ref_sln, v_ref_sln), &err_est_rel) * 100; - #ifdef WITH_EXACT_SOLUTION - // Calculate exact error for each solution component and the total exact error. - Hermes::vector err_exact_rel; - bool solutions_for_adapt = false; - double err_exact_rel_total = adaptivity->calc_err_exact(Hermes::vector >(u_sln, v_sln), - Hermes::vector >(exact_u, exact_v), &err_exact_rel, solutions_for_adapt) * 100; + errorCalculator.calculate_errors(Hermes::vector >(u_sln, v_sln), Hermes::vector >(exact_u, exact_v), false); + double err_exact_rel_total = errorCalculator.get_total_error_squared() * 100; #endif + errorCalculator.calculate_errors(Hermes::vector >(u_sln, v_sln), Hermes::vector >(u_ref_sln, v_ref_sln), true); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + // Time measurement. cpu_time.tick(); @@ -252,10 +226,8 @@ int main(int argc, char* argv[]) #ifdef WITH_EXACT_SOLUTION Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", u_space->get_num_dofs(), ref_u_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%, err_exact_rel[0]: %g%%", err_est_rel[0]*100, err_exact_rel[0]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", v_space->get_num_dofs(), ref_v_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%, err_exact_rel[1]: %g%%", err_est_rel[1]*100, err_exact_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", Space::get_num_dofs(Hermes::vector >(u_space, v_space)), Space::get_num_dofs(ref_spaces)); @@ -285,20 +257,14 @@ int main(int argc, char* argv[]) graph_cpu_exact.save("conv_cpu_exact.dat"); #endif - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector)); } - if (Space::get_num_dofs(Hermes::vector >(u_space, v_space)) - >= NDOF_STOP) done = true; - - // Clean up. - delete adaptivity; // Increase counter. as++; diff --git a/2d-advanced/acoustics/CMakeLists.txt b/2d-advanced/acoustics/CMakeLists.txt index 430f781..fd662cc 100644 --- a/2d-advanced/acoustics/CMakeLists.txt +++ b/2d-advanced/acoustics/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(apartment) -add_subdirectory(horn-axisym) \ No newline at end of file +add_subdirectory(horn-axisym) +add_subdirectory(wave-propagation) \ No newline at end of file diff --git a/2d-advanced/acoustics/apartment/definitions.cpp b/2d-advanced/acoustics/apartment/definitions.cpp index 7ad6da2..6db507c 100644 --- a/2d-advanced/acoustics/apartment/definitions.cpp +++ b/2d-advanced/acoustics/apartment/definitions.cpp @@ -1,17 +1,17 @@ #include "definitions.h" -CustomWeakFormAcoustics::CustomWeakFormAcoustics(std::string bdy_newton, double rho, double sound_speed, double omega) : WeakForm >(1) +CustomWeakFormAcoustics::CustomWeakFormAcoustics(std::string bdy_newton, double rho, double sound_speed, double omega) : WeakForm(1) { std::complex ii = std::complex(0.0, 1.0); // Jacobian. - add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion >(0, 0, HERMES_ANY, new Hermes1DFunction >(1.0/rho), HERMES_SYM)); - add_matrix_form(new WeakFormsH1::DefaultMatrixFormVol >(0, 0, HERMES_ANY, new Hermes2DFunction >(-sqr(omega) / rho / sqr(sound_speed)), HERMES_SYM)); - add_matrix_form_surf(new WeakFormsH1::DefaultMatrixFormSurf >(0, 0, bdy_newton, new Hermes2DFunction >(-ii * omega / rho / sound_speed))); + add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion(0, 0, HERMES_ANY, new Hermes1DFunction(1.0/rho), HERMES_SYM)); + add_matrix_form(new WeakFormsH1::DefaultMatrixFormVol(0, 0, HERMES_ANY, new Hermes2DFunction(-sqr(omega) / rho / sqr(sound_speed)), HERMES_SYM)); + add_matrix_form_surf(new WeakFormsH1::DefaultMatrixFormSurf(0, 0, bdy_newton, new Hermes2DFunction(-ii * omega / rho / sound_speed))); // Residual. - add_vector_form(new WeakFormsH1::DefaultResidualDiffusion >(0, HERMES_ANY, new Hermes1DFunction >(1.0/rho))); - add_vector_form(new WeakFormsH1::DefaultResidualVol >(0, HERMES_ANY, new Hermes2DFunction >(-sqr(omega) / rho / sqr(sound_speed)))); - add_vector_form_surf(new WeakFormsH1::DefaultResidualSurf >(0, bdy_newton, new Hermes2DFunction >(-ii * omega / rho / sound_speed))); + add_vector_form(new WeakFormsH1::DefaultResidualDiffusion(0, HERMES_ANY, new Hermes1DFunction(1.0/rho))); + add_vector_form(new WeakFormsH1::DefaultResidualVol(0, HERMES_ANY, new Hermes2DFunction(-sqr(omega) / rho / sqr(sound_speed)))); + add_vector_form_surf(new WeakFormsH1::DefaultResidualSurf(0, bdy_newton, new Hermes2DFunction(-ii * omega / rho / sound_speed))); } diff --git a/2d-advanced/acoustics/apartment/definitions.h b/2d-advanced/acoustics/apartment/definitions.h index 9aaba3c..f4996f5 100644 --- a/2d-advanced/acoustics/apartment/definitions.h +++ b/2d-advanced/acoustics/apartment/definitions.h @@ -7,9 +7,11 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +typedef std::complex complex; + /* Weak forms */ -class CustomWeakFormAcoustics : public WeakForm > +class CustomWeakFormAcoustics : public WeakForm { public: CustomWeakFormAcoustics(std::string bdy_newton, double rho, double sound_speed, double omega); diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index f2a7cb8..f3c2ae2 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -1,5 +1,3 @@ -#define HERMES_REPORT_ALL -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This problem describes the distribution of the vector potential in @@ -22,45 +20,16 @@ const int P_INIT = 2; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Name of the iterative method employed by AztecOO (ignored by the other solvers). -// Possibilities: gmres, cg, cgs, tfqmr, bicgstab. -const char* iterative_method = "bicgstab"; -// Name of the preconditioner employed by AztecOO (ignored by -// the other solvers). -// Possibilities: none, jacobi, neumann, least-squares, or a -// preconditioner from IFPACK (see solver/aztecoo.h) -const char* preconditioner = "least-squares"; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Problem parameters. const double RHO = 1.25; @@ -75,7 +44,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -88,22 +57,22 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions. - DefaultEssentialBCConst > bc_essential("Source", P_SOURCE); - EssentialBCs > bcs(&bc_essential); + DefaultEssentialBCConst bc_essential("Source", P_SOURCE); + EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); - int ndof = Space >::get_num_dofs(space); + SpaceSharedPtr space(new H1Space (mesh, &bcs, P_INIT)); + int ndof = Space::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormAcoustics wf("Wall", RHO, SOUND_SPEED, OMEGA); // Initialize coarse and reference mesh solution. - MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector > selector(CAND_LIST); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView sview("Acoustic pressure", new WinGeom(0, 0, 600, 350)); @@ -121,24 +90,24 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = Space >::get_num_dofs(ref_space); + int ndof_ref = Space::get_num_dofs(ref_space); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem > dp(&wf, ref_space); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + DiscreteProblem dp(&wf, ref_space); // Time measurement. cpu_time.tick(); // Perform Newton's iteration. - Hermes::Hermes2D::NewtonSolver > newton(&dp); + Hermes::Hermes2D::NewtonSolver newton(&dp); try { newton.solve(); @@ -148,12 +117,12 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln-> - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + // Translate the resulting coefficient vector into the Solution sln-> + Hermes::Hermes2D::Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); @@ -165,38 +134,30 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - // Error calculation. - DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); - // Stopping criterion for an adaptivity step. - AdaptStoppingCriterionCumulative stoppingCriterion(0.3); - - Adapt >* adaptivity = new Adapt >(space); - double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); + graph_dof.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); } - if (Space >::get_num_dofs(space) >= NDOF_STOP) done = true; - - delete adaptivity; - + // Increase counter. as++; } diff --git a/2d-advanced/acoustics/horn-axisym/definitions.cpp b/2d-advanced/acoustics/horn-axisym/definitions.cpp index c9c052f..2eade77 100644 --- a/2d-advanced/acoustics/horn-axisym/definitions.cpp +++ b/2d-advanced/acoustics/horn-axisym/definitions.cpp @@ -1,17 +1,17 @@ #include "definitions.h" CustomWeakFormAcoustics::CustomWeakFormAcoustics(std::string bdy_newton, double rho, - double sound_speed, double omega) : WeakForm >(1) + double sound_speed, double omega) : WeakForm(1) { std::complex ii = std::complex(0.0, 1.0); // Jacobian. - add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion >(0, 0, HERMES_ANY, new Hermes1DFunction >(1.0/rho), HERMES_SYM)); - add_matrix_form(new WeakFormsH1::DefaultMatrixFormVol >(0, 0, HERMES_ANY, new Hermes2DFunction >(-sqr(omega) / rho / sqr(sound_speed)), HERMES_SYM)); - add_matrix_form_surf(new WeakFormsH1::DefaultMatrixFormSurf >(0, 0, bdy_newton, new Hermes2DFunction >(-ii * omega / rho / sound_speed))); + add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion(0, 0, HERMES_ANY, new Hermes1DFunction(1.0/rho), HERMES_SYM)); + add_matrix_form(new WeakFormsH1::DefaultMatrixFormVol(0, 0, HERMES_ANY, new Hermes2DFunction(-sqr(omega) / rho / sqr(sound_speed)), HERMES_SYM)); + add_matrix_form_surf(new WeakFormsH1::DefaultMatrixFormSurf(0, 0, bdy_newton, new Hermes2DFunction(-ii * omega / rho / sound_speed))); // Residual. - add_vector_form(new WeakFormsH1::DefaultResidualDiffusion >(0, HERMES_ANY, new Hermes1DFunction >(1.0/rho))); - add_vector_form(new WeakFormsH1::DefaultResidualVol >(0, HERMES_ANY, new Hermes2DFunction >(-sqr(omega) / rho / sqr(sound_speed)))); - add_vector_form_surf(new WeakFormsH1::DefaultResidualSurf >(0, bdy_newton, new Hermes2DFunction >(-ii * omega / rho / sound_speed))); + add_vector_form(new WeakFormsH1::DefaultResidualDiffusion(0, HERMES_ANY, new Hermes1DFunction(1.0/rho))); + add_vector_form(new WeakFormsH1::DefaultResidualVol(0, HERMES_ANY, new Hermes2DFunction(-sqr(omega) / rho / sqr(sound_speed)))); + add_vector_form_surf(new WeakFormsH1::DefaultResidualSurf(0, bdy_newton, new Hermes2DFunction(-ii * omega / rho / sound_speed))); } diff --git a/2d-advanced/acoustics/horn-axisym/definitions.h b/2d-advanced/acoustics/horn-axisym/definitions.h index c71e029..48cb5f6 100644 --- a/2d-advanced/acoustics/horn-axisym/definitions.h +++ b/2d-advanced/acoustics/horn-axisym/definitions.h @@ -7,9 +7,11 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +typedef std::complex complex; + /* Weak forms */ -class CustomWeakFormAcoustics : public WeakForm > +class CustomWeakFormAcoustics : public WeakForm { public: CustomWeakFormAcoustics(std::string bdy_newton, double rho, diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index 9451ecc..fc8d1e0 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -1,5 +1,3 @@ -#define HERMES_REPORT_ALL -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This problem describes the distribution of the vector potential in @@ -23,44 +21,16 @@ const int P_INIT = 2; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Name of the iterative method employed by AztecOO (ignored by the other solvers). -// Possibilities: gmres, cg, cgs, tfqmr, bicgstab. -const char* iterative_method = "bicgstab"; -// Name of the preconditioner employed by AztecOO (ignored by the other solvers). -// Possibilities: none, jacobi, neumann, least-squares, or a -// preconditioner from IFPACK (see solver/aztecoo.h) -const char* preconditioner = "least-squares"; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Problem parameters. const double RHO = 1.25; @@ -75,7 +45,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -88,22 +58,23 @@ int main(int argc, char* argv[]) for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Initialize boundary conditions. - DefaultEssentialBCConst > bc_essential("Source", P_SOURCE); - EssentialBCs > bcs(&bc_essential); + DefaultEssentialBCConst bc_essential("Source", P_SOURCE); + EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); - int ndof = Space >::get_num_dofs(space); + SpaceSharedPtr space(new H1Space (mesh, &bcs, P_INIT)); + adaptivity.set_space(space); + int ndof = Space::get_num_dofs(space); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormAcoustics wf("Outlet", RHO, SOUND_SPEED, OMEGA); // Initialize coarse and reference mesh solution. - MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - H1ProjBasedSelector > selector(CAND_LIST); + H1ProjBasedSelector selector(CAND_LIST); // Initialize views. ScalarView sview_real("Solution - real part", new WinGeom(0, 0, 330, 350)); @@ -124,23 +95,23 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = Space >::get_num_dofs(ref_space); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = Space::get_num_dofs(ref_space); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); - DiscreteProblem > dp(&wf, ref_space); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + DiscreteProblem dp(&wf, ref_space); // Time measurement. cpu_time.tick(); // Perform Newton's iteration. - Hermes::Hermes2D::NewtonSolver > newton(&dp); + Hermes::Hermes2D::NewtonSolver newton(&dp); try { newton.solve(); @@ -150,12 +121,12 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln-> - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + // Translate the resulting coefficient vector into the Solution sln-> + Hermes::Hermes2D::Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); - OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. cpu_time.tick(); @@ -167,32 +138,28 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt >* adaptivity = new Adapt >(space); - double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); + graph_dof.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); } - if (Space >::get_num_dofs(space) >= NDOF_STOP) done = true; - - delete adaptivity; // Increase counter. as++; diff --git a/2d-advanced/acoustics/wave-propagation/acoustic.xml b/2d-advanced/acoustics/wave-propagation/acoustic.xml new file mode 100644 index 0000000..cad1d1d --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/acoustic.xml @@ -0,0 +1,189 @@ + + + + + Acoustics is the interdisciplinary science that deals with the study of all mechanical waves in gases, liquids and solids. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/acoustics/wave-propagation/definitions.cpp b/2d-advanced/acoustics/wave-propagation/definitions.cpp new file mode 100644 index 0000000..5090542 --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/definitions.cpp @@ -0,0 +1,266 @@ +#include "definitions.h" + +template +volume_matrix_acoustic_transient_planar_linear_form_1_1::volume_matrix_acoustic_transient_planar_linear_form_1_1(unsigned int i, unsigned int j, double ac_rho, double ac_vel) + : MatrixFormVol(i, j), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + +template +Scalar volume_matrix_acoustic_transient_planar_linear_form_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (u->dx[i]*v->dx[i]+u->dy[i]*v->dy[i]); + } + return result / this->ac_rho; +} + +template +Hermes::Ord volume_matrix_acoustic_transient_planar_linear_form_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (u->dx[i]*v->dx[i]+u->dy[i]*v->dy[i]); + } + return result; +} + +template +MatrixFormVol* volume_matrix_acoustic_transient_planar_linear_form_1_1::clone() const +{ + return new volume_matrix_acoustic_transient_planar_linear_form_1_1(*this); +} + +template +volume_matrix_acoustic_transient_planar_linear_form_1_2::volume_matrix_acoustic_transient_planar_linear_form_1_2(unsigned int i, unsigned int j, double ac_rho, double ac_vel) + : MatrixFormVol(i, j), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + + +template +Scalar volume_matrix_acoustic_transient_planar_linear_form_1_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] *u->val[i] * v->val[i]; + } + return result / (ac_rho * ac_vel *ac_vel * this->wf->get_current_time_step()); +} + +template +Hermes::Ord volume_matrix_acoustic_transient_planar_linear_form_1_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return result; +} + +template +MatrixFormVol* volume_matrix_acoustic_transient_planar_linear_form_1_2::clone() const +{ + return new volume_matrix_acoustic_transient_planar_linear_form_1_2(*this); +} + +template +volume_matrix_acoustic_transient_planar_linear_form_2_2::volume_matrix_acoustic_transient_planar_linear_form_2_2(unsigned int i, unsigned int j, double ac_rho, double ac_vel) + : MatrixFormVol(i, j), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + + +template +Scalar volume_matrix_acoustic_transient_planar_linear_form_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return -result; +} + +template +Hermes::Ord volume_matrix_acoustic_transient_planar_linear_form_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return -result; +} + +template +MatrixFormVol* volume_matrix_acoustic_transient_planar_linear_form_2_2::clone() const +{ + return new volume_matrix_acoustic_transient_planar_linear_form_2_2(*this); +} + +template +volume_matrix_acoustic_transient_planar_linear_form_2_1::volume_matrix_acoustic_transient_planar_linear_form_2_1(unsigned int i, unsigned int j, double ac_rho, double ac_vel) + : MatrixFormVol(i, j), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + +template +Scalar volume_matrix_acoustic_transient_planar_linear_form_2_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return result / this->wf->get_current_time_step(); +} + +template +Hermes::Ord volume_matrix_acoustic_transient_planar_linear_form_2_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return result; +} + +template +MatrixFormVol* volume_matrix_acoustic_transient_planar_linear_form_2_1::clone() const +{ + return new volume_matrix_acoustic_transient_planar_linear_form_2_1(*this); +} + +template +volume_vector_acoustic_transient_planar_linear_form_1_2::volume_vector_acoustic_transient_planar_linear_form_1_2(unsigned int i, double ac_rho, double ac_vel) + : VectorFormVol(i), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + +template +Scalar volume_vector_acoustic_transient_planar_linear_form_1_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * v->val[i] * ext[1]->val[i]; + } + return result / (ac_rho * ac_vel * ac_vel * this->wf->get_current_time_step()); +} + +template +Hermes::Ord volume_vector_acoustic_transient_planar_linear_form_1_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * v->val[i] * ext[1]->val[i]; + } + return result; +} + +template +VectorFormVol* volume_vector_acoustic_transient_planar_linear_form_1_2::clone() const +{ + return new volume_vector_acoustic_transient_planar_linear_form_1_2(*this); +} + +template +volume_vector_acoustic_transient_planar_linear_form_2_1::volume_vector_acoustic_transient_planar_linear_form_2_1(unsigned int i, double ac_rho, double ac_vel) + : VectorFormVol(i), ac_rho(ac_rho), ac_vel(ac_vel) +{ +} + +template +Scalar volume_vector_acoustic_transient_planar_linear_form_2_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * v->val[i] * ext[0]->val[i]; + } + return result / this->wf->get_current_time_step(); +} + +template +Hermes::Ord volume_vector_acoustic_transient_planar_linear_form_2_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * v->val[i] * ext[0]->val[i]; + } + return result; +} + +template +VectorFormVol* volume_vector_acoustic_transient_planar_linear_form_2_1::clone() const +{ + return new volume_vector_acoustic_transient_planar_linear_form_2_1(*this); +} + +template +surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance::surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance(unsigned int i, unsigned int j) + : MatrixFormSurf(i, j) +{ +} + +template +Scalar surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return result / ac_Z0; +} + +template +Hermes::Ord surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * u->val[i] * v->val[i]; + } + return result; + +} + +template +MatrixFormSurf* surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance::clone() const +{ + return new surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance(*this); +} + +template class volume_matrix_acoustic_transient_planar_linear_form_1_1; +template class volume_matrix_acoustic_transient_planar_linear_form_1_2; +template class volume_matrix_acoustic_transient_planar_linear_form_2_2; +template class volume_matrix_acoustic_transient_planar_linear_form_2_1; +template class volume_vector_acoustic_transient_planar_linear_form_1_2; +template class volume_vector_acoustic_transient_planar_linear_form_2_1; +template class surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance; \ No newline at end of file diff --git a/2d-advanced/acoustics/wave-propagation/definitions.h b/2d-advanced/acoustics/wave-propagation/definitions.h new file mode 100644 index 0000000..6c215e4 --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/definitions.h @@ -0,0 +1,298 @@ +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; + +#pragma region forms + +template +class volume_matrix_acoustic_transient_planar_linear_form_1_1 : public MatrixFormVol +{ +public: + volume_matrix_acoustic_transient_planar_linear_form_1_1(unsigned int i, unsigned int j, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + MatrixFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class volume_matrix_acoustic_transient_planar_linear_form_1_2 : public MatrixFormVol +{ +public: + volume_matrix_acoustic_transient_planar_linear_form_1_2(unsigned int i, unsigned int j, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + MatrixFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class volume_matrix_acoustic_transient_planar_linear_form_2_2 : public MatrixFormVol +{ +public: + volume_matrix_acoustic_transient_planar_linear_form_2_2(unsigned int i, unsigned int j, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + MatrixFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class volume_matrix_acoustic_transient_planar_linear_form_2_1 : public MatrixFormVol +{ +public: + volume_matrix_acoustic_transient_planar_linear_form_2_1(unsigned int i, unsigned int j, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + MatrixFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class volume_vector_acoustic_transient_planar_linear_form_1_2 : public VectorFormVol +{ +public: + volume_vector_acoustic_transient_planar_linear_form_1_2(unsigned int i, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + VectorFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class volume_vector_acoustic_transient_planar_linear_form_2_1 : public VectorFormVol +{ +public: + volume_vector_acoustic_transient_planar_linear_form_2_1(unsigned int i, double ac_rho, double ac_vel); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + VectorFormVol* clone() const; + + double ac_rho; + double ac_vel; + +}; + +template +class surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance : public MatrixFormSurf +{ +public: + surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance(unsigned int i, unsigned int j); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + MatrixFormSurf* clone() const; + + double ac_Z0; +}; + +#pragma endregion + +class MyWeakForm : public WeakForm +{ +public: + MyWeakForm( + Hermes::vector acoustic_impedance_markers, + Hermes::vector acoustic_impedance_values, + Hermes::vector > prev_slns + ) : WeakForm(2), acoustic_impedance_markers(acoustic_impedance_markers), acoustic_impedance_values(acoustic_impedance_values), prev_slns(prev_slns) + { + this->set_ext(prev_slns); + + double acoustic_density = 1.25; + double acoustic_speed = 343.; + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_1_1(0, 0, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_1_2(0, 1, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_2_1(1, 0, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_2_2(1, 1, acoustic_density, acoustic_speed)); + + this->add_vector_form(new volume_vector_acoustic_transient_planar_linear_form_1_2(0, acoustic_density, acoustic_speed)); + this->add_vector_form(new volume_vector_acoustic_transient_planar_linear_form_2_1(1, acoustic_density, acoustic_speed)); + + for(int i = 0; i < acoustic_impedance_markers.size(); i++) + { + surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance* matrix_form = new surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance(0, 1); + matrix_form->set_area(acoustic_impedance_markers[i]); + matrix_form->ac_Z0 = acoustic_impedance_values[i]; + this->add_matrix_form_surf(matrix_form); + } + } + + MyWeakForm( + std::string acoustic_impedance_marker, + double acoustic_impedance_value, + Hermes::vector > prev_slns + ) : WeakForm(2), prev_slns(prev_slns) + { + this->set_ext(prev_slns); + + double acoustic_density = 1.25; + double acoustic_speed = 343.; + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_1_1(0, 0, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_1_2(0, 1, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_2_1(1, 0, acoustic_density, acoustic_speed)); + this->add_matrix_form(new volume_matrix_acoustic_transient_planar_linear_form_2_2(1, 1, acoustic_density, acoustic_speed)); + + this->add_vector_form(new volume_vector_acoustic_transient_planar_linear_form_1_2(0, acoustic_density, acoustic_speed)); + this->add_vector_form(new volume_vector_acoustic_transient_planar_linear_form_2_1(1, acoustic_density, acoustic_speed)); + + surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance* matrix_form = new surface_matrix_acoustic_transient_planar_linear_form_1_2_acoustic_impedance(0, 1); + matrix_form->set_area(acoustic_impedance_marker); + matrix_form->ac_Z0 = acoustic_impedance_value; + this->add_matrix_form_surf(matrix_form); + } + + Hermes::vector acoustic_impedance_markers; + Hermes::vector acoustic_impedance_values; + Hermes::vector > prev_slns; +}; + +class CustomBCValue : public EssentialBoundaryCondition +{ +public: + CustomBCValue(Hermes::vector markers, double amplitude = 1., double frequency = 1000.) + : EssentialBoundaryCondition(markers), amplitude(amplitude), frequency(frequency) + { + } + + CustomBCValue(std::string marker, double amplitude = 1., double frequency = 1000.) + : EssentialBoundaryCondition(marker), amplitude(amplitude), frequency(frequency) + { + } + + inline EssentialBoundaryCondition::EssentialBCValueType get_value_type() const { return EssentialBoundaryCondition::BC_FUNCTION; } + + virtual double value(double x, double y, double n_x, double n_y, double t_x, double t_y) const + { + if(this->frequency * this->current_time >= 1.) + return 0.; + else + return this->amplitude * std::sin(2 * M_PI * this->frequency * this->current_time); + } + + double amplitude; + double frequency; +}; + +class CustomBCDerivative : public EssentialBoundaryCondition +{ +public: + CustomBCDerivative(Hermes::vector markers, double amplitude = 1., double frequency = 1000.) + : EssentialBoundaryCondition(markers), amplitude(amplitude), frequency(frequency) + { + } + + CustomBCDerivative(std::string marker, double amplitude = 1., double frequency = 1000.) + : EssentialBoundaryCondition(marker), amplitude(amplitude), frequency(frequency) + { + } + + inline EssentialBoundaryCondition::EssentialBCValueType get_value_type() const { return EssentialBoundaryCondition::BC_FUNCTION; } + + virtual double value(double x, double y, double n_x, double n_y, double t_x, double t_y) const + { + if(this->frequency * this->current_time >= 1.) + return 0.; + else + return 2 * M_PI * this->frequency * this->amplitude * std::cos(2 * M_PI * this->frequency * this->current_time); + } + + double amplitude; + double frequency; +}; + + +template +class exact_acoustic_transient_planar_linear_form_1_0_acoustic_pressure : public ExactSolutionScalar +{ +public: + exact_acoustic_transient_planar_linear_form_1_0_acoustic_pressure(MeshSharedPtr mesh, double amplitude, double frequency) : ExactSolutionScalar(mesh), amplitude(amplitude), frequency(frequency) + { + + } + + Scalar value(double x, double y) const + { + return this->amplitude * std::sin(2 * M_PI * this->frequency * this->time); + } + + void derivatives (double x, double y, Scalar& dx, Scalar& dy) const {}; + + Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const + { + return Hermes::Ord(Hermes::Ord::get_max_order()); + } + + double amplitude; + double frequency; + double time; +}; + + +template +class exact_acoustic_transient_planar_linear_form_2_0_acoustic_pressure : public ExactSolutionScalar +{ +public: + exact_acoustic_transient_planar_linear_form_2_0_acoustic_pressure(MeshSharedPtr mesh, double amplitude, double frequency) : ExactSolutionScalar(mesh), amplitude(amplitude), frequency(frequency) + { + + } + + Scalar value(double x, double y) const + { + return 2 * M_PI * this->frequency * this->amplitude * std::cos(2 * M_PI * this->frequency * this->time); + } + + void derivatives (double x, double y, Scalar& dx, Scalar& dy) const {}; + + Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const + { + return Hermes::Ord(Hermes::Ord::get_max_order()); + } + + double amplitude; + double frequency; + double time; +}; \ No newline at end of file diff --git a/2d-advanced/acoustics/wave-propagation/domain.mesh b/2d-advanced/acoustics/wave-propagation/domain.mesh new file mode 100644 index 0000000..bdfea08 --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/domain.mesh @@ -0,0 +1 @@ +01245678910111213161718192021222324262728303233343537394345484952535456586061626364656667686970717273757677787981828384868789919293959698100101102104105106107108109110111113117118119120121122123124125126128129130132133135137138139140141142143146147149150151152155156159160161163164165167168169170171172174175176177184185187192193194195196200201202203204206209213215216218219220221222225226227230231232236237238241246247249250251252253255256259261262264265266267269271273275276277278280281282283285286288289294295296298301302303305307308309310311312314315319321322324328329331332333334335336337339340341342343345347349350351352353357358360363364365366367368373374376377380382383384387389390392394395397398399402403405406407408409410411413414415418419423424425426427428431432433435437439440442447448449450451453454455456457458461463465467469470471473476477479480481486487489491492493494495497500503504506509510511515518519520521523525526527531534535537538539540545546547549550551553554556558559560562563565567568569570572573574578579581582586587589590593595596597598599600601602603604605606607608610611612613614616617618619620622624625626631632634638641642643644645646650652655657658659660664665667668670671672673676678679682684685687688690691697698699700701702703704708709710713714715717718719720723726727729734738739740742743744747748751752753754755756757758759761762763766767770772773774775776777778781782783785786788790792793794797798799800804805810812813818819820822826827828830831832836837840842843844851854855856859862863864865866871874877880881892893894895897898903904906907908911912914918919920922923924925929931932933934936938939940941942943944945946947950953955956957958960961962963964965966967968971972974975976977979982984986988989990991992993994995996998999100010011002100410061009101110121015101610211023102410251026102710281029103110331035103610391043104410451050105410551056105910601064106610681069107010741075107710801084108910901094109610971098110311041106110711091111111211131115111711201123112411251126112711281130113111321133113511371142114411461151115211551156115711581160116111621165117111721173117411761178117911811182118311841185118711881189119111921195119812011202120512061207120812101212121312141215121712181219122212251226122712301231123212331237123812391240124112421246124712481249125112541255125712601261126212631264126512711272127312751276127712781282128312841286128712881289129112921293129412971298129913021306130713091314131513171319132013221323132413261327132813291330133213331334133613371341134313441347134813491350135413551356135713581360136313661369137013731376137713791381138213831384138513901395139713981400140114021406140814091410141314141417142014221423142414251431143414351436143714381444144514461447145014521453145514571458146014631464146514671470147114721473147914801483148414871489149014961497149915011506150715091511151615201521152215271528153215351536153815391543154415451547154915511552155615571559156015611562156315641565156615681569157215731574157515761579158115841585158815891591159215981599160016011602160316041605160716081611161316151617161816201621162316241625162616301631163216331636163816411643164416461647164816491650165216531654165616591660166116621663166416651666166916701673167416751676167816791680168116821684168516871688169116951696169816991700170117021703170417061707170817091710171117131714171517171719172017221727173017331734173517371738173917451749175117521753175617591760176317661768176917701771177317751776177817791782178417851788179017911792179317941795179717981799180018021803180418051808180918101811181218131815181618171818181918201823182418261830183118321834183618371840184618471848185018511852185318541859186018611865186718681869187118721873187518781879188018821883188418861887188818891890189218931894189518971898190019021903190519061907190819101913191419151916191919201923192519281929193019311935193619371940194119421943194519461947195019511955195819591961196219631964196819691973197419751976197719781981198219831986199019921993199619981999200120022004200820092011201220132015201620172019202220232028202920322034203920402041204320442045204620492050205520562057205820592060206120632064206520662068206920702074207620772078207920802087208820912092209420952099210521072108211021112112211921252130213121332134213721382142214321452149215121562159216021622512313255637384939496991783463593985726708088518969579699771058106410691077112911381194119512071247126412731320135014181421148814891492153215351569161116121661168116941701171317301747175617601779180918161843184518631869188119061935194719531957199720062013201620222095210521082122217822512261226522742282230323052309231023112366236923742375238223912395239823992415242224262436244324772519254525632566258926732680271627302738274427572760277327792782279328012819285628862889291629222983299629983001307531223141314431543156316031933194320032333235323832393248326032703272327933023308331133133316332333263327 \ No newline at end of file diff --git a/2d-advanced/acoustics/wave-propagation/domain_apartment.mesh b/2d-advanced/acoustics/wave-propagation/domain_apartment.mesh new file mode 100644 index 0000000..fe5f83c --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/domain_apartment.mesh @@ -0,0 +1,752 @@ +vertices = +{ + { 1.9500000000, 0.2750000000 }, + { 3.6300000000, 0.2750000000 }, + { 9.9500000000, 3.3750000000 }, + { 12.7700000000, 3.3750000000 }, + { 0.2750000000, 3.0000000000 }, + { 0.2750000000, 7.6000000000 }, + { 6.3250000000, 8.0000000000 }, + { 6.3250000000, 8.5000000000 }, + { 0.4500000000, 0.4500000000 }, + { 8.2500000000, 3.5500000000 }, + { 13.6500000000, 3.5500000000 }, + { 6.1500000000, 8.5500000000 }, + { 13.6500000000, 7.0500000000 }, + { 0.4500000000, 8.5500000000 }, + { 0.4500000000, 3.0000000000 }, + { 0.4500000000, 7.6000000000 }, + { 6.1500000000, 8.0000000000 }, + { 6.1500000000, 8.5000000000 }, + { 1.9500000000, 0.4500000000 }, + { 3.6300000000, 0.4500000000 }, + { 7.1500000000, 1.7500000000 }, + { 8.1500000000, 1.7500000000 }, + { 9.9500000000, 3.5500000000 }, + { 12.7700000000, 3.5500000000 }, + { 6.1500000000, 0.4500000000 }, + { 4.1000000000, 8.5500000000 }, + { 4.4000000000, 8.5500000000 }, + { 4.1000000000, 7.0500000000 }, + { 4.4000000000, 7.3500000000 }, + { 5.3500000000, 7.3500000000 }, + { 5.3500000000, 7.0500000000 }, + { 6.1500000000, 5.1000000000 }, + { 8.2500000000, 3.2500000000 }, + { 6.1500000000, 3.2500000000 }, + { 6.4500000000, 7.0500000000 }, + { 6.4500000000, 5.1000000000 }, + { 6.1500000000, 5.8500000000 }, + { 6.4500000000, 5.8500000000 }, + { 10.7700000000, 3.3750000000 }, + { 10.7700000000, 3.5500000000 }, + { 11.9500000000, 3.3750000000 }, + { 11.9500000000, 3.5500000000 }, + { 11.1000000000, 3.5500000000 }, + { 11.4000000000, 3.5500000000 }, + { 11.1000000000, 6.5500000000 }, + { 11.4000000000, 6.5500000000 }, + { 0.2750000000, 6.5000000000 }, + { 0.4500000000, 6.5000000000 }, + { 0.2750000000, 4.1000000000 }, + { 0.4500000000, 4.1000000000 }, + { 6.1500000000, 2.6000000000 }, + { 6.4500000000, 2.6000000000 }, + { 6.4500000000, 1.7500000000 }, + { 8.2500000000, 1.7500000000 }, + { 7.1500000000, 1.5750000000 }, + { 8.1500000000, 1.5750000000 }, + { 4.1000000000, 6.4000000000 }, + { 4.1000000000, 3.8000000000 }, + { 4.1000000000, 3.0000000000 }, + { 4.1000000000, 2.8000000000 }, + { 0.4500000000, 2.8000000000 }, + { 1.0000000000, 2.8000000000 }, + { 1.8000000000, 2.8000000000 }, + { 4.1000000000, 2.5000000000 }, + { 1.0000000000, 2.5000000000 }, + { 1.8000000000, 2.5000000000 }, + { 0.4500000000, 2.5000000000 }, + { 4.1000000000, 0.4500000000 }, + { 4.4000000000, 6.4000000000 }, + { 4.4000000000, 3.8000000000 }, + { 4.4000000000, 3.0000000000 }, + { 4.4000000000, 0.4500000000 }, + { 0.6000000000, 6.4000000000 }, + { 0.8000000000, 6.4000000000 }, + { 0.8000000000, 5.8000000000 }, + { 0.6000000000, 5.8000000000 }, + { 10.0500000000, 7.0500000000 }, + { 0.4500000000, 5.3000000000 }, + { 11.8500000000, 7.0500000000 }, + { 0.4500000000, 5.9000000000 }, + { 10.9500000000, 7.0500000000 }, + { 5.1500000000, 8.5500000000 }, + { 5.6500000000, 8.5500000000 }, + { 5.9000000000, 8.5500000000 }, + { 6.0250000000, 8.5500000000 }, + { 6.0875000000, 8.5500000000 }, + { 6.0562500000, 8.4468750000 }, + { 8.2500000000, 2.7500000000 }, + { 8.2500000000, 2.2500000000 }, + { 8.2500000000, 2.0000000000 }, + { 8.2500000000, 1.8750000000 }, + { 6.3250000000, 8.2500000000 }, + { 6.1812276253, 8.3356093377 }, + { 8.0437500000, 1.9375000000 }, + { 0.2750000000, 3.6000000000 }, + { 2.9500000000, 0.2750000000 }, + { 0.2750000000, 7.0000000000 }, + { 10.2700000000, 3.3750000000 }, + { 12.2700000000, 3.3750000000 }, + { 5.9386197508, 8.1889259093 }, + { 6.1779964338, 8.1666524963 }, + { 7.6500000000, 1.5750000000 }, + { 0.2750000000, 3.2500000000 }, + { 0.2750000000, 3.8500000000 }, + { 3.3800000000, 0.2750000000 }, + { 2.4500000000, 0.2750000000 }, + { 0.2750000000, 7.3500000000 }, + { 0.2750000000, 6.7500000000 }, + { 10.0750000000, 3.3750000000 }, + { 10.5200000000, 3.3750000000 }, + { 12.0750000000, 3.3750000000 }, + { 12.5200000000, 3.3750000000 }, + { 7.9000000000, 1.5750000000 }, + { 7.4000000000, 1.5750000000 }, + { 2.2000000000, 0.2750000000 }, + { 0.7000000000, 2.8000000000 }, + { 3.1000000000, 2.8000000000 }, + { 0.7000000000, 5.4975000000 }, + { 0.4500000000, 6.2000000000 }, + { 0.6000000000, 6.1000000000 }, + { 0.7000000000, 6.7125000000 }, + { 0.4500000000, 5.6000000000 }, + { 10.1725000000, 3.5767857143 }, + { 12.1725000000, 3.5767857143 }, + { 3.6000000000, 2.8000000000 }, + { 3.8500000000, 2.8000000000 }, + { 10.0137663179, 3.9578239769 }, + { 11.4000000000, 4.3000000000 }, + { 6.1500000000, 6.9250000000 }, + { 0.7181810334, 3.7250000000 }, + { 7.7750000000, 1.8343211207 }, + { 2.3250000000, 0.7181810334 }, + { 0.5001838235, 6.8750000000 }, + { 3.7250000000, 3.2125000000 }, + { 7.7264673106, 2.3623301712 }, + { 7.5250000000, 1.7950407806 }, + { 0.8881595835, 7.1479689583 }, + { 0.5194286465, 7.1750000000 }, + { 7.6075019166, 2.0851603006 }, + { 1.4000000000, 2.6500000000 }, + { 4.2500000000, 3.4000000000 }, + { 4.7250000000, 7.0500000000 }, + { 6.6750000000, 3.2500000000 }, + { 11.4000000000, 7.0500000000 }, + { 6.3000000000, 5.4750000000 }, + { 3.1947732766, 0.8056810334 }, + { 0.8500000000, 3.2437500000 }, + { 0.4500000000, 4.7000000000 }, + { 11.1000000000, 5.0500000000 }, + { 12.4774568654, 3.7018473351 }, + { 6.1500000000, 7.4625000000 }, + { 1.2725881642, 6.7234782125 }, + { 7.2000000000, 3.2500000000 }, + { 7.3085709464, 2.0133775639 }, + { 1.2862490504, 5.4714775866 }, + { 12.5113620668, 6.0022741399 }, + { 5.7196800295, 7.7312500000 }, + { 6.8606449022, 2.1036351139 }, + { 10.4774568654, 3.7018473351 }, + { 11.1000000000, 4.3000000000 }, + { 10.8079771571, 3.9808900509 }, + { 9.1000000000, 3.5500000000 }, + { 3.8229166667, 6.7250000000 }, + { 4.2500000000, 6.7250000000 }, + { 5.8729166667, 2.9250000000 }, + { 7.3873141064, 2.3437839400 }, + { 7.7250000000, 3.2500000000 }, + { 5.7562500000, 5.4750000000 }, + { 6.8437500000, 5.4750000000 }, + { 9.5250000000, 3.8253490750 }, + { 4.6175000000, 6.6975000000 }, + { 6.3000000000, 2.9250000000 }, + { 4.4000000000, 5.1000000000 }, + { 5.0375000000, 6.7620567376 }, + { 6.6565476190, 2.8924450549 }, + { 6.8655036072, 2.5257013724 }, + { 1.6620890099, 1.2488620668 }, + { 1.4000000000, 2.0416666667 }, + { 4.8583333333, 3.4000000000 }, + { 4.1000000000, 1.4750000000 }, + { 1.3674080141, 3.1714213710 }, + { 1.1136128915, 4.2911876205 }, + { 5.7077780331, 6.7172794118 }, + { 5.7790039062, 7.2000000000 }, + { 10.3909383956, 4.6557016497 }, + { 2.2750000000, 8.5500000000 }, + { 4.1000000000, 5.1000000000 }, + { 4.4000000000, 1.7250000000 }, + { 6.1500000000, 4.1750000000 }, + { 4.1000000000, 0.9500000000 }, + { 6.1500000000, 6.3875000000 }, + { 10.5000000000, 6.6425000000 }, + { 0.8900125000, 5.0000000000 }, + { 1.3523463070, 6.1000000000 }, + { 7.5321304793, 2.8058450612 }, + { 7.3500000000, 4.3250000000 }, + { 8.2500000000, 7.0500000000 }, + { 8.8243820496, 4.4410822943 }, + { 5.6004416797, 6.0328174863 }, + { 0.4500000000, 1.4750000000 }, + { 2.2421316351, 3.7525769389 }, + { 5.4000000000, 8.1163835824 }, + { 3.3853229899, 7.3786923120 }, + { 4.8992017359, 6.2632936889 }, + { 3.5940323686, 1.2125000000 }, + { 6.9000000000, 4.7125000000 }, + { 7.3116465501, 6.3605101276 }, + { 9.5791538937, 4.5934376401 }, + { 0.4500000000, 2.0000000000 }, + { 4.4000000000, 7.9500000000 }, + { 1.8240117811, 7.6091791745 }, + { 2.9500000000, 2.5000000000 }, + { 7.6708963956, 5.1526942013 }, + { 0.9374269006, 1.7375000000 }, + { 2.7813106820, 1.6107896296 }, + { 3.5174362754, 1.9790138700 }, + { 0.9966719924, 1.0436970736 }, + { 11.4000000000, 5.0500000000 }, + { 6.1500000000, 1.5250000000 }, + { 5.5247716283, 3.5024316139 }, + { 11.1000000000, 5.8000000000 }, + { 1.5751355464, 4.8264529735 }, + { 2.3630526596, 5.6759744646 }, + { 3.1657926727, 3.9828716983 }, + { 5.3340773810, 4.6375000000 }, + { 4.4000000000, 5.7500000000 }, + { 5.0724842512, 5.5846808527 }, + { 9.5526149156, 6.0485241399 }, + { 4.8872782441, 8.1096521948 }, + { 1.1355259634, 7.8261168361 }, + { 2.0946756256, 1.8391164237 }, + { 2.1208140177, 6.5151464697 }, + { 5.0201414771, 4.0479919703 }, + { 5.0087456179, 2.7650657850 }, + { 12.8929118683, 4.1445219423 }, + { 3.3853229899, 6.0713076880 }, + { 10.4273057625, 5.4250000000 }, + { 9.0414626674, 5.3114160861 }, + { 5.5317905993, 2.3535525088 }, + { 12.0137663179, 3.9578239769 }, + { 12.0113283829, 4.6750000000 }, + { 13.6500000000, 5.3000000000 }, + { 12.0472193373, 5.4193062800 }, + { 12.8129218419, 5.0093651019 }, + { 11.4000000000, 5.8000000000 }, + { 8.6030003702, 6.1612554517 } +} + +elements = +{ + { 239, 41, 123, "elt"}, + { 213, 177, 64, "elt"}, + { 65, 62, 139, "elt"}, + { 131, 176, 18, "elt"}, + { 18, 176, 216, "elt"}, + { 91, 92, 100, "elt"}, + { 132, 47, 120, "elt"}, + { 125, 133, 124, "elt"}, + { 94, 102, 129, "elt"}, + { 146, 115, 61, "elt"}, + { 64, 177, 139, "elt"}, + { 103, 129, 49, "elt"}, + { 15, 5, 106, "elt"}, + { 14, 115, 146, "elt"}, + { 85, 84, 86, "elt"}, + { 132, 120, 136, "elt"}, + { 234, 10, 241, "elt"}, + { 104, 1, 19, "elt"}, + { 114, 105, 131, "elt"}, + { 14, 60, 115, "elt"}, + { 145, 19, 204, "elt"}, + { 145, 131, 95, "elt"}, + { 105, 95, 131, "elt"}, + { 215, 214, 204, "elt"}, + { 21, 53, 90, "elt"}, + { 183, 29, 30, "elt"}, + { 90, 89, 93, "elt"}, + { 156, 99, 201, "elt"}, + { 238, 164, 233, "elt"}, + { 58, 70, 140, "elt"}, + { 145, 104, 19, "elt"}, + { 58, 125, 59, "elt"}, + { 126, 160, 184, "elt"}, + { 114, 131, 18, "elt"}, + { 95, 104, 145, "elt"}, + { 223, 57, 186, "elt"}, + { 75, 117, 74, "elt"}, + { 4, 14, 102, "elt"}, + { 129, 181, 49, "elt"}, + { 72, 47, 118, "elt"}, + { 121, 117, 75, "elt"}, + { 79, 75, 119, "elt"}, + { 22, 122, 126, "elt"}, + { 107, 46, 47, "elt"}, + { 96, 107, 132, "elt"}, + { 132, 107, 47, "elt"}, + { 210, 229, 136, "elt"}, + { 151, 136, 120, "elt"}, + { 133, 125, 58, "elt"}, + { 41, 239, 43, "elt"}, + { 120, 72, 73, "elt"}, + { 161, 22, 169, "elt"}, + { 184, 159, 148, "elt"}, + { 74, 117, 154, "elt"}, + { 79, 119, 118, "elt"}, + { 57, 133, 140, "elt"}, + { 41, 40, 110, "elt"}, + { 154, 193, 74, "elt"}, + { 147, 181, 192, "elt"}, + { 185, 202, 25, "elt"}, + { 210, 136, 151, "elt"}, + { 111, 23, 149, "elt"}, + { 163, 162, 56, "elt"}, + { 99, 100, 92, "elt"}, + { 81, 228, 201, "elt"}, + { 106, 96, 137, "elt"}, + { 170, 141, 163, "elt"}, + { 182, 183, 30, "elt"}, + { 224, 232, 188, "elt"}, + { 15, 106, 137, "elt"}, + { 147, 192, 77, "elt"}, + { 123, 98, 149, "elt"}, + { 69, 140, 178, "elt"}, + { 58, 140, 133, "elt"}, + { 71, 218, 187, "elt"}, + { 49, 48, 103, "elt"}, + { 39, 158, 109, "elt"}, + { 18, 0, 114, "elt"}, + { 20, 54, 113, "elt"}, + { 130, 112, 21, "elt"}, + { 219, 233, 164, "elt"}, + { 51, 171, 50, "elt"}, + { 138, 135, 130, "elt"}, + { 135, 101, 130, "elt"}, + { 55, 21, 112, "elt"}, + { 50, 171, 164, "elt"}, + { 153, 157, 20, "elt"}, + { 90, 93, 21, "elt"}, + { 92, 91, 7, "elt"}, + { 174, 142, 171, "elt"}, + { 166, 194, 87, "elt"}, + { 128, 183, 182, "elt"}, + { 109, 38, 39, "elt"}, + { 99, 92, 86, "elt"}, + { 6, 100, 16, "elt"}, + { 138, 93, 134, "elt"}, + { 72, 120, 47, "elt"}, + { 143, 44, 45, "elt"}, + { 158, 97, 109, "elt"}, + { 118, 119, 72, "elt"}, + { 99, 83, 82, "elt"}, + { 108, 97, 122, "elt"}, + { 23, 111, 3, "elt"}, + { 158, 160, 126, "elt"}, + { 88, 93, 89, "elt"}, + { 122, 22, 108, "elt"}, + { 101, 112, 130, "elt"}, + { 217, 127, 240, "elt"}, + { 191, 44, 80, "elt"}, + { 121, 77, 117, "elt"}, + { 103, 94, 129, "elt"}, + { 150, 156, 183, "elt"}, + { 30, 141, 173, "elt"}, + { 17, 86, 92, "elt"}, + { 144, 167, 31, "elt"}, + { 183, 156, 29, "elt"}, + { 85, 86, 17, "elt"}, + { 6, 91, 100, "elt"}, + { 130, 21, 93, "elt"}, + { 17, 92, 7, "elt"}, + { 22, 2, 108, "elt"}, + { 75, 79, 121, "elt"}, + { 214, 230, 131, "elt"}, + { 228, 26, 209, "elt"}, + { 167, 144, 36, "elt"}, + { 16, 100, 99, "elt"}, + { 22, 126, 169, "elt"}, + { 44, 143, 80, "elt"}, + { 43, 239, 127, "elt"}, + { 110, 98, 123, "elt"}, + { 102, 14, 146, "elt"}, + { 110, 123, 41, "elt"}, + { 88, 87, 134, "elt"}, + { 45, 155, 78, "elt"}, + { 83, 86, 84, "elt"}, + { 37, 144, 168, "elt"}, + { 76, 191, 80, "elt"}, + { 197, 9, 161, "elt"}, + { 240, 127, 239, "elt"}, + { 49, 181, 147, "elt"}, + { 17, 11, 85, "elt"}, + { 206, 37, 168, "elt"}, + { 181, 180, 200, "elt"}, + { 37, 36, 144, "elt"}, + { 86, 83, 99, "elt"}, + { 61, 180, 146, "elt"}, + { 93, 88, 134, "elt"}, + { 149, 98, 111, "elt"}, + { 101, 135, 113, "elt"}, + { 81, 201, 82, "elt"}, + { 96, 132, 137, "elt"}, + { 231, 222, 235, "elt"}, + { 116, 124, 133, "elt"}, + { 165, 134, 194, "elt"}, + { 20, 135, 153, "elt"}, + { 130, 93, 138, "elt"}, + { 20, 113, 135, "elt"}, + { 151, 120, 73, "elt"}, + { 202, 210, 231, "elt"}, + { 132, 136, 137, "elt"}, + { 15, 137, 136, "elt"}, + { 157, 175, 51, "elt"}, + { 135, 138, 153, "elt"}, + { 139, 62, 180, "elt"}, + { 61, 64, 139, "elt"}, + { 69, 57, 140, "elt"}, + { 178, 140, 70, "elt"}, + { 163, 68, 170, "elt"}, + { 27, 163, 141, "elt"}, + { 175, 165, 194, "elt"}, + { 142, 33, 171, "elt"}, + { 31, 35, 144, "elt"}, + { 45, 78, 143, "elt"}, + { 144, 35, 168, "elt"}, + { 189, 179, 204, "elt"}, + { 145, 204, 214, "elt"}, + { 61, 139, 180, "elt"}, + { 102, 146, 129, "elt"}, + { 180, 129, 146, "elt"}, + { 162, 202, 235, "elt"}, + { 78, 155, 12, "elt"}, + { 158, 122, 97, "elt"}, + { 240, 234, 243, "elt"}, + { 123, 149, 239, "elt"}, + { 193, 73, 74, "elt"}, + { 150, 16, 156, "elt"}, + { 68, 163, 56, "elt"}, + { 174, 171, 51, "elt"}, + { 51, 52, 157, "elt"}, + { 165, 138, 134, "elt"}, + { 165, 153, 138, "elt"}, + { 192, 154, 117, "elt"}, + { 27, 202, 162, "elt"}, + { 156, 16, 99, "elt"}, + { 217, 240, 242, "elt"}, + { 99, 82, 201, "elt"}, + { 165, 157, 153, "elt"}, + { 52, 20, 157, "elt"}, + { 42, 159, 160, "elt"}, + { 126, 122, 158, "elt"}, + { 42, 160, 39, "elt"}, + { 39, 160, 158, "elt"}, + { 160, 159, 184, "elt"}, + { 25, 202, 27, "elt"}, + { 197, 195, 9, "elt"}, + { 73, 193, 151, "elt"}, + { 178, 233, 219, "elt"}, + { 162, 163, 27, "elt"}, + { 219, 164, 33, "elt"}, + { 152, 174, 175, "elt"}, + { 87, 32, 166, "elt"}, + { 166, 152, 194, "elt"}, + { 128, 182, 190, "elt"}, + { 226, 224, 167, "elt"}, + { 197, 161, 169, "elt"}, + { 206, 34, 37, "elt"}, + { 184, 207, 126, "elt"}, + { 169, 207, 197, "elt"}, + { 69, 178, 232, "elt"}, + { 141, 170, 173, "elt"}, + { 174, 51, 175, "elt"}, + { 171, 33, 164, "elt"}, + { 167, 36, 198, "elt"}, + { 198, 226, 167, "elt"}, + { 203, 170, 68, "elt"}, + { 203, 173, 170, "elt"}, + { 157, 165, 175, "elt"}, + { 152, 142, 174, "elt"}, + { 194, 134, 87, "elt"}, + { 139, 177, 65, "elt"}, + { 176, 213, 216, "elt"}, + { 208, 199, 213, "elt"}, + { 176, 131, 230, "elt"}, + { 222, 223, 186, "elt"}, + { 33, 188, 219, "elt"}, + { 62, 116, 200, "elt"}, + { 204, 19, 189, "elt"}, + { 129, 180, 181, "elt"}, + { 62, 200, 180, "elt"}, + { 117, 77, 192, "elt"}, + { 173, 182, 30, "elt"}, + { 226, 198, 203, "elt"}, + { 128, 150, 183, "elt"}, + { 191, 220, 44, "elt"}, + { 237, 207, 236, "elt"}, + { 15, 136, 229, "elt"}, + { 235, 202, 231, "elt"}, + { 154, 192, 221, "elt"}, + { 162, 235, 56, "elt"}, + { 187, 238, 233, "elt"}, + { 164, 238, 50, "elt"}, + { 167, 224, 31, "elt"}, + { 226, 203, 225, "elt"}, + { 184, 236, 207, "elt"}, + { 19, 67, 189, "elt"}, + { 182, 173, 198, "elt"}, + { 236, 148, 220, "elt"}, + { 221, 192, 181, "elt"}, + { 222, 193, 154, "elt"}, + { 193, 222, 231, "elt"}, + { 175, 194, 152, "elt"}, + { 169, 126, 207, "elt"}, + { 205, 195, 212, "elt"}, + { 195, 197, 212, "elt"}, + { 212, 237, 245, "elt"}, + { 36, 190, 198, "elt"}, + { 182, 198, 190, "elt"}, + { 133, 223, 116, "elt"}, + { 213, 64, 208, "elt"}, + { 223, 133, 57, "elt"}, + { 26, 228, 81, "elt"}, + { 29, 156, 201, "elt"}, + { 198, 173, 203, "elt"}, + { 229, 185, 13, "elt"}, + { 219, 188, 232, "elt"}, + { 211, 215, 63, "elt"}, + { 177, 230, 65, "elt"}, + { 168, 205, 212, "elt"}, + { 168, 35, 205, "elt"}, + { 34, 206, 196, "elt"}, + { 184, 148, 236, "elt"}, + { 227, 191, 76, "elt"}, + { 29, 228, 28, "elt"}, + { 64, 66, 208, "elt"}, + { 29, 201, 228, "elt"}, + { 151, 193, 231, "elt"}, + { 202, 185, 210, "elt"}, + { 197, 207, 237, "elt"}, + { 179, 215, 204, "elt"}, + { 206, 168, 212, "elt"}, + { 216, 213, 199, "elt"}, + { 176, 177, 213, "elt"}, + { 211, 65, 230, "elt"}, + { 131, 145, 214, "elt"}, + { 63, 215, 179, "elt"}, + { 214, 215, 211, "elt"}, + { 199, 8, 216, "elt"}, + { 18, 216, 8, "elt"}, + { 244, 217, 242, "elt"}, + { 243, 155, 242, "elt"}, + { 218, 71, 24, "elt"}, + { 233, 178, 70, "elt"}, + { 224, 188, 31, "elt"}, + { 181, 200, 221, "elt"}, + { 191, 227, 236, "elt"}, + { 223, 200, 116, "elt"}, + { 154, 221, 222, "elt"}, + { 223, 221, 200, "elt"}, + { 222, 186, 235, "elt"}, + { 221, 223, 222, "elt"}, + { 172, 69, 232, "elt"}, + { 225, 172, 226, "elt"}, + { 203, 68, 225, "elt"}, + { 224, 226, 172, "elt"}, + { 196, 245, 76, "elt"}, + { 237, 227, 245, "elt"}, + { 228, 209, 28, "elt"}, + { 185, 229, 210, "elt"}, + { 13, 15, 229, "elt"}, + { 176, 230, 177, "elt"}, + { 211, 230, 214, "elt"}, + { 210, 151, 231, "elt"}, + { 219, 232, 178, "elt"}, + { 172, 232, 224, "elt"}, + { 187, 233, 70, "elt"}, + { 238, 187, 218, "elt"}, + { 12, 155, 241, "elt"}, + { 186, 56, 235, "elt"}, + { 191, 236, 220, "elt"}, + { 236, 227, 237, "elt"}, + { 227, 76, 245, "elt"}, + { 212, 197, 237, "elt"}, + { 218, 50, 238, "elt"}, + { 23, 234, 149, "elt"}, + { 234, 239, 149, "elt"}, + { 10, 234, 23, "elt"}, + { 243, 242, 240, "elt"}, + { 239, 234, 240, "elt"}, + { 234, 241, 243, "elt"}, + { 244, 155, 45, "elt"}, + { 155, 243, 241, "elt"}, + { 196, 206, 245, "elt"}, + { 155, 244, 242, "elt"}, + { 212, 245, 206, "elt"} +} + +boundaries = +{ + { 65, 62, "Wall" }, + { 124, 125, "Wall" }, + { 94, 102, "Wall" }, + { 115, 61, "Wall" }, + { 15, 5, "Wall" }, + { 5, 106, "Wall" }, + { 85, 84, "Wall" }, + { 10, 241, "Wall" }, + { 104, 1, "Wall" }, + { 1, 19, "Wall" }, + { 114, 105, "Wall" }, + { 14, 60, "Wall" }, + { 60, 115, "Wall" }, + { 105, 95, "Wall" }, + { 21, 53, "Wall" }, + { 53, 90, "Wall" }, + { 29, 30, "Wall" }, + { 90, 89, "Wall" }, + { 58, 70, "Wall" }, + { 125, 59, "Wall" }, + { 59, 58, "Wall" }, + { 95, 104, "Wall" }, + { 57, 186, "Wall" }, + { 74, 75, "Wall" }, + { 4, 14, "Wall" }, + { 102, 4, "Wall" }, + { 47, 118, "Wall" }, + { 75, 119, "Wall" }, + { 107, 46, "Wall" }, + { 46, 47, "Wall" }, + { 96, 107, "Wall" }, + { 43, 41, "Wall" }, + { 72, 73, "Wall" }, + { 161, 22, "Wall" }, + { 159, 148, "Wall" }, + { 118, 79, "Wall" }, + { 41, 40, "Wall" }, + { 40, 110, "Wall" }, + { 25, 185, "Wall" }, + { 106, 96, "Wall" }, + { 77, 147, "Wall" }, + { 187, 71, "Wall" }, + { 49, 48, "Wall" }, + { 48, 103, "Wall" }, + { 18, 0, "Wall" }, + { 0, 114, "Wall" }, + { 20, 54, "Wall" }, + { 54, 113, "Wall" }, + { 50, 51, "Wall" }, + { 55, 21, "Wall" }, + { 112, 55, "Wall" }, + { 91, 7, "Wall" }, + { 109, 38, "Wall" }, + { 38, 39, "Wall" }, + { 16, 6, "Wall" }, + { 44, 45, "Wall" }, + { 97, 109, "Wall" }, + { 119, 72, "Wall" }, + { 83, 82, "Wall" }, + { 108, 97, "Wall" }, + { 111, 3, "Wall" }, + { 3, 23, "Wall" }, + { 89, 88, "Wall" }, + { 101, 112, "Wall" }, + { 217, 127, "Wall" }, + { 121, 77, "Wall" }, + { 103, 94, "Wall" }, + { 30, 141, "Wall" }, + { 6, 91, "Wall" }, + { 7, 17, "Wall" }, + { 22, 2, "Wall" }, + { 2, 108, "Wall" }, + { 79, 121, "Wall" }, + { 26, 209, "Wall" }, + { 143, 80, "Wall" }, + { 127, 43, "Wall" }, + { 110, 98, "Wall" }, + { 88, 87, "Wall" }, + { 84, 83, "Wall" }, + { 80, 76, "Wall" }, + { 9, 161, "Wall" }, + { 147, 49, "Wall" }, + { 17, 11, "Wall" }, + { 11, 85, "Wall" }, + { 37, 36, "Wall" }, + { 98, 111, "Wall" }, + { 113, 101, "Wall" }, + { 82, 81, "Wall" }, + { 116, 124, "Wall" }, + { 61, 64, "Wall" }, + { 69, 57, "Wall" }, + { 141, 27, "Wall" }, + { 142, 33, "Wall" }, + { 31, 35, "Wall" }, + { 78, 143, "Wall" }, + { 189, 179, "Wall" }, + { 12, 78, "Wall" }, + { 73, 74, "Source" }, + { 150, 16, "Wall" }, + { 56, 68, "Wall" }, + { 51, 52, "Wall" }, + { 52, 20, "Wall" }, + { 42, 159, "Wall" }, + { 39, 42, "Wall" }, + { 27, 25, "Wall" }, + { 195, 9, "Wall" }, + { 87, 32, "Wall" }, + { 32, 166, "Wall" }, + { 166, 152, "Wall" }, + { 190, 128, "Wall" }, + { 34, 37, "Wall" }, + { 152, 142, "Wall" }, + { 208, 199, "Wall" }, + { 33, 188, "Wall" }, + { 62, 116, "Wall" }, + { 128, 150, "Wall" }, + { 220, 44, "Wall" }, + { 19, 67, "Wall" }, + { 67, 189, "Wall" }, + { 148, 220, "Wall" }, + { 205, 195, "Wall" }, + { 36, 190, "Wall" }, + { 81, 26, "Wall" }, + { 185, 13, "Wall" }, + { 63, 211, "Wall" }, + { 35, 205, "Wall" }, + { 196, 34, "Wall" }, + { 28, 29, "Wall" }, + { 64, 66, "Wall" }, + { 66, 208, "Wall" }, + { 211, 65, "Wall" }, + { 179, 63, "Wall" }, + { 199, 8, "Wall" }, + { 8, 18, "Wall" }, + { 244, 217, "Wall" }, + { 71, 24, "Wall" }, + { 24, 218, "Wall" }, + { 188, 31, "Wall" }, + { 172, 69, "Wall" }, + { 225, 172, "Wall" }, + { 68, 225, "Wall" }, + { 76, 196, "Wall" }, + { 209, 28, "Wall" }, + { 13, 15, "Wall" }, + { 70, 187, "Wall" }, + { 241, 12, "Wall" }, + { 186, 56, "Wall" }, + { 218, 50, "Wall" }, + { 23, 10, "Wall" }, + { 45, 244, "Wall" } +} + diff --git a/2d-advanced/acoustics/wave-propagation/main.cpp b/2d-advanced/acoustics/wave-propagation/main.cpp new file mode 100644 index 0000000..824431d --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/main.cpp @@ -0,0 +1,95 @@ +#include "definitions.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::Views; + + +const int P_INIT = 2; + +const double time_step = 4e-5; + +int main(int argc, char* argv[]) +{ + Hermes2DApi.set_integral_param_value(numThreads,1); + + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + Hermes::vector meshes; + meshes.push_back(mesh); + Hermes::Hermes2D::MeshReaderH2DXML mloader; + mloader.load("domain.mesh", meshes); + + MeshView m; + m.show(mesh); + + Hermes::vector matched_boundaries("0", "1", "7"); + Hermes::vector matched_boundaries_values(345*1.25, 345*1.25, 345*1.25); + Hermes::vector source_boundaries("3", "4", "5", "6"); + Hermes::vector soft_boundaries; + soft_boundaries.push_back("2"); + Hermes::vector hard_boundaries("9", "8", "10"); + + CustomBCValue custom_bc_value(source_boundaries, 1., 1000.); + DefaultEssentialBCConst default_bc_value(soft_boundaries, 0.0); + Hermes::Hermes2D::EssentialBCs bcs_value(Hermes::vector*>(&custom_bc_value, &default_bc_value)); + + CustomBCDerivative custom_bc_derivative(source_boundaries, 1., 1000.); + DefaultEssentialBCConst default_bc_derivative(soft_boundaries, 0.0); + Hermes::Hermes2D::EssentialBCs bcs_derivative(Hermes::vector*>(&custom_bc_derivative, &default_bc_derivative)); + + SpaceSharedPtr space_value(new Hermes::Hermes2D::H1Space(mesh, &bcs_value, P_INIT)); + SpaceSharedPtr space_derivative(new Hermes::Hermes2D::H1Space(mesh, &bcs_derivative, P_INIT)); + Hermes::vector > spaces(space_value, space_derivative); + + BaseView b; + b.show(space_value); + + // Initialize the solution. + MeshFunctionSharedPtr sln_value(new ZeroSolution(mesh)); + MeshFunctionSharedPtr sln_derivative(new ZeroSolution(mesh)); + Hermes::vector > slns(sln_value, sln_derivative); + + Hermes::Hermes2D::Views::ScalarView viewS("Solution", new Hermes::Hermes2D::Views::WinGeom(50, 50, 1000, 800)); + //viewS.set_min_max_range(-1.0, 1.0); + + MyWeakForm wf(matched_boundaries, matched_boundaries_values, slns); + wf.set_current_time_step(time_step); + + // Initialize linear solver. + Hermes::Hermes2D::LinearSolver linear_solver(&wf, spaces); + linear_solver.set_jacobian_constant(); + + // Solve the linear problem. + unsigned int iteration = 0; + for(double time = time_step; time < 1.0; time += time_step) + { + try + { + Hermes::Mixins::Loggable::Static::info("Iteration: %u, Time: %g.", iteration, time); + Space::update_essential_bc_values(spaces, time); + linear_solver.solve(); + + // Get the solution vector. + double* sln_vector = linear_solver.get_sln_vector(); + + // Translate the solution vector into the previously initialized Solution. + Hermes::Hermes2D::Solution::vector_to_solutions(sln_vector, spaces, slns); + + // Visualize the solution. + viewS.show(slns[0]); + + //viewS.wait_for_keypress(); + } + + catch(std::exception& e) + { + std::cout << e.what(); + return -1; + } + + iteration++; + } + + return 0; +} \ No newline at end of file diff --git a/2d-advanced/acoustics/wave-propagation/test.xml b/2d-advanced/acoustics/wave-propagation/test.xml new file mode 100644 index 0000000..c5815ee --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/test.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2d-advanced/acoustics/wave-propagation/test_acoustic_transient_planar.py b/2d-advanced/acoustics/wave-propagation/test_acoustic_transient_planar.py new file mode 100644 index 0000000..d3b5c0f --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/test_acoustic_transient_planar.py @@ -0,0 +1,69 @@ +import agros2d + +# problem +problem = agros2d.problem(clear = True) +problem.coordinate_type = "planar" +problem.mesh_type = "triangle" +problem.matrix_solver = "umfpack" +problem.time_step_method = "fixed" +problem.time_method_order = 2 +problem.time_method_tolerance = 1 +problem.time_total = 0.001 +problem.time_steps = 250 + +# disable view +agros2d.view.mesh.initial_mesh = False +agros2d.view.mesh.solution_mesh = False +agros2d.view.mesh.order = False +agros2d.view.post2d.scalar = False +agros2d.view.post2d.contours = False +agros2d.view.post2d.vectors = False + +# fields +# acoustic +acoustic = agros2d.field("acoustic") +acoustic.analysis_type = "transient" +acoustic.initial_condition = 0 +acoustic.number_of_refinements = 0 +acoustic.polynomial_order = 2 +acoustic.linearity_type = "linear" +acoustic.adaptivity_type = "disabled" + +# boundaries +acoustic.add_boundary("Matched bundary", "acoustic_impedance", {"acoustic_impedance" : 345*1.25 }) +acoustic.add_boundary("Source", "acoustic_pressure", {"acoustic_pressure_real" : { "expression" : "sin(2*pi*(time/(1.0/1000)))" }, "acoustic_pressure_time_derivative" : { "expression" : "2*pi*(1.0/(1.0/1000))*cos(2*pi*(time/(1.0/1000)))" }}) +acoustic.add_boundary("Hard wall", "acoustic_normal_acceleration", {"acoustic_normal_acceleration_real" : 0}) +acoustic.add_boundary("Soft wall", "acoustic_pressure", {"acoustic_pressure_real" : 0, "acoustic_pressure_time_derivative" : 0}) + +# materials +acoustic.add_material("Air", {"acoustic_density" : 1.25, "acoustic_speed" : 343}) + +# geometry +geometry = agros2d.geometry +geometry.add_edge(-0.4, 0.05, 0.1, 0.2, boundaries = {"acoustic" : "Matched bundary"}) +geometry.add_edge(0.1, -0.2, -0.4, -0.05, boundaries = {"acoustic" : "Matched bundary"}) +geometry.add_edge(-0.4, 0.05, -0.4, -0.05, boundaries = {"acoustic" : "Soft wall"}) +geometry.add_edge(-0.18, -0.06, -0.17, -0.05, angle = 90, boundaries = {"acoustic" : "Source"}) +geometry.add_edge(-0.17, -0.05, -0.18, -0.04, angle = 90, boundaries = {"acoustic" : "Source"}) +geometry.add_edge(-0.18, -0.04, -0.19, -0.05, angle = 90, boundaries = {"acoustic" : "Source"}) +geometry.add_edge(-0.19, -0.05, -0.18, -0.06, angle = 90, boundaries = {"acoustic" : "Source"}) +geometry.add_edge(0.1, -0.2, 0.1, 0.2, angle = 90, boundaries = {"acoustic" : "Matched bundary"}) +geometry.add_edge(0.03, 0.1, -0.04, -0.05, angle = 90, boundaries = {"acoustic" : "Hard wall"}) +geometry.add_edge(-0.04, -0.05, 0.08, -0.04, boundaries = {"acoustic" : "Hard wall"}) +geometry.add_edge(0.08, -0.04, 0.03, 0.1, boundaries = {"acoustic" : "Hard wall"}) + +geometry.add_label(-0.0814934, 0.0707097, area = 10e-05, materials = {"acoustic" : "Air"}) +geometry.add_label(-0.181474, -0.0504768, materials = {"acoustic" : "none"}) +geometry.add_label(0.0314514, 0.0411749, materials = {"acoustic" : "none"}) + +agros2d.view.zoom_best_fit() + +# solve problem +problem.solve() + +# point +point = acoustic.local_values(0.042132, -0.072959) +testp = agros2d.test("Acoustic pressure", point["pr"], 0.200436) +# testSPL = agros2d.test("Acoustic sound level", point["SPL"], 77.055706) + +print("Test: Acoustic - transient - planar: " + str(testp)) \ No newline at end of file diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index 5254239..3b1ea19 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -21,45 +21,20 @@ const int P_INIT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.9; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, H2D_HP_ANISO_H -// H2D_HP_ANISO_P, H2D_HP_ANISO. +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Name of the iterative method employed by AztecOO (ignored by the other solvers). -// Possibilities: gmres, cg, cgs, tfqmr, bicgstab. -const char* iterative_method = "bicgstab"; -// Name of the preconditioner employed by AztecOO (ignored by the other solvers). -// Possibilities: none, jacobi, neumann, least-squares, or a -// preconditioner from IFPACK (see solver/aztecoo.h). -const char* preconditioner = "jacobi"; +const double ERR_STOP = 1e-1; int main(int argc, char* args[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -79,7 +54,7 @@ int main(int argc, char* args[]) // DOF and CPU convergence graphs. SimpleGraph graph_dof_est, graph_cpu_est; - // Display the mesh-> + // Display the mesh. OrderView oview("Coarse mesh", new WinGeom(0, 0, 440, 350)); oview.show(space); @@ -99,7 +74,7 @@ int main(int argc, char* args[]) do { // Construct globally refined reference mesh - // and setup reference space-> + // and setup reference space. Mesh::ReferenceMeshCreator ref_mesh_creator(mesh); MeshSharedPtr ref_mesh = ref_mesh_creator.create_ref_mesh(); Space::ReferenceSpaceCreator ref_space_creator(space, ref_mesh); @@ -117,7 +92,7 @@ int main(int argc, char* args[]) { std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln, HERMES_L2_NORM); @@ -128,8 +103,8 @@ int main(int argc, char* args[]) oview.show(space); // Calculate element errors and total error estimate. - Adapt* adaptivity = new Adapt(space); - double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + adaptivity.set_space(space); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; std::cout << "Error: " << err_est_rel << "%." << std::endl; @@ -137,21 +112,12 @@ int main(int argc, char* args[]) graph_dof_est.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof_est.save("conv_dof_est.dat"); - // If err_est_rel too large, adapt the mesh-> + // If err_est_rel too large, adapt the mesh. if(err_est_rel < ERR_STOP) done = true; else { - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - - if(Space::get_num_dofs(space) >= NDOF_STOP) - { - done = true; - break; - } + done = adaptivity.adapt(&selector); } - - // Clean up. - delete adaptivity; as++; } diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 6160124..da5cfcf 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -30,37 +30,16 @@ const int INIT_REF_NUM_BDY = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 5.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Problem parameters. // Diffusivity. @@ -70,7 +49,7 @@ const double B1 = 1., B2 = 1.; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -121,7 +100,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -134,7 +113,7 @@ int main(int argc, char* argv[]) LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); DiscreteProblem* dp = new DiscreteProblem(&wf, ref_space); dp->assemble(matrix, rhs); @@ -146,8 +125,8 @@ int main(int argc, char* argv[]) if(solver->solve()) Solution::vector_to_solution(solver->get_sln_vector(), ref_space, ref_sln); else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. @@ -162,8 +141,8 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(space); - double err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + adaptivity.set_space(space); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", @@ -178,23 +157,21 @@ int main(int argc, char* argv[]) graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); // Increase the counter of performed adaptivity steps. if (done == false) as++; } - if (Space::get_num_dofs(space) >= NDOF_STOP) done = true; - + // Clean up. delete solver; delete matrix; delete rhs; - delete adaptivity; delete dp; } diff --git a/2d-advanced/elasticity-linear/CMakeLists.txt b/2d-advanced/elasticity-linear/CMakeLists.txt index 7f833fd..4bbf1e7 100644 --- a/2d-advanced/elasticity-linear/CMakeLists.txt +++ b/2d-advanced/elasticity-linear/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(bracket) add_subdirectory(crack) \ No newline at end of file diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 629c34f..8505cc8 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -21,7 +21,7 @@ // Initial polynomial degree of all mesh elements. const int P_INIT = 2; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh-> +// MULTI = false ... use single-mesh. // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -30,41 +30,16 @@ const bool MULTI = true; // it has different meanings for various adaptive strategies. const double THRESHOLD_MULTI = 0.35; const double THRESHOLD_SINGLE = 0.7; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(MULTI ? THRESHOLD_MULTI : THRESHOLD_SINGLE); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.3; -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Stopping criterion for the Newton's method. -const double NEWTON_TOL = 1e-6; -// Maximum allowed number of Newton iterations. -const int NEWTON_MAX_ITER = 100; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Problem parameters. // Young modulus for steel: 200 GPa. @@ -86,7 +61,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", u1_mesh); @@ -141,7 +116,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator1(u1_mesh); MeshSharedPtr ref_u1_mesh = refMeshCreator1.create_ref_mesh(); @@ -169,11 +144,9 @@ int main(int argc, char* argv[]) cpu_time.tick(); // Perform Newton's iteration. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); try { - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) @@ -189,8 +162,8 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u1_sln_ref, u2_sln_ref)); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), Hermes::vector >(u1_sln_ref, u2_sln_ref), Hermes::vector >(u1_sln, u2_sln)); @@ -211,30 +184,26 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); // Initialize adaptivity. - Adapt* adaptivity = new Adapt(Hermes::vector >(u1_space, u2_space)); + adaptivity.set_spaces(Hermes::vector >(u1_space, u2_space)); /* // Register custom forms for error calculation. - adaptivity->set_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); - adaptivity->set_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); - adaptivity->set_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); - adaptivity->set_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); + errorCalculator.add_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); + errorCalculator.add_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); + errorCalculator.add_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); + errorCalculator.add_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); */ // Calculate error estimate for each solution component and the total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(u1_sln, u2_sln), - Hermes::vector >(u1_sln_ref, u2_sln_ref), &err_est_rel) * 100; + errorCalculator.calculate_errors(Hermes::vector >(u1_sln, u2_sln), + Hermes::vector >(u1_sln_ref, u2_sln_ref)); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Time measurement. cpu_time.tick(); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d, err_est_rel[0]: %g%%", - u1_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[0]), err_est_rel[0]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d, err_est_rel[1]: %g%%", - u2_space->Space::get_num_dofs(), Space::get_num_dofs((ref_spaces)[1]), err_est_rel[1]*100); Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel_total: %g%%", Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)), Space::get_num_dofs(ref_spaces), err_est_rel_total); @@ -246,19 +215,15 @@ int main(int argc, char* argv[]) graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector), + MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE); } - if (Space::get_num_dofs(Hermes::vector >(u1_space, u2_space)) >= NDOF_STOP) done = true; - - // Clean up. - delete adaptivity; // Increase counter. as++; diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 8f46b93..5ec580b 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -22,7 +22,7 @@ const int INIT_REF_NUM = 0; const int P_INIT_U1 = 2; // Initial polynomial degree of mesh elements (v-displacement). const int P_INIT_U2 = 2; -// true = use multi-mesh, false = use single-mesh-> +// true = use multi-mesh, false = use single-mesh. // Note: in the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr u1_mesh(new Mesh), u2_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", u1_mesh); @@ -198,7 +198,7 @@ int main(int argc, char* argv[]) Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(u1_sln_ref, u2_sln_ref)); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(u1_space, u2_space), Hermes::vector >(u1_sln_ref, u2_sln_ref), @@ -220,10 +220,10 @@ int main(int argc, char* argv[]) /* // Register custom forms for error calculation. - adaptivity->set_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); - adaptivity->set_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); - adaptivity->set_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); - adaptivity->set_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); + errorCalculator.add_error_form(0, 0, bilinear_form_0_0, bilinear_form_0_0); + errorCalculator.add_error_form(0, 1, bilinear_form_0_1, bilinear_form_0_1); + errorCalculator.add_error_form(1, 0, bilinear_form_1_0, bilinear_form_1_0); + errorCalculator.add_error_form(1, 1, bilinear_form_1_1, bilinear_form_1_1); */ // Calculate error estimate for each solution component and the total error estimate. @@ -248,7 +248,7 @@ int main(int argc, char* argv[]) graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index 7f84173..3a36e21 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -1,2 +1,16 @@ +add_subdirectory(forward-step) +add_subdirectory(forward-step-adapt) +add_subdirectory(reflected-shock) +add_subdirectory(reflected-shock-adapt) add_subdirectory(gamm-channel) -add_subdirectory(gamm-channel-adapt) \ No newline at end of file +add_subdirectory(gamm-channel-adapt) +add_subdirectory(heating-induced-vortex) +add_subdirectory(heating-induced-vortex-adapt) +#add_subdirectory(joukowski-profile) +#add_subdirectory(joukowski-profile-adapt) + +# add_subdirectory(euler-coupled) +# add_subdirectory(euler-coupled-adapt) + +add_subdirectory(heating-flow-coupling) +add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index 419b9ec..bb2b189 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -54,34 +54,16 @@ int REFINEMENT_COUNT = 0; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies (see below). const double THRESHOLD = 0.3; -// Adaptive strategy: -const int STRATEGY = 1; - -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_HP_ANISO; - -// Maximum polynomial degree used. -1 for unlimited. -const int MAX_P_ORDER = 1; - -// Maximum allowed level of hanging nodes: -const int MESH_REGULARITY = -1; - -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -double ERR_STOP = 5.0; - -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 16000; - -// Matrix solver for orthogonal projections: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double ERR_STOP = 1e-1; // Equation parameters. const double P_EXT = 1.0; // Exterior pressure (dimensionless). @@ -113,7 +95,7 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), base_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("ffs.mesh", base_mesh); @@ -172,7 +154,7 @@ int main(int argc, char* argv[]) ScalarView s4("RhoE", new WinGeom(700, 400, 700, 400)); // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + L2ProjBasedSelector selector(CAND_LIST); selector.set_error_weights(1.0, 1.0, 1.0); // Set up CFL calculation class. @@ -264,7 +246,7 @@ int main(int argc, char* argv[]) space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); DiscreteProblem dp(&wf, ref_spaces); SparseMatrix* matrix = create_matrix(); @@ -304,8 +286,8 @@ int main(int argc, char* argv[]) std::cout << e.what(); } - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -313,9 +295,9 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), ref_space_rho->get_mesh(), time_step); @@ -323,25 +305,14 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)) >= NDOF_STOP) - { - Hermes::Mixins::Loggable::Static::info("Max. number of DOFs exceeded."); - REFINEMENT_COUNT++; - done = true; - } - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - REFINEMENT_COUNT++; - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - } + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + REFINEMENT_COUNT++; + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector)); if(!done) as++; @@ -380,7 +351,7 @@ int main(int argc, char* argv[]) delete solver; delete matrix; delete rhs; - delete adaptivity; + } while (done == false); diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index b700b75..ff5289a 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -86,7 +86,7 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("ffs.mesh", mesh); diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index a03bc6d..a0a3de3 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char* argv[]) LinearSolver solver(&wf, spaces); #pragma endregion - #pragma region 5.Time stepping loop. + #pragma region 5. Time stepping loop. int iteration = 0; for(double t = 0.0; t < 10.0; t += time_step) { diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index da7fa3a..795ab42 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -82,7 +82,10 @@ const int UNREF_FREQ = 5; // Adaptivity int REFINEMENT_COUNT = 0; const double THRESHOLD = 0.3; -const int STRATEGY = 0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 5); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); CandList CAND_LIST = H2D_HP_ANISO; const int MAX_P_ORDER = -1; const int MESH_REGULARITY = -1; @@ -97,7 +100,7 @@ double ERR_STOP = 5.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -178,8 +181,8 @@ int main(int argc, char* argv[]) ADEStabilityCalculation ADES(ADVECTION_STABILITY_CONSTANT, DIFFUSION_STABILITY_CONSTANT, LAMBDA); // Initialize refinement selector. - H1ProjBasedSelector l2_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); - H1ProjBasedSelector h1_selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + H1ProjBasedSelector l2_selector(CAND_LIST); + H1ProjBasedSelector h1_selector(CAND_LIST); // Look for a saved solution on the disk. int iteration = 0; double t = 0; @@ -229,7 +232,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -263,7 +266,7 @@ int main(int argc, char* argv[]) Space::get_num_dofs(spaces), Space::get_num_dofs(cref_spaces)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); DiscreteProblem dp(&wf, cref_spaces); // Assemble the stiffness matrix and rhs. @@ -299,25 +302,21 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(cspaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(spaces, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_H1_NORM)); - adaptivity->set_error_form(new CouplingErrorFormVelocity(velX, C_P)); - adaptivity->set_error_form(new CouplingErrorFormVelocity(velY, C_P)); - adaptivity->set_norm_form(new CouplingErrorFormVelocity(velX, C_P)); - adaptivity->set_norm_form(new CouplingErrorFormVelocity(velY, C_P)); + Adapt adaptivity(spaces, &errorCalculator, &stoppingCriterion); + errorCalculator.add_error_form(new CouplingErrorFormVelocity(velX, C_P)); + errorCalculator.add_error_form(new CouplingErrorFormVelocity(velY, C_P)); - adaptivity->set_error_form(new CouplingErrorFormTemperature(velX, C_P)); - adaptivity->set_error_form(new CouplingErrorFormTemperature(velY, C_P)); - adaptivity->set_norm_form(new CouplingErrorFormTemperature(velX, C_P)); - adaptivity->set_norm_form(new CouplingErrorFormTemperature(velY, C_P)); + errorCalculator.add_error_form(new CouplingErrorFormTemperature(velX, C_P)); + errorCalculator.add_error_form(new CouplingErrorFormTemperature(velY, C_P)); Hermes::vector component_errors; - double error_value = adaptivity->calc_err_est(slns, rslns, &component_errors) * 100; + double error_value = adaptivity.calc_err_est(slns, rslns, &component_errors) * 100; std::cout << std::endl; for(int k = 0; k < 5; k ++) @@ -336,14 +335,13 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("Error: %g%%.", error_value); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (error_value < ERR_STOP) done = true; else { Hermes::Mixins::Loggable::Static::info("Adapting coarse space->"); - done = adaptivity->adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector, &h1_selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(Hermes::vector *>(&l2_selector, &l2_selector, &l2_selector, &l2_selector, &h1_selector)); } as++; @@ -372,8 +370,6 @@ int main(int argc, char* argv[]) lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); } } - - delete adaptivity; } while (!done); diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 27283af..546d7c3 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -81,7 +81,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 8944374..db65394 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -134,7 +134,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) VectorView velocity_view("Velocity", new WinGeom(700, 400, 600, 300)); // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + L2ProjBasedSelector selector(CAND_LIST); selector.set_error_weights(1.0, 1.0, 1.0); // Set up CFL calculation class. @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -260,7 +260,7 @@ int main(int argc, char* argv[]) space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); DiscreteProblem dp(&wf, ref_spaces); SparseMatrix* matrix = create_matrix(); @@ -292,8 +292,8 @@ int main(int argc, char* argv[]) else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -301,9 +301,9 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); @@ -311,13 +311,13 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP & Space::get_num_dofs(ref_spaces) > NDOFS_MIN) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); REFINEMENT_COUNT++; @@ -332,7 +332,7 @@ int main(int argc, char* argv[]) delete solver; delete matrix; delete rhs; - delete adaptivity; + } while (done == false); diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index 90389bc..dd52a62 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -73,7 +73,7 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index 400751a..e28159f 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -27,11 +27,7 @@ const int MAX_P_ORDER = 1; // Time interval length. const double T_END = 1.0; // Shock capturing. -bool SHOCK_CAPTURING = true; -// Stopping criterion for adaptivity. -double ERR_STOP = 0.95; -// Predefined list of element refinement candidates. -CandList CAND_LIST = H2D_HP_ANISO; +bool SHOCK_CAPTURING = true; // Set to "true" to enable VTK output. const bool VTK_VISUALIZATION = false; @@ -70,32 +66,16 @@ int REFINEMENT_COUNT = 0; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.5; - -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; - -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; - -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; - -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Equation parameters. const double KAPPA = 1.4; @@ -131,7 +111,7 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("channel.mesh", mesh); @@ -191,7 +171,7 @@ int main(int argc, char* argv[]) OrderView space_view("Space", new WinGeom(0, 0, 1500, 700)); // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + L2ProjBasedSelector selector(CAND_LIST); // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); @@ -235,7 +215,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. int order_increase = (CAND_LIST == H2D_HP_ANISO ? 1 : 0); Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); @@ -272,7 +252,7 @@ int main(int argc, char* argv[]) space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); solver.set_spaces(ref_spaces); wf.set_current_time_step(time_step); @@ -295,8 +275,8 @@ int main(int argc, char* argv[]) flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); } - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), @@ -304,9 +284,9 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(space_rho, space_rho_v_x, + Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), + double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); @@ -314,16 +294,16 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (Space::get_num_dofs(ref_spaces) > NDOF_STOP || err_est_rel_total < THRESHOLD) { done = true; } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); REFINEMENT_COUNT++; - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); if(!done) @@ -363,7 +343,7 @@ int main(int argc, char* argv[]) } // Clean up. - delete adaptivity; + } while (done == false); diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index ea1a6cf..9b4dea6 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -90,7 +90,7 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("channel.mesh", mesh); diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h b/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h index 3de6219..57bf93f 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h @@ -36,10 +36,10 @@ class EssentialBCNonConst : public EssentialBoundaryCondition /* Custom error forms */ -class CustomErrorForm : public Adapt::MatrixFormVolError +class CustomErrorForm : public MatrixFormVol { public: - CustomErrorForm(double d, double c) : Adapt::MatrixFormVolError(0, 0, HERMES_H1_NORM), d(d), c(c) {}; + CustomErrorForm(double d, double c) : MatrixFormVol(0, 0), d(d), c(c) {}; template Scalar laplace_form(int n, double *wt, Func *u_ext[], Func *u, diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index dce5732..1560655 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -19,7 +19,7 @@ const double W_SCALING_FACTOR = 100.; // Initial polynomial degrees. const int P_INIT = 2; // MULTI = true ... use multi-mesh, -// MULTI = false ... use single-mesh-> +// MULTI = false ... use single-mesh. // Note: In the single mesh option, the meshes are // forced to be geometrically the same but the // polynomial degrees can still vary. @@ -34,37 +34,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.9; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 2.0; -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e0; // Newton's method // Stopping criterion for Newton on fine mesh-> @@ -132,7 +111,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr basemesh(new Mesh), T_mesh(new Mesh), w_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", basemesh); @@ -232,7 +211,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreatorU(T_mesh); MeshSharedPtr ref_T_mesh = refMeshCreatorU.create_ref_mesh(); @@ -275,24 +254,24 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solutions on coarse meshes for error estimation."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(T_space, w_space), Hermes::vector >(T_time_new, w_time_new), - Hermes::vector >(T_coarse, w_coarse), - matrix_solver); + Hermes::vector >(T_coarse, w_coarse)); // Initialize an instance of the Adapt class and register custom error forms. - Adapt* adaptivity = new Adapt(Hermes::vector >(T_space, w_space)); + Adapt adaptivity(Hermes::vector >(T_space, w_space), &errorCalculator, &stoppingCriterion); CustomErrorForm cef_0_0(d_TT, c_TT); CustomErrorForm cef_0_1(d_Tw, c_TT); CustomErrorForm cef_1_0(d_wT, c_ww); CustomErrorForm cef_1_1(d_ww, c_ww); - adaptivity->set_error_form(0, 0, &cef_0_0); - adaptivity->set_error_form(0, 1, &cef_0_1); - adaptivity->set_error_form(1, 0, &cef_1_0); - adaptivity->set_error_form(1, 1, &cef_1_1); + errorCalculator.add_error_form(0, 0, &cef_0_0); + errorCalculator.add_error_form(0, 1, &cef_0_1); + errorCalculator.add_error_form(1, 0, &cef_1_0); + errorCalculator.add_error_form(1, 1, &cef_1_1); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(T_coarse, w_coarse), - Hermes::vector >(T_time_new, w_time_new)) * 100; + errorCalculator.calculate_errors(Hermes::vector >(T_coarse, w_coarse), + Hermes::vector >(T_time_new, w_time_new)); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", @@ -304,18 +283,12 @@ int main(int argc, char* argv[]) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (Space::get_num_dofs(Hermes::vector >(T_space, w_space)) >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; - } + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector)); - // Clean up. - delete adaptivity; + // Increase the counter of performed adaptivity steps. + as++; + } } while (done == false); diff --git a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp index 0d1fc5f..9ab8347 100644 --- a/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp +++ b/2d-advanced/heat-transfer/wall-on-fire-adapt-space-and-time/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -46,37 +46,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double SPACE_ERR_TOL = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Temporal adaptivity. // This flag decides whether adaptive time stepping will be done. @@ -156,7 +135,7 @@ int main(int argc, char* argv[]) ADAPTIVE_TIME_STEP_ON = false; } - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("wall.mesh", basemesh); @@ -241,14 +220,14 @@ int main(int argc, char* argv[]) bool done = false; int as = 1; double err_est; do { - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - // Initialize Runge-Kutta time stepping on the reference mesh-> + // Initialize Runge-Kutta time stepping on the reference mesh. RungeKutta runge_kutta(&wf, ref_space, &bt); try @@ -337,7 +316,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. MeshFunctionSharedPtr sln(new Solution()); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); ogProjection.project_global(space, ref_sln, sln); @@ -353,19 +332,19 @@ int main(int argc, char* argv[]) // Calculate element errors and spatial error estimate. Hermes::Mixins::Loggable::Static::info("Calculating spatial error estimate."); - Adapt* adaptivity = new Adapt(space); - double err_rel_space = adaptivity->calc_err_est(sln, ref_sln) * 100; + adaptivity.set_space(space); + double err_rel_space = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_rel_space); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_rel_space < SPACE_ERR_TOL) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(&selector); if (Space::get_num_dofs(space) >= NDOF_STOP) done = true; @@ -377,7 +356,7 @@ int main(int argc, char* argv[]) // Clean up. if(!done) - delete adaptivity; + } while (done == false); diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index d878187..1caa957 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" diff --git a/2d-advanced/maxwell/CMakeLists.txt b/2d-advanced/maxwell/CMakeLists.txt index dc7929a..e21a29d 100644 --- a/2d-advanced/maxwell/CMakeLists.txt +++ b/2d-advanced/maxwell/CMakeLists.txt @@ -1,2 +1,6 @@ +add_subdirectory(resonator-time-domain-I) +add_subdirectory(resonator-time-domain-II-ie) +add_subdirectory(resonator-time-domain-II-rk) +add_subdirectory(maxwell-debye-rk) add_subdirectory(magnetostatics) add_subdirectory(microwave-oven) diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 570534e..90d5682 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index c7042bc..061af83 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -64,47 +64,16 @@ int REFINEMENT_COUNT = 0; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies (see below). const double THRESHOLD = 0.5; - -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; - -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_HP_ANISO; - -// Maximum polynomial degree used. -1 for unlimited. -const int MAX_P_ORDER = -1; - -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; - -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; - -// Stopping criterion for adaptivity (rel. error tolerance between the -// fine mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.5; - -// Stopping criterion for adaptivity (number of adaptivity steps). -const int ADAPTIVITY_STEPS = 5; - -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 6200; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 3); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Problem parameters. // Permeability of free space-> @@ -149,7 +118,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr E_mesh(new Mesh), H_mesh(new Mesh), P_mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", E_mesh); @@ -227,8 +196,8 @@ int main(int argc, char* argv[]) runge_kutta.set_verbose_output(true); // Initialize refinement selector. - H1ProjBasedSelector H1selector(CAND_LIST, CONV_EXP, MAX_P_ORDER); - HcurlProjBasedSelector HcurlSelector(CAND_LIST, CONV_EXP, MAX_P_ORDER); + H1ProjBasedSelector H1selector(CAND_LIST); + HcurlProjBasedSelector HcurlSelector(CAND_LIST); // Time stepping loop. int ts = 1; @@ -260,7 +229,7 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. int order_increase = 1; Mesh::ReferenceMeshCreator refMeshCreatorE(E_mesh); @@ -313,42 +282,37 @@ int main(int argc, char* argv[]) P2_view.set_title(title); P2_view.show(P_time_new, H2D_FN_VAL_1); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(E_space, H_space, P_space), Hermes::vector >(E_time_new, H_time_new, P_time_new), Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(E_space, H_space, P_space)); + adaptivity.set_spaces(Hermes::vector >(E_space, H_space, P_space)); + errorCalculator.calculate_errors(Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse), + Hermes::vector >(E_time_new, H_time_new, P_time_new)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse), - Hermes::vector >(E_time_new, H_time_new, P_time_new)) * 100; + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100.; // Report results. Hermes::Mixins::Loggable::Static::info("Error estimate: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh-> - if (err_est_rel_total < ERR_STOP || as > ADAPTIVITY_STEPS - 1) + // If err_est too large, adapt the mesh. + if (err_est_rel_total < ERR_STOP) { - if(err_est_rel_total < ERR_STOP) - Hermes::Mixins::Loggable::Static::info("Error estimate under the specified threshold -> moving to next time step."); - else - Hermes::Mixins::Loggable::Static::info("Error estimate above the specified threshold, but the specified number of adaptivity steps reached -> moving to next time step."); + Hermes::Mixins::Loggable::Static::info("Error estimate under the specified threshold -> moving to next time step."); done = true; } else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); REFINEMENT_COUNT++; - done = adaptivity->adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector), - THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector)); if(!done) as++; } - - delete adaptivity; } while(!done); diff --git a/2d-advanced/maxwell/microwave-oven/definitions.cpp b/2d-advanced/maxwell/microwave-oven/definitions.cpp index 25e418e..9257a34 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.cpp +++ b/2d-advanced/maxwell/microwave-oven/definitions.cpp @@ -17,8 +17,8 @@ Scalar CustomMatrixForm::matrix_form(int n, double *wt, Func *u_ext[], F return 1.0/mu_r * result3 - ikappa * Hermes::sqrt(mu_0 / e_0) * result1 - sqr(kappa) * result2; } -std::complex CustomMatrixForm::value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const +std::complex CustomMatrixForm::value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const { return matrix_form >(n, wt, u_ext, u, v, e, ext); } @@ -45,7 +45,7 @@ Ord CustomMatrixForm::gamma(int marker, Ord x, Ord y) const return Ord(0.0); } -MatrixFormVol >* CustomMatrixForm::clone() const +MatrixFormVol* CustomMatrixForm::clone() const { CustomMatrixForm* form = new CustomMatrixForm(i, j, e_0, mu_0, mu_r, kappa, omega, J, align_mesh); form->wf = this->wf; @@ -97,8 +97,8 @@ Scalar CustomResidualForm::vector_form(int n, double *wt, Func *u_ext[], return 1.0/mu_r * result3 - ikappa * Hermes::sqrt(mu_0 / e_0) * result1 - sqr(kappa) * result2; } -std::complex CustomResidualForm::value(int n, double *wt, Func > *u_ext[], Func *v, - Geom *e, Func > **ext) const +std::complex CustomResidualForm::value(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func **ext) const { return vector_form >(n, wt, u_ext, v, e, ext); } @@ -125,7 +125,7 @@ Ord CustomResidualForm::gamma(int marker, Ord x, Ord y) const return Ord(0.0); } -CustomResidualForm::VectorFormVol >* CustomResidualForm::clone() const +CustomResidualForm::VectorFormVol* CustomResidualForm::clone() const { CustomResidualForm* form = new CustomResidualForm(i, e_0, mu_0, mu_r, kappa, omega, J, align_mesh); form->wf = this->wf; @@ -169,8 +169,8 @@ Scalar CustomVectorFormSurf::vector_form_surf(int n, double *wt, Func *u return ii * omega * J * result; } -std::complex CustomVectorFormSurf::value(int n, double *wt, Func > *u_ext[], - Func *v, Geom *e, Func > **ext) const +std::complex CustomVectorFormSurf::value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func **ext) const { return vector_form_surf , double>(n, wt, u_ext, v, e, ext); } @@ -183,7 +183,7 @@ Ord CustomVectorFormSurf::ord(int n, double *wt, Func *u_ext[], Func * CustomWeakForm::CustomWeakForm(double e_0, double mu_0, double mu_r, double kappa, double omega, - double J, bool align_mesh, MeshSharedPtr mesh, std::string current_bdy) : WeakForm >(1), marker(mesh->get_element_markers_conversion().get_internal_marker("e1").marker) + double J, bool align_mesh, MeshSharedPtr mesh, std::string current_bdy) : WeakForm(1), marker(mesh->get_element_markers_conversion().get_internal_marker("e1").marker) { // Jacobian forms - volumetric. add_matrix_form(new CustomMatrixForm(0, 0, e_0, mu_0, mu_r, kappa, omega, J, align_mesh)); diff --git a/2d-advanced/maxwell/microwave-oven/definitions.h b/2d-advanced/maxwell/microwave-oven/definitions.h index 3a05b24..d5fa94c 100644 --- a/2d-advanced/maxwell/microwave-oven/definitions.h +++ b/2d-advanced/maxwell/microwave-oven/definitions.h @@ -8,23 +8,25 @@ using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; using namespace Hermes::Hermes2D::WeakFormsHcurl; +typedef std::complex complex; + /* Weak forms */ // Jacobian. -class CustomMatrixForm : public MatrixFormVol > +class CustomMatrixForm : public MatrixFormVol { public: CustomMatrixForm(int i, int j, double e_0, double mu_0, double mu_r, double kappa, double omega, double J, bool align_mesh) - : MatrixFormVol >(i, j), e_0(e_0), mu_0(mu_0), + : MatrixFormVol(i, j), e_0(e_0), mu_0(mu_0), mu_r(mu_r), kappa(kappa), omega(omega), J(J), align_mesh(align_mesh) { this->setSymFlag(HERMES_SYM);}; template Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; @@ -39,7 +41,7 @@ class CustomMatrixForm : public MatrixFormVol > Ord er(int marker, Ord x, Ord y) const; - virtual MatrixFormVol >* clone() const; + virtual MatrixFormVol* clone() const; // Geometry of the load. bool in_load(double x, double y) const; @@ -51,24 +53,24 @@ class CustomMatrixForm : public MatrixFormVol > // Residual. -class CustomResidualForm : public VectorFormVol > +class CustomResidualForm : public VectorFormVol { public: CustomResidualForm(int i, double e_0, double mu_0, double mu_r, double kappa, double omega, double J, bool align_mesh) - : VectorFormVol >(i), e_0(e_0), mu_0(mu_0), + : VectorFormVol(i), e_0(e_0), mu_0(mu_0), mu_r(mu_r), kappa(kappa), omega(omega), J(J), align_mesh(align_mesh) {}; template Scalar vector_form(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *v, Geom *e, - Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual VectorFormVol >* clone() const; + virtual VectorFormVol* clone() const; // Gamma as a function of x, y. double gamma(int marker, double x, double y) const; @@ -89,27 +91,27 @@ class CustomResidualForm : public VectorFormVol > }; -class CustomVectorFormSurf : public VectorFormSurf > +class CustomVectorFormSurf : public VectorFormSurf { public: CustomVectorFormSurf(double omega, double J, std::string bnd) - : VectorFormSurf >(0), omega(omega), J(J) { this->set_area(bnd);}; + : VectorFormSurf(0), omega(omega), J(J) { this->set_area(bnd);}; template Scalar vector_form_surf(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], - Func *v, Geom *e, Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual VectorFormSurf >* clone() const { return new CustomVectorFormSurf(omega, J, this->areas[0]); } + virtual VectorFormSurf* clone() const { return new CustomVectorFormSurf(omega, J, this->areas[0]); } double omega, J; }; -class CustomWeakForm : public WeakForm > +class CustomWeakForm : public WeakForm { public: CustomWeakForm(double e_0, double mu_0, double mu_r, double kappa, double omega, @@ -122,10 +124,10 @@ class CustomWeakForm : public WeakForm > // Custom error form. -class CustomErrorForm : public NormFormVol > +class CustomErrorForm : public NormFormVol { public: - CustomErrorForm(double kappa) : NormFormVol >(0, 0) + CustomErrorForm(double kappa) : NormFormVol(0, 0) { kappa_squared = sqr(kappa); }; @@ -144,7 +146,7 @@ class CustomErrorForm : public NormFormVol > return result; } - virtual std::complex value(int n, double *wt, Func > *u, Func > *v, Geom *e) const + virtual std::complex value(int n, double *wt, Func *u, Func *v, Geom *e) const { return hcurl_form_kappa >(n, wt, u, v, e); } diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 33a1cbb..515b876 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -1,5 +1,3 @@ -#define HERMES_REPORT_ALL -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example solves adaptively the electric field in a simplified microwave oven. @@ -85,10 +83,10 @@ const double J = 0.0000033333; const std::string BDY_PERFECT_CONDUCTOR = "b2"; const std::string BDY_CURRENT = "b1"; -class CustomErrorCalculator : public ErrorCalculator > +class CustomErrorCalculator : public ErrorCalculator { public: - CustomErrorCalculator(CalculatedErrorType errorType) : ErrorCalculator >(errorType) + CustomErrorCalculator(CalculatedErrorType errorType) : ErrorCalculator(errorType) { this->add_error_form(new CustomErrorForm (kappa)); } @@ -112,12 +110,12 @@ int main(int argc, char* argv[]) mesh->refine_all_elements(); // Initialize boundary conditions - DefaultEssentialBCConst > bc_essential(BDY_PERFECT_CONDUCTOR, std::complex(0.0, 0.0)); + DefaultEssentialBCConst bc_essential(BDY_PERFECT_CONDUCTOR, std::complex(0.0, 0.0)); - EssentialBCs > bcs(&bc_essential); + EssentialBCs bcs(&bc_essential); // Create an Hcurl space with default shapeset. - SpaceSharedPtr > space(new HcurlSpace > (mesh, &bcs, P_INIT)); + SpaceSharedPtr space(new HcurlSpace (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); @@ -125,19 +123,19 @@ int main(int argc, char* argv[]) CustomWeakForm wf(e_0, mu_0, mu_r, kappa, omega, J, ALIGN_MESH, mesh, BDY_CURRENT); // Initialize coarse and reference mesh solution. - MeshFunctionSharedPtr > sln(new Solution >), ref_sln(new Solution >); + MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinements selector. - HcurlProjBasedSelector > selector(CAND_LIST); + HcurlProjBasedSelector selector(CAND_LIST); // Error calculation. CustomErrorCalculator errorCalculator(RelativeErrorToGlobalNorm); // Stopping criterion for an adaptivity step. - AdaptStoppingCriterionSingleElement > stoppingCriterion(THRESHOLD); + AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity. - Adapt > adaptivity(space, &errorCalculator, &stoppingCriterion); + Adapt adaptivity(space, &errorCalculator, &stoppingCriterion); // Initialize views. ScalarView eview("Electric field", new WinGeom(0, 0, 580, 400)); @@ -150,7 +148,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - Hermes::Hermes2D::NewtonSolver > newton(&wf, space); + Hermes::Hermes2D::NewtonSolver newton(&wf, space); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); newton.set_tolerance(NEWTON_TOL); @@ -161,13 +159,13 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); - int ndof_ref = Space >::get_num_dofs(ref_space); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = Space::get_num_dofs(ref_space); // Initialize reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); @@ -184,12 +182,12 @@ int main(int argc, char* argv[]) e.print_msg(); throw Hermes::Exceptions::Exception("Newton's iteration failed."); }; - // Translate the resulting coefficient vector into the Solution > sln-> - Hermes::Hermes2D::Solution >::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + // Translate the resulting coefficient vector into the Solution sln-> + Hermes::Hermes2D::Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // View the coarse mesh solution and polynomial orders. MeshFunctionSharedPtr real(new RealFilter(ref_sln)); @@ -213,14 +211,14 @@ int main(int argc, char* argv[]) // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space >::get_num_dofs(space), - Space >::get_num_dofs(ref_space), err_est_rel); + Space::get_num_dofs(space), + Space::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); // Add entry to DOF and CPU convergence graphs. - graph_dof.add_values(Space >::get_num_dofs(space), err_est_rel); + graph_dof.add_values(Space::get_num_dofs(space), err_est_rel); graph_dof.save("conv_dof_est.dat"); graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); graph_cpu.save("conv_cpu_est.dat"); diff --git a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp index 4a8b34b..a27d915 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -59,7 +59,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp index 055c745..4ec24e5 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp @@ -9,6 +9,15 @@ static Scalar int_e_f(int n, double *wt, Func *u, Func *v) return result; } +template +static Scalar int_curl_e_curl_f(int n, double *wt, Func *u, Func *v) +{ + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (u->curl[i] * conj(v->curl[i])); + return result; +} + CustomWeakFormWaveIE::CustomWeakFormWaveIE(double tau, double c_squared, MeshFunctionSharedPtr E_prev_sln, MeshFunctionSharedPtr F_prev_sln) : WeakForm(2) { // Jacobian. diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index a8f6f8b..c44bf04 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -51,7 +51,7 @@ const double C_SQUARED = 1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp index f365567..97bb5a2 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp @@ -9,6 +9,15 @@ static Scalar int_e_f(int n, double *wt, Func *u, Func *v) return result; } +template +static Scalar int_curl_e_curl_f(int n, double *wt, Func *u, Func *v) +{ + Scalar result = Scalar(0); + for (int i = 0; i < n; i++) + result += wt[i] * (u->curl[i] * conj(v->curl[i])); + return result; +} + Scalar2 CustomInitialConditionWave::value (double x, double y) const { return Scalar2(std::sin(x) * std::cos(y), -std::cos(x) * std::sin(y)); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp index 81a890b..a8d81a2 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index ba135f4..0fec8e4 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain-excentric.mesh", mesh); diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index f8b105a..e02f777 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -52,34 +52,18 @@ const int UNREF_FREQ = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 3); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; +const double ERR_STOP = 1e-1; // Problem parameters // Reynolds number. @@ -99,10 +83,7 @@ const double NEWTON_TOL = 0.05; const int NEWTON_MAX_ITER = 20; // Domain height (necessary to define the parabolic // velocity profile at inlet). -const double H = 5; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double H = 5; // Current time (defined as global since needed in weak forms). double TIME = 0; @@ -142,7 +123,7 @@ void mag(int n, double* a, double* dadx, double* dady, int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", basemesh); @@ -254,7 +235,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); // Construct globally refined reference mesh - // and setup reference space-> + // and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -300,8 +281,8 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V // Update previous time level solutions. Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProj; ogProj.project_global(Hermes::vector >(xvel_space, yvel_space, p_space), Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), Hermes::vector >(xvel_sln, yvel_sln, p_sln), @@ -309,34 +290,29 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - //Adapt* adaptivity = new Adapt(ref_spaces); - Adapt* adaptivity = new Adapt(Hermes::vector >(xvel_space, yvel_space, p_space)); + adaptivity.set_spaces(Hermes::vector >(xvel_space, yvel_space, p_space)); - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)) * 100.; + errorCalculator.calculate_errors(Hermes::vector >(xvel_sln, yvel_sln, p_sln), + Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), Space::get_num_dofs(ref_spaces), err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)) >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector)); + + // Increase the counter of performed adaptivity steps. + as++; } // Clean up. - delete adaptivity; delete [] coeff_vec; } while (done == false); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 12e8a54..2b30fee 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -81,7 +81,7 @@ double current_time = 0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index 66b531b..014d9db 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index 23d2fe7..dff99ea 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -77,7 +77,7 @@ bool SIMPLE_TEMPERATURE_ADVECTION = false; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh_whole_domain(new Mesh), mesh_with_hole(new Mesh); Hermes::vector meshes (mesh_whole_domain, mesh_with_hole); MeshReaderH2DXML mloader; diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 9182860..d2afe80 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -71,7 +71,7 @@ const double ALPHA_AIR = 5.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index efa4af3..cd89714 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -105,7 +105,7 @@ const bool MULTIMESH = true; // 1 for implicit Euler, 2 for Crank-Nicolson. const int TIME_DISCR = 2; -// Stopping criterion for Newton on coarse mesh-> +// Stopping criterion for Newton on coarse mesh. const double NEWTON_TOL_COARSE = 0.01; // Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_FINE = 0.05; @@ -117,36 +117,16 @@ const int UNREF_FREQ = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// To prevent adaptivity from going on forever. -const int NDOF_STOP = 5000; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.1; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Weak forms. #include "definitions.cpp" @@ -203,7 +183,7 @@ int main (int argc, char* argv[]) { } } - // When nonadaptive solution, refine the mesh-> + // When nonadaptive solution, refine the mesh. basemesh->refine_towards_boundary(BDY_TOP, REF_INIT); basemesh->refine_towards_boundary(BDY_BOT, REF_INIT - 1); basemesh->refine_all_elements(1); @@ -276,7 +256,7 @@ int main (int argc, char* argv[]) { phiview.show(phi_prev_time); phiordview.show(phi_space); - // Newton's loop on the coarse mesh-> + // Newton's loop on the coarse mesh. Hermes::Mixins::Loggable::Static::info("Solving on initial coarse mesh"); try { @@ -299,7 +279,7 @@ int main (int argc, char* argv[]) { Cview.show(C_sln); phiview.show(phi_sln); - // Cleanup after the Newton loop on the coarse mesh-> + // Cleanup after the Newton loop on the coarse mesh. delete solver_coarse; delete[] coeff_vec_coarse; @@ -332,7 +312,7 @@ int main (int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", pid.get_timestep_number(), as); // Construct globally refined reference mesh - // and setup reference space-> + // and setup reference space. Mesh::ReferenceMeshCreator refMeshCreatorC(C_mesh); MeshSharedPtr ref_C_mesh = refMeshCreatorC.create_ref_mesh(); @@ -387,44 +367,32 @@ int main (int argc, char* argv[]) { Hermes::vector >(C_ref_sln, phi_ref_sln)); // Projecting reference solution onto the coarse mesh - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(C_space, phi_space), Hermes::vector >(C_ref_sln, phi_ref_sln), - Hermes::vector >(C_sln, phi_sln), - matrix_solver); + Hermes::vector >(C_sln, phi_sln)); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(Hermes::vector >(C_space, phi_space)); - Hermes::vector err_est_rel; - double err_est_rel_total = adaptivity->calc_err_est(Hermes::vector >(C_sln, phi_sln), - Hermes::vector >(C_ref_sln, phi_ref_sln), &err_est_rel) * 100; + adaptivity.set_spaces(Hermes::vector >(C_space, phi_space)); - // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", - C_space->get_num_dofs(), ref_C_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%", err_est_rel[0]*100); - Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", - phi_space->get_num_dofs(), ref_phi_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%", err_est_rel[1]*100); + errorCalculator.calculate_errors(Hermes::vector >(C_sln, phi_sln), + Hermes::vector >(C_ref_sln, phi_ref_sln)); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d, err_est_rel: %g%%", Space::get_num_dofs(Hermes::vector >(C_space, phi_space)), Space::get_num_dofs(ref_spaces), err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(Hermes::vector *>(&selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector)); Hermes::Mixins::Loggable::Static::info("Adapted..."); - - if (Space::get_num_dofs(Hermes::vector >(C_space, phi_space)) >= NDOF_STOP) - done = true; - else as++; + as++; } // Visualize the solution and mesh-> @@ -452,7 +420,7 @@ int main (int argc, char* argv[]) { // Clean up. delete solver; - delete adaptivity; + delete dp; delete [] coeff_vec; } diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h index da5ab25..7d31afc 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/timestep_controller.h @@ -82,7 +82,9 @@ bool PidTimestepController::end_step(Hermes::vector::calc_rel_error(solutions[i].get(), prev_solutions[i].get(), HERMES_H1_NORM); + DefaultErrorCalculator temp_error_calculator(RelativeErrorToGlobalNorm, 1); + temp_error_calculator.calculate_errors(solutions[i], prev_solutions[i], false); + double rel_error = temp_error_calculator.get_total_error_squared(); max_rel_error = (rel_error > max_rel_error) ? rel_error : max_rel_error; Hermes::Mixins::Loggable::Static::info("Solution[%i]: rel error %g, largest relative error %g", diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index 57eed5a..65019b5 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "hermes2d.h" @@ -30,38 +30,16 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.6; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 0.1; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Problem parameters // Total horizontal length. @@ -113,7 +91,7 @@ double SIGMA_A_5 = SIGMA_T_5 - SIGMA_S_5; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -197,8 +175,8 @@ int main(int argc, char* argv[]) // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); - // Project the fine mesh solution onto the coarse mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh->"); + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. @@ -213,10 +191,11 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(space); + Adapt adaptivity(space, &errorCalculator, &stoppingCriterion); bool solutions_for_adapt = true; - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln, solutions_for_adapt, - HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100; + + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", @@ -232,20 +211,18 @@ int main(int argc, char* argv[]) // Skip the time spent to save the convergence graphs. cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); // Increase the counter of performed adaptivity steps. if (done == false) as++; } - if (space->get_num_dofs() >= NDOF_STOP) - done = true; } while (done == false); diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index 0bbab5d..3f30b64 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -67,7 +67,7 @@ const double DAMPING_COEFF = 1.0; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index 57c3134..65fcaed 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -65,7 +65,7 @@ const int PICARD_MAX_ITER = 100; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index b15af10..33089ec 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -33,9 +33,19 @@ const int P_INIT = 2; double time_step = 5e-4; // Time interval length. const double T_FINAL = 0.4; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +// This is a quantitative parameter of the adapt(...) function and +// it has different meanings for various adaptive strategies. +const double THRESHOLD = 0.5; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Problem parameters. double K_S = 20.464; @@ -61,37 +71,6 @@ const int UNREF_FREQ = 1; // 3... one ref. layer shaved off, poly degrees decreased by one. // and just one polynomial degree subtracted. const int UNREF_METHOD = 3; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity. -const double ERR_STOP = 0.5; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; // Newton's method // Stopping criterion for the Newton's method. @@ -124,7 +103,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", basemesh); @@ -141,6 +120,7 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); int ndof_coarse = Space::get_num_dofs(space); + adaptivity.set_space(space); Hermes::Mixins::Loggable::Static::info("ndof_coarse = %d.", ndof_coarse); // Zero initial solution. This is why we use H_OFFSET. @@ -208,7 +188,7 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -239,15 +219,15 @@ int main(int argc, char* argv[]) throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); } - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; ogProjection.project_global(space, h_time_new, sln_coarse); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(space); - double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, h_time_new) * 100; + errorCalculator.calculate_errors(sln_coarse, h_time_new, true); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", @@ -256,22 +236,16 @@ int main(int argc, char* argv[]) // Time measurement. cpu_time.tick(); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (Space::get_num_dofs(space) >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(&selector); + + // Increase the counter of performed adaptivity steps. + as++; } - - // Clean up. - delete adaptivity; } while (done == false); diff --git a/2d-advanced/richards/basic-rk-newton/main.cpp b/2d-advanced/richards/basic-rk-newton/main.cpp index 228d401..93f3f25 100644 --- a/2d-advanced/richards/basic-rk-newton/main.cpp +++ b/2d-advanced/richards/basic-rk-newton/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); diff --git a/2d-advanced/richards/capillary-barrier-adapt/extras.cpp b/2d-advanced/richards/capillary-barrier-adapt/extras.cpp index c16a08e..70b720d 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/extras.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/extras.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace std; diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 7159620..305a831 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -65,37 +65,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Constitutive relations. enum CONSTITUTIVE_RELATIONS { @@ -224,7 +203,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load(mesh_file.c_str(), basemesh); @@ -328,7 +307,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Time step %d, time step lenght %g, time %g (days), adaptivity step %d:", ts, time_step, current_time, as); // Construct globally refined reference mesh - // and setup reference space-> + // and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -354,7 +333,7 @@ int main(int argc, char* argv[]) // Initialize the FE problem. DiscreteProblem dp(wf, ref_space); - // Perform Newton's iteration on the reference mesh-> If necessary, + // Perform Newton's iteration on the reference mesh. If necessary, // reduce time step to make it converge, but then restore time step // size to its original value. Hermes::Mixins::Loggable::Static::info("Performing Newton's iteration (tau = %g days):", time_step); @@ -419,7 +398,7 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, sln_prev_iter); } - // Perform Picard iteration on the reference mesh-> If necessary, + // Perform Picard iteration on the reference mesh. If necessary, // reduce time step to make it converge, but then restore time step // size to its original value. Hermes::Mixins::Loggable::Static::info("Performing Picard's iteration (tau = %g days):", time_step); @@ -459,36 +438,29 @@ int main(int argc, char* argv[]) /*** ADAPTIVITY ***/ - // Project the fine mesh solution on the coarse mesh-> + // Project the fine mesh solution on the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error calculation."); if(space->get_mesh() == NULL) throw Hermes::Exceptions::Exception("it is NULL"); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(space); + adaptivity.set_space(space); // Calculate error estimate wrt. fine mesh solution. - err_est_rel = adaptivity->calc_err_est(sln, ref_sln) * 100; + err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, space_err_est_rel: %g%%", Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); - // If space_err_est too large, adapt the mesh-> + // If space_err_est too large, adapt the mesh. if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - if (Space::get_num_dofs(space) >= NDOF_STOP) { - done = true; - break; - } + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); as++; } - - delete adaptivity; - } while (!done); diff --git a/2d-advanced/richards/capillary-barrier-rk/extras.cpp b/2d-advanced/richards/capillary-barrier-rk/extras.cpp index c16a08e..70b720d 100644 --- a/2d-advanced/richards/capillary-barrier-rk/extras.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/extras.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace std; diff --git a/2d-advanced/richards/capillary-barrier-rk/main.cpp b/2d-advanced/richards/capillary-barrier-rk/main.cpp index 26448fe..15a8e87 100644 --- a/2d-advanced/richards/capillary-barrier-rk/main.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load(mesh_file, basemesh); diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp index 8f81a8b..79499eb 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp @@ -17,12 +17,12 @@ Ord CustomInitialCondition::ord(Ord x, Ord y) const return exp(-20*(x*x + y*y)); } -MeshFunction >* CustomInitialCondition::clone() const +MeshFunction* CustomInitialCondition::clone() const { return new CustomInitialCondition(this->mesh); } -CustomWeakFormGPRK::CustomWeakFormGPRK(double h, double m, double g, double omega) : WeakForm >(1) +CustomWeakFormGPRK::CustomWeakFormGPRK(double h, double m, double g, double omega) : WeakForm(1) { // Jacobian volumetric part. add_matrix_form(new CustomFormMatrixFormVol(0, 0, h, m, g, omega)); @@ -47,8 +47,8 @@ Scalar CustomWeakFormGPRK::CustomFormMatrixFormVol::matrix_form_rk(int n, double return result; } -std::complex CustomWeakFormGPRK::CustomFormMatrixFormVol::value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const +std::complex CustomWeakFormGPRK::CustomFormMatrixFormVol::value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const { return matrix_form_rk >(n, wt, u_ext, u, v, e, ext); } @@ -59,7 +59,7 @@ Ord CustomWeakFormGPRK::CustomFormMatrixFormVol::ord(int n, double *wt, Func(n, wt, u_ext, u, v, e, ext); } -MatrixFormVol >* CustomWeakFormGPRK::CustomFormMatrixFormVol::clone() const +MatrixFormVol* CustomWeakFormGPRK::CustomFormMatrixFormVol::clone() const { return new CustomFormMatrixFormVol(*this); } @@ -81,8 +81,8 @@ Scalar CustomWeakFormGPRK::CustomFormVectorFormVol::vector_form_rk(int n, double return result; } -std::complex CustomWeakFormGPRK::CustomFormVectorFormVol::value(int n, double *wt, Func > *u_ext[], Func *v, Geom *e, - Func > **ext) const +std::complex CustomWeakFormGPRK::CustomFormVectorFormVol::value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func **ext) const { return vector_form_rk >(n, wt, u_ext, v, e, ext); } @@ -92,7 +92,7 @@ Ord CustomWeakFormGPRK::CustomFormVectorFormVol::ord(int n, double *wt, Func(n, wt, u_ext, v, e, ext); } -VectorFormVol >* CustomWeakFormGPRK::CustomFormVectorFormVol::clone() const +VectorFormVol* CustomWeakFormGPRK::CustomFormVectorFormVol::clone() const { return new CustomFormVectorFormVol(*this); } diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h index cd993ab..3c2abe9 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h @@ -7,11 +7,12 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +typedef std::complex complex; -class CustomInitialCondition : public ExactSolutionScalar > +class CustomInitialCondition : public ExactSolutionScalar { public: - CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar >(mesh) {}; + CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) {}; virtual void derivatives (double x, double y, std::complex & dx, std::complex & dy) const; @@ -19,59 +20,59 @@ class CustomInitialCondition : public ExactSolutionScalar > virtual Ord ord(Ord x, Ord y) const; - virtual MeshFunction >* clone() const; + virtual MeshFunction* clone() const; }; /* Weak forms */ -class CustomWeakFormGPRK : public WeakForm > +class CustomWeakFormGPRK : public WeakForm { public: CustomWeakFormGPRK(double h, double m, double g, double omega); private: - class CustomFormMatrixFormVol : public MatrixFormVol > + class CustomFormMatrixFormVol : public MatrixFormVol { public: CustomFormMatrixFormVol(int i, int j, double h, double m, double g, double omega) - : MatrixFormVol >(i, j), h(h), m(m), g(g), omega(omega) {}; + : MatrixFormVol(i, j), h(h), m(m), g(g), omega(omega) {}; template Scalar matrix_form_rk(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; - virtual MatrixFormVol >* clone() const; + virtual MatrixFormVol* clone() const; // Members. double h, m, g, omega; }; - class CustomFormVectorFormVol : public VectorFormVol > + class CustomFormVectorFormVol : public VectorFormVol { public: CustomFormVectorFormVol(int i, double h, double m, double g, double omega) - : VectorFormVol >(i), h(h), m(m), g(g), omega(omega) {}; + : VectorFormVol(i), h(h), m(m), g(g), omega(omega) {}; template Scalar vector_form_rk(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *v, Geom *e, - Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual VectorFormVol >* clone() const; + virtual VectorFormVol* clone() const; // Members. double h, m, g, omega; diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp index fb2c266..6533c88 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -40,37 +40,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double SPACE_ERR_TOL = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double ERR_STOP = 1e-1; // Temporal adaptivity. // This flag decides whether adaptive time stepping will be done. @@ -89,7 +68,7 @@ const double TIME_STEP_INC_RATIO = 1.1; const double TIME_STEP_DEC_RATIO = 0.8; // Newton's method. -// Stopping criterion for Newton on coarse mesh-> +// Stopping criterion for Newton on coarse mesh. const double NEWTON_TOL_COARSE = 0.01; // Stopping criterion for Newton on fine mesh-> const double NEWTON_TOL_FINE = 0.05; @@ -137,7 +116,7 @@ int main(int argc, char* argv[]) ADAPTIVE_TIME_STEP_ON = false; } - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", basemesh); @@ -146,8 +125,8 @@ int main(int argc, char* argv[]) // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); - // Convert initial condition into a Solution >. - MeshFunctionSharedPtr > psi_time_prev(new CustomInitialCondition(mesh)); + // Convert initial condition into a Solution. + MeshFunctionSharedPtr psi_time_prev(new CustomInitialCondition(mesh)); // Initialize the weak formulation. double current_time = 0; @@ -156,19 +135,19 @@ int main(int argc, char* argv[]) CustomWeakFormGPRK wf(h, m, g, omega); // Initialize boundary conditions. - DefaultEssentialBCConst > bc_essential("Bdy", 0.0); - EssentialBCs > bcs(&bc_essential); + DefaultEssentialBCConst bc_essential("Bdy", 0.0); + EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + SpaceSharedPtr space(new H1Space (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. - DiscreteProblem > dp(&wf, space); + DiscreteProblem dp(&wf, space); // Create a refinement selector. - H1ProjBasedSelector > selector(CAND_LIST); + H1ProjBasedSelector selector(CAND_LIST); // Visualize initial condition. char title[100]; @@ -224,29 +203,29 @@ int main(int argc, char* argv[]) default: throw Hermes::Exceptions::Exception("Wrong global derefinement method."); } - ndof = Space >::get_num_dofs(space); + ndof = Space::get_num_dofs(space); } Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); // Spatial adaptivity loop. Note: psi_time_prev must not be // changed during spatial adaptivity. - MeshFunctionSharedPtr > ref_sln(new Solution >()); - MeshFunctionSharedPtr > time_error_fn(new Solution >); + MeshFunctionSharedPtr ref_sln(new Solution()); + MeshFunctionSharedPtr time_error_fn(new Solution); bool done = false; int as = 1; double err_est; do { - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space >::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); - SpaceSharedPtr > ref_space = refSpaceCreator.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - // Initialize discrete problem on reference mesh-> - DiscreteProblem >* ref_dp = new DiscreteProblem >(&wf, ref_space); + // Initialize discrete problem on reference mesh. + DiscreteProblem* ref_dp = new DiscreteProblem(&wf, ref_space); - RungeKutta > runge_kutta(&wf, ref_space, &bt); + RungeKutta runge_kutta(&wf, ref_space, &bt); // Runge-Kutta step on the fine mesh-> Hermes::Mixins::Loggable::Static::info("Runge-Kutta time step on fine mesh (t = %g s, time step = %g s, stages: %d).", @@ -285,8 +264,8 @@ int main(int argc, char* argv[]) time_error_view.show(abs_tef); - rel_err_time = Global >::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / - Global >::calc_norm(ref_sln.get(), HERMES_H1_NORM) * 100; + rel_err_time = Global::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / + Global::calc_norm(ref_sln.get(), HERMES_H1_NORM) * 100; if (ADAPTIVE_TIME_STEP_ON == false) Hermes::Mixins::Loggable::Static::info("rel_err_time: %g%%", rel_err_time); } @@ -322,14 +301,14 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Spatial adaptivity step %d.", as); - // Project the fine mesh solution onto the coarse mesh-> - MeshFunctionSharedPtr > sln(new Solution >); + // Project the fine mesh solution onto the coarse mesh. + MeshFunctionSharedPtr sln(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); - OGProjection > ogProjection; ogProjection.project_global(space, ref_sln, sln); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Show spatial error. sprintf(title, "Spatial error est, spatial adaptivity step %d", as); - MeshFunctionSharedPtr > space_error_fn(new DiffFilter >(Hermes::vector > >(ref_sln, sln))); + MeshFunctionSharedPtr space_error_fn(new DiffFilter(Hermes::vector >(ref_sln, sln))); space_error_view.set_title(title); space_error_view.show_mesh(false); @@ -341,29 +320,26 @@ int main(int argc, char* argv[]) // Calculate element errors and spatial error estimate. Hermes::Mixins::Loggable::Static::info("Calculating spatial error estimate."); - Adapt >* adaptivity = new Adapt >(space); - double err_rel_space = adaptivity->calc_err_est(sln, ref_sln) * 100; + Adapt adaptivity(space); + double err_rel_space = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_rel_space: %g%%", - Space >::get_num_dofs(space), Space >::get_num_dofs(ref_space), err_rel_space); + Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_rel_space); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_rel_space < SPACE_ERR_TOL) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (Space >::get_num_dofs(space) >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(&selector); + + // Increase the counter of performed adaptivity steps. + as++; } // Clean up. - delete adaptivity; + delete ref_dp; } while (done == false); diff --git a/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp b/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp index da471c6..dffaad1 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp @@ -17,12 +17,12 @@ Ord CustomInitialCondition::ord(Ord x, Ord y) const return exp(-10*(x*x + y*y)); } -MeshFunction >* CustomInitialCondition::clone() const +MeshFunction* CustomInitialCondition::clone() const { return new CustomInitialCondition(this->mesh); } -CustomWeakFormGPRK::CustomWeakFormGPRK(double h, double m, double g, double omega) : WeakForm >(1) +CustomWeakFormGPRK::CustomWeakFormGPRK(double h, double m, double g, double omega) : WeakForm(1) { // Jacobian volumetric part. add_matrix_form(new CustomFormMatrixFormVol(0, 0, h, m, g, omega)); @@ -47,8 +47,8 @@ Scalar CustomWeakFormGPRK::CustomFormMatrixFormVol::matrix_form_rk(int n, double return result; } -std::complex CustomWeakFormGPRK::CustomFormMatrixFormVol::value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const +std::complex CustomWeakFormGPRK::CustomFormMatrixFormVol::value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const { return matrix_form_rk >(n, wt, u_ext, u, v, e, ext); } @@ -59,7 +59,7 @@ Ord CustomWeakFormGPRK::CustomFormMatrixFormVol::ord(int n, double *wt, Func(n, wt, u_ext, u, v, e, ext); } -MatrixFormVol >* CustomWeakFormGPRK::CustomFormMatrixFormVol::clone() const +MatrixFormVol* CustomWeakFormGPRK::CustomFormMatrixFormVol::clone() const { return new CustomFormMatrixFormVol(*this); } @@ -81,8 +81,8 @@ Scalar CustomWeakFormGPRK::CustomFormVectorFormVol::vector_form_rk(int n, double return result; } -std::complex CustomWeakFormGPRK::CustomFormVectorFormVol::value(int n, double *wt, Func > *u_ext[], Func *v, Geom *e, - Func > **ext) const +std::complex CustomWeakFormGPRK::CustomFormVectorFormVol::value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func **ext) const { return vector_form_rk >(n, wt, u_ext, v, e, ext); } @@ -92,7 +92,7 @@ Ord CustomWeakFormGPRK::CustomFormVectorFormVol::ord(int n, double *wt, Func(n, wt, u_ext, v, e, ext); } -VectorFormVol >* CustomWeakFormGPRK::CustomFormVectorFormVol::clone() const +VectorFormVol* CustomWeakFormGPRK::CustomFormVectorFormVol::clone() const { return new CustomFormVectorFormVol(*this); } diff --git a/2d-advanced/schroedinger/gross-pitaevski/definitions.h b/2d-advanced/schroedinger/gross-pitaevski/definitions.h index cac8a82..c511fa2 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski/definitions.h @@ -7,72 +7,73 @@ using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; +typedef std::complex complex; /* Initial condition */ -class CustomInitialCondition : public ExactSolutionScalar > +class CustomInitialCondition : public ExactSolutionScalar { public: - CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar >(mesh) {}; + CustomInitialCondition(MeshSharedPtr mesh) : ExactSolutionScalar(mesh) {}; virtual void derivatives (double x, double y, std::complex & dx, std::complex & dy) const; virtual std::complex value (double x, double y) const; virtual Ord ord(Ord x, Ord y) const; - virtual MeshFunction >* clone() const; + virtual MeshFunction* clone() const; }; /* Weak forms */ -class CustomWeakFormGPRK : public WeakForm > +class CustomWeakFormGPRK : public WeakForm { public: CustomWeakFormGPRK(double h, double m, double g, double omega); private: - class CustomFormMatrixFormVol : public MatrixFormVol > + class CustomFormMatrixFormVol : public MatrixFormVol { public: CustomFormMatrixFormVol(int i, int j, double h, double m, double g, double omega) - : MatrixFormVol >(i, j), h(h), m(m), g(g), omega(omega) {}; + : MatrixFormVol(i, j), h(h), m(m), g(g), omega(omega) {}; template Scalar matrix_form_rk(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *u, - Func *v, Geom *e, Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const; - virtual MatrixFormVol >* clone() const; + virtual MatrixFormVol* clone() const; // Members. double h, m, g, omega; }; - class CustomFormVectorFormVol : public VectorFormVol > + class CustomFormVectorFormVol : public VectorFormVol { public: CustomFormVectorFormVol(int i, double h, double m, double g, double omega) - : VectorFormVol >(i), h(h), m(m), g(g), omega(omega) {}; + : VectorFormVol(i), h(h), m(m), g(g), omega(omega) {}; template Scalar vector_form_rk(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual std::complex value(int n, double *wt, Func > *u_ext[], Func *v, Geom *e, - Func > **ext) const; + virtual std::complex value(int n, double *wt, Func *u_ext[], Func *v, Geom *e, + Func **ext) const; virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const; - virtual VectorFormVol >* clone() const; + virtual VectorFormVol* clone() const; // Members. double h, m, g, omega; diff --git a/2d-advanced/schroedinger/gross-pitaevski/main.cpp b/2d-advanced/schroedinger/gross-pitaevski/main.cpp index 32150b7..2067992 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -77,9 +77,9 @@ int main(int argc, char* argv[]) // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); - // Convert initial condition into a Solution >. - MeshFunctionSharedPtr > psi_time_prev(new CustomInitialCondition(mesh)); - MeshFunctionSharedPtr > psi_time_new(new Solution >(mesh)); + // Convert initial condition into a Solution. + MeshFunctionSharedPtr psi_time_prev(new CustomInitialCondition(mesh)); + MeshFunctionSharedPtr psi_time_new(new Solution(mesh)); // Initialize the weak formulation. double current_time = 0; @@ -87,16 +87,16 @@ int main(int argc, char* argv[]) CustomWeakFormGPRK wf(h, m, g, omega); // Initialize boundary conditions. - DefaultEssentialBCConst > bc_essential("Bdy", 0.0); - EssentialBCs > bcs(&bc_essential); + DefaultEssentialBCConst bc_essential("Bdy", 0.0); + EssentialBCs bcs(&bc_essential); // Create an H1 space with default shapeset. - SpaceSharedPtr > space(new H1Space > (mesh, &bcs, P_INIT)); + SpaceSharedPtr space(new H1Space (mesh, &bcs, P_INIT)); int ndof = space->get_num_dofs(); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the FE problem. - DiscreteProblem > dp(&wf, space); + DiscreteProblem dp(&wf, space); // Initialize views. ScalarView sview_real("Solution - real part", new WinGeom(0, 0, 600, 500)); @@ -105,7 +105,7 @@ int main(int argc, char* argv[]) sview_imag.fix_scale_width(80); // Initialize Runge-Kutta time stepping. - RungeKutta > runge_kutta(&wf, space, &bt); + RungeKutta runge_kutta(&wf, space, &bt); // Time stepping: int ts = 1; diff --git a/2d-advanced/wave-equation/wave-1/main.cpp b/2d-advanced/wave-equation/wave-1/main.cpp index 2f7062c..ab6d6f8 100644 --- a/2d-advanced/wave-equation/wave-1/main.cpp +++ b/2d-advanced/wave-equation/wave-1/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index 7146f69..0b465e3 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -27,46 +27,25 @@ const int INIT_REF_NUM = 0; const int INIT_REF_NUM_BDY = 5; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 0.5; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +const double THRESHOLD = 0.5; + +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Problem parameters. const double K = 1e2; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square.mesh", mesh); @@ -115,7 +94,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -126,7 +105,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -150,17 +129,20 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; - + adaptivity.set_space(space); + // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; + cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -188,12 +170,9 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) - done = true; - else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index faa1f66..02d7df2 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -27,38 +27,16 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 0.5; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Problem parameters. // Slope of the layer. @@ -66,7 +44,7 @@ double slope = 60; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. @@ -119,7 +97,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -130,7 +108,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -154,16 +132,17 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + adaptivity.set_space(space); + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -192,12 +171,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index f2369a9..3499ff8 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -26,42 +26,20 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-2; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("lshape.mesh", mesh); @@ -107,7 +85,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -118,7 +96,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -142,16 +120,17 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; + + // Calculate element errors and total error estimate. + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -180,12 +159,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index 507be8f..48a5935 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -39,38 +39,16 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// fine mesh and coarse mesh solution in percent). -const double ERR_STOP = 1.0; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Newton's method // Stopping criterion for Newton on fine mesh-> @@ -115,7 +93,7 @@ int main(int argc, char* argv[]) if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", basemesh); @@ -187,7 +165,7 @@ int main(int argc, char* argv[]) do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -216,7 +194,7 @@ int main(int argc, char* argv[]) e.print_msg(); } - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. MeshFunctionSharedPtr sln_coarse(new Solution); Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh for error estimation."); OGProjection ogProjection; @@ -224,29 +202,22 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt* adaptivity = new Adapt(space); - double err_est_rel_total = adaptivity->calc_err_est(sln_coarse, sln_time_new) * 100; + adaptivity.set_space(space); + errorCalculator.calculate_errors(sln_coarse, sln_time_new); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_ref: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel_total); - // If err_est too large, adapt the mesh-> + // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh->"); - done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); - - if (space->get_num_dofs() >= NDOF_STOP) - done = true; - else - // Increase the counter of performed adaptivity steps. - as++; + Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); + done = adaptivity.adapt(&selector); + as++; } - - // Clean up. - delete adaptivity; } while (done == false); diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index 595dfee..e9310c3 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -24,42 +24,20 @@ int P_INIT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-4; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -102,7 +80,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -113,7 +91,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -137,16 +115,17 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + adaptivity.set_space(space); + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -175,12 +154,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 4d5e00b..5343047 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -23,42 +23,20 @@ int P_INIT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-4; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -100,7 +78,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -111,7 +89,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -135,23 +113,23 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel_total = errorCalculator.get_total_error_squared() * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel_total, err_exact_rel_total); // Time measurement. cpu_time.tick(); @@ -162,23 +140,23 @@ int main(int argc, char* argv[]) oview.show(space); // Add entry to DOF and CPU convergence graphs. - graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel_total); graph_dof_est.save("conv_dof_est.dat"); - graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.add_values(accum_time, err_est_rel_total); graph_cpu_est.save("conv_cpu_est.dat"); - graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel_total); graph_dof_exact.save("conv_dof_exact.dat"); - graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.add_values(accum_time, err_exact_rel_total); graph_cpu_exact.save("conv_cpu_exact.dat"); cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel_total < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index 5f22e55..2c33f6c 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -23,42 +23,20 @@ int P_INIT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-4; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); @@ -100,7 +78,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -111,7 +89,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -135,16 +113,16 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); - // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; + + errorCalculator.calculate_errors(sln, ref_sln, true); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -173,12 +151,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index 3be9e90..d5a1219 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -25,42 +25,20 @@ int P_INIT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 0; -// Predefined list of element refinement candidates. Possible values are -// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, -// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; -// Maximum allowed level of hanging nodes: -// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), -// MESH_REGULARITY = 1 ... at most one-level hanging nodes, -// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. -// Note that regular meshes are not supported, this is due to -// their notoriously bad performance. -const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1.0; -// Stopping criterion for adaptivity (rel. error tolerance between the -// reference mesh and coarse mesh solution in percent). -const double ERR_STOP = 1e-4; -// Adaptivity process stops when the number of degrees of freedom grows -// over this limit. This is to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 60000; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -Hermes::MatrixSolverType matrix_solver = Hermes::SOLVER_UMFPACK; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; int main(int argc, char* argv[]) { - // Load the mesh-> + // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); @@ -110,7 +88,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -122,7 +100,7 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); cpu_time.tick(); - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); // Assemble the discrete problem. DiscreteProblem dp(&wf, ref_space); @@ -146,16 +124,18 @@ int main(int argc, char* argv[]) cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); - // Project the fine mesh solution onto the coarse mesh-> + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - Adapt adaptivity(space); - double err_est_rel = adaptivity.calc_err_est(sln, ref_sln) * 100; + Adapt adaptivity(space, &errorCalculator, &stoppingCriterion); + + errorCalculator.calculate_errors(sln, exact_sln, false); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100; - // Calculate exact error. - double err_exact_rel = Global::calc_rel_error(sln.get(), exact_sln.get(), HERMES_H1_NORM) * 100; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -184,12 +164,12 @@ int main(int argc, char* argv[]) cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - // If err_est too large, adapt the mesh-> The NDOF test must be here, so that the solution may be visualized + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized // after ending due to this criterion. - if (err_exact_rel < ERR_STOP || space->get_num_dofs() >= NDOF_STOP) + if (err_exact_rel < ERR_STOP) done = true; else - done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY); + done = adaptivity.adapt(&selector); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index 7858760..f001a4d 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -43,7 +43,6 @@ const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; - int main(int argc, char* argv[]) { // Load the mesh. @@ -78,7 +77,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -98,7 +97,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -139,13 +138,13 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator errorCalculator(errorType, 1); + errorCalculator.calculate_errors(sln, exact_sln); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; - Adapt adaptivity(space, &error_calculator); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index a373b27..cf2abd5 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -163,13 +163,13 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator errorCalculator(errorType, 1); + errorCalculator.calculate_errors(sln, exact_sln); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; - Adapt adaptivity(space, &error_calculator); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); cpu_time.tick(); diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 4fa2db5..0f9a386 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -46,16 +46,16 @@ const int P_INIT_V = 2; const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.6; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) Hermes::vector >exact_slns(exact_u, exact_v); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView s_view_u("Solution for u", new WinGeom(0, 0, 440, 350)); @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreatorU(u_mesh); MeshSharedPtr ref_u_mesh = refMeshCreatorU.create_ref_mesh(); @@ -203,14 +203,10 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(spaces, ref_slns, slns); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 2); - error_calculator.calculate_errors(slns, exact_slns); - double err_exact_rel_total = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(slns, ref_slns); - double err_est_rel_total = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(spaces, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); + errorCalculator.calculate_errors(slns, exact_slns); + double err_exact_rel_total = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(slns, ref_slns); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100.0; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index 0c76a2a..d770ae5 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -100,8 +100,8 @@ int main(int argc, char* argv[]) linear_solver.set_UMFPACK_output(true, false); // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); + DefaultErrorCalculator errorCalculator(errorType, 1); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "%s.csv", resultStringIdentification); @@ -196,7 +196,7 @@ int main(int argc, char* argv[]) linear_solver, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index da22f5d..987e19e 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -25,14 +25,16 @@ const int P_INIT = 1; const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. -CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; +CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e-1; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -76,7 +78,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 320, 600)); @@ -89,11 +91,6 @@ int main(int argc, char* argv[]) NewtonSolver newton; newton.set_weak_formulation(&wf); - // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); - sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); std::ofstream data(filename); data.precision(10); @@ -178,6 +175,9 @@ int main(int argc, char* argv[]) int cache_record_found; int cache_record_found_reinit; int cache_record_not_found; + double FactorizationSize; + double PeakMemoryUsage; + double Flops; // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; @@ -192,14 +192,14 @@ int main(int argc, char* argv[]) mesh, space, sln, - selector, + &selector, is_p(CAND_LIST) ? 1 : 0, ref_sln, cpu_time, newton, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, @@ -209,7 +209,10 @@ int main(int argc, char* argv[]) cache_record_found, cache_record_found_reinit, cache_record_not_found, - exact_error_reached)) + exact_error_reached, + FactorizationSize, + PeakMemoryUsage, + Flops)) { dof_cumulative += dof_reached; diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 18f7ac4..58ec0bf 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -89,8 +89,8 @@ int main(int argc, char* argv[]) char* filename = new char[1000]; // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); + DefaultErrorCalculator errorCalculator(errorType, 1); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "%s.csv", resultStringIdentification); @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) newton, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index c35793a..fc77fa8 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -94,8 +94,8 @@ int main(int argc, char* argv[]) char* filename = new char[1000]; // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); + DefaultErrorCalculator errorCalculator(errorType, 1); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "%s.csv", resultStringIdentification); @@ -195,7 +195,7 @@ int main(int argc, char* argv[]) newton, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 260a62a..93148f4 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -89,8 +89,8 @@ int main(int argc, char* argv[]) char* filename = new char[1000]; // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); + DefaultErrorCalculator errorCalculator(errorType, 1); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "%s.csv", resultStringIdentification); @@ -189,7 +189,7 @@ int main(int argc, char* argv[]) newton, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index 35ca366..b757d6f 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -35,16 +35,16 @@ const int P_INIT = 1; const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -123,7 +123,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -143,7 +143,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -184,14 +184,10 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); + errorCalculator.calculate_errors(sln, exact_sln); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 9110227..92b2908 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #define HERMES_REPORT_FILE "application.log" #include "definitions.h" @@ -31,16 +31,16 @@ const int P_INIT = 2; const int INIT_REF_NUM = 0; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -138,14 +138,12 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); + errorCalculator.calculate_errors(sln, exact_sln); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + + adaptivity.set_space(space); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index e210fb5..42af7b0 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -35,16 +35,16 @@ const int P_INIT = 2; const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); - +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO_H; -// Maximum allowed level of hanging nodes. -const int MESH_REGULARITY = -1; +const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-1; -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(CAND_LIST); + MySelector selector(hXORpSelectionBasedOnError); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -138,14 +138,12 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator error_calculator(errorType, 1); - error_calculator.calculate_errors(sln, exact_sln); - double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - - Adapt adaptivity(space, &error_calculator); - adaptivity.set_strategy(stoppingCriterion); + errorCalculator.calculate_errors(sln, exact_sln); + double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + + adaptivity.set_space(space); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index d752459..96a2425 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -1,4 +1,4 @@ -#define HERMES_REPORT_ALL + #include "definitions.h" using namespace RefinementSelectors; @@ -99,8 +99,8 @@ int main(int argc, char* argv[]) char* filename = new char[1000]; // Adaptivity loop. - DefaultErrorCalculator error_calculator(errorType, 1); - Adapt adaptivity(space, &error_calculator); + DefaultErrorCalculator errorCalculator(errorType, 1); + Adapt adaptivity(space, &errorCalculator); adaptivity.set_strategy(stoppingCriterion); sprintf(filename, "%s.csv", resultStringIdentification); @@ -212,7 +212,7 @@ int main(int argc, char* argv[]) newton, sview, oview, - error_calculator, + errorCalculator, adaptivity, as, error_stop, diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index 4cb4df5..921b33d 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -42,7 +42,7 @@ bool adaptive_step_single_space( Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, - ErrorCalculator& error_calculator, + ErrorCalculator& errorCalculator, Adapt& adaptivity, int& as, double error_stop, @@ -61,7 +61,7 @@ bool adaptive_step_single_space( { try { - // Construct globally refined reference mesh and setup reference space-> + // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -89,11 +89,11 @@ bool adaptive_step_single_space( double err_exact_rel; if(exact_sln) { - error_calculator.calculate_errors(sln, exact_sln); - err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, exact_sln); + err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; } - error_calculator.calculate_errors(sln, ref_sln); - double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + errorCalculator.calculate_errors(sln, ref_sln); + double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; // Report results - skip time. cpu_time.tick(); diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index 308891f..f3bd05b 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -222,7 +222,7 @@ bool adaptive_step_single_space( Solver& solver, Views::ScalarView& sview, Views::OrderView & oview, - ErrorCalculator& error_calculator, + ErrorCalculator& errorCalculator, Adapt& adaptivity, int& as, double error_stop, diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d36e8..fabc0c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,24 +26,25 @@ project(hermes_examples) # set(MPI_LIBRARIES -lmpi) # set(MPI_INCLUDE_PATH /usr/include/openmpi - -SET(WITH_1d NO) + # By default all examples are turned on. + # This can be changed in your CMake.vars file. + SET(WITH_1d YES) SET(WITH_2d-advanced YES) - SET(WITH_acoustics NO) - SET(WITH_advection-diffusion-reaction NO) - SET(WITH_heat-transfer NO) + SET(WITH_acoustics YES) + SET(WITH_advection-diffusion-reaction YES) + SET(WITH_heat-transfer YES) SET(WITH_helmholtz YES) SET(WITH_euler YES) SET(WITH_elasticity-linear YES) SET(WITH_maxwell YES) - SET(WITH_navier-stokes NO) - SET(WITH_nernst-planck NO) - SET(WITH_neutronics NO) - SET(WITH_richards NO) - SET(WITH_schroedinger NO) - SET(WITH_wave-equation NO) - SET(WITH_2d-benchmarks-general NO) - SET(WITH_2d-benchmarks-nist NO) + SET(WITH_navier-stokes YES) + SET(WITH_nernst-planck YES) + SET(WITH_neutronics YES) + SET(WITH_richards YES) + SET(WITH_schroedinger YES) + SET(WITH_wave-equation YES) + SET(WITH_2d-benchmarks-general YES) + SET(WITH_2d-benchmarks-nist YES) # Allow to override the default values in CMake.vars: include(CMake.vars OPTIONAL) From b57a90ef641a443ae674d0ffe1979d7e9145c02b Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 30 May 2013 15:41:38 +0200 Subject: [PATCH 37/64] Fix some comments. --- 1d/poisson/main.cpp | 4 ++-- 2d-advanced/acoustics/apartment/main.cpp | 4 ++-- 2d-advanced/acoustics/horn-axisym/main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/1d/poisson/main.cpp b/1d/poisson/main.cpp index 7f1b920..545563e 100644 --- a/1d/poisson/main.cpp +++ b/1d/poisson/main.cpp @@ -93,8 +93,8 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Views::Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(sln, "sln->vtk", "Temperature", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); + lin.save_solution_vtk(sln, "sln.vtk", "Temperature", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); // Output mesh and element orders in VTK format. Views::Orderizer ord; diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index f3c2ae2..12db971 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -174,8 +174,8 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); + lin.save_solution_vtk(ref_mag, "sln.vtk", "Acoustic pressure", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index fc8d1e0..603395e 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -176,8 +176,8 @@ int main(int argc, char* argv[]) // Output solution in VTK format. Linearizer lin; bool mode_3D = true; - lin.save_solution_vtk(ref_mag, "sln->vtk", "Acoustic pressure", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln->vtk"); + lin.save_solution_vtk(ref_mag, "sln.vtk", "Acoustic pressure", mode_3D); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); // Wait for all views to be closed. View::wait(); From ec08c58427e9c2a6476791fb0b9c7d545de01511 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 10 Jun 2013 13:09:04 +0200 Subject: [PATCH 38/64] Work on CMMSE outputs. --- 2d-advanced/acoustics/apartment/main.cpp | 28 ++++++++++++------- .../acoustics/wave-propagation/main.cpp | 2 -- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 16 +++++++---- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index 12db971..3002563 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -19,13 +19,8 @@ const int INIT_REF_NUM = 0; const int P_INIT = 2; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +const double THRESHOLD = 0.75; + // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. @@ -49,9 +44,12 @@ int main(int argc, char* argv[]) MeshReaderH2D mloader; mloader.load("domain.mesh", mesh); - //MeshView mv("Initial mesh", new WinGeom(0, 0, 400, 400)); - //mv.show(mesh); - //View::wait(HERMES_WAIT_KEYPRESS); + // Error calculation & adaptivity. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Adaptivity processor class. + Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); @@ -76,15 +74,18 @@ int main(int argc, char* argv[]) // Initialize views. ScalarView sview("Acoustic pressure", new WinGeom(0, 0, 600, 350)); + ScalarView eview("Error", new WinGeom(0, 370, 600, 350)); sview.show_mesh(false); sview.fix_scale_width(50); OrderView oview("Polynomial orders", new WinGeom(610, 0, 600, 350)); + ScalarView ref_view("Refined elements", new WinGeom(610, 370, 600, 350)); // DOF and CPU convergence graphs initialization. SimpleGraph graph_dof, graph_cpu; // Adaptivity loop: int as = 1; + adaptivity.set_space(space); bool done = false; do { @@ -137,6 +138,8 @@ int main(int argc, char* argv[]) errorCalculator.calculate_errors(sln, ref_sln); double err_est_rel = errorCalculator.get_total_error_squared() * 100; + eview.show(errorCalculator.get_errorMeshFunction()); + // Report results. Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); @@ -156,6 +159,11 @@ int main(int argc, char* argv[]) { Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); done = adaptivity.adapt(&selector); + ref_view.show(adaptivity.get_refinementInfoMeshFunction()); + cpu_time.tick(); + char* cpu_time_string = cpu_time.accumulated_str().c_str(); + ref_view.titl + ref_view.set_title(); } // Increase counter. diff --git a/2d-advanced/acoustics/wave-propagation/main.cpp b/2d-advanced/acoustics/wave-propagation/main.cpp index 824431d..38bef91 100644 --- a/2d-advanced/acoustics/wave-propagation/main.cpp +++ b/2d-advanced/acoustics/wave-propagation/main.cpp @@ -11,8 +11,6 @@ const double time_step = 4e-5; int main(int argc, char* argv[]) { - Hermes2DApi.set_integral_param_value(numThreads,1); - // Load the mesh. MeshSharedPtr mesh(new Mesh); Hermes::vector meshes; diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index f7d1486..6617754 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -40,9 +40,9 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 1; +const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; +const int INIT_REF_NUM = 2; // CFL value. double CFL_NUMBER = 0.9; // Initial time step. @@ -64,10 +64,10 @@ const double THRESHOLD = 0.6; // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_H_ISO; +CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.005; +const double ERR_STOP = 0.01; // Adaptivity process stops when the number of degrees of freedom grows over // this limit. This is mainly to prevent h-adaptivity to go on forever. @@ -155,12 +155,15 @@ int main(int argc, char* argv[]) Mach_number_view.show_contours(.02); Mach_number_view.show_mesh(false); VectorView velocity_view("Velocity", new WinGeom(0, 330, 600, 300)); + OrderView order_view("Orders", new WinGeom(700, 330, 600, 300)); #pragma endregion #pragma region 4. Adaptivity setup. // Initialize refinement selector. L2ProjBasedSelector selector(CAND_LIST); - selector.set_error_weights(1.0, 1.0, 1.0); + selector.set_dof_score_exponent(2.0); + + //selector.set_error_weights(1.0, 1.0, 1.0); // Error calculation. DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); @@ -265,6 +268,8 @@ int main(int argc, char* argv[]) flux_limiter->limit_according_to_detector(spaces); flux_limiter->get_limited_solutions(rslns); + + delete flux_limiter; } #pragma endregion @@ -311,6 +316,7 @@ int main(int argc, char* argv[]) pressure_view.show(pressure, 1); Mach_number_view.show(Mach_number, 1); velocity_view.show(rsln_rho_v_x, rsln_rho_v_y); + order_view.show((ref_spaces)[0]); } } #pragma endregion From f8069d85cde88ec8260fd902cfb688a912f15d3d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 11 Jun 2013 09:41:41 +0200 Subject: [PATCH 39/64] Add missing cmake file. --- 2d-advanced/acoustics/wave-propagation/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 2d-advanced/acoustics/wave-propagation/CMakeLists.txt diff --git a/2d-advanced/acoustics/wave-propagation/CMakeLists.txt b/2d-advanced/acoustics/wave-propagation/CMakeLists.txt new file mode 100644 index 0000000..ea64707 --- /dev/null +++ b/2d-advanced/acoustics/wave-propagation/CMakeLists.txt @@ -0,0 +1,3 @@ +project(acoustics-wave-propagation) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp definitions.h) +set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file From 3976f5bb0cbb851540b9d261441c711a052b4273 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 11 Jun 2013 18:23:50 +0200 Subject: [PATCH 40/64] Finish with CMMSE outputs. --- 2d-advanced/acoustics/apartment/main.cpp | 259 ++++++++++++++++-- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 14 +- 2d-benchmarks-nist/05-battery/main.cpp | 2 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 25 +- 2d-benchmarks-nist/NIST-util.cpp | 6 +- 5 files changed, 251 insertions(+), 55 deletions(-) diff --git a/2d-advanced/acoustics/apartment/main.cpp b/2d-advanced/acoustics/apartment/main.cpp index 3002563..c3119d8 100644 --- a/2d-advanced/acoustics/apartment/main.cpp +++ b/2d-advanced/acoustics/apartment/main.cpp @@ -19,7 +19,7 @@ const int INIT_REF_NUM = 0; const int P_INIT = 2; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.75; +const double THRESHOLD = 0.25; // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO; @@ -33,8 +33,210 @@ const double OMEGA = 2 * M_PI * FREQ; const double SOUND_SPEED = 353.0; const std::complex P_SOURCE(1.0, 0.0); +enum hpAdaptivityStrategy +{ + noSelectionH = 0, + noSelectionHP = 1, + hXORpSelectionBasedOnError = 2, + hORpSelectionBasedOnDOFs = 3, + isoHPSelectionBasedOnDOFs = 4, + anisoHPSelectionBasedOnDOFs = 5 +}; + +class MySelector : public H1ProjBasedSelector +{ +public: + MySelector(hpAdaptivityStrategy strategy) : H1ProjBasedSelector(cand_list), strategy(strategy) + { + if(strategy == hXORpSelectionBasedOnError) + { + //this->set_error_weights(1.0,1.0,1.0); + } + } +private: + bool select_refinement(Element* element, int order, MeshFunction* rsln, ElementToRefine& refinement) + { + switch(strategy) + { + case(noSelectionH): + { + refinement.split = H2D_REFINEMENT_H; + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = + order; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); + return true; + } + break; + case(noSelectionHP): + { + int max_allowed_order = this->max_order; + if(this->max_order == H2DRS_DEFAULT_ORDER) + max_allowed_order = H2DRS_MAX_ORDER; + int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); + int increased_order_h = std::min(max_allowed_order, order_h + 1), increased_order_v = std::min(max_allowed_order, order_v + 1); + int increased_order; + if(element->is_triangle()) + increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_h); + else + increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_v); + + refinement.split = H2D_REFINEMENT_H; + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = + refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = + increased_order; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); + return true; + } + case(hXORpSelectionBasedOnError): + { + //make an uniform order in a case of a triangle + int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); + + int current_min_order, current_max_order; + this->get_current_order_range(element, current_min_order, current_max_order); + + if(current_max_order < std::max(order_h, order_v)) + current_max_order = std::max(order_h, order_v); + + int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); + int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); + + //build candidates. + Hermes::vector candidates; + candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); + candidates.push_back(Cand(H2D_REFINEMENT_H, order, order, order, order)); + + this->evaluate_cands_error(candidates, element, rsln); + + Cand* best_candidate = (candidates[0].error < candidates[1].error) ? &candidates[0] : &candidates[1]; + Cand* best_candidates_specific_type[4]; + best_candidates_specific_type[H2D_REFINEMENT_P] = &candidates[0]; + best_candidates_specific_type[H2D_REFINEMENT_H] = &candidates[1]; + best_candidates_specific_type[2] = NULL; + best_candidates_specific_type[3] = NULL; + + //copy result to output + refinement.split = best_candidate->split; + ElementToRefine::copy_orders(refinement.refinement_polynomial_order, best_candidate->p); + for(int i = 0; i < 4; i++) + if(best_candidates_specific_type[i] != NULL) + ElementToRefine::copy_orders(refinement.best_refinement_polynomial_order_type[i], best_candidates_specific_type[i]->p); + + ElementToRefine::copy_errors(refinement.errors, best_candidate->errors); + + //modify orders in a case of a triangle such that order_v is zero + if(element->is_triangle()) + for(int i = 0; i < H2D_MAX_ELEMENT_SONS; i++) + refinement.refinement_polynomial_order[i] = H2D_MAKE_QUAD_ORDER(H2D_GET_H_ORDER(refinement.refinement_polynomial_order[i]), 0); + + return true; + } + default: + H1ProjBasedSelector::select_refinement(element, order, rsln, refinement); + return true; + break; + } + } + + Hermes::vector create_candidates(Element* e, int quad_order) + { + Hermes::vector candidates; + + // Get the current order range. + int current_min_order, current_max_order; + this->get_current_order_range(e, current_min_order, current_max_order); + + int order_h = H2D_GET_H_ORDER(quad_order), order_v = H2D_GET_V_ORDER(quad_order); + + if(current_max_order < std::max(order_h, order_v)) + current_max_order = std::max(order_h, order_v); + + int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); + int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); + + switch(strategy) + { + case(hORpSelectionBasedOnDOFs): + { + candidates.push_back(Cand(H2D_REFINEMENT_P, quad_order)); + } + case(hXORpSelectionBasedOnError): + { + candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); + candidates.push_back(Cand(H2D_REFINEMENT_H, quad_order, quad_order, quad_order, quad_order)); + return candidates; + } + break; + case(isoHPSelectionBasedOnDOFs): + { + this->cand_list = H2D_HP_ISO; + return H1ProjBasedSelector::create_candidates(e, quad_order); + } + break; + case(anisoHPSelectionBasedOnDOFs): + { + this->cand_list = H2D_HP_ANISO; + return H1ProjBasedSelector::create_candidates(e, quad_order); + } + break; + } + } + + void evaluate_cands_score(Hermes::vector& candidates, Element* e) + { + switch(strategy) + { + case(hXORpSelectionBasedOnError): + { + if(candidates[0].error > candidates[1].error) + { + candidates[0].score = 0.0; + candidates[1].score = 1.0; + } + else + { + candidates[1].score = 0.0; + candidates[0].score = 1.0; + } + } + break; + default: + { + //calculate score of candidates + Cand& unrefined = candidates[0]; + const int num_cands = (int)candidates.size(); + unrefined.score = 0; + + for (int i = 1; i < num_cands; i++) + { + Cand& cand = candidates[i]; + if(cand.error < unrefined.error) + { + double delta_dof = cand.dofs - unrefined.dofs; + candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; + } + else + candidates[i].score = 0; + } + } + } + } + + int strategy; +}; + int main(int argc, char* argv[]) { + // Initialize refinement selector. + MySelector selector(hORpSelectionBasedOnDOFs); + + HermesCommonApi.set_integral_param_value(Hermes::showInternalWarnings, false); + // Time measurement. Hermes::Mixins::TimeMeasurable cpu_time; cpu_time.tick(); @@ -61,7 +263,7 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space (mesh, &bcs, P_INIT)); int ndof = Space::get_num_dofs(space); - Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); + //Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Initialize the weak formulation. CustomWeakFormAcoustics wf("Wall", RHO, SOUND_SPEED, OMEGA); @@ -69,27 +271,35 @@ int main(int argc, char* argv[]) // Initialize coarse and reference mesh solution. MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); - // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST); - // Initialize views. - ScalarView sview("Acoustic pressure", new WinGeom(0, 0, 600, 350)); - ScalarView eview("Error", new WinGeom(0, 370, 600, 350)); + ScalarView sview("Acoustic pressure", new WinGeom(600, 0, 600, 350)); + sview.show_contours(.2); + ScalarView eview("Error", new WinGeom(600, 377, 600, 350)); sview.show_mesh(false); sview.fix_scale_width(50); - OrderView oview("Polynomial orders", new WinGeom(610, 0, 600, 350)); - ScalarView ref_view("Refined elements", new WinGeom(610, 370, 600, 350)); + OrderView oview("Polynomial orders", new WinGeom(1208, 0, 600, 350)); + ScalarView ref_view("Refined elements", new WinGeom(1208, 377, 600, 350)); + ref_view.show_scale(false); + ref_view.set_min_max_range(0, 2); // DOF and CPU convergence graphs initialization. SimpleGraph graph_dof, graph_cpu; + //Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + // Time measurement. + cpu_time.tick(); + + // Perform Newton's iteration. + Hermes::Hermes2D::NewtonSolver newton(&wf, space); + newton.set_verbose_output(false); + // Adaptivity loop: int as = 1; adaptivity.set_space(space); bool done = false; do { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + //Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); // Construct globally refined reference mesh and setup reference space. Mesh::ReferenceMeshCreator refMeshCreator(mesh); @@ -99,16 +309,10 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); int ndof_ref = Space::get_num_dofs(ref_space); + wf.set_verbose_output(false); + newton.set_space(ref_space); // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - DiscreteProblem dp(&wf, ref_space); - - // Time measurement. - cpu_time.tick(); - - // Perform Newton's iteration. - Hermes::Hermes2D::NewtonSolver newton(&dp); try { newton.solve(); @@ -122,7 +326,7 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + //Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Time measurement. @@ -134,15 +338,14 @@ int main(int argc, char* argv[]) oview.show(space); // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + //Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); errorCalculator.calculate_errors(sln, ref_sln); double err_est_rel = errorCalculator.get_total_error_squared() * 100; eview.show(errorCalculator.get_errorMeshFunction()); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", - Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); + //Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", Space::get_num_dofs(space), Space::get_num_dofs(ref_space), err_est_rel); // Time measurement. cpu_time.tick(); @@ -157,21 +360,19 @@ int main(int argc, char* argv[]) if (err_est_rel < ERR_STOP) done = true; else { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + //Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); done = adaptivity.adapt(&selector); ref_view.show(adaptivity.get_refinementInfoMeshFunction()); cpu_time.tick(); - char* cpu_time_string = cpu_time.accumulated_str().c_str(); - ref_view.titl - ref_view.set_title(); + std::cout << "Adaptivity step: " << as << ", running CPU time: " << cpu_time.accumulated_str() << std::endl; } - + // Increase counter. as++; } while (done == false); - Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + //Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); // Show the reference solution - the final result. sview.set_title("Fine mesh solution magnitude"); @@ -183,7 +384,7 @@ int main(int argc, char* argv[]) Linearizer lin; bool mode_3D = true; lin.save_solution_vtk(ref_mag, "sln.vtk", "Acoustic pressure", mode_3D); - Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); + //Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk"); // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 6617754..4ff7d4a 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -44,7 +44,7 @@ const int P_INIT = 0; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 2; // CFL value. -double CFL_NUMBER = 0.9; +double CFL_NUMBER = 0.3; // Initial time step. double time_step_n = 1E-6; @@ -67,7 +67,7 @@ const double THRESHOLD = 0.6; CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.01; +const double ERR_STOP = 0.007; // Adaptivity process stops when the number of degrees of freedom grows over // this limit. This is mainly to prevent h-adaptivity to go on forever. @@ -151,11 +151,12 @@ int main(int argc, char* argv[]) ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); pressure_view.show_contours(.1); pressure_view.show_mesh(false); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); + ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); Mach_number_view.show_contours(.02); Mach_number_view.show_mesh(false); - VectorView velocity_view("Velocity", new WinGeom(0, 330, 600, 300)); - OrderView order_view("Orders", new WinGeom(700, 330, 600, 300)); + ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); + ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); + OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); #pragma endregion #pragma region 4. Adaptivity setup. @@ -189,7 +190,7 @@ int main(int argc, char* argv[]) #pragma region 6. Time stepping loop. int iteration = 1; - for(double t = 0.0; t < 3.5; t += time_step_n) + for(double t = 0.0; t < 50.; t += time_step_n) { Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); @@ -315,7 +316,6 @@ int main(int argc, char* argv[]) pressure->reinit(); pressure_view.show(pressure, 1); Mach_number_view.show(Mach_number, 1); - velocity_view.show(rsln_rho_v_x, rsln_rho_v_y); order_view.show((ref_spaces)[0]); } } diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 987e19e..741ea0d 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -26,7 +26,7 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. double THRESHOLD = 0.3; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 58ec0bf..112ff9a 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -21,7 +21,7 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -double epsilon = 1e1; +double eps = 1e1; // Initial polynomial degree of mesh elements. const int P_INIT = 2; @@ -63,10 +63,10 @@ int main(int argc, char* argv[]) basemesh->copy(mesh); // Set exact solution. - MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, epsilon)); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, eps)); // Define right-hand side. - CustomRightHandSide f(epsilon); + CustomRightHandSide f(eps); // Initialize weak formulation. CustomWeakForm wf(&f); @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) logger.set_verbose_output(true); int iterations_count = 10; - int error_levels_count = 5; + int error_levels_count = 1; double error_stop = ERR_STOP; for(int iteration = 0; iteration < iterations_count; iteration++) @@ -130,6 +130,7 @@ int main(int argc, char* argv[]) // Assemble the discrete problem. NewtonSolver newton; newton.set_weak_formulation(&wf); + newton.set_tolerance(1e-5); newton.set_UMFPACK_output(true, false); mesh->copy(basemesh); @@ -137,13 +138,13 @@ int main(int argc, char* argv[]) space->assign_dofs(); double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - epsilon = 10. / std::pow(2, (iteration + 2)); - f.epsilon = epsilon; - ((CustomExactSolution*)exact_sln.get())->epsilon = epsilon; - + eps = 10. / std::pow(2, (iteration + 2)); + f.epsilon = eps; + ((CustomExactSolution*)exact_sln.get())->epsilon = eps; + error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Epsilon: %g%.", iteration, error_level, error_stop, factor, epsilon); + logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Epsilon: %g%.", iteration, error_level, error_stop, factor, eps); // Cumulative. int dof_cumulative = 0; @@ -255,14 +256,8 @@ int main(int argc, char* argv[]) cpu_time.tick(); { - /* sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - */ } cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index 921b33d..cbe89c3 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -89,7 +89,7 @@ bool adaptive_step_single_space( double err_exact_rel; if(exact_sln) { - errorCalculator.calculate_errors(sln, exact_sln); + errorCalculator.calculate_errors(sln, exact_sln, false); err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; } errorCalculator.calculate_errors(sln, ref_sln); @@ -104,8 +104,8 @@ bool adaptive_step_single_space( logger->info("err_exact_rel: %g%%.", err_exact_rel); // View the coarse mesh solution and polynomial orders. - // sview.show(ref_sln); - // oview.show(ref_space); + sview.show(ref_sln); + oview.show(ref_space); error_reached = err_est_rel; if(exact_sln) From 50cb5433a5109ef7ec53746a3a6070fb9dac44df Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Fri, 14 Jun 2013 13:39:14 +0200 Subject: [PATCH 41/64] Fix in an example. --- 2d-advanced/richards/capillary-barrier-rk/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/2d-advanced/richards/capillary-barrier-rk/main.cpp b/2d-advanced/richards/capillary-barrier-rk/main.cpp index 15a8e87..dfb95f8 100644 --- a/2d-advanced/richards/capillary-barrier-rk/main.cpp +++ b/2d-advanced/richards/capillary-barrier-rk/main.cpp @@ -289,7 +289,10 @@ int main(int argc, char* argv[]) // reduced and the entire time step repeated. If yes, then another // check is run, and if the relative error is very low, time step // is increased. - double rel_err_time = Global::calc_norm(time_error_fn.get(), HERMES_H1_NORM) / Global::calc_norm(h_time_new.get(), HERMES_H1_NORM) * 100; + DefaultNormCalculator normCalculator(1); + normCalculator.calculate_norm(time_error_fn); + double rel_err_time = normCalculator.get_total_norm_squared() * 100; + Hermes::Mixins::Loggable::Static::info("rel_err_time = %g%%", rel_err_time); if (rel_err_time > time_tol_upper) { Hermes::Mixins::Loggable::Static::info("rel_err_time above upper limit %g%% -> decreasing time step from %g to %g days and repeating time step.", From 97b23c65cb05b4dc06fec36e03d801ec5905543e Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Fri, 14 Jun 2013 14:46:34 +0200 Subject: [PATCH 42/64] Update and unification of the Euler examples. --- 2d-advanced/euler/euler-init-main-adapt.cpp | 63 ++++ 2d-advanced/euler/euler-init-main.cpp | 34 ++ .../euler/euler-time-loop-space-adapt.cpp | 190 ++++++++++ 2d-advanced/euler/euler-time-loop.cpp | 115 ++++++ 2d-advanced/euler/forward-step-adapt/main.cpp | 334 +++--------------- 2d-advanced/euler/forward-step/main.cpp | 139 +------- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 272 ++------------ 2d-advanced/euler/gamm-channel/main.cpp | 163 ++------- .../heating-induced-vortex-adapt/main.cpp | 292 ++------------- .../euler/heating-induced-vortex/main.cpp | 139 +------- .../euler/reflected-shock-adapt/main.cpp | 324 +++-------------- 2d-advanced/euler/reflected-shock/main.cpp | 130 +------ 12 files changed, 623 insertions(+), 1572 deletions(-) create mode 100644 2d-advanced/euler/euler-init-main-adapt.cpp create mode 100644 2d-advanced/euler/euler-init-main.cpp create mode 100644 2d-advanced/euler/euler-time-loop-space-adapt.cpp create mode 100644 2d-advanced/euler/euler-time-loop.cpp diff --git a/2d-advanced/euler/euler-init-main-adapt.cpp b/2d-advanced/euler/euler-init-main-adapt.cpp new file mode 100644 index 0000000..0eef021 --- /dev/null +++ b/2d-advanced/euler/euler-init-main-adapt.cpp @@ -0,0 +1,63 @@ +#pragma region 1. Load mesh and initialize spaces. + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load(MESH_FILENAME, mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + #pragma endregion + + #pragma region 2. Initialize solutions. + MeshFunctionSharedPtr sln_rho(new Solution(mesh)); + MeshFunctionSharedPtr sln_rho_v_x(new Solution (mesh)); + MeshFunctionSharedPtr sln_rho_v_y(new Solution (mesh)); + MeshFunctionSharedPtr sln_e(new Solution (mesh)); + Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); + + MeshFunctionSharedPtr rsln_rho(new Solution(mesh)); + MeshFunctionSharedPtr rsln_rho_v_x(new Solution (mesh)); + MeshFunctionSharedPtr rsln_rho_v_y(new Solution (mesh)); + MeshFunctionSharedPtr rsln_e(new Solution (mesh)); + Hermes::vector > rslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e); + #pragma endregion + + #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(rslns, KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(rslns, KAPPA)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); + ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); + ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); + OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); + #pragma endregion + + // Set up CFL calculation class. + CFLCalculation CFL(CFL_NUMBER, KAPPA); + + Vector* rhs_stabilization = create_vector(HermesCommonApi.get_integral_param_value(matrixSolverType)); + + #pragma region 4. Adaptivity setup. + // Initialize refinement selector. + L2ProjBasedSelector selector(CAND_LIST); + selector.set_dof_score_exponent(2.0); + + //selector.set_error_weights(1.0, 1.0, 1.0); + + // Error calculation. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + Adapt adaptivity(spaces, &errorCalculator, &stoppingCriterion); + #pragma endregion \ No newline at end of file diff --git a/2d-advanced/euler/euler-init-main.cpp b/2d-advanced/euler/euler-init-main.cpp new file mode 100644 index 0000000..3ced474 --- /dev/null +++ b/2d-advanced/euler/euler-init-main.cpp @@ -0,0 +1,34 @@ +#pragma region 1. Load mesh and initialize spaces. + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load(MESH_FILENAME, mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + #pragma endregion + + #pragma region 2. Initialize solutions. + MeshFunctionSharedPtr sln_rho(new Solution(mesh)); + MeshFunctionSharedPtr sln_rho_v_x(new Solution (mesh)); + MeshFunctionSharedPtr sln_rho_v_y(new Solution (mesh)); + MeshFunctionSharedPtr sln_e(new Solution (mesh)); + Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); + #pragma endregion + + // Set up CFL calculation class. + CFLCalculation CFL(CFL_NUMBER, KAPPA); + + Vector* rhs_stabilization = create_vector(HermesCommonApi.get_integral_param_value(matrixSolverType)); + \ No newline at end of file diff --git a/2d-advanced/euler/euler-time-loop-space-adapt.cpp b/2d-advanced/euler/euler-time-loop-space-adapt.cpp new file mode 100644 index 0000000..725efb8 --- /dev/null +++ b/2d-advanced/euler/euler-time-loop-space-adapt.cpp @@ -0,0 +1,190 @@ +Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); +EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); + +if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + wf.set_stabilization(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, NU_1, NU_2); + +// Solver. +LinearSolver solver(&wf, spaces); + +#pragma region 6. Time stepping loop. +int iteration = 0; +for(double t = 0.0; t < TIME_INTERVAL_LENGTH; t += time_step_n) +{ + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + +#pragma region 6.1. Periodic global derefinements. + if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) + { + Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); + REFINEMENT_COUNT = 0; + + space_rho->unrefine_all_mesh_elements(true); + + space_rho->adjust_element_order(-1, P_INIT); + space_rho_v_x->adjust_element_order(-1, P_INIT); + space_rho_v_y->adjust_element_order(-1, P_INIT); + space_e->adjust_element_order(-1, P_INIT); + Space::assign_dofs(spaces); + } +#pragma endregion + +#pragma region 7. Adaptivity loop. + int as = 1; int ndofs_prev = 0; bool done = false; + do + { + // Info. + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + // Set the current time step. + wf.set_current_time_step(time_step_n); + +#pragma region 7.1. Construct globally refined reference mesh and setup reference space. + int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; + + Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); + MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); + SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); + SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); + Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); + solver.set_spaces(ref_spaces); + + if(ndofs_prev != 0) + if(Space::get_num_dofs(ref_spaces) == ndofs_prev) + selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); + else + selector.set_error_weights(1.0, 1.0, 1.0); + + ndofs_prev = Space::get_num_dofs(ref_spaces); + + // Project the previous time level solution onto the new fine mesh + Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); + OGProjection::project_global(ref_spaces, prev_slns, prev_slns); +#pragma endregion + + if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + { + SpaceSharedPtr ref_space_stabilization(new L2Space(ref_mesh, 0)); + int mesh_size = ref_mesh->get_num_active_elements(); + DiscreteProblem dp_stabilization(&wf_stabilization, ref_space_stabilization); + dp_stabilization.set_space(ref_space_stabilization); + dp_stabilization.assemble(rhs_stabilization); + if(!wf.discreteIndicator) + { + wf.set_discreteIndicator(new bool[mesh_size], mesh_size); + memset(wf.discreteIndicator, 0, mesh_size * sizeof(bool)); + } + Element* e; + for_all_active_elements(e, ref_space_stabilization->get_mesh()) + { + AsmList al; + ref_space_stabilization->get_element_assembly_list(e, &al); + if(rhs_stabilization->get(al.get_dof()[0]) >= 1) + wf.discreteIndicator[e->id] = true; + } + } + + // Solve the problem. + solver.solve(); + +#pragma region *. Get the solution with optional shock capturing. + if(!SHOCK_CAPTURING) + Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, rslns); + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), ref_spaces); + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(spaces); + + flux_limiter->limit_according_to_detector(spaces); + + flux_limiter->get_limited_solutions(rslns); + + delete flux_limiter; + } +#pragma endregion + + // Calculate time step according to CFL condition. + CFL.calculate(rslns, (ref_spaces)[0]->get_mesh(), time_step_n); + +#pragma region 7.2. Project to coarse mesh -> error estimation -> space adaptivity + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection::project_global(spaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); + + // Calculate element errors and total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + errorCalculator.calculate_errors(slns, rslns); + double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + + // Report results. + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); + + // If err_est too large, adapt the mesh. + if (err_est_rel_total < adaptivityErrorStop(iteration)) + done = true; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector)); + REFINEMENT_COUNT++; + as++; + } +#pragma endregion + +#pragma region 7.3. Visualization and saving on disk. + if(done && (iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure, 1); + Mach_number_view.show(Mach_number, 1); + order_view.show((ref_spaces)[0]); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure->reinit(); + Linearizer lin; + char filename[40]; + sprintf(filename, "Pressure-%i.vtk", iteration - 1); + lin.save_solution_vtk(pressure, filename, "Pressure", false); + sprintf(filename, "VelocityX-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho_v_x, filename, "VelocityX", false); + sprintf(filename, "VelocityY-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho_v_y, filename, "VelocityY", false); + sprintf(filename, "Rho-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho, filename, "Rho", false); + } + } +#pragma endregion + } + while (done == false); +#pragma endregion + + // Copy the solutions into the previous time level ones. + prev_rho->copy(rsln_rho); + prev_rho_v_x->copy(rsln_rho_v_x); + prev_rho_v_y->copy(rsln_rho_v_y); + prev_e->copy(rsln_e); +} +#pragma endregion + +pressure_view.close(); +Mach_number_view.close(); + +return 0; \ No newline at end of file diff --git a/2d-advanced/euler/euler-time-loop.cpp b/2d-advanced/euler/euler-time-loop.cpp new file mode 100644 index 0000000..ba15c12 --- /dev/null +++ b/2d-advanced/euler/euler-time-loop.cpp @@ -0,0 +1,115 @@ +Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); + +#pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(prev_slns, KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(prev_slns, KAPPA)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); + ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); + ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); + OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); + #pragma endregion + +EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); +DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); + +if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + wf.set_stabilization(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, NU_1, NU_2); + +LinearSolver solver(&wf, spaces); + +#pragma region 5. Time stepping loop. +int iteration = 0; +for(double t = 0.0; t < TIME_INTERVAL_LENGTH; t += time_step_n) +{ + // Info. + Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); + + if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) + { + int mesh_size = space_stabilization->get_num_dofs(); + assert(mesh_size == space_stabilization->get_mesh()->get_num_active_elements()); + dp_stabilization.assemble(rhs_stabilization); + if(!wf.discreteIndicator) + { + wf.set_discreteIndicator(new bool[mesh_size], mesh_size); + memset(wf.discreteIndicator, 0, mesh_size * sizeof(bool)); + } + Element* e; + for_all_active_elements(e, space_stabilization->get_mesh()) + { + AsmList al; + space_stabilization->get_element_assembly_list(e, &al); + if(rhs_stabilization->get(al.get_dof()[0]) >= 1) + wf.discreteIndicator[e->id] = true; + } + } + + // Set the current time step. + wf.set_current_time_step(time_step_n); + + try + { + // Solve. + solver.solve(); + +#pragma region *. Get the solution with optional shock capturing. + if(!SHOCK_CAPTURING) + Solution::vector_to_solutions(solver.get_sln_vector(), spaces, prev_slns); + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), spaces, true); + else + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), spaces); + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(); + + flux_limiter->limit_according_to_detector(); + + flux_limiter->get_limited_solutions(prev_slns); + } +#pragma endregion + } + catch(std::exception& e) { std::cout << e.what(); } + + // Calculate time step according to CFL condition. + CFL.calculate(prev_slns, mesh, time_step_n); + +#pragma region 5.1. Visualization + if((iteration - 1) % EVERY_NTH_STEP == 0) + { + // Hermes visualization. + if(HERMES_VISUALIZATION) + { + Mach_number->reinit(); + pressure->reinit(); + pressure_view.show(pressure, 1); + Mach_number_view.show(Mach_number, 1); + order_view.show(space_rho); + } + // Output solution in VTK format. + if(VTK_VISUALIZATION) + { + pressure->reinit(); + Linearizer lin; + char filename[40]; + sprintf(filename, "Pressure-%i.vtk", iteration - 1); + lin.save_solution_vtk(pressure, filename, "Pressure", false); + sprintf(filename, "VelocityX-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho_v_x, filename, "VelocityX", false); + sprintf(filename, "VelocityY-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho_v_y, filename, "VelocityY", false); + sprintf(filename, "Rho-%i.vtk", iteration - 1); + lin.save_solution_vtk(prev_rho, filename, "Rho", false); + } + } +#pragma endregion +} +#pragma endregion + +// Done. +return 0; \ No newline at end of file diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index bb2b189..a1b896e 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -21,49 +21,62 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // Visualization. // Set to "true" to enable Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = false; +const bool HERMES_VISUALIZATION = true; // Set to "true" to enable VTK output. -const bool VTK_VISUALIZATION = true; +const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; // Shock capturing. -bool SHOCK_CAPTURING = true; -// Quantitative parameter of the discontinuity detector. +enum shockCapturingType +{ + FEISTAUER, + KUZMIN, + KRIVODONOVA +}; +bool SHOCK_CAPTURING = false; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +// Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; - -// Initial polynomial degree. -const int P_INIT = 0; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; -// Number of initial localized mesh refinements. -const int INIT_REF_NUM_STEP = 1; +// Quantitative parameter of the shock capturing in case of Feistauer. +const double NU_1 = 0.1; +const double NU_2 = 0.1; + +// Initial polynomial degree. +const int P_INIT = 0; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 0; // CFL value. -double CFL_NUMBER = 0.5; +double CFL_NUMBER = 0.1; // Initial time step. -double time_step = 1E-6; +double time_step_n = 1E-6; +double TIME_INTERVAL_LENGTH = 20.; // Adaptivity. // Every UNREF_FREQth time step the mesh is unrefined. -const int UNREF_FREQ = 5; +const int UNREF_FREQ = 10; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since // last unrefinement. -int REFINEMENT_COUNT = 0; +int REFINEMENT_COUNT = 1; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies (see below). -const double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +const double THRESHOLD = 0.6; + +// Predefined list of element refinement candidates. Possible values are +// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, +// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. +CandList CAND_LIST = H2D_HP_ANISO; + // Stopping criterion for adaptivity. -double ERR_STOP = 1e-1; +double adaptivityErrorStop(int iteration) +{ + if(iteration > 49) + return 0.01; + else + return 0.5 - iteration * 0.01; +} // Equation parameters. const double P_EXT = 1.0; // Exterior pressure (dimensionless). @@ -72,6 +85,8 @@ const double V1_EXT = 3.0; // Inlet x-velocity (dimensionless). const double V2_EXT = 0.0; // Inlet y-velocity (dimensionless). const double KAPPA = 1.4; // Kappa. +// Mesh filename. +const std::string MESH_FILENAME = "ffs.mesh"; // Boundary markers. const std::string BDY_SOLID_WALL_BOTTOM = "1"; const std::string BDY_OUTLET = "2"; @@ -84,53 +99,16 @@ const std::string BDY_INLET = "4"; // Initial condition. #include "../initial_condition.cpp" -// Criterion for mesh refinement. -int refinement_criterion(Element* e) -{ - if(e->vn[2]->y <= 0.4 && e->vn[1]->x <= 0.6) - return 0; - else - return -1; -} - int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh), base_mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("ffs.mesh", base_mesh); - - base_mesh->refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - base_mesh->refine_all_elements(0, true); - - mesh->copy(base_mesh); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - - MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); +#include "../euler-init-main-adapt.cpp" + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); Hermes::vector inlet_markers; @@ -140,232 +118,6 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - - ScalarView s1("Rho", new WinGeom(0, 0, 700, 400)); - ScalarView s2("RhoVX", new WinGeom(700, 0, 700, 400)); - ScalarView s3("RhoVY", new WinGeom(0, 400, 700, 400)); - ScalarView s4("RhoE", new WinGeom(700, 400, 700, 400)); - - // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST); - selector.set_error_weights(1.0, 1.0, 1.0); - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - // Time stepping loop. - double t = 0.0; - int iteration = 0; - for(; t < 14.5; t += time_step) - { - if(t > 0.3) - ERR_STOP = 2.5; - - CFL.set_number(CFL_NUMBER + (t/4.5) * 1.0); - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration, t); - - // Adaptivity loop: - int as = 1; - int ndofs_prev = 0; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - Hermes::vector >* ref_spacesNoDerefinement; - - // Periodic global derefinements. - if (as == 1 && (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0)) - { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - - REFINEMENT_COUNT = 0; - - space_rho->unrefine_all_mesh_elements(true); - - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); - } - - Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); - MeshSharedPtr ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); - - int order_increase = 1; - Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - - if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces) == ndofs_prev) - selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); - else - selector.set_error_weights(1.0, 1.0, 1.0); - - ndofs_prev = Space::get_num_dofs(ref_spaces); - - // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; - ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); - - FluxLimiter flux_limiterLoading(FluxLimiter::Kuzmin, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), ref_spaces, true); - - flux_limiterLoading.limitOscillations = true; - - int limited = flux_limiterLoading.limit_according_to_detector(); - int counter = 0; - Hermes::Mixins::Loggable::Static::info("Limited in %d-th step: %d.", ++counter, limited); - while(limited > 10) - { - limited = flux_limiterLoading.limit_according_to_detector(); - Hermes::Mixins::Loggable::Static::info("Limited in %d-th step: %d.", ++counter, limited); - } - - flux_limiterLoading.get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - - // Report NDOFs. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); - - // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - DiscreteProblem dp(&wf, ref_spaces); - - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - - wf.set_current_time_step(time_step); - - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - dp.assemble(matrix, rhs); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - try - { - solver->solve(); - - Hermes::Mixins::Loggable::Static::info("Solved."); - - if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - else - { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces, true); - - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - - flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - - flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - } - } - catch(std::exception& e) - { - std::cout << e.what(); - } - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), - Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - - CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), ref_space_rho->get_mesh(), time_step); - - // Report results. - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - - // If err_est too large, adapt the mesh. - if (err_est_rel_total < ERR_STOP) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - REFINEMENT_COUNT++; - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector)); - - if(!done) - as++; - } - - // Visualization and saving on disk. - if(done && (iteration - 1) % EVERY_NTH_STEP == 0 && iteration > 1) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - pressure_view.show(pressure); - Mach_number_view.show(Mach_number); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - Mach_number->reinit(); - Linearizer lin; - Orderizer ord; - char filename[40]; - sprintf(filename, "Density-%i.vtk", iteration); - lin.save_solution_vtk(rsln_rho, filename, "Density", false); - sprintf(filename, "Mach number-%i.vtk", iteration); - lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); - sprintf(filename, "Space-%i.vtk", iteration); - ord.save_orders_vtk(ref_space_rho, filename); - sprintf(filename, "Mesh-%i.vtk", iteration); - ord.save_mesh_vtk(ref_space_rho, filename); - } - } - - // Clean up. - delete solver; - delete matrix; - delete rhs; - - } - while (done == false); - - iteration++; - - // Copy the solutions into the previous time level ones. - prev_rho->copy(rsln_rho); - prev_rho_v_x->copy(rsln_rho_v_x); - prev_rho_v_y->copy(rsln_rho_v_y); - prev_e->copy(rsln_e); - } - - pressure_view.close(); - Mach_number_view.close(); - return 0; +#include "../euler-time-loop-space-adapt.cpp" } diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index ff5289a..1aa899a 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -29,6 +29,7 @@ const unsigned int EVERY_NTH_STEP = 1; // Shock capturing. enum shockCapturingType { + FEISTAUER, KUZMIN, KRIVODONOVA }; @@ -49,7 +50,7 @@ const int INIT_REF_NUM_STEP = 2; // CFL value. double CFL_NUMBER = 0.25; // Initial time step. -double time_step = 1E-6; +double time_step_n = 1E-6; // Equation parameters. // Exterior pressure (dimensionless). @@ -63,6 +64,10 @@ const double V2_EXT = 0.0; // Kappa. const double KAPPA = 1.4; +double TIME_INTERVAL_LENGTH = 20.; + +// Mesh filename. +const std::string MESH_FILENAME = "ffs.mesh"; // Boundary markers. const std::string BDY_SOLID_WALL_BOTTOM = "1"; const std::string BDY_OUTLET = "2"; @@ -86,51 +91,14 @@ int refinement_criterion(Element* e) int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("ffs.mesh", mesh); - mesh->refine_by_criterion(refinement_criterion, INIT_REF_NUM_STEP); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - MeshView m; - m.show(mesh); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); +#include "../euler-init-main.cpp" - // Initialize solutions, set initial conditions. + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA, RHO_EXT, P_EXT)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); - ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); - ScalarView s2("prev_rho_v_x", new WinGeom(700, 0, 600, 300)); - ScalarView s3("prev_rho_v_y", new WinGeom(0, 400, 600, 300)); - ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - // Initialize weak formulation. Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); Hermes::vector inlet_markers; @@ -140,95 +108,6 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); - - // Initialize the FE problem. - Hermes::vector > spaces (space_rho, space_rho_v_x, space_rho_v_y, space_e); - DiscreteProblem dp(&wf, spaces); - DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); - LinearSolver solver(&dp); - - // Time stepping loop. - int iteration = 0; - double t = 0.0; - for(; t < 10.0; t += time_step) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - CFL.set_number(0.1 + (t/7.0) * 1.0); - - // Set the current time step. - wf.set_current_time_step(time_step); - - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - try - { - solver.solve(); - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); - - flux_limiter->limit_according_to_detector(); - - flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - } - catch(std::exception& e) - { - std::cout << e.what(); - } - - CFL.calculate(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); - - // Visualization. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - entropy->reinit(); - pressure_view.show(pressure); - entropy_production_view.show(entropy); - Mach_number_view.show(Mach_number); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Mach_number->reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); - Linearizer lin_mach; - sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); - } - } - } - - pressure_view.close(); - entropy_production_view.close(); - Mach_number_view.close(); - return 0; +#include "../euler-time-loop.cpp" } diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 4ff7d4a..5bb883e 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -23,11 +23,14 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // Visualization. // Set to "true" to enable Hermes OpenGL visualization. const bool HERMES_VISUALIZATION = true; +// Set to "true" to enable VTK output. +const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; // Shock capturing. enum shockCapturingType { + FEISTAUER, KUZMIN, KRIVODONOVA }; @@ -67,15 +70,10 @@ const double THRESHOLD = 0.6; CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 0.007; - -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; - -// Matrix solver for orthogonal projections: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double adaptivityErrorStop(int iteration) +{ + return 0.007; +} // Equation parameters. // Exterior pressure (dimensionless). @@ -87,8 +85,12 @@ const double V1_EXT = 1.25; // Inlet y-velocity (dimensionless). const double V2_EXT = 0.0; // Kappa. -const double KAPPA = 1.4; +const double KAPPA = 1.4; + +double TIME_INTERVAL_LENGTH = 20.; +// Mesh filename. +const std::string MESH_FILENAME = "GAMM-channel.mesh"; // Boundary markers. const std::string BDY_INLET = "1"; const std::string BDY_OUTLET = "2"; @@ -103,237 +105,21 @@ const std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - #pragma region 1. Load mesh and initialize spaces. - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); - int ndof = Space::get_num_dofs(spaces); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - #pragma endregion - - #pragma region 2. Initialize solutions, set initial conditions. - MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); - - MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - - MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - Hermes::vector > rslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e); - #pragma endregion - - #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter(rslns, KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(rslns, KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - pressure_view.show_contours(.1); - pressure_view.show_mesh(false); - ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); - Mach_number_view.show_contours(.02); - Mach_number_view.show_mesh(false); - ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); - ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); - OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); - #pragma endregion - - #pragma region 4. Adaptivity setup. - // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST); - selector.set_dof_score_exponent(2.0); - - //selector.set_error_weights(1.0, 1.0, 1.0); - - // Error calculation. - DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); - // Stopping criterion for an adaptivity step. - AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); - Adapt adaptivity(spaces, &errorCalculator, &stoppingCriterion); - #pragma endregion - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - #pragma region 5. Initialize weak formulation and solver. - Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); - Hermes::vector inlet_markers; - inlet_markers.push_back(BDY_INLET); - Hermes::vector outlet_markers; - outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - - // Solver. - LinearSolver solver(&wf, spaces); - #pragma endregion - - #pragma region 6. Time stepping loop. - int iteration = 1; - for(double t = 0.0; t < 50.; t += time_step_n) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - #pragma region 6.1. Periodic global derefinements. - if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) - { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - REFINEMENT_COUNT = 0; - - space_rho->unrefine_all_mesh_elements(true); - - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); - Space::assign_dofs(spaces); - } - #pragma endregion - - #pragma region 7. Adaptivity loop. - int as = 1; int ndofs_prev = 0; bool done = false; - do - { - // Info. - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - // Set the current time step. - wf.set_current_time_step(time_step_n); - - #pragma region 7.1. Construct globally refined reference mesh and setup reference space. - int order_increase = CAND_LIST == H2D_HP_ANISO ? 1 : 0; - - Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); - MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); - SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - solver.set_spaces(ref_spaces); - - if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces) == ndofs_prev) - selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); - else - selector.set_error_weights(1.0, 1.0, 1.0); - - ndofs_prev = Space::get_num_dofs(ref_spaces); - - // Project the previous time level solution onto the new fine mesh - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh."); - OGProjection::project_global(ref_spaces, prev_slns, prev_slns); - #pragma endregion - - // Solve the problem. - solver.solve(); - - #pragma region *. Get the solution with optional shock capturing. - if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, rslns); - else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), ref_spaces); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(spaces); - - flux_limiter->limit_according_to_detector(spaces); - - flux_limiter->get_limited_solutions(rslns); - - delete flux_limiter; - } - #pragma endregion - - // Calculate time step according to CFL condition. - CFL.calculate(rslns, (ref_spaces)[0]->get_mesh(), time_step_n); - - #pragma region 7.2. Project to coarse mesh -> error estimation -> space adaptivity - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection::project_global(spaces, rslns, slns, Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - errorCalculator.calculate_errors(slns, rslns); - double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; - - // Report results. - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - - // If err_est too large, adapt the mesh. - if (err_est_rel_total < ERR_STOP) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector)); - - REFINEMENT_COUNT++; - if (Space::get_num_dofs(spaces) >= NDOF_STOP) - done = true; - else - as++; - } - #pragma endregion - - #pragma region 7.3. Visualization and saving on disk. - if(done && (iteration - 1) % EVERY_NTH_STEP == 0 && iteration > 2) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - pressure_view.show(pressure, 1); - Mach_number_view.show(Mach_number, 1); - order_view.show((ref_spaces)[0]); - } - } - #pragma endregion - } - while (done == false); - #pragma endregion - - // Copy the solutions into the previous time level ones. - prev_rho->copy(rsln_rho); - prev_rho_v_x->copy(rsln_rho_v_x); - prev_rho_v_y->copy(rsln_rho_v_y); - prev_e->copy(rsln_e); - } - #pragma endregion - - pressure_view.close(); - Mach_number_view.close(); - - return 0; +#include "../euler-init-main-adapt.cpp" + + // Set initial conditions. + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); + + // Initialize weak formulation. + Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + outlet_markers.push_back(BDY_OUTLET); + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); + +#include "../euler-time-loop-space-adapt.cpp" } diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index a0a3de3..9a1d6d3 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -1,5 +1,3 @@ -#define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" #include "hermes2d.h" using namespace Hermes; @@ -42,13 +40,13 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 1; +const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 4; +const int INIT_REF_NUM = 2; // CFL value. double CFL_NUMBER = 0.9; // Initial time step. -double time_step = 1E-6; +double time_step_n = 1E-6; // Equation parameters. // Exterior pressure (dimensionless). @@ -62,11 +60,15 @@ const double V2_EXT = 0.0; // Kappa. const double KAPPA = 1.4; +double TIME_INTERVAL_LENGTH = 20.; + +// Mesh filename. +const std::string MESH_FILENAME = "GAMM-channel.mesh"; // Boundary markers. -std::string BDY_INLET = "1"; -std::string BDY_OUTLET = "2"; -std::string BDY_SOLID_WALL_BOTTOM = "3"; -std::string BDY_SOLID_WALL_TOP = "4"; +const std::string BDY_INLET = "1"; +const std::string BDY_OUTLET = "2"; +const std::string BDY_SOLID_WALL_BOTTOM = "3"; +const std::string BDY_SOLID_WALL_TOP = "4"; // Weak forms. #include "../forms_explicit.cpp" @@ -76,136 +78,23 @@ std::string BDY_SOLID_WALL_TOP = "4"; int main(int argc, char* argv[]) { - #pragma region 1. Load mesh and initialize spaces. - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("GAMM-channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); - int ndof = Space::get_num_dofs(spaces); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - #pragma endregion - - #pragma region 2. Initialize solutions, set initial conditions. - MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); - MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); - MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); - MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - #pragma endregion - - #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter (prev_slns, KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(prev_slns, KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - pressure_view.show_contours(.1); - pressure_view.show_mesh(false); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - Mach_number_view.show_contours(.02); - Mach_number_view.show_mesh(false); - VectorView velocity_view("Velocity", new WinGeom(0, 330, 600, 300)); - #pragma endregion - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - #pragma region 4. Initialize weak formulation -> EF problem -> linear solver. - Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); - Hermes::vector inlet_markers; - inlet_markers.push_back(BDY_INLET); - Hermes::vector outlet_markers; - outlet_markers.push_back(BDY_OUTLET); - - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, - inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - - // Initialize the FE problem. - Space::assign_dofs(spaces); - - LinearSolver solver(&wf, spaces); - #pragma endregion - - #pragma region 5. Time stepping loop. - int iteration = 0; - for(double t = 0.0; t < 10.0; t += time_step) - { - // Info. - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Set the current time step. - wf.set_current_time_step(time_step); - - try - { - // Solve. - solver.solve(); - - #pragma region *. Get the solution with optional shock capturing. - if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver.get_sln_vector(), spaces, prev_slns); - else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), spaces, true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), spaces); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); - - flux_limiter->limit_according_to_detector(); +#include "../euler-init-main.cpp" - flux_limiter->get_limited_solutions(prev_slns); - } - #pragma endregion - } - catch(std::exception& e) { std::cout << e.what(); } + // Set initial conditions. + MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_EXT)); + MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_EXT * V1_EXT)); + MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_EXT * V2_EXT)); + MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA))); - // Calculate time step according to CFL condition. - CFL.calculate(prev_slns, mesh, time_step); + // Initialize weak formulation. + Hermes::vector solid_wall_markers(BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP); + Hermes::vector inlet_markers; + inlet_markers.push_back(BDY_INLET); + Hermes::vector outlet_markers; + outlet_markers.push_back(BDY_OUTLET); - #pragma region 5.1. Visualization - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - pressure_view.show(pressure); - Mach_number_view.show(Mach_number); - velocity_view.show(prev_rho_v_x, prev_rho_v_y); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Mach_number->reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); - Linearizer lin_mach; - sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); - } - } - #pragma endregion - } - #pragma endregion + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - // Done. - return 0; +#include "../euler-time-loop.cpp" } diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index db65394..1da9b43 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -26,23 +26,30 @@ const bool HERMES_VISUALIZATION = true; const bool VTK_VISUALIZATION = false; // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; - // Shock capturing. -bool SHOCK_CAPTURING = true; -// Quantitative parameter of the discontinuity detector. +enum shockCapturingType +{ + FEISTAUER, + KUZMIN, + KRIVODONOVA +}; +bool SHOCK_CAPTURING = false; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +// Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; +// Quantitative parameter of the shock capturing in case of Feistauer. +const double NU_1 = 0.1; +const double NU_2 = 0.1; // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // CFL value. -double CFL_NUMBER = 0.5; - // Initial time step. -double time_step = 1E-6; - -// Adaptivity. -const int NDOFS_MIN = 7000; +double CFL_NUMBER = 0.1; +// Initial time step. +double time_step_n = 1E-6; +double TIME_INTERVAL_LENGTH = 20.; // Every UNREF_FREQth time step the mesh is unrefined. const int UNREF_FREQ = 5; @@ -56,16 +63,6 @@ int REFINEMENT_COUNT = 0; // it has different meanings for various adaptive strategies (see below). const double THRESHOLD = 0.3; -// Adaptive strategy: -// STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total -// error is processed. If more elements have similar errors, refine -// all to keep the mesh symmetric. -// STRATEGY = 1 ... refine all elements whose error is larger -// than THRESHOLD times maximum element error. -// STRATEGY = 2 ... refine all elements whose error is larger -// than THRESHOLD. -const int STRATEGY = 1; - // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. @@ -83,20 +80,14 @@ const int MAX_P_ORDER = 1; // their notoriously bad performance. const int MESH_REGULARITY = -1; -// This parameter influences the selection of -// candidates in hp-adaptivity. Default value is 1.0. -const double CONV_EXP = 1; - // Stopping criterion for adaptivity. -double ERR_STOP = 5.0; - -// Adaptivity process stops when the number of degrees of freedom grows over -// this limit. This is mainly to prevent h-adaptivity to go on forever. -const int NDOF_STOP = 100000; - -// Matrix solver for orthogonal projections: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double adaptivityErrorStop(int iteration) +{ + if(iteration > 49) + return 0.01; + else + return 0.5 - iteration * 0.01; +} // Equation parameters. // Exterior pressure (dimensionless). @@ -116,16 +107,16 @@ const double V1_EXT = 0.0; // Inlet y-velocity (dimensionless). const double V2_EXT = 0.0; // Kappa. -const double KAPPA = 1.4; +const double KAPPA = 1.4; +const double MESH_SIZE = 3.0; + +// Mesh filename. +const std::string MESH_FILENAME = "square.mesh"; // Boundary markers. const std::string BDY_INLET = "Inlet"; const std::string BDY_SOLID_WALL = "Solid"; -// Area (square) size. -// Must be in accordance with the mesh file. -const double MESH_SIZE = 3.0; - // Weak forms. #include "../forms_explicit.cpp" @@ -134,39 +125,14 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("square.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); +#include "../euler-init-main-adapt.cpp" - // Initialize solutions, set initial conditions. + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - MeshFunctionSharedPtr sln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); - MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, 0.0)); - MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, 0.0)); - MeshFunctionSharedPtr sln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - - MeshFunctionSharedPtr rsln_rho(new InitialSolutionLinearProgress(mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); - MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, 0.0)); - MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, 0.0)); - MeshFunctionSharedPtr rsln_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); @@ -177,201 +143,5 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA, RHO_INITIAL_HIGH, P_INITIAL_HIGH)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - VectorView velocity_view("Velocity", new WinGeom(700, 400, 600, 300)); - - // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST); - selector.set_error_weights(1.0, 1.0, 1.0); - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - // Time stepping loop. - int iteration = 0; double t = 0; - for(; t < 7.0; t += time_step) - { - if(t > 0.25) - ERR_STOP = 2.3; - - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Periodic global derefinements. - if (iteration > 1 && iteration % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) - { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - REFINEMENT_COUNT = 0; - - space_rho->unrefine_all_mesh_elements(true); - - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); - } - - // Adaptivity loop: - int as = 1; - int ndofs_prev = 0; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - // Construct globally refined reference mesh and setup reference space. - int order_increase = 1; - - Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); - MeshSharedPtr ref_mesh_flow = refMeshCreatorFlow.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh_flow, order_increase); - SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - - if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces) == ndofs_prev) - selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); - else - selector.set_error_weights(1.0, 1.0, 1.0); - - ndofs_prev = Space::get_num_dofs(ref_spaces); - - // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector(), iteration > 1); - - - // Report NDOFs. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); - - // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - DiscreteProblem dp(&wf, ref_spaces); - - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - - wf.set_current_time_step(time_step); - - dp.assemble(matrix, rhs); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) - if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver->get_sln_vector(), ref_spaces, - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - else - { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), ref_spaces); - - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), - Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - - CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); - - // Report results. - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - - // If err_est too large, adapt the mesh. - if (err_est_rel_total < ERR_STOP & Space::get_num_dofs(ref_spaces) > NDOFS_MIN) - done = true; - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - - REFINEMENT_COUNT++; - if (Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)) >= NDOF_STOP) - done = true; - else - as++; - } - - // Clean up. - delete solver; - delete matrix; - delete rhs; - - } - while (done == false); - - // Copy the solutions into the previous time level ones. - prev_rho->copy(rsln_rho); - prev_rho_v_x->copy(rsln_rho_v_x); - prev_rho_v_y->copy(rsln_rho_v_y); - prev_e->copy(rsln_e); - - // Visualization and saving on disk. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - pressure->reinit(); - pressure_view.show(pressure); - velocity_view.show(rsln_rho_v_x, rsln_rho_v_y); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Linearizer lin; - char filename[40]; - sprintf(filename, "Pressure-%i.vtk", iteration - 1); - lin.save_solution_vtk(pressure, filename, "Pressure", false); - sprintf(filename, "VelocityX-%i.vtk", iteration - 1); - lin.save_solution_vtk(prev_rho_v_x, filename, "VelocityX", false); - sprintf(filename, "VelocityY-%i.vtk", iteration - 1); - lin.save_solution_vtk(prev_rho_v_y, filename, "VelocityY", false); - sprintf(filename, "Rho-%i.vtk", iteration - 1); - lin.save_solution_vtk(prev_rho, filename, "Rho", false); - } - } - } - - pressure_view.close(); - velocity_view.close(); - - return 0; +#include "../euler-time-loop-space-adapt.cpp" } diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index dd52a62..e9b3e0b 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -17,13 +17,14 @@ const unsigned int EVERY_NTH_STEP = 1; // Initial polynomial degree. -const int P_INIT_FLOW = 0; +const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 5; // Shock capturing. enum shockCapturingType { + FEISTAUER, KUZMIN, KRIVODONOVA }; @@ -31,6 +32,9 @@ bool SHOCK_CAPTURING = false; shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; +// Quantitative parameter of the shock capturing in case of Feistauer. +const double NU_1 = 0.1; +const double NU_2 = 0.1; // Equation parameters. // Exterior pressure (dimensionless). @@ -55,8 +59,12 @@ const double KAPPA = 1.4; // CFL value. const double CFL_NUMBER = 0.1; // Initial time step. -double time_step = 1E-5; +double time_step_n = 1E-5; +double TIME_INTERVAL_LENGTH = 20.; + +// Mesh filename. +const std::string MESH_FILENAME = "square.mesh"; // Boundary markers. const std::string BDY_INLET = "Inlet"; const std::string BDY_SOLID_WALL = "Solid"; @@ -73,49 +81,14 @@ const double MESH_SIZE = 3.0; int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh), mesh_heat(new Mesh); - MeshReaderH2D mloader; - mloader.load("square.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT_FLOW)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT_FLOW)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT_FLOW)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT_FLOW)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - - // Initialize solutions, set initial conditions. +#include "../euler-init-main.cpp" + + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new InitialSolutionLinearProgress (mesh, RHO_INITIAL_HIGH, RHO_INITIAL_LOW, MESH_SIZE)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, 0.0)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, 0.0)); MeshFunctionSharedPtr prev_e(new InitialSolutionLinearProgress (mesh, QuantityCalculator::calc_energy(RHO_INITIAL_HIGH, RHO_INITIAL_HIGH * V1_EXT, RHO_INITIAL_HIGH * V2_EXT, P_INITIAL_HIGH, KAPPA), QuantityCalculator::calc_energy(RHO_INITIAL_LOW, RHO_INITIAL_LOW * V1_EXT, RHO_INITIAL_LOW * V2_EXT, P_INITIAL_LOW, KAPPA), MESH_SIZE)); - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr pressure(new PressureFilter (Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr vel_x(new VelocityFilter (Hermes::vector >(prev_rho, prev_rho_v_x))); - MeshFunctionSharedPtr vel_y(new VelocityFilter(Hermes::vector >(prev_rho, prev_rho_v_y))); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 800, 600)); - VectorView velocity_view("Velocity", new WinGeom(0, 700, 800, 600)); - ScalarView density_view("Density", new WinGeom(900, 0, 800, 600)); - - // Set up the solver, matrix, and rhs according to the solver selection. - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); - Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - - // Set up stability calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - // Look for a saved solution on the disk. - int iteration = 0; double t = 0; - // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); @@ -123,84 +96,8 @@ int main(int argc, char* argv[]) inlet_markers.push_back(BDY_INLET); Hermes::vector outlet_markers; - EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, solid_wall_markers, - inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - - // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - - // Time stepping loop. - for(; t < 10.0; t += time_step) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Set the current time step. - wf.set_current_time_step(time_step); - - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - dp.assemble(matrix, rhs); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) - { - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); - - flux_limiter->limit_according_to_detector(); - - flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); - - CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); - - // Visualization. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - pressure->reinit(); - vel_x->reinit(); - vel_y->reinit(); - pressure_view.show(pressure); - velocity_view.show(vel_x, vel_y); - density_view.show(prev_rho); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); - } - } - } - - pressure_view.close(); - velocity_view.close(); - density_view.close(); - - return 0; + EulerEquationsWeakFormSemiImplicit wf(KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT,solid_wall_markers, + inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); + +#include "../euler-time-loop.cpp" } diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index e28159f..4f6c7ab 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -19,63 +19,75 @@ using namespace Hermes::Hermes2D::RefinementSelectors; // // The following parameters can be changed: -// Frequently changed parameters. +// Visualization. // Set to "true" to enable Hermes OpenGL visualization. -const bool HERMES_VISUALIZATION = false; -// Maximum polynomial degree used. -1 for unlimited. -const int MAX_P_ORDER = 1; -// Time interval length. -const double T_END = 1.0; -// Shock capturing. -bool SHOCK_CAPTURING = true; - +const bool HERMES_VISUALIZATION = true; // Set to "true" to enable VTK output. const bool VTK_VISUALIZATION = false; - // Set visual output for every nth step. const unsigned int EVERY_NTH_STEP = 1; - -// Quantitative parameter of the discontinuity detector. +// Shock capturing. +enum shockCapturingType +{ + FEISTAUER, + KUZMIN, + KRIVODONOVA +}; +bool SHOCK_CAPTURING = true; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +// Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; +// Quantitative parameter of the shock capturing in case of Feistauer. +const double NU_1 = 0.1; +const double NU_2 = 0.1; // Initial polynomial degree. const int P_INIT = 0; - -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 4; - +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 2; // CFL value. -double CFL_NUMBER = 0.1; - +double CFL_NUMBER = 0.1; // Initial time step. -double time_step = 1E-4; +double time_step_n = 1E-6; +double TIME_INTERVAL_LENGTH = 20.; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -const MatrixSolverType matrix_solver = SOLVER_UMFPACK; - -// Adaptivity. // Every UNREF_FREQth time step the mesh is unrefined. const int UNREF_FREQ = 5; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since // last unrefinement. -int REFINEMENT_COUNT = 0; +int REFINEMENT_COUNT = 0; // This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.5; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +// it has different meanings for various adaptive strategies (see below). +const double THRESHOLD = 0.3; + +// Predefined list of element refinement candidates. Possible values are +// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, +// H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. +CandList CAND_LIST = H2D_HP_ANISO; + +// Maximum polynomial degree used. -1 for unlimited. +// See User Documentation for details. +const int MAX_P_ORDER = 1; + +// Maximum allowed level of hanging nodes: +// MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default), +// MESH_REGULARITY = 1 ... at most one-level hanging nodes, +// MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc. +// Note that regular meshes are not supported, this is due to +// their notoriously bad performance. +const int MESH_REGULARITY = -1; + // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +double adaptivityErrorStop(int iteration) +{ + if(iteration > 49) + return 0.01; + else + return 0.5 - iteration * 0.01; +} // Equation parameters. const double KAPPA = 1.4; @@ -97,6 +109,8 @@ const double V1_INIT = 2.9; const double V2_INIT = 0.0; const double PRESSURE_INIT = 0.714286; +// Mesh filename. +const std::string MESH_FILENAME = "channel.mesh"; // Boundary markers. const std::string BDY_SOLID_WALL = "1"; const std::string BDY_OUTLET = "2"; @@ -111,43 +125,18 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); +#include "../euler-init-main-adapt.cpp" - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - - // Initialize solutions, set initial conditions. + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_INIT)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); MeshFunctionSharedPtr prev_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); - MeshFunctionSharedPtr sln_rho(new ConstantSolution(mesh, RHO_INIT)); - MeshFunctionSharedPtr sln_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); - MeshFunctionSharedPtr sln_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); - MeshFunctionSharedPtr sln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); - - MeshFunctionSharedPtr rsln_rho(new ConstantSolution(mesh, RHO_INIT)); - MeshFunctionSharedPtr rsln_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); - MeshFunctionSharedPtr rsln_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); - MeshFunctionSharedPtr rsln_e(new ConstantSolution (mesh, QuantityCalculator::calc_energy(RHO_INIT, RHO_INIT * V1_INIT, RHO_INIT * V2_INIT, PRESSURE_INIT, KAPPA))); - // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); - + Hermes::vector inlet_markers(BDY_INLET_LEFT, BDY_INLET_TOP); Hermes::vector rho_ext(RHO_LEFT, RHO_TOP); Hermes::vector v1_ext(V1_LEFT, V1_TOP); @@ -157,210 +146,7 @@ int main(int argc, char* argv[]) Hermes::vector outlet_markers; outlet_markers.push_back(BDY_OUTLET); - EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA)); - MeshFunctionSharedPtr entropy(new EntropyFilter(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), KAPPA, RHO_INIT, P_INIT)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); - ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); - Orderizer orderizer; - OrderView space_view("Space", new WinGeom(0, 0, 1500, 700)); - - // Initialize refinement selector. - L2ProjBasedSelector selector(CAND_LIST); - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - LinearSolver solver(&dp); - - // Time stepping loop. - double t = 0.0; - int iteration = 0; - for(; t < T_END && iteration < 25; t += time_step) - { - CFL.set_number(CFL_NUMBER + (t/4.0) * 1.0); - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Periodic global derefinements. - if (iteration > 1 && iteration % UNREF_FREQ == 0) - { - if(REFINEMENT_COUNT > 0) - { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - REFINEMENT_COUNT = 0; - - space_rho->unrefine_all_mesh_elements(true); - - space_rho->adjust_element_order(-1, P_INIT); - space_rho_v_x->adjust_element_order(-1, P_INIT); - space_rho_v_y->adjust_element_order(-1, P_INIT); - space_e->adjust_element_order(-1, P_INIT); - - Space::assign_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - } - } - - // Adaptivity loop: - int as = 1; - int ndofs_prev = 0; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); - - // Construct globally refined reference mesh and setup reference space. - int order_increase = (CAND_LIST == H2D_HP_ANISO ? 1 : 0); - - Mesh::ReferenceMeshCreator refMeshCreatorFlow(mesh); - MeshSharedPtr ref_mesh = refMeshCreatorFlow.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreatorRho(space_rho, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho = refSpaceCreatorRho.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVx(space_rho_v_x, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_x = refSpaceCreatorRhoVx.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorRhoVy(space_rho_v_y, ref_mesh, order_increase); - SpaceSharedPtr ref_space_rho_v_y = refSpaceCreatorRhoVy.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorE(space_e, ref_mesh, order_increase); - SpaceSharedPtr ref_space_e = refSpaceCreatorE.create_ref_space(); - - Hermes::vector > ref_spaces(ref_space_rho, ref_space_rho_v_x, ref_space_rho_v_y, ref_space_e); - - if(ndofs_prev != 0) - if(Space::get_num_dofs(ref_spaces) == ndofs_prev) - selector.set_error_weights(2.0 * selector.get_error_weight_h(), 1.0, 1.0); - else - selector.set_error_weights(1.0, 1.0, 1.0); - - ndofs_prev = Space::get_num_dofs(ref_spaces); - - // Project the previous time level solution onto the new fine mesh-> - Hermes::Mixins::Loggable::Static::info("Projecting the previous time level solution onto the new fine mesh->"); - OGProjection ogProjection; - ogProjection.project_global(ref_spaces, Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), - Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), Hermes::vector()); - - // Report NDOFs. - Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d.", - Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), Space::get_num_dofs(ref_spaces)); - - // Assemble the reference problem. - Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - - solver.set_spaces(ref_spaces); - wf.set_current_time_step(time_step); - - solver.solve(); - - if(!SHOCK_CAPTURING) - Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - else - { - FluxLimiter flux_limiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces, true); - - flux_limiter.limit_second_orders_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter.limit_according_to_detector(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); - - flux_limiter.get_limited_solutions(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)); - } - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - ogProjection.project_global(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), - Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - Adapt adaptivity(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector(HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM, HERMES_L2_NORM)); - double err_est_rel_total = adaptivity.calc_err_est(Hermes::vector >(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e), - Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e)) * 100; - - CFL.calculate_semi_implicit(Hermes::vector >(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e), (ref_spaces)[0]->get_mesh(), time_step); - - // Report results. - Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%", err_est_rel_total); - - // If err_est too large, adapt the mesh. - if (Space::get_num_dofs(ref_spaces) > NDOF_STOP || err_est_rel_total < THRESHOLD) - { - done = true; - } - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - REFINEMENT_COUNT++; - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector, &selector), - THRESHOLD, STRATEGY, MESH_REGULARITY); - - if(!done) - as++; - } - - // Visualization and saving on disk. - //if(done) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - //pressure->reinit(); - //entropy->reinit(); - //pressure_view.show(pressure); - Mach_number_view.show(Mach_number); - space_view.show(ref_space_rho); - - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Mach_number->reinit(); - Linearizer lin; - char filename[40]; - //sprintf(filename, "Pressure-%i.vtk", iteration - 1); - //lin.save_solution_vtk(pressure, filename, "Pressure", false); - sprintf(filename, "Mach number-%i.vtk", iteration - 1); - lin.save_solution_vtk(Mach_number, filename, "MachNumber", false); - sprintf(filename, "Mesh-%i.vtk", iteration - 1); - orderizer.save_mesh_vtk(ref_space_rho, filename); - sprintf(filename, "Space-%i.vtk", iteration - 1); - orderizer.save_orders_vtk(ref_space_rho, filename); - } - } - - // Clean up. - - } - while (done == false); - - - // Copy the solutions into the previous time level ones. - prev_rho->copy(rsln_rho); - prev_rho_v_x->copy(rsln_rho_v_x); - prev_rho_v_y->copy(rsln_rho_v_y); - prev_e->copy(rsln_e); - } - - if(HERMES_VISUALIZATION) - { - pressure_view.close(); - entropy_production_view.close(); - Mach_number_view.close(); - } + EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); - return 0; +#include "../euler-time-loop-space-adapt.cpp" } diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index 9b4dea6..baad2d5 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -50,10 +50,7 @@ const int INIT_REF_NUM = 3; // CFL value. double CFL_NUMBER = 0.1; // Initial time step. -double time_step = 1E-4; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -const MatrixSolverType matrix_solver = SOLVER_UMFPACK; +double time_step_n = 1E-4; double KAPPA = 1.4; @@ -76,6 +73,10 @@ const double V1_INIT = 2.9; const double V2_INIT = 0.0; const double PRESSURE_INIT = 0.714286; +double TIME_INTERVAL_LENGTH = 20.; + +// Mesh filename. +const std::string MESH_FILENAME = "channel.mesh"; // Boundary markers. const std::string BDY_SOLID_WALL = "1"; const std::string BDY_OUTLET = "2"; @@ -90,25 +91,9 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { - // Load the mesh. - MeshSharedPtr mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("channel.mesh", mesh); - - // Perform initial mesh refinements. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(0, true); - - // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); - int ndof = Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); - - // Initialize solutions, set initial conditions. +#include "../euler-init-main.cpp" + + // Set initial conditions. MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_INIT)); MeshFunctionSharedPtr prev_rho_v_x(new ConstantSolution (mesh, RHO_INIT * V1_INIT)); MeshFunctionSharedPtr prev_rho_v_y(new ConstantSolution (mesh, RHO_INIT * V2_INIT)); @@ -117,7 +102,7 @@ int main(int argc, char* argv[]) // Initialize weak formulation. Hermes::vector solid_wall_markers; solid_wall_markers.push_back(BDY_SOLID_WALL); - + Hermes::vector inlet_markers(BDY_INLET_LEFT, BDY_INLET_TOP); Hermes::vector rho_ext(RHO_LEFT, RHO_TOP); Hermes::vector v1_ext(V1_LEFT, V1_TOP); @@ -129,100 +114,5 @@ int main(int argc, char* argv[]) EulerEquationsWeakFormSemiImplicit wf(KAPPA, rho_ext, v1_ext, v2_ext, pressure_ext, solid_wall_markers, inlet_markers, outlet_markers, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, (P_INIT == 0)); - // Filters for visualization of Mach number, pressure and entropy. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(700, 400, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(700, 700, 600, 300)); - ScalarView s1("prev_rho", new WinGeom(0, 0, 600, 300)); - ScalarView s2("prev_rho_v_x", new WinGeom(700, 0, 600, 300)); - ScalarView s3("prev_rho_v_y", new WinGeom(0, 400, 600, 300)); - ScalarView s4("prev_e", new WinGeom(700, 400, 600, 300)); - - // Set up CFL calculation class. - CFLCalculation CFL(CFL_NUMBER, KAPPA); - - if(SHOCK_CAPTURING && SHOCK_CAPTURING_TYPE == FEISTAUER) - wf.set_stabilization(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, NU_1, NU_2); - - // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(space_rho, space_rho_v_x, space_rho_v_y, space_e)); - LinearSolver solver(&dp); - solver.output_matrix(); - solver.output_rhs(); - - int iteration = 0.; - double t = 0.0; - - // Time stepping loop. - for(; t < 6.0; t += time_step) - { - Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f.", iteration++, t); - - // Set the current time step. - wf.set_current_time_step(time_step); - - // Assemble the stiffness matrix and rhs. - Hermes::Mixins::Loggable::Static::info("Assembling the stiffness matrix and right-hand side vector."); - - // Solve the matrix problem. - Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - solver.solve(); - if(!SHOCK_CAPTURING || SHOCK_CAPTURING_TYPE == FEISTAUER) - { - Solution::vector_to_solutions(solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); - - flux_limiter->limit_according_to_detector(); - - flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - } - - CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); - - // Visualization. - if((iteration - 1) % EVERY_NTH_STEP == 0) - { - // Hermes visualization. - if(HERMES_VISUALIZATION) - { - Mach_number->reinit(); - pressure->reinit(); - pressure_view.show(pressure); - Mach_number_view.show(Mach_number); - } - // Output solution in VTK format. - if(VTK_VISUALIZATION) - { - pressure->reinit(); - Mach_number->reinit(); - Linearizer lin_pressure; - char filename[40]; - sprintf(filename, "pressure-3D-%i.vtk", iteration - 1); - lin_pressure.save_solution_vtk(pressure, filename, "Pressure", true); - Linearizer lin_mach; - sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1); - lin_mach.save_solution_vtk(Mach_number, filename, "MachNumber", true); - } - } - } - - pressure_view.close(); - Mach_number_view.close(); - - return 0; +#include "../euler-time-loop.cpp" } From 5a63e0ae19f38a8ef501ac913639c5d6d0a041f2 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sun, 22 Sep 2013 18:13:21 +0200 Subject: [PATCH 43/64] Work on Euler --- 2d-advanced/euler/euler-init-main-adapt.cpp | 8 +- 2d-advanced/euler/euler-init-main.cpp | 8 +- .../euler/euler-time-loop-space-adapt.cpp | 23 +++-- 2d-advanced/euler/euler-time-loop.cpp | 84 ++++++++++++++----- 2d-advanced/euler/forms_explicit.cpp | 6 +- 2d-advanced/euler/gamm-channel/main.cpp | 12 +-- 2d-advanced/euler/initial_condition.cpp | 2 +- .../euler/reflected-shock-adapt/main.cpp | 13 ++- 8 files changed, 97 insertions(+), 59 deletions(-) diff --git a/2d-advanced/euler/euler-init-main-adapt.cpp b/2d-advanced/euler/euler-init-main-adapt.cpp index 0eef021..a184742 100644 --- a/2d-advanced/euler/euler-init-main-adapt.cpp +++ b/2d-advanced/euler/euler-init-main-adapt.cpp @@ -9,10 +9,10 @@ mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); diff --git a/2d-advanced/euler/euler-init-main.cpp b/2d-advanced/euler/euler-init-main.cpp index 3ced474..8be5e67 100644 --- a/2d-advanced/euler/euler-init-main.cpp +++ b/2d-advanced/euler/euler-init-main.cpp @@ -9,10 +9,10 @@ mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); SpaceSharedPtr space_stabilization(new L2Space(mesh, 0)); Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); int ndof = Space::get_num_dofs(spaces); diff --git a/2d-advanced/euler/euler-time-loop-space-adapt.cpp b/2d-advanced/euler/euler-time-loop-space-adapt.cpp index 725efb8..8d3f0fd 100644 --- a/2d-advanced/euler/euler-time-loop-space-adapt.cpp +++ b/2d-advanced/euler/euler-time-loop-space-adapt.cpp @@ -98,20 +98,19 @@ for(double t = 0.0; t < TIME_INTERVAL_LENGTH; t += time_step_n) Solution::vector_to_solutions(solver.get_sln_vector(), ref_spaces, rslns); else { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), ref_spaces); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), ref_spaces); + if(SHOCK_CAPTURING_TYPE == KRIVODONOVA) + { + FluxLimiter* flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), ref_spaces); + flux_limiter->limit_according_to_detector(); + flux_limiter->get_limited_solutions(rslns); + delete flux_limiter; + } if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(spaces); - - flux_limiter->limit_according_to_detector(spaces); - - flux_limiter->get_limited_solutions(rslns); - - delete flux_limiter; + { + PostProcessing::VertexBasedLimiter limiter(ref_spaces, solver.get_sln_vector(), 1); + limiter.get_solutions(rslns); + } } #pragma endregion diff --git a/2d-advanced/euler/euler-time-loop.cpp b/2d-advanced/euler/euler-time-loop.cpp index ba15c12..5831cb0 100644 --- a/2d-advanced/euler/euler-time-loop.cpp +++ b/2d-advanced/euler/euler-time-loop.cpp @@ -1,15 +1,15 @@ Hermes::vector > prev_slns(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e); #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. - MeshFunctionSharedPtr Mach_number(new MachNumberFilter(prev_slns, KAPPA)); - MeshFunctionSharedPtr pressure(new PressureFilter(prev_slns, KAPPA)); - - ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); - ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); - ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); - ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); - OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); - #pragma endregion +MeshFunctionSharedPtr Mach_number(new MachNumberFilter(prev_slns, KAPPA)); +MeshFunctionSharedPtr pressure(new PressureFilter(prev_slns, KAPPA)); + +ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); +ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); +ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); +ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); +OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); +#pragma endregion EulerEquationsWeakFormStabilization wf_stabilization(prev_rho); DiscreteProblem dp_stabilization(&wf_stabilization, space_stabilization); @@ -59,18 +59,60 @@ for(double t = 0.0; t < TIME_INTERVAL_LENGTH; t += time_step_n) Solution::vector_to_solutions(solver.get_sln_vector(), spaces, prev_slns); else { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver.get_sln_vector(), spaces, true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), spaces); - - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); - - flux_limiter->limit_according_to_detector(); - - flux_limiter->get_limited_solutions(prev_slns); + if(SHOCK_CAPTURING_TYPE == KRIVODONOVA) + { + FluxLimiter* flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver.get_sln_vector(), spaces); + flux_limiter->limit_according_to_detector(); + flux_limiter->get_limited_solutions(prev_slns); + delete flux_limiter; + } + + if(SHOCK_CAPTURING_TYPE == KUZMIN) + { + PostProcessing::VertexBasedLimiter limiter(spaces, solver.get_sln_vector(), 1); + limiter.get_solutions(prev_slns); + + int running_dofs = 0; + int ndof = spaces[0]->get_num_dofs(); + double* density_sln_vector = limiter.get_solution_vector(); + Element* e; + AsmList al_density; + for(int component = 1; component < 4; component++) + { + if(spaces[component]->get_num_dofs() != ndof) + throw Exceptions::Exception("Euler code is supposed to be executed on a single mesh."); + + double* conservative_vector = limiter.get_solution_vector() + component * ndof; + double* real_vector = new double[ndof]; + memset(real_vector, 0, sizeof(double) * ndof); + + for_all_active_elements(e, spaces[0]->get_mesh()) + { + spaces[0]->get_element_assembly_list(e, &al_density); + + real_vector[al_density.dof[0]] = conservative_vector[al_density.dof[0]] / density_sln_vector[al_density.dof[0]]; + real_vector[al_density.dof[1]] = (conservative_vector[al_density.dof[1]] - real_vector[al_density.dof[0]] * density_sln_vector[al_density.dof[1]]) / density_sln_vector[al_density.dof[0]]; + real_vector[al_density.dof[2]] = (conservative_vector[al_density.dof[2]] - real_vector[al_density.dof[0]] * density_sln_vector[al_density.dof[2]]) / density_sln_vector[al_density.dof[0]]; + } + + PostProcessing::VertexBasedLimiter real_component_limiter(spaces[0], real_vector, 1); + real_component_limiter.get_solution(); + real_vector = real_component_limiter.get_solution_vector(); + + for_all_active_elements(e, spaces[0]->get_mesh()) + { + spaces[0]->get_element_assembly_list(e, &al_density); + + conservative_vector[al_density.dof[1]] = density_sln_vector[al_density.dof[0]] * real_vector[al_density.dof[1]] + + density_sln_vector[al_density.dof[1]] * real_vector[al_density.dof[0]]; + + conservative_vector[al_density.dof[2]] = density_sln_vector[al_density.dof[0]] * real_vector[al_density.dof[2]] + + density_sln_vector[al_density.dof[2]] * real_vector[al_density.dof[0]]; + } + + Solution::vector_to_solution(conservative_vector, spaces[0], prev_slns[component]); + } + } } #pragma endregion } diff --git a/2d-advanced/euler/forms_explicit.cpp b/2d-advanced/euler/forms_explicit.cpp index fc333b0..f9ee168 100644 --- a/2d-advanced/euler/forms_explicit.cpp +++ b/2d-advanced/euler/forms_explicit.cpp @@ -681,7 +681,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return Ord(10); } MatrixFormSurf* clone() const @@ -812,7 +812,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return Ord(10); } VectorFormSurf* clone() const @@ -889,7 +889,7 @@ class EulerEquationsWeakFormSemiImplicit : public WeakForm Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, Geom *e, Func* *ext) const { - return Ord(24); + return Ord(10); } MatrixFormSurf* clone() const diff --git a/2d-advanced/euler/gamm-channel/main.cpp b/2d-advanced/euler/gamm-channel/main.cpp index 9a1d6d3..324065c 100644 --- a/2d-advanced/euler/gamm-channel/main.cpp +++ b/2d-advanced/euler/gamm-channel/main.cpp @@ -31,8 +31,8 @@ enum shockCapturingType KUZMIN, KRIVODONOVA }; -bool SHOCK_CAPTURING = false; -shockCapturingType SHOCK_CAPTURING_TYPE = FEISTAUER; +bool SHOCK_CAPTURING = true; +shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; // Quantitative parameter of the shock capturing in case of Feistauer. @@ -40,11 +40,11 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 0; -// Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int P_INIT = 1; +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 4; // CFL value. -double CFL_NUMBER = 0.9; +double CFL_NUMBER = 0.1; // Initial time step. double time_step_n = 1E-6; diff --git a/2d-advanced/euler/initial_condition.cpp b/2d-advanced/euler/initial_condition.cpp index d1a478c..b694ebf 100644 --- a/2d-advanced/euler/initial_condition.cpp +++ b/2d-advanced/euler/initial_condition.cpp @@ -43,7 +43,7 @@ class InitialSolutionLinearProgress : public ExactSolutionScalar dy = - (max - min) / size; }; - virtual Ord ord(Ord x, Ord y) const { + virtual Ord ord(double x, double y) const { return Ord(1); } diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index 4f6c7ab..89ea6c1 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -42,17 +42,17 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 0; +const int P_INIT = 1; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 2; // CFL value. -double CFL_NUMBER = 0.1; +double CFL_NUMBER = 0.3; // Initial time step. double time_step_n = 1E-6; double TIME_INTERVAL_LENGTH = 20.; // Every UNREF_FREQth time step the mesh is unrefined. -const int UNREF_FREQ = 5; +const int UNREF_FREQ = 10; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since @@ -66,7 +66,7 @@ const double THRESHOLD = 0.3; // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_HP_ANISO; +CandList CAND_LIST = H2D_H_ANISO; // Maximum polynomial degree used. -1 for unlimited. // See User Documentation for details. @@ -83,10 +83,7 @@ const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. double adaptivityErrorStop(int iteration) { - if(iteration > 49) - return 0.01; - else - return 0.5 - iteration * 0.01; + return 0.02; } // Equation parameters. From 1bbf58fcf5b392045db10fb5cf555592024ab871 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 24 Sep 2013 09:33:47 +0200 Subject: [PATCH 44/64] Fix Richards weak formulation for Picard. --- .../richards/basic-ie-picard/definitions.cpp | 18 +++++------------- 2d-advanced/richards/basic-ie-picard/main.cpp | 1 - 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/2d-advanced/richards/basic-ie-picard/definitions.cpp b/2d-advanced/richards/basic-ie-picard/definitions.cpp index 5aa4c78..a3b54cd 100644 --- a/2d-advanced/richards/basic-ie-picard/definitions.cpp +++ b/2d-advanced/richards/basic-ie-picard/definitions.cpp @@ -39,14 +39,11 @@ double CustomWeakFormRichardsIEPicard::CustomJacobian::value(int n, double *wt, Func *v, Geom *e, Func* *ext) const { double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext[0]; - Func* h_prev_picard = ext[1]; + Func* h_prev_picard = u_ext[0]; for (int i = 0; i < n; i++) { - double h_prev_newton_i = h_prev_newton->val[i] - H_OFFSET; double h_prev_picard_i = h_prev_picard->val[i] - H_OFFSET; - double h_prev_time_i = h_prev_time->val[i] - H_OFFSET; + result += wt[i] * ( static_cast(wf)->constitutive->C(h_prev_picard_i) * u->val[i] * v->val[i] + static_cast(wf)->constitutive->K(h_prev_picard_i) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) * time_step - static_cast(wf)->constitutive->dKdh(h_prev_picard_i) * u->dy[i] * v->val[i] * time_step @@ -70,18 +67,13 @@ double CustomWeakFormRichardsIEPicard::CustomResidual::value(int n, double *wt, Func* *ext) const { double result = 0; - Func* h_prev_newton = u_ext[0]; + Func* h_prev_picard = u_ext[0]; Func* h_prev_time = ext[0]; - Func* h_prev_picard = ext[1]; for (int i = 0; i < n; i++) { - double h_prev_newton_i = h_prev_newton->val[i] - H_OFFSET; double h_prev_picard_i = h_prev_picard->val[i] - H_OFFSET; - double h_prev_time_i = h_prev_time->val[i] - H_OFFSET; - result += wt[i] * ( static_cast(wf)->constitutive->C(h_prev_picard_i) * (h_prev_newton_i - h_prev_time_i) * v->val[i] - + static_cast(wf)->constitutive->K(h_prev_picard_i) * (h_prev_newton->dx[i] * v->dx[i] + h_prev_newton->dy[i] * v->dy[i]) * time_step - - static_cast(wf)->constitutive->dKdh(h_prev_picard_i) * h_prev_newton->dy[i] * v->val[i] * time_step - ); + double h_prev_time_i = h_prev_time->val[i];// - H_OFFSET; + result += wt[i] * static_cast(wf)->constitutive->C(h_prev_picard_i) * (h_prev_time_i) * v->val[i]; } return result; } diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index 65fcaed..41a3037 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -120,7 +120,6 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("---- Time step %d, time %3.5f s", ts, current_time); // Perform the Picard's iteration (Anderson acceleration on by default). - picard.set_tolerance(PICARD_TOL); picard.set_max_allowed_iterations(PICARD_MAX_ITER); picard.set_num_last_vector_used(PICARD_NUM_LAST_ITER_USED); picard.set_anderson_beta(PICARD_ANDERSON_BETA); From 638bf939f9740f871a8314a3f1117c33da01ae37 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 24 Sep 2013 09:46:52 +0200 Subject: [PATCH 45/64] Fix examples wrt. recent changes. --- 1d/layer-boundary/definitions.cpp | 2 +- 1d/layer-boundary/definitions.h | 2 +- 1d/moving-front/definitions.cpp | 2 +- 1d/moving-front/definitions.h | 2 +- 1d/system/definitions.cpp | 8 ++-- 1d/system/definitions.h | 8 ++-- .../acoustics/wave-propagation/definitions.h | 4 +- .../linear-advection-diffusion/main.cpp | 4 +- .../elasticity-linear/bracket/main.cpp | 3 +- 2d-advanced/elasticity-linear/crack/main.cpp | 2 +- 2d-advanced/euler/CMakeLists.txt | 2 +- .../heating-flow-coupling-adapt/main.cpp | 34 +++++++-------- .../euler/heating-flow-coupling/main.cpp | 43 +++++++++---------- 2d-advanced/heat-transfer/CMakeLists.txt | 4 +- 2d-advanced/helmholtz/waveguide/main.cpp | 2 +- .../maxwell/magnetostatics/definitions.cpp | 4 +- .../maxwell/magnetostatics/definitions.h | 2 +- 2d-advanced/maxwell/magnetostatics/main.cpp | 4 +- .../maxwell/maxwell-debye-rk/definitions.cpp | 6 +-- .../maxwell/maxwell-debye-rk/definitions.h | 6 +-- 2d-advanced/maxwell/microwave-oven/main.cpp | 2 +- .../resonator-time-domain-I/definitions.cpp | 2 +- .../resonator-time-domain-I/definitions.h | 2 +- .../definitions.cpp | 2 +- .../resonator-time-domain-II-ie/definitions.h | 2 +- .../resonator-time-domain-II-ie/main.cpp | 2 +- .../definitions.cpp | 2 +- .../resonator-time-domain-II-rk/definitions.h | 2 +- 2d-advanced/navier-stokes/bearing/main.cpp | 2 +- .../circular-obstacle-adapt/main.cpp | 2 +- .../navier-stokes/circular-obstacle/main.cpp | 2 +- .../navier-stokes/driven-cavity/main.cpp | 2 +- .../ns-heat-subdomains/definitions.cpp | 2 +- .../ns-heat-subdomains/definitions.h | 2 +- .../navier-stokes/rayleigh-benard/main.cpp | 2 +- .../np-poisson-timedep-adapt/main.cpp | 8 ++-- 2d-advanced/richards/CMakeLists.txt | 2 +- 2d-advanced/richards/basic-ie-newton/main.cpp | 1 - .../capillary-barrier-adapt/definitions.h | 6 +-- .../richards/capillary-barrier-adapt/main.cpp | 4 +- 2d-advanced/schroedinger/CMakeLists.txt | 2 +- .../gross-pitaevski-adapt/definitions.cpp | 2 +- .../gross-pitaevski-adapt/definitions.h | 2 +- .../gross-pitaevski/definitions.cpp | 4 +- .../gross-pitaevski/definitions.h | 2 +- .../wave-equation/wave-1/definitions.cpp | 2 +- .../wave-equation/wave-1/definitions.h | 2 +- .../layer-boundary/definitions.cpp | 2 +- .../layer-boundary/definitions.h | 2 +- .../layer-interior/definitions.cpp | 2 +- .../layer-interior/definitions.h | 2 +- 2d-benchmarks-general/lshape/definitions.cpp | 2 +- 2d-benchmarks-general/lshape/definitions.h | 2 +- .../moving-front-space-adapt/definitions.cpp | 2 +- .../moving-front-space-adapt/definitions.h | 2 +- .../nonsym-check/definitions.cpp | 2 +- .../nonsym-check/definitions.h | 2 +- .../smooth-aniso-x/definitions.cpp | 2 +- .../smooth-aniso-x/definitions.h | 2 +- .../smooth-aniso-y/definitions.cpp | 2 +- .../smooth-aniso-y/definitions.h | 2 +- .../smooth-iso/definitions.cpp | 2 +- .../smooth-iso/definitions.h | 2 +- .../01-analytic-solution/definitions.cpp | 2 +- .../01-analytic-solution/definitions.h | 2 +- .../02-reentrant-corner/definitions.cpp | 2 +- .../02-reentrant-corner/definitions.h | 2 +- .../03-linear-elasticity/definitions.cpp | 4 +- .../03-linear-elasticity/definitions.h | 4 +- .../03-linear-elasticity/main.cpp | 2 +- .../04-exponential-peak/definitions.cpp | 2 +- .../04-exponential-peak/definitions.h | 2 +- .../04-exponential-peak/main.cpp | 2 +- 2d-benchmarks-nist/05-battery/main.cpp | 2 +- .../06-boundary-layer/definitions.cpp | 2 +- .../06-boundary-layer/definitions.h | 2 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 4 +- .../definitions.cpp | 2 +- .../definitions.h | 2 +- .../07-boundary-line-singularity/main.cpp | 2 +- .../08-oscillatory/definitions.cpp | 2 +- .../08-oscillatory/definitions.h | 2 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 2 +- .../09-wave-front-kelly-dealii/definitions.h | 2 +- .../09-wave-front-kelly/definitions.h | 2 +- .../09-wave-front/definitions.h | 2 +- .../definitions.cpp | 2 +- .../definitions.h | 2 +- 2d-benchmarks-nist/11-kellogg/definitions.cpp | 2 +- 2d-benchmarks-nist/11-kellogg/definitions.h | 2 +- .../12-multiple-difficulties/definitions.cpp | 2 +- .../12-multiple-difficulties/definitions.h | 2 +- .../12-multiple-difficulties/main.cpp | 6 +-- 93 files changed, 152 insertions(+), 161 deletions(-) diff --git a/1d/layer-boundary/definitions.cpp b/1d/layer-boundary/definitions.cpp index 6384257..278f226 100644 --- a/1d/layer-boundary/definitions.cpp +++ b/1d/layer-boundary/definitions.cpp @@ -36,7 +36,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = 0; } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/1d/layer-boundary/definitions.h b/1d/layer-boundary/definitions.h index a230b30..4dc92c2 100644 --- a/1d/layer-boundary/definitions.h +++ b/1d/layer-boundary/definitions.h @@ -31,7 +31,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; ~CustomExactSolution(); diff --git a/1d/moving-front/definitions.cpp b/1d/moving-front/definitions.cpp index e5f95c5..24b8f83 100644 --- a/1d/moving-front/definitions.cpp +++ b/1d/moving-front/definitions.cpp @@ -17,7 +17,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = 0; } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/1d/moving-front/definitions.h b/1d/moving-front/definitions.h index b1d4f70..51e2ea4 100644 --- a/1d/moving-front/definitions.h +++ b/1d/moving-front/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double x0, x1, y0, y1, *t_ptr, s, c; }; diff --git a/1d/system/definitions.cpp b/1d/system/definitions.cpp index 7fcbccc..88a3655 100644 --- a/1d/system/definitions.cpp +++ b/1d/system/definitions.cpp @@ -47,7 +47,7 @@ double CustomRightHandSide1::value(double x, double y) const return -d_u * d_u * Laplace_u - u + sigma * v; } -Hermes::Ord CustomRightHandSide1::ord(Hermes::Ord x, Hermes::Ord y) const +Hermes::Ord CustomRightHandSide1::ord (Hermes::Ord x, Hermes::Ord y) const { return Hermes::Ord(10); } @@ -73,7 +73,7 @@ double CustomRightHandSide2::value(double x, double y) const return -d_v*d_v * Laplace_v - u + v; } -Hermes::Ord CustomRightHandSide2::ord(Hermes::Ord x, Hermes::Ord y) const +Hermes::Ord CustomRightHandSide2::ord (Hermes::Ord x, Hermes::Ord y) const { return Hermes::Ord(10); } @@ -102,7 +102,7 @@ void ExactSolutionFitzHughNagumo1::derivatives (double x, double y, double& dx, dy = 0; } -Hermes::Ord ExactSolutionFitzHughNagumo1::ord(Hermes::Ord x, Hermes::Ord y) const +Hermes::Ord ExactSolutionFitzHughNagumo1::ord (double x, double y) const { return Hermes::Ord(10); } @@ -135,7 +135,7 @@ void ExactSolutionFitzHughNagumo2::derivatives (double x, double y, double& dx, dy = 0; } -Hermes::Ord ExactSolutionFitzHughNagumo2::ord(Hermes::Ord x, Hermes::Ord y) const +Hermes::Ord ExactSolutionFitzHughNagumo2::ord (double x, double y) const { return Hermes::Ord(10); } diff --git a/1d/system/definitions.h b/1d/system/definitions.h index d3c4b21..6e9be14 100644 --- a/1d/system/definitions.h +++ b/1d/system/definitions.h @@ -39,7 +39,7 @@ class CustomRightHandSide1: public Hermes::Hermes2DFunction virtual double value(double x, double y) const; - virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const; + virtual Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const; ~CustomRightHandSide1(); @@ -55,7 +55,7 @@ class CustomRightHandSide2: public Hermes::Hermes2DFunction virtual double value(double x, double y) const; - virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const; + virtual Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const; ~CustomRightHandSide2(); @@ -75,7 +75,7 @@ class ExactSolutionFitzHughNagumo1 : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const; + virtual Hermes::Ord ord (double x, double y) const; ~ExactSolutionFitzHughNagumo1(); @@ -92,7 +92,7 @@ class ExactSolutionFitzHughNagumo2 : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const; + virtual Hermes::Ord ord (double x, double y) const; ~ExactSolutionFitzHughNagumo2(); diff --git a/2d-advanced/acoustics/wave-propagation/definitions.h b/2d-advanced/acoustics/wave-propagation/definitions.h index 6c215e4..faf0212 100644 --- a/2d-advanced/acoustics/wave-propagation/definitions.h +++ b/2d-advanced/acoustics/wave-propagation/definitions.h @@ -260,7 +260,7 @@ class exact_acoustic_transient_planar_linear_form_1_0_acoustic_pressure : public void derivatives (double x, double y, Scalar& dx, Scalar& dy) const {}; - Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const + Hermes::Ord ord (double x, double y) const { return Hermes::Ord(Hermes::Ord::get_max_order()); } @@ -287,7 +287,7 @@ class exact_acoustic_transient_planar_linear_form_2_0_acoustic_pressure : public void derivatives (double x, double y, Scalar& dx, Scalar& dy) const {}; - Hermes::Ord ord (Hermes::Ord x, Hermes::Ord y) const + Hermes::Ord ord (double x, double y) const { return Hermes::Ord(Hermes::Ord::get_max_order()); } diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index da5cfcf..a7983a9 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -122,8 +122,8 @@ int main(int argc, char* argv[]) // Solve the linear system of the reference problem. // If successful, obtain the solution. - if(solver->solve()) Solution::vector_to_solution(solver->get_sln_vector(), ref_space, ref_sln); - else throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); + solver->solve(); + Solution::vector_to_solution(solver->get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 8505cc8..a4b68ad 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -221,8 +221,7 @@ int main(int argc, char* argv[]) else { Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector), - MULTI == true ? THRESHOLD_MULTI : THRESHOLD_SINGLE); + done = adaptivity.adapt(Hermes::vector *>(&selector, &selector)); } // Increase counter. diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 5ec580b..0db9f80 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -182,7 +182,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index 3a36e21..35b91aa 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -13,4 +13,4 @@ add_subdirectory(heating-induced-vortex-adapt) # add_subdirectory(euler-coupled-adapt) add_subdirectory(heating-flow-coupling) -add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file +#add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index 795ab42..36f9689 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -275,32 +275,28 @@ int main(int argc, char* argv[]) // Solve the matrix problem. Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) + solver->solve(); + if(!SHOCK_CAPTURING) { - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver->get_sln_vector(), cref_spaces, rslns); - } + Solution::vector_to_solutions(solver->get_sln_vector(), cref_spaces, rslns); + } + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), cref_flow_spaces, true); else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), cref_flow_spaces, true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), cref_flow_spaces); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), cref_flow_spaces); - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(flow_spaces); + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(flow_spaces); - flux_limiter->limit_according_to_detector(flow_spaces); + flux_limiter->limit_according_to_detector(flow_spaces); - flux_limiter->get_limited_solutions(rflow_slns); + flux_limiter->get_limited_solutions(rflow_slns); - Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(cref_flow_spaces), ref_space_temp, rsln_temp); - } + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(cref_flow_spaces), ref_space_temp, rsln_temp); } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 546d7c3..d6526b9 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -171,36 +171,33 @@ int main(int argc, char* argv[]) // Solve the matrix problem. Hermes::Mixins::Loggable::Static::info("Solving the matrix problem."); - if(solver->solve()) + solver->solve(); + + if(!SHOCK_CAPTURING) { - if(!SHOCK_CAPTURING) - { - Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e, space_temp), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp)); - } + Solution::vector_to_solutions(solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e, space_temp), Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e, prev_temp)); + } + else + { + FluxLimiter* flux_limiter; + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e), true); else - { - FluxLimiter* flux_limiter; - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter = new FluxLimiter(FluxLimiter::Kuzmin, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e), true); - else - flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)); + flux_limiter = new FluxLimiter(FluxLimiter::Krivodonova, solver->get_sln_vector(), Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)); - if(SHOCK_CAPTURING_TYPE == KUZMIN) - flux_limiter->limit_second_orders_according_to_detector(); + if(SHOCK_CAPTURING_TYPE == KUZMIN) + flux_limiter->limit_second_orders_according_to_detector(); - flux_limiter->limit_according_to_detector(); + flux_limiter->limit_according_to_detector(); - flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); + flux_limiter->get_limited_solutions(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e)); - Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, - space_rho_v_y, space_e)), space_temp, prev_temp); - } + Solution::vector_to_solution(solver->get_sln_vector() + Space::get_num_dofs(Hermes::vector >(space_rho, space_rho_v_x, + space_rho_v_y, space_e)), space_temp, prev_temp); } - else - throw Hermes::Exceptions::Exception("Matrix solver failed.\n"); CFL.calculate_semi_implicit(Hermes::vector >(prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e), mesh, time_step); diff --git a/2d-advanced/heat-transfer/CMakeLists.txt b/2d-advanced/heat-transfer/CMakeLists.txt index 9966d83..35eb78d 100644 --- a/2d-advanced/heat-transfer/CMakeLists.txt +++ b/2d-advanced/heat-transfer/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(wall-on-fire-adapt-space-and-time) -add_subdirectory(heat-and-moisture-adapt) +#add_subdirectory(wall-on-fire-adapt-space-and-time) +#add_subdirectory(heat-and-moisture-adapt) diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index 1caa957..4166705 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) ndof = Space::get_num_dofs(Hermes::vector >(e_r_space, e_i_space)); Hermes::Hermes2D::NewtonSolver newton(&dp); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); ScalarView viewEr("Er [V/m]", new WinGeom(600, 0, 700, 200)); diff --git a/2d-advanced/maxwell/magnetostatics/definitions.cpp b/2d-advanced/maxwell/magnetostatics/definitions.cpp index e17d9f6..04d65d0 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.cpp +++ b/2d-advanced/maxwell/magnetostatics/definitions.cpp @@ -54,9 +54,9 @@ FilterFluxDensity::FilterFluxDensity(Hermes::vector* FilterFluxDensity::get_pt_value(double x, double y, Element* e) +Func* FilterFluxDensity::get_pt_value(double x, double y, bool use_MeshHashGrid, Element* e) { - throw Hermes::Exceptions::Exception("Not implemented yet"); return 0; + throw Hermes::Exceptions::Exception("Not implemented yet"); return NULL; } MeshFunction* FilterFluxDensity::clone() const diff --git a/2d-advanced/maxwell/magnetostatics/definitions.h b/2d-advanced/maxwell/magnetostatics/definitions.h index 0aa4f42..36b6df3 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.h +++ b/2d-advanced/maxwell/magnetostatics/definitions.h @@ -35,7 +35,7 @@ class FilterFluxDensity : public Hermes::Hermes2D::Filter public: FilterFluxDensity(Hermes::vector > solutions); - virtual Func* get_pt_value(double x, double y, Element* e = NULL); + virtual Func* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = NULL); virtual MeshFunction* clone() const; protected: diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 90d5682..53f514a 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -109,13 +109,13 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. Hermes::Hermes2D::NewtonSolver newton(&dp); - newton.set_manual_damping_coeff(0.1); + newton.set_manual_damping_coeff(true, 0.1); newton.set_sufficient_improvement_factor_jacobian(0.5); newton.set_max_steps_with_reused_jacobian(5); try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp b/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp index cd879e1..992db29 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/definitions.cpp @@ -32,7 +32,7 @@ void CustomInitialConditionE::derivatives (double x, double y, Scalar2& dy[1] = omega*k_x*exp(-omega*time) * std::sin(k_x * M_PI * x) * (-1.0*std::sin(k_y * M_PI * y)*k_y*M_PI); } -Ord CustomInitialConditionE::ord(Ord x, Ord y) const +Ord CustomInitialConditionE::ord(double x, double y) const { return Ord(20); } @@ -51,7 +51,7 @@ void CustomInitialConditionH::derivatives (double x, double y, double& dx, doubl dy = k_squared * M_PI * exp(-omega*time) * std::cos(k_x * M_PI * x) * (-1.0*std::sin(k_y * M_PI * y)*k_y*M_PI); } -Ord CustomInitialConditionH::ord(Ord x, Ord y) const +Ord CustomInitialConditionH::ord(double x, double y) const { return Ord(20); } @@ -76,7 +76,7 @@ void CustomInitialConditionP::derivatives (double x, double y, Scalar2& dy[1] = -k_x*alpha(omega, k)*exp(-omega*time) * std::sin(k_x * M_PI * x) * (-1.0*std::sin(k_y * M_PI * y)*k_y*M_PI); } -Ord CustomInitialConditionP::ord(Ord x, Ord y) const +Ord CustomInitialConditionP::ord(double x, double y) const { return Ord(20); } diff --git a/2d-advanced/maxwell/maxwell-debye-rk/definitions.h b/2d-advanced/maxwell/maxwell-debye-rk/definitions.h index b6dbc94..067ef90 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/definitions.h +++ b/2d-advanced/maxwell/maxwell-debye-rk/definitions.h @@ -23,7 +23,7 @@ class CustomInitialConditionE : public ExactSolutionVector virtual void derivatives (double x, double y, Scalar2& dx, Scalar2& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const { return new CustomInitialConditionE(mesh, time, omega, k_x, k_y); } double time, omega, k_x, k_y; @@ -41,7 +41,7 @@ class CustomInitialConditionH : public ExactSolutionScalar virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const { return new CustomInitialConditionH(mesh, time, omega, k_x, k_y); } double time, omega, k_x, k_y; @@ -59,7 +59,7 @@ class CustomInitialConditionP : public ExactSolutionVector virtual void derivatives (double x, double y, Scalar2& dx, Scalar2& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const { return new CustomInitialConditionP(mesh, time, omega, k_x, k_y); } double time, omega, k_x, k_y; }; diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 515b876..317b130 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -150,7 +150,7 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::NewtonSolver newton(&wf, space); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); // Newton's iteration. // Adaptivity loop: diff --git a/2d-advanced/maxwell/resonator-time-domain-I/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-I/definitions.cpp index 744303b..3e447fe 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/definitions.cpp @@ -15,7 +15,7 @@ void CustomInitialConditionWave::derivatives (double x, double y, Scalar2 virtual void derivatives (double x, double y, Scalar2& dx, Scalar2& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; MeshFunction* clone() const; }; diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp index 4ec24e5..bbce812 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/definitions.cpp @@ -169,7 +169,7 @@ void CustomInitialConditionWave::derivatives (double x, double y, Scalar2 virtual void derivatives (double x, double y, Scalar2& dx, Scalar2& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; MeshFunction* clone() const; }; diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index c44bf04..061c3e9 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp index 97bb5a2..d2cecd2 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/definitions.cpp @@ -31,7 +31,7 @@ void CustomInitialConditionWave::derivatives (double x, double y, Scalar2 virtual void derivatives (double x, double y, Scalar2& dx, Scalar2& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const; }; diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 0fec8e4..113d603 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index e02f777..7ea9527 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -268,7 +268,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V { newton.set_spaces(ref_spaces); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); if(as == 2) newton.output_matrix(); newton.solve(coeff_vec); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 2b30fee..127e8e8 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::NewtonSolver newton(&dp); Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.set_jacobian_constant(); // Initialize views. diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index 014d9db..b779343 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -175,7 +175,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp index 7e3268c..68798fa 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.cpp @@ -19,7 +19,7 @@ void CustomInitialConditionTemperature::derivatives(double x, double y, double& dy = 0; } -Ord CustomInitialConditionTemperature::ord(Ord x, Ord y) const +Ord CustomInitialConditionTemperature::ord(double x, double y) const { return Ord(1); } diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h index 9ee67bd..7de223b 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/definitions.h @@ -26,7 +26,7 @@ class CustomInitialConditionTemperature : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; MeshFunction* clone() const; diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index d2afe80..5a2f4da 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -158,7 +158,7 @@ SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_V try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index cd89714..4d08986 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -216,8 +216,8 @@ int main (int argc, char* argv[]) { WeakForm *wf; if (TIME_DISCR == 2) { if (SCALED) { - wf = new ScaledWeakFormPNPCranic(TAU, epsilon, C_prev_time, phi_prev_time); - Hermes::Mixins::Loggable::Static::info("Scaled weak form, with time step %g and epsilon %g", *TAU, epsilon); + wf = new ScaledWeakFormPNPCranic(TAU, ::epsilon, C_prev_time, phi_prev_time); + Hermes::Mixins::Loggable::Static::info("Scaled weak form, with time step %g and epsilon %g", *TAU, ::epsilon); } else { wf = new WeakFormPNPCranic(TAU, C0, K, L, D, C_prev_time, phi_prev_time); } @@ -261,7 +261,7 @@ int main (int argc, char* argv[]) { try { solver_coarse->set_max_allowed_iterations(NEWTON_MAX_ITER); - solver_coarse->set_tolerance(NEWTON_TOL_COARSE); + solver_coarse->set_tolerance(NEWTON_TOL_COARSE, ResidualNormAbsolute); solver_coarse->solve(coeff_vec_coarse); } catch(Hermes::Exceptions::Exception e) @@ -353,7 +353,7 @@ int main (int argc, char* argv[]) { try { solver->set_max_allowed_iterations(NEWTON_MAX_ITER); - solver->set_tolerance(NEWTON_TOL_FINE); + solver->set_tolerance(NEWTON_TOL_FINE, ResidualNormAbsolute); solver->solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/richards/CMakeLists.txt b/2d-advanced/richards/CMakeLists.txt index 46e5c6d..ccdacff 100644 --- a/2d-advanced/richards/CMakeLists.txt +++ b/2d-advanced/richards/CMakeLists.txt @@ -2,6 +2,6 @@ add_subdirectory(basic-ie-picard) add_subdirectory(basic-ie-newton) add_subdirectory(basic-rk-newton) add_subdirectory(basic-rk-newton-adapt) -add_subdirectory(capillary-barrier-rk) +#add_subdirectory(capillary-barrier-rk) add_subdirectory(capillary-barrier-adapt) #add_subdirectory(seepage-adapt) diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index 3f30b64..347933d 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -123,7 +123,6 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/richards/capillary-barrier-adapt/definitions.h b/2d-advanced/richards/capillary-barrier-adapt/definitions.h index ef77b69..869d366 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/definitions.h +++ b/2d-advanced/richards/capillary-barrier-adapt/definitions.h @@ -28,7 +28,7 @@ class InitialSolutionRichards : public ExactSolutionScalar dy = 0.0; }; - virtual Ord ord(Ord x, Ord y) const { + virtual Ord ord(double x, double y) const { return Ord(0); } @@ -60,8 +60,8 @@ class ExactSolutionPoisson : public ExactSolutionScalar return new ExactSolutionPoisson(mesh); } - virtual Ord ord(Ord x, Ord y) const { - return x*x +y*y; + virtual Ord ord(double x, double y) const { + return Ord(2); } }; diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 305a831..36366fe 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -355,7 +355,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL); + newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); newton.solve(coeff_vec); newton_converged = true; } @@ -411,7 +411,7 @@ int main(int argc, char* argv[]) PicardSolver picard(&dp); picard.set_verbose_output(verbose); picard.set_max_allowed_iterations(PICARD_MAX_ITER); - picard.set_tolerance(PICARD_TOL); + picard.set_tolerance(PICARD_TOL, SolutionChangeRelative); while(true) { try diff --git a/2d-advanced/schroedinger/CMakeLists.txt b/2d-advanced/schroedinger/CMakeLists.txt index f735083..3a67c58 100644 --- a/2d-advanced/schroedinger/CMakeLists.txt +++ b/2d-advanced/schroedinger/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(gross-pitaevski) -add_subdirectory(gross-pitaevski-adapt) +#add_subdirectory(gross-pitaevski-adapt) diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp index 79499eb..2ca1f50 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.cpp @@ -12,7 +12,7 @@ std::complex CustomInitialCondition::value (double x, double y) const return exp(-20*(x*x + y*y)); } -Ord CustomInitialCondition::ord(Ord x, Ord y) const +Ord CustomInitialCondition::ord(double x, double y) const { return exp(-20*(x*x + y*y)); } diff --git a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h index 3c2abe9..6205f62 100644 --- a/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski-adapt/definitions.h @@ -18,7 +18,7 @@ class CustomInitialCondition : public ExactSolutionScalar virtual std::complex value (double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const; }; diff --git a/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp b/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp index dffaad1..922520d 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/definitions.cpp @@ -12,9 +12,9 @@ std::complex CustomInitialCondition::value (double x, double y) const return exp(-10*(x*x + y*y)); } -Ord CustomInitialCondition::ord(Ord x, Ord y) const +Ord CustomInitialCondition::ord(double x, double y) const { - return exp(-10*(x*x + y*y)); + return Ord(20); } MeshFunction* CustomInitialCondition::clone() const diff --git a/2d-advanced/schroedinger/gross-pitaevski/definitions.h b/2d-advanced/schroedinger/gross-pitaevski/definitions.h index c511fa2..1876387 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/definitions.h +++ b/2d-advanced/schroedinger/gross-pitaevski/definitions.h @@ -20,7 +20,7 @@ class CustomInitialCondition : public ExactSolutionScalar virtual std::complex value (double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const; }; diff --git a/2d-advanced/wave-equation/wave-1/definitions.cpp b/2d-advanced/wave-equation/wave-1/definitions.cpp index d1a5801..f661bba 100644 --- a/2d-advanced/wave-equation/wave-1/definitions.cpp +++ b/2d-advanced/wave-equation/wave-1/definitions.cpp @@ -11,7 +11,7 @@ void CustomInitialConditionWave::derivatives (double x, double y, double& dx, do dy = exp(-x*x - y*y) * (-2*y); } -Ord CustomInitialConditionWave::ord(Ord x, Ord y) const +Ord CustomInitialConditionWave::ord(double x, double y) const { return Ord(10); } diff --git a/2d-advanced/wave-equation/wave-1/definitions.h b/2d-advanced/wave-equation/wave-1/definitions.h index 7989e75..749cdbd 100644 --- a/2d-advanced/wave-equation/wave-1/definitions.h +++ b/2d-advanced/wave-equation/wave-1/definitions.h @@ -18,7 +18,7 @@ class CustomInitialConditionWave : public ExactSolutionScalar virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; virtual MeshFunction* clone() const; }; diff --git a/2d-benchmarks-general/layer-boundary/definitions.cpp b/2d-benchmarks-general/layer-boundary/definitions.cpp index e529c17..e23eef8 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.cpp +++ b/2d-benchmarks-general/layer-boundary/definitions.cpp @@ -36,7 +36,7 @@ void CustomExactSolution::derivatives (double x, double y, double& dx, double& d dy = cef->uhat(x) * cef->duhat_dx(y); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/2d-benchmarks-general/layer-boundary/definitions.h b/2d-benchmarks-general/layer-boundary/definitions.h index a230b30..4dc92c2 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.h +++ b/2d-benchmarks-general/layer-boundary/definitions.h @@ -31,7 +31,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; ~CustomExactSolution(); diff --git a/2d-benchmarks-general/layer-interior/definitions.cpp b/2d-benchmarks-general/layer-interior/definitions.cpp index 0e13793..fbc2920 100644 --- a/2d-benchmarks-general/layer-interior/definitions.cpp +++ b/2d-benchmarks-general/layer-interior/definitions.cpp @@ -13,7 +13,7 @@ void CustomExactSolution::derivatives (double x, double y, double& dx, double& d dy = slope * (y + 0.25) / u; } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/2d-benchmarks-general/layer-interior/definitions.h b/2d-benchmarks-general/layer-interior/definitions.h index 94b5b08..4b70501 100644 --- a/2d-benchmarks-general/layer-interior/definitions.h +++ b/2d-benchmarks-general/layer-interior/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double slope; }; diff --git a/2d-benchmarks-general/lshape/definitions.cpp b/2d-benchmarks-general/lshape/definitions.cpp index 7b04278..be5ff4f 100644 --- a/2d-benchmarks-general/lshape/definitions.cpp +++ b/2d-benchmarks-general/lshape/definitions.cpp @@ -16,7 +16,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = 2.0/3.0*y*Hermes::sin(t1)/(t2*t2) - 2.0/3.0*x*t2*Hermes::cos(t1)/t3; } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/2d-benchmarks-general/lshape/definitions.h b/2d-benchmarks-general/lshape/definitions.h index 3ea548b..2354936 100644 --- a/2d-benchmarks-general/lshape/definitions.h +++ b/2d-benchmarks-general/lshape/definitions.h @@ -17,5 +17,5 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; }; diff --git a/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp b/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp index edc3e56..8f14a3f 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp @@ -20,7 +20,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy M_PI*(2*y - y0 - y1) + (4*y - 2*(y0 + y1))*Hermes::atan(S*(t - Hermes::sqrt(x*x + y*y)))))/(2.*C); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/2d-benchmarks-general/moving-front-space-adapt/definitions.h b/2d-benchmarks-general/moving-front-space-adapt/definitions.h index f8be419..e771585 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/definitions.h +++ b/2d-benchmarks-general/moving-front-space-adapt/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double x0, x1, y0, y1, *t_ptr, s, c; }; diff --git a/2d-benchmarks-general/nonsym-check/definitions.cpp b/2d-benchmarks-general/nonsym-check/definitions.cpp index 855a8e2..51435e6 100644 --- a/2d-benchmarks-general/nonsym-check/definitions.cpp +++ b/2d-benchmarks-general/nonsym-check/definitions.cpp @@ -11,7 +11,7 @@ double CustomExactSolution::value(double x, double y) const return sin(x); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(20); } diff --git a/2d-benchmarks-general/nonsym-check/definitions.h b/2d-benchmarks-general/nonsym-check/definitions.h index 758cbf4..afe1a0d 100644 --- a/2d-benchmarks-general/nonsym-check/definitions.h +++ b/2d-benchmarks-general/nonsym-check/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const; }; diff --git a/2d-benchmarks-general/smooth-aniso-x/definitions.cpp b/2d-benchmarks-general/smooth-aniso-x/definitions.cpp index 0df044f..b515e6d 100644 --- a/2d-benchmarks-general/smooth-aniso-x/definitions.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/definitions.cpp @@ -11,7 +11,7 @@ double CustomExactSolution::value(double x, double y) const return Hermes::sin(x); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(7); } diff --git a/2d-benchmarks-general/smooth-aniso-x/definitions.h b/2d-benchmarks-general/smooth-aniso-x/definitions.h index 129ff11..212a0d7 100644 --- a/2d-benchmarks-general/smooth-aniso-x/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-x/definitions.h @@ -18,7 +18,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; }; /* Custom function f */ diff --git a/2d-benchmarks-general/smooth-aniso-y/definitions.cpp b/2d-benchmarks-general/smooth-aniso-y/definitions.cpp index f9bbf55..51c2fbe 100644 --- a/2d-benchmarks-general/smooth-aniso-y/definitions.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/definitions.cpp @@ -11,7 +11,7 @@ double CustomExactSolution::value(double x, double y) const return Hermes::sin(y); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(7); } diff --git a/2d-benchmarks-general/smooth-aniso-y/definitions.h b/2d-benchmarks-general/smooth-aniso-y/definitions.h index 101cb3a..e6f0c56 100644 --- a/2d-benchmarks-general/smooth-aniso-y/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-y/definitions.h @@ -18,7 +18,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; }; /* Custom function f */ diff --git a/2d-benchmarks-general/smooth-iso/definitions.cpp b/2d-benchmarks-general/smooth-iso/definitions.cpp index fd0eb36..43ed643 100644 --- a/2d-benchmarks-general/smooth-iso/definitions.cpp +++ b/2d-benchmarks-general/smooth-iso/definitions.cpp @@ -11,7 +11,7 @@ double CustomExactSolution::value(double x, double y) const return Hermes::sin(x)*Hermes::sin(y); } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(7); } diff --git a/2d-benchmarks-general/smooth-iso/definitions.h b/2d-benchmarks-general/smooth-iso/definitions.h index 32d57d3..dabd06f 100644 --- a/2d-benchmarks-general/smooth-iso/definitions.h +++ b/2d-benchmarks-general/smooth-iso/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; }; /* Custom function f */ diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.cpp b/2d-benchmarks-nist/01-analytic-solution/definitions.cpp index 25f2955..de6873b 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.cpp @@ -38,7 +38,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + (poly_deg*Hermes::pow(16.0, poly_deg)*B*D)/y)*A*C; } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(8); } diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.h b/2d-benchmarks-nist/01-analytic-solution/definitions.h index 511775f..d36c039 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.h +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.h @@ -32,7 +32,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord(double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, poly_deg); } double poly_deg; diff --git a/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp b/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp index d86f9ad..a74f014 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp @@ -18,7 +18,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + ((alpha * y * Hermes::sin(alpha* get_angle(y, x)) * b)/a)); } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(10); } diff --git a/2d-benchmarks-nist/02-reentrant-corner/definitions.h b/2d-benchmarks-nist/02-reentrant-corner/definitions.h index 56010b1..0fe1640 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/definitions.h +++ b/2d-benchmarks-nist/02-reentrant-corner/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double get_angle(double y, double x) const; diff --git a/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp b/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp index 71081ff..be1917f 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp @@ -216,7 +216,7 @@ void CustomExactSolutionU::derivatives (double x, double y, double& dx, double& D * r(x, y) * (lambda * (-1) * (lambda - 2) * Hermes::sin((lambda - 2) * get_angle(y, x)) * d_theta_dy(x, y)); } -Ord CustomExactSolutionU::ord (Ord x, Ord y) const +Ord CustomExactSolutionU::ord(double x, double y) const { return Ord(4.0); } @@ -426,7 +426,7 @@ void CustomExactSolutionV::derivatives (double x, double y, double& dx, double& D * r(x, y) * (lambda * (lambda - 2) * Hermes::cos((lambda - 2) * get_angle(y, x)) * d_theta_dy(x, y)); } -Ord CustomExactSolutionV::ord (Ord x, Ord y) const +Ord CustomExactSolutionV::ord(double x, double y) const { return Ord(4.0); } diff --git a/2d-benchmarks-nist/03-linear-elasticity/definitions.h b/2d-benchmarks-nist/03-linear-elasticity/definitions.h index 66bef8e..1f77400 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/definitions.h +++ b/2d-benchmarks-nist/03-linear-elasticity/definitions.h @@ -82,7 +82,7 @@ class CustomExactSolutionU : public ExactSolutionScalar virtual MeshFunction* clone() const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double E, nu, lambda, Q; @@ -164,7 +164,7 @@ class CustomExactSolutionV : public ExactSolutionScalar virtual MeshFunction* clone() const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double E, nu, lambda, Q; }; diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 0f9a386..d7228af 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); - newton.set_tolerance(1e-4); + newton.set_tolerance(1e-4, ResidualNormAbsolute); try { diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp index 7f745aa..9cddba3 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp @@ -25,7 +25,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = -exp(a) * (2 * alpha * (y - y_loc)); } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(8); } diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.h b/2d-benchmarks-nist/04-exponential-peak/definitions.h index ca557f2..42b18de 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.h +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.h @@ -34,7 +34,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc); } diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index d770ae5..ce310d2 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) resultStringIdentification = "Custom"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 741ea0d..3307e32 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) THRESHOLD_STRING = thresholds[atoi(argv[2])]; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); double ERR_STOP = 1.; diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp index a50d79f..d9bc3ec 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp @@ -30,7 +30,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy - (1 - exp(-(1 - x)/epsilon))*Hermes::cos(M_PI*(x + y))*exp(-(1 - y)/epsilon)/epsilon; } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(8); } diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index e1a122d..dd7ca27 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -32,7 +32,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, epsilon); } diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index 112ff9a..dd05a14 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) resultStringIdentification = "Custom"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) // Assemble the discrete problem. NewtonSolver newton; newton.set_weak_formulation(&wf); - newton.set_tolerance(1e-5); + newton.set_tolerance(1e-5, ResidualNormAbsolute); newton.set_UMFPACK_output(true, false); mesh->copy(basemesh); diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp index aa92eab..66891a5 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp @@ -21,7 +21,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = 0; } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord((int)(alpha + 1)); } diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h index 5f69a8e..18c8906 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h +++ b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.h @@ -32,7 +32,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha); } diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index fc77fa8..d8f0c86 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) resultStringIdentification = "Custom"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.cpp b/2d-benchmarks-nist/08-oscillatory/definitions.cpp index b5de5de..8234b8c 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.cpp +++ b/2d-benchmarks-nist/08-oscillatory/definitions.cpp @@ -39,7 +39,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = -Hermes::cos(h) * h * h * y / r; } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(10); } diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.h b/2d-benchmarks-nist/08-oscillatory/definitions.h index dc7ba52..2fbcc01 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.h +++ b/2d-benchmarks-nist/08-oscillatory/definitions.h @@ -32,7 +32,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha); } diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 93148f4..02c110c 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) resultStringIdentification = "noSelectionH-Lower"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); diff --git a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h index 250bca3..e8d2550 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly-dealii/definitions.h @@ -72,7 +72,7 @@ class CustomExactSolution : public ExactSolutionScalar }; virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const { return Ord(Ord::get_max_order()); } + virtual Ord ord (double x, double y) const { return Ord(Ord::get_max_order()); } MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc, r_zero); } diff --git a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h index 84aa567..787f222 100644 --- a/2d-benchmarks-nist/09-wave-front-kelly/definitions.h +++ b/2d-benchmarks-nist/09-wave-front-kelly/definitions.h @@ -71,7 +71,7 @@ class CustomExactSolution : public ExactSolutionScalar }; virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const { return Ord(Ord::get_max_order()); } + virtual Ord ord (double x, double y) const { return Ord(Ord::get_max_order()); } virtual MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc, r_zero); } double alpha, x_loc, y_loc, r_zero; diff --git a/2d-benchmarks-nist/09-wave-front/definitions.h b/2d-benchmarks-nist/09-wave-front/definitions.h index 5577d46..5dfcd0b 100644 --- a/2d-benchmarks-nist/09-wave-front/definitions.h +++ b/2d-benchmarks-nist/09-wave-front/definitions.h @@ -72,7 +72,7 @@ class CustomExactSolution : public ExactSolutionScalar }; virtual void derivatives (double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const { return Ord(Ord::get_max_order()); } + virtual Ord ord (double x, double y) const { return Ord(Ord::get_max_order()); } MeshFunction* clone() const { return new CustomExactSolution(mesh, alpha, x_loc, y_loc, r_zero); } diff --git a/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp b/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp index 65752cb..668ad55 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/definitions.cpp @@ -51,7 +51,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = -Hermes::sin(k * y) * k; } -Ord CustomExactSolution::ord(Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(16); } diff --git a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h index 24cee72..63bd74c 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/definitions.h +++ b/2d-benchmarks-nist/10-interior-line-singularity/definitions.h @@ -46,7 +46,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; ~CustomExactSolution(); diff --git a/2d-benchmarks-nist/11-kellogg/definitions.cpp b/2d-benchmarks-nist/11-kellogg/definitions.cpp index 2929a8c..6964cf8 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.cpp +++ b/2d-benchmarks-nist/11-kellogg/definitions.cpp @@ -54,7 +54,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy - (tau * Hermes::pow(r, tau) * Hermes::cos((M_PI/2. - rho)*tau) * Hermes::sin(tau*((-3.*M_PI)/2. - sigma + theta))*x/(r*r)); } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(6); } diff --git a/2d-benchmarks-nist/11-kellogg/definitions.h b/2d-benchmarks-nist/11-kellogg/definitions.h index fe72848..4d29c10 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.h +++ b/2d-benchmarks-nist/11-kellogg/definitions.h @@ -17,7 +17,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, sigma, tau, rho); } diff --git a/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp b/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp index 01e30e1..6be0dc1 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp @@ -63,7 +63,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + (-1) * (1.0 / epsilon) * exp(-(1 + y) / epsilon); } -Ord CustomExactSolution::ord (Ord x, Ord y) const +Ord CustomExactSolution::ord(double x, double y) const { return Ord(10); } diff --git a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h index c9d1036..88153a9 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/definitions.h +++ b/2d-benchmarks-nist/12-multiple-difficulties/definitions.h @@ -44,7 +44,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord (Ord x, Ord y) const; + virtual Ord ord (double x, double y) const; double get_angle(double y, double x) const; diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index 96a2425..ab42e1d 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) resultStringIdentification = "Custom"; } - sprintf(Hermes::Mixins::Loggable::logFileName, "Logfile-%s.log", resultStringIdentification); + sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); if(argc > 2 && atoi(argv[1]) == 0) P_INIT = 2; @@ -72,10 +72,10 @@ int main(int argc, char* argv[]) basemesh->copy(mesh); // Set exact solution. - MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p)); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, ::epsilon, x_p, y_p)); // Define right-hand side. - CustomRightHandSide f(alpha_w, alpha_p, x_w, y_w, r_0, omega_c, epsilon, x_p, y_p); + CustomRightHandSide f(alpha_w, alpha_p, x_w, y_w, r_0, omega_c, ::epsilon, x_p, y_p); // Initialize the weak formulation. Hermes1DFunction lambda(1.0); From 5139d3eefd99f16706b2889804ce162b8b2d685e Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 24 Sep 2013 09:53:34 +0200 Subject: [PATCH 46/64] Remove wrong include. --- 1d/moving-front/definitions.h | 1 - 2d-benchmarks-general/moving-front-space-adapt/definitions.h | 1 - 2 files changed, 2 deletions(-) diff --git a/1d/moving-front/definitions.h b/1d/moving-front/definitions.h index 51e2ea4..fefab82 100644 --- a/1d/moving-front/definitions.h +++ b/1d/moving-front/definitions.h @@ -1,5 +1,4 @@ #include "hermes2d.h" -#include "runge_kutta.h" using namespace Hermes; using namespace Hermes::Hermes2D; diff --git a/2d-benchmarks-general/moving-front-space-adapt/definitions.h b/2d-benchmarks-general/moving-front-space-adapt/definitions.h index e771585..8a2c696 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/definitions.h +++ b/2d-benchmarks-general/moving-front-space-adapt/definitions.h @@ -1,5 +1,4 @@ #include "hermes2d.h" -#include "runge_kutta.h" using namespace Hermes; using namespace Hermes::Hermes2D; From 2461b17e5b51e9efe83516c1a4dbf4be9c267f6b Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 3 Jul 2013 08:54:29 +0200 Subject: [PATCH 47/64] Unify CMakeLists.txt with other repositories. --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fabc0c2..77b8509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,3 @@ -set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_HOME_DIRECTORY}/cmake/cxx_flag_overrides.cmake) project(hermes_examples) cmake_minimum_required(VERSION 2.6) @@ -63,7 +62,7 @@ project(hermes_examples) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") endif(MSVC) - include_directories("${PTHREAD_ROOT}/include") + include_directories("${PTHREAD_ROOT}/include") find_package(PTHREAD REQUIRED) find_package(TCMALLOC REQUIRED) include_directories(${TCMALLOC_INCLUDE_DIR}) From f094ddc636e5033609df96aedc14243278af9677 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Fri, 11 Oct 2013 09:59:24 +0200 Subject: [PATCH 48/64] Work on CMake. --- .gitignore | 28 ++- CMake.vars.example | 33 +++- CMakeLists.txt | 263 ++++++++++++++++++++--------- cmake/BuildAndInstallScripts.cmake | 69 ++++++++ cmake/FindBSON.cmake | 16 ++ cmake/FindCLAPACK.cmake | 35 ++++ cmake/FindEXECINFO.cmake | 17 ++ cmake/FindEXODUSII.cmake | 57 +++++++ cmake/FindGLEW.cmake | 12 ++ cmake/FindGLUT.cmake | 12 ++ cmake/FindHDF5.cmake | 14 ++ cmake/FindMATIO.cmake | 16 ++ cmake/FindMUMPS.cmake | 90 ++++++++++ cmake/FindPARALUTION.cmake | 16 ++ cmake/FindPETSC.cmake | 69 ++++++++ cmake/FindPTHREAD.cmake | 6 +- cmake/FindSCALAPACK.cmake | 15 ++ cmake/FindSUPERLU.cmake | 55 ++++++ cmake/FindTCMALLOC.cmake | 15 +- cmake/FindTRILINOS.cmake | 130 +++++--------- cmake/FindUMFPACK.cmake | 9 +- cmake/FindWINBLAS.cmake | 12 ++ cmake/FindXERCES.cmake | 15 ++ cmake/FindXSD.cmake | 13 ++ 24 files changed, 827 insertions(+), 190 deletions(-) create mode 100644 cmake/BuildAndInstallScripts.cmake create mode 100644 cmake/FindBSON.cmake create mode 100644 cmake/FindCLAPACK.cmake create mode 100644 cmake/FindEXECINFO.cmake create mode 100644 cmake/FindEXODUSII.cmake create mode 100644 cmake/FindGLEW.cmake create mode 100644 cmake/FindGLUT.cmake create mode 100644 cmake/FindHDF5.cmake create mode 100644 cmake/FindMATIO.cmake create mode 100644 cmake/FindMUMPS.cmake create mode 100644 cmake/FindPARALUTION.cmake create mode 100644 cmake/FindPETSC.cmake create mode 100644 cmake/FindSCALAPACK.cmake create mode 100644 cmake/FindSUPERLU.cmake create mode 100644 cmake/FindWINBLAS.cmake create mode 100644 cmake/FindXERCES.cmake create mode 100644 cmake/FindXSD.cmake diff --git a/.gitignore b/.gitignore index 8912af5..191db7b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,13 @@ # in that subdirectory instead. # +*.out.* +*.tmp +*.cbp +*.m +.gitignore CMake.vars +CTestCheckpoint.txt *.h2d .* *.o @@ -18,7 +24,6 @@ tutorial.* *.png *.bmp *.user -*make* *.bak # top-level files @@ -65,9 +70,6 @@ Debug/ # kdevelop project files *.kdev* -# Python stuff -!python/_hermes_common.so - # Documentation generated *.html *.eps @@ -82,5 +84,19 @@ Debug/ *.sty *.dvi *.vtk -*.m -doc/* \ No newline at end of file + + +# Misc +*.exe +*.dat +*.lastbuildstate +*.cfg +*.bak +*.options +*.pdr.* +*.jit +*My Inspector* +*.exp +*.ipgset +*.psess +*.vsp \ No newline at end of file diff --git a/CMake.vars.example b/CMake.vars.example index 1ea9da7..fa92840 100644 --- a/CMake.vars.example +++ b/CMake.vars.example @@ -1,12 +1,29 @@ -set(DEP_ROOT "d:/hpfem/hermes/dependencies") # Root of a directory with dependecies. This line has to be modified. Don't forget to replace all backslashes '\' with slashes '/'. +# This is a sample CMake.vars file for Hermes. -#PTHREAD - set(PTHREAD_ROOT ${DEP_ROOT}) +# Some search paths. +if (WIN32) + set(GLUT_ROOT "d:/hpfem/hermes/dependencies/glut") + set(GLEW_ROOT "d:/hpfem/hermes/dependencies/glew") + set(PTHREAD_ROOT "d:/hpfem/hermes/dependencies/pthread") + set(UMFPACK_ROOT "d:/hpfem/hermes/dependencies/umfpack") + set(CLAPACK_ROOT "d:/hpfem/hermes/dependencies/clapack") + # Target (installation) path. + set(TARGET_ROOT "d:/hpfem/hermes/dependencies") +else() + #set(GLUT_ROOT "/usr/lib/") + #set(GLEW_ROOT "/usr/lib/") + #set(PTHREAD_ROOT "/usr/lib/") + #set(UMFPACK_ROOT "/usr/lib/") + #set(CLAPACK_ROOT "/usr/lib/") +endif() -#HERMES - set(HERMES_DIRECTORY "${DEP_ROOT}/lib") - set(HERMES_INCLUDE_PATH "${DEP_ROOT}/include") +# Python. +set(WITH_PYTHON NO) # Trilinos - SET(WITH_TRILINOS YES) - set(TRILINOS_ROOT ${DEP_ROOT}) \ No newline at end of file +if (WIN32) + set(TRILINOS_ROOT "d:/hpfem/hermes/dependencies/trilinos") +else() + set(TRILINOS_ROOT "~/solvers/trilinos") +endif() +SET(WITH_TRILINOS YES) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 77b8509..250ba22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,32 +1,6 @@ -project(hermes_examples) - cmake_minimum_required(VERSION 2.6) +project(hermes-examples) + cmake_minimum_required(VERSION 2.8) - set(HERMES_EXAMPLES_DEBUG YES) - - set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake) - include(CommonTargetProperties) - - # Where to look for the static libraries. - set(HERMES_DIRECTORY /usr/local/lib) - set(HERMES_INCLUDE_PATH /usr/local/include) - set(DEP_INCLUDE_PATHS /usr/local/include) - - # Trilinos - # Enable support for Trilinos solvers. - set(WITH_TRILINOS NO) - - # Experimental - set(WITH_ZOLTAN NO) - # If MPI is enabled, the MPI library installed on the system should be found by - # CMake automatically. If the found library doesn't match the one used to compile the - # particular MPI-dependent package, the other two options should be used to specify it. - # - set(WITH_MPI NO) - # set(MPI_LIBRARIES -lmpi) - # set(MPI_INCLUDE_PATH /usr/include/openmpi - - # By default all examples are turned on. - # This can be changed in your CMake.vars file. SET(WITH_1d YES) SET(WITH_2d-advanced YES) SET(WITH_acoustics YES) @@ -44,52 +18,156 @@ project(hermes_examples) SET(WITH_wave-equation YES) SET(WITH_2d-benchmarks-general YES) SET(WITH_2d-benchmarks-nist YES) - - # Allow to override the default values in CMake.vars: - include(CMake.vars OPTIONAL) - - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Disable all warnings and turn on only important ones: - set(CMAKE_CXX_FLAGS "-w ${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS "-Wuninitialized -Wvla -Wsign-compare ${CMAKE_CXX_FLAGS}") - - set(RELEASE_FLAGS "-DNDEBUG -O3") - set(DEBUG_FLAGS "-g") - endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - - # Enabling multiprocessor build on MSVC - if(MSVC) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") - endif(MSVC) - - include_directories("${PTHREAD_ROOT}/include") - find_package(PTHREAD REQUIRED) - find_package(TCMALLOC REQUIRED) - include_directories(${TCMALLOC_INCLUDE_DIR}) - - find_package(UMFPACK REQUIRED) - include_directories(${UMFPACK_INCLUDE_DIRS}) - - if(WITH_TRILINOS) - find_package(TRILINOS REQUIRED) - include_directories(${TRILINOS_INCLUDE_DIR}) - endif(WITH_TRILINOS) - - if(WITH_MPI) - if(NOT MPI_INCLUDE_PATH) - find_package(MPI REQUIRED) - endif(NOT MPI_INCLUDE_PATH) - include_directories(${MPI_INCLUDE_PATH}) - endif(WITH_MPI) - - set(HERMES2D_INCLUDE_PATH ${HERMES_INCLUDE_PATH}/hermes2d) - set(HERMES_COMMON_INCLUDE_PATH ${HERMES_INCLUDE_PATH}/hermes_common) - - find_package(HERMES_COMMON REQUIRED) - include_directories(${HERMES_COMMON_INCLUDE_PATH}) - include_directories(${HERMES2D_INCLUDE_PATH}) - include_directories(${DEP_INCLUDE_PATHS}) + set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake) + include(CommonTargetProperties) + + # For Win64 + if(${CMAKE_CL_64}) + set(WIN64 YES) + else(${CMAKE_CL_64}) + set(WIN64 NO) + endif(${CMAKE_CL_64}) + + # This has to be the same as in the library's CMake. + # Default "yes" + set(H2D_WITH_GLUT YES) + set(WITH_TC_MALLOC YES) + set(WITH_PARALUTION YES) + set(WITH_UMFPACK YES) + set(WITH_OPENMP YES) + # Default "no" + set(WITH_EXODUSII NO) + set(WITH_MUMPS NO) + set(WITH_MATIO NO) + set(WITH_BSON NO) + set(WITH_SUPERLU NO) + + # Where to look for the static libraries. + set(HERMES_DIRECTORY /usr/local/lib) + set(HERMES_INCLUDE_PATH /usr/local/include) + set(DEP_INCLUDE_PATHS /usr/local/include) + + # Allow to override the default values in CMake.vars: + include(CMake.vars OPTIONAL) + + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Disable all warnings and turn on only important ones: + set(CMAKE_CXX_FLAGS "-w ${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "-Wuninitialized -Wvla -Wsign-compare ${CMAKE_CXX_FLAGS}") + + set(RELEASE_FLAGS "-DNDEBUG -O3") + set(DEBUG_FLAGS "-g") + endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + + # Enabling multiprocessor build on MSVC + if(MSVC) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + if(WITH_OPENMP) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") + endif(WITH_OPENMP) + endif(MSVC) + + # This overrides CXX flags for MSVC + if(MSVC) + if(WIN64) + set(MSVC_DEFINES "/DWIN64 /D_WINDOWS /Dfinite=_finite /wd4275 /wd4251") + else(WIN64) + set(MSVC_DEFINES "/DWIN32 /D_WINDOWS /Dfinite=_finite /wd4275 /wd4251") + endif(WIN64) + set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Ob2 /MDd /Zi ${MSVC_DEFINES}") + set(HERMES_DEBUG_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O2 /Ob2 /MD ${MSVC_DEFINES}") + set(CMAKE_CXX_FLAGS_RELEASE "/DNDEBUG /O2 /Ob2 /MD ${MSVC_DEFINES}") + set(HERMES_RELEASE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/DNDEBUG /O2 /Ob2 /MD /Zi ${MSVC_DEFINES}") + + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") + set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") + endif(MSVC) + + include_directories("${PTHREAD_ROOT}/include") + + if(${WITH_UMFPACK}) + find_package(UMFPACK REQUIRED) + include_directories(${UMFPACK_INCLUDE_DIRS}) + endif() + + find_package(PTHREAD REQUIRED) + + if(${WITH_TC_MALLOC}) + find_package(TCMALLOC REQUIRED) + include_directories(${TCMALLOC_INCLUDE_DIR}) + endif() + + if(${WITH_PARALUTION}) + find_package(PARALUTION REQUIRED) + include_directories(${PARALUTION_INCLUDE_DIR}) + endif() + + if(${WITH_MATIO}) + find_package(MATIO REQUIRED) + include_directories(${MATIO_INCLUDE_DIR}) + endif() + + if(MSVC) + if(WITH_PETSC OR WITH_TRILINOS OR WITH_SUPERLU) + find_package(CLAPACK REQUIRED) + include_directories(${CLAPACK_INCLUDE_DIRS}) + endif(WITH_PETSC OR WITH_TRILINOS OR WITH_SUPERLU) + if(WITH_MUMPS) + find_package(WINBLAS REQUIRED) + endif(WITH_MUMPS) + else(MSVC) + if(WITH_UMFPACK OR WITH_PETSC OR WITH_MUMPS OR WITH_TRILINOS OR WITH_SUPERLU) + if (NOT LAPACK_FOUND) + enable_language(Fortran) + find_package(LAPACK REQUIRED) + set(LAPACK_LIBRARIES ${LAPACK_LIBRARIES} + CACHE STRING "Path to LAPACK/BLAS libraries.") + set(LAPACK_FOUND YES + CACHE STRING "Have LAPACK/BLAS libraries been found?") + endif (NOT LAPACK_FOUND) + add_definitions(-DWITH_BLAS) + endif(WITH_UMFPACK OR WITH_PETSC OR WITH_MUMPS OR WITH_TRILINOS OR WITH_SUPERLU) + endif(MSVC) + + if(WITH_MUMPS) + find_package(MUMPS REQUIRED) + if(WITH_MPI) + find_package(SCALAPACK REQUIRED) # parallel version of MUMPS needs ScaLapack+BLACS + endif(WITH_MPI) + include_directories(${MUMPS_INCLUDE_DIR}) + set(MUMPS_LIBRARIES ${MUMPS_CPLX_LIBRARIES}) + LIST(APPEND MUMPS_LIBRARIES ${MUMPS_REAL_LIBRARIES}) + endif(WITH_MUMPS) + + if(WITH_TRILINOS) + find_package(TRILINOS REQUIRED) + include_directories(${TRILINOS_INCLUDE_DIR}) + endif(WITH_TRILINOS) + + if(${WITH_BSON}) + find_package(BSON REQUIRED) + include_directories(${BSON_INCLUDE_DIR}) + endif() + + if(WITH_SUPERLU) + find_package(SUPERLU REQUIRED) + include_directories(${SUPERLU_INCLUDE_DIR}) + if(SUPERLU_MT) + add_definitions(-DSLU_MT) + endif(SUPERLU_MT) + endif(WITH_SUPERLU) + set(HERMES2D_INCLUDE_PATH ${HERMES_INCLUDE_PATH}/hermes2d) + set(HERMES_COMMON_INCLUDE_PATH ${HERMES_INCLUDE_PATH}/hermes_common) + + find_package(HERMES_COMMON REQUIRED) + + include_directories(${HERMES_COMMON_INCLUDE_PATH}) + include_directories(${HERMES2D_INCLUDE_PATH}) + include_directories(${DEP_INCLUDE_PATHS}) IF(WITH_1d) add_subdirectory(1d) @@ -103,9 +181,36 @@ project(hermes_examples) IF(WITH_2d-benchmarks-nist) add_subdirectory(2d-benchmarks-nist) ENDIF(WITH_2d-benchmarks-nist) - - - - - - \ No newline at end of file + + #------------------------------------------------------------------------------ + # Report. + #~~~~~~~~ + message("\nHermes-examples Configuration results") + message("---------------------") + if(WIN32) + message("Build for Win64: ${WIN64}") + endif(WIN32) + + message("\n-------Features-------") + message("Build with OpenMP: ${WITH_OPENMP}") + message("Build with TCMalloc: ${WITH_TC_MALLOC}") + message("Build with BSON: ${WITH_BSON}") + message("Build with MATIO: ${WITH_MATIO}") + if(${WITH_MATIO}) + message(" MATIO with HDF5: ${MATIO_WITH_HDF5}") + endif() + if(${WITH_MPI}) + message("Build with MPI: ${WITH_MPI}") + endif() + message("Build with EXODUSII: ${WITH_EXODUSII}") + + message("\n-------Solvers-------") + message("Build with UMFPACK: ${WITH_UMFPACK}") + message("Build with PARALUTION: ${WITH_PARALUTION}") + message("Build with PETSC: !TO_DO!") + message("Build with MUMPS: ${WITH_MUMPS}") + message("Build with SUPERLU${MT}: ${WITH_SUPERLU}") + message("Build with TRILINOS: !TO_DO!") + + message("---------------------") + message("\n") diff --git a/cmake/BuildAndInstallScripts.cmake b/cmake/BuildAndInstallScripts.cmake new file mode 100644 index 0000000..9d36564 --- /dev/null +++ b/cmake/BuildAndInstallScripts.cmake @@ -0,0 +1,69 @@ +# Macro for generating classes for XML mesh parsing according to XSD +macro(GENERATE_XSD_FILES PROJECT_NAME HEADER_XML_FILE_OUTPUT SOURCE_XML_FILE_OUTPUT XSD_FILE TARGET_DIR) + add_custom_target(${PROJECT_NAME} ALL DEPENDS ${HEADER_XML_FILE_OUTPUT} "src/${SOURCE_XML_FILE_OUTPUT}") + +IF(WIN32) + MAKE_PATH(PATH_FOR_MOVE "${PROJECT_SOURCE_DIR}/include/${SOURCE_XML_FILE_OUTPUT}") + ADD_CUSTOM_COMMAND( + COMMAND ${XSD_BIN} ARGS cxx-tree --generate-doxygen --generate-ostream --hxx-suffix .h --cxx-suffix .cpp --root-element-first --generate-polymorphic --generate-serialization --output-dir include/${TARGET_DIR} ${XSD_FILE} + COMMAND move ARGS "/Y" "${PATH_FOR_MOVE}" "${PROJECT_SOURCE_DIR}\\src\\${TARGET_DIR}" + OUTPUT ${HEADER_XML_FILE_OUTPUT} "src/${SOURCE_XML_FILE_OUTPUT}") +ELSE() + ADD_CUSTOM_COMMAND( + COMMAND ${XSD_BIN} ARGS cxx-tree --generate-doxygen --generate-ostream --hxx-suffix .h --cxx-suffix .cpp --root-element-first --generate-polymorphic --generate-serialization --output-dir include/${TARGET_DIR} ${XSD_FILE} + COMMAND mv ARGS "-f" "${PROJECT_SOURCE_DIR}/include/${SOURCE_XML_FILE_OUTPUT}" "${PROJECT_SOURCE_DIR}/src/${TARGET_DIR}/" + OUTPUT ${HEADER_XML_FILE_OUTPUT} "src/${SOURCE_XML_FILE_OUTPUT}") +ENDIF() +ADD_CUSTOM_COMMAND( + TARGET ${PROJECT_NAME} + DEPENDS ${HEADER_XML_FILE_OUTPUT} "src/${SOURCE_XML_FILE_OUTPUT}") + +endmacro(GENERATE_XSD_FILES) + +# MSVC (Win) helper macros + +# Makes Win32 path from Unix-style patch which is used by CMAKE. Used when a path is provided to an OS utility. +macro(MAKE_PATH PATH_OUT PATH_IN) + if(WIN32) + string(REPLACE "/" "\\" ${PATH_OUT} ${PATH_IN}) + else(WIN32) + set(${PATH_OUT} ${PATH_IN}) + endif(WIN32) +endmacro(MAKE_PATH) + +# This ensures that a .dll library is built for both debug and release configurations under MSVC. +macro(ADD_MSVC_BUILD_FLAGS LIB LIB_DEBUG LIB_RELEASE) + set_target_properties(${LIB} PROPERTIES COMPILE_FLAGS "-DEXPORT_HERMES_DLL") + IF(DEFINED AGROS_BUILD) + IF(${AGROS_DEBUG}) + set_target_properties(${LIB} PROPERTIES DEBUG_OUTPUT_NAME ${LIB_DEBUG}) + set_target_properties(${LIB} PROPERTIES RELEASE_OUTPUT_NAME ${LIB_RELEASE}) + ENDIF() + ELSE(DEFINED AGROS_BUILD) + set_target_properties(${LIB} PROPERTIES DEBUG_OUTPUT_NAME ${LIB_DEBUG}) + set_target_properties(${LIB} PROPERTIES RELEASE_OUTPUT_NAME ${LIB_RELEASE}) + ENDIF() +endmacro(ADD_MSVC_BUILD_FLAGS) + +# Installs a library to directories relative to CMAKE_INSTALL_PREFIX. +macro(INSTALL_LIB LIB) + install(TARGETS ${LIB} + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib + ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + IF(NOT DEFINED AGROS_BUILD) + IF(MSVC) + MAKE_PATH(TARGET_DIR "${CMAKE_INSTALL_PREFIX}/bin") + get_target_property(SOURCE_DEBUG_FILE ${LIB} LOCATION_Debug) + MAKE_PATH(SOURCE_DEBUG_FILE ${SOURCE_DEBUG_FILE}) + get_target_property(SOURCE_RELEASE_FILE ${LIB} LOCATION_Release) + MAKE_PATH(SOURCE_RELEASE_FILE ${SOURCE_RELEASE_FILE}) + add_custom_command(TARGET ${LIB} + POST_BUILD + COMMAND if not exist ${TARGET_DIR} mkdir ${TARGET_DIR} + COMMAND if exist ${SOURCE_DEBUG_FILE} copy /Y ${SOURCE_DEBUG_FILE} ${TARGET_DIR} + COMMAND if exist ${SOURCE_RELEASE_FILE} copy /Y ${SOURCE_RELEASE_FILE} ${TARGET_DIR}) + unset(TARGET_DIR) + ENDIF() + ENDIF() +endmacro(INSTALL_LIB) diff --git a/cmake/FindBSON.cmake b/cmake/FindBSON.cmake new file mode 100644 index 0000000..5f24c4e --- /dev/null +++ b/cmake/FindBSON.cmake @@ -0,0 +1,16 @@ +# +# BSON +# FROM https://github.com/mongodb/mongo-c-driver +# + +FIND_PATH(BSON_INCLUDE_DIR bson.h ${BSON_ROOT}/src ${BSON_ROOT}/include /usr/local/include /usr/include) + +if(WIN64) + FIND_LIBRARY(BSON_LIBRARY NAMES agros2d_3rd_party_bson bson PATHS ${BSON_ROOT} ${BSON_ROOT}/lib/x64 ${BSON_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(BSON_LIBRARY NAMES agros2d_3rd_party_bson bson PATHS ${BSON_ROOT} ${BSON_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(BSON DEFAULT_MSG BSON_LIBRARY BSON_INCLUDE_DIR) diff --git a/cmake/FindCLAPACK.cmake b/cmake/FindCLAPACK.cmake new file mode 100644 index 0000000..ed2100b --- /dev/null +++ b/cmake/FindCLAPACK.cmake @@ -0,0 +1,35 @@ +# +# CLAPACK & CBLAS +# (for Windows) +# + +SET(CLAPACK_INCLUDE_SEARCH_PATH ${CLAPACK_ROOT}/include) +if(WIN64) + SET(CLAPACK_LIB_SEARCH_PATH ${CLAPACK_ROOT}/lib/x64 ${CLAPACK_ROOT}/lib) +else(WIN64) + SET(CLAPACK_LIB_SEARCH_PATH ${CLAPACK_ROOT}/lib) +endif(WIN64) + +FIND_PATH(BLAS_INCLUDE_PATH blaswrap.h ${CLAPACK_INCLUDE_SEARCH_PATH}) +FIND_PATH(CLAPACK_INCLUDE_PATH clapack.h ${CLAPACK_INCLUDE_SEARCH_PATH}) +FIND_PATH(F2C_INCLUDE_PATH f2c.h ${CLAPACK_INCLUDE_SEARCH_PATH}) + +FIND_LIBRARY(BLAS_LIBRARY blas ${CLAPACK_LIB_SEARCH_PATH}) +FIND_LIBRARY(CLAPACK_LIBRARY lapack ${CLAPACK_LIB_SEARCH_PATH}) +FIND_LIBRARY(F2C_LIBRARY libf2c ${CLAPACK_LIB_SEARCH_PATH}) + +IF(BLAS_INCLUDE_PATH AND CLAPACK_INCLUDE_PATH AND F2C_INCLUDE_PATH AND BLAS_LIBRARY AND CLAPACK_LIBRARY AND F2C_LIBRARY) + SET(CLAPACK_INCLUDE_DIR ${BLAS_INCLUDE_PATH} ${CLAPACK_INCLUDE_PATH} ${F2C_INCLUDE_PATH}) + SET(CLAPACK_LIBRARY ${BLAS_LIBRARY} ${CLAPACK_LIBRARY} ${F2C_LIBRARY}) + SET(HAVE_CLAPACK YES) + find_package_handle_standard_args(LAPACK DEFAULT_MSG CLAPACK_LIBRARY) + find_package_handle_standard_args(BLAS DEFAULT_MSG BLAS_LIBRARY) + find_package_handle_standard_args(F2C DEFAULT_MSG F2C_LIBRARY) +ENDIF(BLAS_INCLUDE_PATH AND CLAPACK_INCLUDE_PATH AND F2C_INCLUDE_PATH AND BLAS_LIBRARY AND CLAPACK_LIBRARY AND F2C_LIBRARY) + +IF(LAPACK_FOUND AND BLAS_FOUND AND F2C_FOUND) + SET(CLAPACK_FOUND TRUE) + MESSAGE(STATUS "CLAPACK found.") +ELSE(LAPACK_FOUND AND BLAS_FOUND AND F2C_FOUND) + MESSAGE(FATAL_ERROR "Could not find CLAPACK.") +ENDIF(LAPACK_FOUND AND BLAS_FOUND AND F2C_FOUND) \ No newline at end of file diff --git a/cmake/FindEXECINFO.cmake b/cmake/FindEXECINFO.cmake new file mode 100644 index 0000000..8498ea0 --- /dev/null +++ b/cmake/FindEXECINFO.cmake @@ -0,0 +1,17 @@ +MESSAGE(STATUS "Looking for execinfo") + FIND_PATH(EXECINFO_INCLUDE_PATH + NAMES + execinfo.h + PATHS + /usr/include + /usr/local/include + /sw/include + /opt/local/include + NO_DEFAULT_PATH) + + IF(EXECINFO_INCLUDE_PATH) + SET(EXECINFO_FOUND 1 CACHE STRING "Set to 1 if execinfo is found, 0 otherwise") + MESSAGE(STATUS "Looking for execinfo headers - found") + ENDIF(EXECINFO_INCLUDE_PATH) + + MARK_AS_ADVANCED(EXECINFO_FOUND) \ No newline at end of file diff --git a/cmake/FindEXODUSII.cmake b/cmake/FindEXODUSII.cmake new file mode 100644 index 0000000..0cd1403 --- /dev/null +++ b/cmake/FindEXODUSII.cmake @@ -0,0 +1,57 @@ +# +# Exodus2 +# +# Looks for library to process exodusII files +# Needs netcdf library installed (this is checked by this module) +# + +SET(NETCDF_INCLUDE_SEARCH_PATH + ${NETCDF_ROOT}/include + /usr/include + /usr/local/include/ +) + +SET(EXODUSII_INCLUDE_SEARCH_PATH + ${EXODUSII_ROOT}/include + /usr/include + /usr/local/include/ +) + +IF(WIN64) + SET(NETCDF_LIB_SEARCH_PATH ${NETCDF_ROOT}/lib/x64 ${NETCDF_ROOT}/lib /usr/lib64 /usr/lib /usr/local/lib/) + SET(EXODUSII_LIB_SEARCH_PATH ${EXODUSII_ROOT}/lib/x64 ${EXODUSII_ROOT}/lib /usr/lib64 /usr/lib /usr/local/lib/) +ELSE(WIN64) + SET(NETCDF_LIB_SEARCH_PATH ${NETCDF_ROOT}/lib /usr/lib64 /usr/lib /usr/local/lib/) + SET(EXODUSII_LIB_SEARCH_PATH ${EXODUSII_ROOT}/lib /usr/lib64 /usr/lib /usr/local/lib/) +ENDIF(WIN64) + +FIND_PATH(EXODUSII_INCLUDE_PATH exodusII.h ${EXODUSII_INCLUDE_SEARCH_PATH}) +FIND_PATH(NETCDF_INCLUDE_PATH netcdf.h ${NETCDF_INCLUDE_SEARCH_PATH}) + +FIND_LIBRARY(NETCDF_LIBRARY netcdf ${NETCDF_LIB_SEARCH_PATH}) +FIND_LIBRARY(EXODUSII_LIBRARY exoIIv2c ${EXODUSII_LIB_SEARCH_PATH}) + +IF(EXODUSII_INCLUDE_PATH) + SET(EXODUSII_INCLUDE_DIR ${EXODUSII_INCLUDE_DIR} ${EXODUSII_INCLUDE_PATH}) +ENDIF(EXODUSII_INCLUDE_PATH) + +IF(EXODUSII_LIBRARY) + SET(EXODUSII_LIBRARIES ${EXODUSII_LIBRARIES} ${EXODUSII_LIBRARY}) +ENDIF(EXODUSII_LIBRARY) + +IF(NETCDF_INCLUDE_PATH) + SET(EXODUSII_INCLUDE_DIR ${EXODUSII_INCLUDE_DIR} ${NETCDF_INCLUDE_PATH}) + SET(NETCDF_INCLUDE_DIR ${NETCDF_INCLUDE_PATH}) +ENDIF(NETCDF_INCLUDE_PATH) + +IF(NETCDF_LIBRARY) + SET(EXODUSII_LIBRARIES ${EXODUSII_LIBRARIES} ${NETCDF_LIBRARY}) +ENDIF(NETCDF_LIBRARY) + +IF(EXODUSII_INCLUDE_PATH AND EXODUSII_LIBRARY AND NETCDF_INCLUDE_PATH AND NETCDF_LIBRARY) + SET(EXODUSII_FOUND TRUE) +ENDIF(EXODUSII_INCLUDE_PATH AND EXODUSII_LIBRARY AND NETCDF_INCLUDE_PATH AND NETCDF_LIBRARY) + +INCLUDE(FindPackageHandleStandardArgs) +find_package_handle_standard_args(EXODUSII DEFAULT_MSG EXODUSII_LIBRARY EXODUSII_INCLUDE_DIR NETCDF_LIBRARY NETCDF_INCLUDE_DIR) + diff --git a/cmake/FindGLEW.cmake b/cmake/FindGLEW.cmake new file mode 100644 index 0000000..025764d --- /dev/null +++ b/cmake/FindGLEW.cmake @@ -0,0 +1,12 @@ +# +# GLEW +# + +if(WIN64) + FIND_LIBRARY(GLEW_LIBRARY NAMES glew32 GLEW PATHS ${GLEW_ROOT}/lib/x64 ${GLEW_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(GLEW_LIBRARY NAMES glew32 GLEW PATHS ${GLEW_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLEW DEFAULT_MSG GLEW_LIBRARY) diff --git a/cmake/FindGLUT.cmake b/cmake/FindGLUT.cmake new file mode 100644 index 0000000..621af71 --- /dev/null +++ b/cmake/FindGLUT.cmake @@ -0,0 +1,12 @@ +# +# GLUT +# + +if(WIN64) + FIND_LIBRARY(GLUT_LIBRARY NAMES freeglut glut PATHS ${GLUT_ROOT}/lib/x64 ${GLUT_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(GLUT_LIBRARY NAMES freeglut glut PATHS ${GLUT_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT DEFAULT_MSG GLUT_LIBRARY) \ No newline at end of file diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake new file mode 100644 index 0000000..269a5ba --- /dev/null +++ b/cmake/FindHDF5.cmake @@ -0,0 +1,14 @@ +# +# HDF5 +# + +FIND_PATH(HDF5_INCLUDE_DIR hdf5.h ${HDF5_ROOT}/include ${MATIO_ROOT}/include /usr/include/ /usr/local/include/hdf5) + +if(WIN64) + FIND_LIBRARY(HDF5_LIBRARY hdf5 ${HDF5_ROOT}/lib/x64 ${MATIO_ROOT}/lib/x64 ${HDF5_ROOT}/lib ${MATIO_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(HDF5_LIBRARY hdf5 ${HDF5_ROOT}/lib ${MATIO_ROOT}/lib /usr/lib /usr/lib/hdf5 /usr/local/lib /usr/local/lib/hfd5) +endif(WIN64) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( HDF5 DEFAULT_MSG HDF5_LIBRARY HDF5_INCLUDE_DIR ) diff --git a/cmake/FindMATIO.cmake b/cmake/FindMATIO.cmake new file mode 100644 index 0000000..ac743f3 --- /dev/null +++ b/cmake/FindMATIO.cmake @@ -0,0 +1,16 @@ +# +# MATIO +# FROM http://sourceforge.net/projects/matio/ +# + +FIND_PATH(MATIO_INCLUDE_DIR matio.h ${MATIO_ROOT}/src ${MATIO_ROOT}/include /usr/local/include /usr/include) + +if(WIN64) + FIND_LIBRARY(MATIO_LIBRARY NAMES agros2d_3rd_party_matio matio libmatio PATHS ${MATIO_ROOT} ${MATIO_ROOT}/lib/x64 ${MATIO_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(MATIO_LIBRARY NAMES agros2d_3rd_party_matio matio libmatio PATHS ${MATIO_ROOT} ${MATIO_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MATIO DEFAULT_MSG MATIO_LIBRARY MATIO_INCLUDE_DIR) diff --git a/cmake/FindMUMPS.cmake b/cmake/FindMUMPS.cmake new file mode 100644 index 0000000..c6b5176 --- /dev/null +++ b/cmake/FindMUMPS.cmake @@ -0,0 +1,90 @@ +# +# MUMPS +# +# set WITH_MUMPS to YES to enable MUMPS support +# set MUMPS_ROOT to point to the directory containing your MUMPS library +# + +# You can specify your own version of the library instead of the one provided by +# Femhub by specifying the environment variables MY_MUMPS_LIB_DIRS and +# MY_MUMPS_INC_DIRS. + +if(WIN64) + SET(MUMPS_LIB_SEARCH_PATH ${MUMPS_ROOT}/lib/x64 ${MUMPS_ROOT}/lib) +else(WIN64) + SET(MUMPS_LIB_SEARCH_PATH ${MUMPS_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +FIND_PATH(MUMPS_INCLUDE_PATH mumps_c_types.h ${MUMPS_ROOT}/include /usr/include /usr/include/mumps_seq /usr/local/include/ /usr/local/include/mumps_seq) + +FIND_LIBRARY(MUMPS_MPISEQ_LIBRARY NAMES mpiseq_seq libseq_c PATHS ${MUMPS_LIB_SEARCH_PATH}) +FIND_LIBRARY(MUMPS_COMMON_LIBRARY NAMES mumps_common_seq mumps_common_c PATHS ${MUMPS_LIB_SEARCH_PATH}) +FIND_LIBRARY(MUMPS_PORD_LIBRARY NAMES pord_seq pord_c PATHS ${MUMPS_LIB_SEARCH_PATH}) + +if(WITH_MPI) +FIND_PATH(MUMPS_MPISEQ_INCLUDE_PATH mpi.h PATHS ${MUMPS_INCLUDE_SEARCH_PATH}) +endif(WITH_MPI) + +SET(MUMPS_INCLUDE_PATH ${MUMPS_INCLUDE_PATH} ${MUMPS_MPISEQ_INCLUDE_PATH}) +FIND_LIBRARY(MUMPSD_SEQ_LIBRARY NAMES dmumps_seq dmumps_c PATHS ${MUMPS_LIB_SEARCH_PATH}) +LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPSD_SEQ_LIBRARY") + +FIND_LIBRARY(MUMPSZ_SEQ_LIBRARY NAMES zmumps_seq zmumps_c PATHS ${MUMPS_LIB_SEARCH_PATH}) +LIST(APPEND REQUIRED_CPLX_LIBRARIES "MUMPSZ_SEQ_LIBRARY") + +LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPS_MPISEQ_LIBRARY") +LIST(APPEND REQUIRED_CPLX_LIBRARIES "MUMPS_MPISEQ_LIBRARY") + +LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPS_COMMON_LIBRARY" "MUMPS_PORD_LIBRARY") +LIST(APPEND REQUIRED_CPLX_LIBRARIES "MUMPS_COMMON_LIBRARY" "MUMPS_PORD_LIBRARY") + +# Fortran libraries. +FIND_LIBRARY(MUMPS_MPISEQ_FORTRAN_LIBRARY NAMES libseq_fortran PATHS ${MUMPS_LIB_SEARCH_PATH}) + if(NOT(${MUMPS_MPISEQ_FORTRAN_LIBRARY} STREQUAL "MUMPS_MPISEQ_FORTRAN_LIBRARY-NOTFOUND")) + LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPS_MPISEQ_FORTRAN_LIBRARY") + endif(NOT(${MUMPS_MPISEQ_FORTRAN_LIBRARY} STREQUAL "MUMPS_MPISEQ_FORTRAN_LIBRARY-NOTFOUND")) + +FIND_LIBRARY(MUMPSC_SEQ_FORTRAN_LIBRARY NAMES cmumps_fortran PATHS ${MUMPS_LIB_SEARCH_PATH}) + if(NOT(${MUMPSC_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSC_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPSC_SEQ_FORTRAN_LIBRARY") + else(NOT(${MUMPSC_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSC_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + MESSAGE(STATUS "MUMPSC_SEQ_FORTRAN_LIBRARY not found - if WinMUMPS is used, this is an error.") + endif(NOT(${MUMPSC_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSC_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + +FIND_LIBRARY(MUMPSS_SEQ_FORTRAN_LIBRARY NAMES smumps_fortran PATHS ${MUMPS_LIB_SEARCH_PATH}) + if(NOT(${MUMPSS_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSS_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPSS_SEQ_FORTRAN_LIBRARY") + else(NOT(${MUMPSS_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSS_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + MESSAGE(STATUS "MUMPSS_SEQ_FORTRAN_LIBRARY not found - if WinMUMPS is used, this is an error.") + endif(NOT(${MUMPSS_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSS_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + +FIND_LIBRARY(MUMPSD_SEQ_FORTRAN_LIBRARY NAMES dmumps_fortran PATHS ${MUMPS_LIB_SEARCH_PATH}) + if(NOT(${MUMPSD_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSD_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPSD_SEQ_FORTRAN_LIBRARY") + else(NOT(${MUMPSD_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSD_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + MESSAGE(STATUS "MUMPSD_SEQ_FORTRAN_LIBRARY not found - if WinMUMPS is used, this is an error.") + endif(NOT(${MUMPSD_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSD_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + +FIND_LIBRARY(MUMPSZ_SEQ_FORTRAN_LIBRARY NAMES zmumps_fortran PATHS ${MUMPS_LIB_SEARCH_PATH}) + if(NOT(${MUMPSZ_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSZ_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + LIST(APPEND REQUIRED_REAL_LIBRARIES "MUMPSZ_SEQ_FORTRAN_LIBRARY") + else(NOT(${MUMPSZ_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSZ_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + MESSAGE(STATUS "MUMPSZ_SEQ_FORTRAN_LIBRARY not found - if WinMUMPS is used, this is an error.") + endif(NOT(${MUMPSZ_SEQ_FORTRAN_LIBRARY} STREQUAL "MUMPSZ_SEQ_FORTRAN_LIBRARY-NOTFOUND")) + +# Test if all the required libraries have been found. If they haven't, end with fatal error... +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( MUMPS DEFAULT_MSG + ${REQUIRED_REAL_LIBRARIES} ${REQUIRED_CPLX_LIBRARIES} MUMPS_INCLUDE_PATH +) + +# ...if they have, append them all to the MUMPS_{REAL/CPLX}_LIBRARIES variable. + FOREACH(_LIB ${REQUIRED_REAL_LIBRARIES}) + LIST(APPEND MUMPS_REAL_LIBRARIES ${${_LIB}}) + ENDFOREACH(_LIB ${REQUIRED_REAL_LIBRARIES}) + FOREACH(_LIB ${REQUIRED_CPLX_LIBRARIES}) + LIST(APPEND MUMPS_CPLX_LIBRARIES ${${_LIB}}) + ENDFOREACH(_LIB ${REQUIRED_CPLX_LIBRARIES}) + +# Finally, set MUMPS_INCLUDE_DIR to point to the MUMPS include directory. +SET(MUMPS_INCLUDE_DIR ${MUMPS_INCLUDE_DIR} ${MUMPS_INCLUDE_PATH}) diff --git a/cmake/FindPARALUTION.cmake b/cmake/FindPARALUTION.cmake new file mode 100644 index 0000000..8c7e619 --- /dev/null +++ b/cmake/FindPARALUTION.cmake @@ -0,0 +1,16 @@ +# +# PARALUTION +# FROM http://www.paralution.com/ +# + +FIND_PATH(PARALUTION_INCLUDE_DIR paralution.hpp ${PARALUTION_ROOT}/include ${PARALUTION_ROOT}/inc /usr/local/include/google /usr/include/google) + +if(WIN64) + FIND_LIBRARY(PARALUTION_LIBRARY NAMES agros2d_3rd_party_paralution paralution PATHS ${PARALUTION_ROOT} ${PARALUTION_ROOT}/lib/x64 ${PARALUTION_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(PARALUTION_LIBRARY NAMES agros2d_3rd_party_paralution paralution PATHS ${PARALUTION_ROOT} ${PARALUTION_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PARALUTION DEFAULT_MSG PARALUTION_LIBRARY PARALUTION_INCLUDE_DIR) diff --git a/cmake/FindPETSC.cmake b/cmake/FindPETSC.cmake new file mode 100644 index 0000000..b73e022 --- /dev/null +++ b/cmake/FindPETSC.cmake @@ -0,0 +1,69 @@ +# +# PETSc +# +# When you configure and install PETSc, set PETSC_ROOT to some /root/dir/of/petsc/ +# and PETSC_ARCH to petsc-arch-real (if you intend to solve real problems) and/or +# petsc-arch-complex (if you intend to solve complex problems). Then, in order to +# configure Hermes with PETSc, you need to say (in global CMake.vars): +# set(WITH_PETSC YES) +# set(PETSC_ROOT /root/dir/of/petsc/) +# set(PETSC_ARCH petsc-arch) +# +# Example: +# In PETSc source directory (this is automatically done by the +# standalone-install script when using the prepackaged library from hpfem/solvers): +# ./config/configure.py PETSC_ARCH=linux-cxx-real --with-clanguage=cxx +# make PETSC_DIR=/opt/petsc/petsc-3.1-p7 PETSC_ARCH=linux-cxx-real all +# ./config/configure.py PETSC_ARCH=linux-cxx-complex --with-clanguage=cxx --with-scalar-type=complex +# make PETSC_DIR=/opt/petsc/petsc-3.1-p7 PETSC_ARCH=linux-mpicxx-complex all +# +# In hermes/CMake.vars: +# set(WITH_PETSC YES) +# set(PETSC_ROOT /opt/petsc/petsc-3.1-p7) +# set(PETSC_ARCH linux-cxx) +# + +IF(WIN32) + MESSAGE(FATAL_ERROR "PETSc only supported on Linux.") +ENDIF(WIN32) + +SET(COMMON_PETSC_INCLUDE_DIRS + ${PETSC_ROOT}/include + ${PETSC_ROOT}/${PETSC_ARCH}/include + /usr/include + /usr/local/include +) + +SET(COMMON_PETSC_LIB_DIRS + ${PETSC_ROOT}/${PETSC_ARCH}/lib + /usr/lib + /usr/local/lib + /usr/lib/petscdir/3.1/lib +) + +FIND_PATH(PETSC_INCLUDE_DIRS petsc.h ${COMMON_PETSC_INCLUDE_DIRS}) +FIND_PATH(PETSC_CONF_INCLUDE_DIRS petscconf.h ${COMMON_PETSC_INCLUDE_DIRS}) + +# PETSc 3.1 +FIND_LIBRARY(PETSC_LIB_C petsc ${COMMON_PETSC_LIB_DIRS}) + +IF (PETSC_INCLUDE_DIRS AND PETSC_LIB_C) + SET(PETSC_FOUND TRUE) + SET(PETSC_CPLX_LIBRARIES ${PETSC_LIB_C}) +ENDIF (PETSC_INCLUDE_DIRS AND PETSC_LIB_C) + + +IF (PETSC_FOUND) +IF (NOT PETSC_FIND_QUIETLY) + MESSAGE(STATUS "PETSc found: ${PETSC_LIB_C}") +ENDIF (NOT PETSC_FIND_QUIETLY) +ELSE (PETSC_FOUND) +IF (PETSC_FIND_REQUIRED) + MESSAGE( FATAL_ERROR + "PETSC could not be found. Either disable it by setting + WITH_PETSC to NO in your CMake.vars file, or install it according to + instructions at\n + ." +) +ENDIF (PETSC_FIND_REQUIRED) +ENDIF (PETSC_FOUND) diff --git a/cmake/FindPTHREAD.cmake b/cmake/FindPTHREAD.cmake index b261b87..87aef95 100644 --- a/cmake/FindPTHREAD.cmake +++ b/cmake/FindPTHREAD.cmake @@ -8,7 +8,11 @@ else(MSVC) set(PTHREAD_LIBRARY_NAME pthread) endif(MSVC) -FIND_LIBRARY(PTHREAD_LIBRARY ${PTHREAD_LIBRARY_NAME} ${PTHREAD_ROOT}/lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib) +if(WIN64) + FIND_LIBRARY(PTHREAD_LIBRARY ${PTHREAD_LIBRARY_NAME} ${PTHREAD_ROOT}/lib/x64 ${PTHREAD_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(PTHREAD_LIBRARY ${PTHREAD_LIBRARY_NAME} ${PTHREAD_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) # Report the found libraries, quit with fatal error if any required library has not been found. INCLUDE(FindPackageHandleStandardArgs) diff --git a/cmake/FindSCALAPACK.cmake b/cmake/FindSCALAPACK.cmake new file mode 100644 index 0000000..607eb62 --- /dev/null +++ b/cmake/FindSCALAPACK.cmake @@ -0,0 +1,15 @@ +# +# ScaLAPACK and BLACS +# + +FIND_LIBRARY(SCALAPACK_LIBRARY NAMES scalapack scalapack-pvm scalapack-mpi scalapack-mpich scalapack-mpich2 scalapack-openmpi scalapack-lam + PATHS /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib) + +FIND_LIBRARY(BLACS_LIBRARY NAMES blacs blacs-pvm blacs-mpi blacs-mpich blacs-mpich2 blacs-openmpi blacs-lam + PATHS /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCALAPACK DEFAULT_MSG SCALAPACK_LIBRARY BLACS_LIBRARY) + +SET(SCALAPACK_LIBRARIES ${SCALAPACK_LIBRARY} ${BLACS_LIBRARY}) diff --git a/cmake/FindSUPERLU.cmake b/cmake/FindSUPERLU.cmake new file mode 100644 index 0000000..8de88e7 --- /dev/null +++ b/cmake/FindSUPERLU.cmake @@ -0,0 +1,55 @@ +# +# SuperLU +# + +# You can specify your own version of the library instead of the one provided by +# Femhub by specifying the environment variables MY_SUPERLU_LIB_DIRS and +# MY_SUPERLU_INC_DIRS. +IF ("$ENV{MY_SUPERLU_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_SUPERLU_INC_DIRS}" STREQUAL "") + # When linking the library to stand-alone Hermes, you may also specify the + # variables directly in CMake.vars + IF (NOT MY_SUPERLU_LIB_DIRS OR NOT MY_SUPERLU_INC_DIRS) + # Alternatively, you may simply specify SUPERLU_ROOT in CMake.vars. This is + # the traditional way used also in the spkg files from the hpfem/solvers + # repository and in the Hermes spkg. + IF(WIN64) + SET(MY_SUPERLU_LIB_DIRS ${SUPERLU_ROOT}/lib/x64 ${SUPERLU_ROOT}/lib) + ELSE(WIN64) + SET(MY_SUPERLU_LIB_DIRS ${SUPERLU_ROOT}/lib) + ENDIF(WIN64) + SET(MY_SUPERLU_INC_DIRS ${SUPERLU_ROOT}/include) + ENDIF (NOT MY_SUPERLU_LIB_DIRS OR NOT MY_SUPERLU_INC_DIRS) +ELSE ("$ENV{MY_SUPERLU_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_SUPERLU_INC_DIRS}" STREQUAL "") + SET(MY_SUPERLU_LIB_DIRS $ENV{MY_SUPERLU_LIB_DIRS}) + SET(MY_SUPERLU_INC_DIRS $ENV{MY_SUPERLU_INC_DIRS}) +ENDIF ("$ENV{MY_SUPERLU_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_SUPERLU_INC_DIRS}" STREQUAL "") + +IF(SUPERLU_MT AND WITH_OPENMP) + SET(POST _mt_OPENMP) +ELSEIF(SUPERLU_MT) + SET(POST _mt_PTHREAD) +ENDIF(SUPERLU_MT AND WITH_OPENMP) + +IF(POST) + FIND_PATH(SUPERLU_INCLUDE_DIR pdsp_defs.h ${MY_SUPERLU_INC_DIRS} NO_DEFAULT_PATH) + FIND_PATH(SUPERLU_INCLUDE_DIR pdsp_defs.h /usr/include/superlu_mt /usr/local/include/superlu_mt) +ELSE(POST) + FIND_PATH(SUPERLU_INCLUDE_DIR slu_ddefs.h ${MY_SUPERLU_INC_DIRS} NO_DEFAULT_PATH) + FIND_PATH(SUPERLU_INCLUDE_DIR slu_ddefs.h /usr/include /usr/include/superlu /usr/local/include/superlu) +ENDIF(POST) + +IF(MSVC) + SET(PRE lib) +ENDIF(MSVC) + +FIND_LIBRARY( SUPERLU_LIBRARY ${PRE}superlu${POST} ${MY_SUPERLU_LIB_DIRS} NO_DEFAULT_PATH) +FIND_LIBRARY( SUPERLU_LIBRARY ${PRE}superlu${POST} /usr/lib /usr/lib/superlu /usr/local/lib/superlu) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( SUPERLU + "SUPERLU could not be found. Please install it according to instructions at\n + < http://hpfem.org/hermes/doc/src/installation/matrix_solvers/superlu.html >\n + and/or provide path to its root directory by setting variable SUPERLU_ROOT + in the CMake.vars file." + SUPERLU_LIBRARY SUPERLU_INCLUDE_DIR +) diff --git a/cmake/FindTCMALLOC.cmake b/cmake/FindTCMALLOC.cmake index 8d330cd..cbb2bf9 100644 --- a/cmake/FindTCMALLOC.cmake +++ b/cmake/FindTCMALLOC.cmake @@ -3,14 +3,13 @@ # FROM http://code.google.com/p/google-perftools/ # -SET(MY_TCMALLOC_LIB_DIRS ${TCMALLOC_ROOT}/lib) -SET(MY_TCMALLOC_INC_DIRS ${TCMALLOC_ROOT}/include) +FIND_PATH(TCMALLOC_INCLUDE_DIR tcmalloc.h ${TCMALLOC_ROOT}/include /usr/local/include/google /usr/include/google) -FIND_PATH(TCMALLOC_INCLUDE_DIR tcmalloc.h ${MY_TCMALLOC_INC_DIRS} /usr/local/include/google /usr/include/google) - -FIND_LIBRARY(TCMALLOC_LIBRARY NAMES tcmalloc_minimal tcmalloc_minimal_debug libtcmalloc_minimal libtcmalloc_minimal-debug PATHS ${MY_TCMALLOC_LIB_DIRS} /usr/lib /usr/local/lib) +if(WIN64) + FIND_LIBRARY(TCMALLOC_LIBRARY NAMES tcmalloc_minimal libtcmalloc_minimal PATHS ${TCMALLOC_ROOT}/lib/x64 ${TCMALLOC_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(TCMALLOC_LIBRARY NAMES tcmalloc_minimal libtcmalloc_minimal PATHS ${TCMALLOC_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( TCMALLOC "TCMALLOC could not be found." - TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR -) \ No newline at end of file +FIND_PACKAGE_HANDLE_STANDARD_ARGS( TCMALLOC DEFAULT_MSG TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindTRILINOS.cmake b/cmake/FindTRILINOS.cmake index 1e0f3ee..036be80 100644 --- a/cmake/FindTRILINOS.cmake +++ b/cmake/FindTRILINOS.cmake @@ -7,101 +7,59 @@ # - Epetra, Teuchos # -# You can specify your own version of the library instead of the one provided by -# Femhub by specifying the environment variables MY_TRILINOS_LIB_DIRS and -# MY_TRILINOS_INC_DIRS. -IF ("$ENV{MY_TRILINOS_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_TRILINOS_INC_DIRS}" STREQUAL "") - # When linking the library to stand-alone Hermes, you may also specify the - # variables directly in CMake.vars - IF (NOT MY_TRILINOS_LIB_DIRS OR NOT MY_TRILINOS_INC_DIRS) - # Alternatively, you may simply specify TRILINOS_ROOT in CMake.vars. This is - # the traditional way used also in the spkg files from the hpfem/solvers - # repository and in the Hermes spkg. - SET(MY_TRILINOS_LIB_DIRS ${TRILINOS_ROOT}/lib) - SET(MY_TRILINOS_INC_DIRS ${TRILINOS_ROOT}/include) - ENDIF (NOT MY_TRILINOS_LIB_DIRS OR NOT MY_TRILINOS_INC_DIRS) -ELSE ("$ENV{MY_TRILINOS_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_TRILINOS_INC_DIRS}" STREQUAL "") - SET(MY_TRILINOS_LIB_DIRS $ENV{MY_TRILINOS_LIB_DIRS}) - SET(MY_TRILINOS_INC_DIRS $ENV{MY_TRILINOS_INC_DIRS}) -ENDIF ("$ENV{MY_TRILINOS_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_TRILINOS_INC_DIRS}" STREQUAL "") - # CMake maybe looks into the following paths by itself, but specifying them # explicitly doesn't hurt either. SET(TRILINOS_INCLUDE_SEARCH_PATH /usr/include /usr/local/include/ + /usr/include/trilinos + ${TRILINOS_ROOT}/include ) -SET(TRILINOS_LIB_SEARCH_PATH - /usr/lib64 - /usr/lib - /usr/local/lib/ -) - -FIND_PATH(AMESOS_INCLUDE_PATH Amesos.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(AZTECOO_INCLUDE_PATH AztecOO.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(EPETRA_INCLUDE_PATH Epetra_Object.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(IFPACK_INCLUDE_PATH Ifpack.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(LOCA_INCLUDE_PATH LOCA.H ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(ML_INCLUDE_PATH MLAPI.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(NOX_INCLUDE_PATH NOX.H ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(TEUCHOS_INCLUDE_PATH Teuchos_Object.hpp ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(KOMPLEX_INCLUDE_PATH Komplex_Version.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) - -FIND_PATH(LOCA_EPETRA_INCLUDE_PATH LOCA_Epetra.H ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(NOX_EPETRA_INCLUDE_PATH NOX_Epetra.H ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) -FIND_PATH(EPETRAEXT_INCLUDE_PATH EpetraExt_Version.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) - -FIND_LIBRARY(AMESOS_LIBRARY amesos ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(AZTECOO_LIBRARY aztecoo ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(EPETRA_LIBRARY epetra ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(IFPACK_LIBRARY ifpack ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(LOCA_LIBRARY loca ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(ML_LIBRARY ml ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(NOX_LIBRARY nox ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(TEUCHOS_LIBRARY teuchos ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(KOMPLEX_LIBRARY komplex ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) - -FIND_LIBRARY(LOCA_EPETRA_LIBRARY locaepetra ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(NOX_EPETRA_LIBRARY noxepetra ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(EPETRAEXT_LIBRARY epetraext ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) - -FIND_PATH(AMESOS_INCLUDE_PATH Amesos.h ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(AZTECOO_INCLUDE_PATH AztecOO.h ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(EPETRA_INCLUDE_PATH Epetra_Object.h ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(IFPACK_INCLUDE_PATH Ifpack.h ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(LOCA_INCLUDE_PATH LOCA.H ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(ML_INCLUDE_PATH MLAPI.h ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(NOX_INCLUDE_PATH NOX.H ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(TEUCHOS_INCLUDE_PATH Teuchos_Object.hpp ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(KOMPLEX_INCLUDE_PATH Komplex_Version.h ${TRILINOS_INCLUDE_SEARCH_PATH}) - -FIND_PATH(LOCA_EPETRA_INCLUDE_PATH LOCA_Epetra.H ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(NOX_EPETRA_INCLUDE_PATH NOX_Epetra.H ${TRILINOS_INCLUDE_SEARCH_PATH}) -FIND_PATH(EPETRAEXT_INCLUDE_PATH EpetraExt_Version.h ${TRILINOS_INCLUDE_SEARCH_PATH}) - -FIND_LIBRARY(AMESOS_LIBRARY amesos ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(AZTECOO_LIBRARY aztecoo ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(EPETRA_LIBRARY epetra ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(IFPACK_LIBRARY ifpack ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(LOCA_LIBRARY loca ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(ML_LIBRARY ml ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(NOX_LIBRARY nox ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(TEUCHOS_LIBRARY teuchos ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(KOMPLEX_LIBRARY komplex ${TRILINOS_LIB_SEARCH_PATH}) - -FIND_LIBRARY(LOCA_EPETRA_LIBRARY locaepetra ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(NOX_EPETRA_LIBRARY noxepetra ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(EPETRAEXT_LIBRARY epetraext ${TRILINOS_LIB_SEARCH_PATH}) +if(WIN64) + SET(TRILINOS_LIB_SEARCH_PATH ${TRILINOS_ROOT}/lib/x64 ${TRILINOS_ROOT}/lib) +else(WIN64) + SET(TRILINOS_LIB_SEARCH_PATH /usr/lib64 /usr/lib /usr/local/lib/ ${TRILINOS_ROOT}/lib) +endif(WIN64) + +FIND_PATH(AMESOS_INCLUDE_PATH Amesos.h ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(AZTECOO_INCLUDE_PATH AztecOO.h ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(EPETRA_INCLUDE_PATH Epetra_Object.h ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(IFPACK_INCLUDE_PATH Ifpack.h ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(LOCA_INCLUDE_PATH LOCA.H ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(ML_INCLUDE_PATH MLAPI.h ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(NOX_INCLUDE_PATH NOX.H ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(TEUCHOS_INCLUDE_PATH Teuchos_Object.hpp ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(KOMPLEX_INCLUDE_PATH Komplex_Version.h ${TRILINOS_INCLUDE_SEARCH_PATH}) + +FIND_PATH(LOCA_EPETRA_INCLUDE_PATH LOCA_Epetra.H ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(NOX_EPETRA_INCLUDE_PATH NOX_Epetra.H ${TRILINOS_INCLUDE_SEARCH_PATH}) +FIND_PATH(EPETRAEXT_INCLUDE_PATH EpetraExt_Version.h ${TRILINOS_INCLUDE_SEARCH_PATH}) + +FIND_LIBRARY(AMESOS_LIBRARY NAMES amesos trilinos_amesos PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(AZTECOO_LIBRARY NAMES aztecoo trilinos_aztecoo PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(EPETRA_LIBRARY NAMES epetra trilinos_epetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(IFPACK_LIBRARY NAMES ifpack trilinos_ifpack PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(LOCA_LIBRARY NAMES loca trilinos_loca PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(ML_LIBRARY NAMES ml trilinos_ml PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(NOX_LIBRARY NAMES nox trilinos_nox PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(TEUCHOS_LIBRARY NAMES teuchos trilinos_teuchos teuchoscore PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(TEUCHOS_LIBRARY_COMM NAMES teuchoscomm PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(TEUCHOS_LIBRARY_NUMERICS NAMES teuchosnumerics PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(TEUCHOS_LIBRARY_PARAMETER_LIST NAMES teuchosparameterlist PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(TEUCHOS_LIBRARY_REMAINDER NAMES teuchosremainder PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(KOMPLEX_LIBRARY NAMES komplex trilinos_komplex PATHS ${TRILINOS_LIB_SEARCH_PATH}) + +FIND_LIBRARY(THYRA_LIBRARY NAMES thyra thyracore PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(THYRA_EPETRA_LIBRARY NAMES thyraepetra trilinos_thyraepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) + +FIND_LIBRARY(LOCA_EPETRA_LIBRARY NAMES locaepetra trilinos_locaepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(NOX_EPETRA_LIBRARY NAMES noxepetra trilinos_noxepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) +FIND_LIBRARY(EPETRAEXT_LIBRARY NAMES epetraext trilinos_epetraext PATHS ${TRILINOS_LIB_SEARCH_PATH}) # Experimental if(WITH_ZOLTAN) - FIND_PATH(ZOLTAN_INCLUDE_PATH zoltan.h ${MY_TRILINOS_INC_DIRS} NO_DEFAULT_PATH) - - FIND_LIBRARY(ZOLTAN_LIBRARY zoltan ${MY_TRILINOS_LIB_DIRS} NO_DEFAULT_PATH) - FIND_PATH(ZOLTAN_INCLUDE_PATH zoltan.h ${TRILINOS_INCLUDE_SEARCH_PATH}) - FIND_LIBRARY(ZOLTAN_LIBRARY zoltan ${TRILINOS_LIB_SEARCH_PATH}) endif(WITH_ZOLTAN) @@ -115,7 +73,7 @@ ENDIF(EPETRA_INCLUDE_PATH AND EPETRA_LIBRARY) IF(TEUCHOS_INCLUDE_PATH AND TEUCHOS_LIBRARY) SET(TRILINOS_INCLUDE_DIR ${TRILINOS_INCLUDE_DIR} ${TEUCHOS_INCLUDE_PATH}) - SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${TEUCHOS_LIBRARY}) + SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${TEUCHOS_LIBRARY} ${TEUCHOS_LIBRARY_PARAMETER_LIST} ${TEUCHOS_LIBRARY_NUMERICS} ${TEUCHOS_LIBRARY_REMAINDER} ${TEUCHOS_LIBRARY_COMM}) SET(HAVE_TEUCHOS YES) ENDIF(TEUCHOS_INCLUDE_PATH AND TEUCHOS_LIBRARY) @@ -159,7 +117,7 @@ ENDIF(ML_INCLUDE_PATH AND ML_LIBRARY) IF(NOX_INCLUDE_PATH AND NOX_LIBRARY AND NOX_EPETRA_INCLUDE_PATH AND NOX_EPETRA_LIBRARY) SET(TRILINOS_INCLUDE_DIR ${TRILINOS_INCLUDE_DIR} ${NOX_INCLUDE_PATH} ${NOX_EPETRA_INCLUDE_PATH}) - SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${NOX_LIBRARY} ${NOX_EPETRA_LIBRARY}) + SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${NOX_LIBRARY} ${NOX_EPETRA_LIBRARY} ${THYRA_LIBRARY} ${THYRA_EPETRA_LIBRARY}) SET(HAVE_NOX YES) find_package_handle_standard_args(NOX DEFAULT_MSG NOX_LIBRARY) ENDIF(NOX_INCLUDE_PATH AND NOX_LIBRARY AND NOX_EPETRA_INCLUDE_PATH AND NOX_EPETRA_LIBRARY) diff --git a/cmake/FindUMFPACK.cmake b/cmake/FindUMFPACK.cmake index 86c77a6..63d667b 100644 --- a/cmake/FindUMFPACK.cmake +++ b/cmake/FindUMFPACK.cmake @@ -12,7 +12,11 @@ IF ("$ENV{MY_UMFPACK_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_UMFPACK_INC_DIRS}" STREQ # Alternatively, you may simply specify UMFPACK_ROOT in CMake.vars. This is # the traditional way used also in the spkg files from the hpfem/solvers # repository and in the Hermes spkg. - SET(MY_UMFPACK_LIB_DIRS ${UMFPACK_ROOT}/lib) + if(WIN64) + SET(MY_UMFPACK_LIB_DIRS ${UMFPACK_ROOT}/lib/x64 ${UMFPACK_ROOT}/lib) + else(WIN64) + SET(MY_UMFPACK_LIB_DIRS ${UMFPACK_ROOT}/lib) + endif(WIN64) SET(MY_UMFPACK_INC_DIRS ${UMFPACK_ROOT}/include) ENDIF (NOT MY_UMFPACK_LIB_DIRS OR NOT MY_UMFPACK_INC_DIRS) ELSE ("$ENV{MY_UMFPACK_LIB_DIRS}" STREQUAL "" OR "$ENV{MY_UMFPACK_INC_DIRS}" STREQUAL "") @@ -28,7 +32,8 @@ FIND_PATH(AMD_INCLUDE_DIR amd.h /usr/include /usr/local/include/AMD /usr FIND_LIBRARY(UMFPACK_LIBRARY NAMES libumfpack umfpack PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) FIND_LIBRARY(SSC_LIBRARY NAMES libsuitesparseconfig suitesparseconfig PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) FIND_LIBRARY(AMD_LIBRARY NAMES libamd amd PATHS ${MY_UMFPACK_LIB_DIRS} NO_DEFAULT_PATH) -FIND_LIBRARY(UMFPACK_LIBRARY NAMES libumfpack umfpack PATHS /usr/lib /usr/local/lib/UMFPACK) + +FIND_LIBRARY(UMFPACK_LIBRARY NAMES libumfpack umfpack PATHS /usr/lib /usr/local/lib/UMFPACK) FIND_LIBRARY(SSC_LIBRARY NAMES libsuitesparseconfig suitesparseconfig PATHS /usr/lib /usr/local/lib/UMFPACK) FIND_LIBRARY(AMD_LIBRARY NAMES libamd amd PATHS /usr/lib /usr/local/lib/AMD) diff --git a/cmake/FindWINBLAS.cmake b/cmake/FindWINBLAS.cmake new file mode 100644 index 0000000..b36b760 --- /dev/null +++ b/cmake/FindWINBLAS.cmake @@ -0,0 +1,12 @@ +# +# BLAS (for Windows) +# + +if(WIN64) + SET(BLAS_LIB_SEARCH_PATH ${WINBLAS_ROOT}/lib/x64 ${WINBLAS_ROOT}/lib) +else(WIN64) + SET(BLAS_LIB_SEARCH_PATH ${WINBLAS_ROOT}/lib) +endif(WIN64) + +FIND_LIBRARY(WINBLAS_LIBRARY libblas blas ${BLAS_LIB_SEARCH_PATH}) +find_package_handle_standard_args(WINBLAS DEFAULT_MSG WINBLAS_LIBRARY) \ No newline at end of file diff --git a/cmake/FindXERCES.cmake b/cmake/FindXERCES.cmake new file mode 100644 index 0000000..658d81b --- /dev/null +++ b/cmake/FindXERCES.cmake @@ -0,0 +1,15 @@ +# +# XERCES +# + +FIND_PATH(XERCES_INCLUDE_DIR xercesc/sax/InputSource.hpp xercesc/dom/DOMDocument.hpp xercesc/dom/DOMErrorHandler.hpp ${XERCES_ROOT}/include) + +if(WIN64) + FIND_LIBRARY(XERCES_LIBRARY NAMES xerces-c_3 xerces-c PATHS ${XERCES_ROOT}/lib/x64 ${XERCES_ROOT}/lib) +else(WIN64) + FIND_LIBRARY(XERCES_LIBRARY NAMES xerces-c_3 xerces-c PATHS ${XERCES_ROOT}/lib /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64) +endif(WIN64) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(XERCES DEFAULT_MSG XERCES_LIBRARY XERCES_INCLUDE_DIR) diff --git a/cmake/FindXSD.cmake b/cmake/FindXSD.cmake new file mode 100644 index 0000000..be5d3d6 --- /dev/null +++ b/cmake/FindXSD.cmake @@ -0,0 +1,13 @@ +SET(XSD_INCLUDE_SEARCH_PATH + ${XSD_ROOT}/include + /usr/include + /usr/local/include +) + +FIND_PATH(XSD_INCLUDE_DIR xsd/cxx/pre.hxx xsd/cxx/xml/dom/parsing-source.hxx xsd/cxx/post.hxx xsd/cxx/xml/sax/std-input-source.hxx xsd/cxx/tree/error-handler.hxx ${XSD_INCLUDE_SEARCH_PATH}) + +FIND_PROGRAM(XSD_BIN NAMES xsd xsdcxx) + +# Report the found libraries, quit with fatal error if any required library has not been found. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(XSD DEFAULT_MSG XSD_INCLUDE_DIR XSD_BIN) \ No newline at end of file From 10d4ea9990214620280b7caa1547b46a2065e968 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Fri, 11 Oct 2013 19:04:50 +0200 Subject: [PATCH 49/64] Work towards release. --- .../linear-advection-diffusion/main.cpp | 14 +++----------- 2d-advanced/elasticity-linear/crack/main.cpp | 2 +- 2d-advanced/euler/euler-coupled-adapt/main.cpp | 2 +- 2d-advanced/euler/euler-coupled/main.cpp | 2 +- .../euler/heating-flow-coupling-adapt/main.cpp | 2 +- 2d-advanced/euler/heating-flow-coupling/main.cpp | 3 ++- .../euler/joukowski-profile-adapt/main.cpp | 2 +- 2d-advanced/euler/joukowski-profile/main.cpp | 2 +- 2d-advanced/helmholtz/waveguide/main.cpp | 2 +- 2d-advanced/maxwell/magnetostatics/main.cpp | 2 +- 2d-advanced/maxwell/microwave-oven/main.cpp | 2 +- .../maxwell/resonator-time-domain-II-ie/main.cpp | 2 +- 2d-advanced/navier-stokes/bearing/main.cpp | 2 +- .../circular-obstacle-adapt/main.cpp | 2 +- .../navier-stokes/circular-obstacle/main.cpp | 2 +- 2d-advanced/navier-stokes/driven-cavity/main.cpp | 2 +- .../navier-stokes/rayleigh-benard/main.cpp | 2 +- .../np-poisson-timedep-adapt/main.cpp | 4 ++-- 2d-advanced/neutronics/4-group-adapt/main.cpp | 2 +- .../richards/basic-ie-picard/definitions.cpp | 14 +++++++------- .../richards/basic-ie-picard/definitions.h | 2 +- 2d-advanced/richards/basic-ie-picard/main.cpp | 16 +++++----------- .../richards/capillary-barrier-adapt/main.cpp | 4 ++-- 2d-benchmarks-nist/03-linear-elasticity/main.cpp | 2 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 2 +- 25 files changed, 40 insertions(+), 53 deletions(-) diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index a7983a9..64fde62 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example solves a linear advection diffusion problem using optional @@ -107,23 +105,17 @@ int main(int argc, char* argv[]) Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); - // Initialize matrix solver. - SparseMatrix* matrix = create_matrix(); - Vector* rhs = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); - // Assemble the reference problem. Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); - DiscreteProblem* dp = new DiscreteProblem(&wf, ref_space); - dp->assemble(matrix, rhs); + LinearSolver solver(&wf, ref_space); // Time measurement. cpu_time.tick(); // Solve the linear system of the reference problem. // If successful, obtain the solution. - solver->solve(); - Solution::vector_to_solution(solver->get_sln_vector(), ref_space, ref_sln); + solver.solve(); + Solution::vector_to_solution(solver.get_sln_vector(), ref_space, ref_sln); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 0db9f80..4090005 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -182,7 +182,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/euler/euler-coupled-adapt/main.cpp b/2d-advanced/euler/euler-coupled-adapt/main.cpp index e4c65bf..e7869af 100644 --- a/2d-advanced/euler/euler-coupled-adapt/main.cpp +++ b/2d-advanced/euler/euler-coupled-adapt/main.cpp @@ -353,7 +353,7 @@ SpaceSharedPtr* ref_space_c = refSpaceCreatorConcentration.create_ref_sp SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Initialize the FE problem. DiscreteProblem dp(&wf, ref_spaces_const); diff --git a/2d-advanced/euler/euler-coupled/main.cpp b/2d-advanced/euler/euler-coupled/main.cpp index c576711..4ac4b2e 100644 --- a/2d-advanced/euler/euler-coupled/main.cpp +++ b/2d-advanced/euler/euler-coupled/main.cpp @@ -190,7 +190,7 @@ SpaceSharedPtrspace_rho(&mesh_flow, P_FLOW); SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver(matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver(matrix, rhs); // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); diff --git a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp index 36f9689..590f370 100644 --- a/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling-adapt/main.cpp @@ -174,7 +174,7 @@ int main(int argc, char* argv[]) SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Set up stability calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index d6526b9..14a462e 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -3,6 +3,7 @@ #include "hermes2d.h" using namespace Hermes; +using namespace Hermes::Solvers; using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::RefinementSelectors; using namespace Hermes::Hermes2D::Views; @@ -132,7 +133,7 @@ int main(int argc, char* argv[]) SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Set up stability calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); diff --git a/2d-advanced/euler/joukowski-profile-adapt/main.cpp b/2d-advanced/euler/joukowski-profile-adapt/main.cpp index 8555be1..e035574 100644 --- a/2d-advanced/euler/joukowski-profile-adapt/main.cpp +++ b/2d-advanced/euler/joukowski-profile-adapt/main.cpp @@ -288,7 +288,7 @@ SpaceSharedPtr *>(new Hermes::vector(ref_space_rho SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); wf.set_current_time_step(time_step); diff --git a/2d-advanced/euler/joukowski-profile/main.cpp b/2d-advanced/euler/joukowski-profile/main.cpp index 247b4a1..05bb258 100644 --- a/2d-advanced/euler/joukowski-profile/main.cpp +++ b/2d-advanced/euler/joukowski-profile/main.cpp @@ -129,7 +129,7 @@ SpaceSharedPtr space_rho(&mesh, P_INIT); SparseMatrix* matrix = create_matrix(); Vector* rhs = create_vector(); Vector* rhs_stabilization = create_vector(); - LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( matrix, rhs); // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index 4166705..6c95657 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) ndof = Space::get_num_dofs(Hermes::vector >(e_r_space, e_i_space)); Hermes::Hermes2D::NewtonSolver newton(&dp); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); ScalarView viewEr("Er [V/m]", new WinGeom(600, 0, 700, 200)); diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 53f514a..76155aa 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/maxwell/microwave-oven/main.cpp b/2d-advanced/maxwell/microwave-oven/main.cpp index 317b130..d8c9bb8 100644 --- a/2d-advanced/maxwell/microwave-oven/main.cpp +++ b/2d-advanced/maxwell/microwave-oven/main.cpp @@ -150,7 +150,7 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::NewtonSolver newton(&wf, space); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); // Newton's iteration. // Adaptivity loop: diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index 061c3e9..7fbb2e0 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 113d603..95a2985 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 7ea9527..60ce0c3 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -268,7 +268,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V { newton.set_spaces(ref_spaces); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); if(as == 2) newton.output_matrix(); newton.solve(coeff_vec); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 127e8e8..6e01747 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) Hermes::Hermes2D::NewtonSolver newton(&dp); Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.set_jacobian_constant(); // Initialize views. diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index b779343..7b4433e 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -175,7 +175,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 5a2f4da..76dc800 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -158,7 +158,7 @@ SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_V try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index 4d08986..68d5822 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -261,7 +261,7 @@ int main (int argc, char* argv[]) { try { solver_coarse->set_max_allowed_iterations(NEWTON_MAX_ITER); - solver_coarse->set_tolerance(NEWTON_TOL_COARSE, ResidualNormAbsolute); + solver_coarse->set_tolerance(NEWTON_TOL_COARSE, Hermes::Solvers::ResidualNormAbsolute); solver_coarse->solve(coeff_vec_coarse); } catch(Hermes::Exceptions::Exception e) @@ -353,7 +353,7 @@ int main (int argc, char* argv[]) { try { solver->set_max_allowed_iterations(NEWTON_MAX_ITER); - solver->set_tolerance(NEWTON_TOL_FINE, ResidualNormAbsolute); + solver->set_tolerance(NEWTON_TOL_FINE, Hermes::Solvers::ResidualNormAbsolute); solver->solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) diff --git a/2d-advanced/neutronics/4-group-adapt/main.cpp b/2d-advanced/neutronics/4-group-adapt/main.cpp index 8e8543f..b0b7404 100644 --- a/2d-advanced/neutronics/4-group-adapt/main.cpp +++ b/2d-advanced/neutronics/4-group-adapt/main.cpp @@ -169,7 +169,7 @@ SpaceSharedPtr*> spaces(&space1, &space2, &space3, &space4); SparseMatrix* mat = create_matrix(); Vector* rhs = create_vector(); // Instantiate the solver itself. - LinearMatrixSolver* solver = create_linear_solver( mat, rhs); + Hermes::Solvers::LinearMatrixSolver* solver = create_linear_solver( mat, rhs); // Initialize views. /* for 1280x800 display */ diff --git a/2d-advanced/richards/basic-ie-picard/definitions.cpp b/2d-advanced/richards/basic-ie-picard/definitions.cpp index a3b54cd..1de18de 100644 --- a/2d-advanced/richards/basic-ie-picard/definitions.cpp +++ b/2d-advanced/richards/basic-ie-picard/definitions.cpp @@ -5,7 +5,7 @@ // as the zero vector. Note: the resulting // pressure head will also be greater than the // true one by this offset. -double H_OFFSET = 1000; +double H_OFFSET = 1e3; /* Custom non-constant Dirichlet condition */ @@ -22,16 +22,16 @@ double CustomEssentialBCNonConst::value(double x, double y, double n_x, double n /* Custom weak forms */ -CustomWeakFormRichardsIEPicard::CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, MeshFunctionSharedPtr h_iter_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) +CustomWeakFormRichardsIEPicard::CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, ConstitutiveRelations* constitutive) : WeakForm(1), constitutive(constitutive) { // Jacobian. CustomJacobian* matrix_form = new CustomJacobian(0, 0, time_step); - matrix_form->set_ext(Hermes::vector >(h_time_prev, h_iter_prev)); + matrix_form->set_ext(h_time_prev); add_matrix_form(matrix_form); // Residual. CustomResidual* vector_form = new CustomResidual(0, time_step); - vector_form->set_ext(Hermes::vector >(h_time_prev, h_iter_prev)); + vector_form->set_ext(h_time_prev); add_vector_form(vector_form); } @@ -42,7 +42,7 @@ double CustomWeakFormRichardsIEPicard::CustomJacobian::value(int n, double *wt, Func* h_prev_picard = u_ext[0]; for (int i = 0; i < n; i++) { - double h_prev_picard_i = h_prev_picard->val[i] - H_OFFSET; + double h_prev_picard_i = h_prev_picard->val[i] - 0.; result += wt[i] * ( static_cast(wf)->constitutive->C(h_prev_picard_i) * u->val[i] * v->val[i] + static_cast(wf)->constitutive->K(h_prev_picard_i) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) * time_step @@ -71,8 +71,8 @@ double CustomWeakFormRichardsIEPicard::CustomResidual::value(int n, double *wt, Func* h_prev_time = ext[0]; for (int i = 0; i < n; i++) { - double h_prev_picard_i = h_prev_picard->val[i] - H_OFFSET; - double h_prev_time_i = h_prev_time->val[i];// - H_OFFSET; + double h_prev_picard_i = h_prev_picard->val[i] - 0.; + double h_prev_time_i = h_prev_time->val[i] - 0.; result += wt[i] * static_cast(wf)->constitutive->C(h_prev_picard_i) * (h_prev_time_i) * v->val[i]; } return result; diff --git a/2d-advanced/richards/basic-ie-picard/definitions.h b/2d-advanced/richards/basic-ie-picard/definitions.h index 58f4d81..8f28961 100644 --- a/2d-advanced/richards/basic-ie-picard/definitions.h +++ b/2d-advanced/richards/basic-ie-picard/definitions.h @@ -28,7 +28,7 @@ class CustomEssentialBCNonConst : public EssentialBoundaryCondition class CustomWeakFormRichardsIEPicard : public WeakForm { public: - CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, MeshFunctionSharedPtr h_iter_prev, ConstitutiveRelations* constitutive); + CustomWeakFormRichardsIEPicard(double time_step, MeshFunctionSharedPtr h_time_prev, ConstitutiveRelations* constitutive); private: diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index 41a3037..b39602a 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -85,15 +85,12 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); // Zero initial solutions. This is why we use H_OFFSET. - MeshFunctionSharedPtr h_time_prev(new ZeroSolution(mesh)), h_iter_prev(new ZeroSolution(mesh)); + MeshFunctionSharedPtr h_time_prev(new ConstantSolution(mesh, 0.)); // Initialize views. ScalarView view("Initial condition", new WinGeom(0, 0, 600, 500)); view.fix_scale_width(80); - // Visualize the initial condition. - view.show(h_time_prev); - // Initialize the constitutive relations. ConstitutiveRelations* constitutive_relations; if(constitutive_relations_type == CONSTITUTIVE_GENUCHTEN) @@ -103,14 +100,14 @@ int main(int argc, char* argv[]) // Initialize the weak formulation. double current_time = 0; - CustomWeakFormRichardsIEPicard wf(time_step, h_time_prev, h_iter_prev, constitutive_relations); + CustomWeakFormRichardsIEPicard wf(time_step, h_time_prev, constitutive_relations); // Initialize the FE problem. DiscreteProblem dp(&wf, space); dp.set_linear(); // Initialize the Picard solver. - PicardSolver picard(&dp); + PicardSolver picard(&wf, space); picard.set_verbose_output(true); // Time stepping: @@ -134,7 +131,7 @@ int main(int argc, char* argv[]) } // Translate the coefficient vector into a Solution. - Solution::vector_to_solution(picard.get_sln_vector(), space, h_iter_prev); + Solution::vector_to_solution(picard.get_sln_vector(), space, h_time_prev); // Increase current time and time step counter. current_time += time_step; @@ -144,10 +141,7 @@ int main(int argc, char* argv[]) char title[100]; sprintf(title, "Time %g s", current_time); view.set_title(title); - view.show(h_iter_prev); - - // Save the next time level solution. - h_time_prev->copy(h_iter_prev); + view.show(h_time_prev); } while (current_time < T_FINAL); diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 36366fe..7960bcb 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -355,7 +355,7 @@ int main(int argc, char* argv[]) try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, ResidualNormAbsolute); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); newton.solve(coeff_vec); newton_converged = true; } @@ -411,7 +411,7 @@ int main(int argc, char* argv[]) PicardSolver picard(&dp); picard.set_verbose_output(verbose); picard.set_max_allowed_iterations(PICARD_MAX_ITER); - picard.set_tolerance(PICARD_TOL, SolutionChangeRelative); + picard.set_tolerance(PICARD_TOL, Hermes::Solvers::SolutionChangeRelative); while(true) { try diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index d7228af..15100be 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); - newton.set_tolerance(1e-4, ResidualNormAbsolute); + newton.set_tolerance(1e-4, Hermes::Solvers::ResidualNormAbsolute); try { diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index dd05a14..f7ce606 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) // Assemble the discrete problem. NewtonSolver newton; newton.set_weak_formulation(&wf); - newton.set_tolerance(1e-5, ResidualNormAbsolute); + newton.set_tolerance(1e-5, Hermes::Solvers::ResidualNormAbsolute); newton.set_UMFPACK_output(true, false); mesh->copy(basemesh); From 2c919f78f43ed0dcfa6ae4b4ee646f9773b40b0d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Sat, 12 Oct 2013 17:26:31 +0200 Subject: [PATCH 50/64] Fixes for release. --- .../linear-advection-diffusion/main.cpp | 7 ------- 2d-benchmarks-nist/NIST-util.cpp | 5 +---- cmake/CommonTargetProperties.cmake | 19 +++---------------- cmake/FindHERMES.cmake | 13 +++++++------ cmake/FindHERMES_COMMON.cmake | 14 +++++++------- cmake/FindTRILINOS.cmake | 11 ++--------- 6 files changed, 20 insertions(+), 49 deletions(-) diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 64fde62..5da8585 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -159,13 +159,6 @@ int main(int argc, char* argv[]) // Increase the counter of performed adaptivity steps. if (done == false) as++; } - - // Clean up. - delete solver; - delete matrix; - delete rhs; - - delete dp; } while (done == false); diff --git a/2d-benchmarks-nist/NIST-util.cpp b/2d-benchmarks-nist/NIST-util.cpp index cbe89c3..230ace5 100644 --- a/2d-benchmarks-nist/NIST-util.cpp +++ b/2d-benchmarks-nist/NIST-util.cpp @@ -74,10 +74,7 @@ bool adaptive_step_single_space( solver.set_report_cache_hits_and_misses(); solver.set_space(ref_space); solver.solve(); - FactorizationSize = solver.get_UMFPACK_reporting_data(Solver::FactorizationSize); - PeakMemoryUsage = solver.get_UMFPACK_reporting_data(Solver::PeakMemoryUsage); - Flops = solver.get_UMFPACK_reporting_data(Solver::Flops); - + // Translate the resulting coefficient vector into the instance of Solution. Solution::vector_to_solution(solver.get_sln_vector(), ref_space, ref_sln); diff --git a/cmake/CommonTargetProperties.cmake b/cmake/CommonTargetProperties.cmake index e40f791..f317ccd 100644 --- a/cmake/CommonTargetProperties.cmake +++ b/cmake/CommonTargetProperties.cmake @@ -1,24 +1,11 @@ macro(SET_COMMON_TARGET_PROPERTIES TRGT HERMES_VERSION) - set(HERMES_VERSION ${HERMES_VERSION}) - find_package(HERMES REQUIRED) - if (COMPILE_FLAGS) - set_target_properties(${TRGT} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS}) - endif (COMPILE_FLAGS) - - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "-fopenmp ${CMAKE_CXX_FLAGS}") - endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - - if(MSVC) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") - endif(MSVC) - target_link_libraries(${TRGT} ${HERMES_COMMON_LIBRARY}) - target_link_libraries(${TRGT} ${HERMES_LIBRARY}) + target_link_libraries(${TRGT} ${HERMES_LIBRARY} ${MATIO_LIBRARY} ${BSON_LIBRARY}) + target_link_libraries(${TRGT} ${TESTING_CORE_LIBRARY}) + # Is empty if WITH_TRILINOS = NO target_link_libraries(${TRGT} ${TRILINOS_LIBRARIES}) - endmacro(SET_COMMON_TARGET_PROPERTIES) diff --git a/cmake/FindHERMES.cmake b/cmake/FindHERMES.cmake index 5412d27..1388430 100644 --- a/cmake/FindHERMES.cmake +++ b/cmake/FindHERMES.cmake @@ -1,11 +1,12 @@ INCLUDE(FindPackageHandleStandardArgs) if(${HERMES_VERSION} STREQUAL "HERMES2D") -IF(HERMES_EXAMPLES_DEBUG) - FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) -ELSE(HERMES_EXAMPLES_DEBUG) - FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) -ENDIF(HERMES_EXAMPLES_DEBUG) - FIND_PATH(HERMES_INCLUDE hermes2d.h ${HERMES2D_INCLUDE_PATH} /usr/lib /usr/local/lib) + if(WIN64) + FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d_64 hermes2d_64-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib NO_DEFAULT_PATH) + else() + FIND_LIBRARY(HERMES_LIBRARY NAMES hermes2d hermes2d-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib NO_DEFAULT_PATH) + endif() + + FIND_PATH(HERMES_INCLUDE hermes2d.h ${HERMES2D_INCLUDE_PATH} /usr/include/hermes2d /usr/local/include/hermes2d) FIND_PACKAGE_HANDLE_STANDARD_ARGS(HERMES DEFAULT_MSG HERMES_LIBRARY HERMES_INCLUDE) endif(${HERMES_VERSION} STREQUAL "HERMES2D") diff --git a/cmake/FindHERMES_COMMON.cmake b/cmake/FindHERMES_COMMON.cmake index 1cc133c..dba8a0b 100644 --- a/cmake/FindHERMES_COMMON.cmake +++ b/cmake/FindHERMES_COMMON.cmake @@ -1,10 +1,10 @@ INCLUDE(FindPackageHandleStandardArgs) -IF(HERMES_EXAMPLES_DEBUG) - FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) -ELSE(HERMES_EXAMPLES_DEBUG) - FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib) -ENDIF(HERMES_EXAMPLES_DEBUG) - -FIND_PATH(HERMES_COMMON_INCLUDE hermes_common.h ${HERMES_COMMON_INCLUDE_PATH} /usr/include /usr/local/include) +if(WIN64) + FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common_64 hermes_common_64-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib NO_DEFAULT_PATH) +else() + FIND_LIBRARY(HERMES_COMMON_LIBRARY NAMES hermes_common hermes_common-debug PATHS ${HERMES_DIRECTORY} /usr/lib /usr/local/lib NO_DEFAULT_PATH) +endif() + +FIND_PATH(HERMES_COMMON_INCLUDE hermes_common.h ${HERMES_COMMON_INCLUDE_PATH} /usr/include/hermes_common /usr/local/include/hermes_common) FIND_PACKAGE_HANDLE_STANDARD_ARGS(HERMES_COMMON DEFAULT_MSG HERMES_COMMON_LIBRARY HERMES_COMMON_INCLUDE) diff --git a/cmake/FindTRILINOS.cmake b/cmake/FindTRILINOS.cmake index 036be80..58c11b1 100644 --- a/cmake/FindTRILINOS.cmake +++ b/cmake/FindTRILINOS.cmake @@ -44,15 +44,8 @@ FIND_LIBRARY(LOCA_LIBRARY NAMES loca trilinos_loca P FIND_LIBRARY(ML_LIBRARY NAMES ml trilinos_ml PATHS ${TRILINOS_LIB_SEARCH_PATH}) FIND_LIBRARY(NOX_LIBRARY NAMES nox trilinos_nox PATHS ${TRILINOS_LIB_SEARCH_PATH}) FIND_LIBRARY(TEUCHOS_LIBRARY NAMES teuchos trilinos_teuchos teuchoscore PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(TEUCHOS_LIBRARY_COMM NAMES teuchoscomm PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(TEUCHOS_LIBRARY_NUMERICS NAMES teuchosnumerics PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(TEUCHOS_LIBRARY_PARAMETER_LIST NAMES teuchosparameterlist PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(TEUCHOS_LIBRARY_REMAINDER NAMES teuchosremainder PATHS ${TRILINOS_LIB_SEARCH_PATH}) FIND_LIBRARY(KOMPLEX_LIBRARY NAMES komplex trilinos_komplex PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(THYRA_LIBRARY NAMES thyra thyracore PATHS ${TRILINOS_LIB_SEARCH_PATH}) -FIND_LIBRARY(THYRA_EPETRA_LIBRARY NAMES thyraepetra trilinos_thyraepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) - FIND_LIBRARY(LOCA_EPETRA_LIBRARY NAMES locaepetra trilinos_locaepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) FIND_LIBRARY(NOX_EPETRA_LIBRARY NAMES noxepetra trilinos_noxepetra PATHS ${TRILINOS_LIB_SEARCH_PATH}) FIND_LIBRARY(EPETRAEXT_LIBRARY NAMES epetraext trilinos_epetraext PATHS ${TRILINOS_LIB_SEARCH_PATH}) @@ -73,7 +66,7 @@ ENDIF(EPETRA_INCLUDE_PATH AND EPETRA_LIBRARY) IF(TEUCHOS_INCLUDE_PATH AND TEUCHOS_LIBRARY) SET(TRILINOS_INCLUDE_DIR ${TRILINOS_INCLUDE_DIR} ${TEUCHOS_INCLUDE_PATH}) - SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${TEUCHOS_LIBRARY} ${TEUCHOS_LIBRARY_PARAMETER_LIST} ${TEUCHOS_LIBRARY_NUMERICS} ${TEUCHOS_LIBRARY_REMAINDER} ${TEUCHOS_LIBRARY_COMM}) + SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${TEUCHOS_LIBRARY}) SET(HAVE_TEUCHOS YES) ENDIF(TEUCHOS_INCLUDE_PATH AND TEUCHOS_LIBRARY) @@ -117,7 +110,7 @@ ENDIF(ML_INCLUDE_PATH AND ML_LIBRARY) IF(NOX_INCLUDE_PATH AND NOX_LIBRARY AND NOX_EPETRA_INCLUDE_PATH AND NOX_EPETRA_LIBRARY) SET(TRILINOS_INCLUDE_DIR ${TRILINOS_INCLUDE_DIR} ${NOX_INCLUDE_PATH} ${NOX_EPETRA_INCLUDE_PATH}) - SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${NOX_LIBRARY} ${NOX_EPETRA_LIBRARY} ${THYRA_LIBRARY} ${THYRA_EPETRA_LIBRARY}) + SET(TRILINOS_LIBRARIES ${TRILINOS_LIBRARIES} ${NOX_LIBRARY} ${NOX_EPETRA_LIBRARY}) SET(HAVE_NOX YES) find_package_handle_standard_args(NOX DEFAULT_MSG NOX_LIBRARY) ENDIF(NOX_INCLUDE_PATH AND NOX_LIBRARY AND NOX_EPETRA_INCLUDE_PATH AND NOX_EPETRA_LIBRARY) From a45686ee3d3f7de3244c2a4a48d87e9416a0c2ec Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 14 Oct 2013 21:44:22 +0200 Subject: [PATCH 51/64] Re-work the NIST benchmark to usable state. --- .../01-analytic-solution/CMakeLists.txt | 2 +- .../01-analytic-solution/definitions.cpp | 2 +- .../01-analytic-solution/definitions.h | 2 +- .../01-analytic-solution/main.cpp | 30 +- .../02-reentrant-corner/CMakeLists.txt | 2 +- .../02-reentrant-corner/definitions.cpp | 2 +- .../02-reentrant-corner/main.cpp | 30 +- .../03-linear-elasticity/CMakeLists.txt | 2 +- .../03-linear-elasticity/definitions.cpp | 4 +- .../03-linear-elasticity/main.cpp | 40 +- .../04-exponential-peak/CMakeLists.txt | 2 +- .../04-exponential-peak/definitions.cpp | 4 +- .../04-exponential-peak/main.cpp | 371 ++++++---------- 2d-benchmarks-nist/05-battery/CMakeLists.txt | 2 +- 2d-benchmarks-nist/05-battery/definitions.cpp | 6 +- 2d-benchmarks-nist/05-battery/definitions.h | 52 +-- 2d-benchmarks-nist/05-battery/main.cpp | 362 ++++++---------- .../06-boundary-layer/CMakeLists.txt | 2 +- .../06-boundary-layer/definitions.cpp | 6 +- .../06-boundary-layer/definitions.h | 6 +- 2d-benchmarks-nist/06-boundary-layer/main.cpp | 374 ++++++----------- .../CMakeLists.txt | 2 +- .../definitions.cpp | 2 +- .../07-boundary-line-singularity/main.cpp | 354 ++++++---------- .../08-oscillatory/CMakeLists.txt | 2 +- .../08-oscillatory/definitions.cpp | 6 +- .../08-oscillatory/definitions.h | 6 +- 2d-benchmarks-nist/08-oscillatory/main.cpp | 371 ++++++---------- .../09-wave-front/CMakeLists.txt | 2 +- 2d-benchmarks-nist/09-wave-front/main.cpp | 40 +- .../CMakeLists.txt | 2 +- .../10-interior-line-singularity/main.cpp | 41 +- 2d-benchmarks-nist/11-kellogg/CMakeLists.txt | 2 +- 2d-benchmarks-nist/11-kellogg/definitions.cpp | 2 +- 2d-benchmarks-nist/11-kellogg/main.cpp | 39 +- .../12-multiple-difficulties/CMakeLists.txt | 2 +- .../12-multiple-difficulties/definitions.cpp | 2 +- .../12-multiple-difficulties/lshape.mesh | 8 +- .../12-multiple-difficulties/main.cpp | 395 ++++++------------ 2d-benchmarks-nist/NIST-util.h | 236 +---------- 40 files changed, 1000 insertions(+), 1817 deletions(-) diff --git a/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt b/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt index 377166a..8230b32 100644 --- a/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt +++ b/2d-benchmarks-nist/01-analytic-solution/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-01) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.cpp b/2d-benchmarks-nist/01-analytic-solution/definitions.cpp index de6873b..950408b 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.cpp @@ -38,7 +38,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + (poly_deg*Hermes::pow(16.0, poly_deg)*B*D)/y)*A*C; } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(8); } diff --git a/2d-benchmarks-nist/01-analytic-solution/definitions.h b/2d-benchmarks-nist/01-analytic-solution/definitions.h index d36c039..13f80fd 100644 --- a/2d-benchmarks-nist/01-analytic-solution/definitions.h +++ b/2d-benchmarks-nist/01-analytic-solution/definitions.h @@ -32,7 +32,7 @@ class CustomExactSolution : public ExactSolutionScalar virtual void derivatives(double x, double y, double& dx, double& dy) const; - virtual Ord ord(double x, double y) const; + virtual Ord ord (double x, double y) const; MeshFunction* clone() const { return new CustomExactSolution(mesh, poly_deg); } double poly_deg; diff --git a/2d-benchmarks-nist/01-analytic-solution/main.cpp b/2d-benchmarks-nist/01-analytic-solution/main.cpp index f001a4d..ee4ab5b 100644 --- a/2d-benchmarks-nist/01-analytic-solution/main.cpp +++ b/2d-benchmarks-nist/01-analytic-solution/main.cpp @@ -30,19 +30,22 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; + int main(int argc, char* argv[]) { // Load the mesh. @@ -77,7 +80,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -97,7 +100,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -138,14 +141,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator errorCalculator(errorType, 1); - errorCalculator.calculate_errors(sln, exact_sln); - double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(sln, ref_sln); - double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -191,5 +194,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt b/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt index f843522..8c7a365 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt +++ b/2d-benchmarks-nist/02-reentrant-corner/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-02) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp b/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp index a74f014..0b0a509 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/definitions.cpp @@ -18,7 +18,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + ((alpha * y * Hermes::sin(alpha* get_angle(y, x)) * b)/a)); } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(10); } diff --git a/2d-benchmarks-nist/02-reentrant-corner/main.cpp b/2d-benchmarks-nist/02-reentrant-corner/main.cpp index cf2abd5..f3f83c6 100644 --- a/2d-benchmarks-nist/02-reentrant-corner/main.cpp +++ b/2d-benchmarks-nist/02-reentrant-corner/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -36,19 +35,21 @@ const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; // This is a stopping criterion for Adaptivity. -AdaptStoppingCriterionSingleElement* stoppingCriterion = new AdaptStoppingCriterionSingleElement(THRESHOLD); +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO_H; // Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -102,7 +103,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -122,7 +123,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -163,14 +164,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - DefaultErrorCalculator errorCalculator(errorType, 1); - errorCalculator.calculate_errors(sln, exact_sln); - double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(sln, ref_sln); - double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -216,5 +217,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt b/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt index 2835760..e6c5d3a 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt +++ b/2d-benchmarks-nist/03-linear-elasticity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-03) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp b/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp index be1917f..769a6aa 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/definitions.cpp @@ -216,7 +216,7 @@ void CustomExactSolutionU::derivatives (double x, double y, double& dx, double& D * r(x, y) * (lambda * (-1) * (lambda - 2) * Hermes::sin((lambda - 2) * get_angle(y, x)) * d_theta_dy(x, y)); } -Ord CustomExactSolutionU::ord(double x, double y) const +Ord CustomExactSolutionU::ord (double x, double y) const { return Ord(4.0); } @@ -426,7 +426,7 @@ void CustomExactSolutionV::derivatives (double x, double y, double& dx, double& D * r(x, y) * (lambda * (lambda - 2) * Hermes::cos((lambda - 2) * get_angle(y, x)) * d_theta_dy(x, y)); } -Ord CustomExactSolutionV::ord(double x, double y) const +Ord CustomExactSolutionV::ord (double x, double y) const { return Ord(4.0); } diff --git a/2d-benchmarks-nist/03-linear-elasticity/main.cpp b/2d-benchmarks-nist/03-linear-elasticity/main.cpp index 15100be..b1689f8 100644 --- a/2d-benchmarks-nist/03-linear-elasticity/main.cpp +++ b/2d-benchmarks-nist/03-linear-elasticity/main.cpp @@ -46,20 +46,22 @@ const int P_INIT_V = 2; const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.6; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; // Problem parameters. @@ -130,7 +132,7 @@ int main(int argc, char* argv[]) Hermes::vector >exact_slns(exact_u, exact_v); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView s_view_u("Solution for u", new WinGeom(0, 0, 440, 350)); @@ -154,7 +156,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreatorU(u_mesh); MeshSharedPtr ref_u_mesh = refMeshCreatorU.create_ref_mesh(); @@ -180,7 +182,6 @@ int main(int argc, char* argv[]) DiscreteProblem dp(&wf, ref_spaces); NewtonSolver newton(&dp); - newton.set_tolerance(1e-4, Hermes::Solvers::ResidualNormAbsolute); try { @@ -203,10 +204,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(spaces, ref_slns, slns); // Calculate element errors and total error estimate. - errorCalculator.calculate_errors(slns, exact_slns); - double err_exact_rel_total = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(slns, ref_slns); - double err_est_rel_total = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 2); + error_calculator.calculate_errors(slns, exact_slns); + double err_exact_rel_total = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(slns, ref_slns); + double err_est_rel_total = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(spaces, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -254,5 +259,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt b/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt index 02497f8..223c146 100644 --- a/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt +++ b/2d-benchmarks-nist/04-exponential-peak/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-04) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp index 9cddba3..4a13540 100644 --- a/2d-benchmarks-nist/04-exponential-peak/definitions.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/definitions.cpp @@ -4,7 +4,7 @@ double CustomRightHandSide::value(double x, double y) const { double a_P = (-alpha * Hermes::pow((x - x_loc), 2) - alpha * Hermes::pow((y - y_loc), 2)); - return -(4 * exp(a_P) * alpha * (alpha * (x - x_loc) * (x - x_loc) + return (4 * exp(a_P) * alpha * (alpha * (x - x_loc) * (x - x_loc) + alpha * (y - y_loc) * (y - y_loc) - 1)); } @@ -25,7 +25,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = -exp(a) * (2 * alpha * (y - y_loc)); } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(8); } diff --git a/2d-benchmarks-nist/04-exponential-peak/main.cpp b/2d-benchmarks-nist/04-exponential-peak/main.cpp index ce310d2..bf0abea 100644 --- a/2d-benchmarks-nist/04-exponential-peak/main.cpp +++ b/2d-benchmarks-nist/04-exponential-peak/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -21,41 +20,31 @@ using namespace RefinementSelectors; // This problem has and exponential peak in the interior of the domain. // (x_loc, y_loc) is the location of the peak, and alpha determines the strenghth of the peak. -double alpha = 10; +double alpha = 1000; double x_loc = 0.5; double y_loc = 0.5; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; - -// Error stop type. -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Maximum allowed level of hanging node s. +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; - -// Error stop value (in percent). -double ERR_STOP = 0.1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; int main(int argc, char* argv[]) { - Selector* refinement_selector; - AdaptivityStoppingCriterion* stoppingCriterion; - char* resultStringIdentification; - if(argc > 2) - resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); - else - { - refinement_selector = new MySelector(hXORpSelectionBasedOnError); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); - resultStringIdentification = "Custom"; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. mloader.load("square_quad.mesh", mesh); @@ -65,7 +54,6 @@ int main(int argc, char* argv[]) // Perform initial mesh refinements. for (int i = 0; irefine_all_elements(); - basemesh->copy(mesh); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha, x_loc, y_loc)); @@ -74,7 +62,8 @@ int main(int argc, char* argv[]) CustomRightHandSide f(alpha, x_loc, y_loc); // Initialize weak formulation. - WeakFormsH1::DefaultWeakFormPoissonLinear wf(HERMES_ANY, &f); + Hermes1DFunction lambda(1.0); + WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, &lambda, &f); // Initialize boundary conditions DefaultEssentialBCNonConst bc_essential("Bdy", exact_sln); @@ -85,235 +74,123 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); - MeshFunctionSharedPtr ref_sln(new Solution()); + + // Initialize refinement selector. + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); - Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - - // Assemble the discrete problem. - LinearSolver linear_solver; - linear_solver.set_weak_formulation(&wf); - linear_solver.set_UMFPACK_output(true, false); + sview.show_mesh(false); + sview.fix_scale_width(50); + Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - // Adaptivity loop. - DefaultErrorCalculator errorCalculator(errorType, 1); - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - sprintf(filename, "%s.csv", resultStringIdentification); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "ErrorLevel" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "max_FactorizationSize" << ';' << - "total_PeakMemoryUsage" << ';' << - "total_Flops" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); - - int iterations_count = 10; - int error_levels_count = 5; - double error_stop = ERR_STOP; + // Assemble the discrete problem. + NewtonSolver newton; + newton.set_weak_formulation(&wf); + MeshFunctionSharedPtr ref_sln(new Solution()); - for(int iteration = 0; iteration < iterations_count; iteration++) + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); + cpu_time.tick(); + + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + newton.set_space(ref_space); + try { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - alpha = 10. + factor * 5000.; - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - - error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - - logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Alpha: %g%.", iteration, error_level, error_stop, factor, alpha); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - double total_PeakMemoryUsage = 0; - double total_Flops = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached; - double max_FactorizationSize = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - refinement_selector, - (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, - ref_sln, - cpu_time, - linear_solver, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops, - exact_sln)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - } - } - catch(std::exception& e) - { - logger.info(e.what()); - data << - iteration << ';' << - error_level << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << - std::endl; - continue; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - - cpu_time.tick(); - { - /* - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(linear_solver.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(linear_solver.get_space(0), filename); - */ - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - data << - iteration << ';' << - error_level << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - max_FactorizationSize << ';' << - total_PeakMemoryUsage << ';' << - total_Flops << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; - std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; - std::cout << "total_Flops: " << total_Flops << std::endl; - - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - + newton.solve(); } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(sln); + oview.show(space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_exact_rel < ERR_STOP) + done = true; + else + done = adaptivity.adapt(&selector); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); + + // Increase the counter of adaptivity steps. + if (done == false) + as++; } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - data.close(); + // Wait for all views to be closed. + Views::View::wait(); return 0; -} \ No newline at end of file +} diff --git a/2d-benchmarks-nist/05-battery/CMakeLists.txt b/2d-benchmarks-nist/05-battery/CMakeLists.txt index a9584dd..d428095 100644 --- a/2d-benchmarks-nist/05-battery/CMakeLists.txt +++ b/2d-benchmarks-nist/05-battery/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-05) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/05-battery/definitions.cpp b/2d-benchmarks-nist/05-battery/definitions.cpp index 3ab3235..b1214d3 100644 --- a/2d-benchmarks-nist/05-battery/definitions.cpp +++ b/2d-benchmarks-nist/05-battery/definitions.cpp @@ -380,5 +380,9 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string omega_1, std::string om WeakForm* CustomWeakFormPoisson::clone() const { - return new CustomWeakFormPoisson(*this); + return new CustomWeakFormPoisson(this->omega_1, this->omega_2, + this->omega_3, this->omega_4, + this->omega_5, this->bdy_left, + this->bdy_top, this->bdy_right, + this->bdy_bottom, this->mesh); } \ No newline at end of file diff --git a/2d-benchmarks-nist/05-battery/definitions.h b/2d-benchmarks-nist/05-battery/definitions.h index f3b2580..f0d9dc1 100644 --- a/2d-benchmarks-nist/05-battery/definitions.h +++ b/2d-benchmarks-nist/05-battery/definitions.h @@ -105,23 +105,23 @@ class CustomWeakFormPoisson : public WeakForm const std::string omega_4; const std::string omega_5; - double p_1; - double p_2; - double p_3; - double p_4; - double p_5; - - double q_1; - double q_2; - double q_3; - double q_4; - double q_5; - - double f_1; - double f_2; - double f_3; - double f_4; - double f_5; + const double p_1; + const double p_2; + const double p_3; + const double p_4; + const double p_5; + + const double q_1; + const double q_2; + const double q_3; + const double q_4; + const double q_5; + + const double f_1; + const double f_2; + const double f_3; + const double f_4; + const double f_5; // Boundary markers. const std::string bdy_left; @@ -130,15 +130,15 @@ class CustomWeakFormPoisson : public WeakForm const std::string bdy_bottom; // Boundary condition coefficients for the four sides. - double c_left; - double c_top; - double c_right; - double c_bottom; - - double g_n_left; - double g_n_top; - double g_n_right; - double g_n_bottom; + const double c_left; + const double c_top; + const double c_right; + const double c_bottom; + + const double g_n_left; + const double g_n_top; + const double g_n_right; + const double g_n_bottom; virtual WeakForm* clone() const; }; diff --git a/2d-benchmarks-nist/05-battery/main.cpp b/2d-benchmarks-nist/05-battery/main.cpp index 3307e32..c05fb7f 100644 --- a/2d-benchmarks-nist/05-battery/main.cpp +++ b/2d-benchmarks-nist/05-battery/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -20,53 +19,38 @@ using namespace RefinementSelectors; // The following parameters can be changed: // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. -double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Predefined list of element refinement candidates. -CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; + int main(int argc, char* argv[]) { - const char* THRESHOLD_STRING = "Custom"; - - if(argc > 2) - { - CAND_LIST = CandList(atoi(argv[1])); - THRESHOLD = threshold_values[atoi(argv[2])]; - THRESHOLD_STRING = thresholds[atoi(argv[2])]; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s-%s.log", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); - - double ERR_STOP = 1.; - - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("battery.mesh", mesh); - MeshView m; - m.show(mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); - basemesh->copy(mesh); - // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, P_INIT)); @@ -78,207 +62,139 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. ScalarView sview("Solution", new WinGeom(0, 0, 320, 600)); + sview.fix_scale_width(50); + sview.show_mesh(false); OrderView oview("Polynomial orders", new WinGeom(330, 0, 300, 600)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); - - sprintf(filename, "Results-%s-%s.csv", get_cand_list_str(CAND_LIST), THRESHOLD_STRING); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; - - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); - - int iterations_count = 8; - int error_levels_count = 5; - double error_stop = ERR_STOP; - - for(int iteration = 0; iteration < iterations_count; iteration++) + + // DOF and CPU convergence graphs initialization. + SimpleGraph graph_dof, graph_cpu; + + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; + + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as); + + // Time measurement. + cpu_time.tick(); + + // Construct globally refined mesh and setup fine mesh space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + // Initialize fine mesh problem. + Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); + DiscreteProblem dp(&wf, ref_space); + + NewtonSolver newton(&dp); + newton.set_verbose_output(true); + + // Perform Newton's iteration. + try + { + newton.solve(); + } + catch(Hermes::Exceptions::Exception e) { - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - - wf.p_1 = (25.0) * factor * factor; - wf.p_2 = (7.0) * factor; - wf.p_3 = (5.0) * factor; - wf.p_4 = (0.2) * factor; - wf.p_5 = (0.05) * factor; - - wf.q_1 = 25. - (25.0) * factor; - wf.q_2 = 0.8 - (0.8) * factor; - wf.q_3 = 0.0001 - (0.0001) * factor; - wf.q_4 = 0.2 - (0.2) * factor; - wf.q_5 = 0.05 - (0.05) * factor; - - /* - wf.c_left = factor; - wf.c_top = factor + 1.; - wf.c_right = factor + 2.; - wf.c_bottom = factor + 3.; - - wf.g_n_left(0.0), - wf.g_n_top(3.0), - wf.g_n_right(2.0), - wf.g_n_bottom(1.0) - */ - - newton.set_weak_formulation(&wf); - - logger.info("Iteration: %i-%i, Error level: %g, Factor: %g.", iteration, error_level, error_stop, factor); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - &selector, - is_p(CAND_LIST) ? 1 : 0, - ref_sln, - cpu_time, - newton, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - } - } - catch(std::exception& e) - { - data.close(); - return -1; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - cpu_time.tick(); - { - sprintf(filename, "Solution-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%s-%i-%i.vtk", get_cand_list_str(CAND_LIST), THRESHOLD_STRING, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - data << - iteration << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + } + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting fine mesh solution on coarse mesh."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Time measurement. + cpu_time.tick(); + + // VTK output. + if (VTK_VISUALIZATION) + { + // Output solution in VTK format. + Views::Linearizer lin; + char* title = new char[100]; + sprintf(title, "sln-%d.vtk", as); + lin.save_solution_vtk(sln, title, "Potential", false); + Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", title); + + // Output mesh and element orders in VTK format. + Views::Orderizer ord; + sprintf(title, "ord-%d.vtk", as); + ord.save_orders_vtk(space, title); + Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", title); + } + // View the coarse mesh solution and polynomial orders. + if (HERMES_VISUALIZATION) + { + sview.show(sln); + oview.show(space); + } + + // Skip visualization time. + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // Calculate element errors and total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%", space->get_num_dofs(), ref_space->get_num_dofs(), err_est_rel); + + // Add entry to DOF and CPU convergence graphs. + cpu_time.tick(); + graph_cpu.add_values(cpu_time.accumulated(), err_est_rel); + graph_cpu.save("conv_cpu_est.dat"); + graph_dof.add_values(space->get_num_dofs(), err_est_rel); + graph_dof.save("conv_dof_est.dat"); + + // Skip the time spent to save the convergence graphs. + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. + if (err_est_rel < ERR_STOP) + done = true; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(&selector); + + // Increase the counter of performed adaptivity steps. + if (done == false) + as++; } } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + + // Show the fine mesh solution - final result. + sview.set_title("Fine mesh solution"); + sview.show_mesh(false); + sview.show(ref_sln); + + // Wait for all views to be closed. + Views::View::wait(); - data.close(); return 0; -} \ No newline at end of file +} + diff --git a/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt b/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt index c857f90..3037101 100644 --- a/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt +++ b/2d-benchmarks-nist/06-boundary-layer/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-06) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp index d9bc3ec..17a114e 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.cpp @@ -30,7 +30,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy - (1 - exp(-(1 - x)/epsilon))*Hermes::cos(M_PI*(x + y))*exp(-(1 - y)/epsilon)/epsilon; } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(8); } @@ -39,7 +39,7 @@ Ord CustomExactSolution::ord(double x, double y) const CustomWeakForm::CustomWeakForm(CustomRightHandSide* f) : WeakForm(1) { // Jacobian. - add_matrix_form(new CustomMatrixFormVol(0, 0, f)); + add_matrix_form(new CustomMatrixFormVol(0, 0, f->epsilon)); // Residual. add_vector_form(new CustomVectorFormVol(0, f)); } @@ -51,7 +51,7 @@ Scalar CustomWeakForm::CustomMatrixFormVol::matrix_form(int n, double *wt, Func< Scalar val = Scalar(0); for (int i = 0; i < n; i++) { - val += wt[i] * f->epsilon * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]); + val += wt[i] * epsilon * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]); val += wt[i] * (2*u->dx[i] + u->dy[i]) * v->val[i]; } diff --git a/2d-benchmarks-nist/06-boundary-layer/definitions.h b/2d-benchmarks-nist/06-boundary-layer/definitions.h index dd7ca27..48b685b 100644 --- a/2d-benchmarks-nist/06-boundary-layer/definitions.h +++ b/2d-benchmarks-nist/06-boundary-layer/definitions.h @@ -50,8 +50,8 @@ class CustomWeakForm : public WeakForm class CustomMatrixFormVol : public MatrixFormVol { public: - CustomMatrixFormVol(int i, int j, CustomRightHandSide* f) - : MatrixFormVol(i, j), f(f) {}; + CustomMatrixFormVol(int i, int j, double epsilon) + : MatrixFormVol(i, j), epsilon(epsilon) {}; template Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, @@ -65,7 +65,7 @@ class CustomWeakForm : public WeakForm MatrixFormVol* clone() const; - CustomRightHandSide* f; + double epsilon; }; class CustomVectorFormVol : public VectorFormVol diff --git a/2d-benchmarks-nist/06-boundary-layer/main.cpp b/2d-benchmarks-nist/06-boundary-layer/main.cpp index f7ce606..3eedcd2 100644 --- a/2d-benchmarks-nist/06-boundary-layer/main.cpp +++ b/2d-benchmarks-nist/06-boundary-layer/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -21,52 +20,46 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -double eps = 1e1; +const double epsilon = 1e-1; // Initial polynomial degree of mesh elements. const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; - -// Error stop type. -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Maximum allowed level of hanging node s. +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; -// Error stop value (in percent). -double ERR_STOP = 0.1; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - Selector* refinement_selector; - AdaptivityStoppingCriterion* stoppingCriterion; - char* resultStringIdentification; - if(argc > 2) - resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); - else - { - refinement_selector = new MySelector(hXORpSelectionBasedOnError); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); - resultStringIdentification = "Custom"; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(); - basemesh->copy(mesh); - + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); + // Set exact solution. - MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, eps)); + MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, ::epsilon)); // Define right-hand side. - CustomRightHandSide f(eps); + CustomRightHandSide f(::epsilon); // Initialize weak formulation. CustomWeakForm wf(&f); @@ -79,230 +72,125 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); + MeshFunctionSharedPtr sln(new Solution()); + // Initialize refinement selector. + MySelector selector(CAND_LIST); + // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); + sview.show_mesh(false); + sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - - // Adaptivity loop. - DefaultErrorCalculator errorCalculator(errorType, 1); - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); - sprintf(filename, "%s.csv", resultStringIdentification); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "ErrorLevel" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "max_FactorizationSize" << ';' << - "total_PeakMemoryUsage" << ';' << - "total_Flops" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; - int iterations_count = 10; - int error_levels_count = 1; - double error_stop = ERR_STOP; - - for(int iteration = 0; iteration < iterations_count; iteration++) + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); + cpu_time.tick(); + + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + // Assemble the discrete problem. + DiscreteProblem dp(&wf, ref_space); + + NewtonSolver newton(&dp); + + + MeshFunctionSharedPtr ref_sln(new Solution()); + try { - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); - newton.set_tolerance(1e-5, Hermes::Solvers::ResidualNormAbsolute); - newton.set_UMFPACK_output(true, false); - - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - eps = 10. / std::pow(2, (iteration + 2)); - f.epsilon = eps; - ((CustomExactSolution*)exact_sln.get())->epsilon = eps; - - error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - - logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Epsilon: %g%.", iteration, error_level, error_stop, factor, eps); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - double total_PeakMemoryUsage = 0; - double total_Flops = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached; - double max_FactorizationSize = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - refinement_selector, - (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, - ref_sln, - cpu_time, - newton, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops, - exact_sln)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - } - } - catch(std::exception& e) - { - logger.info(e.what()); - data << - iteration << ';' << - error_level << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << - std::endl; - continue; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - - cpu_time.tick(); - { - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - data << - iteration << ';' << - error_level << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - max_FactorizationSize << ';' << - total_PeakMemoryUsage << ';' << - total_Flops << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; - std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; - std::cout << "total_Flops: " << total_Flops << std::endl; - - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - + newton.solve(); } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(sln); + oview.show(space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_exact_rel < ERR_STOP) + done = true; + else + done = adaptivity.adapt(&selector); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); + + // Increase the counter of adaptivity steps. + if (done == false) + as++; } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - data.close(); + // Wait for all views to be closed. + Views::View::wait(); return 0; -} \ No newline at end of file +} diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt b/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt index d377387..d030885 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt +++ b/2d-benchmarks-nist/07-boundary-line-singularity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-07) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp index 66891a5..441f4e0 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/definitions.cpp @@ -21,7 +21,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = 0; } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord((int)(alpha + 1)); } diff --git a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp index d8f0c86..9181215 100644 --- a/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp +++ b/2d-benchmarks-nist/07-boundary-line-singularity/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -24,36 +23,32 @@ using namespace RefinementSelectors; double alpha = 0.6; // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 1; - -// Error stop type. -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Maximum allowed level of hanging node s. +const int INIT_REF_NUM = 2; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; -// Error stop value (in percent). -double ERR_STOP = 0.1; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - Selector* refinement_selector; - AdaptivityStoppingCriterion* stoppingCriterion; - char* resultStringIdentification; - if(argc > 2) - resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); - else - { - refinement_selector = new MySelector(hXORpSelectionBasedOnError); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); - resultStringIdentification = "Custom"; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; // Quadrilaterals. mloader.load("square_quad.mesh", mesh); @@ -61,9 +56,7 @@ int main(int argc, char* argv[]) // mloader.load("square_tri.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(); - basemesh->copy(mesh); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); @@ -84,215 +77,124 @@ int main(int argc, char* argv[]) // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); - MeshFunctionSharedPtr ref_sln(new Solution()); + // Initialize refinement selector. + MySelector selector(CAND_LIST); + // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); + sview.show_mesh(false); + sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - - // Adaptivity loop. - DefaultErrorCalculator errorCalculator(errorType, 1); - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); - - sprintf(filename, "%s.csv", resultStringIdentification); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "ErrorLevel" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "max_FactorizationSize" << ';' << - "total_PeakMemoryUsage" << ';' << - "total_Flops" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - int iterations_count = 10; - int error_levels_count = 5; - double error_stop = ERR_STOP; + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; - for(int iteration = 0; iteration < iterations_count; iteration++) + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); + cpu_time.tick(); + + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + // Assemble the discrete problem. + DiscreteProblem dp(&wf, ref_space); + + NewtonSolver newton(&dp); + + + MeshFunctionSharedPtr ref_sln(new Solution()); + try { - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); - newton.set_UMFPACK_output(true, false); - - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - double factor = std::abs(std::sin( 0.5 * M_PI * std::pow((double)(iteration + 1) / (double)iterations_count, 4.0))); - alpha = 10. + factor * 5000.; - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - - error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - - logger.info("Iteration: %i-%i, Error level: %g, Factor: %g, Alpha: %g%.", iteration, error_level, error_stop, factor, alpha); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - double total_PeakMemoryUsage = 0; - double total_Flops = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached; - double max_FactorizationSize = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - refinement_selector, - 1, - ref_sln, - cpu_time, - newton, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops, - exact_sln)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - } - } - catch(std::exception& e) - { - data.close(); - return -1; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - - cpu_time.tick(); - { - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - data << - iteration << ';' << - error_level << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - max_FactorizationSize << ';' << - total_PeakMemoryUsage << ';' << - total_Flops << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; - std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; - std::cout << "total_Flops: " << total_Flops << std::endl; - - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - + newton.solve(); } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(sln); + oview.show(space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_exact_rel < ERR_STOP) + done = true; + else + done = adaptivity.adapt(&selector); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); + + // Increase the counter of adaptivity steps. + if (done == false) + as++; } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - data.close(); + // Wait for all views to be closed. + Views::View::wait(); return 0; -} \ No newline at end of file +} diff --git a/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt b/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt index 5894ecc..a59b81a 100644 --- a/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt +++ b/2d-benchmarks-nist/08-oscillatory/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-08) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.cpp b/2d-benchmarks-nist/08-oscillatory/definitions.cpp index 8234b8c..f541bd4 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.cpp +++ b/2d-benchmarks-nist/08-oscillatory/definitions.cpp @@ -39,7 +39,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy dy = -Hermes::cos(h) * h * h * y / r; } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(10); } @@ -48,7 +48,7 @@ Ord CustomExactSolution::ord(double x, double y) const CustomWeakForm::CustomWeakForm(CustomRightHandSide* f) : WeakForm(1) { // Jacobian. - add_matrix_form(new CustomMatrixFormVol(0, 0, f)); + add_matrix_form(new CustomMatrixFormVol(0, 0, f->alpha)); // Residual. add_vector_form(new CustomVectorFormVol(0, f)); } @@ -63,7 +63,7 @@ Scalar CustomWeakForm::CustomMatrixFormVol::matrix_form(int n, double *wt, Func< Scalar x = e->x[i]; Scalar y = e->y[i]; Scalar r = Hermes::sqrt(x*x + y*y); - Scalar h = 1/(f->alpha + r); + Scalar h = 1/(alpha + r); Scalar grad_u_grad_v = u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]; val += wt[i] * (grad_u_grad_v - Hermes::pow(h, 4) * u->val[i] * v->val[i]); } diff --git a/2d-benchmarks-nist/08-oscillatory/definitions.h b/2d-benchmarks-nist/08-oscillatory/definitions.h index 2fbcc01..4ac78b7 100644 --- a/2d-benchmarks-nist/08-oscillatory/definitions.h +++ b/2d-benchmarks-nist/08-oscillatory/definitions.h @@ -50,8 +50,8 @@ class CustomWeakForm : public WeakForm class CustomMatrixFormVol : public MatrixFormVol { public: - CustomMatrixFormVol(int i, int j, CustomRightHandSide* f) - : MatrixFormVol(i, j), f(f) {}; + CustomMatrixFormVol(int i, int j, double alpha) + : MatrixFormVol(i, j), alpha(alpha) {}; template Scalar matrix_form(int n, double *wt, Func *u_ext[], Func *u, @@ -65,7 +65,7 @@ class CustomWeakForm : public WeakForm MatrixFormVol* clone() const; - CustomRightHandSide* f; + double alpha; }; class CustomVectorFormVol : public VectorFormVol diff --git a/2d-benchmarks-nist/08-oscillatory/main.cpp b/2d-benchmarks-nist/08-oscillatory/main.cpp index 02c110c..411afa9 100644 --- a/2d-benchmarks-nist/08-oscillatory/main.cpp +++ b/2d-benchmarks-nist/08-oscillatory/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -21,46 +20,40 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -double alpha = 2. / M_PI; +const double alpha = 1/(10*M_PI); // Initial polynomial degree of mesh elements. -const int P_INIT = 2; +const int P_INIT = 2; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; - -// Error stop type. -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Maximum allowed level of hanging node s. +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.3; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; -// Error stop value (in percent). -double ERR_STOP = 1.0; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - Selector* refinement_selector; - AdaptivityStoppingCriterion* stoppingCriterion; - char* resultStringIdentification; - if(argc > 2) - resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); - else - { - refinement_selector = new MySelector(noSelectionH); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.4); - resultStringIdentification = "noSelectionH-Lower"; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("square_quad.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(); - basemesh->copy(mesh); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha)); @@ -79,233 +72,125 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); + MeshFunctionSharedPtr sln(new Solution()); + // Initialize refinement selector. + MySelector selector(CAND_LIST); + // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); + sview.show_mesh(false); + sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - // Adaptivity loop. - DefaultErrorCalculator errorCalculator(errorType, 1); - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - sprintf(filename, "%s.csv", resultStringIdentification); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "ErrorLevel" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "max_FactorizationSize" << ';' << - "total_PeakMemoryUsage" << ';' << - "total_Flops" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); - - int iterations_count = 10; - int error_levels_count = 5; - double error_stop = ERR_STOP; - - for(int iteration = 0; iteration < iterations_count; iteration++) + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); + cpu_time.tick(); + + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + // Assemble the discrete problem. + DiscreteProblem dp(&wf, ref_space); + + NewtonSolver newton(&dp); + + + MeshFunctionSharedPtr ref_sln(new Solution()); + try { - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); - newton.set_UMFPACK_output(true, false); - - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - alpha = (1. / M_PI) * std::pow(0.75, iteration); - f.alpha = alpha; - ((CustomExactSolution*)exact_sln.get())->alpha = alpha; - - error_stop = ERR_STOP / std::pow(4.0, (double)error_level); - - logger.info("Iteration: %i-%i, Error level: %g, Alpha: %g%.", iteration, error_level, error_stop, alpha); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - double total_PeakMemoryUsage = 0; - double total_Flops = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached; - double max_FactorizationSize = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - refinement_selector, - (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, - ref_sln, - cpu_time, - newton, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops, - exact_sln)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - } - } - catch(std::exception& e) - { - logger.info(e.what()); - data << - iteration << ';' << - error_level << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << - std::endl; - continue; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - - cpu_time.tick(); - { - sprintf(filename, "Solution-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - lin.save_solution_vtk(ref_sln, filename, "sln", false, 1, HERMES_EPS_LOW); - sprintf(filename, "Orders-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_orders_vtk(newton.get_space(0), filename); - sprintf(filename, "Mesh-%s-%i-%i.vtk", resultStringIdentification, error_level, iteration); - ord.save_mesh_vtk(newton.get_space(0), filename); - } - cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); - - data << - iteration << ';' << - error_level << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - max_FactorizationSize << ';' << - total_PeakMemoryUsage << ';' << - total_Flops << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; - std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; - std::cout << "total_Flops: " << total_Flops << std::endl; - - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - + newton.solve(); } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(sln); + oview.show(space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_exact_rel < ERR_STOP) + done = true; + else + done = adaptivity.adapt(&selector); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); + + // Increase the counter of adaptivity steps. + if (done == false) + as++; } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - data.close(); + // Wait for all views to be closed. + Views::View::wait(); return 0; } - diff --git a/2d-benchmarks-nist/09-wave-front/CMakeLists.txt b/2d-benchmarks-nist/09-wave-front/CMakeLists.txt index f185515..2756abc 100644 --- a/2d-benchmarks-nist/09-wave-front/CMakeLists.txt +++ b/2d-benchmarks-nist/09-wave-front/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-09) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index b757d6f..6964826 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -35,20 +34,22 @@ const int P_INIT = 1; const int INIT_REF_NUM = 2; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -123,7 +124,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -143,7 +144,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -184,10 +185,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - errorCalculator.calculate_errors(sln, exact_sln); - double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(sln, ref_sln); - double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -233,5 +238,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt b/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt index 01b2897..13369dc 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt +++ b/2d-benchmarks-nist/10-interior-line-singularity/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-10) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp index 92b2908..b28ecaa 100644 --- a/2d-benchmarks-nist/10-interior-line-singularity/main.cpp +++ b/2d-benchmarks-nist/10-interior-line-singularity/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" using namespace RefinementSelectors; @@ -31,20 +29,22 @@ const int P_INIT = 2; const int INIT_REF_NUM = 0; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -138,12 +138,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - errorCalculator.calculate_errors(sln, exact_sln); - double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(sln, ref_sln); - double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - adaptivity.set_space(space); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -189,5 +191,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/11-kellogg/CMakeLists.txt b/2d-benchmarks-nist/11-kellogg/CMakeLists.txt index 52ab58b..a78331d 100644 --- a/2d-benchmarks-nist/11-kellogg/CMakeLists.txt +++ b/2d-benchmarks-nist/11-kellogg/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-11) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/11-kellogg/definitions.cpp b/2d-benchmarks-nist/11-kellogg/definitions.cpp index 6964cf8..d00730e 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.cpp +++ b/2d-benchmarks-nist/11-kellogg/definitions.cpp @@ -54,7 +54,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy - (tau * Hermes::pow(r, tau) * Hermes::cos((M_PI/2. - rho)*tau) * Hermes::sin(tau*((-3.*M_PI)/2. - sigma + theta))*x/(r*r)); } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(6); } diff --git a/2d-benchmarks-nist/11-kellogg/main.cpp b/2d-benchmarks-nist/11-kellogg/main.cpp index 42af7b0..ae5e252 100644 --- a/2d-benchmarks-nist/11-kellogg/main.cpp +++ b/2d-benchmarks-nist/11-kellogg/main.cpp @@ -35,20 +35,22 @@ const int P_INIT = 2; const int INIT_REF_NUM = 1; // This is a quantitative parameter of Adaptivity. const double THRESHOLD = 0.3; -// Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); -// Stopping criterion for an adaptivity step. -AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); -// Adaptivity processor class. -Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + // Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_HP_ANISO_H; +// Maximum allowed level of hanging nodes. +const int MESH_REGULARITY = -1; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; // Newton tolerance const double NEWTON_TOLERANCE = 1e-6; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { @@ -77,7 +79,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr sln(new Solution()); // Initialize refinement selector. - MySelector selector(hXORpSelectionBasedOnError); + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); @@ -97,7 +99,7 @@ int main(int argc, char* argv[]) { cpu_time.tick(); - // Construct globally refined reference mesh and setup reference space. + // Construct globally refined reference mesh and setup reference space-> Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); @@ -138,12 +140,14 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - errorCalculator.calculate_errors(sln, exact_sln); - double err_exact_rel = errorCalculator.get_total_error_squared() * 100.0; - errorCalculator.calculate_errors(sln, ref_sln); - double err_est_rel = errorCalculator.get_total_error_squared() * 100.0; + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; - adaptivity.set_space(space); + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); cpu_time.tick(); Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); @@ -189,5 +193,8 @@ int main(int argc, char* argv[]) while (done == false); Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); -return 0; + + // Wait for all views to be closed. + Views::View::wait(); + return 0; } diff --git a/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt b/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt index cf12b3e..b1ffeac 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt +++ b/2d-benchmarks-nist/12-multiple-difficulties/CMakeLists.txt @@ -1,5 +1,5 @@ project(nist-12) -add_executable(${PROJECT_NAME} main.cpp ../NIST-util.cpp definitions.cpp) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp) set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp b/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp index 6be0dc1..1c15d71 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/definitions.cpp @@ -63,7 +63,7 @@ void CustomExactSolution::derivatives(double x, double y, double& dx, double& dy + (-1) * (1.0 / epsilon) * exp(-(1 + y) / epsilon); } -Ord CustomExactSolution::ord(double x, double y) const +Ord CustomExactSolution::ord (double x, double y) const { return Ord(10); } diff --git a/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh b/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh index 0f898f2..61d3ac9 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh +++ b/2d-benchmarks-nist/12-multiple-difficulties/lshape.mesh @@ -17,12 +17,12 @@ elements = [ boundaries = [ [ 2, 1, "Bdy" ], - [ 3, 2, "a" ], + [ 3, 2, "Bdy" ], [ 1, 0, "Bdy" ], - [ 4, 3, "a" ], - [ 5, 4, "a" ], + [ 4, 3, "Bdy" ], + [ 5, 4, "Bdy" ], [ 0, 7, "Bdy" ], - [ 6, 5, "a" ], + [ 6, 5, "Bdy" ], [ 7, 6, "Bdy" ] ] diff --git a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp index ab42e1d..a149e7c 100644 --- a/2d-benchmarks-nist/12-multiple-difficulties/main.cpp +++ b/2d-benchmarks-nist/12-multiple-difficulties/main.cpp @@ -1,4 +1,3 @@ - #include "definitions.h" using namespace RefinementSelectors; @@ -19,57 +18,48 @@ using namespace RefinementSelectors; // // The following parameters can be changed: -double omega_c = 3.0 * M_PI / 2.0; -double x_w = 0.0; -double y_w = -1.0 / 4.0; -double r_0 = 1.0 / 4.0; -double alpha_w = 200.0; -double x_p = 3.0 / 4.0; -double y_p = 2.0 / 4.0; -double alpha_p = 100.0; -double epsilon = 1.0 / 100.0; +const double omega_c = 3.0 * M_PI / 2.0; +const double x_w = 0.0; +const double y_w = -3.0 / 4.0; +const double r_0 = 3.0 / 4.0; +const double alpha_w = 200.0; +const double x_p = -Hermes::sqrt(5.0) / 4.0; +const double y_p = -1.0 / 4.0; +const double alpha_p = 1000.0; +const double epsilon = 1.0 / 100.0; // Initial polynomial degree of mesh elements. -int P_INIT = 1; +const int P_INIT = 2; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; - -// Error stop type. -const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; -// Maximum allowed level of hanging node s. +const int INIT_REF_NUM = 0; +// This is a quantitative parameter of Adaptivity. +const double THRESHOLD = 0.8; +// This is a stopping criterion for Adaptivity. +AdaptStoppingCriterionLevels stoppingCriterion(THRESHOLD); + +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Maximum allowed level of hanging nodes. const int MESH_REGULARITY = -1; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +const CalculatedErrorType errorType = RelativeErrorToGlobalNorm; + +// Newton tolerance +const double NEWTON_TOLERANCE = 1e-6; -// Error stop value (in percent). -double ERR_STOP = 0.05; +bool HERMES_VISUALIZATION = false; +bool VTK_VISUALIZATION = false; int main(int argc, char* argv[]) { - Selector* refinement_selector; - AdaptivityStoppingCriterion* stoppingCriterion; - char* resultStringIdentification; - if(argc > 2) - resultStringIdentification = process_arguments_main_comparison(argc, argv, refinement_selector, stoppingCriterion); - else - { - refinement_selector = new MySelector(hXORpSelectionBasedOnError); - stoppingCriterion = new AdaptStoppingCriterionSingleElement(0.5); - resultStringIdentification = "Custom"; - } - - sprintf(Hermes::Mixins::Loggable::staticLogFileName, "Logfile-%s.log", resultStringIdentification); - - if(argc > 2 && atoi(argv[1]) == 0) - P_INIT = 2; - // Load the mesh. - MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); + MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; mloader.load("lshape.mesh", mesh); // Perform initial mesh refinement. - for (int i = 0; i < INIT_REF_NUM; i++) - mesh->refine_all_elements(); - basemesh->copy(mesh); + for (int i = 0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); // Set exact solution. MeshFunctionSharedPtr exact_sln(new CustomExactSolution(mesh, alpha_w, alpha_p, x_w, y_w, r_0, omega_c, ::epsilon, x_p, y_p)); @@ -89,234 +79,125 @@ int main(int argc, char* argv[]) SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); // Initialize approximate solution. - MeshFunctionSharedPtr sln(new Solution), ref_sln(new Solution); + MeshFunctionSharedPtr sln(new Solution()); + + // Initialize refinement selector. + MySelector selector(CAND_LIST); // Initialize views. Views::ScalarView sview("Solution", new Views::WinGeom(0, 0, 440, 350)); + sview.show_mesh(false); + sview.fix_scale_width(50); Views::OrderView oview("Polynomial orders", new Views::WinGeom(450, 0, 420, 350)); - Linearizer lin; - Orderizer ord; - char* filename = new char[1000]; - - // Adaptivity loop. - DefaultErrorCalculator errorCalculator(errorType, 1); - Adapt adaptivity(space, &errorCalculator); - adaptivity.set_strategy(stoppingCriterion); - - sprintf(filename, "%s.csv", resultStringIdentification); - std::ofstream data(filename); - data.precision(10); - data.setf( std::ios::fixed, std::ios::floatfield ); - data << - "Iteration" << ';' << - "ErrorLevel" << ';' << - "CPUTime" << ';' << - "AdaptivitySteps" << ';' << - "dof_reached" << ';' << - "dof_cumulative" << ';' << - "total_cache_searches" << ';' << - "total_cache_record_found" << ';' << - "total_cache_record_found_reinit" << ';' << - "total_cache_record_not_found" << ';' << - "max_FactorizationSize" << ';' << - "total_PeakMemoryUsage" << ';' << - "total_Flops" << ';' << - "error_stop" << ';' << - "error_reached" << ';' << - "exact_error_reached" << - std::endl; - Hermes::Mixins::Loggable logger; - logger.set_verbose_output(true); + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est, graph_dof_exact, graph_cpu_exact; - int iterations_count = 10; - int error_levels_count = 1; - double error_stop = ERR_STOP; + // Time measurement. + Hermes::Mixins::TimeMeasurable cpu_time; - for(int iteration = 0; iteration < iterations_count; iteration++) + // Adaptivity loop: + int as = 1; bool done = false; + do { - for(int error_level = 0; error_level < error_levels_count; error_level++) + cpu_time.tick(); + + // Construct globally refined reference mesh and setup reference space-> + Mesh::ReferenceMeshCreator refMeshCreator(mesh); + MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreator(space, ref_mesh); + SpaceSharedPtr ref_space = refSpaceCreator.create_ref_space(); + int ndof_ref = ref_space->get_num_dofs(); + + Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d (%d DOF):", as, ndof_ref); + cpu_time.tick(); + + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + // Assemble the discrete problem. + DiscreteProblem dp(&wf, ref_space); + + NewtonSolver newton(&dp); + + + MeshFunctionSharedPtr ref_sln(new Solution()); + try { - // Assemble the discrete problem. - NewtonSolver newton; - newton.set_weak_formulation(&wf); - newton.set_UMFPACK_output(true, false); - - mesh->copy(basemesh); - space->set_uniform_order(P_INIT); - space->assign_dofs(); - - x_w = 0.0 - (iteration / 9.) * 0.05; - y_w = (-1.0 / 4.0) - (iteration / 9.) * 0.5; - r_0 = (1.0 / 4.0) + (iteration / 9.) * 0.5; - x_p = (3.0 / 4.0) + ((-Hermes::sqrt(5.0) / 4.0) - (3.0 / 4.0)) * (iteration / 9.); - y_p = (2.0 / 4.0) - (iteration / 9.) * 0.75; - - f.x_w = x_w; - ((CustomExactSolution*)exact_sln.get())->x_w = x_w; - f.y_w = y_w; - ((CustomExactSolution*)exact_sln.get())->y_w = y_w; - f.r_0 = r_0; - ((CustomExactSolution*)exact_sln.get())->r_0 = r_0; - f.x_p = x_p; - ((CustomExactSolution*)exact_sln.get())->x_p = x_p; - f.y_p = y_p; - ((CustomExactSolution*)exact_sln.get())->y_p = y_p; - - error_stop = ERR_STOP / std::pow(2.0, (double)error_level); - - logger.info("Iteration: %i-%i, Error level: %g%%.", iteration, error_level, error_stop); - - // Cumulative. - int dof_cumulative = 0; - int total_cache_searches = 0; - int total_cache_record_found = 0; - int total_cache_record_found_reinit = 0; - int total_cache_record_not_found = 0; - double total_PeakMemoryUsage = 0; - double total_Flops = 0; - - // Max. - int as = 1; - int dof_reached; - double error_reached; - double exact_error_reached; - double max_FactorizationSize = 0; - - // One step. - int cache_searches; - int cache_record_found; - int cache_record_found_reinit; - int cache_record_not_found; - double FactorizationSize; - double PeakMemoryUsage; - double Flops; - - // Time measurement. - Hermes::Mixins::TimeMeasurable cpu_time; - - // Tick. - cpu_time.tick(); - - try - { - while (!adaptive_step_single_space( - &logger, - mesh, - space, - sln, - refinement_selector, - (argc > 2 && atoi(argv[1]) == 0) ? 0 : 1, - ref_sln, - cpu_time, - newton, - sview, - oview, - errorCalculator, - adaptivity, - as, - error_stop, - error_reached, - dof_reached, - cache_searches, - cache_record_found, - cache_record_found_reinit, - cache_record_not_found, - exact_error_reached, - FactorizationSize, - PeakMemoryUsage, - Flops, - exact_sln)) - { - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - } - } - catch(std::exception& e) - { - logger.info(e.what()); - data << - iteration << ';' << - error_level << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << ';' << - -1. << - std::endl; - continue; - } - - dof_cumulative += dof_reached; - - total_cache_searches += cache_searches; - total_cache_record_found += cache_record_found; - total_cache_record_found_reinit += cache_record_found_reinit; - total_cache_record_not_found += cache_record_not_found; - - max_FactorizationSize = std::max(max_FactorizationSize, FactorizationSize); - total_PeakMemoryUsage += PeakMemoryUsage; - total_Flops += Flops; - - data << - iteration << ';' << - error_level << ';' << - cpu_time.accumulated() << ';' << - as - 1 << ';' << - dof_reached << ';' << - dof_cumulative << ';' << - total_cache_searches << ';' << - total_cache_record_found << ';' << - total_cache_record_found_reinit << ';' << - total_cache_record_not_found << ';' << - max_FactorizationSize << ';' << - total_PeakMemoryUsage << ';' << - total_Flops << ';' << - error_stop << ';' << - error_reached << ';' << - exact_error_reached << - std::endl; - - std::cout << std::endl << "Results:" << std::endl; - std::cout << "CPU time: " << cpu_time.accumulated_str() << std::endl; - std::cout << "Adaptivity steps: " << as - 1 << std::endl; - std::cout << "dof_reached: " << dof_reached << std::endl; - std::cout << "dof_cumulative: " << dof_cumulative << std::endl; - - std::cout << "total_cache_searches: " << total_cache_searches << std::endl; - std::cout << "total_cache_record_found: " << total_cache_record_found << std::endl; - std::cout << "total_cache_record_found_reinit: " << total_cache_record_found_reinit << std::endl; - std::cout << "total_cache_record_not_found: " << total_cache_record_not_found << std::endl; - - std::cout << "max_FactorizationSize: " << max_FactorizationSize << std::endl; - std::cout << "total_PeakMemoryUsage: " << total_PeakMemoryUsage << std::endl; - std::cout << "total_Flops: " << total_Flops << std::endl; - - - std::cout << "error_stop: " << error_stop << std::endl; - std::cout << "error_reached: " << error_reached << std::endl; - std::cout << "exact_error_reached: " << exact_error_reached << std::endl; - + newton.solve(); } + catch(Hermes::Exceptions::Exception e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Newton's iteration failed."); + }; + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solution(newton.get_sln_vector(), ref_space, ref_sln); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Solution: %g s", cpu_time.last()); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); + OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + + // Calculate element errors and total error estimate. + DefaultErrorCalculator error_calculator(errorType, 1); + error_calculator.calculate_errors(sln, exact_sln); + double err_exact_rel = error_calculator.get_total_error_squared() * 100.0; + error_calculator.calculate_errors(sln, ref_sln); + double err_est_rel = error_calculator.get_total_error_squared() * 100.0; + + Adapt adaptivity(space, &error_calculator); + adaptivity.set_strategy(&stoppingCriterion); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Error calculation: %g s", cpu_time.last()); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d", space->get_num_dofs(), ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("err_est_rel: %g%%, err_exact_rel: %g%%", err_est_rel, err_exact_rel); + + // Time measurement. + cpu_time.tick(); + double accum_time = cpu_time.accumulated(); + + // View the coarse mesh solution and polynomial orders. + sview.show(sln); + oview.show(space); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(space->get_num_dofs(), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(accum_time, err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + graph_dof_exact.add_values(space->get_num_dofs(), err_exact_rel); + graph_dof_exact.save("conv_dof_exact.dat"); + graph_cpu_exact.add_values(accum_time, err_exact_rel); + graph_cpu_exact.save("conv_cpu_exact.dat"); + + cpu_time.tick(Hermes::Mixins::TimeMeasurable::HERMES_SKIP); + + // If err_est too large, adapt the mesh. The NDOF test must be here, so that the solution may be visualized + // after ending due to this criterion. + if (err_exact_rel < ERR_STOP) + done = true; + else + done = adaptivity.adapt(&selector); + + cpu_time.tick(); + Hermes::Mixins::Loggable::Static::info("Adaptation: %g s", cpu_time.last()); + + // Increase the counter of adaptivity steps. + if (done == false) + as++; } + while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); - data.close(); + // Wait for all views to be closed. + Views::View::wait(); return 0; -} \ No newline at end of file +} diff --git a/2d-benchmarks-nist/NIST-util.h b/2d-benchmarks-nist/NIST-util.h index f3bd05b..86b8aa0 100644 --- a/2d-benchmarks-nist/NIST-util.h +++ b/2d-benchmarks-nist/NIST-util.h @@ -1,241 +1,33 @@ -#ifndef __NIST_UTIL_H -#define __NIST_UTIL_H - #include "hermes2d.h" using namespace Hermes::Hermes2D; using namespace Hermes::Hermes2D::Views; using namespace Hermes::Hermes2D::RefinementSelectors; -extern const char* thresholds[7]; -extern const double threshold_values[7]; - -enum hpAdaptivityStrategy -{ - noSelectionH = 0, - noSelectionHP = 1, - hXORpSelectionBasedOnError = 2, - hORpSelectionBasedOnDOFs = 3, - isoHPSelectionBasedOnDOFs = 4, - anisoHPSelectionBasedOnDOFs = 5 -}; -extern const char* strategies[6]; - class MySelector : public H1ProjBasedSelector { public: - MySelector(hpAdaptivityStrategy strategy) : H1ProjBasedSelector(cand_list), strategy(strategy) + MySelector(CandList cand_list) : H1ProjBasedSelector(cand_list) { - if(strategy == hXORpSelectionBasedOnError) - { - //this->set_error_weights(1.0,1.0,1.0); - } } private: - bool select_refinement(Element* element, int order, MeshFunction* rsln, ElementToRefine& refinement) - { - switch(strategy) - { - case(noSelectionH): - { - refinement.split = H2D_REFINEMENT_H; - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = - order; - ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); - return true; - } - break; - case(noSelectionHP): - { - int max_allowed_order = this->max_order; - if(this->max_order == H2DRS_DEFAULT_ORDER) - max_allowed_order = H2DRS_MAX_ORDER; - int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); - int increased_order_h = std::min(max_allowed_order, order_h + 1), increased_order_v = std::min(max_allowed_order, order_v + 1); - int increased_order; - if(element->is_triangle()) - increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_h); - else - increased_order = refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = H2D_MAKE_QUAD_ORDER(increased_order_h, increased_order_v); - - refinement.split = H2D_REFINEMENT_H; - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][0] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][1] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][2] = - refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H][3] = - increased_order; - ElementToRefine::copy_orders(refinement.refinement_polynomial_order, refinement.best_refinement_polynomial_order_type[H2D_REFINEMENT_H]); - return true; - } - case(hXORpSelectionBasedOnError): - { - //make an uniform order in a case of a triangle - int order_h = H2D_GET_H_ORDER(order), order_v = H2D_GET_V_ORDER(order); - - int current_min_order, current_max_order; - this->get_current_order_range(element, current_min_order, current_max_order); - - if(current_max_order < std::max(order_h, order_v)) - current_max_order = std::max(order_h, order_v); - - int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); - int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); - - //build candidates. - Hermes::vector candidates; - candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); - candidates.push_back(Cand(H2D_REFINEMENT_H, order, order, order, order)); - - this->evaluate_cands_error(candidates, element, rsln); - - Cand* best_candidate = (candidates[0].error < candidates[1].error) ? &candidates[0] : &candidates[1]; - Cand* best_candidates_specific_type[4]; - best_candidates_specific_type[H2D_REFINEMENT_P] = &candidates[0]; - best_candidates_specific_type[H2D_REFINEMENT_H] = &candidates[1]; - best_candidates_specific_type[2] = NULL; - best_candidates_specific_type[3] = NULL; - - //copy result to output - refinement.split = best_candidate->split; - ElementToRefine::copy_orders(refinement.refinement_polynomial_order, best_candidate->p); - for(int i = 0; i < 4; i++) - if(best_candidates_specific_type[i] != NULL) - ElementToRefine::copy_orders(refinement.best_refinement_polynomial_order_type[i], best_candidates_specific_type[i]->p); - - ElementToRefine::copy_errors(refinement.errors, best_candidate->errors); - - //modify orders in a case of a triangle such that order_v is zero - if(element->is_triangle()) - for(int i = 0; i < H2D_MAX_ELEMENT_SONS; i++) - refinement.refinement_polynomial_order[i] = H2D_MAKE_QUAD_ORDER(H2D_GET_H_ORDER(refinement.refinement_polynomial_order[i]), 0); - - return true; - } - default: - H1ProjBasedSelector::select_refinement(element, order, rsln, refinement); - return true; - break; - } - } - - Hermes::vector create_candidates(Element* e, int quad_order) - { - Hermes::vector candidates; - - // Get the current order range. - int current_min_order, current_max_order; - this->get_current_order_range(e, current_min_order, current_max_order); - - int order_h = H2D_GET_H_ORDER(quad_order), order_v = H2D_GET_V_ORDER(quad_order); - - if(current_max_order < std::max(order_h, order_v)) - current_max_order = std::max(order_h, order_v); - - int last_order_h = std::min(current_max_order, order_h + 1), last_order_v = std::min(current_max_order, order_v + 1); - int last_order = H2D_MAKE_QUAD_ORDER(last_order_h, last_order_v); - - switch(strategy) - { - case(hORpSelectionBasedOnDOFs): - { - candidates.push_back(Cand(H2D_REFINEMENT_P, quad_order)); - } - case(hXORpSelectionBasedOnError): - { - candidates.push_back(Cand(H2D_REFINEMENT_P, last_order)); - candidates.push_back(Cand(H2D_REFINEMENT_H, quad_order, quad_order, quad_order, quad_order)); - return candidates; - } - break; - case(isoHPSelectionBasedOnDOFs): - { - this->cand_list = H2D_HP_ISO; - return H1ProjBasedSelector::create_candidates(e, quad_order); - } - break; - case(anisoHPSelectionBasedOnDOFs): - { - this->cand_list = H2D_HP_ANISO; - return H1ProjBasedSelector::create_candidates(e, quad_order); - } - break; - } - } - void evaluate_cands_score(Hermes::vector& candidates, Element* e) { - switch(strategy) + //calculate score of candidates + Cand& unrefined = candidates[0]; + const int num_cands = (int)candidates.size(); + unrefined.score = 0; + + for (int i = 1; i < num_cands; i++) { - case(hXORpSelectionBasedOnError): + Cand& cand = candidates[i]; + if(cand.error < unrefined.error) { - if(candidates[0].error > candidates[1].error) - { - candidates[0].score = 0.0; - candidates[1].score = 1.0; - } - else - { - candidates[1].score = 0.0; - candidates[0].score = 1.0; - } - } - break; - default: - { - //calculate score of candidates - Cand& unrefined = candidates[0]; - const int num_cands = (int)candidates.size(); - unrefined.score = 0; - - for (int i = 1; i < num_cands; i++) - { - Cand& cand = candidates[i]; - if(cand.error < unrefined.error) - { - double delta_dof = cand.dofs - unrefined.dofs; - candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; - } - else - candidates[i].score = 0; - } + double delta_dof = cand.dofs - unrefined.dofs; + candidates[i].score = (log10(unrefined.error) - log10(cand.error)) / delta_dof; } + else + candidates[i].score = 0; } } - - int strategy; -}; - -char* process_arguments_main_comparison(int argc, char* argv[], Selector*& selector, AdaptivityStoppingCriterion*& stoppingCriterion); - -bool adaptive_step_single_space( - Hermes::Mixins::Loggable* logger, - MeshSharedPtr& mesh, - SpaceSharedPtr& space, - MeshFunctionSharedPtr& sln, - Selector* selector, - unsigned int order_increase, - MeshFunctionSharedPtr& ref_sln, - Hermes::Mixins::TimeMeasurable& cpu_time, - Solver& solver, - Views::ScalarView& sview, - Views::OrderView & oview, - ErrorCalculator& errorCalculator, - Adapt& adaptivity, - int& as, - double error_stop, - double& error_reached, - int& dof_reached, - int& cache_searches, - int& cache_record_found, - int& cache_record_found_reinit, - int& cache_record_not_found, - double& exact_error_reached, - double& FactorizationSize, - double& PeakMemoryUsage, - double& Flops, - MeshFunctionSharedPtr& exact_sln = MeshFunctionSharedPtr() - ); -#endif \ No newline at end of file +}; \ No newline at end of file From 0b7016f645b7ac23977f4d986a6c33595eedfa36 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 14 Oct 2013 23:49:26 +0200 Subject: [PATCH 52/64] Make the examples ready for release (except for Runge-Kutta). --- 1d/layer-boundary/definitions.cpp | 2 +- 1d/layer-boundary/definitions.h | 3 + 1d/layer-boundary/main.cpp | 2 +- 1d/moving-front/main.cpp | 4 +- 1d/system/main.cpp | 2 +- 2d-advanced/acoustics/horn-axisym/main.cpp | 1 + .../linear-advection-dg-adapt/main.cpp | 2 +- .../linear-advection-diffusion/main.cpp | 1 + .../elasticity-linear/bracket/main.cpp | 2 +- 2d-advanced/euler/CMakeLists.txt | 2 +- 2d-advanced/euler/euler-init-main-adapt.cpp | 8 +- 2d-advanced/euler/forward-step-adapt/main.cpp | 2 +- 2d-advanced/euler/forward-step/main.cpp | 7 +- 2d-advanced/euler/gamm-channel-adapt/main.cpp | 4 +- .../euler/heating-flow-coupling/main.cpp | 2 +- .../heating-induced-vortex-adapt/main.cpp | 5 +- .../euler/heating-induced-vortex/main.cpp | 4 +- .../euler/reflected-shock-adapt/main.cpp | 66 ++++++++++- 2d-advanced/euler/reflected-shock/main.cpp | 4 +- 2d-advanced/helmholtz/waveguide/main.cpp | 2 +- 2d-advanced/maxwell/magnetostatics/main.cpp | 2 +- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 2 +- .../maxwell/resonator-time-domain-I/main.cpp | 10 +- .../resonator-time-domain-II-ie/main.cpp | 2 +- .../resonator-time-domain-II-rk/main.cpp | 2 +- 2d-advanced/navier-stokes/bearing/main.cpp | 2 +- .../circular-obstacle-adapt/main.cpp | 104 ++++++++++-------- .../navier-stokes/circular-obstacle/main.cpp | 2 +- .../navier-stokes/driven-cavity/main.cpp | 24 ++-- .../navier-stokes/ns-heat-subdomains/main.cpp | 2 +- .../navier-stokes/rayleigh-benard/main.cpp | 2 +- .../np-poisson-timedep-adapt/main.cpp | 18 ++- 2d-advanced/neutronics/saphir/main.cpp | 4 +- 2d-advanced/richards/basic-ie-newton/main.cpp | 2 +- 2d-advanced/richards/basic-ie-picard/main.cpp | 2 +- .../richards/basic-rk-newton-adapt/main.cpp | 4 +- 2d-advanced/richards/basic-rk-newton/main.cpp | 2 +- .../richards/capillary-barrier-adapt/main.cpp | 24 ++-- .../schroedinger/gross-pitaevski/main.cpp | 2 +- 2d-advanced/wave-equation/wave-1/main.cpp | 8 +- .../layer-boundary/definitions.cpp | 2 +- .../layer-boundary/definitions.h | 3 + 2d-benchmarks-general/layer-boundary/main.cpp | 6 +- .../layer-interior/definitions.h | 2 + 2d-benchmarks-general/layer-interior/main.cpp | 4 +- 2d-benchmarks-general/lshape/definitions.h | 2 + 2d-benchmarks-general/lshape/main.cpp | 5 +- .../moving-front-space-adapt/main.cpp | 4 +- .../nonsym-check/definitions.cpp | 2 +- 2d-benchmarks-general/nonsym-check/main.cpp | 8 +- .../smooth-aniso-x/definitions.h | 2 + 2d-benchmarks-general/smooth-aniso-x/main.cpp | 5 +- .../smooth-aniso-y/definitions.h | 2 + 2d-benchmarks-general/smooth-aniso-y/main.cpp | 5 +- .../smooth-iso/definitions.h | 2 + 2d-benchmarks-general/smooth-iso/main.cpp | 5 +- 56 files changed, 243 insertions(+), 161 deletions(-) diff --git a/1d/layer-boundary/definitions.cpp b/1d/layer-boundary/definitions.cpp index 278f226..1278342 100644 --- a/1d/layer-boundary/definitions.cpp +++ b/1d/layer-boundary/definitions.cpp @@ -15,7 +15,7 @@ double CustomExactFunction::dduhat_dxx(double x) return -K*K * (exp(K*x) + exp(-K*x)) / (exp(K) + exp(-K)); } -CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh, double K) : ExactSolutionScalar(mesh) +CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh, double K) : ExactSolutionScalar(mesh), K(K) { cef = new CustomExactFunction(K); } diff --git a/1d/layer-boundary/definitions.h b/1d/layer-boundary/definitions.h index 4dc92c2..3949161 100644 --- a/1d/layer-boundary/definitions.h +++ b/1d/layer-boundary/definitions.h @@ -33,9 +33,12 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (double x, double y) const; + MeshFunction* clone() const { return new CustomExactSolution(this->mesh, this->K); } + ~CustomExactSolution(); CustomExactFunction* cef; + double K; }; /* Custom function */ diff --git a/1d/layer-boundary/main.cpp b/1d/layer-boundary/main.cpp index d26e95e..3dd8806 100644 --- a/1d/layer-boundary/main.cpp +++ b/1d/layer-boundary/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; diff --git a/1d/moving-front/main.cpp b/1d/moving-front/main.cpp index 6b35048..37cfb8f 100644 --- a/1d/moving-front/main.cpp +++ b/1d/moving-front/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -50,7 +50,7 @@ const CandList CAND_LIST = H2D_HP_ANISO; const double ERR_STOP = 1e-1; // Newton's method -// Stopping criterion for Newton on fine mesh-> +// Stopping criterion for Newton on fine mesh. const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; diff --git a/1d/system/main.cpp b/1d/system/main.cpp index 3269352..4e100ce 100644 --- a/1d/system/main.cpp +++ b/1d/system/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; diff --git a/2d-advanced/acoustics/horn-axisym/main.cpp b/2d-advanced/acoustics/horn-axisym/main.cpp index 603395e..8c5ffee 100644 --- a/2d-advanced/acoustics/horn-axisym/main.cpp +++ b/2d-advanced/acoustics/horn-axisym/main.cpp @@ -138,6 +138,7 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + errorCalculator.calculate_errors(sln, ref_sln); double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp index 3b1ea19..4e8f0bc 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-dg-adapt/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example solves a linear advection equation using Dicontinuous Galerkin (DG) method. diff --git a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp index 5da8585..385f98c 100644 --- a/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp +++ b/2d-advanced/advection-diffusion-reaction/linear-advection-diffusion/main.cpp @@ -134,6 +134,7 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); adaptivity.set_space(space); + errorCalculator.calculate_errors(sln, ref_sln); double err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index a4b68ad..9c56c13 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example uses adaptive multimesh hp-FEM to solve a simple problem diff --git a/2d-advanced/euler/CMakeLists.txt b/2d-advanced/euler/CMakeLists.txt index 35b91aa..8e293db 100644 --- a/2d-advanced/euler/CMakeLists.txt +++ b/2d-advanced/euler/CMakeLists.txt @@ -12,5 +12,5 @@ add_subdirectory(heating-induced-vortex-adapt) # add_subdirectory(euler-coupled) # add_subdirectory(euler-coupled-adapt) -add_subdirectory(heating-flow-coupling) +#add_subdirectory(heating-flow-coupling) #add_subdirectory(heating-flow-coupling-adapt) \ No newline at end of file diff --git a/2d-advanced/euler/euler-init-main-adapt.cpp b/2d-advanced/euler/euler-init-main-adapt.cpp index a184742..0eef021 100644 --- a/2d-advanced/euler/euler-init-main-adapt.cpp +++ b/2d-advanced/euler/euler-init-main-adapt.cpp @@ -9,10 +9,10 @@ mesh->refine_all_elements(0, true); // Initialize boundary condition types and spaces with default shapesets. - SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); - SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); - SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); - SpaceSharedPtr space_e(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT)); Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); int ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); diff --git a/2d-advanced/euler/forward-step-adapt/main.cpp b/2d-advanced/euler/forward-step-adapt/main.cpp index a1b896e..f96a4aa 100644 --- a/2d-advanced/euler/forward-step-adapt/main.cpp +++ b/2d-advanced/euler/forward-step-adapt/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; diff --git a/2d-advanced/euler/forward-step/main.cpp b/2d-advanced/euler/forward-step/main.cpp index 1aa899a..63c57bc 100644 --- a/2d-advanced/euler/forward-step/main.cpp +++ b/2d-advanced/euler/forward-step/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -42,9 +42,10 @@ const double NU_1 = 0.1; const double NU_2 = 0.1; // Initial polynomial degree. -const int P_INIT = 0; +// Do not change this. +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; +const int INIT_REF_NUM = 2; // Number of initial localized mesh refinements. const int INIT_REF_NUM_STEP = 2; // CFL value. diff --git a/2d-advanced/euler/gamm-channel-adapt/main.cpp b/2d-advanced/euler/gamm-channel-adapt/main.cpp index 5bb883e..be5eaf9 100644 --- a/2d-advanced/euler/gamm-channel-adapt/main.cpp +++ b/2d-advanced/euler/gamm-channel-adapt/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -67,7 +67,7 @@ const double THRESHOLD = 0.6; // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -CandList CAND_LIST = H2D_HP_ANISO; +CandList CAND_LIST = H2D_H_ISO; // Stopping criterion for adaptivity. double adaptivityErrorStop(int iteration) diff --git a/2d-advanced/euler/heating-flow-coupling/main.cpp b/2d-advanced/euler/heating-flow-coupling/main.cpp index 14a462e..7164328 100644 --- a/2d-advanced/euler/heating-flow-coupling/main.cpp +++ b/2d-advanced/euler/heating-flow-coupling/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; diff --git a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp index 1da9b43..7118421 100644 --- a/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex-adapt/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -41,7 +41,8 @@ double DISCONTINUITY_DETECTOR_PARAM = 1.0; const double NU_1 = 0.1; const double NU_2 = 0.1; -// Initial polynomial degree. +// Initial polynomial degree. +// Do not change. const int P_INIT = 0; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 1; diff --git a/2d-advanced/euler/heating-induced-vortex/main.cpp b/2d-advanced/euler/heating-induced-vortex/main.cpp index e9b3e0b..a0e758b 100644 --- a/2d-advanced/euler/heating-induced-vortex/main.cpp +++ b/2d-advanced/euler/heating-induced-vortex/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -19,7 +19,7 @@ const unsigned int EVERY_NTH_STEP = 1; // Initial polynomial degree. const int P_INIT = 0; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 5; +const int INIT_REF_NUM = 3; // Shock capturing. enum shockCapturingType diff --git a/2d-advanced/euler/reflected-shock-adapt/main.cpp b/2d-advanced/euler/reflected-shock-adapt/main.cpp index 89ea6c1..2b9db73 100644 --- a/2d-advanced/euler/reflected-shock-adapt/main.cpp +++ b/2d-advanced/euler/reflected-shock-adapt/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -122,7 +122,69 @@ const std::string BDY_INLET_LEFT = "4"; int main(int argc, char* argv[]) { -#include "../euler-init-main-adapt.cpp" +#pragma region 1. Load mesh and initialize spaces. + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load(MESH_FILENAME, mesh); + + // Perform initial mesh refinements. + for (int i = 0; i < INIT_REF_NUM; i++) + mesh->refine_all_elements(0, true); + + // Initialize boundary condition types and spaces with default shapesets. + SpaceSharedPtr space_rho(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_x(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_rho_v_y(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + SpaceSharedPtr space_e(new L2Space(mesh, P_INIT, new L2ShapesetTaylor)); + Hermes::vector > spaces(space_rho, space_rho_v_x, space_rho_v_y, space_e); + int ndof = Space::get_num_dofs(spaces); + Hermes::Mixins::Loggable::Static::info("ndof: %d", ndof); + #pragma endregion + + #pragma region 2. Initialize solutions. + MeshFunctionSharedPtr sln_rho(new Solution(mesh)); + MeshFunctionSharedPtr sln_rho_v_x(new Solution (mesh)); + MeshFunctionSharedPtr sln_rho_v_y(new Solution (mesh)); + MeshFunctionSharedPtr sln_e(new Solution (mesh)); + Hermes::vector > slns(sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e); + + MeshFunctionSharedPtr rsln_rho(new Solution(mesh)); + MeshFunctionSharedPtr rsln_rho_v_x(new Solution (mesh)); + MeshFunctionSharedPtr rsln_rho_v_y(new Solution (mesh)); + MeshFunctionSharedPtr rsln_e(new Solution (mesh)); + Hermes::vector > rslns(rsln_rho, rsln_rho_v_x, rsln_rho_v_y, rsln_e); + #pragma endregion + + #pragma region 3. Filters for visualization of Mach number, pressure + visualization setup. + MeshFunctionSharedPtr Mach_number(new MachNumberFilter(rslns, KAPPA)); + MeshFunctionSharedPtr pressure(new PressureFilter(rslns, KAPPA)); + + ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); + ScalarView Mach_number_view("Mach number", new WinGeom(650, 0, 600, 300)); + ScalarView eview("Error - density", new WinGeom(0, 330, 600, 300)); + ScalarView eview1("Error - momentum", new WinGeom(0, 660, 600, 300)); + OrderView order_view("Orders", new WinGeom(650, 330, 600, 300)); + #pragma endregion + + // Set up CFL calculation class. + CFLCalculation CFL(CFL_NUMBER, KAPPA); + + Vector* rhs_stabilization = create_vector(HermesCommonApi.get_integral_param_value(matrixSolverType)); + + #pragma region 4. Adaptivity setup. + // Initialize refinement selector. + L2ProjBasedSelector selector(CAND_LIST); + selector.set_dof_score_exponent(2.0); + + //selector.set_error_weights(1.0, 1.0, 1.0); + + // Error calculation. + DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); + // Stopping criterion for an adaptivity step. + AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); + Adapt adaptivity(spaces, &errorCalculator, &stoppingCriterion); + #pragma endregion // Set initial conditions. MeshFunctionSharedPtr prev_rho(new ConstantSolution(mesh, RHO_INIT)); diff --git a/2d-advanced/euler/reflected-shock/main.cpp b/2d-advanced/euler/reflected-shock/main.cpp index baad2d5..7459cfc 100644 --- a/2d-advanced/euler/reflected-shock/main.cpp +++ b/2d-advanced/euler/reflected-shock/main.cpp @@ -1,5 +1,5 @@ #define HERMES_REPORT_INFO -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -36,7 +36,7 @@ enum shockCapturingType KRIVODONOVA }; bool SHOCK_CAPTURING = true; -shockCapturingType SHOCK_CAPTURING_TYPE = KUZMIN; +shockCapturingType SHOCK_CAPTURING_TYPE = KRIVODONOVA; // Quantitative parameter of the discontinuity detector in case of Krivodonova. double DISCONTINUITY_DETECTOR_PARAM = 1.0; // Quantitative parameter of the shock capturing in case of Feistauer. diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index 6c95657..0c1e93c 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example shows how to model harmonic steady state in parallel plate waveguide. diff --git a/2d-advanced/maxwell/magnetostatics/main.cpp b/2d-advanced/maxwell/magnetostatics/main.cpp index 76155aa..1832d15 100644 --- a/2d-advanced/maxwell/magnetostatics/main.cpp +++ b/2d-advanced/maxwell/magnetostatics/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example shows how to set an arbitrary initial guess for the diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 061af83..6810bc4 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example is a simple test case for the Debye-Maxwell model solved in terms of diff --git a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp index a27d915..f66bb39 100644 --- a/2d-advanced/maxwell/resonator-time-domain-I/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-I/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example shows how to discretize the first-order time-domain Maxwell's equations @@ -25,10 +23,7 @@ const int INIT_REF_NUM = 1; // Time step. const double time_step = 0.05; // Final time. -const double T_FINAL = 35.0; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double T_FINAL = 35.0; // Choose one of the following time-integration methods, or define your own Butcher's table. The last number // in the name of each method is its order. The one before last, if present, is the number of stages. @@ -82,7 +77,7 @@ int main(int argc, char* argv[]) EssentialBCs bcs_B; // Create x- and y- displacement space using the default H1 shapeset. - SpaceSharedPtr B_space(new HcurlSpace(mesh, &bcs_B, P_INIT)); + SpaceSharedPtr B_space(new H1Space(mesh, &bcs_B, P_INIT)); Hermes::vector > spaces(E_space, B_space); Hermes::vector > spaces_mutable(E_space, B_space); Hermes::Mixins::Loggable::Static::info("ndof = %d.", Space::get_num_dofs(spaces)); @@ -134,6 +129,7 @@ int main(int argc, char* argv[]) // Update time. current_time += time_step; + ts++; } while (current_time < T_FINAL); diff --git a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp index 7fbb2e0..210f228 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-ie/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example solves a time-domain resonator problem for the Maxwell's equation. diff --git a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp index a8d81a2..fbb67da 100644 --- a/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp +++ b/2d-advanced/maxwell/resonator-time-domain-II-rk/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example solves a time-domain resonator problem for the Maxwell's equation. diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index 95a2985..e890955 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // Flow in between two circles, inner circle is rotating with surface diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 60ce0c3..4bcdfe6 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // The time-dependent laminar incompressible Navier-Stokes equations are @@ -45,7 +45,7 @@ const int INIT_REF_NUM_BDY = 3; const int P_INIT_VEL = 2; // Initial polynomial degree for pressure. const int P_INIT_PRESSURE = 1; - + // Adaptivity // Every UNREF_FREQth time step the mesh is unrefined. const int UNREF_FREQ = 1; @@ -53,7 +53,15 @@ const int UNREF_FREQ = 1; // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 3); +class CustomErrorCalculator : public DefaultErrorCalculator +{ +public: + // Two first components are in the H1 space - we can use the classic class for that, for the last component, we will manually add the L2 norm for pressure. + CustomErrorCalculator(CalculatedErrorType errorType) : DefaultErrorCalculator(errorType, 2) + { + this->add_error_form(new DefaultNormFormVol(2, 2, HERMES_L2_NORM)); + } +} errorCalculator(RelativeErrorToGlobalNorm); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. @@ -61,9 +69,9 @@ Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_HP_ANISO; +const CandList CAND_LIST = H2D_H_ISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1e-3; // Problem parameters // Reynolds number. @@ -74,10 +82,10 @@ const double VEL_INLET = 1.0; // from 0 to VEL_INLET, then it stays constant. const double STARTUP_TIME = 1.0; // Time step. -const double TAU = 0.01; +const double TAU = 0.001; // Time interval length. const double T_FINAL = 30000.0; -// Stopping criterion for Newton on fine mesh-> +// Stopping criterion for Newton on fine mesh. const double NEWTON_TOL = 0.05; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; @@ -100,29 +108,31 @@ double current_time = 0; /*// Boundary condition values for x-velocity double essential_bc_values_xvel(double x, double y, double time) { - // time-dependent inlet velocity (parabolic profile) - double val_y = VEL_INLET * y*(H-y) / (H/2.)/(H/2.); //parabolic profile with peak VEL_INLET at y = H/2 - if (time <= STARTUP_TIME) return val_y * time/STARTUP_TIME; - else return val_y; +// time-dependent inlet velocity (parabolic profile) +double val_y = VEL_INLET * y*(H-y) / (H/2.)/(H/2.); //parabolic profile with peak VEL_INLET at y = H/2 +if (time <= STARTUP_TIME) return val_y * time/STARTUP_TIME; +else return val_y; } */ /* void mag(int n, double* a, double* dadx, double* dady, - double* b, double* dbdx, double* dbdy, - double* out, double* outdx, double* outdy) +double* b, double* dbdx, double* dbdy, +double* out, double* outdx, double* outdy) { - for (int i = 0; i < n; i++) - { - out[i] = sqrt(sqr(a[i]) + sqr(b[i])); - outdx[i] = (0.5 / out[i]) * (2.0 * a[i] * dadx[i] + 2.0 * b[i] * dbdx[i]); - outdy[i] = (0.5 / out[i]) * (2.0 * a[i] * dady[i] + 2.0 * b[i] * dbdy[i]); - } +for (int i = 0; i < n; i++) +{ +out[i] = sqrt(sqr(a[i]) + sqr(b[i])); +outdx[i] = (0.5 / out[i]) * (2.0 * a[i] * dadx[i] + 2.0 * b[i] * dbdx[i]); +outdy[i] = (0.5 / out[i]) * (2.0 * a[i] * dady[i] + 2.0 * b[i] * dbdy[i]); +} } */ int main(int argc, char* argv[]) { + HermesCommonApi.set_integral_param_value(numThreads, 1); + // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; @@ -145,8 +155,8 @@ int main(int argc, char* argv[]) DefaultEssentialBCConst bc_vel_y(Hermes::vector(BDY_LEFT, BDY_BOTTOM, BDY_TOP, BDY_OBSTACLE), 0.0); EssentialBCs bcs_vel_y(&bc_vel_y); -SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); -SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); + SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else @@ -177,7 +187,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); - + MeshFunctionSharedPtr xvel_sln(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_sln(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_sln(new ZeroSolution(mesh)); @@ -223,10 +233,10 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V yvel_space->assign_dofs(); p_space->assign_dofs(); } - + DiscreteProblem dp(&wf, spaces); Hermes::Hermes2D::NewtonSolver newton(&dp); - + // Spatial adaptivity loop. Note: xvel_prev_time, yvel_prev_time and pvel_prev_time // must not be changed during spatial adaptivity. bool done = false; int as = 1; @@ -239,27 +249,27 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V Mesh::ReferenceMeshCreator refMeshCreator(mesh); MeshSharedPtr ref_mesh = refMeshCreator.create_ref_mesh(); - Space::ReferenceSpaceCreator refSpaceCreatorX(xvel_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorX(xvel_space, ref_mesh, 0); SpaceSharedPtr ref_xvel_space = refSpaceCreatorX.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorY(yvel_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorY(yvel_space, ref_mesh, 0); SpaceSharedPtr ref_yvel_space = refSpaceCreatorY.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorP(p_space, ref_mesh); + Space::ReferenceSpaceCreator refSpaceCreatorP(p_space, ref_mesh, 0); SpaceSharedPtr ref_p_space = refSpaceCreatorP.create_ref_space(); Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); - // Calculate initial coefficient vector for Newton on the fine mesh-> + // Calculate initial coefficient vector for Newton on the fine mesh. double* coeff_vec = new double[Space::get_num_dofs(ref_spaces)]; if (ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh."); OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_sln, yvel_sln, p_sln), - coeff_vec); + coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time), - coeff_vec); + coeff_vec); } // Perform Newton's iteration. @@ -280,26 +290,34 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V // Update previous time level solutions. Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); - + // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); OGProjection ogProj; ogProj.project_global(Hermes::vector >(xvel_space, yvel_space, p_space), - Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), - Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); + Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), + Hermes::vector >(xvel_sln, yvel_sln, p_sln), + Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); adaptivity.set_spaces(Hermes::vector >(xvel_space, yvel_space, p_space)); errorCalculator.calculate_errors(Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); + Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), - Space::get_num_dofs(ref_spaces), err_est_rel_total); + Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), + Space::get_num_dofs(ref_spaces), err_est_rel_total); + + // Show the solution at the end of time step. + sprintf(title, "Velocity, time %g", TIME); + vview.set_title(title); + vview.show(xvel_ref_sln, yvel_ref_sln); + sprintf(title, "Pressure, time %g", TIME); + pview.set_title(title); + pview.show(p_ref_sln); // If err_est too large, adapt the mesh. if (err_est_rel_total < ERR_STOP) done = true; @@ -321,14 +339,6 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V xvel_prev_time->copy(xvel_ref_sln); yvel_prev_time->copy(yvel_ref_sln); p_prev_time->copy(p_ref_sln); - - // Show the solution at the end of time step. - sprintf(title, "Velocity, time %g", TIME); - vview.set_title(title); - vview.show(xvel_prev_time, yvel_prev_time, HERMES_EPS_LOW); - sprintf(title, "Pressure, time %g", TIME); - pview.set_title(title); - pview.show(p_prev_time); } ndof = Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)); diff --git a/2d-advanced/navier-stokes/circular-obstacle/main.cpp b/2d-advanced/navier-stokes/circular-obstacle/main.cpp index 6e01747..40df7b8 100644 --- a/2d-advanced/navier-stokes/circular-obstacle/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // The time-dependent laminar incompressible Navier-Stokes equations are diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index 7b4433e..3ca1c34 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // Flow inside a rotating circle. Both the flow and the circle are not moving @@ -51,9 +49,7 @@ const double T_FINAL = 3600.0; // Stopping criterion for the Newton's method. const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. -const int NEWTON_MAX_ITER = 10; // Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const int NEWTON_MAX_ITER = 10; // Current time (used in weak forms). double current_time = 0; @@ -93,8 +89,6 @@ double integrate_over_wall(MeshFunction* meshfn, int marker) int main(int argc, char* argv[]) { - - // Load the mesh. MeshSharedPtr mesh(new Mesh); MeshReaderH2D mloader; @@ -105,7 +99,7 @@ int main(int argc, char* argv[]) // Initial mesh refinements. for (int i=0; i < INIT_REF_NUM; i++) mesh->refine_all_elements(); mesh->refine_towards_boundary(Hermes::vector("Bdy-1", "Bdy-2", "Bdy-3", "Bdy-4"), - INIT_BDY_REF_NUM_INNER, false); // True for anisotropic refinement. + INIT_BDY_REF_NUM_INNER, false); // True for anisotropic refinement. // Initialize boundary conditions. EssentialBCNonConstX bc_vel_x(Hermes::vector("Bdy-1", "Bdy-2", "Bdy-3","Bdy-4"), VEL, STARTUP_TIME); @@ -113,8 +107,8 @@ int main(int argc, char* argv[]) EssentialBCs bcs_vel_x(&bc_vel_x); EssentialBCs bcs_vel_y(&bc_vel_y); -SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); -SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); + SpaceSharedPtr xvel_space(new H1Space(mesh, &bcs_vel_x, P_INIT_VEL)); + SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_VEL)); #ifdef PRESSURE_IN_L2 SpaceSharedPtr p_space(new L2Space(mesh, P_INIT_PRESSURE)); #else @@ -140,14 +134,11 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); Hermes::vector > slns_prev_time = - Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); + Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time); // Initialize weak formulation. WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); - // Initialize the FE problem. - DiscreteProblem dp(&wf, spaces); - // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 600, 500)); ScalarView pview("pressure [Pa]", new WinGeom(610, 0, 600, 500)); @@ -171,7 +162,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); - Hermes::Hermes2D::NewtonSolver newton(&dp); + Hermes::Hermes2D::NewtonSolver newton(&wf, spaces); try { newton.set_max_allowed_iterations(NEWTON_MAX_ITER); @@ -194,8 +185,7 @@ SpaceSharedPtr yvel_space(new H1Space(mesh, &bcs_vel_y, P_INIT_V sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); vview.show(xvel_prev_time, yvel_prev_time, HERMES_EPS_LOW*10); - - } + } // Wait for all views to be closed. View::wait(); diff --git a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp index dff99ea..57863e4 100644 --- a/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp +++ b/2d-advanced/navier-stokes/ns-heat-subdomains/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" diff --git a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp index 76dc800..ff5a30d 100644 --- a/2d-advanced/navier-stokes/rayleigh-benard/main.cpp +++ b/2d-advanced/navier-stokes/rayleigh-benard/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example solves the Rayleigh-Benard convection problem diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index 68d5822..448bb4d 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" #include "timestep_controller.h" @@ -107,7 +105,7 @@ const int TIME_DISCR = 2; // Stopping criterion for Newton on coarse mesh. const double NEWTON_TOL_COARSE = 0.01; -// Stopping criterion for Newton on fine mesh-> +// Stopping criterion for Newton on fine mesh. const double NEWTON_TOL_FINE = 0.05; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 100; @@ -165,10 +163,7 @@ double physVoltage(double phi) { double SCALED_INIT_TAU = scaleTime(INIT_TAU); - int main (int argc, char* argv[]) { - - // Load the mesh file. MeshSharedPtr C_mesh(new Mesh), phi_mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; @@ -302,7 +297,8 @@ int main (int argc, char* argv[]) { } C_space->set_uniform_order(P_INIT); phi_space->set_uniform_order(P_INIT); - + C_space->assign_dofs(); + phi_space->assign_dofs(); } // Adaptivity loop. Note: C_prev_time and Phi_prev_time must not be changed during spatial adaptivity. @@ -334,21 +330,21 @@ int main (int argc, char* argv[]) { NewtonSolver* solver = new NewtonSolver(dp); - // Calculate initial coefficient vector for Newton on the fine mesh-> + // Calculate initial coefficient vector for Newton on the fine mesh. if (as == 1 && pid.get_timestep_number() == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(C_sln, phi_sln), coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_spaces, Hermes::vector >(C_ref_sln, phi_ref_sln), coeff_vec); } - // Newton's loop on the fine mesh-> + // Newton's loop on the fine mesh. Hermes::Mixins::Loggable::Static::info("Solving on fine mesh:"); try { diff --git a/2d-advanced/neutronics/saphir/main.cpp b/2d-advanced/neutronics/saphir/main.cpp index 65019b5..a1f8f54 100644 --- a/2d-advanced/neutronics/saphir/main.cpp +++ b/2d-advanced/neutronics/saphir/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "hermes2d.h" using namespace Hermes; @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) int ndof_ref = ref_space->get_num_dofs(); // Initialize fine mesh problem. - Hermes::Mixins::Loggable::Static::info("Solving on fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Solving on fine mesh."); DiscreteProblem dp(&wf, ref_space); NewtonSolver newton(&dp); diff --git a/2d-advanced/richards/basic-ie-newton/main.cpp b/2d-advanced/richards/basic-ie-newton/main.cpp index 347933d..ee4ab5d 100644 --- a/2d-advanced/richards/basic-ie-newton/main.cpp +++ b/2d-advanced/richards/basic-ie-newton/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" diff --git a/2d-advanced/richards/basic-ie-picard/main.cpp b/2d-advanced/richards/basic-ie-picard/main.cpp index b39602a..ff3a9da 100644 --- a/2d-advanced/richards/basic-ie-picard/main.cpp +++ b/2d-advanced/richards/basic-ie-picard/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example is similar to basic-ie-newton except it uses the diff --git a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp index 33089ec..d4b90f0 100644 --- a/2d-advanced/richards/basic-rk-newton-adapt/main.cpp +++ b/2d-advanced/richards/basic-rk-newton-adapt/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example uses adaptivity with dynamical meshes to solve @@ -37,7 +35,7 @@ const double T_FINAL = 0.4; // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.5; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 4); +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. diff --git a/2d-advanced/richards/basic-rk-newton/main.cpp b/2d-advanced/richards/basic-rk-newton/main.cpp index 93f3f25..a1524bb 100644 --- a/2d-advanced/richards/basic-rk-newton/main.cpp +++ b/2d-advanced/richards/basic-rk-newton/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" diff --git a/2d-advanced/richards/capillary-barrier-adapt/main.cpp b/2d-advanced/richards/capillary-barrier-adapt/main.cpp index 7960bcb..689bcc6 100644 --- a/2d-advanced/richards/capillary-barrier-adapt/main.cpp +++ b/2d-advanced/richards/capillary-barrier-adapt/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example uses adaptivity with dynamical meshes to solve @@ -51,7 +51,7 @@ double time_step_max = 1.0; // Initial polynomial degree of all mesh elements. const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 0; +const int INIT_REF_NUM = 1; // Number of initial mesh refinements towards the top edge. const int INIT_REF_NUM_BDY_TOP = 0; @@ -74,7 +74,7 @@ Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. const CandList CAND_LIST = H2D_HP_ANISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-1; +const double ERR_STOP = 1e-2; // Constitutive relations. enum CONSTITUTIVE_RELATIONS { @@ -85,11 +85,11 @@ enum CONSTITUTIVE_RELATIONS { CONSTITUTIVE_RELATIONS constitutive_relations_type = CONSTITUTIVE_GENUCHTEN; // Newton's and Picard's methods. -// Stopping criterion for Newton on fine mesh-> +// Stopping criterion for Newton on fine mesh. const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. int NEWTON_MAX_ITER = 10; -// Stopping criterion for Picard on fine mesh-> +// Stopping criterion for Picard on fine mesh. const double PICARD_TOL = 1e-2; // Maximum allowed number of Picard iterations. int PICARD_MAX_ITER = 23; @@ -320,13 +320,13 @@ int main(int argc, char* argv[]) if(ITERATIVE_METHOD == 1) { double* coeff_vec = new double[ref_space->get_num_dofs()]; - // Calculate initial coefficient vector for Newton on the fine mesh-> + // Calculate initial coefficient vector for Newton on the fine mesh. if (as == 1 && ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_space, sln_prev_time, coeff_vec); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, coeff_vec); } @@ -349,6 +349,7 @@ int main(int argc, char* argv[]) // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); Hermes::Hermes2D::NewtonSolver newton(&dp); + newton.set_sufficient_improvement_factor(1.1); bool newton_converged = false; while(!newton_converged) { @@ -388,13 +389,13 @@ int main(int argc, char* argv[]) delete [] coeff_vec; } else { - // Calculate initial condition for Picard on the fine mesh-> + // Calculate initial condition for Picard on the fine mesh. if (as == 1 && ts == 1) { - Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain initial vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_space, sln_prev_time, sln_prev_iter); } else { - Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh->"); + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain initial vector on new fine mesh."); OGProjection ogProjection; ogProjection.project_global(ref_space, ref_sln, sln_prev_iter); } @@ -448,6 +449,7 @@ int main(int argc, char* argv[]) adaptivity.set_space(space); // Calculate error estimate wrt. fine mesh solution. + errorCalculator.calculate_errors(sln, ref_sln); err_est_rel = errorCalculator.get_total_error_squared() * 100; // Report results. diff --git a/2d-advanced/schroedinger/gross-pitaevski/main.cpp b/2d-advanced/schroedinger/gross-pitaevski/main.cpp index 2067992..84c61be 100644 --- a/2d-advanced/schroedinger/gross-pitaevski/main.cpp +++ b/2d-advanced/schroedinger/gross-pitaevski/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" // This example uses the Newton's method to solve a nonlinear complex-valued diff --git a/2d-advanced/wave-equation/wave-1/main.cpp b/2d-advanced/wave-equation/wave-1/main.cpp index ab6d6f8..0bb1432 100644 --- a/2d-advanced/wave-equation/wave-1/main.cpp +++ b/2d-advanced/wave-equation/wave-1/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example solves a simple linear wave equation by converting it @@ -29,10 +27,7 @@ const int P_INIT = 6; // Time step. const double time_step = 0.01; // Final time. -const double T_FINAL = 2.0; -// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, -// SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. -MatrixSolverType matrix_solver = SOLVER_UMFPACK; +const double T_FINAL = 2.0; // Choose one of the following time-integration methods, or define your own Butcher's table. The last number // in the name of each method is its order. The one before last, if present, is the number of stages. @@ -115,7 +110,6 @@ int main(int argc, char* argv[]) { runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); - runge_kutta.rk_time_step_newton(slns, slns); } catch(Exceptions::Exception& e) diff --git a/2d-benchmarks-general/layer-boundary/definitions.cpp b/2d-benchmarks-general/layer-boundary/definitions.cpp index e23eef8..ed04ab4 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.cpp +++ b/2d-benchmarks-general/layer-boundary/definitions.cpp @@ -15,7 +15,7 @@ double CustomExactFunction::dduhat_dxx(double x) return -K*K * (exp(K*x) + exp(-K*x)) / (exp(K) + exp(-K)); } -CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh,double K) : ExactSolutionScalar(mesh) +CustomExactSolution::CustomExactSolution(MeshSharedPtr mesh,double K) : ExactSolutionScalar(mesh), K(K) { cef = new CustomExactFunction(K); } diff --git a/2d-benchmarks-general/layer-boundary/definitions.h b/2d-benchmarks-general/layer-boundary/definitions.h index 4dc92c2..1163e62 100644 --- a/2d-benchmarks-general/layer-boundary/definitions.h +++ b/2d-benchmarks-general/layer-boundary/definitions.h @@ -35,7 +35,10 @@ class CustomExactSolution : public ExactSolutionScalar ~CustomExactSolution(); + MeshFunction* clone() const { return new CustomExactSolution(mesh, K); } + CustomExactFunction* cef; + double K; }; /* Custom function */ diff --git a/2d-benchmarks-general/layer-boundary/main.cpp b/2d-benchmarks-general/layer-boundary/main.cpp index 0b465e3..ed379c5 100644 --- a/2d-benchmarks-general/layer-boundary/main.cpp +++ b/2d-benchmarks-general/layer-boundary/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -30,7 +30,7 @@ const int INIT_REF_NUM_BDY = 5; const double THRESHOLD = 0.5; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. @@ -131,7 +131,7 @@ int main(int argc, char* argv[]) // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error."); - OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); + OGProjection::project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. adaptivity.set_space(space); diff --git a/2d-benchmarks-general/layer-interior/definitions.h b/2d-benchmarks-general/layer-interior/definitions.h index 4b70501..6f16ce3 100644 --- a/2d-benchmarks-general/layer-interior/definitions.h +++ b/2d-benchmarks-general/layer-interior/definitions.h @@ -19,6 +19,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual Ord ord (double x, double y) const; + MeshFunction* clone() const { return new CustomExactSolution(mesh, slope); } + double slope; }; diff --git a/2d-benchmarks-general/layer-interior/main.cpp b/2d-benchmarks-general/layer-interior/main.cpp index 02d7df2..4377899 100644 --- a/2d-benchmarks-general/layer-interior/main.cpp +++ b/2d-benchmarks-general/layer-interior/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -28,7 +28,7 @@ const int INIT_REF_NUM = 1; // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. diff --git a/2d-benchmarks-general/lshape/definitions.h b/2d-benchmarks-general/lshape/definitions.h index 2354936..2ec7b42 100644 --- a/2d-benchmarks-general/lshape/definitions.h +++ b/2d-benchmarks-general/lshape/definitions.h @@ -13,6 +13,8 @@ class CustomExactSolution : public ExactSolutionScalar { } + MeshFunction* clone() const { return new CustomExactSolution(mesh); } + virtual double value(double x, double y) const; virtual void derivatives(double x, double y, double& dx, double& dy) const; diff --git a/2d-benchmarks-general/lshape/main.cpp b/2d-benchmarks-general/lshape/main.cpp index 3499ff8..c8c164c 100644 --- a/2d-benchmarks-general/lshape/main.cpp +++ b/2d-benchmarks-general/lshape/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -61,6 +61,9 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + // Set the space to adaptivity. + adaptivity.set_space(space); + // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); diff --git a/2d-benchmarks-general/moving-front-space-adapt/main.cpp b/2d-benchmarks-general/moving-front-space-adapt/main.cpp index 48a5935..bde6764 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/main.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -51,7 +51,7 @@ const CandList CAND_LIST = H2D_HP_ANISO; const double ERR_STOP = 1e-1; // Newton's method -// Stopping criterion for Newton on fine mesh-> +// Stopping criterion for Newton on fine mesh. const double NEWTON_TOL = 1e-5; // Maximum allowed number of Newton iterations. const int NEWTON_MAX_ITER = 20; diff --git a/2d-benchmarks-general/nonsym-check/definitions.cpp b/2d-benchmarks-general/nonsym-check/definitions.cpp index 51435e6..316f6c2 100644 --- a/2d-benchmarks-general/nonsym-check/definitions.cpp +++ b/2d-benchmarks-general/nonsym-check/definitions.cpp @@ -18,7 +18,7 @@ Ord CustomExactSolution::ord(double x, double y) const MeshFunction* CustomExactSolution::clone() const { - return new CustomExactSolution(*this); + return new CustomExactSolution(this->mesh); } diff --git a/2d-benchmarks-general/nonsym-check/main.cpp b/2d-benchmarks-general/nonsym-check/main.cpp index e9310c3..aa62946 100644 --- a/2d-benchmarks-general/nonsym-check/main.cpp +++ b/2d-benchmarks-general/nonsym-check/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -25,7 +25,7 @@ int P_INIT = 1; // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.3; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 1); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. @@ -55,6 +55,9 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + // Set the space to adaptivity. + adaptivity.set_space(space); + // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); @@ -120,7 +123,6 @@ int main(int argc, char* argv[]) OGProjection ogProjection; ogProjection.project_global(space, ref_sln, sln); // Calculate element errors and total error estimate. - adaptivity.set_space(space); errorCalculator.calculate_errors(sln, exact_sln, false); double err_exact_rel = errorCalculator.get_total_error_squared() * 100; diff --git a/2d-benchmarks-general/smooth-aniso-x/definitions.h b/2d-benchmarks-general/smooth-aniso-x/definitions.h index 212a0d7..c8f9d29 100644 --- a/2d-benchmarks-general/smooth-aniso-x/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-x/definitions.h @@ -19,6 +19,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; virtual Ord ord (double x, double y) const; + + MeshFunction* clone() const { return new CustomExactSolution(mesh); } }; /* Custom function f */ diff --git a/2d-benchmarks-general/smooth-aniso-x/main.cpp b/2d-benchmarks-general/smooth-aniso-x/main.cpp index 5343047..8ea0814 100644 --- a/2d-benchmarks-general/smooth-aniso-x/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-x/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -54,6 +54,9 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + // Set it to adaptivity. + adaptivity.set_space(space); + // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); diff --git a/2d-benchmarks-general/smooth-aniso-y/definitions.h b/2d-benchmarks-general/smooth-aniso-y/definitions.h index e6f0c56..978acf0 100644 --- a/2d-benchmarks-general/smooth-aniso-y/definitions.h +++ b/2d-benchmarks-general/smooth-aniso-y/definitions.h @@ -19,6 +19,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; virtual Ord ord (double x, double y) const; + + MeshFunction* clone() const { return new CustomExactSolution(mesh); } }; /* Custom function f */ diff --git a/2d-benchmarks-general/smooth-aniso-y/main.cpp b/2d-benchmarks-general/smooth-aniso-y/main.cpp index 2c33f6c..d42d196 100644 --- a/2d-benchmarks-general/smooth-aniso-y/main.cpp +++ b/2d-benchmarks-general/smooth-aniso-y/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace RefinementSelectors; @@ -53,6 +53,9 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + + // Set it to adaptivity. + adaptivity.set_space(space); // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); diff --git a/2d-benchmarks-general/smooth-iso/definitions.h b/2d-benchmarks-general/smooth-iso/definitions.h index dabd06f..dc0bdef 100644 --- a/2d-benchmarks-general/smooth-iso/definitions.h +++ b/2d-benchmarks-general/smooth-iso/definitions.h @@ -18,6 +18,8 @@ class CustomExactSolution : public ExactSolutionScalar virtual double value(double x, double y) const; virtual Ord ord (double x, double y) const; + + MeshFunction* clone() const { return new CustomExactSolution(mesh); } }; /* Custom function f */ diff --git a/2d-benchmarks-general/smooth-iso/main.cpp b/2d-benchmarks-general/smooth-iso/main.cpp index d5a1219..f6cb4fc 100644 --- a/2d-benchmarks-general/smooth-iso/main.cpp +++ b/2d-benchmarks-general/smooth-iso/main.cpp @@ -1,5 +1,5 @@ -#define HERMES_REPORT_FILE "application.log" + #include "definitions.h" using namespace Hermes; @@ -63,6 +63,9 @@ int main(int argc, char* argv[]) // Create an H1 space with default shapeset. SpaceSharedPtr space(new H1Space(mesh, &bcs, P_INIT)); + + // Set it to adaptivity. + adaptivity.set_space(space); // Initialize approximate solution. MeshFunctionSharedPtr sln(new Solution()); From b8fe63886d7e22fc73f6ae097f94a7a20f8bdcf5 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 30 Oct 2013 13:16:28 +0100 Subject: [PATCH 53/64] Fix examples. --- 2d-advanced/euler/euler_util.cpp | 4 +- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 465 +++++++++--------- 2 files changed, 241 insertions(+), 228 deletions(-) diff --git a/2d-advanced/euler/euler_util.cpp b/2d-advanced/euler/euler_util.cpp index ba6770c..f7978a2 100644 --- a/2d-advanced/euler/euler_util.cpp +++ b/2d-advanced/euler/euler_util.cpp @@ -1190,7 +1190,7 @@ int FluxLimiter::limit_according_to_detector(Hermes::vectorset_element_order_internal(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, 0); + coarse_spaces_to_limit[space_i]->set_element_order(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, 0); } } } @@ -1263,7 +1263,7 @@ void FluxLimiter::limit_second_orders_according_to_detector(Hermes::vectorset_element_order_internal(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, H2D_MAKE_QUAD_ORDER(h_order_to_set, v_order_to_set)); + coarse_spaces_to_limit[space_i]->set_element_order(spaces[space_i]->get_mesh()->get_element(*it)->parent->id, H2D_MAKE_QUAD_ORDER(h_order_to_set, v_order_to_set)); } } } diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 6810bc4..83da156 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -24,17 +24,17 @@ // The following parameters can be changed: // Initial polynomial degree of mesh elements. -const int P_INIT = 1; +const int P_INIT = 1; // Number of initial uniform mesh refinements. -const int INIT_REF_NUM = 2; +const int INIT_REF_NUM = 2; // Time step. -const double time_step = 0.00001; +const double time_step = 0.00001; // Final time. -const double T_FINAL = 35.0; +const double T_FINAL = 35.0; // Stopping criterion for the Newton's method. -const double NEWTON_TOL = 1e-4; +const double NEWTON_TOL = 1e-4; // Maximum allowed number of Newton iterations. -const int NEWTON_MAX_ITER = 100; +const int NEWTON_MAX_ITER = 100; // Choose one of the following time-integration methods, or define your own Butcher's table. The last number // in the name of each method is its order. The one before last, if present, is the number of stages. @@ -59,13 +59,23 @@ const int UNREF_FREQ = 5; // Number of mesh refinements between two unrefinements. // The mesh is not unrefined unless there has been a refinement since // last unrefinement. -int REFINEMENT_COUNT = 0; +int REFINEMENT_COUNT = 0; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies (see below). const double THRESHOLD = 0.5; // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 3); +class CustomErrorCalculator : public ErrorCalculator +{ +public: + // Two first components are in the H1 space - we can use the classic class for that, for the last component, we will manually add the L2 norm for pressure. + CustomErrorCalculator(CalculatedErrorType errorType) : ErrorCalculator(errorType) + { + this->add_error_form(new DefaultNormFormVol(0, 0, HERMES_HCURL_NORM)); + this->add_error_form(new DefaultNormFormVol(1, 1, HERMES_H1_NORM)); + this->add_error_form(new DefaultNormFormVol(2, 2, HERMES_HCURL_NORM)); + } +} errorCalculator(RelativeErrorToGlobalNorm); // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. @@ -99,241 +109,244 @@ double K_y = 1.0; int main(int argc, char* argv[]) { - try - { - // Sanity check for omega. - double K_squared = Hermes::sqr(OMEGA/M_PI) * (OMEGA - 2) / (1 - OMEGA); - if (K_squared <= 0) throw Hermes::Exceptions::Exception("Wrong choice of omega, K_squared < 0!"); - double K_norm_coeff = std::sqrt(K_squared) / std::sqrt(Hermes::sqr(K_x) + Hermes::sqr(K_y)); - Hermes::Mixins::Loggable::Static::info("Wave number K = %g", std::sqrt(K_squared)); - K_x *= K_norm_coeff; - K_y *= K_norm_coeff; - - // Wave number. - double K = std::sqrt(Hermes::sqr(K_x) + Hermes::sqr(K_y)); - - // Choose a Butcher's table or define your own. - ButcherTable bt(butcher_table); - if (bt.is_explicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage explicit R-K method.", bt.get_size()); - if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); - if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); - - // Load the mesh. - MeshSharedPtr E_mesh(new Mesh), H_mesh(new Mesh), P_mesh(new Mesh); - MeshReaderH2D mloader; - mloader.load("domain.mesh", E_mesh); - mloader.load("domain.mesh", H_mesh); - mloader.load("domain.mesh", P_mesh); - - // Perform initial mesh refinemets. - for (int i = 0; i < INIT_REF_NUM; i++) - { - E_mesh->refine_all_elements(); - H_mesh->refine_all_elements(); - P_mesh->refine_all_elements(); - } - - // Initialize solutions. - double current_time = 0; - MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionE(E_mesh, current_time, OMEGA, K_x, K_y)); - MeshFunctionSharedPtr H_time_prev(new CustomInitialConditionH(H_mesh, current_time, OMEGA, K_x, K_y)); - MeshFunctionSharedPtr P_time_prev(new CustomInitialConditionP(P_mesh, current_time, OMEGA, K_x, K_y)); - Hermes::vector > slns_time_prev(E_time_prev, H_time_prev, P_time_prev); - MeshFunctionSharedPtr E_time_new(new Solution(E_mesh)), H_time_new(new Solution(H_mesh)), P_time_new(new Solution(P_mesh)); - MeshFunctionSharedPtr E_time_new_coarse(new Solution(E_mesh)), H_time_new_coarse(new Solution(H_mesh)), P_time_new_coarse(new Solution(P_mesh)); - Hermes::vector > slns_time_new(E_time_new, H_time_new, P_time_new); - - // Initialize the weak formulation. - CustomWeakFormMD wf(OMEGA, K_x, K_y, MU_0, EPS_0, EPS_INF, EPS_Q, TAU); - - // Initialize boundary conditions - DefaultEssentialBCConst bc_essential("Bdy", 0.0); - EssentialBCs bcs(&bc_essential); - - SpaceSharedPtr E_space(new HcurlSpace (E_mesh, &bcs, P_INIT)); - SpaceSharedPtr H_space(new H1Space (H_mesh, NULL, P_INIT)); - //L2Space H_space(mesh, P_INIT)); - SpaceSharedPtr P_space(new HcurlSpace(P_mesh, &bcs, P_INIT)); - - Hermes::vector > spaces = Hermes::vector >(E_space, H_space, P_space); - - // Initialize views. - ScalarView E1_view("Solution E1", new WinGeom(0, 0, 400, 350)); - E1_view.fix_scale_width(50); - ScalarView E2_view("Solution E2", new WinGeom(410, 0, 400, 350)); - E2_view.fix_scale_width(50); - ScalarView H_view("Solution H", new WinGeom(0, 410, 400, 350)); - H_view.fix_scale_width(50); - ScalarView P1_view("Solution P1", new WinGeom(410, 410, 400, 350)); - P1_view.fix_scale_width(50); - ScalarView P2_view("Solution P2", new WinGeom(820, 410, 400, 350)); - P2_view.fix_scale_width(50); - - // Visualize initial conditions. - char title[100]; - sprintf(title, "E1 - Initial Condition"); - E1_view.set_title(title); - E1_view.show(E_time_prev, H2D_FN_VAL_0); - sprintf(title, "E2 - Initial Condition"); - E2_view.set_title(title); - E2_view.show(E_time_prev, H2D_FN_VAL_1); - - sprintf(title, "H - Initial Condition"); - H_view.set_title(title); - H_view.show(H_time_prev); - - sprintf(title, "P1 - Initial Condition"); - P1_view.set_title(title); - P1_view.show(P_time_prev, H2D_FN_VAL_0); - sprintf(title, "P2 - Initial Condition"); - P2_view.set_title(title); - P2_view.show(P_time_prev, H2D_FN_VAL_1); - - // Initialize Runge-Kutta time stepping. - RungeKutta runge_kutta(&wf, spaces, &bt); + try + { + // Sanity check for omega. + double K_squared = Hermes::sqr(OMEGA / M_PI) * (OMEGA - 2) / (1 - OMEGA); + if (K_squared <= 0) throw Hermes::Exceptions::Exception("Wrong choice of omega, K_squared < 0!"); + double K_norm_coeff = std::sqrt(K_squared) / std::sqrt(Hermes::sqr(K_x) + Hermes::sqr(K_y)); + Hermes::Mixins::Loggable::Static::info("Wave number K = %g", std::sqrt(K_squared)); + K_x *= K_norm_coeff; + K_y *= K_norm_coeff; + + // Wave number. + double K = std::sqrt(Hermes::sqr(K_x) + Hermes::sqr(K_y)); + + // Choose a Butcher's table or define your own. + ButcherTable bt(butcher_table); + if (bt.is_explicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage explicit R-K method.", bt.get_size()); + if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size()); + if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size()); + + // Load the mesh. + MeshSharedPtr E_mesh(new Mesh), H_mesh(new Mesh), P_mesh(new Mesh); + MeshReaderH2D mloader; + mloader.load("domain.mesh", E_mesh); + mloader.load("domain.mesh", H_mesh); + mloader.load("domain.mesh", P_mesh); + + // Perform initial mesh refinemets. + for (int i = 0; i < INIT_REF_NUM; i++) + { + E_mesh->refine_all_elements(); + H_mesh->refine_all_elements(); + P_mesh->refine_all_elements(); + } + + // Initialize solutions. + double current_time = 0; + MeshFunctionSharedPtr E_time_prev(new CustomInitialConditionE(E_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr H_time_prev(new CustomInitialConditionH(H_mesh, current_time, OMEGA, K_x, K_y)); + MeshFunctionSharedPtr P_time_prev(new CustomInitialConditionP(P_mesh, current_time, OMEGA, K_x, K_y)); + Hermes::vector > slns_time_prev(E_time_prev, H_time_prev, P_time_prev); + MeshFunctionSharedPtr E_time_new(new Solution(E_mesh)), H_time_new(new Solution(H_mesh)), P_time_new(new Solution(P_mesh)); + MeshFunctionSharedPtr E_time_new_coarse(new Solution(E_mesh)), H_time_new_coarse(new Solution(H_mesh)), P_time_new_coarse(new Solution(P_mesh)); + Hermes::vector > slns_time_new(E_time_new, H_time_new, P_time_new); + + // Initialize the weak formulation. + CustomWeakFormMD wf(OMEGA, K_x, K_y, MU_0, EPS_0, EPS_INF, EPS_Q, TAU); + + // Initialize boundary conditions + DefaultEssentialBCConst bc_essential("Bdy", 0.0); + EssentialBCs bcs(&bc_essential); + + SpaceSharedPtr E_space(new HcurlSpace(E_mesh, &bcs, P_INIT)); + SpaceSharedPtr H_space(new H1Space(H_mesh, NULL, P_INIT)); + //L2Space H_space(mesh, P_INIT)); + SpaceSharedPtr P_space(new HcurlSpace(P_mesh, &bcs, P_INIT)); + + Hermes::vector > spaces = Hermes::vector >(E_space, H_space, P_space); + + // Initialize views. + ScalarView E1_view("Solution E1", new WinGeom(0, 0, 400, 350)); + E1_view.fix_scale_width(50); + ScalarView E2_view("Solution E2", new WinGeom(410, 0, 400, 350)); + E2_view.fix_scale_width(50); + ScalarView H_view("Solution H", new WinGeom(0, 410, 400, 350)); + H_view.fix_scale_width(50); + ScalarView P1_view("Solution P1", new WinGeom(410, 410, 400, 350)); + P1_view.fix_scale_width(50); + ScalarView P2_view("Solution P2", new WinGeom(820, 410, 400, 350)); + P2_view.fix_scale_width(50); + + // Visualize initial conditions. + char title[100]; + sprintf(title, "E1 - Initial Condition"); + E1_view.set_title(title); + E1_view.show(E_time_prev, H2D_FN_VAL_0); + sprintf(title, "E2 - Initial Condition"); + E2_view.set_title(title); + E2_view.show(E_time_prev, H2D_FN_VAL_1); + + sprintf(title, "H - Initial Condition"); + H_view.set_title(title); + H_view.show(H_time_prev); + + sprintf(title, "P1 - Initial Condition"); + P1_view.set_title(title); + P1_view.show(P_time_prev, H2D_FN_VAL_0); + sprintf(title, "P2 - Initial Condition"); + P2_view.set_title(title); + P2_view.show(P_time_prev, H2D_FN_VAL_1); + + // Initialize Runge-Kutta time stepping. + RungeKutta runge_kutta(&wf, spaces, &bt); runge_kutta.set_max_allowed_iterations(NEWTON_MAX_ITER); - runge_kutta.set_tolerance(NEWTON_TOL); - runge_kutta.set_verbose_output(true); - - // Initialize refinement selector. - H1ProjBasedSelector H1selector(CAND_LIST); - HcurlProjBasedSelector HcurlSelector(CAND_LIST); - - // Time stepping loop. - int ts = 1; - do - { - // Perform one Runge-Kutta time step according to the selected Butcher's table. - Hermes::Mixins::Loggable::Static::info("\nRunge-Kutta time step (t = %g s, time_step = %g s, stages: %d).", - current_time, time_step, bt.get_size()); - - // Periodic global derefinements. - if (ts > 1 && ts % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) - { - Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); - REFINEMENT_COUNT = 0; - - E_space->unrefine_all_mesh_elements(true); - H_space->unrefine_all_mesh_elements(true); - P_space->unrefine_all_mesh_elements(true); - - E_space->adjust_element_order(-1, P_INIT); - H_space->adjust_element_order(-1, P_INIT); - P_space->adjust_element_order(-1, P_INIT); - } - - // Adaptivity loop: - int as = 1; - bool done = false; - do - { - Hermes::Mixins::Loggable::Static::info("Adaptivity step %d:", as); - - // Construct globally refined reference mesh and setup reference space. - int order_increase = 1; - - Mesh::ReferenceMeshCreator refMeshCreatorE(E_mesh); - Mesh::ReferenceMeshCreator refMeshCreatorH(H_mesh); - Mesh::ReferenceMeshCreator refMeshCreatorP(P_mesh); - MeshSharedPtr ref_mesh_E = refMeshCreatorE.create_ref_mesh(); - MeshSharedPtr ref_mesh_H = refMeshCreatorH.create_ref_mesh(); - MeshSharedPtr ref_mesh_P = refMeshCreatorP.create_ref_mesh(); - - Space::ReferenceSpaceCreator refSpaceCreatorE(E_space, ref_mesh_E, order_increase); - SpaceSharedPtr ref_space_E = refSpaceCreatorE.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorH(H_space, ref_mesh_H, order_increase); - SpaceSharedPtr ref_space_H = refSpaceCreatorH.create_ref_space(); - Space::ReferenceSpaceCreator refSpaceCreatorP(P_space, ref_mesh_P, order_increase); - SpaceSharedPtr ref_space_P = refSpaceCreatorP.create_ref_space(); + runge_kutta.set_tolerance(NEWTON_TOL); + runge_kutta.set_verbose_output(true); + + // Initialize refinement selector. + H1ProjBasedSelector H1selector(CAND_LIST); + HcurlProjBasedSelector HcurlSelector(CAND_LIST); + + // Time stepping loop. + int ts = 1; + do + { + // Perform one Runge-Kutta time step according to the selected Butcher's table. + Hermes::Mixins::Loggable::Static::info("\nRunge-Kutta time step (t = %g s, time_step = %g s, stages: %d).", + current_time, time_step, bt.get_size()); + + // Periodic global derefinements. + if (ts > 1 && ts % UNREF_FREQ == 0 && REFINEMENT_COUNT > 0) + { + Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); + REFINEMENT_COUNT = 0; + + E_space->unrefine_all_mesh_elements(true); + H_space->unrefine_all_mesh_elements(true); + P_space->unrefine_all_mesh_elements(true); + + E_space->adjust_element_order(-1, P_INIT); + H_space->adjust_element_order(-1, P_INIT); + P_space->adjust_element_order(-1, P_INIT); + + E_space->assign_dofs(); + H_space->assign_dofs(); + P_space->assign_dofs(); + } + + // Adaptivity loop: + int as = 1; + bool done = false; + do + { + Hermes::Mixins::Loggable::Static::info("Adaptivity step %d:", as); + + // Construct globally refined reference mesh and setup reference space. + int order_increase = 1; + + Mesh::ReferenceMeshCreator refMeshCreatorE(E_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorH(H_mesh); + Mesh::ReferenceMeshCreator refMeshCreatorP(P_mesh); + MeshSharedPtr ref_mesh_E = refMeshCreatorE.create_ref_mesh(); + MeshSharedPtr ref_mesh_H = refMeshCreatorH.create_ref_mesh(); + MeshSharedPtr ref_mesh_P = refMeshCreatorP.create_ref_mesh(); + + Space::ReferenceSpaceCreator refSpaceCreatorE(E_space, ref_mesh_E, order_increase); + SpaceSharedPtr ref_space_E = refSpaceCreatorE.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorH(H_space, ref_mesh_H, order_increase); + SpaceSharedPtr ref_space_H = refSpaceCreatorH.create_ref_space(); + Space::ReferenceSpaceCreator refSpaceCreatorP(P_space, ref_mesh_P, order_increase); + SpaceSharedPtr ref_space_P = refSpaceCreatorP.create_ref_space(); int ndof = Space::get_num_dofs(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); - Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); + Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); - try - { + try + { runge_kutta.set_spaces(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); - runge_kutta.set_time(current_time); - runge_kutta.set_time_step(time_step); - runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new); - } - catch(Exceptions::Exception& e) - { - e.print_msg(); - throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); - } + runge_kutta.set_time(current_time); + runge_kutta.set_time_step(time_step); + runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new); + } + catch (Exceptions::Exception& e) + { + e.print_msg(); + throw Hermes::Exceptions::Exception("Runge-Kutta time step failed"); + } // Visualize the solutions. - char title[100]; - sprintf(title, "E1, t = %g", current_time + time_step); - E1_view.set_title(title); - E1_view.show(E_time_new, H2D_FN_VAL_0); - sprintf(title, "E2, t = %g", current_time + time_step); - E2_view.set_title(title); - E2_view.show(E_time_new, H2D_FN_VAL_1); - - sprintf(title, "H, t = %g", current_time + time_step); - H_view.set_title(title); - H_view.show(H_time_new); - - sprintf(title, "P1, t = %g", current_time + time_step); - P1_view.set_title(title); - P1_view.show(P_time_new, H2D_FN_VAL_0); - sprintf(title, "P2, t = %g", current_time + time_step); - P2_view.set_title(title); - P2_view.show(P_time_new, H2D_FN_VAL_1); - - // Project the fine mesh solution onto the coarse mesh. - Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(E_space, H_space, - P_space), Hermes::vector >(E_time_new, H_time_new, P_time_new), Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse)); - - // Calculate element errors and total error estimate. - Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - adaptivity.set_spaces(Hermes::vector >(E_space, H_space, P_space)); + char title[100]; + sprintf(title, "E1, t = %g", current_time + time_step); + E1_view.set_title(title); + E1_view.show(E_time_new, H2D_FN_VAL_0); + sprintf(title, "E2, t = %g", current_time + time_step); + E2_view.set_title(title); + E2_view.show(E_time_new, H2D_FN_VAL_1); + + sprintf(title, "H, t = %g", current_time + time_step); + H_view.set_title(title); + H_view.show(H_time_new); + + sprintf(title, "P1, t = %g", current_time + time_step); + P1_view.set_title(title); + P1_view.show(P_time_new, H2D_FN_VAL_0); + sprintf(title, "P2, t = %g", current_time + time_step); + P2_view.set_title(title); + P2_view.show(P_time_new, H2D_FN_VAL_1); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection ogProjection; ogProjection.project_global(Hermes::vector >(E_space, H_space, + P_space), Hermes::vector >(E_time_new, H_time_new, P_time_new), Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse)); + + // Calculate element errors and total error estimate. + Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); + adaptivity.set_spaces(Hermes::vector >(E_space, H_space, P_space)); errorCalculator.calculate_errors(Hermes::vector >(E_time_new_coarse, H_time_new_coarse, P_time_new_coarse), - Hermes::vector >(E_time_new, H_time_new, P_time_new)); + Hermes::vector >(E_time_new, H_time_new, P_time_new)); double err_est_rel_total = errorCalculator.get_total_error_squared() * 100.; - // Report results. - Hermes::Mixins::Loggable::Static::info("Error estimate: %g%%", err_est_rel_total); + // Report results. + Hermes::Mixins::Loggable::Static::info("Error estimate: %g%%", err_est_rel_total); - // If err_est too large, adapt the mesh. - if (err_est_rel_total < ERR_STOP) + // If err_est too large, adapt the mesh. + if (err_est_rel_total < ERR_STOP) { Hermes::Mixins::Loggable::Static::info("Error estimate under the specified threshold -> moving to next time step."); - done = true; + done = true; } - else - { - Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); - REFINEMENT_COUNT++; - done = adaptivity.adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector)); - - if(!done) - as++; - } - } - while(!done); - - //View::wait(); - E_time_prev->copy(E_time_new); - H_time_prev->copy(H_time_new); - P_time_prev->copy(P_time_new); - - // Update time. - current_time += time_step; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + REFINEMENT_COUNT++; + done = adaptivity.adapt(Hermes::vector *>(&HcurlSelector, &H1selector, &HcurlSelector)); + + if (!done) + as++; + } + } while (!done); + + //View::wait(); + E_time_prev->copy(E_time_new); + H_time_prev->copy(H_time_new); + P_time_prev->copy(P_time_new); + + // Update time. + current_time += time_step; ts++; - } while (current_time < T_FINAL); + } while (current_time < T_FINAL); - // Wait for the view to be closed. - View::wait(); - } - catch (std::exception& e) - { - std::cout << e.what(); - } + // Wait for the view to be closed. + View::wait(); + } + catch (std::exception& e) + { + std::cout << e.what(); + } - return 0; + return 0; } From db70f3b8ecef3ea0989b47237ca15a47fc82e5b8 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 30 Oct 2013 13:53:37 +0100 Subject: [PATCH 54/64] Work on CMake. --- CMakeLists.txt | 28 +++------------------------- cmake/MSVC_FLAGS.cmake | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 cmake/MSVC_FLAGS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 250ba22..4eadc60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,33 +60,11 @@ project(hermes-examples) set(DEBUG_FLAGS "-g") endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # Enabling multiprocessor build on MSVC - if(MSVC) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") - if(WITH_OPENMP) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") - endif(WITH_OPENMP) - endif(MSVC) - # This overrides CXX flags for MSVC if(MSVC) - if(WIN64) - set(MSVC_DEFINES "/DWIN64 /D_WINDOWS /Dfinite=_finite /wd4275 /wd4251") - else(WIN64) - set(MSVC_DEFINES "/DWIN32 /D_WINDOWS /Dfinite=_finite /wd4275 /wd4251") - endif(WIN64) - set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Ob2 /MDd /Zi ${MSVC_DEFINES}") - set(HERMES_DEBUG_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "/O2 /Ob2 /MD ${MSVC_DEFINES}") - set(CMAKE_CXX_FLAGS_RELEASE "/DNDEBUG /O2 /Ob2 /MD ${MSVC_DEFINES}") - set(HERMES_RELEASE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/DNDEBUG /O2 /Ob2 /MD /Zi ${MSVC_DEFINES}") - - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") - set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") - set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") - endif(MSVC) - + include(MSVC_FLAGS) + endif(MSVC + include_directories("${PTHREAD_ROOT}/include") if(${WITH_UMFPACK}) diff --git a/cmake/MSVC_FLAGS.cmake b/cmake/MSVC_FLAGS.cmake new file mode 100644 index 0000000..a6507b5 --- /dev/null +++ b/cmake/MSVC_FLAGS.cmake @@ -0,0 +1,32 @@ +# Always use inlining. +# Disable some warnings. +# Use multi-processor. +set(HERMES_MSVC_CXX_FLAGS "/Ob2 /wd4275 /wd4251 /wd4018 /wd4251 /wd4661 /wd4996 /MP") +if(WITH_OPENMP) + SET(HERMES_MSVC_CXX_FLAGS "${HERMES_MSVC_CXX_FLAGS} /openmp") +endif(WITH_OPENMP) + +if(WIN64) + set(HERMES_MSVC_CXX_FLAGS "${HERMES_MSVC_CXX_FLAGS} /DWIN64") +endif(WIN64) + +# Generate debug info in the proper format. +SET(HERMES_MSVC_DEBUG_INFO_FLAGS "/Zi /MDd") +# No debug info. +SET(HERMES_MSVC_NDEBUG_FLAGS "/DNDEBUG /MD") +# Optimizations. +SET(HERMES_MSVC_OPTIMIZATIONS_FLAGS "/O2 /Ot") +# NO optimizations. +SET(HERMES_MSVC_NO_OPTIMIZATIONS_FLAGS "/Od") + +# Debugging - add the "_DEBUG" definition. +set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG ${HERMES_MSVC_DEBUG_INFO_FLAGS} ${HERMES_MSVC_NO_OPTIMIZATIONS_FLAGS} ${HERMES_MSVC_CXX_FLAGS}") +# Release with deb. info -> primarily for VTune etc. +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${HERMES_MSVC_DEBUG_INFO_FLAGS} ${HERMES_MSVC_OPTIMIZATIONS_FLAGS} ${HERMES_MSVC_CXX_FLAGS}") +# Release +set(CMAKE_CXX_FLAGS_RELEASE "${HERMES_MSVC_NDEBUG_FLAGS} ${HERMES_MSVC_OPTIMIZATIONS_FLAGS} ${HERMES_MSVC_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE}") + +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") +set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") +set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") \ No newline at end of file From e1e11efbf97e9b39b463cdb68af2a0b21da47a28 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 30 Oct 2013 14:22:47 +0100 Subject: [PATCH 55/64] Fix of CMake. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eadc60..7438340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ project(hermes-examples) # This overrides CXX flags for MSVC if(MSVC) include(MSVC_FLAGS) - endif(MSVC + endif(MSVC) include_directories("${PTHREAD_ROOT}/include") @@ -191,4 +191,4 @@ project(hermes-examples) message("Build with TRILINOS: !TO_DO!") message("---------------------") - message("\n") + message("\n") \ No newline at end of file From 6f731d61ffeb0c0d9a621e8b68c22cd3220ab133 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 30 Oct 2013 17:44:08 +0100 Subject: [PATCH 56/64] Tufn off TCMalloc by default. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7438340..9884bd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ project(hermes-examples) # This has to be the same as in the library's CMake. # Default "yes" set(H2D_WITH_GLUT YES) - set(WITH_TC_MALLOC YES) + set(WITH_TC_MALLOC NO) set(WITH_PARALUTION YES) set(WITH_UMFPACK YES) set(WITH_OPENMP YES) @@ -191,4 +191,4 @@ project(hermes-examples) message("Build with TRILINOS: !TO_DO!") message("---------------------") - message("\n") \ No newline at end of file + message("\n") From 09608114e110f0fc7a58174553ad06330c1e5144 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Wed, 30 Oct 2013 17:54:16 +0100 Subject: [PATCH 57/64] Fixes in examples. --- 2d-advanced/elasticity-linear/bracket/main.cpp | 3 ++- 2d-advanced/elasticity-linear/crack/main.cpp | 5 +++-- 2d-advanced/helmholtz/waveguide/main.cpp | 3 ++- 2d-advanced/maxwell/maxwell-debye-rk/main.cpp | 7 ++++--- 2d-advanced/navier-stokes/bearing/main.cpp | 4 +--- 2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp | 2 +- 2d-advanced/navier-stokes/driven-cavity/main.cpp | 2 +- .../nernst-planck/np-poisson-timedep-adapt/main.cpp | 4 +++- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/2d-advanced/elasticity-linear/bracket/main.cpp b/2d-advanced/elasticity-linear/bracket/main.cpp index 9c56c13..9857608 100644 --- a/2d-advanced/elasticity-linear/bracket/main.cpp +++ b/2d-advanced/elasticity-linear/bracket/main.cpp @@ -88,7 +88,8 @@ int main(int argc, char* argv[]) CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy_top", f0, f1); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); + Hermes::vector > spaces(u1_space, u2_space); + DiscreteProblem dp(&wf, spaces); // Initialize coarse and reference mesh solutions. MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); diff --git a/2d-advanced/elasticity-linear/crack/main.cpp b/2d-advanced/elasticity-linear/crack/main.cpp index 4090005..6f5e364 100644 --- a/2d-advanced/elasticity-linear/crack/main.cpp +++ b/2d-advanced/elasticity-linear/crack/main.cpp @@ -112,7 +112,8 @@ int main(int argc, char* argv[]) CustomWeakFormLinearElasticity wf(E, nu, rho*g1, "bdy rest", f0, f1); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(u1_space, u2_space)); + Hermes::vector > spaces(u1_space, u2_space); + DiscreteProblem dp(&wf, spaces); // Initialize coarse and reference mesh solutions. MeshFunctionSharedPtr u1_sln(new Solution), u2_sln(new Solution); @@ -279,4 +280,4 @@ int main(int argc, char* argv[]) // Wait for all views to be closed. View::wait(); return 0; -} \ No newline at end of file +} diff --git a/2d-advanced/helmholtz/waveguide/main.cpp b/2d-advanced/helmholtz/waveguide/main.cpp index 0c1e93c..5c2f6c1 100644 --- a/2d-advanced/helmholtz/waveguide/main.cpp +++ b/2d-advanced/helmholtz/waveguide/main.cpp @@ -87,7 +87,8 @@ int main(int argc, char* argv[]) wf.set_verbose_output(false); // Initialize the FE problem. - DiscreteProblem dp(&wf, Hermes::vector >(e_r_space, e_i_space)); + Hermes::vector > spaces(e_r_space, e_i_space); + DiscreteProblem dp(&wf, spaces); // Initialize the solutions. MeshFunctionSharedPtr e_r_sln(new Solution), e_i_sln(new Solution); diff --git a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp index 83da156..6d0d047 100644 --- a/2d-advanced/maxwell/maxwell-debye-rk/main.cpp +++ b/2d-advanced/maxwell/maxwell-debye-rk/main.cpp @@ -259,13 +259,14 @@ int main(int argc, char* argv[]) SpaceSharedPtr ref_space_H = refSpaceCreatorH.create_ref_space(); Space::ReferenceSpaceCreator refSpaceCreatorP(P_space, ref_mesh_P, order_increase); SpaceSharedPtr ref_space_P = refSpaceCreatorP.create_ref_space(); - - int ndof = Space::get_num_dofs(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); + Hermes::vector > ref_spaces(ref_space_E, ref_space_H, ref_space_P); + + int ndof = Space::get_num_dofs(ref_spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof); try { - runge_kutta.set_spaces(Hermes::vector >(ref_space_E, ref_space_H, ref_space_P)); + runge_kutta.set_spaces(ref_spaces); runge_kutta.set_time(current_time); runge_kutta.set_time_step(time_step); runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new); diff --git a/2d-advanced/navier-stokes/bearing/main.cpp b/2d-advanced/navier-stokes/bearing/main.cpp index e890955..f6a1ea7 100644 --- a/2d-advanced/navier-stokes/bearing/main.cpp +++ b/2d-advanced/navier-stokes/bearing/main.cpp @@ -1,5 +1,3 @@ - - #include "definitions.h" // Flow in between two circles, inner circle is rotating with surface @@ -180,7 +178,7 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space, p_space), current_time); + Space::update_essential_bc_values(spaces, current_time); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index 4bcdfe6..f67a5e9 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -219,7 +219,7 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space, p_space), current_time); + Space::update_essential_bc_values(spaces, current_time); // Periodic global derefinements. if (ts > 1 && ts % UNREF_FREQ == 0) { diff --git a/2d-advanced/navier-stokes/driven-cavity/main.cpp b/2d-advanced/navier-stokes/driven-cavity/main.cpp index 3ca1c34..bf22e29 100644 --- a/2d-advanced/navier-stokes/driven-cavity/main.cpp +++ b/2d-advanced/navier-stokes/driven-cavity/main.cpp @@ -158,7 +158,7 @@ int main(int argc, char* argv[]) // Update time-dependent essential BCs. Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); - Space::update_essential_bc_values(Hermes::vector >(xvel_space, yvel_space), current_time); + Space::update_essential_bc_values(spaces, current_time); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); diff --git a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp index 448bb4d..4e883d6 100644 --- a/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp +++ b/2d-advanced/nernst-planck/np-poisson-timedep-adapt/main.cpp @@ -195,6 +195,8 @@ int main (int argc, char* argv[]) { SpaceSharedPtr C_space(new H1Space(C_mesh, P_INIT)); SpaceSharedPtr phi_space(new H1Space(MULTIMESH ? phi_mesh : C_mesh, &bcs_phi, P_INIT)); + Hermes::vector > spaces(C_space, phi_space); + MeshFunctionSharedPtr C_sln(new Solution), C_ref_sln(new Solution); MeshFunctionSharedPtr phi_sln(new Solution), phi_ref_sln(new Solution); @@ -222,7 +224,7 @@ int main (int argc, char* argv[]) { wf = new WeakFormPNPEuler(TAU, C0, K, L, D, C_prev_time); } - DiscreteProblem dp_coarse(wf, Hermes::vector >(C_space, phi_space)); + DiscreteProblem dp_coarse(wf, spaces); NewtonSolver* solver_coarse = new NewtonSolver(&dp_coarse); From 690b93c7f58fe143b88fb111f21588b3e7acb43f Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Mon, 18 Nov 2013 18:29:05 +0100 Subject: [PATCH 58/64] Some resuscitation of older examples. Heat and moisture works like charm. --- 2d-advanced/heat-transfer/CMakeLists.txt | 2 +- .../heat-and-moisture-adapt/definitions.h | 27 +- .../heat-and-moisture-adapt/main.cpp | 62 +- 2d-advanced/richards/CMakeLists.txt | 2 +- .../richards/seepage-adapt/definitions.cpp | 368 ---------- .../richards/seepage-adapt/definitions.h | 651 +++++++++++++++++- 2d-advanced/richards/seepage-adapt/main.cpp | 42 +- 7 files changed, 692 insertions(+), 462 deletions(-) diff --git a/2d-advanced/heat-transfer/CMakeLists.txt b/2d-advanced/heat-transfer/CMakeLists.txt index 35eb78d..1235c80 100644 --- a/2d-advanced/heat-transfer/CMakeLists.txt +++ b/2d-advanced/heat-transfer/CMakeLists.txt @@ -1,2 +1,2 @@ #add_subdirectory(wall-on-fire-adapt-space-and-time) -#add_subdirectory(heat-and-moisture-adapt) +add_subdirectory(heat-and-moisture-adapt) diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h b/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h index 57bf93f..10649be 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/definitions.h @@ -36,33 +36,14 @@ class EssentialBCNonConst : public EssentialBoundaryCondition /* Custom error forms */ -class CustomErrorForm : public MatrixFormVol +class CustomErrorForm : public NormFormVol { public: - CustomErrorForm(double d, double c) : MatrixFormVol(0, 0), d(d), c(c) {}; + CustomErrorForm(int i, int j, double d, double c) : NormFormVol(i, j), d(d), c(c) {}; - template - Scalar laplace_form(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const + virtual double value(int n, double *wt, Func *u, Func *v, Geom *e) const { - return d / c * int_grad_u_grad_v(n, wt, u, v); - } - - virtual double value(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const - { - return laplace_form(n, wt, u_ext, u, v, e, ext); - } - - virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, Func* *ext) const - { - return laplace_form(n, wt, u_ext, u, v, e, ext); - } - - MatrixFormVol* clone() const - { - return new CustomErrorForm(*this); + return d / c * int_grad_u_grad_v(n, wt, u, v); } double d, c; diff --git a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp index 1560655..80606b5 100644 --- a/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp +++ b/2d-advanced/heat-transfer/heat-and-moisture-adapt/main.cpp @@ -1,5 +1,3 @@ - -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" using namespace RefinementSelectors; @@ -34,16 +32,43 @@ const int UNREF_METHOD = 3; // This is a quantitative parameter of the adapt(...) function and // it has different meanings for various adaptive strategies. const double THRESHOLD = 0.9; +// Predefined list of element refinement candidates. +const CandList CAND_LIST = H2D_HP_ANISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1e0; + +// Problem parameters. +const double c_TT = 2.18e+6; +const double d_TT = 2.1; +const double d_Tw = 2.37e-2 / W_SCALING_FACTOR; +const double k_TT = 25; +const double c_ww = 24.9; +const double d_wT = 1.78e-10 * W_SCALING_FACTOR; +const double d_ww = 3.02e-8; +const double k_ww = 1.84e-7; + +CustomErrorForm cef_0_0(0, 0, d_TT, c_TT); +CustomErrorForm cef_0_1(0, 1, d_Tw, c_TT); +CustomErrorForm cef_1_0(1, 0, d_wT, c_ww); +CustomErrorForm cef_1_1(1, 1, d_ww, c_ww); + // Error calculation & adaptivity. -DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 2); +class MyErrorCalculator : public Hermes::Hermes2D::ErrorCalculator +{ +public: + MyErrorCalculator() : Hermes::Hermes2D::ErrorCalculator(RelativeErrorToGlobalNorm) + { + this->add_error_form(&cef_0_0); + this->add_error_form(&cef_0_1); + this->add_error_form(&cef_1_0); + this->add_error_form(&cef_1_1); + } +} +errorCalculator; // Stopping criterion for an adaptivity step. AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); // Adaptivity processor class. Adapt adaptivity(&errorCalculator, &stoppingCriterion); -// Predefined list of element refinement candidates. -const CandList CAND_LIST = H2D_HP_ANISO; -// Stopping criterion for adaptivity. -const double ERR_STOP = 1e0; // Newton's method // Stopping criterion for Newton on fine mesh-> @@ -74,16 +99,6 @@ const double time_step = 10.*24*60*60; // Physical time [seconds]. const double SIMULATION_TIME = 10000*time_step + 0.001; -// Problem parameters. -const double c_TT = 2.18e+6; -const double d_TT = 2.1; -const double d_Tw = 2.37e-2 / W_SCALING_FACTOR; -const double k_TT = 25; -const double c_ww = 24.9; -const double d_wT = 1.78e-10 * W_SCALING_FACTOR; -const double d_ww = 3.02e-8; -const double k_ww = 1.84e-7; - // Initial and boundary conditions. // (Kelvins) const double T_INITIAL = 293.0; @@ -127,6 +142,8 @@ int main(int argc, char* argv[]) SpaceSharedPtr T_space(new H1Space(T_mesh, &bcs_T, P_INIT)); SpaceSharedPtr w_space(new H1Space(MULTI ? w_mesh : T_mesh, P_INIT)); + Hermes::vector > spaces(T_space, w_space); + adaptivity.set_spaces(spaces); // Define constant initial conditions. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); @@ -202,6 +219,7 @@ int main(int argc, char* argv[]) } T_space->assign_dofs(); w_space->assign_dofs(); + Space::assign_dofs(spaces); } // Spatial adaptivity loop. Note: T_time_prev and w_time_prev must not be changed during @@ -256,16 +274,6 @@ int main(int argc, char* argv[]) Hermes::vector >(T_time_new, w_time_new), Hermes::vector >(T_coarse, w_coarse)); - // Initialize an instance of the Adapt class and register custom error forms. - Adapt adaptivity(Hermes::vector >(T_space, w_space), &errorCalculator, &stoppingCriterion); - CustomErrorForm cef_0_0(d_TT, c_TT); - CustomErrorForm cef_0_1(d_Tw, c_TT); - CustomErrorForm cef_1_0(d_wT, c_ww); - CustomErrorForm cef_1_1(d_ww, c_ww); - errorCalculator.add_error_form(0, 0, &cef_0_0); - errorCalculator.add_error_form(0, 1, &cef_0_1); - errorCalculator.add_error_form(1, 0, &cef_1_0); - errorCalculator.add_error_form(1, 1, &cef_1_1); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); diff --git a/2d-advanced/richards/CMakeLists.txt b/2d-advanced/richards/CMakeLists.txt index ccdacff..7a5c1e1 100644 --- a/2d-advanced/richards/CMakeLists.txt +++ b/2d-advanced/richards/CMakeLists.txt @@ -4,4 +4,4 @@ add_subdirectory(basic-rk-newton) add_subdirectory(basic-rk-newton-adapt) #add_subdirectory(capillary-barrier-rk) add_subdirectory(capillary-barrier-adapt) -#add_subdirectory(seepage-adapt) +add_subdirectory(seepage-adapt) diff --git a/2d-advanced/richards/seepage-adapt/definitions.cpp b/2d-advanced/richards/seepage-adapt/definitions.cpp index 2f1390d..e69de29 100644 --- a/2d-advanced/richards/seepage-adapt/definitions.cpp +++ b/2d-advanced/richards/seepage-adapt/definitions.cpp @@ -1,368 +0,0 @@ -#include "definitions.h" - -// Jacobian matrix - volumetric part -double jac_form_vol_euler(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double x = e->x[0]; - double y = e->x[1]; - if (is_in_mat_1(x,y)) { - K_S = K_S_1; - ALPHA = ALPHA_1; - THETA_R = THETA_R_1; - THETA_S = THETA_R_1; - N = N_1; - M = M_1; - } - if (is_in_mat_2(x,y)) { - K_S = K_S_2; - ALPHA = ALPHA_2; - THETA_R = THETA_R_2; - THETA_S = THETA_R_2; - N = N_2; - M = M_2; - } - if (is_in_mat_3(x,y)) { - K_S = K_S_3; - ALPHA = ALPHA_3; - THETA_R = THETA_R_3; - THETA_S = THETA_R_3; - N = N_3; - M = M_3; - } - if (is_in_mat_4(x,y)) { - K_S = K_S_4; - ALPHA = ALPHA_4; - THETA_R = THETA_R_4; - THETA_S = THETA_R_4; - N = N_4; - M = M_4; - } - - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) - result += wt[i] * ( - C(h_prev_newton->val[i]) * u->val[i] * v->val[i] / TAU - + dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->val[i] * v->val[i] / TAU - - dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_time->val[i] * v->val[i] / TAU - + K(h_prev_newton->val[i]) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) - + dKdh(h_prev_newton->val[i]) * u->val[i] * - (h_prev_newton->dx[i]*v->dx[i] + h_prev_newton->dy[i]*v->dy[i]) - - dKdh(h_prev_newton->val[i]) * u->dy[i] * v->val[i] - - ddKdhh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->dy[i] * v->val[i] - ); - return result; -} - -// Jacobian matrix - volumetric part -double jac_form_vol_cranic(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double x = e->x[0]; - double y = e->x[1]; - if (is_in_mat_1(x,y)) { - K_S = K_S_1; - ALPHA = ALPHA_1; - THETA_R = THETA_R_1; - THETA_S = THETA_R_1; - N = N_1; - M = M_1; - } - if (is_in_mat_2(x,y)) { - K_S = K_S_2; - ALPHA = ALPHA_2; - THETA_R = THETA_R_2; - THETA_S = THETA_R_2; - N = N_2; - M = M_2; - } - if (is_in_mat_3(x,y)) { - K_S = K_S_3; - ALPHA = ALPHA_3; - THETA_R = THETA_R_3; - THETA_S = THETA_R_3; - N = N_3; - M = M_3; - } - if (is_in_mat_4(x,y)) { - K_S = K_S_4; - ALPHA = ALPHA_4; - THETA_R = THETA_R_4; - THETA_S = THETA_R_4; - N = N_4; - M = M_4; - } - - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) - result += wt[i] * 0.5 * ( // implicit Euler part: - C(h_prev_newton->val[i]) * u->val[i] * v->val[i] / TAU - + dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->val[i] * v->val[i] / TAU - - dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_time->val[i] * v->val[i] / TAU - + K(h_prev_newton->val[i]) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) - + dKdh(h_prev_newton->val[i]) * u->val[i] * - (h_prev_newton->dx[i]*v->dx[i] + h_prev_newton->dy[i]*v->dy[i]) - - dKdh(h_prev_newton->val[i]) * u->dy[i] * v->val[i] - - ddKdhh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->dy[i] * v->val[i] - ) - + wt[i] * 0.5 * ( // explicit Euler part, - C(h_prev_time->val[i]) * u->val[i] * v->val[i] / TAU - ); - return result; -} - -// Integration order for Jacobian matrix - volumetric part -Ord jac_form_vol_ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, - Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Jacobian matrix - surface part on bdy 1 -double jac_form_surf_1_euler(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Jacobian matrix - surface part on bdy 1 -double jac_form_surf_1_cranic(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - // Just the implicit Euler contributes: - result += wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Integration order for Jacobian matrix - surface part on bdy 1 -Ord jac_form_surf_1_ord(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Jacobian matrix - surface part on bdy 4 -double jac_form_surf_4_euler(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result -= wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Jacobian matrix - surface part on bdy 4 -double jac_form_surf_4_cranic(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - // Just the implicit Euler contributes: - result -= wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Integration order for Jacobian matrix - surface part on bdy 4 -Ord jac_form_surf_4_ord(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Jacobian matrix - surface part on bdy 6 -double jac_form_surf_6_euler(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Jacobian matrix - surface part on bdy 6 -double jac_form_surf_6_cranic(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - // Just the implicit Euler contributes: - for (int i = 0; i < n; i++) { - result += wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; - } - - return result; -} - -// Integration order for Jacobian matrix - surface part on bdy 6 -Ord jac_form_surf_6_ord(int n, double *wt, Func *u_ext[], Func *u, - Func *v, Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Residual vector - volumetric part -double res_form_vol_euler(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * ( - C(h_prev_newton->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU - + K(h_prev_newton->val[i]) * (h_prev_newton->dx[i] * v->dx[i] + h_prev_newton->dy[i] * v->dy[i]) - - dKdh(h_prev_newton->val[i]) * h_prev_newton->dy[i] * v->val[i] - ); - } - return result; -} - -// Residual vector - volumetric part -double res_form_vol_cranic(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * 0.5 * ( // implicit Euler part - C(h_prev_newton->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU - + K(h_prev_newton->val[i]) * (h_prev_newton->dx[i] * v->dx[i] + h_prev_newton->dy[i] * v->dy[i]) - - dKdh(h_prev_newton->val[i]) * h_prev_newton->dy[i] * v->val[i] - ) - + wt[i] * 0.5 * ( // explicit Euler part - C(h_prev_time->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU - + K(h_prev_time->val[i]) * (h_prev_time->dx[i] * v->dx[i] + h_prev_time->dy[i] * v->dy[i]) - - dKdh(h_prev_time->val[i]) * h_prev_time->dy[i] * v->val[i] - ); - } - return result; -} - -// Integration order for residual vector - volumetric part -Ord res_form_vol_ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Residual vector - surface part on bdy 1 -double res_form_surf_1_euler(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * K(h_prev_newton->val[i]) * v->val[i]; - } - return result; -} - -// Residual vector - surface part on bdy 1 -double res_form_surf_1_cranic(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i])) * v->val[i]; - } - return result; -} - -// Integration order for residual vector - surface part on bdy 1 -Ord res_form_surf_1_ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Residual vector - surface part on bdy 4 -double res_form_surf_4_euler(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result -= wt[i] * K(h_prev_newton->val[i]) * v->val[i]; - } - return result; -} - -// Residual vector - surface part on bdy 4 -double res_form_surf_4_cranic(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) { - result -= wt[i] * 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i]))* v->val[i]; - } - return result; -} - -// Integration order for residual vector - surface part on bdy 4 -Ord res_form_surf_4_ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - return Ord(30); -} - -// Residual vector - surface part on bdy 6 -double res_form_surf_6_euler(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * (q_function() + K(h_prev_newton->val[i])) * v->val[i]; - } - return result; -} - -// Residual vector - surface part on bdy 6 -double res_form_surf_6_cranic(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - double result = 0; - Func* h_prev_newton = u_ext[0]; - Func* h_prev_time = ext->fn[0]; - for (int i = 0; i < n; i++) { - result += wt[i] * (q_function() + 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i]))) * v->val[i]; - } - return result; -} - -// Integration order for residual vector - surface part on bdy 6 -Ord res_form_surf_6_ord(int n, double *wt, Func *u_ext[], Func *v, - Geom *e, ExtData *ext) -{ - return Ord(30); -} - diff --git a/2d-advanced/richards/seepage-adapt/definitions.h b/2d-advanced/richards/seepage-adapt/definitions.h index 1ca6c44..4c84ac6 100644 --- a/2d-advanced/richards/seepage-adapt/definitions.h +++ b/2d-advanced/richards/seepage-adapt/definitions.h @@ -46,4 +46,653 @@ double N_4 = 5.0; double M_1 = 0.49546; double M_2 = 0.38726; double M_3 = 0.8; -double M_4 = 0.8; \ No newline at end of file +double M_4 = 0.8; + +// Boundary markers. +const std::string BDY_1 = "1"; +const std::string BDY_2 = "2"; +const std::string BDY_3 = "3"; +const std::string BDY_4 = "4"; +const std::string BDY_5 = "5"; +const std::string BDY_6 = "6"; + +class CustomWeakForm : public WeakForm +{ + CustomWeakForm(int TIME_INTEGRATION, MeshFunctionSharedPtr prev_sln) + { + this->set_ext(prev_sln); + if (TIME_INTEGRATION == 1) { + this->add_matrix_form(new JacobianFormVolEuler(0, 0)); + this->add_matrix_form_surf(new JacobianFormSurf1Euler(0, 0)); + this->mfsurf.back()->set_area(BDY_1); + this->add_matrix_form_surf(new JacobianFormSurf4Euler(0, 0)); + this->mfsurf.back()->set_area(BDY_4); + this->add_matrix_form_surf(new JacobianFormSurf6Euler(0, 0)); + this->mfsurf.back()->set_area(BDY_6); + + this->add_vector_form(new ResidualFormVolEuler(0)); + this->add_vector_form_surf(new ResidualFormSurf1Euler(0)); + this->vfsurf.back()->set_area(BDY_1); + this->add_vector_form_surf(new ResidualFormSurf4Euler(0)); + this->vfsurf.back()->set_area(BDY_4); + this->add_vector_form_surf(new ResidualFormSurf6Euler(0)); + this->vfsurf.back()->set_area(BDY_6); + } + else + { + this->add_matrix_form(new JacobianFormVolCrankNicolson(0, 0)); + this->add_matrix_form_surf(new JacobianFormSurf1CrankNicolson(0, 0)); + this->mfsurf.back()->set_area(BDY_1); + this->add_matrix_form_surf(new JacobianFormSurf4CrankNicolson(0, 0)); + this->mfsurf.back()->set_area(BDY_4); + this->add_matrix_form_surf(new JacobianFormSurf6CrankNicolson(0, 0)); + this->mfsurf.back()->set_area(BDY_6); + + this->add_vector_form(new ResidualFormVolCrankNicolson(0)); + this->add_vector_form_surf(new ResidualFormSurf1CrankNicolson(0)); + this->vfsurf.back()->set_area(BDY_1); + this->add_vector_form_surf(new ResidualFormSurf4CrankNicolson(0)); + this->vfsurf.back()->set_area(BDY_4); + this->add_vector_form_surf(new ResidualFormSurf6CrankNicolson(0)); + this->vfsurf.back()->set_area(BDY_6); + } + } + + class JacobianFormVolEuler : public MatrixFormVol + { + public: + JacobianFormVolEuler(int i, int j) : MatrixFormVol(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double x = e->x[0]; + double y = e->x[1]; + if (is_in_mat_1(x,y)) { + K_S = K_S_1; + ALPHA = ALPHA_1; + THETA_R = THETA_R_1; + THETA_S = THETA_R_1; + N = N_1; + M = M_1; + } + if (is_in_mat_2(x,y)) { + K_S = K_S_2; + ALPHA = ALPHA_2; + THETA_R = THETA_R_2; + THETA_S = THETA_R_2; + N = N_2; + M = M_2; + } + if (is_in_mat_3(x,y)) { + K_S = K_S_3; + ALPHA = ALPHA_3; + THETA_R = THETA_R_3; + THETA_S = THETA_R_3; + N = N_3; + M = M_3; + } + if (is_in_mat_4(x,y)) { + K_S = K_S_4; + ALPHA = ALPHA_4; + THETA_R = THETA_R_4; + THETA_S = THETA_R_4; + N = N_4; + M = M_4; + } + + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) + result += wt[i] * ( + C(h_prev_newton->val[i]) * u->val[i] * v->val[i] / TAU + + dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->val[i] * v->val[i] / TAU + - dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_time->val[i] * v->val[i] / TAU + + K(h_prev_newton->val[i]) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) + + dKdh(h_prev_newton->val[i]) * u->val[i] * + (h_prev_newton->dx[i]*v->dx[i] + h_prev_newton->dy[i]*v->dy[i]) + - dKdh(h_prev_newton->val[i]) * u->dy[i] * v->val[i] + - ddKdhh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->dy[i] * v->val[i] + ); + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormVol* clone() const + { + return new JacobianFormVolEuler(); + } + }; + + class JacobianFormVolCrankNicolson : public MatrixFormVol + { + public: + JacobianFormVolCrankNicolson(int i, int j) : MatrixFormVol(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double x = e->x[0]; + double y = e->x[1]; + if (is_in_mat_1(x,y)) { + K_S = K_S_1; + ALPHA = ALPHA_1; + THETA_R = THETA_R_1; + THETA_S = THETA_R_1; + N = N_1; + M = M_1; + } + if (is_in_mat_2(x,y)) { + K_S = K_S_2; + ALPHA = ALPHA_2; + THETA_R = THETA_R_2; + THETA_S = THETA_R_2; + N = N_2; + M = M_2; + } + if (is_in_mat_3(x,y)) { + K_S = K_S_3; + ALPHA = ALPHA_3; + THETA_R = THETA_R_3; + THETA_S = THETA_R_3; + N = N_3; + M = M_3; + } + if (is_in_mat_4(x,y)) { + K_S = K_S_4; + ALPHA = ALPHA_4; + THETA_R = THETA_R_4; + THETA_S = THETA_R_4; + N = N_4; + M = M_4; + } + + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) + result += wt[i] * 0.5 * ( // implicit Euler part: + C(h_prev_newton->val[i]) * u->val[i] * v->val[i] / TAU + + dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->val[i] * v->val[i] / TAU + - dCdh(h_prev_newton->val[i]) * u->val[i] * h_prev_time->val[i] * v->val[i] / TAU + + K(h_prev_newton->val[i]) * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]) + + dKdh(h_prev_newton->val[i]) * u->val[i] * + (h_prev_newton->dx[i]*v->dx[i] + h_prev_newton->dy[i]*v->dy[i]) + - dKdh(h_prev_newton->val[i]) * u->dy[i] * v->val[i] + - ddKdhh(h_prev_newton->val[i]) * u->val[i] * h_prev_newton->dy[i] * v->val[i] + ) + + wt[i] * 0.5 * ( // explicit Euler part, + C(h_prev_time->val[i]) * u->val[i] * v->val[i] / TAU + ); + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormVol* clone() const + { + return new JacobianFormVolEuler(this->i, this->j); + } + }; + + class JacobianFormSurf1Euler : public MatrixFormSurf + { + public: + JacobianFormSurf1Euler(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf1Euler(this->i, this->j); + } + }; + + class JacobianFormSurf1CrankNicolson : public MatrixFormSurf + { + public: + JacobianFormSurf1CrankNicolson(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + // Just the implicit Euler contributes: + result += wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf1CrankNicolson(this->i, this->j); + } + }; + + class JacobianFormSurf4Euler : public MatrixFormSurf + { + public: + JacobianFormSurf4Euler(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result -= wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf4Euler(this->i, this->j); + } + }; + + class JacobianFormSurf4CrankNicolson : public MatrixFormSurf + { + public: + JacobianFormSurf4CrankNicolson(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + // Just the implicit Euler contributes: + result -= wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf4CrankNicolson(this->i, this->j); + } + }; + + class JacobianFormSurf6Euler : public MatrixFormSurf + { + public: + JacobianFormSurf6Euler(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf6Euler(this->i, this->j); + } + }; + + class JacobianFormSurf6CrankNicolson : public MatrixFormSurf + { + public: + JacobianFormSurf6CrankNicolson(int i, int j) : MatrixFormSurf(i, j) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + // Just the implicit Euler contributes: + for (int i = 0; i < n; i++) { + result += wt[i] * 0.5 * dKdh(h_prev_newton->val[i]) * u->val[i] * v->val[i]; + } + + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + MatrixFormSurf* clone() const + { + return new JacobianFormSurf6CrankNicolson(this->i, this->j); + } + }; + + class ResidualFormVolEuler : public VectorFormVol + { + public: + ResidualFormVolEuler(int i) : VectorFormVol(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * ( + C(h_prev_newton->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU + + K(h_prev_newton->val[i]) * (h_prev_newton->dx[i] * v->dx[i] + h_prev_newton->dy[i] * v->dy[i]) + - dKdh(h_prev_newton->val[i]) * h_prev_newton->dy[i] * v->val[i] + ); + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormVol* clone() const + { + return new ResidualFormVolEuler(this->i); + } + }; + + class ResidualFormVolCrankNicolson : public VectorFormVol + { + public: + ResidualFormVolCrankNicolson(int i) : VectorFormVol(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * 0.5 * ( // implicit Euler part + C(h_prev_newton->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU + + K(h_prev_newton->val[i]) * (h_prev_newton->dx[i] * v->dx[i] + h_prev_newton->dy[i] * v->dy[i]) + - dKdh(h_prev_newton->val[i]) * h_prev_newton->dy[i] * v->val[i] + ) + + wt[i] * 0.5 * ( // explicit Euler part + C(h_prev_time->val[i]) * (h_prev_newton->val[i] - h_prev_time->val[i]) * v->val[i] / TAU + + K(h_prev_time->val[i]) * (h_prev_time->dx[i] * v->dx[i] + h_prev_time->dy[i] * v->dy[i]) + - dKdh(h_prev_time->val[i]) * h_prev_time->dy[i] * v->val[i] + ); + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormVol* clone() const + { + return new ResidualFormVolEuler(this->i); + } + }; + + class ResidualFormSurf1Euler : public VectorFormSurf + { + public: + ResidualFormSurf1Euler(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * K(h_prev_newton->val[i]) * v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf1Euler(this->i); + } + }; + + class ResidualFormSurf1CrankNicolson : public VectorFormSurf + { + public: + ResidualFormSurf1CrankNicolson(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i])) * v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf1CrankNicolson(this->i); + } + }; + + class ResidualFormSurf4Euler : public VectorFormSurf + { + public: + ResidualFormSurf4Euler(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result -= wt[i] * K(h_prev_newton->val[i]) * v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf4Euler(this->i); + } + }; + + class ResidualFormSurf4CrankNicolson : public VectorFormSurf + { + public: + ResidualFormSurf4CrankNicolson(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) { + result -= wt[i] * 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i]))* v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf4CrankNicolson(this->i, this->j); + } + }; + + class ResidualFormSurf6Euler : public VectorFormSurf + { + public: + ResidualFormSurf6Euler(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * (q_function() + K(h_prev_newton->val[i])) * v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf6Euler(this->i); + } + }; + + class ResidualFormSurf6CrankNicolson : public VectorFormSurf + { + public: + ResidualFormSurf6CrankNicolson(int i) : VectorFormSurf(i) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const + { + double result = 0; + Func* h_prev_newton = u_ext[0]; + Func* h_prev_time = ext[0]; + for (int i = 0; i < n; i++) { + result += wt[i] * (q_function() + 0.5 * (K(h_prev_newton->val[i]) + K(h_prev_time->val[i]))) * v->val[i]; + } + return result; + } + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const + { + return Ord(20); + } + + VectorFormSurf* clone() const + { + return new ResidualFormSurf6CrankNicolson(this->i); + } + }; +}; \ No newline at end of file diff --git a/2d-advanced/richards/seepage-adapt/main.cpp b/2d-advanced/richards/seepage-adapt/main.cpp index e1c3be7..053f48f 100644 --- a/2d-advanced/richards/seepage-adapt/main.cpp +++ b/2d-advanced/richards/seepage-adapt/main.cpp @@ -1,5 +1,3 @@ -#define HERMES_REPORT_ALL -#define HERMES_REPORT_FILE "application.log" #include "definitions.h" // This example uses adaptivity with dynamical meshes to solve @@ -116,14 +114,6 @@ bool is_in_mat_3(double x, double y) { #include "constitutive_gardner.cpp" #endif -// Boundary markers. -const int BDY_1 = 1; -const int BDY_2 = 2; -const int BDY_3 = 3; -const int BDY_4 = 4; -const int BDY_5 = 5; -const int BDY_6 = 6; - // Initial condition. double init_cond(double x, double y, double& dx, double& dy) { dx = 0; @@ -138,9 +128,6 @@ double essential_bc_values(double x, double y, double time) else return -y + H_INIT + H_ELEVATION; } -// Weak forms. -#include "definitions.cpp" - int main(int argc, char* argv[]) { // Time measurement. @@ -228,34 +215,7 @@ SpaceSharedPtr init_space(&basemesh, &bc_types, &bc_values, P_INIT); while (done == false); // Initialize the weak formulation. - WeakForm wf; - if (TIME_INTEGRATION == 1) { - wf.add_matrix_form(jac_form_vol_euler, jac_form_vol_ord, HERMES_NONSYM, HERMES_ANY, - &sln_prev_time); - wf.add_matrix_form_surf(jac_form_surf_1_euler, jac_form_surf_1_ord, BDY_1); - wf.add_matrix_form_surf(jac_form_surf_4_euler, jac_form_surf_4_ord, BDY_4); - wf.add_matrix_form_surf(jac_form_surf_6_euler, jac_form_surf_6_ord, BDY_6); - wf.add_vector_form(res_form_vol_euler, res_form_vol_ord, HERMES_ANY, - &sln_prev_time); - wf.add_vector_form_surf(res_form_surf_1_euler, res_form_surf_1_ord, BDY_1); - wf.add_vector_form_surf(res_form_surf_4_euler, res_form_surf_4_ord, BDY_4); - wf.add_vector_form_surf(res_form_surf_6_euler, res_form_surf_6_ord, BDY_6); - } - else { - wf.add_matrix_form(jac_form_vol_cranic, jac_form_vol_ord, HERMES_NONSYM, HERMES_ANY, - &sln_prev_time); - wf.add_matrix_form_surf(jac_form_surf_1_cranic, jac_form_surf_1_ord, BDY_1); - wf.add_matrix_form_surf(jac_form_surf_4_cranic, jac_form_surf_4_ord, BDY_4); - wf.add_matrix_form_surf(jac_form_surf_6_cranic, jac_form_surf_6_ord, BDY_6); - wf.add_vector_form(res_form_vol_cranic, res_form_vol_ord, HERMES_ANY, - &sln_prev_time); - wf.add_vector_form_surf(res_form_surf_1_cranic, res_form_surf_1_ord, BDY_1, - &sln_prev_time); - wf.add_vector_form_surf(res_form_surf_4_cranic, res_form_surf_4_ord, BDY_4, - &sln_prev_time); - wf.add_vector_form_surf(res_form_surf_6_cranic, res_form_surf_6_ord, BDY_6, - &sln_prev_time); - } + CustomWeakForm wf; // Error estimate and discrete problem size as a function of physical time. SimpleGraph graph_time_err_est, graph_time_err_exact, graph_time_dof, graph_time_cpu; From fd03f97e24ff961f69f2ef55fac02b8af89ba72d Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 19 Nov 2013 15:44:06 +0100 Subject: [PATCH 59/64] Some progress & fixes. --- 1d/moving-front/definitions.cpp | 10 +++++----- 2d-advanced/maxwell/magnetostatics/definitions.cpp | 4 ++-- 2d-advanced/richards/CMakeLists.txt | 2 +- .../moving-front-space-adapt/definitions.cpp | 10 +++++----- 2d-benchmarks-nist/09-wave-front/main.cpp | 2 +- 2d-benchmarks-nist/11-kellogg/definitions.cpp | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/1d/moving-front/definitions.cpp b/1d/moving-front/definitions.cpp index 24b8f83..d3ec480 100644 --- a/1d/moving-front/definitions.cpp +++ b/1d/moving-front/definitions.cpp @@ -43,8 +43,8 @@ CustomVectorFormVol::CustomVectorFormVol(int i, : VectorFormVol(i), coeff(coeff), gt(gt) { this->set_area(area); - // If coeff is HERMES_ONE, initialize it to be constant 1.0. - if (coeff == HERMES_ONE) this->coeff = new Hermes::Hermes2DFunction(1.0); + // If coeff is nullptr, initialize it to be constant 1.0. + if (coeff == nullptr) this->coeff = new Hermes::Hermes2DFunction(1.0); } CustomVectorFormVol::CustomVectorFormVol(int i, @@ -52,14 +52,14 @@ CustomVectorFormVol::CustomVectorFormVol(int i, : VectorFormVol(i), coeff(coeff), gt(gt) { this->set_areas(areas); - // If coeff is HERMES_ONE, initialize it to be constant 1.0. - if (coeff == HERMES_ONE) this->coeff = new Hermes::Hermes2DFunction(1.0); + // If coeff is nullptr, initialize it to be constant 1.0. + if (coeff == nullptr) this->coeff = new Hermes::Hermes2DFunction(1.0); } CustomVectorFormVol::~CustomVectorFormVol() { // FIXME: Should be deleted here only if it was created here. - //if (coeff != HERMES_ONE) delete coeff; + //if (coeff != nullptr) delete coeff; }; double CustomVectorFormVol::value(int n, double *wt, Func *u_ext[], Func *v, diff --git a/2d-advanced/maxwell/magnetostatics/definitions.cpp b/2d-advanced/maxwell/magnetostatics/definitions.cpp index 04d65d0..8968165 100644 --- a/2d-advanced/maxwell/magnetostatics/definitions.cpp +++ b/2d-advanced/maxwell/magnetostatics/definitions.cpp @@ -8,12 +8,12 @@ CustomWeakFormMagnetostatics::CustomWeakFormMagnetostatics(std::string material_ // Jacobian. add_matrix_form(new DefaultJacobianMagnetostatics(0, 0, Hermes::vector(material_air, material_copper), - 1.0, HERMES_DEFAULT_SPLINE, HERMES_NONSYM, HERMES_AXISYM_Y, order_inc)); + 1.0, nullptr, HERMES_NONSYM, HERMES_AXISYM_Y, order_inc)); add_matrix_form(new DefaultJacobianMagnetostatics(0, 0, Hermes::vector(material_iron_1, material_iron_2), 1.0, mu_inv_iron, HERMES_NONSYM, HERMES_AXISYM_Y, order_inc)); // Residual. add_vector_form(new DefaultResidualMagnetostatics(0, Hermes::vector(material_air, material_copper), - 1.0, HERMES_ONE, HERMES_AXISYM_Y, order_inc)); + 1.0, nullptr, HERMES_AXISYM_Y, order_inc)); add_vector_form(new DefaultResidualMagnetostatics(0, Hermes::vector(material_iron_1, material_iron_2), 1.0, mu_inv_iron, HERMES_AXISYM_Y, order_inc)); add_vector_form(new DefaultVectorFormVol(0, material_copper, new Hermes2DFunction(-current_density * mu_vacuum))); diff --git a/2d-advanced/richards/CMakeLists.txt b/2d-advanced/richards/CMakeLists.txt index 7a5c1e1..d86dcfe 100644 --- a/2d-advanced/richards/CMakeLists.txt +++ b/2d-advanced/richards/CMakeLists.txt @@ -4,4 +4,4 @@ add_subdirectory(basic-rk-newton) add_subdirectory(basic-rk-newton-adapt) #add_subdirectory(capillary-barrier-rk) add_subdirectory(capillary-barrier-adapt) -add_subdirectory(seepage-adapt) +#add_subdirectory(seepage-adapt) \ No newline at end of file diff --git a/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp b/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp index 8f14a3f..3e5a649 100644 --- a/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp +++ b/2d-benchmarks-general/moving-front-space-adapt/definitions.cpp @@ -60,8 +60,8 @@ CustomVectorFormVol::CustomVectorFormVol(int i, std::string area, : VectorFormVol(i), coeff(coeff), gt(gt) { this->set_area(area); - // If coeff is HERMES_ONE, initialize it to be constant 1.0. - if (coeff == HERMES_ONE) this->coeff = new Hermes::Hermes2DFunction(1.0); + // If coeff is nullptr, initialize it to be constant 1.0. + if (coeff == nullptr) this->coeff = new Hermes::Hermes2DFunction(1.0); } CustomVectorFormVol::CustomVectorFormVol(int i, Hermes::vector areas, @@ -70,14 +70,14 @@ CustomVectorFormVol::CustomVectorFormVol(int i, Hermes::vector area : VectorFormVol(i), coeff(coeff), gt(gt) { this->set_areas(areas); - // If coeff is HERMES_ONE, initialize it to be constant 1.0. - if (coeff == HERMES_ONE) this->coeff = new Hermes::Hermes2DFunction(1.0); + // If coeff is nullptr, initialize it to be constant 1.0. + if (coeff == nullptr) this->coeff = new Hermes::Hermes2DFunction(1.0); } CustomVectorFormVol::~CustomVectorFormVol() { // FIXME: Should be deleted here only if it was created here. - //if (coeff != HERMES_ONE) delete coeff; + //if (coeff != nullptr) delete coeff; }; double CustomVectorFormVol::value(int n, double *wt, Func *u_ext[], Func *v, diff --git a/2d-benchmarks-nist/09-wave-front/main.cpp b/2d-benchmarks-nist/09-wave-front/main.cpp index 6964826..19b6d68 100644 --- a/2d-benchmarks-nist/09-wave-front/main.cpp +++ b/2d-benchmarks-nist/09-wave-front/main.cpp @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) // Initialize the weak formulation. CustomWeakForm wf(&rhs); // Equivalent, but slower: - // WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, HERMES_ONE, &rhs); + // WeakFormsH1::DefaultWeakFormPoisson wf(HERMES_ANY, nullptr, &rhs); // Initialize boundary conditions. DefaultEssentialBCNonConst bc("Bdy", exact_sln); diff --git a/2d-benchmarks-nist/11-kellogg/definitions.cpp b/2d-benchmarks-nist/11-kellogg/definitions.cpp index d00730e..ee6c283 100644 --- a/2d-benchmarks-nist/11-kellogg/definitions.cpp +++ b/2d-benchmarks-nist/11-kellogg/definitions.cpp @@ -63,9 +63,9 @@ CustomWeakFormPoisson::CustomWeakFormPoisson(std::string area_1, double r, std:: { // Jacobian. add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion(0, 0, area_1, new Hermes1DFunction(r))); - add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion(0, 0, area_2, HERMES_ONE)); + add_matrix_form(new WeakFormsH1::DefaultJacobianDiffusion(0, 0, area_2, nullptr)); // Residual. add_vector_form(new WeakFormsH1::DefaultResidualDiffusion(0, area_1, new Hermes1DFunction(r))); - add_vector_form(new WeakFormsH1::DefaultResidualDiffusion(0, area_2, HERMES_ONE)); + add_vector_form(new WeakFormsH1::DefaultResidualDiffusion(0, area_2, nullptr)); } From 903ff6ebd890bda36b718a75fcfa0bcb2d284031 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 19 Nov 2013 15:44:23 +0100 Subject: [PATCH 60/64] Start working on profile conductor example. --- 2d-advanced/maxwell/CMakeLists.txt | 1 + .../maxwell/profile-conductor/CMakeLists.txt | 3 + .../maxwell/profile-conductor/definitions.cpp | 1429 +++++++++++++++++ .../maxwell/profile-conductor/definitions.h | 610 +++++++ .../maxwell/profile-conductor/domain.xml | 1 + .../maxwell/profile-conductor/main.cpp | 0 6 files changed, 2044 insertions(+) create mode 100644 2d-advanced/maxwell/profile-conductor/CMakeLists.txt create mode 100644 2d-advanced/maxwell/profile-conductor/definitions.cpp create mode 100644 2d-advanced/maxwell/profile-conductor/definitions.h create mode 100644 2d-advanced/maxwell/profile-conductor/domain.xml create mode 100644 2d-advanced/maxwell/profile-conductor/main.cpp diff --git a/2d-advanced/maxwell/CMakeLists.txt b/2d-advanced/maxwell/CMakeLists.txt index e21a29d..83ee9aa 100644 --- a/2d-advanced/maxwell/CMakeLists.txt +++ b/2d-advanced/maxwell/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(resonator-time-domain-II-rk) add_subdirectory(maxwell-debye-rk) add_subdirectory(magnetostatics) add_subdirectory(microwave-oven) +#add_subdirectory(profile-conductor) \ No newline at end of file diff --git a/2d-advanced/maxwell/profile-conductor/CMakeLists.txt b/2d-advanced/maxwell/profile-conductor/CMakeLists.txt new file mode 100644 index 0000000..8fefdfe --- /dev/null +++ b/2d-advanced/maxwell/profile-conductor/CMakeLists.txt @@ -0,0 +1,3 @@ +project(profile-conductor) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp definitions.h) +set_common_target_properties(${PROJECT_NAME} "HERMES2D") \ No newline at end of file diff --git a/2d-advanced/maxwell/profile-conductor/definitions.cpp b/2d-advanced/maxwell/profile-conductor/definitions.cpp new file mode 100644 index 0000000..3e009bb --- /dev/null +++ b/2d-advanced/maxwell/profile-conductor/definitions.cpp @@ -0,0 +1,1429 @@ +#include "definitions.h" + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1::volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1* volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i] + u->val[i] * v->dx[i] / e->x[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i] + u->val[i] * v->dx[i] / e->x[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2::volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2* volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i] + u->val[i] * v->dx[i] / e->x[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[14]->val[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i] + u->val[i] * v->dx[i] / e->x[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1::volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ((ext[5]->val[i] - e->y[i] * ext[7]->val[i])*v->dx[i] + (ext[6]->val[i] + e->x[i] * ext[7]->val[i])*v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ((ext[5]->val[i] - e->y[i] * ext[7]->val[i])*v->dx[i] + (ext[6]->val[i] + e->x[i] * ext[7]->val[i])*v->dy[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1* volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ext[6]->val[i] * v->dy[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ext[6]->val[i] * v->dy[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2::volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ((ext[5]->val[i] - e->y[i] * ext[7]->val[i])*v->dx[i] + (ext[6]->val[i] + e->x[i] * ext[7]->val[i])*v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ((ext[5]->val[i] - e->y[i] * ext[7]->val[i])*v->dx[i] + (ext[6]->val[i] + e->x[i] * ext[7]->val[i])*v->dy[i])); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2* volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ext[6]->val[i] * v->dy[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[2]->val[i] * u->val[i] * ext[6]->val[i] * v->dy[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2::volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2* volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1::volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1* volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i] / (2 * M_PI*(e->x[i] + 1e-12))); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i] / (2 * M_PI*(e->x[i] + 1e-12))); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i] / (2 * M_PI*(e->x[i] + 1e-12))); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i] * v->val[i] / (2 * M_PI*(e->x[i] + 1e-12))); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * ext[10]->val[i] * u->val[i]); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, -2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i], 1)); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, -2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i], 1)); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3(*this); +} + + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3::volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, -2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] / (2 * M_PI*(e->x[i] + 1e-12)), 1)); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, -2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i] / (2 * M_PI*(e->x[i] + 1e-12)), 1)); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3* volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3::clone() const +{ + //return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3(*this); +} + + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4::volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: MatrixFormVolAgros(i, j, offsetI, offsetJ) +{ +} + + +template +Scalar volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, 2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i], 1)); + } + return result; +} + +template +Hermes::Ord volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (tern(ext[10]->val[i]>0, 2 * M_PI*this->m_markerSource->fieldInfo()->frequency()*ext[2]->val[i] * u->val[i], 1)); + } + return result; +} + +template +volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4* volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4::clone() const +{ + //return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4(*this); +} + + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1::volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[3]->val[i] * ext[14]->val[i] * (-ext[16]->val[i] * v->dx[i] + ext[17]->val[i] * v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[3]->val[i] * ext[14]->val[i] * (-ext[16]->val[i] * v->dx[i] + ext[17]->val[i] * v->dy[i])); + } + return result; +} + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1* volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1::clone() const +{ + //return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1(*this); +} + + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1::volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[3]->val[i] * ext[14]->val[i] * (-ext[16]->val[i] * v->dx[i] + ext[17]->val[i] * v->dy[i])); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-ext[3]->val[i] * ext[14]->val[i] * (-ext[16]->val[i] * v->dx[i] + ext[17]->val[i] * v->dy[i])); + } + return result; +} + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1* volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1::clone() const +{ + //return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1(*this); +} + + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1::volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[8]->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[8]->val[i] * v->val[i]); + } + return result; +} + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1* volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1::clone() const +{ + //return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1(*this); +} + + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1::volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[8]->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[8]->val[i] * v->val[i]); + } + return result; +} + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1* volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1::clone() const +{ + //return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1(*this); +} + + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2::volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[9]->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[9]->val[i] * v->val[i]); + } + return result; +} + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2* volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2::clone() const +{ + //return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2(*this); +} + + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2::volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[9]->val[i] * v->val[i]); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[9]->val[i] * v->val[i]); + } + return result; +} + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2* volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2::clone() const +{ + //return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2(*this); +} + + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3::volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[12]->val[i] / this->markerVolume() - ext[9]->val[i])); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[12]->val[i] / this->markerVolume() - ext[9]->val[i])); + } + return result; +} + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3* volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3::clone() const +{ + //return new volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3(*this); +} + + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3::volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[12]->val[i] / this->markerVolume() - ext[9]->val[i])); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[12]->val[i] / this->markerVolume() - ext[9]->val[i])); + } + return result; +} + +template +volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3* volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3::clone() const +{ + //return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3(*this); +} + + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4::volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt) +: VectorFormVolAgros(i, offsetI, offsetJ, offsetPreviousTimeExt, offsetCouplingExt), j(j) +{ +} + +template +Scalar volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[11]->val[i] / this->markerVolume() - ext[8]->val[i])); + } + return result; +} + +template +Hermes::Ord volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (ext[10]->val[i] * (ext[11]->val[i] / this->markerVolume() - ext[8]->val[i])); + } + return result; +} + +template +volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4* volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4::clone() const +{ + //return new volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4(this->i, this->j, this->m_offsetI, this->m_offsetJ, this->m_offsetPreviousTimeExt, this->m_offsetCouplingExt); + return new volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4(*this); +} + + + + +template +surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current::surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current(unsigned int i, unsigned int j, int offsetI, int offsetJ) + +: VectorFormSurfAgros(i, offsetI, offsetJ), j(j) +{ +} + +template +Scalar surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Jr*v->val[i]); + } + return result; +} + +template +Hermes::Ord surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Jr*v->val[i]); + } + return result; + +} + +template +surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current* surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current::clone() const +{ + //return new surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current(*this); +} + +template +surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current::surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current(unsigned int i, unsigned int j, int offsetI, int offsetJ) +: VectorFormSurfAgros(i, offsetI, offsetJ), j(j) +{ +} + +template +Scalar surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Jr*v->val[i]); + } + return result; +} + +template +Hermes::Ord surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Jr*v->val[i]); + } + return result; + +} + +template +surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current* surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current::clone() const +{ + //return new surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new surface_vector_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_1_1_magnetic_surface_current(*this); +} + +template +surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current::surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current(unsigned int i, unsigned int j, int offsetI, int offsetJ) + +: VectorFormSurfAgros(i, offsetI, offsetJ), j(j) +{ +} + +template +Scalar surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current::value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Scalar result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Ji*v->val[i]); + } + return result; +} + +template +Hermes::Ord surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current::ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const +{ + Hermes::Ord result(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (-Ji*v->val[i]); + } + return result; + +} + +template +surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current* surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current::clone() const +{ + //return new surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current(this->i, this->j, this->m_offsetI, this->m_offsetJ); + return new surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current(*this); +} + +template +exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential::exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential(Hermes::Hermes2D::MeshSharedPtr mesh) +: ExactSolutionScalarAgros(mesh) +{ +} + +template +Scalar exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential::value(double x, double y) const +{ + Scalar result = Ar; + return result; +} + +template +void exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential::derivatives(double x, double y, Scalar& dx, Scalar& dy) const +{ + +} + +template +exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential::exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential(Hermes::Hermes2D::MeshSharedPtr mesh) +: ExactSolutionScalarAgros(mesh) +{ +} + +template +Scalar exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential::value(double x, double y) const +{ + Scalar result = Ai; + return result; +} + +template +void exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential::derivatives(double x, double y, Scalar& dx, Scalar& dy) const +{ + +} + + +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3; +template class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4; +template class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1; +template class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1; +template class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2; +template class volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3; +template class volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4; +template class exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential; +template class exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential; +template class surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current; +template class surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current; diff --git a/2d-advanced/maxwell/profile-conductor/definitions.h b/2d-advanced/maxwell/profile-conductor/definitions.h new file mode 100644 index 0000000..ecf91cf --- /dev/null +++ b/2d-advanced/maxwell/profile-conductor/definitions.h @@ -0,0 +1,610 @@ +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_1_1_1_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_1_1_1_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_laplace_2_2_2_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_laplace_2_2_2_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_1_1_1_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_1_1_1_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_velocity_2_2_2_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_velocity_2_2_2_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_1_2_1_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_1_2_1_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_gamma_2_1_2_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_gamma_2_1_2_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_1_4_1_4* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_1_4_1_4* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_2_3_2_3* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_2_3_2_3* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_1_3_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_1_3_1* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_2_4_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_4_2_4_2* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_3_3_3_3* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_axisymmetric_linear_harmonic_current_3_3_3_3* clone() const; + +private: +}; + +template +class volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4 : public MatrixFormVol +{ +public: + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *u, + Hermes::Hermes2D::Func *v, Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_matrix_magnetic_harmonic_planar_linear_harmonic_current_4_4_4_4* clone() const; + +private: +}; + + +template +class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_remanence_1_1* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_remanence_1_1* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_1_1_current_1_1* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_1_1_current_1_1* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_planar_linear_harmonic_rhs_2_2_current_2_2* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_rhs_2_2_current_2_2* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_3_3_3_3* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_axisymmetric_linear_harmonic_vec_current_3_3_3_3* clone() const; + +private: + unsigned int j; +}; + +template +class volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4 : public VectorFormVol +{ +public: + volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4(unsigned int i, unsigned int j, int offsetI, int offsetJ, int* offsetPreviousTimeExt, int* offsetCouplingExt); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + + volume_vector_magnetic_harmonic_planar_linear_harmonic_vec_current_4_4_4_4* clone() const; + +private: + unsigned int j; +}; + + +template +class surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current : public VectorFormSurf +{ +public: + surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + surface_vector_magnetic_harmonic_planar_linear_harmonic_current_1_1_1_magnetic_surface_current* clone() const; + +private: + unsigned int j; + + + double Jr; + double Ji; +}; + + +template +class surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current : public VectorFormSurf +{ +public: + surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current(unsigned int i, unsigned int j, int offsetI, int offsetJ); + + virtual Scalar value(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + virtual Hermes::Ord ord(int n, double *wt, Hermes::Hermes2D::Func *u_ext[], Hermes::Hermes2D::Func *v, + Hermes::Hermes2D::Geom *e, Hermes::Hermes2D::Func **ext) const; + surface_vector_magnetic_harmonic_planar_linear_harmonic_current_2_2_2_magnetic_surface_current* clone() const; + +private: + unsigned int j; + + + double Jr; + double Ji; +}; + + +template +class exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential : public ExactSolutionScalarAgros +{ +public: + exact_magnetic_harmonic_planar_linear_harmonic_essential_1_1_0_magnetic_potential(Hermes::Hermes2D::MeshSharedPtr mesh); + + Scalar value(double x, double y) const; + void derivatives(double x, double y, Scalar& dx, Scalar& dy) const; + + Hermes::Ord ord(double x, double y) const + { + return Hermes::Ord(Hermes::Ord::get_max_order()); + } + +private: + + double Ar; + double Ai; +}; + + +template +class exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential : public ExactSolutionScalarAgros +{ +public: + exact_magnetic_harmonic_planar_linear_harmonic_essential_2_2_0_magnetic_potential(Hermes::Hermes2D::MeshSharedPtr mesh); + + Scalar value(double x, double y) const; + void derivatives(double x, double y, Scalar& dx, Scalar& dy) const; + + Hermes::Ord ord(double x, double y) const + { + return Hermes::Ord(Hermes::Ord::get_max_order()); + } + +private: + + double Ar; + double Ai; +}; diff --git a/2d-advanced/maxwell/profile-conductor/domain.xml b/2d-advanced/maxwell/profile-conductor/domain.xml new file mode 100644 index 0000000..8f7ad1b --- /dev/null +++ b/2d-advanced/maxwell/profile-conductor/domain.xml @@ -0,0 +1 @@ +01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980102326284044636985929810510911211311612312612712813068173443515865679094 \ No newline at end of file diff --git a/2d-advanced/maxwell/profile-conductor/main.cpp b/2d-advanced/maxwell/profile-conductor/main.cpp new file mode 100644 index 0000000..e69de29 From 0878f89ac6ab2417cd21cbbd2115f2746387c222 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Thu, 21 Nov 2013 17:58:52 +0100 Subject: [PATCH 61/64] Work on circular-obstacle-adapt. --- .../circular-obstacle-adapt/main.cpp | 90 +++++++------------ 1 file changed, 31 insertions(+), 59 deletions(-) diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index f67a5e9..a59ca81 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -1,5 +1,3 @@ - - #include "definitions.h" // The time-dependent laminar incompressible Navier-Stokes equations are @@ -31,7 +29,7 @@ const bool STOKES = false; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 0; // Number of initial mesh refinements towards boundary. -const int INIT_REF_NUM_BDY = 3; +const int INIT_REF_NUM_BDY = 1; // If this is defined, the pressure is approximated using // discontinuous L2 elements (making the velocity discreetely // divergence-free, more accurate than using a continuous @@ -49,9 +47,6 @@ const int P_INIT_PRESSURE = 1; // Adaptivity // Every UNREF_FREQth time step the mesh is unrefined. const int UNREF_FREQ = 1; -// This is a quantitative parameter of the adapt(...) function and -// it has different meanings for various adaptive strategies. -const double THRESHOLD = 0.3; // Error calculation & adaptivity. class CustomErrorCalculator : public DefaultErrorCalculator { @@ -63,6 +58,7 @@ class CustomErrorCalculator : public DefaultErrorCalculator stoppingCriterion(THRESHOLD); // Adaptivity processor class. Adapt adaptivity(&errorCalculator, &stoppingCriterion); @@ -71,7 +67,7 @@ Adapt adaptivity(&errorCalculator, &stoppingCriterion); // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. const CandList CAND_LIST = H2D_H_ISO; // Stopping criterion for adaptivity. -const double ERR_STOP = 1e-3; +const double ERR_STOP = 1e-4; // Problem parameters // Reynolds number. @@ -106,45 +102,19 @@ const std::string BDY_OBSTACLE = "b5"; // Current time (used in weak forms). double current_time = 0; -/*// Boundary condition values for x-velocity -double essential_bc_values_xvel(double x, double y, double time) { -// time-dependent inlet velocity (parabolic profile) -double val_y = VEL_INLET * y*(H-y) / (H/2.)/(H/2.); //parabolic profile with peak VEL_INLET at y = H/2 -if (time <= STARTUP_TIME) return val_y * time/STARTUP_TIME; -else return val_y; -} -*/ - -/* -void mag(int n, double* a, double* dadx, double* dady, -double* b, double* dbdx, double* dbdy, -double* out, double* outdx, double* outdy) -{ -for (int i = 0; i < n; i++) -{ -out[i] = sqrt(sqr(a[i]) + sqr(b[i])); -outdx[i] = (0.5 / out[i]) * (2.0 * a[i] * dadx[i] + 2.0 * b[i] * dbdx[i]); -outdy[i] = (0.5 / out[i]) * (2.0 * a[i] * dady[i] + 2.0 * b[i] * dbdy[i]); -} -} -*/ - int main(int argc, char* argv[]) { - HermesCommonApi.set_integral_param_value(numThreads, 1); - // Load the mesh. MeshSharedPtr mesh(new Mesh), basemesh(new Mesh); MeshReaderH2D mloader; mloader.load("domain.mesh", basemesh); // Initial mesh refinements. - //mesh->refine_all_elements(); - basemesh->refine_towards_boundary(BDY_OBSTACLE, 1, false); - // '4' is the number of levels. - basemesh->refine_towards_boundary(BDY_TOP, 1, true); - // 'true' stands for anisotropic refinements. - basemesh->refine_towards_boundary(BDY_BOTTOM, 1, true); + for(int i = 0; i < INIT_REF_NUM; i++) + basemesh->refine_all_elements(); + basemesh->refine_towards_boundary(BDY_OBSTACLE, INIT_REF_NUM_BDY, false); + basemesh->refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY, true); + basemesh->refine_towards_boundary(BDY_BOTTOM, INIT_REF_NUM_BDY, true); mesh->copy(basemesh); @@ -163,6 +133,7 @@ int main(int argc, char* argv[]) SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_PRESSURE)); #endif Hermes::vector > spaces(xvel_space, yvel_space, p_space); + adaptivity.set_spaces(spaces); // Calculate and report the number of degrees of freedom. int ndof = Space::get_num_dofs(spaces); @@ -187,6 +158,7 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); + Hermes::vector > prev_time(xvel_prev_time, yvel_prev_time, p_prev_time); MeshFunctionSharedPtr xvel_sln(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_sln(new ZeroSolution(mesh)); @@ -196,14 +168,21 @@ int main(int argc, char* argv[]) WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); // Initialize the FE problem. - DiscreteProblem dp(&wf, spaces); - + NewtonSolver newton(&wf, spaces); + newton.set_max_allowed_iterations(NEWTON_MAX_ITER); + newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); + // Initialize refinement selector. - H1ProjBasedSelector selector(CAND_LIST); + H1ProjBasedSelector selector_h1(CAND_LIST); + L2ProjBasedSelector selector_l2(CAND_LIST); // Initialize views. - VectorView vview("velocity [m/s]", new WinGeom(0, 0, 750, 240)); - ScalarView pview("pressure [Pa]", new WinGeom(0, 290, 750, 240)); + VectorView vview("velocity [m/s]", new WinGeom(0, 0, 500, 220)); + ScalarView pview("pressure [Pa]", new WinGeom(520, 0, 500, 220)); + ScalarView eview_x("Error", new WinGeom(0, 250, 500, 220)); + ScalarView eview_y("Error", new WinGeom(520, 250, 500, 220)); + ScalarView eview_p("Error", new WinGeom(0, 500, 500, 220)); + ScalarView aview("Adapted", new WinGeom(520, 500, 500, 220)); vview.set_min_max_range(0, 1.6); vview.fix_scale_width(80); pview.fix_scale_width(80); @@ -234,13 +213,9 @@ int main(int argc, char* argv[]) p_space->assign_dofs(); } - DiscreteProblem dp(&wf, spaces); - Hermes::Hermes2D::NewtonSolver newton(&dp); - // Spatial adaptivity loop. Note: xvel_prev_time, yvel_prev_time and pvel_prev_time // must not be changed during spatial adaptivity. bool done = false; int as = 1; - double err_est; do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); @@ -263,24 +238,20 @@ int main(int argc, char* argv[]) if (ts == 1) { Hermes::Mixins::Loggable::Static::info("Projecting coarse mesh solution to obtain coefficient vector on new fine mesh."); - OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_sln, yvel_sln, p_sln), - coeff_vec); + OGProjection::project_global(ref_spaces, prev_time, coeff_vec); } else { Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); - OGProjection ogProj; ogProj.project_global(ref_spaces, Hermes::vector >(xvel_prev_time, yvel_prev_time, p_prev_time), - coeff_vec); + OGProjection::project_global(ref_spaces, prev_time, coeff_vec); } + OGProjection::project_global(ref_spaces, prev_time, prev_time); + // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); try { newton.set_spaces(ref_spaces); - newton.set_max_allowed_iterations(NEWTON_MAX_ITER); - newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); - if(as == 2) - newton.output_matrix(); newton.solve(coeff_vec); } catch(Hermes::Exceptions::Exception e) @@ -300,12 +271,13 @@ int main(int argc, char* argv[]) // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - adaptivity.set_spaces(Hermes::vector >(xvel_space, yvel_space, p_space)); errorCalculator.calculate_errors(Hermes::vector >(xvel_sln, yvel_sln, p_sln), Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; - + eview_x.show(errorCalculator.get_errorMeshFunction(0)); + eview_y.show(errorCalculator.get_errorMeshFunction(1)); + eview_p.show(errorCalculator.get_errorMeshFunction(2)); // Report results. Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), @@ -324,8 +296,8 @@ int main(int argc, char* argv[]) else { Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); - done = adaptivity.adapt(Hermes::vector *>(&selector, &selector, &selector)); - + done = adaptivity.adapt(Hermes::vector *>(&selector_h1, &selector_h1, &selector_l2)); + aview.show(adaptivity.get_refinementInfoMeshFunction()); // Increase the counter of performed adaptivity steps. as++; } From 186a494daacc8b94d198bcd50fe303aa773c9d65 Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 26 Nov 2013 00:07:13 +0100 Subject: [PATCH 62/64] Finish the example for now. --- .../circular-obstacle-adapt/main.cpp | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index a59ca81..add5bc6 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -46,7 +46,11 @@ const int P_INIT_PRESSURE = 1; // Adaptivity // Every UNREF_FREQth time step the mesh is unrefined. -const int UNREF_FREQ = 1; +const int UNREF_FREQ = 5; +bool FORCE_DEREFINEMENT = false; +const int NOT_ADAPTING_REF_SPACES_SIZE = 6e4; +const int FORCE_DEREFINEMENT_REF_SPACES_SIZE = 1e5; + // Error calculation & adaptivity. class CustomErrorCalculator : public DefaultErrorCalculator { @@ -65,7 +69,7 @@ Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_H_ISO; +const CandList CAND_LIST = H2D_H_ANISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-4; @@ -146,6 +150,7 @@ int main(int argc, char* argv[]) #else NormType p_proj_norm = HERMES_H1_NORM; #endif + Hermes::vector proj_norms(vel_proj_norm, vel_proj_norm, p_proj_norm); // Solutions for the Newton's iteration and time stepping. Hermes::Mixins::Loggable::Static::info("Setting initial conditions."); @@ -154,18 +159,24 @@ int main(int argc, char* argv[]) MeshFunctionSharedPtr xvel_ref_sln(new Solution()); MeshFunctionSharedPtr yvel_ref_sln(new Solution()); MeshFunctionSharedPtr p_ref_sln(new Solution()); + Hermes::vector > ref_slns(xvel_ref_sln, yvel_ref_sln, p_ref_sln); MeshFunctionSharedPtr xvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_prev_time(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_prev_time(new ZeroSolution(mesh)); Hermes::vector > prev_time(xvel_prev_time, yvel_prev_time, p_prev_time); + MeshFunctionSharedPtr xvel_prev_time_projected(new ZeroSolution(mesh)); + MeshFunctionSharedPtr yvel_prev_time_projected(new ZeroSolution(mesh)); + MeshFunctionSharedPtr p_prev_time_projected(new ZeroSolution(mesh)); + Hermes::vector > prev_time_projected(xvel_prev_time_projected, yvel_prev_time_projected, p_prev_time_projected); MeshFunctionSharedPtr xvel_sln(new ZeroSolution(mesh)); MeshFunctionSharedPtr yvel_sln(new ZeroSolution(mesh)); MeshFunctionSharedPtr p_sln(new ZeroSolution(mesh)); + Hermes::vector > slns(xvel_sln, yvel_sln, p_sln); // Initialize weak formulation. - WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time, yvel_prev_time); + WeakFormNSNewton wf(STOKES, RE, TAU, xvel_prev_time_projected, yvel_prev_time_projected); // Initialize the FE problem. NewtonSolver newton(&wf, spaces); @@ -175,14 +186,15 @@ int main(int argc, char* argv[]) // Initialize refinement selector. H1ProjBasedSelector selector_h1(CAND_LIST); L2ProjBasedSelector selector_l2(CAND_LIST); + Hermes::vector *> selectors(&selector_h1, &selector_h1, &selector_l2); // Initialize views. VectorView vview("velocity [m/s]", new WinGeom(0, 0, 500, 220)); ScalarView pview("pressure [Pa]", new WinGeom(520, 0, 500, 220)); - ScalarView eview_x("Error", new WinGeom(0, 250, 500, 220)); - ScalarView eview_y("Error", new WinGeom(520, 250, 500, 220)); - ScalarView eview_p("Error", new WinGeom(0, 500, 500, 220)); - ScalarView aview("Adapted", new WinGeom(520, 500, 500, 220)); + ScalarView eview_x("Error - Velocity-x", new WinGeom(0, 250, 500, 220)); + ScalarView eview_y("Error - Velocity-y", new WinGeom(520, 250, 500, 220)); + ScalarView eview_p("Error - Pressure", new WinGeom(0, 500, 500, 220)); + ScalarView aview("Adapted elements", new WinGeom(520, 500, 500, 220)); vview.set_min_max_range(0, 1.6); vview.fix_scale_width(80); pview.fix_scale_width(80); @@ -201,7 +213,8 @@ int main(int argc, char* argv[]) Space::update_essential_bc_values(spaces, current_time); // Periodic global derefinements. - if (ts > 1 && ts % UNREF_FREQ == 0) { + if ((ts > 1) && (ts % UNREF_FREQ == 0 || FORCE_DEREFINEMENT)) + { Hermes::Mixins::Loggable::Static::info("Global mesh derefinement."); mesh->copy(basemesh); xvel_space->set_uniform_order(P_INIT_VEL); @@ -211,10 +224,10 @@ int main(int argc, char* argv[]) xvel_space->assign_dofs(); yvel_space->assign_dofs(); p_space->assign_dofs(); + + FORCE_DEREFINEMENT = false; } - // Spatial adaptivity loop. Note: xvel_prev_time, yvel_prev_time and pvel_prev_time - // must not be changed during spatial adaptivity. bool done = false; int as = 1; do { Hermes::Mixins::Loggable::Static::info("Time step %d, adaptivity step %d:", ts, as); @@ -244,8 +257,9 @@ int main(int argc, char* argv[]) Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to obtain coefficient vector on new fine mesh."); OGProjection::project_global(ref_spaces, prev_time, coeff_vec); } - - OGProjection::project_global(ref_spaces, prev_time, prev_time); + + Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to the new mesh - without this, the calculation fails."); + OGProjection::project_global(ref_spaces, prev_time, prev_time_projected); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); @@ -260,27 +274,23 @@ int main(int argc, char* argv[]) }; // Update previous time level solutions. - Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, ref_slns); // Project the fine mesh solution onto the coarse mesh. Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); - OGProjection ogProj; ogProj.project_global(Hermes::vector >(xvel_space, yvel_space, p_space), - Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln), - Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector(vel_proj_norm, vel_proj_norm, p_proj_norm) ); + OGProjection ogProj; ogProj.project_global(spaces, ref_slns, slns, proj_norms); // Calculate element errors and total error estimate. Hermes::Mixins::Loggable::Static::info("Calculating error estimate."); - errorCalculator.calculate_errors(Hermes::vector >(xvel_sln, yvel_sln, p_sln), - Hermes::vector >(xvel_ref_sln, yvel_ref_sln, p_ref_sln)); + errorCalculator.calculate_errors(slns, ref_slns); double err_est_rel_total = errorCalculator.get_total_error_squared() * 100; + eview_x.show(errorCalculator.get_errorMeshFunction(0)); eview_y.show(errorCalculator.get_errorMeshFunction(1)); eview_p.show(errorCalculator.get_errorMeshFunction(2)); // Report results. - Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", - Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)), + Hermes::Mixins::Loggable::Static::info("ndof: %d, ref_ndof: %d, err_est_rel: %g%%", Space::get_num_dofs(spaces), Space::get_num_dofs(ref_spaces), err_est_rel_total); // Show the solution at the end of time step. @@ -292,14 +302,18 @@ int main(int argc, char* argv[]) pview.show(p_ref_sln); // If err_est too large, adapt the mesh. - if (err_est_rel_total < ERR_STOP) done = true; + if (err_est_rel_total < ERR_STOP || Space::get_num_dofs(ref_spaces) > NOT_ADAPTING_REF_SPACES_SIZE) + done = true; else { Hermes::Mixins::Loggable::Static::info("Adapting the coarse mesh."); - done = adaptivity.adapt(Hermes::vector *>(&selector_h1, &selector_h1, &selector_l2)); + done = adaptivity.adapt(selectors); aview.show(adaptivity.get_refinementInfoMeshFunction()); // Increase the counter of performed adaptivity steps. as++; + + if (Space::get_num_dofs(ref_spaces) > FORCE_DEREFINEMENT_REF_SPACES_SIZE) + FORCE_DEREFINEMENT = false; } // Clean up. @@ -313,7 +327,7 @@ int main(int argc, char* argv[]) p_prev_time->copy(p_ref_sln); } - ndof = Space::get_num_dofs(Hermes::vector >(xvel_space, yvel_space, p_space)); + ndof = Space::get_num_dofs(spaces); Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof); // Wait for all views to be closed. From 4c6e0fd65110aa7124497f45d52460c5144ddaab Mon Sep 17 00:00:00 2001 From: Lukas Korous Date: Tue, 26 Nov 2013 01:50:59 +0100 Subject: [PATCH 63/64] Further work on a proper discretization of N-S adaptivity example. --- .../circular-obstacle-adapt/main.cpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp index add5bc6..24b816c 100644 --- a/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp +++ b/2d-advanced/navier-stokes/circular-obstacle-adapt/main.cpp @@ -29,14 +29,15 @@ const bool STOKES = false; // Number of initial uniform mesh refinements. const int INIT_REF_NUM = 0; // Number of initial mesh refinements towards boundary. -const int INIT_REF_NUM_BDY = 1; +const int INIT_REF_NUM_BDY = 0; +const int INIT_REF_NUM_OBSTACLE = 0; // If this is defined, the pressure is approximated using // discontinuous L2 elements (making the velocity discreetely // divergence-free, more accurate than using a continuous // pressure approximation). Otherwise the standard continuous // elements are used. The results are striking - check the // tutorial for comparisons. -//#define PRESSURE_IN_L2 +#define PRESSURE_IN_L2 // Initial polynomial degree for velocity components. // Note: P_INIT_VEL should always be greater than // P_INIT_PRESSURE because of the inf-sup condition. @@ -62,14 +63,14 @@ class CustomErrorCalculator : public DefaultErrorCalculator stoppingCriterion(THRESHOLD); // Adaptivity processor class. Adapt adaptivity(&errorCalculator, &stoppingCriterion); // Predefined list of element refinement candidates. Possible values are // H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, // H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. -const CandList CAND_LIST = H2D_H_ANISO; +const CandList CAND_LIST = H2D_H_ISO; // Stopping criterion for adaptivity. const double ERR_STOP = 1e-4; @@ -82,7 +83,7 @@ const double VEL_INLET = 1.0; // from 0 to VEL_INLET, then it stays constant. const double STARTUP_TIME = 1.0; // Time step. -const double TAU = 0.001; +const double TAU = 0.1; // Time interval length. const double T_FINAL = 30000.0; // Stopping criterion for Newton on fine mesh. @@ -93,9 +94,6 @@ const int NEWTON_MAX_ITER = 20; // velocity profile at inlet). const double H = 5; -// Current time (defined as global since needed in weak forms). -double TIME = 0; - // Boundary markers. const std::string BDY_BOTTOM = "b1"; const std::string BDY_RIGHT = "b2"; @@ -116,9 +114,9 @@ int main(int argc, char* argv[]) // Initial mesh refinements. for(int i = 0; i < INIT_REF_NUM; i++) basemesh->refine_all_elements(); - basemesh->refine_towards_boundary(BDY_OBSTACLE, INIT_REF_NUM_BDY, false); - basemesh->refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY, true); - basemesh->refine_towards_boundary(BDY_BOTTOM, INIT_REF_NUM_BDY, true); + basemesh->refine_towards_boundary(BDY_OBSTACLE, INIT_REF_NUM_OBSTACLE, false); + basemesh->refine_towards_boundary(BDY_TOP, INIT_REF_NUM_BDY, false); + basemesh->refine_towards_boundary(BDY_BOTTOM, INIT_REF_NUM_BDY, false); mesh->copy(basemesh); @@ -182,7 +180,8 @@ int main(int argc, char* argv[]) NewtonSolver newton(&wf, spaces); newton.set_max_allowed_iterations(NEWTON_MAX_ITER); newton.set_tolerance(NEWTON_TOL, Hermes::Solvers::ResidualNormAbsolute); - + newton.output_matrix(); + // Initialize refinement selector. H1ProjBasedSelector selector_h1(CAND_LIST); L2ProjBasedSelector selector_l2(CAND_LIST); @@ -246,6 +245,9 @@ int main(int argc, char* argv[]) Hermes::vector > ref_spaces(ref_xvel_space, ref_yvel_space, ref_p_space); + Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC."); + Space::update_essential_bc_values(ref_spaces, current_time); + // Calculate initial coefficient vector for Newton on the fine mesh. double* coeff_vec = new double[Space::get_num_dofs(ref_spaces)]; @@ -259,7 +261,7 @@ int main(int argc, char* argv[]) } Hermes::Mixins::Loggable::Static::info("Projecting previous fine mesh solution to the new mesh - without this, the calculation fails."); - OGProjection::project_global(ref_spaces, prev_time, prev_time_projected); + //OGProjection::project_global(ref_spaces, prev_time, prev_time_projected); // Perform Newton's iteration. Hermes::Mixins::Loggable::Static::info("Solving nonlinear problem:"); @@ -294,10 +296,10 @@ int main(int argc, char* argv[]) Space::get_num_dofs(ref_spaces), err_est_rel_total); // Show the solution at the end of time step. - sprintf(title, "Velocity, time %g", TIME); + sprintf(title, "Velocity, time %g", current_time); vview.set_title(title); vview.show(xvel_ref_sln, yvel_ref_sln); - sprintf(title, "Pressure, time %g", TIME); + sprintf(title, "Pressure, time %g", current_time); pview.set_title(title); pview.show(p_ref_sln); From 92b1d326d43b90493e987eccda372e888987d9bd Mon Sep 17 00:00:00 2001 From: Tomas Svaton Date: Sat, 24 May 2014 15:03:58 +0200 Subject: [PATCH 64/64] I would be pleased if you check this for the forcing of h-FEM. Thank you in advance. Tomas. --- .../distortion/CMakeLists.txt | 3 + .../distortion/definitions.cpp | 738 + .../distortion/definitions.h | 572 + .../elasticity-linear/distortion/main.cpp | 322 + .../distortion/rect_1-1_Q.mesh | 20 + .../distortion/rect_1-1_Q.xml | 28 + .../distortion/rect_3-1_Q.mesh | 32 + .../distortion/rect_3-1_Q.xml | 40 + .../distortion/rect_3-3_Q.mesh | 52 + .../distortion/rect_3-3_Q.xml | 60 + .../distortion/squareCoarse.xml | 443 + .../distortion/squareECoarse.xml | 77 + .../distortion/squareFine.xml | 4508 ++++ .../distortion/squareNormal.xml | 1634 ++ .../distortion/squareTiny.xml | 18086 ++++++++++++++++ 15 files changed, 26615 insertions(+) create mode 100644 2d-advanced/elasticity-linear/distortion/CMakeLists.txt create mode 100644 2d-advanced/elasticity-linear/distortion/definitions.cpp create mode 100644 2d-advanced/elasticity-linear/distortion/definitions.h create mode 100644 2d-advanced/elasticity-linear/distortion/main.cpp create mode 100644 2d-advanced/elasticity-linear/distortion/rect_1-1_Q.mesh create mode 100644 2d-advanced/elasticity-linear/distortion/rect_1-1_Q.xml create mode 100644 2d-advanced/elasticity-linear/distortion/rect_3-1_Q.mesh create mode 100644 2d-advanced/elasticity-linear/distortion/rect_3-1_Q.xml create mode 100644 2d-advanced/elasticity-linear/distortion/rect_3-3_Q.mesh create mode 100644 2d-advanced/elasticity-linear/distortion/rect_3-3_Q.xml create mode 100644 2d-advanced/elasticity-linear/distortion/squareCoarse.xml create mode 100644 2d-advanced/elasticity-linear/distortion/squareECoarse.xml create mode 100644 2d-advanced/elasticity-linear/distortion/squareFine.xml create mode 100644 2d-advanced/elasticity-linear/distortion/squareNormal.xml create mode 100644 2d-advanced/elasticity-linear/distortion/squareTiny.xml diff --git a/2d-advanced/elasticity-linear/distortion/CMakeLists.txt b/2d-advanced/elasticity-linear/distortion/CMakeLists.txt new file mode 100644 index 0000000..5c4a425 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/CMakeLists.txt @@ -0,0 +1,3 @@ +project(distortion) +add_executable(${PROJECT_NAME} main.cpp definitions.cpp definitions.h) +set_common_target_properties(${PROJECT_NAME} "HERMES2D") diff --git a/2d-advanced/elasticity-linear/distortion/definitions.cpp b/2d-advanced/elasticity-linear/distortion/definitions.cpp new file mode 100644 index 0000000..cb3a4cf --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/definitions.cpp @@ -0,0 +1,738 @@ +#include "definitions.h" + +CustomWeakFormLinearElasticity::CustomWeakFormLinearElasticity(double E, double nu, Hermes2DFunction* Eo11d, Hermes2DFunction* Eo12d, Hermes2DFunction* Eo22d, Hermes2DFunction* Eo33d, double Eo11, double Eo12, double Eo22, double Eo33, double rho_g, + std::string surface_force_bdy, double f0, double f1) : WeakForm(3) +{ + double lambda = (E * nu) / ((1 + nu) * (1 - 2 * nu)); + double mu = E / (2 * (1 + nu)); + double kappa = 2.0 * (2.0 * E - 3.0 * nu) / 3 / (1 + nu) / (1 - 2 * nu); + + // SINGLE-COMPONENT FORMS. USEFUL FOR MULTIMESH, DO NOT REMOVE. + // Jacobian. + add_matrix_form(new CustomJacobianElast00(0, 0, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast01(0, 1, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast02(0, 2, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast10(1, 0, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast11(1, 1, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast12(1, 2, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast20(2, 0, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast21(2, 1, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + add_matrix_form(new CustomJacobianElast22(2, 2, lambda, mu, kappa, Eo11, Eo12, Eo22, Eo33)); + + //Residuals + add_vector_form(new CustomVectorRes0(0, lambda, mu, kappa, Eo11d, Eo12d, Eo22d, Eo33d, Eo11, Eo12, Eo22, Eo33)); + add_vector_form(new CustomVectorRes1(1, lambda, mu, kappa, Eo11d, Eo12d, Eo22d, Eo33d, Eo11, Eo12, Eo22, Eo33)); + add_vector_form(new CustomVectorRes2(2, lambda, mu, kappa, Eo11d, Eo12d, Eo22d, Eo33d, Eo11, Eo12, Eo22, Eo33)); +} + +// Jacobian lin elast 0-0 +double CustomWeakFormLinearElasticity::CustomJacobianElast00::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((lambda + 2.0 * mu) * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + //result += wt[i] * ((kappa + 4.0 * mu / 3.0) * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + result += - wt[i] * (4.0*mu/3.0 * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast00::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((lambda + 2.0 * mu) * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + //result += wt[i] * ((kappa + 4.0 * mu / 3.0) * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + result += - wt[i] * (4.0*mu/3.0 * u->dx[i] * v->dx[i] + mu * u->dy[i] * v->dy[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast00::clone() const +{ + return new CustomJacobianElast00(*this); +} + +// Jacobian lin elast 0-1 +double CustomWeakFormLinearElasticity::CustomJacobianElast01::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += - wt[i] * (-2.0*mu/3.0 * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast01::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += - wt[i] * (-2.0*mu/3.0 * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast01::clone() const +{ + return new CustomJacobianElast01(*this); +} + +// Jacobian lin elast 0-2 +double CustomWeakFormLinearElasticity::CustomJacobianElast02::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->val[i] * v->dx[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast02::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->val[i] * v->dx[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast02::clone() const +{ + return new CustomJacobianElast02(*this); +} + +// Jacobian lin elast 1-0 +double CustomWeakFormLinearElasticity::CustomJacobianElast10::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dy[i] * v->dx[i] + lambda * u->dx[i] * v->dy[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dx[i] * v->dy[i] + mu * u->dy[i] * v->dx[i]); + result += - wt[i] * ((-2.0*mu/3.0) * u->dx[i] * v->dy[i] + mu * u->dy[i] * v->dx[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast10::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dy[i] * v->dx[i] + lambda * u->dx[i] * v->dy[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dx[i] * v->dy[i] + mu * u->dy[i] * v->dx[i]); + result += - wt[i] * ((-2.0*mu/3.0) * u->dx[i] * v->dy[i] + mu * u->dy[i] * v->dx[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast10::clone() const +{ + return new CustomJacobianElast10(*this); +} + +// Jacobian lin elast 1-1 +double CustomWeakFormLinearElasticity::CustomJacobianElast11::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((lambda + 2 * mu) * u->dy[i] * v->dy[i] + mu * u->dx[i] * v->dx[i]); + //result += wt[i] * ((kappa + 4.0 * mu / 3.0) * u->dy[i] * v->dy[i] + mu * u->dx[i] * v->dx[i]); + result += - wt[i] * (mu * u->dx[i] * v->dx[i] + 4.0*mu/3.0 * u->dy[i] * v->dy[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast11::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((lambda + 2 * mu) * u->dy[i] * v->dy[i] + mu * u->dx[i] * v->dx[i]); + //result += wt[i] * ((kappa + 4.0 * mu / 3.0) * u->dy[i] * v->dy[i] + mu * u->dx[i] * v->dx[i]); + result += - wt[i] * (mu * u->dx[i] * v->dx[i] + 4.0*mu/3.0 * u->dy[i] * v->dy[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast11::clone() const +{ + return new CustomJacobianElast11(*this); +} + +// Jacobian lin elast 1-2 +double CustomWeakFormLinearElasticity::CustomJacobianElast12::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->val[i] * v->dy[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast12::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->val[i] * v->dy[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast12::clone() const +{ + return new CustomJacobianElast12(*this); +} + +// Jacobian lin elast 2-0 +double CustomWeakFormLinearElasticity::CustomJacobianElast20::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->dx[i] * v->val[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast20::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->dx[i] * v->val[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast20::clone() const +{ + return new CustomJacobianElast20(*this); +} + +// Jacobian lin elast 2-1 +double CustomWeakFormLinearElasticity::CustomJacobianElast21::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->dy[i] * v->val[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast21::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (u->dy[i] * v->val[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast21::clone() const +{ + return new CustomJacobianElast21(*this); +} + +// Jacobian lin elast 2-2 +double CustomWeakFormLinearElasticity::CustomJacobianElast22::value(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (1.0/kappa * u->val[i] * v->val[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomJacobianElast22::ord(int n, double *wt, Func *u_ext[], + Func *u, Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * (mu * u->dx[i] * v->dy[i] + lambda * u->dy[i] * v->dx[i]); + //result += wt[i] * ((kappa - 2.0 * mu / 3.0) * u->dy[i] * v->dx[i] + mu * u->dx[i] * v->dy[i]); + result += wt[i] * (1.0/kappa * u->val[i] * v->val[i]); + } + return result; +} +MatrixFormVol* CustomWeakFormLinearElasticity::CustomJacobianElast22::clone() const +{ + return new CustomJacobianElast22(*this); +} + +//residuum lin elast 0 +double CustomWeakFormLinearElasticity::CustomVectorRes0::value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11) + lambda * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dy[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dy[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11d->value(e->x[i],e->y[i])) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i]))) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dy[i]); + result += - wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11d->value(e->x[i],e->y[i])) - (2.0*mu/3.0 * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) + u_ext[2]->val[i])) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dy[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomVectorRes0::ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11) + lambda * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dy[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dy[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11d->value(e->x[i],e->y[i])) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i]))) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dy[i]); + result += - wt[i] * ((2.0 * mu * (u_ext[0]->dx[i] - Eo11d->value(e->x[i],e->y[i])) - (2.0*mu/3.0 * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) + u_ext[2]->val[i])) * v->dx[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dy[i]); + } + return result; +} +VectorFormVol* CustomWeakFormLinearElasticity::CustomVectorRes0::clone() const +{ + return new CustomVectorRes0(*this); +} + +//residuum lin elast 1 +double CustomWeakFormLinearElasticity::CustomVectorRes1::value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22) + lambda * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dx[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dx[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22d->value(e->x[i],e->y[i])) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i]))) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dx[i]); + result += - wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22d->value(e->x[i],e->y[i])) - (2.0*mu/3.0 * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) + u_ext[2]->val[i])) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dx[i]); + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomVectorRes1::ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22) + lambda * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dx[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11 - Eo22 - Eo33)) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12) * v->dx[i]); + //result += wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22d->value(e->x[i],e->y[i])) + (kappa - 2.0 * mu / 3.0) * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i]))) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dx[i]); + result += - wt[i] * ((2.0 * mu * (u_ext[1]->dy[i] - Eo22d->value(e->x[i],e->y[i])) - (2.0*mu/3.0 * (u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) + u_ext[2]->val[i])) * v->dy[i] + mu * (u_ext[0]->dy[i] + u_ext[1]->dx[i] - 2.0 * Eo12d->value(e->x[i],e->y[i])) * v->dx[i]); + } + return result; +} +VectorFormVol* CustomWeakFormLinearElasticity::CustomVectorRes1::clone() const +{ + return new CustomVectorRes1(*this); +} + +//residuum lin elast 2 +double CustomWeakFormLinearElasticity::CustomVectorRes2::value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const +{ + double result = 0; + for (int i = 0; i < n; i++) + { + result += wt[i] * (u_ext[2]->val[i]/kappa + u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) * v->val[i]; + } + return result; +} +Ord CustomWeakFormLinearElasticity::CustomVectorRes2::ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const +{ + Ord result = Ord(0); + for (int i = 0; i < n; i++) + { + result += wt[i] * (u_ext[2]->val[i]/kappa + u_ext[0]->dx[i] + u_ext[1]->dy[i] - Eo11d->value(e->x[i],e->y[i]) - Eo22d->value(e->x[i],e->y[i]) - Eo33d->value(e->x[i],e->y[i])) * v->val[i]; + } + return result; +} +VectorFormVol* CustomWeakFormLinearElasticity::CustomVectorRes2::clone() const +{ + return new CustomVectorRes2(*this); +} + +// Custom exact function Eo11 +double CustomExactFunctionEo11::val(double x, double y) +{ + double stepBot = dist * (1.0 / 3.0 + 0.0 * Hermes::sin(8.0 * M_PI * x) / 50 < y); + double stepTop = dist * (2.0 / 3.0 + 0.0 * Hermes::sin(2.0 * M_PI * x) / 25 < y); + return stepBot - stepTop; +} +double CustomExactFunctionEo11::dx(double x, double y) +{ + return 0.0; // this does not correspond to the value +} +double CustomExactFunctionEo11::ddxx(double x, double y) +{ + return 0.0; // this also probably +} + +// Custom exact function Eo12 +double CustomExactFunctionEo12::val(double x, double y) +{ + double stepBot = dist * (1.0 / 3.0 + 0.0 * Hermes::sin(8.0 * M_PI * x) / 50 < y); + double stepTop = dist * (2.0 / 3.0 + 0.0 * Hermes::sin(2.0 * M_PI * x) / 25 < y); + return stepBot - stepTop; +} +double CustomExactFunctionEo12::dx(double x, double y) +{ + return 0.0; // this does not correspond to the value +} + +// Custom exact function Eo22 +double CustomExactFunctionEo22::val(double x, double y) +{ + double stepBot = dist * (1.0 / 3.0 + 0.0 * Hermes::sin(8.0 * M_PI * x) / 50 < y); + double stepTop = dist * (2.0 / 3.0 + 0.0 * Hermes::sin(2.0 * M_PI * x) / 25 < y); + return stepBot - stepTop; +} +double CustomExactFunctionEo22::dx(double x, double y) +{ + return 0.0; // this does not correspond to the value +} + +// Custom exact function Eo33 +double CustomExactFunctionEo33::val(double x, double y) +{ + double stepBot = dist * (1.0 / 3.0 + 0.0 * Hermes::sin(8.0 * M_PI * x) / 50 < y); + double stepTop = dist * (2.0 / 3.0 + 0.0 * Hermes::sin(2.0 * M_PI * x) / 25 < y); + return stepBot - stepTop; +} +double CustomExactFunctionEo33::dx(double x, double y) +{ + return 0.0; // this does not correspond to the value +} + +// Eo11 Hermes2DFunction +CustomEo11::CustomEo11(double dist) + : Hermes2DFunction(), dist(dist) +{ + cefEo11 = new CustomExactFunctionEo11(dist); +} +double CustomEo11::value(double x, double y) const +{ + return cefEo11->val(x,y); +} +Ord CustomEo11::value(Ord x, Ord y) const +{ + return Ord(10); +} +CustomEo11::~CustomEo11() +{ + delete cefEo11; +} + +// Eo12 Hermes2DFunction +CustomEo12::CustomEo12(double dist) + : Hermes2DFunction(), dist(dist) +{ + cefEo12 = new CustomExactFunctionEo12(dist); +} +double CustomEo12::value(double x, double y) const +{ + return cefEo12->val(x,y); +} +Ord CustomEo12::value(Ord x, Ord y) const +{ + return Ord(10); +} +CustomEo12::~CustomEo12() +{ + delete cefEo12; +} + +// Eo22 Hermes2DFunction +CustomEo22::CustomEo22(double dist) + : Hermes2DFunction(), dist(dist) +{ + cefEo22 = new CustomExactFunctionEo22(dist); +} +double CustomEo22::value(double x, double y) const +{ + return cefEo22->val(x,y); +} +Ord CustomEo22::value(Ord x, Ord y) const +{ + return Ord(10); +} +CustomEo22::~CustomEo22() +{ + delete cefEo22; +} + +// Eo33 Hermes2DFunction +CustomEo33::CustomEo33(double dist) + : Hermes2DFunction(), dist(dist) +{ + cefEo33 = new CustomExactFunctionEo33(dist); +} +double CustomEo33::value(double x, double y) const +{ + return cefEo33->val(x,y); +} +Ord CustomEo33::value(Ord x, Ord y) const +{ + return Ord(10); +} +CustomEo33::~CustomEo33() +{ + delete cefEo33; +} + +// Exact Function Solution Eo11 +ExactSolutionEo11::ExactSolutionEo11(MeshSharedPtr mesh, double dist) + : ExactSolutionScalar(mesh), dist(dist) +{ + cefEo11 = new CustomExactFunctionEo11(dist); +} +double ExactSolutionEo11::value(double x, double y) const +{ + return cefEo11->val(x,y); +} +void ExactSolutionEo11::derivatives(double x, double y, double& dx, double& dy) const +{ + dx = cefEo11->dx(x,y); + dy = -cefEo11->dx(x,y); +} +Ord ExactSolutionEo11::ord(double x, double y) const +{ + return Ord(10); +} +ExactSolutionEo11::~ExactSolutionEo11() +{ + delete cefEo11; +} +MeshFunction* ExactSolutionEo11::clone() const +{ + return new ExactSolutionEo11(this->mesh,this->dist); +} + +// Exact Function Solution Eo12 +ExactSolutionEo12::ExactSolutionEo12(MeshSharedPtr mesh, double dist) + : ExactSolutionScalar(mesh), dist(dist) +{ + cefEo12 = new CustomExactFunctionEo12(dist); +} +double ExactSolutionEo12::value(double x, double y) const +{ + return cefEo12->val(x,y); +} +void ExactSolutionEo12::derivatives(double x, double y, double& dx, double& dy) const +{ + dx = cefEo12->dx(x,y); + dy = -cefEo12->dx(x,y); +} +Ord ExactSolutionEo12::ord(double x, double y) const +{ + return Ord(10); +} +ExactSolutionEo12::~ExactSolutionEo12() +{ + delete cefEo12; +} +MeshFunction* ExactSolutionEo12::clone() const +{ + return new ExactSolutionEo12(this->mesh,this->dist); +} + +// Exact Function Solution Eo22 +ExactSolutionEo22::ExactSolutionEo22(MeshSharedPtr mesh, double dist) + : ExactSolutionScalar(mesh), dist(dist) +{ + cefEo22 = new CustomExactFunctionEo22(dist); +} +double ExactSolutionEo22::value(double x, double y) const +{ + return cefEo22->val(x,y); +} +void ExactSolutionEo22::derivatives(double x, double y, double& dx, double& dy) const +{ + dx = cefEo22->dx(x,y); + dy = -cefEo22->dx(x,y); +} +Ord ExactSolutionEo22::ord(double x, double y) const +{ + return Ord(10); +} +ExactSolutionEo22::~ExactSolutionEo22() +{ + delete cefEo22; +} +MeshFunction* ExactSolutionEo22::clone() const +{ + return new ExactSolutionEo22(this->mesh,this->dist); +} + +// Exact Function Solution Eo33 +ExactSolutionEo33::ExactSolutionEo33(MeshSharedPtr mesh, double dist) + : ExactSolutionScalar(mesh), dist(dist) +{ + cefEo33 = new CustomExactFunctionEo33(dist); +} +double ExactSolutionEo33::value(double x, double y) const +{ + return cefEo33->val(x,y); +} +void ExactSolutionEo33::derivatives(double x, double y, double& dx, double& dy) const +{ + dx = cefEo33->dx(x,y); + dy = -cefEo33->dx(x,y); +} +Ord ExactSolutionEo33::ord(double x, double y) const +{ + return Ord(10); +} +ExactSolutionEo33::~ExactSolutionEo33() +{ + delete cefEo33; +} +MeshFunction* ExactSolutionEo33::clone() const +{ + return new ExactSolutionEo33(this->mesh,this->dist); +} + +// Exact Function Solution tr(Eo) +ExactSolutionTrEo::ExactSolutionTrEo(MeshSharedPtr mesh, double Eo11, double Eo22, double Eo33) + : ExactSolutionScalar(mesh), Eo11(Eo11), Eo22(Eo22), Eo33(Eo33) +{ + cefEo11 = new CustomExactFunctionEo11(Eo11); + cefEo22 = new CustomExactFunctionEo22(Eo22); + cefEo33 = new CustomExactFunctionEo33(Eo33); +} +double ExactSolutionTrEo::value(double x, double y) const +{ + return cefEo11->val(x,y)+cefEo22->val(x,y)+cefEo33->val(x,y); +} +void ExactSolutionTrEo::derivatives(double x, double y, double& dx, double& dy) const +{ + dx = cefEo11->dx(x,y); + dy = -cefEo11->dx(x,y); +} +Ord ExactSolutionTrEo::ord(double x, double y) const +{ + return Ord(10); +} +ExactSolutionTrEo::~ExactSolutionTrEo() +{ + delete cefEo11, cefEo22, cefEo33; +} +MeshFunction* ExactSolutionTrEo::clone() const +{ + return new ExactSolutionTrEo(this->mesh,this->Eo11,this->Eo22,this->Eo33); +} + +// Custom filter S11 +void CustomFilterS11::filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, + double* out, double* outdx, double* outdy) +{ + for (int i = 0; i < n; i++) + { + out[i] = 2.0 * mu * (dx.at(0)[i] - this->Eo11d->value(x[i],y[i])) - 2.0/3.0*mu * (dx.at(0)[i] + dy.at(1)[i]-this->Eo11d->value(x[i],y[i])-this->Eo22d->value(x[i],y[i])-this->Eo33d->value(x[i],y[i])) - values.at(2)[i]; + outdx[i] = 0.0; + outdy[i] = 0.0; + } +} + +// Custom filter S12 +void CustomFilterS12::filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, + double* out, double* outdx, double* outdy) +{ + for (int i = 0; i < n; i++) + { + out[i] = mu * ((dy.at(0)[i] + dx.at(1)[i]) - 2.0 * this->Eo12d->value(x[i],y[i])); + outdx[i] = 0.0; + outdy[i] = 0.0; + } +} + +// Custom filter S22 +void CustomFilterS22::filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, + double* out, double* outdx, double* outdy) +{ + for (int i = 0; i < n; i++) + { + out[i] = 2.0 * mu * (dy.at(1)[i] - this->Eo22d->value(x[i],y[i])) - 2.0/3.0*mu * (dx.at(0)[i] + dy.at(1)[i]-this->Eo11d->value(x[i],y[i])-this->Eo22d->value(x[i],y[i])-this->Eo33d->value(x[i],y[i])) - values.at(2)[i]; + outdx[i] = 0.0; + outdy[i] = 0.0; + } +} + +// Custom filter S33 +void CustomFilterS33::filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, + double* out, double* outdx, double* outdy) +{ + for (int i = 0; i < n; i++) + { + out[i] = - 2.0 * mu * this->Eo33d->value(x[i],y[i]) - 2.0/3.0*mu * (dx.at(0)[i] + dy.at(1)[i]-this->Eo11d->value(x[i],y[i])-this->Eo22d->value(x[i],y[i])-this->Eo33d->value(x[i],y[i])) - values.at(2)[i]; + outdx[i] = 0.0; + outdy[i] = 0.0; + } +} + +// Custom filter von Mises (with distortions) +void CustomFilter_vM::filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, + double* out, double* outdx, double* outdy) +{ + for (int i = 0; i < n; i++) + { + double S11S22 = 2.0 * mu * (dx.at(0)[i] - dy.at(1)[i] - (this->Eo11d->value(x[i],y[i]) - this->Eo22d->value(x[i],y[i]))); + double S11S33 = 2.0 * mu * (dx.at(0)[i] - (this->Eo11d->value(x[i],y[i]) - this->Eo33d->value(x[i],y[i]))); + double S22S33 = 2.0 * mu * (dy.at(1)[i] - (this->Eo22d->value(x[i],y[i]) - this->Eo33d->value(x[i],y[i]))); + double S12 = mu * (dy.at(0)[i] + dx.at(1)[i] - this->Eo12d->value(x[i],y[i])); + out[i] = 1.0/Hermes::pow(2.0, 0.5) * Hermes::pow((Hermes::pow(S11S22, 2.0) + Hermes::pow(S11S33, 2.0) + Hermes::pow(S22S33, 2.0) + 6 * Hermes::pow(S12, 2.0)), 0.5); + outdx[i] = 0.0; + outdy[i] = 0.0; + } +} diff --git a/2d-advanced/elasticity-linear/distortion/definitions.h b/2d-advanced/elasticity-linear/distortion/definitions.h new file mode 100644 index 0000000..6059271 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/definitions.h @@ -0,0 +1,572 @@ +#include "hermes2d.h" + +using namespace Hermes; +using namespace Hermes::Hermes2D; +using namespace Hermes::Hermes2D::WeakFormsH1; +using namespace Hermes::Hermes2D::WeakFormsElasticity; +using namespace Hermes::Hermes2D::Views; +using namespace Hermes::Hermes2D::RefinementSelectors; + +class CustomWeakFormLinearElasticity : public WeakForm +{ +public: + CustomWeakFormLinearElasticity(double E, double nu, Hermes2DFunction* Eo11d, Hermes2DFunction* Eo12d, Hermes2DFunction* Eo22d, Hermes2DFunction* Eo33d, double Eo11, double Eo12, double Eo22, double Eo33, double rho_g, + std::string surface_force_bdy, double f0, double f1); // +private: + class CustomJacobianElast00 : public MatrixFormVol + { + public: + CustomJacobianElast00(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast01 : public MatrixFormVol + { + public: + CustomJacobianElast01(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast02 : public MatrixFormVol + { + public: + CustomJacobianElast02(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast10 : public MatrixFormVol + { + public: + CustomJacobianElast10(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast11 : public MatrixFormVol + { + public: + CustomJacobianElast11(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast12 : public MatrixFormVol + { + public: + CustomJacobianElast12(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast20 : public MatrixFormVol + { + public: + CustomJacobianElast20(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast21 : public MatrixFormVol + { + public: + CustomJacobianElast21(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomJacobianElast22 : public MatrixFormVol + { + public: + CustomJacobianElast22(int i, int j, double lambda, double mu, double kappa, double Eo11, double Eo12, double Eo22, double Eo33) + : MatrixFormVol(i, j), lambda(lambda), mu(mu), kappa(kappa), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) {}; + virtual double value(int n, double *wt, Func *u_ext[], Func *u, + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *u, Func *v, + Geom *e, Func* *ext) const; + virtual MatrixFormVol* clone() const; + protected: + double lambda; + double mu; + double kappa; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomVectorRes0 : public VectorFormVol + { + public: + CustomVectorRes0(int i, double lambda, double mu, double kappa, Hermes2DFunction* Eo11d, Hermes2DFunction* Eo12d, Hermes2DFunction* Eo22d, Hermes2DFunction* Eo33d, double Eo11, double Eo12, double Eo22, double Eo33) + : VectorFormVol(i), lambda(lambda), mu(mu), kappa(kappa), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const; + + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const; + virtual VectorFormVol* clone() const; + private: + double lambda; + double mu; + double kappa; + Hermes2DFunction* Eo11d; + Hermes2DFunction* Eo12d; + Hermes2DFunction* Eo22d; + Hermes2DFunction* Eo33d; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomVectorRes1 : public VectorFormVol + { + public: + CustomVectorRes1(int i, double lambda, double mu, double kappa, Hermes2DFunction* Eo11d, Hermes2DFunction* Eo12d, Hermes2DFunction* Eo22d, Hermes2DFunction* Eo33d, double Eo11, double Eo12, double Eo22, double Eo33) + : VectorFormVol(i), lambda(lambda), mu(mu), kappa(kappa), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const; + virtual VectorFormVol* clone() const; + private: + double lambda; + double mu; + double kappa; + Hermes2DFunction* Eo11d; + Hermes2DFunction* Eo12d; + Hermes2DFunction* Eo22d; + Hermes2DFunction* Eo33d; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; + class CustomVectorRes2 : public VectorFormVol + { + public: + CustomVectorRes2(int i, double lambda, double mu, double kappa, Hermes2DFunction* Eo11d, Hermes2DFunction* Eo12d, Hermes2DFunction* Eo22d, Hermes2DFunction* Eo33d, double Eo11, double Eo12, double Eo22, double Eo33) + : VectorFormVol(i), lambda(lambda), mu(mu), kappa(kappa), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d), Eo11(Eo11), Eo12(Eo12), Eo22(Eo22), Eo33(Eo33) + { + } + + virtual double value(int n, double *wt, Func *u_ext[], + Func *v, Geom *e, Func* *ext) const; + virtual Ord ord(int n, double *wt, Func *u_ext[], Func *v, + Geom *e, Func* *ext) const; + virtual VectorFormVol* clone() const; + private: + double lambda; + double mu; + double kappa; + Hermes2DFunction* Eo11d; + Hermes2DFunction* Eo12d; + Hermes2DFunction* Eo22d; + Hermes2DFunction* Eo33d; + double Eo11; + double Eo12; + double Eo22; + double Eo33; + }; +}; + +// Custom function Eo11 +class CustomExactFunctionEo11 +{ +public: + CustomExactFunctionEo11(double dist) : dist(dist) {}; + double val(double x, double y); + double dx(double x, double y); + double ddxx(double x, double y); +protected : + double dist; +}; + +// Custom function Eo12 +class CustomExactFunctionEo12 +{ +public: + CustomExactFunctionEo12(double dist) : dist(dist) {}; + double val(double x, double y); + double dx(double x, double y); +protected : + double dist; +}; + +// Custom function Eo22 +class CustomExactFunctionEo22 +{ +public: + CustomExactFunctionEo22(double dist) : dist(dist) {}; + double val(double x, double y); + double dx(double x, double y); +protected : + double dist; +}; + +// Custom function Eo33 +class CustomExactFunctionEo33 +{ +public: + CustomExactFunctionEo33(double dist) : dist(dist) {}; + double val(double x, double y); + double dx(double x, double y); +protected : + double dist; +}; + +// Eo11 Hermes2DFunction +class CustomEo11: public Hermes2DFunction +{ +public: + CustomEo11(double dist); + virtual double value(double x, double y) const; + virtual Ord value(Ord x, Ord y) const; + ~CustomEo11(); + CustomExactFunctionEo11* cefEo11; +protected : + double dist; +}; + +// Eo12 Hermes2DFunction +class CustomEo12: public Hermes2DFunction +{ +public: + CustomEo12(double dist); + virtual double value(double x, double y) const; + virtual Ord value(Ord x, Ord y) const; + ~CustomEo12(); + CustomExactFunctionEo12* cefEo12; +protected : + double dist; +}; + +// Eo22 Hermes2DFunction +class CustomEo22: public Hermes2DFunction +{ +public: + CustomEo22(double dist); + virtual double value(double x, double y) const; + virtual Ord value(Ord x, Ord y) const; + ~CustomEo22(); + CustomExactFunctionEo22* cefEo22; +protected : + double dist; +}; + +// Eo33 Hermes2DFunction +class CustomEo33: public Hermes2DFunction +{ +public: + CustomEo33(double dist); + virtual double value(double x, double y) const; + virtual Ord value(Ord x, Ord y) const; + ~CustomEo33(); + CustomExactFunctionEo33* cefEo33; +protected : + double dist; +}; + +// Exact solution Eo11 +class ExactSolutionEo11 : public ExactSolutionScalar +{ +public: + ExactSolutionEo11(MeshSharedPtr mesh, double dist); + virtual double value(double x, double y) const; + virtual void derivatives(double x, double y, double& dx, double& dy) const; + virtual Ord ord(double x, double y) const; + ~ExactSolutionEo11(); + virtual MeshFunction* clone() const; + CustomExactFunctionEo11* cefEo11; +protected : + double dist; +}; + +// Exact solution Eo12 +class ExactSolutionEo12 : public ExactSolutionScalar +{ +public: + ExactSolutionEo12(MeshSharedPtr mesh, double dist); + virtual double value(double x, double y) const; + virtual void derivatives(double x, double y, double& dx, double& dy) const; + virtual Ord ord(double x, double y) const; + ~ExactSolutionEo12(); + virtual MeshFunction* clone() const; + CustomExactFunctionEo12* cefEo12; +protected : + double dist; +}; + +// Exact solution Eo22 +class ExactSolutionEo22 : public ExactSolutionScalar +{ +public: + ExactSolutionEo22(MeshSharedPtr mesh, double dist); + virtual double value(double x, double y) const; + virtual void derivatives(double x, double y, double& dx, double& dy) const; + virtual Ord ord(double x, double y) const; + ~ExactSolutionEo22(); + virtual MeshFunction* clone() const; + CustomExactFunctionEo22* cefEo22; +protected : + double dist; +}; + +// Exact solution Eo33 +class ExactSolutionEo33 : public ExactSolutionScalar +{ +public: + ExactSolutionEo33(MeshSharedPtr mesh, double dist); + virtual double value(double x, double y) const; + virtual void derivatives(double x, double y, double& dx, double& dy) const; + virtual Ord ord(double x, double y) const; + ~ExactSolutionEo33(); + virtual MeshFunction* clone() const; + CustomExactFunctionEo33* cefEo33; +protected : + double dist; +}; + +// Exact solution TrEo +class ExactSolutionTrEo : public ExactSolutionScalar +{ +public: + ExactSolutionTrEo(MeshSharedPtr mesh, double Eo11, double Eo22, double Eo33); + virtual double value(double x, double y) const; + virtual void derivatives(double x, double y, double& dx, double& dy) const; + virtual Ord ord(double x, double y) const; + ~ExactSolutionTrEo(); + virtual MeshFunction* clone() const; + CustomExactFunctionEo11* cefEo11; + CustomExactFunctionEo22* cefEo22; + CustomExactFunctionEo33* cefEo33; +protected : + double Eo11; + double Eo22; + double Eo33; +}; + +// Custom filter S11 +class CustomFilterS11 : public Hermes::Hermes2D::DXDYFilter +{ +public: + CustomFilterS11(Hermes::vector> solutions, double lambda, double mu, CustomEo11* Eo11d, CustomEo12* Eo12d, CustomEo22* Eo22d, CustomEo33* Eo33d) : Hermes::Hermes2D::DXDYFilter(solutions), lambda(lambda), mu(mu), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d) +{ +} +virtual MeshFunction* clone() const +{ + Hermes::vector > slns; + for(int i = 0; i < this->num; i++) + { + slns.push_back(this->sln[i]->clone()); + } + CustomFilterS11* filter = new CustomFilterS11(slns, lambda, mu, Eo11d, Eo12d, Eo22d, Eo33d); + return filter; +} +private: +virtual void filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, double* rslt, double* rslt_dx, double* rslt_dy); +double mu, lambda; +CustomEo11* Eo11d; +CustomEo12* Eo12d; +CustomEo22* Eo22d; +CustomEo33* Eo33d; +}; + +// Custom filter S12 +class CustomFilterS12 : public Hermes::Hermes2D::DXDYFilter +{ +public: + CustomFilterS12(Hermes::vector> solutions, double lambda, double mu, CustomEo11* Eo11d, CustomEo12* Eo12d, CustomEo22* Eo22d, CustomEo33* Eo33d) : Hermes::Hermes2D::DXDYFilter(solutions), lambda(lambda), mu(mu), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d) +{ +} +virtual MeshFunction* clone() const +{ + Hermes::vector > slns; + for(int i = 0; i < this->num; i++) + { + slns.push_back(this->sln[i]->clone()); + } + CustomFilterS12* filter = new CustomFilterS12(slns, lambda, mu, Eo11d, Eo12d, Eo22d, Eo33d); + return filter; +} +private: +virtual void filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, double* rslt, double* rslt_dx, double* rslt_dy); +double mu, lambda; +CustomEo11* Eo11d; +CustomEo12* Eo12d; +CustomEo22* Eo22d; +CustomEo33* Eo33d; +}; + +// Custom filter S22 +class CustomFilterS22 : public Hermes::Hermes2D::DXDYFilter +{ +public: + CustomFilterS22(Hermes::vector> solutions, double lambda, double mu, CustomEo11* Eo11d, CustomEo12* Eo12d, CustomEo22* Eo22d, CustomEo33* Eo33d) : Hermes::Hermes2D::DXDYFilter(solutions), lambda(lambda), mu(mu), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d) +{ +} +virtual MeshFunction* clone() const +{ + Hermes::vector > slns; + for(int i = 0; i < this->num; i++) + { + slns.push_back(this->sln[i]->clone()); + } + CustomFilterS22* filter = new CustomFilterS22(slns, lambda, mu, Eo11d, Eo12d, Eo22d, Eo33d); + return filter; +} +private: +virtual void filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, double* rslt, double* rslt_dx, double* rslt_dy); +double mu, lambda; +CustomEo11* Eo11d; +CustomEo12* Eo12d; +CustomEo22* Eo22d; +CustomEo33* Eo33d; +}; + +// Custom filter S33 +class CustomFilterS33 : public Hermes::Hermes2D::DXDYFilter +{ +public: + CustomFilterS33(Hermes::vector> solutions, double lambda, double mu, CustomEo11* Eo11d, CustomEo12* Eo12d, CustomEo22* Eo22d, CustomEo33* Eo33d) : Hermes::Hermes2D::DXDYFilter(solutions), lambda(lambda), mu(mu), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d) +{ +} +virtual MeshFunction* clone() const +{ + Hermes::vector > slns; + for(int i = 0; i < this->num; i++) + { + slns.push_back(this->sln[i]->clone()); + } + CustomFilterS33* filter = new CustomFilterS33(slns, lambda, mu, Eo11d, Eo12d, Eo22d, Eo33d); + return filter; +} +private: +virtual void filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, double* rslt, double* rslt_dx, double* rslt_dy); +double mu, lambda; +CustomEo11* Eo11d; +CustomEo12* Eo12d; +CustomEo22* Eo22d; +CustomEo33* Eo33d; +}; + +// Custom filter von Mises (with distortion) +class CustomFilter_vM : public Hermes::Hermes2D::DXDYFilter +{ +public: + CustomFilter_vM(Hermes::vector> solutions, double lambda, double mu, CustomEo11* Eo11d, CustomEo12* Eo12d, CustomEo22* Eo22d, CustomEo33* Eo33d) : Hermes::Hermes2D::DXDYFilter(solutions), lambda(lambda), mu(mu), Eo11d(Eo11d), Eo12d(Eo12d), Eo22d(Eo22d), Eo33d(Eo33d) +{ +} +virtual MeshFunction* clone() const +{ + Hermes::vector > slns; + for(int i = 0; i < this->num; i++) + { + slns.push_back(this->sln[i]->clone()); + } + CustomFilter_vM* filter = new CustomFilter_vM(slns, lambda, mu, Eo11d, Eo12d, Eo22d, Eo33d); + return filter; +} +private: +virtual void filter_fn(int n, double* x, double* y, Hermes::vector values, Hermes::vector dx, Hermes::vector dy, double* rslt, double* rslt_dx, double* rslt_dy); +double mu, lambda; +CustomEo11* Eo11d; +CustomEo12* Eo12d; +CustomEo22* Eo22d; +CustomEo33* Eo33d; +}; diff --git a/2d-advanced/elasticity-linear/distortion/main.cpp b/2d-advanced/elasticity-linear/distortion/main.cpp new file mode 100644 index 0000000..4a837ab --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/main.cpp @@ -0,0 +1,322 @@ +#define HERMES_REPORT_ALL +#define HERMES_REPORT_FILE "application.log" +#include "definitions.h" +#include "function/function.h" + +// Read original or XML mesh file. +const bool USE_XML_FORMAT = true; +// Visualisation of the distortion and stress +const bool VIEW_DIST = false; +const bool VIEW_STRESS = false; +// Parameter influencing the candidate selection. +const double THRESHOLD = .8; +// Predefined list of element refinement candidates. Possible values are +// H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO. +const CandList CAND_LIST = H2D_H_ISO; +// Stopping criterion for adaptivity. +const double ERR_STOP = 1.0; +// Error calculation & adaptivity. +DefaultErrorCalculator errorCalculator(RelativeErrorToGlobalNorm, 3); +// Stopping criterion for an adaptivity step. +AdaptStoppingCriterionSingleElement stoppingCriterion(THRESHOLD); +// Adaptivity processor class. +Adapt adaptivity(&errorCalculator, &stoppingCriterion); +// Selector. +H1ProjBasedSelector selector(CAND_LIST); + +// Initial polynomial degree of all elements. +const int P_INIT_U = 2; +const int P_INIT_V = 2; +const int P_INIT_P = 1; + +// Newton's method. +const double NEWTON_TOL_FINE = 1e-0; +// Stopping criterion for the Newton's method. +const double NEWTON_TOL = 1e-3; +// Maximum allowed number of Newton iterations. +const int NEWTON_MAX_ITER = 25; + +// Number of initial uniform mesh refinements. +const int INIT_REF_NUM = 3; +// Matrix solver: SOLVER_AMESOS, SOLVER_AZTECOO, SOLVER_MUMPS, SOLVER_PETSC, SOLVER_SUPERLU, SOLVER_UMFPACK. +MatrixSolverType matrix_solver = SOLVER_UMFPACK; + +// Problem parameters. +// Young modulus (cautchuque). +const double E = 1000; +// Poisson ratio. +const double nu = 0.49; +// Density. +const double rho = 1010.0; +// Gravitational acceleration. +const double g1 = -9.81; +// Surface force in x-direction. +const double f0 = 0; +// Surface force in y-direction. +const double f1 = 8e4; +// Components of distortion +const double Eo11 = 0.0; +const double Eo12 = 0.0; +const double Eo22 = 0.1; +const double Eo33 = 0.0; +CustomEo11 Eo11d(Eo11); +CustomEo12 Eo12d(Eo12); +CustomEo22 Eo22d(Eo22); +CustomEo33 Eo33d(Eo33); + +int main(int argc, char* argv[]) +{ + // Time measurement + Hermes::Mixins::TimeMeasurable cpu_time; + cpu_time.tick(); + + // Load the mesh. + MeshSharedPtr mesh(new Mesh); + if (USE_XML_FORMAT == true) + { + MeshReaderH2DXML mloader; + Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format."); + mloader.load("rect_1-1_Q.xml", mesh); + } + else + { + MeshReaderH2D mloader; + Hermes::Mixins::Loggable::Static::info("Reading mesh in original format."); + mloader.load("rect_1-1_Q.mesh", mesh); + } + + // Perform uniform mesh refinement. + int refinement_type = 0; + for (int i = 0; i < INIT_REF_NUM; i++) + { + mesh->refine_all_elements(refinement_type); + } + + // Initialize boundary conditions. + DefaultEssentialBCConst disp_bot_top_x(Hermes::vector("Bottom","Top"), 0.0); + DefaultEssentialBCConst disp_bot_y("Bottom", 0.0); + DefaultEssentialBCConst disp_top_y("Top", 0.0); + EssentialBCs bcs_x(&disp_bot_top_x); + EssentialBCs bcs_y(Hermes::vector *>(&disp_bot_y, &disp_top_y)); + + // Create x- and y- displacement space using the default H1 shapeset. + SpaceSharedPtr u_space(new H1Space(mesh, &bcs_x, P_INIT_U)); + SpaceSharedPtr v_space(new H1Space(mesh, &bcs_y, P_INIT_V)); + SpaceSharedPtr p_space(new H1Space(mesh, P_INIT_P)); + Hermes::vector> spaces(u_space, v_space, p_space); + // Set the spaces to adaptivity. + adaptivity.set_spaces(spaces); + + // Initialise coarse and reference mesh solutions + MeshFunctionSharedPtr u_sln(new Solution), v_sln(new Solution), p_sln(new Solution), + u_ref_sln(new Solution), v_ref_sln(new Solution), p_ref_sln(new Solution); + + Hermes::vector> solutions(u_sln, v_sln, p_sln); + Hermes::vector> ref_solutions(u_ref_sln, v_ref_sln, p_ref_sln); + + // DOF and CPU convergence graphs. + SimpleGraph graph_dof_est, graph_cpu_est; + SimpleGraph graph_dof_exact, graph_cpu_exact; + + // Initialize the weak formulation. + CustomWeakFormLinearElasticity wf(E, nu, &Eo11d, &Eo12d, &Eo22d, &Eo33d, Eo11, Eo12, Eo22, Eo33, rho*g1, "Top", f0, f1); + + // Initialize the FE problem. + DiscreteProblem dp(&wf, spaces); + // Initialize Newton solver. + NewtonSolver newton(&dp); + newton.set_verbose_output(true); + newton.set_tolerance(1e-3, Hermes::Solvers::ResidualNormAbsolute); + + // Initialize views. + Views::OrderView o_view_0("Mesh u", new Views::WinGeom(0, 0, 420, 350)); + Views::OrderView o_view_1("Mesh v", new Views::WinGeom(450, 0, 420, 350)); + Views::OrderView o_view_2("Mesh p", new Views::WinGeom(1330, 0, 420, 350)); + Views::ScalarView s_view_0("Solution u [m]", new Views::WinGeom(0, 380, 440, 350)); + Views::ScalarView s_view_1("Solution v [m]", new Views::WinGeom(470, 380, 440, 350)); + Views::ScalarView s_view_2("Solution p [Pa]", new Views::WinGeom(940, 380, 440, 350)); + s_view_0.show_mesh(false); + s_view_1.show_mesh(false); + s_view_2.show_mesh(false); + + Views::ScalarView viewEo22("Distortion Eo22 [1]", new Views::WinGeom(690, 710, 680, 400)); + Views::ScalarView viewTrEo("Distortion Tr(Eo) [1]", new Views::WinGeom(690, 710, 680, 400)); + viewEo22.show_mesh(false); + viewTrEo.show_mesh(false); + + Views::ScalarView viewU("Displacement u [m]", new Views::WinGeom(0, 710, 680, 400)); + Views::ScalarView viewV("Displacement v [m]", new Views::WinGeom(690, 710, 680, 400)); + Views::ScalarView viewP("Pressure p [Pa]", new Views::WinGeom(390, 410, 680, 400)); + viewU.show_mesh(false); + viewV.show_mesh(false); + viewP.show_mesh(false); + + Views::ScalarView viewS11("Stress S11 [Pa]", new Views::WinGeom(20, 40, 680, 400)); + Views::ScalarView viewS12("Stress S12 [Pa]", new Views::WinGeom(120, 80, 680, 400)); + Views::ScalarView viewS22("Stress S22 [Pa]", new Views::WinGeom(220, 120, 680, 400)); + Views::ScalarView viewS33("Stress S33 [Pa]", new Views::WinGeom(320, 160, 680, 400)); + Views::ScalarView view_vM("Stress von Mises [Pa]", new Views::WinGeom(420, 200, 680, 400)); + viewS11.show_mesh(false); + viewS12.show_mesh(false); + viewS22.show_mesh(false); + viewS33.show_mesh(false); + view_vM.show_mesh(false); + + // Adaptivity loop: + int as = 1; + bool done = false; + do + { + Hermes::Mixins::Loggable::Static::info(" ---- Adaptivity step %d:", as); + + // Construct globally refined reference mesh and setup reference space. + Mesh::ReferenceMeshCreator ref_mesh_creator(mesh); + MeshSharedPtr ref_mesh = ref_mesh_creator.create_ref_mesh(); + Space::ReferenceSpaceCreator u_ref_space_creator(u_space, ref_mesh); + SpaceSharedPtr u_ref_space = u_ref_space_creator.create_ref_space(); + Space::ReferenceSpaceCreator v_ref_space_creator(v_space, ref_mesh); + SpaceSharedPtr v_ref_space = v_ref_space_creator.create_ref_space(); + Space::ReferenceSpaceCreator p_ref_space_creator(p_space, ref_mesh); + SpaceSharedPtr p_ref_space = p_ref_space_creator.create_ref_space(); +/* + MeshView mvu("Mesh u", new WinGeom(0, 0, 580, 400)); + mvu.show(u_mesh); + MeshView mvv("Mesh v", new WinGeom(500, 0, 580, 400)); + mvv.show(v_mesh); + MeshView mvp("Mesh p", new WinGeom(800, 0, 580, 400)); + mvp.show(p_mesh); + + MeshView mvru("Mesh ref u", new WinGeom(0, 600, 580, 400)); + mvru.show(u_ref_mesh); + MeshView mvrv("Mesh ref v", new WinGeom(500, 600, 580, 400)); + mvrv.show(v_ref_mesh); + MeshView mvrp("Mesh ref p", new WinGeom(800, 600, 580, 400)); + mvrp.show(p_ref_mesh); +*/ + Hermes::vector> ref_spaces(u_ref_space, v_ref_space, p_ref_space); + + int ndof_ref = Space::get_num_dofs(ref_spaces); + + // Initialize reference problem. + Hermes::Mixins::Loggable::Static::info("Solving on reference mesh."); + + // Time measurement. + cpu_time.tick(); + + // Perform Newton's iteration. + try + { + newton.set_spaces(ref_spaces); + newton.solve(); + } + catch(std::exception& e) + { + std::cout << e.what(); + } + + // Translate the resulting coefficient vector into the instance of Solution. + Solution::vector_to_solutions(newton.get_sln_vector(), ref_spaces, ref_solutions); + + // Project the fine mesh solution onto the coarse mesh. + Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh."); + OGProjection::project_global(spaces, ref_solutions, solutions); + + cpu_time.tick(); +/* + // View the coarse mesh solution and polynomial orders. + s_view_0.show(u_sln); + s_view_1.show(v_sln); + s_view_2.show(p_sln); + o_view_0.show(u_space); + o_view_1.show(v_space); + o_view_2.show(p_space); +*/ + // View the refined mesh solution and polynomial orders. + s_view_0.show(u_ref_sln); + s_view_1.show(v_ref_sln); + s_view_2.show(p_ref_sln); + o_view_0.show(u_ref_space); + o_view_1.show(v_ref_space); + o_view_2.show(p_ref_space); + + // Calculate error estimate. + errorCalculator.calculate_errors(solutions, ref_solutions); + double err_est_rel = errorCalculator.get_total_error_squared() * 100; + + // Time measurement. + cpu_time.tick(); + + // Report results. + Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d", + u_space->get_num_dofs(), u_ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d", + v_space->get_num_dofs(), v_ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse[2]: %d, ndof_fine[2]: %d", + p_space->get_num_dofs(), p_ref_space->get_num_dofs()); + Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d", + Space::get_num_dofs(spaces), Space::get_num_dofs(ref_spaces)); + Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%", err_est_rel); + + // Add entry to DOF and CPU convergence graphs. + graph_dof_est.add_values(Space::get_num_dofs(spaces), err_est_rel); + graph_dof_est.save("conv_dof_est.dat"); + graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel); + graph_cpu_est.save("conv_cpu_est.dat"); + + // If err_est too large, adapt the mesh. + if (err_est_rel < ERR_STOP) + done = true; + else + { + Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh."); + done = adaptivity.adapt(Hermes::vector*>(&selector, &selector, &selector)); + } + + // Increase counter. + as++; + } + while (as<2); // ! ! ! attention this is to control the number of iterations to be replaced by the line bottom +// while (done == false); + + Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated()); + + // Distortion visualisation + if (VIEW_DIST == true) + { + MeshFunctionSharedPtr exact_Eo22(new ExactSolutionEo22(mesh, Eo22)); + viewEo22.show(exact_Eo22); + + MeshFunctionSharedPtr exact_TrEo(new ExactSolutionTrEo(mesh, Eo11, Eo22, Eo33)); + viewTrEo.show(exact_TrEo); + } + + // Stress visualisation + if (VIEW_STRESS == true) + { + // First Lame constant. + double lambda = (E * nu) / ((1 + nu) * (1 - 2*nu)); + // Second Lame constant. + double mu = E / (2 * (1 + nu)); + + // Visualize the solution. + MeshFunctionSharedPtr S11(new CustomFilterS11(solutions, lambda, mu, &Eo11d, &Eo12d, &Eo22d, &Eo33d)); + MeshFunctionSharedPtr S12(new CustomFilterS12(solutions, lambda, mu, &Eo11d, &Eo12d, &Eo22d, &Eo33d)); + MeshFunctionSharedPtr S22(new CustomFilterS22(solutions, lambda, mu, &Eo11d, &Eo12d, &Eo22d, &Eo33d)); + MeshFunctionSharedPtr S33(new CustomFilterS33(solutions, lambda, mu, &Eo11d, &Eo12d, &Eo22d, &Eo33d)); + MeshFunctionSharedPtr vM(new CustomFilter_vM(solutions, lambda, mu, &Eo11d, &Eo12d, &Eo22d, &Eo33d)); + + viewU.show(u_sln); + viewV.show(v_sln); + viewP.show(p_sln); + viewS11.show(S11, HERMES_EPS_HIGH, H2D_FN_VAL_0, u_sln, v_sln, 1.0); + viewS12.show(S12, HERMES_EPS_HIGH, H2D_FN_VAL_0, u_sln, v_sln, 1.0); + viewS22.show(S22, HERMES_EPS_HIGH, H2D_FN_VAL_0, u_sln, v_sln, 1.0); + viewS33.show(S33, HERMES_EPS_HIGH, H2D_FN_VAL_0, u_sln, v_sln, 1.0); + view_vM.show(vM, HERMES_EPS_HIGH, H2D_FN_VAL_0, u_sln, v_sln, 1.0); + } + + // Wait for the view to be closed. + View::wait(); + + return 0; +} diff --git a/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.mesh b/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.mesh new file mode 100644 index 0000000..82ca1b1 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.mesh @@ -0,0 +1,20 @@ +a = 1.0 +b = 1.0 + +vertices = [ + [ 0, 0 ], # vertex 0 + [ a, 0 ], # vertex 1 + [ a, b ], # vertex 2 + [ 0, b ] # vertex 3 +] + +elements = [ + [ 0, 1, 2, 3, "Mat" ] # quad 0 +] + +boundaries = [ + [ 0, 1, "Bottom" ], + [ 1, 2, "BndR" ], + [ 2, 3, "Top" ], + [ 3, 0, "BndL" ] +] diff --git a/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.xml b/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.xml new file mode 100644 index 0000000..d1ce661 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_1-1_Q.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.mesh b/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.mesh new file mode 100644 index 0000000..fd6baae --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.mesh @@ -0,0 +1,32 @@ +a = 1.0 +b = 1.0 +b3 = 0.333333333333333 +b23 = 0.666666666666667 + +vertices = [ + [ 0, 0 ], # vertex 0 + [ a, 0 ], # vertex 1 + [ a, b3 ], # vertex 2 + [ a, b23 ], # vertex 3 + [ a, b ], # vertex 4 + [ 0, b ], # vertex 5 + [ 0, b23 ], # vertex 6 + [ 0, b3 ] # vertex 7 +] + +elements = [ + [ 0, 1, 2, 7, "Mat" ] # quad 0 + [ 7, 2, 3, 6, "Mat" ] # quad 1 + [ 6, 3, 4, 5, "Mat" ] # quad 2 +] + +boundaries = [ + [ 0, 1, "Bottom" ], + [ 1, 2, "BndR" ], + [ 2, 3, "BndR" ], + [ 3, 4, "BndR" ], + [ 4, 5, "Top" ], + [ 5, 6, "BndL" ], + [ 6, 7, "BndL" ], + [ 7, 0, "BndL" ] +] diff --git a/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.xml b/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.xml new file mode 100644 index 0000000..8fb70f4 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_3-1_Q.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.mesh b/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.mesh new file mode 100644 index 0000000..c64bfda --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.mesh @@ -0,0 +1,52 @@ +a = 1.0 +a3 = 0.333333333333333 +a23 = 0.666666666666667 +b = 1.0 +b3 = 0.333333333333333 +b23 = 0.666666666666667 + +vertices = [ + [ 0, 0 ], # vertex 0 + [ a3, 0 ], # vertex 1 + [ a23, 0 ], # vertex 2 + [ a, 0 ], # vertex 3 + [ a, b3 ], # vertex 4 + [ a, b23 ], # vertex 5 + [ a, b ], # vertex 6 + [ a23, b ], # vertex 7 + [ a3, b ], # vertex 8 + [ 0, b ], # vertex 9 + [ 0, b23 ], # vertex 10 + [ 0, b3 ], # vertex 11 + [ a3, b3 ], # vertex 12 + [ a23, b3 ], # vertex 13 + [ a23, b23 ], # vertex 14 + [ a3, b23 ] # vertex 15 +] + +elements = [ + [ 0, 1, 12, 11, "Mat" ] # quad 0 + [ 1, 2, 13, 12, "Mat" ] # quad 1 + [ 2, 3, 4, 13, "Mat" ] # quad 2 + [ 13, 4, 5, 14, "Mat" ] # quad 3 + [ 14, 5, 6, 7, "Mat" ] # quad 4 + [ 15, 14, 7, 8, "Mat" ] # quad 5 + [ 10, 15, 8, 9, "Mat" ] # quad 6 + [ 11, 12, 15, 10, "Mat" ] # quad 7 + [ 12, 13, 14, 15, "Mat" ] # quad 8 +] + +boundaries = [ + [ 0, 1, "Bottom" ], + [ 1, 2, "Bottom" ], + [ 2, 3, "Bottom" ], + [ 3, 4, "BndR" ], + [ 4, 5, "BndR" ], + [ 5, 6, "BndR" ], + [ 6, 7, "Top" ], + [ 7, 8, "Top" ], + [ 8, 9, "Top" ], + [ 9, 10, "BndL" ], + [ 10, 11, "BndL" ], + [ 11, 0, "BndL" ] +] diff --git a/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.xml b/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.xml new file mode 100644 index 0000000..9865687 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/rect_3-3_Q.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/squareCoarse.xml b/2d-advanced/elasticity-linear/distortion/squareCoarse.xml new file mode 100644 index 0000000..308b87a --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/squareCoarse.xml @@ -0,0 +1,443 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/squareECoarse.xml b/2d-advanced/elasticity-linear/distortion/squareECoarse.xml new file mode 100644 index 0000000..c747966 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/squareECoarse.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/squareFine.xml b/2d-advanced/elasticity-linear/distortion/squareFine.xml new file mode 100644 index 0000000..6e62c05 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/squareFine.xml @@ -0,0 +1,4508 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/squareNormal.xml b/2d-advanced/elasticity-linear/distortion/squareNormal.xml new file mode 100644 index 0000000..7a21896 --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/squareNormal.xml @@ -0,0 +1,1634 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/2d-advanced/elasticity-linear/distortion/squareTiny.xml b/2d-advanced/elasticity-linear/distortion/squareTiny.xml new file mode 100644 index 0000000..2ca686e --- /dev/null +++ b/2d-advanced/elasticity-linear/distortion/squareTiny.xml @@ -0,0 +1,18086 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +