Skip to content

Commit 3fb5271

Browse files
committed
Created hi mesh and clean up.
1 parent 287a807 commit 3fb5271

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

miniapps/tools/reconstruction_lor.cpp

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int main(int argc, char *argv[])
4242
{
4343
// Parse command-line options.
4444
const char *mesh_file = "../../data/star.mesh";
45+
int order_ho = 3;
4546
int order_im = 3;
4647
int lref = order_im+1; // 4
4748
int order_lo = 0;
@@ -80,56 +81,73 @@ int main(int argc, char *argv[])
8081
// Configure device
8182
Device device(device_config);
8283

83-
// Create the intermediate mesh
84+
// ======================================================
85+
// Create meshes
86+
// ======================================================
87+
88+
// intermediate mesh
8489
const int num_x = 2;
8590
const int num_y = 2;
8691
Mesh mesh_im = Mesh::MakeCartesian2D(num_x, num_y, Element::QUADRILATERAL, false, 1.0, 1.0 ); // sx = sy =1
8792
int dim = mesh_im.Dimension();
8893

89-
// Create the low-order refined mesh
94+
// low-order refined mesh
9095
Mesh mesh_lo = Mesh::MakeRefined(mesh_im, lref, BasisType::GaussLobatto);
9196

92-
// Create the high-order mesh
97+
// high-order mesh
9398
Mesh mesh_hi(mesh_lo);
9499

100+
// ======================================================
95101
// Create spaces
96-
FiniteElementCollection *fec_im, *fec_lo;
102+
// ======================================================
103+
104+
FiniteElementCollection *fec_lo, *fec_im, *fec_hi;
97105
space = "L2";
98-
fec_im = new L2_FECollection(order_im, dim);
99106
fec_lo = new L2_FECollection(order_lo, dim);
107+
fec_im = new L2_FECollection(order_im, dim);
108+
fec_hi = new L2_FECollection(order_ho, dim);
100109

101-
FiniteElementSpace fespace_im(&mesh_im, fec_im);
102110
FiniteElementSpace fespace_lo(&mesh_lo, fec_lo);
111+
FiniteElementSpace fespace_im(&mesh_im, fec_im);
112+
FiniteElementSpace fespace_hi(&mesh_hi, fec_hi);
103113

104-
GridFunction rho_im(&fespace_im);
105114
GridFunction rho_lo(&fespace_lo);
115+
GridFunction rho_im(&fespace_im);
116+
GridFunction rho_hi(&fespace_hi);
106117

107118
// Data collections for vis/analysis
108-
VisItDataCollection HO_dc("HO", &mesh_im);
109-
HO_dc.RegisterField("density", &rho_im);
110-
VisItDataCollection LOR_dc("LOR", &mesh_lo);
111-
LOR_dc.RegisterField("density", &rho_lo);
112-
113-
BilinearForm M_ho(&fespace_im);
114-
M_ho.AddDomainIntegrator(new MassIntegrator);
115-
M_ho.Assemble();
116-
M_ho.Finalize();
119+
VisItDataCollection dc_lo("LO", &mesh_lo);
120+
dc_lo.RegisterField("density", &rho_lo);
121+
VisItDataCollection dc_im("IM", &mesh_im);
122+
dc_im.RegisterField("density", &rho_im);
123+
VisItDataCollection dc_hi("HO", &mesh_hi);
124+
dc_hi.RegisterField("density", &rho_hi);
117125

118126
BilinearForm M_lo(&fespace_lo);
119127
M_lo.AddDomainIntegrator(new MassIntegrator);
120128
M_lo.Assemble();
121129
M_lo.Finalize();
122130

131+
BilinearForm M_im(&fespace_im);
132+
M_im.AddDomainIntegrator(new MassIntegrator);
133+
M_im.Assemble();
134+
M_im.Finalize();
135+
136+
BilinearForm M_hi(&fespace_hi);
137+
M_hi.AddDomainIntegrator(new MassIntegrator);
138+
M_hi.Assemble();
139+
M_hi.Finalize();
140+
123141
// HO projections
124142
direction = "HO -> LOR @ HO";
125143
FunctionCoefficient RHO(RHO_exact);
144+
126145
rho_im.ProjectCoefficient(RHO);
127-
// Make sure AMR constraints are satisfied
128146
rho_im.SetTrueVector();
129147
rho_im.SetFromTrueVector();
130148

131-
real_t ho_mass = compute_mass(&fespace_im, -1.0, HO_dc, "HO ");
132-
if (vis) { visualize(HO_dc, "HO", Wx, Wy, visport); Wx += offx; }
149+
real_t mass_im = compute_mass(&fespace_im, -1.0, dc_im, "HO ");
150+
if (vis) { visualize(dc_im, "HO", Wx, Wy, visport); Wx += offx; }
133151

134152
GridTransfer *gt;
135153
if (use_pointwise_transfer)
@@ -151,8 +169,8 @@ int main(int argc, char *argv[])
151169

152170
R.Mult(rho_im, rho_lo);
153171

154-
compute_mass(&fespace_lo, ho_mass, LOR_dc, "R(HO) ");
155-
if (vis) { visualize(LOR_dc, "R(HO)", Wx, Wy, visport); Wx += offx; }
172+
compute_mass(&fespace_lo, mass_im, dc_lo, "R(HO) ");
173+
if (vis) { visualize(dc_lo, "R(HO)", Wx, Wy, visport); Wx += offx; }
156174

157175
if (gt->SupportsBackwardsOperator()) // 1
158176
{
@@ -161,8 +179,8 @@ int main(int argc, char *argv[])
161179
direction = "HO -> LOR @ HO";
162180
GridFunction rho_prev = rho_im;
163181
P.Mult(rho_lo, rho_im);
164-
compute_mass(&fespace_im, ho_mass, HO_dc, "P(R(HO)) ");
165-
if (vis) { visualize(HO_dc, "P(R(HO))", Wx, Wy, visport); Wx = 0; Wy += offy; }
182+
compute_mass(&fespace_im, mass_im, dc_im, "P(R(HO)) ");
183+
if (vis) { visualize(dc_im, "P(R(HO))", Wx, Wy, visport); Wx = 0; Wy += offy; }
166184

167185
rho_prev -= rho_im;
168186
cout.precision(12);
@@ -174,7 +192,7 @@ int main(int argc, char *argv[])
174192
if (!use_pointwise_transfer && gt->SupportsBackwardsOperator())
175193
{
176194
const Operator &P = gt->BackwardOperator();
177-
M_ho.Mult(rho_im, M_rho);
195+
M_im.Mult(rho_im, M_rho);
178196
P.MultTranspose(M_rho, M_rho_lo);
179197
cout << "HO -> LOR dual field: " << abs(M_rho.Sum()-M_rho_lo.Sum()) << "\n\n";
180198
}
@@ -183,24 +201,24 @@ int main(int argc, char *argv[])
183201
direction = "LOR -> HO @ LOR";
184202
rho_lo.ProjectCoefficient(RHO);
185203
GridFunction rho_lo_prev = rho_lo;
186-
real_t lor_mass = compute_mass(&fespace_lo, -1.0, LOR_dc, "LOR ");
187-
if (vis) { visualize(LOR_dc, "LOR", Wx, Wy, visport); Wx += offx; }
204+
real_t lor_mass = compute_mass(&fespace_lo, -1.0, dc_lo, "LOR ");
205+
if (vis) { visualize(dc_lo, "LOR", Wx, Wy, visport); Wx += offx; }
188206

189207
if (gt->SupportsBackwardsOperator())
190208
{
191209
const Operator &P = gt->BackwardOperator();
192210
// Prolongate to HO space
193211
direction = "LOR -> HO @ HO";
194212
P.Mult(rho_lo, rho_im);
195-
compute_mass(&fespace_im, lor_mass, HO_dc, "P(LOR) ");
196-
if (vis) { visualize(HO_dc, "P(LOR)", Wx, Wy, visport); Wx += offx; }
213+
compute_mass(&fespace_im, lor_mass, dc_im, "P(LOR) ");
214+
if (vis) { visualize(dc_im, "P(LOR)", Wx, Wy, visport); Wx += offx; }
197215

198216
// Restrict back to LOR space. This won't give the original function because
199217
// the rho_lo doesn't necessarily live in the range of R.
200218
direction = "LOR -> HO @ LOR";
201219
R.Mult(rho_im, rho_lo);
202-
compute_mass(&fespace_lo, lor_mass, LOR_dc, "R(P(LOR))");
203-
if (vis) { visualize(LOR_dc, "R(P(LOR))", Wx, Wy, visport); }
220+
compute_mass(&fespace_lo, lor_mass, dc_lo, "R(P(LOR))");
221+
if (vis) { visualize(dc_lo, "R(P(LOR))", Wx, Wy, visport); }
204222

205223
rho_lo_prev -= rho_lo;
206224
cout.precision(12);

0 commit comments

Comments
 (0)