MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
fem_extras.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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, bool vec)
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 << "solution\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  else { sock << "keys maaAc\n"; }
85  if ( vec ) { sock << "vvv"; }
86  sock << endl;
87  }
88 
89  connection_failed = !sock && !newly_opened;
90  }
91  while (connection_failed);
92 }
93 
94 void VisualizeField(socketstream &sock, const char *vishost, int visport,
95  GridFunction &gf, const char *title,
96  int x, int y, int w, int h, const char * keys, bool vec)
97 {
98  Mesh &mesh = *gf.FESpace()->GetMesh();
99 
100  bool newly_opened = false;
101  int connection_failed;
102 
103  do
104  {
105  if (!sock.is_open() || !sock)
106  {
107  sock.open(vishost, visport);
108  sock.precision(8);
109  newly_opened = true;
110  }
111  sock << "solution\n";
112 
113  mesh.Print(sock);
114  gf.Save(sock);
115 
116  if (newly_opened)
117  {
118  sock << "window_title '" << title << "'\n"
119  << "window_geometry "
120  << x << " " << y << " " << w << " " << h << "\n";
121  if ( keys ) { sock << "keys " << keys << "\n"; }
122  else { sock << "keys maaAc\n"; }
123  if ( vec ) { sock << "vvv"; }
124  sock << endl;
125  }
126 
127  connection_failed = !sock && !newly_opened;
128  }
129  while (connection_failed);
130 }
131 
132 } // namespace common
133 
134 } // namespace mfem
virtual void Print(std::ostream &out=mfem::out) const
Definition: mesh.hpp:1234
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
const FiniteElementCollection * fec
Associated FE collection (not owned).
Definition: fespace.hpp:97
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:3417
constexpr char vishost[]
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:314
constexpr int visport
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:595
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Definition: fe_coll.hpp:272
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:87
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, bool vec)
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:333
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:94
Arbitrary order H1-conforming (continuous) finite elements.
Definition: fe_coll.hpp:159