A quartic convergence rate is identified by graphing log(error) vs.
These functions cannot be integrated exactly wih Gauss Quadrature, and so we look for quartic convergence to the analytical solution
log(h), where h is the length of the longest rayfire elem. Linear regression is then used to fit a line to that data. For quartic convergence, this line should have a slope of 4. A 2% tolerance for the slope value is allowed in order to keep the test runtime from becoming excessive.
154 const std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+
"/integrated_function_quad9.in";
157 libMesh::Point origin(0.0,0.0);
160 std::vector<libMesh::Real> theta;
161 theta.push_back(0.0);
162 theta.push_back(0.25);
164 for (
unsigned int t=0; t<theta.size(); t++)
166 libMesh::Real costheta = std::cos(theta[t]);
167 libMesh::Real sintheta = std::sin(theta[t]);
168 libMesh::Real L = 3.0/costheta;
170 std::vector<std::string> functions;
171 std::vector<libMesh::Real> calc_answers;
172 std::vector<libMesh::Real> tolerance;
173 std::vector<bool> converged;
176 functions.push_back(
"sin(x)+cos(y)");
179 calc_answers.push_back( L-std::cos(L)+1.0 );
181 calc_answers.push_back( ( (std::sin(L*sintheta))/sintheta ) - ( (std::cos(L*costheta)-1.0)/costheta ) );
183 tolerance.push_back(1e-9);
184 converged.push_back(
false);
187 functions.push_back(
"exp(x)");
188 calc_answers.push_back( (std::exp(3.0) - 1.0) / costheta);
189 tolerance.push_back(1e-8);
190 converged.push_back(
false);
192 std::vector<std::vector<libMesh::Real> > errors(functions.size());
193 std::vector<std::vector<libMesh::Real> > h_vals(functions.size());
196 GRINS::SharedPtr<libMesh::EquationSystems> es =
_sim->get_equation_system();
198 CPPUNIT_ASSERT_EQUAL(functions.size(), calc_answers.size());
207 GRINS::SharedPtr<GRINS::RayfireMesh> ref_rayfire(
new GRINS::RayfireMesh(origin,theta[t]));
208 ref_rayfire->init( system->get_mesh() );
210 for (
unsigned int i=0; i<functions.size(); i++)
214 comp_qoi.add_qoi(integ_func);
217 comp_qoi.init(*
_input,*system);
218 system->attach_qoi(&comp_qoi);
220 libMesh::MeshRefinement mr(system->get_mesh());
222 unsigned int num_converged = 0;
223 unsigned int iter = 0;
226 unsigned int max_iter = 7;
232 std::vector<libMesh::dof_id_type> elems_in_rayfire;
233 ref_rayfire->elem_ids_in_rayfire(elems_in_rayfire);
235 system->assemble_qoi();
238 libMesh::Real h = -1.0;
239 for (
unsigned int i=0; i<elems_in_rayfire.size(); i++)
241 libMesh::Real l = (ref_rayfire->map_to_rayfire_elem(elems_in_rayfire[i]))->length(0,1);
246 CPPUNIT_ASSERT(h > 0.0);
249 for (
unsigned int i=0; i<calc_answers.size(); i++)
253 libMesh::Real err = std::abs(
_sim->get_qoi_value(i) - calc_answers[i] );
254 if (err < tolerance[i])
258 h_vals[i].push_back(std::log10(h));
259 errors[i].push_back(std::log10(err));
263 h_vals[i].push_back(std::log10(h));
264 errors[i].push_back(std::log10(err));
270 if (num_converged < calc_answers.size())
272 if (iter++ > max_iter+1 )
273 libmesh_error_msg(
"Exceeded maximum iterations");
275 for (
unsigned int i=0; i<elems_in_rayfire.size(); i++)
276 system->get_mesh().elem_ref(elems_in_rayfire[i]).set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
278 mr.refine_elements();
281 for (
unsigned int i=0; i<elems_in_rayfire.size(); i++)
282 CPPUNIT_ASSERT( !( system->get_mesh().elem_ref(elems_in_rayfire[i]).active() ) );
285 ref_rayfire->reinit(system->get_mesh());
288 libMesh::DifferentiableQoI* diff_qoi = system->get_qoi();
295 }
while(num_converged < calc_answers.size());
298 for (
unsigned int i=0; i<functions.size(); i++)
void check_convergence_rate(std::vector< libMesh::Real > x, std::vector< libMesh::Real > y, unsigned int start_index, unsigned int end_index, libMesh::Real convergence_rate, libMesh::Real tol)
Check the convergence rate of the supplied data to within the given absolute tolerance.
Interface with libMesh for solving Multiphysics problems.
GRINS::SharedPtr< GRINS::Simulation > _sim
GRINS::SharedPtr< GetPot > _input
void init_sim(const std::string &filename)
Initialize the GetPot and Simulation class objects.
virtual void reinit(MultiphysicsSystem &system)
Reinitialize qoi.