22 if (mesh->Dimension() != 1 || mesh->SpaceDimension() != 1)
28 double xmin = numeric_limits<double>::infinity();
30 for (
int i = 0; i < mesh->GetNV(); i++)
32 const double x = mesh->GetVertex(i)[0];
43 Mesh *mesh2d = Extrude1D(mesh.get(), 1, 0.1*(xmax - xmin));
47 GridFunction *grid_f_2d =
48 Extrude1DGridFunction(mesh.get(), mesh2d, grid_f.get(), 1);
50 grid_f.reset(grid_f_2d);
52 else if (sol.Size() == mesh->GetNV())
54 Vector sol2d(mesh2d->GetNV());
55 for (
int i = 0; i < mesh->GetNV(); i++)
57 sol2d(2*i+0) = sol2d(2*i+1) = sol(i);
70 FiniteElementCollection *cfec;
71 if (mesh->Dimension() == 1)
73 cfec =
new L2_FECollection(0, 1);
75 else if (mesh->Dimension() == 2)
77 cfec =
new Const2DFECollection;
81 cfec =
new Const3DFECollection;
83 FiniteElementSpace *cfes =
new FiniteElementSpace(mesh.get(), cfec);
84 grid_f.reset(
new GridFunction(cfes));
85 grid_f->MakeOwner(cfec);
89 double a = double(rand()) / (double(RAND_MAX) + 1.);
90 int el0 = (int)floor(a * mesh->GetNE());
91 cout <<
"Generating coloring starting with element " << el0+1
92 <<
" / " << mesh->GetNE() << endl;
93 mesh->GetElementColoring(coloring, el0);
94 for (
int i = 0; i < coloring.Size(); i++)
96 (*grid_f)(i) = coloring[i];
98 cout <<
"Number of colors: " << grid_f->Max() + 1 << endl;
100 grid_f->GetNodalValues(sol);
104 const char col_fname[] =
"GLVis_coloring.gf";
105 ofstream fgrid(col_fname);
106 cout <<
"Saving the coloring function -> " << flush;
108 cout << col_fname << endl;
113 sol.SetSize (mesh -> GetNV());
125 if (data_type ==
"fem2d_data")
127 mesh.reset(
new Mesh(is, 0, 0, fix_elem_orient));
128 sol.Load(is, mesh->GetNV());
130 else if (data_type ==
"vfem2d_data" || data_type ==
"vfem2d_data_keys")
133 mesh.reset(
new Mesh(is, 0, 0, fix_elem_orient));
134 solu.Load(is, mesh->GetNV());
135 solv.Load(is, mesh->GetNV());
136 if (data_type ==
"vfem2d_data_keys")
141 else if (data_type ==
"fem3d_data")
143 mesh.reset(
new Mesh(is, 0, 0, fix_elem_orient));
144 sol.Load(is, mesh->GetNV());
146 else if (data_type ==
"vfem3d_data" || data_type ==
"vfem3d_data_keys")
149 mesh.reset(
new Mesh(is, 0, 0, fix_elem_orient));
150 solu.Load(is, mesh->GetNV());
151 solv.Load(is, mesh->GetNV());
152 solw.Load(is, mesh->GetNV());
153 if (data_type ==
"vfem3d_data_keys")
158 else if (data_type ==
"fem2d_gf_data" || data_type ==
"fem2d_gf_data_keys")
160 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
161 grid_f.reset(
new GridFunction(mesh.get(), is));
162 if (data_type ==
"fem2d_gf_data_keys")
167 else if (data_type ==
"vfem2d_gf_data" || data_type ==
"vfem2d_gf_data_keys")
170 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
171 grid_f.reset(
new GridFunction(mesh.get(), is));
172 if (data_type ==
"vfem2d_gf_data_keys")
177 else if (data_type ==
"fem3d_gf_data" || data_type ==
"fem3d_gf_data_keys")
179 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
180 grid_f.reset(
new GridFunction(mesh.get(), is));
181 if (data_type ==
"fem3d_gf_data_keys")
186 else if (data_type ==
"vfem3d_gf_data" || data_type ==
"vfem3d_gf_data_keys")
189 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
190 grid_f.reset(
new GridFunction(mesh.get(), is));
191 if (data_type ==
"vfem3d_gf_data_keys")
196 else if (data_type ==
"solution")
198 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
199 grid_f.reset(
new GridFunction(mesh.get(), is));
200 field_type = (grid_f->VectorDim() == 1) ? 0 : 1;
202 else if (data_type ==
"mesh")
204 mesh.reset(
new Mesh(is, 1, 0, fix_elem_orient));
208 else if (data_type ==
"raw_scalar_2d")
210 Array<Array<double> *> vertices;
211 Array<Array<int> *> elements;
212 Array<int> elem_types;
214 int num_patches, num_vert, num_elem, n;
218 vertices.SetSize(num_patches);
220 elements.SetSize(num_patches);
222 elem_types.SetSize(num_patches);
224 int tot_num_vert = 0;
225 int tot_num_elem = 0;
227 for (
int i = 0; i < num_patches; i++)
233 vertices[i] =
new Array<double>(6*num_vert);
234 Array<double> &verts = *vertices[i];
235 for (
int j = 0; j < verts.Size(); j++)
241 if (ident ==
"triangles")
243 n = 3, mesh_type |= 1;
247 n = 4, mesh_type |= 2;
252 elements[i] =
new Array<int>(n*num_elem);
253 Array<int> &elems = *elements[i];
254 for (
int j = 0; j < elems.Size(); j++)
257 elems[j] += tot_num_vert;
259 tot_num_vert += num_vert;
260 tot_num_elem += num_elem;
263 mesh.reset(
new Mesh(2, tot_num_vert, tot_num_elem, 0));
264 sol.SetSize(tot_num_vert);
265 normals.SetSize(3*tot_num_vert);
268 for (
int i = 0; i < num_patches; i++)
270 Array<double> &verts = *vertices[i];
271 num_vert = verts.Size()/6;
272 for (
int j = 0; j < num_vert; j++)
274 mesh->AddVertex(&verts[6*j]);
275 sol(v_off) = verts[6*j+2];
276 normals(3*v_off+0) = verts[6*j+3];
277 normals(3*v_off+1) = verts[6*j+4];
278 normals(3*v_off+2) = verts[6*j+5];
283 Array<int> &elems = *elements[i];
284 num_elem = elems.Size()/n;
288 for (
int j = 0; j < num_elem; j++)
290 mesh->AddTriangle(&elems[3*j], attr);
293 for (
int j = 0; j < num_elem; j++)
295 mesh->AddQuad(&elems[4*j], attr);
301 mesh->FinalizeTriMesh(1, 0, fix_elem_orient);
303 else if (mesh_type == 2)
305 mesh->FinalizeQuadMesh(1, 0, fix_elem_orient);
309 mfem_error(
"Input data contains mixture of triangles and quads!");
312 mesh->GenerateBoundaryElements();
314 for (
int i = num_patches; i > 0; )
326 cerr <<
"Unknown data format" << endl;
327 cerr << data_type << endl;
330 if (field_type >= 0 && field_type <= 2)
332 Extrude1DMeshAndSolution();
341 std::unique_ptr<GridFunction>
344 if ((gf->VectorDim() == 3) && (gf->FESpace()->GetVDim() == 1))
346 int p = gf->FESpace()->GetOrder(0);
347 cout <<
"Switching to order " << p
348 <<
" discontinuous vector grid function..." << endl;
349 int dim = gf->FESpace()->GetMesh()->Dimension();
350 FiniteElementCollection *d_fec =
351 (p == 1 && dim == 3) ?
352 (FiniteElementCollection*)
new LinearDiscont3DFECollection :
353 (FiniteElementCollection*)
new L2_FECollection(p, dim, 1);
354 FiniteElementSpace *d_fespace =
355 new FiniteElementSpace(gf->FESpace()->GetMesh(), d_fec, 3);
356 GridFunction *d_gf =
new GridFunction(d_fespace);
357 d_gf->MakeOwner(d_fec);
358 gf->ProjectVectorFieldOn(*d_gf);
367 if (new_state.
mesh->SpaceDimension() == mesh->SpaceDimension() &&
368 new_state.
grid_f->VectorDim() == grid_f->VectorDim())
370 std::unique_ptr<mfem::Mesh> new_m = std::move(new_state.
mesh);
371 std::unique_ptr<mfem::GridFunction> new_g = std::move(new_state.
grid_f);
372 if (new_m->SpaceDimension() == 2)
374 if (new_g->VectorDim() == 1)
378 new_g->GetNodalValues(sol);
390 if (new_g->VectorDim() == 1)
394 new_g->GetNodalValues(sol);
406 grid_f = std::move(new_g);
407 mesh = std::move(new_m);
std::unique_ptr< GridFunction > ProjectVectorFEGridFunction(std::unique_ptr< GridFunction > gf)
void Extrude1DMeshAndSolution()
Helper function for visualizing 1D data.
std::unique_ptr< mfem::GridFunction > grid_f
thread_local VisualizationSceneScalarData * vs
void SetMeshSolution()
Set a (checkerboard) solution when only the mesh is given.
void NewMeshAndSolution(Mesh *new_m, Vector *new_sol, GridFunction *new_u=NULL)
bool SetNewMeshAndSolution(StreamState new_state, VisualizationScene *vs)
void NewMeshAndSolution(GridFunction &vgf)
std::unique_ptr< mfem::Mesh > mesh
void NewMeshAndSolution(Mesh *new_m, GridFunction *new_v)
int ReadStream(std::istream &is, const std::string &data_type)
void NewMeshAndSolution(Mesh *new_m, Vector *new_sol, GridFunction *new_u=NULL)