forked from 2012ZGZYY/Dual_error_DG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefine.cc
225 lines (190 loc) · 8.31 KB
/
refine.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include<deal.II/base/exceptions.h>
#include "claw.h"
#include "dual_functional.h"
#include "dual_solver.h"
using namespace dealii;
// @sect4{ConservationLaw::compute_refinement_indicators}
// This function is real simple: We don't
// pretend that we know here what a good
// refinement indicator would be. Rather, we
// assume that the <code>EulerEquation</code>
// class would know about this, and so we
// simply defer to the respective function
// we've implemented there:
template <int dim>
void
ConservationLaw<dim>::
compute_refinement_indicators (Vector<double> &refinement_indicators, double& estimated_error_obj) const
{
//extract mesh_name from parameters.mesh_filename, i.e. remove '.msh' from the filename.
std::string mesh_name = parameters.mesh_filename;
int pos = mesh_name.rfind('.');
if(pos>0)
mesh_name = mesh_name.erase(pos);
std::cout<<"mesh_name is "<<mesh_name<<std::endl;
if(parameters.refinement_indicators == Parameters::Refinement::weighted_residual)
{
if(mesh_name == "corner" || mesh_name == "corner_coarse")
{
const Point<dim> evaluation_point(5, 2.10); //used in corner compression flow
DualFunctional::PointValueEvaluation<dim> dual_functional(evaluation_point);
DualSolver<dim> dual_solver(triangulation,
mapping(),
fe,
current_solution,
parameters,
dual_functional,
time_iter
//mesh_name
//present_time,
//end_time
);
//implemented in dual_solver.cc
dual_solver.compute_DWR_indicators(refinement_indicators, estimated_error_obj);
}
else if(mesh_name == "ringleb_structured" || mesh_name == "ringleb" || mesh_name == "ringleb_structured_refined")
{
const Point<dim> evaluation_point(0.3, 1.5); //used in ringleb's flow. this point is defined myself, so there's no reference to compare with.
DualFunctional::PointValueEvaluation<dim> dual_functional(evaluation_point);
DualSolver<dim> dual_solver(triangulation,
mapping(),
fe,
current_solution,
parameters,
dual_functional,
time_iter
//mesh_name
//present_time,
//end_time
);
dual_solver.compute_DWR_indicators(refinement_indicators, estimated_error_obj);
}
else if(mesh_name == "naca" || mesh_name == "naca0012" || mesh_name == "naca_uns")
{
//use the drag on airfoil face as objective functional, assemble the rhs of the dual_system
//note: here dual_functional serve as only algorithm to assemble rhs_dual, so it will not take
//many arguments.
DualFunctional::DragEvaluation<dim> dual_functional(parameters);
DualSolver<dim> dual_solver(triangulation,
mapping(),
fe,
current_solution,
parameters,
dual_functional,
time_iter
);
dual_solver.compute_DWR_indicators(refinement_indicators, estimated_error_obj);
}
else
{
AssertThrow(false, ExcNotImplemented());
}
}
else if(parameters.refinement_indicators == Parameters::Refinement::residual)
{std::cout<<"not finished!";}
else if(parameters.refinement_indicators == Parameters::Refinement::kelly)
{std::cout<<"not finished!";}
else if(parameters.refinement_indicators == Parameters::Refinement::easy){
if(parameters.time_step_type == "global")
EulerEquations<dim>::compute_refinement_indicators (dof_handler,
mapping(),
predictor,
refinement_indicators);
else
EulerEquations<dim>::compute_refinement_indicators (dof_handler,
mapping(),
current_solution,
refinement_indicators);
}
else
{
AssertThrow(false, ExcNotImplemented());
}
}
template <int dim>
void
ConservationLaw<dim>::refine_grid (const Vector<double> &refinement_indicators)
{
if(parameters.refinement_indicators == Parameters::Refinement::easy){
typename DoFHandler<dim>::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (unsigned int cell_no=0; cell!=endc; ++cell, ++cell_no)
{
cell->clear_coarsen_flag();
cell->clear_refine_flag();
if ((cell->level() < parameters.shock_levels) &&
(std::fabs(refinement_indicators(cell_no)) > parameters.shock_val))
cell->set_refine_flag();
else
if ((cell->level() > 0) &&
(std::fabs(refinement_indicators(cell_no)) < 0.75*parameters.shock_val))
cell->set_coarsen_flag();
}
}
else if(parameters.refinement_indicators == Parameters::Refinement::weighted_residual){
GridRefinement::refine_and_coarsen_fixed_fraction(triangulation,
refinement_indicators,
parameters.refine_fraction,
parameters.coarsen_fraction,
parameters.max_n_cells);
}
// Then we need to transfer the
// various solution vectors from
// the old to the new grid while we
// do the refinement. The
// SolutionTransfer class is our
// friend here; it has a fairly
// extensive documentation,
// including examples, so we won't
// comment much on the following
// code. The last three lines
// simply re-set the sizes of some
// other vectors to the now correct
// size:
std::vector<Vector<double> > transfer_in;
std::vector<Vector<double> > transfer_out;
transfer_in.push_back(old_solution);
transfer_in.push_back(predictor);
triangulation.prepare_coarsening_and_refinement();
SolutionTransfer<dim> soltrans(dof_handler);
soltrans.prepare_for_coarsening_and_refinement(transfer_in);
triangulation.execute_coarsening_and_refinement ();
setup_system ();
{
Vector<double> new_old_solution(1);
Vector<double> new_predictor(1);
transfer_out.push_back(new_old_solution);
transfer_out.push_back(new_predictor);
transfer_out[0].reinit(dof_handler.n_dofs());
transfer_out[1].reinit(dof_handler.n_dofs());
}
soltrans.interpolate(transfer_in, transfer_out);
old_solution = transfer_out[0];
predictor = transfer_out[1];
current_solution = old_solution;
}
//---------------------------------------------------------------------------
// Refine cells near the corner of forward step problem
//---------------------------------------------------------------------------
template <int dim>
void
ConservationLaw<dim>::refine_forward_step ()
{
const double radius = 0.05;
const Point<dim> corner(0.6, 0.2);
typename DoFHandler<dim>::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (unsigned int cell_no=0; cell!=endc; ++cell, ++cell_no)
{
cell->clear_coarsen_flag();
cell->clear_refine_flag();
Tensor<1,dim> dr = cell->center() - corner;
if(dr.norm() < radius)
cell->set_refine_flag();
}
triangulation.prepare_coarsening_and_refinement();
triangulation.execute_coarsening_and_refinement ();
}
template class ConservationLaw<2>;