From: Wolfgang Bangerth Date: Fri, 27 Sep 2013 13:04:43 +0000 (+0000) Subject: Let the main class only store a pointer to the obstacle, not the object that reads... X-Git-Tag: v8.1.0~706 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f15fc7c56ae3c7918d7b93b70429df5a74dda10e;p=dealii.git Let the main class only store a pointer to the obstacle, not the object that reads in the file. git-svn-id: https://svn.dealii.org/trunk@30981 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-42/step-42.cc b/deal.II/examples/step-42/step-42.cc index 5496cb266b..bcb91e5fce 100644 --- a/deal.II/examples/step-42/step-42.cc +++ b/deal.II/examples/step-42/step-42.cc @@ -112,7 +112,7 @@ namespace Step42 double get_value (const double x, - const double y); + const double y) const; private: std::vector obstacle_data; @@ -120,7 +120,7 @@ namespace Step42 int nx, ny; double get_pixel_value (const int i, - const int j); + const int j) const; }; @@ -154,14 +154,15 @@ namespace Step42 hy = 1.0 / (ny - 1); if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) - std::cout << "Resolution of the scanned obstacle picture: " << nx << " x " << ny + std::cout << "Read obstacle from file <" << name << ">" << std::endl + << "Resolution of the scanned obstacle picture: " << nx << " x " << ny << std::endl; } template double Input::get_pixel_value (const int i, - const int j) + const int j) const { assert(i >= 0 && i < nx); assert(j >= 0 && j < ny); @@ -172,7 +173,7 @@ namespace Step42 template double Input::get_value (const double x, - const double y) + const double y) const { const int ix = std::min(std::max((int) (x / hx), 0), nx-2); const int iy = std::min(std::max((int) (y / hy), 0), ny-2); @@ -544,11 +545,11 @@ namespace Step42 class ChineseObstacle : public Function { public: - ChineseObstacle (const std_cxx1x::shared_ptr > &input, + ChineseObstacle (const std::string &filename, const double z_max_domain) : Function(dim), - input_obstacle(input), + input_obstacle(filename), z_max_domain(z_max_domain) {} @@ -561,7 +562,7 @@ namespace Step42 Vector &values) const; private: - const std_cxx1x::shared_ptr > &input_obstacle; + const Input input_obstacle; double z_max_domain; }; @@ -578,7 +579,7 @@ namespace Step42 //component==2: if (p(0) >= 0.0 && p(0) <= 1.0 && p(1) >= 0.0 && p(1) <= 1.0) - return z_max_domain + 0.999 - input_obstacle->get_value(p(0), p(1)); + return z_max_domain + 0.999 - input_obstacle.get_value(p(0), p(1)); else return 10000.0; @@ -678,7 +679,7 @@ namespace Step42 TrilinosWrappers::PreconditionAMG::AdditionalData additional_data; TrilinosWrappers::PreconditionAMG preconditioner_u; - std_cxx1x::shared_ptr > input_obstacle; + std_cxx1x::shared_ptr > obstacle; std_cxx1x::shared_ptr > plast_lin_hard; double sigma_0; // Yield stress @@ -1276,15 +1277,6 @@ namespace Step42 void PlasticityContactProblem::update_solution_and_constraints () { - Function *obstacle; - - if (obstacle_filename != "") - obstacle = new EquationData::ChineseObstacle(input_obstacle, (base_mesh == "box" ? 1.0 : 0.5)); - else - obstacle = new EquationData::SphereObstacle((base_mesh == "box" ? 1.0 : 0.5)); - -// const EquationData::ChineseObstacle obstacle(input_obstacle, (base_mesh == "box" ? 1.0 : 0.5)); - std::vector vertex_touched(dof_handler.n_dofs(), false); typename DoFHandler::active_cell_iterator cell = @@ -1406,9 +1398,6 @@ namespace Step42 // constraints_dirichlet_hanging_nodes.print (std::cout); constraints.merge(constraints_dirichlet_hanging_nodes); - - delete obstacle; - //constraints.print (std::cout); } // @sect4{PlasticityContactProblem::dirichlet_constraints} @@ -1955,14 +1944,12 @@ namespace Step42 void PlasticityContactProblem::run () { - if (obstacle_filename != "") - { - pcout << "Read the obstacle from '" << obstacle_filename << "' ... " - << std::flush; - input_obstacle.reset(new Input(obstacle_filename.c_str())); - pcout << "done." << std::endl; - } + obstacle.reset (new EquationData::ChineseObstacle(obstacle_filename, (base_mesh == "box" ? 1.0 : 0.5))); + else + obstacle.reset (new EquationData::SphereObstacle((base_mesh == "box" ? 1.0 : 0.5))); + + computing_timer.reset(); for (cycle = 0; cycle < n_cycles; ++cycle)