-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output after every AMR step #530
base: master
Are you sure you want to change the base?
Changes from all commits
af334d1
3d60d4c
062dde9
de7e337
ad937cd
d387a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,8 @@ namespace GRINS | |
libMesh::MeshBase& mesh = context.equation_system->get_mesh(); | ||
this->build_mesh_refinement( mesh ); | ||
|
||
bool converged = false; | ||
|
||
/*! \todo This output cannot be toggled in the input file, but it should be able to be. */ | ||
std::cout << "==========================================================" << std::endl | ||
<< "Performing " << _mesh_adaptivity_options.max_refinement_steps() | ||
|
@@ -94,71 +96,92 @@ namespace GRINS | |
|
||
for ( unsigned int r_step = 0; r_step < _mesh_adaptivity_options.max_refinement_steps(); r_step++ ) | ||
{ | ||
std::cout << "==========================================================" << std::endl | ||
std::cout << std::endl | ||
<< "==========================================================" << std::endl | ||
<< "Adaptive Refinement Step " << r_step << std::endl | ||
<< "==========================================================" << std::endl; | ||
|
||
// Solve the forward problem | ||
context.system->solve(); | ||
converged = this->amr_helper(context,r_step,true); | ||
if (converged) | ||
break; | ||
|
||
if( context.output_vis ) | ||
{ | ||
context.postprocessing->update_quantities( *(context.equation_system) ); | ||
context.vis->output( context.equation_system ); | ||
} | ||
} // r_step for-loop | ||
|
||
// Solve adjoint system | ||
if(context.do_adjoint_solve) | ||
this->steady_adjoint_solve(context); | ||
// this will print output the error estimates and/or meshes after the final AMR run | ||
if (! converged) | ||
{ | ||
std::cout << std::endl | ||
<< "==========================================================" << std::endl | ||
<< "Post-AMR Output " << std::endl | ||
<< "==========================================================" << std::endl; | ||
this->amr_helper(context,_mesh_adaptivity_options.max_refinement_steps(),false); | ||
} | ||
|
||
if(context.output_adjoint) | ||
context.vis->output_adjoint(context.equation_system, context.system); | ||
return; | ||
} | ||
|
||
if( context.output_residual ) | ||
{ | ||
context.vis->output_residual( context.equation_system, context.system ); | ||
} | ||
bool SteadyMeshAdaptiveSolver::amr_helper(SolverContext & context, unsigned int r_step, bool do_amr) | ||
{ | ||
// Solve the forward problem | ||
context.system->solve(); | ||
|
||
// Now we construct the data structures for the mesh refinement process | ||
libMesh::ErrorVector error; | ||
this->estimate_error_for_amr( context, error ); | ||
if( context.output_vis ) | ||
{ | ||
context.postprocessing->update_quantities( *(context.equation_system) ); | ||
|
||
// Get the global error estimate if you can and are asked to | ||
if( _error_estimator_options.compute_qoi_error_estimate() ) | ||
for(unsigned int i = 0; i != context.system->qoi.size(); i++) | ||
{ | ||
libMesh::AdjointRefinementEstimator* adjoint_ref_error_estimator = libMesh::cast_ptr<libMesh::AdjointRefinementEstimator*>( context.error_estimator.get() ); | ||
std::cout<<"The error estimate for QoI("<<i<<") is: "<<adjoint_ref_error_estimator->get_global_QoI_error_estimate(i)<<std::endl; | ||
} | ||
if (context.output_every_amr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a bool, maybe an integer to output every n refinement steps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that would make sense, especially in the context of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was actually thinking about unsteady case, but yeah, for steady case, let's be able to reuse that code and if we're just and if the user put something > 1, we can flash a warning and switch it back to 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, not quite sure what you're saying here... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What my stream-of-consciousness comments don't make sense?! :P Let's use integer for steady case, but if the user puts anything other than 0 or 1, we print a warning and change it back to 0 or 1 (whatever makes sense). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hadn't had my morning tea yet, that makes more sense haha |
||
context.vis->output_amr( context.equation_system,r_step ); | ||
else | ||
context.vis->output( context.equation_system ); | ||
} | ||
|
||
// Check for convergence of error | ||
bool converged = this->check_for_convergence( context, error ); | ||
// Solve adjoint system | ||
if(context.do_adjoint_solve) | ||
this->steady_adjoint_solve(context); | ||
|
||
if( converged ) | ||
{ | ||
// Break out of adaptive loop | ||
std::cout << "==========================================================" << std::endl | ||
<< "Convergence detected!" << std::endl | ||
<< "==========================================================" << std::endl; | ||
break; | ||
} | ||
else | ||
if(context.output_adjoint) | ||
context.vis->output_adjoint(context.equation_system, context.system); | ||
|
||
if( context.output_residual ) | ||
{ | ||
context.vis->output_residual( context.equation_system, context.system ); | ||
} | ||
|
||
// Now we construct the data structures for the mesh refinement process | ||
libMesh::ErrorVector error; | ||
this->estimate_error_for_amr( context, error ); | ||
|
||
// Get the global error estimate if you can and are asked to | ||
if( _error_estimator_options.compute_qoi_error_estimate() ) | ||
for(unsigned int i = 0; i != context.system->qoi.size(); i++) | ||
{ | ||
libMesh::AdjointRefinementEstimator* adjoint_ref_error_estimator = libMesh::cast_ptr<libMesh::AdjointRefinementEstimator*>( context.error_estimator.get() ); | ||
std::cout<<"The error estimate for QoI("<<i<<") is: "<<adjoint_ref_error_estimator->get_global_QoI_error_estimate(i)<<std::endl; | ||
} | ||
|
||
// Check for convergence of error | ||
bool converged = this->check_for_convergence(context,error); | ||
|
||
if( converged ) | ||
{ | ||
// Break out of adaptive loop | ||
std::cout << "==========================================================" << std::endl | ||
<< "Convergence detected!" << std::endl | ||
<< "==========================================================" << std::endl; | ||
} | ||
else | ||
{ | ||
if (do_amr) | ||
{ | ||
// Only bother refining if we're on the last step. | ||
if( r_step < _mesh_adaptivity_options.max_refinement_steps() -1 ) | ||
{ | ||
this->perform_amr(context, error); | ||
|
||
// It's helpful to print the qoi along the way, but only do it if the user | ||
// asks for it | ||
if( context.qoi_output->output_qoi_set() ) | ||
this->print_qoi(context); | ||
} | ||
// print the QoI before AMR | ||
if( context.qoi_output->output_qoi_set() ) | ||
this->print_qoi(context); | ||
|
||
this->perform_amr(context, error); | ||
} | ||
} | ||
|
||
} // r_step for-loop | ||
|
||
return; | ||
return converged; | ||
} | ||
|
||
void SteadyMeshAdaptiveSolver::adjoint_qoi_parameter_sensitivity | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why force append?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can add an additional
bool append = false
parameter so it can be toggled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I guess it's not unreasonable to just append QoI values after each AMR step. And if you're not doing AMR, it won't matter. OK, I'm fine with just having it append.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only potential problem I can see is that if the file already exists from a previous run and we append to it, it might get confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought about that, but if we're not appending, we're overwriting. Six in one, half dozen the other IMO, so instead of adding a bunch of extra code to worry about the case, let's just carefully document in the
master_example_inputfile.in
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good