MFEM  v4.5.2
Finite element discretization library
fem_extras.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #include "fem_extras.hpp"
13 
14 using namespace std;
15 
16 namespace mfem
17 {
18 
19 namespace common
20 {
21 
22 H1_FESpace::H1_FESpace(Mesh *m,
23  const int p, const int space_dim, const int type,
24  int vdim, int order)
25  : FiniteElementSpace(m, new H1_FECollection(p,space_dim,type),vdim,order)
26 {
27  FEC_ = this->FiniteElementSpace::fec;
28 }
29 
31 {
32  delete FEC_;
33 }
34 
35 ND_FESpace::ND_FESpace(Mesh *m, const int p, const int space_dim,
36  int vdim, int order)
37  : FiniteElementSpace(m, new ND_FECollection(p,space_dim),vdim,order)
38 {
39  FEC_ = this->FiniteElementSpace::fec;
40 }
41 
43 {
44  delete FEC_;
45 }
46 
47 RT_FESpace::RT_FESpace(Mesh *m, const int p, const int space_dim,
48  int vdim, int order)
49  : FiniteElementSpace(m, new RT_FECollection(p-1,space_dim),vdim,order)
50 {
51  FEC_ = this->FiniteElementSpace::fec;
52 }
53 
55 {
56  delete FEC_;
57 }
58 
59 void VisualizeMesh(socketstream &sock, const char *vishost, int visport,
60  Mesh &mesh, const char *title,
61  int x, int y, int w, int h, const char * keys)
62 {
63  bool newly_opened = false;
64  int connection_failed;
65 
66  do
67  {
68  if (!sock.is_open() || !sock)
69  {
70  sock.open(vishost, visport);
71  sock.precision(8);
72  newly_opened = true;
73  }
74  sock << "mesh\n";
75 
76  mesh.Print(sock);
77 
78  if (newly_opened)
79  {
80  sock << "window_title '" << title << "'\n"
81  << "window_geometry "
82  << x << " " << y << " " << w << " " << h << "\n";
83  if ( keys ) { sock << "keys " << keys << "\n"; }
84  sock << endl;
85  }
86 
87  connection_failed = !sock && !newly_opened;
88  }
89  while (connection_failed);
90 }
91 
92 void VisualizeField(socketstream &sock, const char *vishost, int visport,
93  GridFunction &gf, const char *title,
94  int x, int y, int w, int h, const char * keys, bool vec)
95 {
96  Mesh &mesh = *gf.FESpace()->GetMesh();
97 
98  bool newly_opened = false;
99  int connection_failed;
100 
101  do
102  {
103  if (!sock.is_open() || !sock)
104  {
105  sock.open(vishost, visport);
106  sock.precision(8);
107  newly_opened = true;
108  }
109  sock << "solution\n";
110 
111  mesh.Print(sock);
112  gf.Save(sock);
113 
114  if (newly_opened)
115  {
116  sock << "window_title '" << title << "'\n"
117  << "window_geometry "
118  << x << " " << y << " " << w << " " << h << "\n";
119  if ( keys ) { sock << "keys " << keys << "\n"; }
120  else { sock << "keys maaAc\n"; }
121  if ( vec ) { sock << "vvv"; }
122  sock << endl;
123  }
124 
125  connection_failed = !sock && !newly_opened;
126  }
127  while (connection_failed);
128 }
129 
130 } // namespace common
131 
132 } // namespace mfem
const char vishost[]
RT_FESpace(Mesh *m, const int p, const int space_dim, int vdim=1, int order=Ordering::byNODES)
Definition: fem_extras.cpp:47
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
ND_FESpace(Mesh *m, const int p, const int space_dim, int vdim=1, int order=Ordering::byNODES)
Definition: fem_extras.cpp:35
STL namespace.
const FiniteElementCollection * fec
Associated FE collection (not owned).
Definition: fespace.hpp:108
const int visport
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:683
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Definition: fe_coll.hpp:373
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:441
bool is_open()
True if the socketstream is open, false otherwise.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:96
void VisualizeMesh(socketstream &sock, const char *vishost, int visport, Mesh &mesh, const char *title, int x, int y, int w, int h, const char *keys)
Definition: fem_extras.cpp:59
int open(const char hostname[], int port)
Open the socket stream on &#39;port&#39; at &#39;hostname&#39;.
Arbitrary order H(curl)-conforming Nedelec finite elements.
Definition: fe_coll.hpp:447
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
Definition: fem_extras.cpp:92
virtual void Print(std::ostream &os=mfem::out) const
Definition: mesh.hpp:1749
Arbitrary order H1-conforming (continuous) finite elements.
Definition: fe_coll.hpp:252
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:3673