MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
fem_extras.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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
14using namespace std;
15
16namespace mfem
17{
18
19namespace common
20{
21
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
35ND_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
47RT_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
59void 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
92void 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
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:220
const FiniteElementCollection * fec
Associated FE collection (not owned).
Definition fespace.hpp:231
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:559
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:31
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
FiniteElementSpace * FESpace()
Definition gridfunc.hpp:696
Arbitrary order H1-conforming (continuous) finite elements.
Definition fe_coll.hpp:260
Mesh data type.
Definition mesh.hpp:56
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Definition mesh.hpp:2288
Arbitrary order H(curl)-conforming Nedelec finite elements.
Definition fe_coll.hpp:465
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Definition fe_coll.hpp:386
H1_FESpace(Mesh *m, const int p, const int space_dim=3, const int type=BasisType::GaussLobatto, int vdim=1, int order=Ordering::byNODES)
ND_FESpace(Mesh *m, const int p, const int space_dim, int vdim=1, int order=Ordering::byNODES)
RT_FESpace(Mesh *m, const int p, const int space_dim, int vdim=1, int order=Ordering::byNODES)
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
bool is_open()
True if the socketstream is open, false otherwise.
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)
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)
const int visport
const char vishost[]
real_t p(const Vector &x, real_t t)