@@ -103,7 +103,14 @@ int main(int argc, char *argv[])
103103 // Create spaces
104104 // ======================================================
105105
106- FiniteElementCollection *fec_lo, *fec_im, *fec_hi;
106+ // _lo: low-order given
107+ // _im: intermediate
108+ // _hi: high-order reconstructed
109+ // _ex: high-order exact
110+
111+ FiniteElementCollection *fec_lo;
112+ FiniteElementCollection *fec_im;
113+ FiniteElementCollection *fec_hi;
107114 space = " L2" ;
108115 fec_lo = new L2_FECollection (order_lo, dim);
109116 fec_im = new L2_FECollection (order_im, dim);
@@ -116,14 +123,17 @@ int main(int argc, char *argv[])
116123 GridFunction rho_lo (&fespace_lo);
117124 GridFunction rho_im (&fespace_im);
118125 GridFunction rho_hi (&fespace_hi);
126+ GridFunction rho_ex (&fespace_hi);
119127
120128 // Data collections for vis/analysis
121129 VisItDataCollection dc_lo (" LO" , &mesh_lo);
122130 dc_lo.RegisterField (" density" , &rho_lo);
123131 VisItDataCollection dc_im (" IM" , &mesh_im);
124132 dc_im.RegisterField (" density" , &rho_im);
125133 VisItDataCollection dc_hi (" HO" , &mesh_hi);
126- dc_hi.RegisterField (" density" , &rho_hi);
134+ dc_hi.RegisterField (" density" , &rho_hi);
135+ VisItDataCollection dc_ex (" EX" , &mesh_hi);
136+ dc_ex.RegisterField (" density" , &rho_ex);
127137
128138 // ======================================================
129139 // Create BilinearForms
@@ -148,7 +158,7 @@ int main(int argc, char *argv[])
148158 // Defind GridTransfers
149159 // ======================================================
150160
151- std::cout<<" SK: Defind GridTransfers" <<std::endl;
161+ std::cout<<" Defind GridTransfers" <<std::endl;
152162
153163 GridTransfer *gt1 = nullptr ;
154164 GridTransfer *gt2 = nullptr ;
@@ -177,16 +187,21 @@ int main(int argc, char *argv[])
177187 // Compute GridFunctions
178188 // ======================================================
179189
180- std::cout<<" SK: LO projection " <<std::endl;
190+ std::cout<<" Compute GridFunctions " <<std::endl;
181191
182- // STEP1: LO projection
192+ // STEP1: LO & EX projections
183193
184194 FunctionCoefficient RHO (RHO_exact);
185195 rho_lo.ProjectCoefficient (RHO);
186196 rho_lo.SetTrueVector ();
187197 rho_lo.SetFromTrueVector ();
188198
189- std::cout<<" SK: LO compute mass" <<std::endl;
199+ rho_ex.ProjectCoefficient (RHO);
200+ rho_ex.SetTrueVector ();
201+ rho_ex.SetFromTrueVector ();
202+
203+ real_t mass_ex = compute_mass (&fespace_hi, -1.0 , dc_ex, " EX" );
204+ if (vis) { visualize (dc_ex, " EX" , Wx, Wy, visport); Wx += offx; }
190205
191206 real_t mass_lo = compute_mass (&fespace_lo, -1.0 , dc_lo, " LO" );
192207 if (vis) { visualize (dc_lo, " LO" , Wx, Wy, visport); Wx += offx; }
@@ -204,75 +219,22 @@ int main(int argc, char *argv[])
204219 real_t mass_hi = compute_mass (&fespace_hi, -1.0 , dc_hi, " P2(IM) " );
205220 if (vis) { visualize (dc_hi, " HO=P2(IM)" , Wx, Wy, visport); Wx += offx; }
206221
207- // if (gt1->SupportsBackwardsOperator()) // 1
208- // {
209- // const Operator &P1 = gt1->BackwardOperator(); // Prolongation
210- // // LOR->HO prolongation
211- // direction = "HO -> LOR @ HO";
212- // GridFunction rho_prev = rho_im;
213- // P1.Mult(rho_lo, rho_im); // rho_im = P1 * rho_lo
214- // compute_mass(&fespace_im, mass_im, dc_im, "P(R(HO)) ");
215- // if (vis) { visualize(dc_im, "P(R(HO))", Wx, Wy, visport); Wx = 0; Wy += offy; }
216-
217- // rho_prev -= rho_im;
218- // cout.precision(12);
219- // cout << "|HO - P(R(HO))|_∞ = " << rho_prev.Normlinf() << endl;
220- // }
221-
222- // // HO* to LOR* dual fields
223- // LinearForm M_rho(&fespace_im), M_rho_lo(&fespace_lo);
224- // if (!use_pointwise_transfer && gt1->SupportsBackwardsOperator())
225- // {
226- // const Operator &P1 = gt1->BackwardOperator();
227- // M_im.Mult(rho_im, M_rho);
228- // P1.MultTranspose(M_rho, M_rho_lo);
229- // cout << "HO -> LOR dual field: " << abs(M_rho.Sum()-M_rho_lo.Sum()) << "\n\n";
230- // }
231-
232- // // LOR projections
233- // direction = "LOR -> HO @ LOR";
234- // rho_lo.ProjectCoefficient(RHO);
235- // GridFunction rho_lo_prev = rho_lo;
236- // real_t lor_mass = compute_mass(&fespace_lo, -1.0, dc_lo, "LOR ");
237- // if (vis) { visualize(dc_lo, "LOR", Wx, Wy, visport); Wx += offx; }
238-
239- // if (gt1->SupportsBackwardsOperator())
240- // {
241- // const Operator &P1 = gt1->BackwardOperator();
242- // // Prolongate to HO space
243- // direction = "LOR -> HO @ HO";
244- // P1.Mult(rho_lo, rho_im);
245- // compute_mass(&fespace_im, lor_mass, dc_im, "P(LOR) ");
246- // if (vis) { visualize(dc_im, "P(LOR)", Wx, Wy, visport); Wx += offx; }
247-
248- // // Restrict back to LOR space. This won't give the original function because
249- // // the rho_lo doesn't necessarily live in the range of R.
250- // direction = "LOR -> HO @ LOR";
251- // R1.Mult(rho_im, rho_lo);
252- // compute_mass(&fespace_lo, lor_mass, dc_lo, "R(P(LOR))");
253- // if (vis) { visualize(dc_lo, "R(P(LOR))", Wx, Wy, visport); }
254-
255- // rho_lo_prev -= rho_lo;
256- // cout.precision(12);
257- // cout << "|LOR - R(P(LOR))|_∞ = " << rho_lo_prev.Normlinf() << endl;
258- // if (abs(rho_lo_prev.Normlinf()-1.11022302463e-15) < 1e-15) {
259- // cout << "SK: LOR reconstruction is Good!\n";
260- // }
261- // }
262-
263- // // LOR* to HO* dual fields
264- // if (!use_pointwise_transfer)
265- // {
266- // M_lo.Mult(rho_lo, M_rho_lo);
267- // R1.MultTranspose(M_rho_lo, M_rho);
268- // cout << "LOR -> HO dual field: " << abs(M_rho.Sum() - M_rho_lo.Sum()) << '\n';
269- // }
270-
271- // delete gt1;
272- // delete gt2;
273- // delete fec_lo;
274- // delete fec_im;
275- // delete fec_hi;
222+ // ======================================================
223+ // Compute Errors
224+ // ======================================================
225+ // Compute error with respect to exact solution
226+
227+ GridFunction rho_error = rho_hi;
228+ rho_error -= rho_ex;
229+ real_t error = rho_error.Normlinf ();
230+ cout.precision (12 );
231+ cout << " |HO - EX|_∞ = " << error << endl;
232+
233+ delete gt1;
234+ delete gt2;
235+ delete fec_lo;
236+ delete fec_im;
237+ delete fec_hi;
276238
277239 return 0 ;
278240}
0 commit comments