MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
nurbs_mesh_info.cpp
Go to the documentation of this file.
1// MFEM Print info of NURBS mesh
2//
3// Compile with: make nurbs_mesh_info
4//
5// Sample runs:
6// nurbs_mesh_info -m ../../data/cube-nurbs.mesh -o 0 -r 2
7//
8// Description: This code prints detailed mesh information such as:
9// - Print separate patch info
10// - 1D shape functions associated knot vectors
11// - Give Greville, Botella and Demko points of the knot vectors
12
13#include <iostream>
14#include "mfem.hpp"
15
16using namespace std;
17using namespace mfem;
18
19int main(int argc, char *argv[])
20{
21 // Read parameters from command line
22 const char *mesh_file = "../../data/square-nurbs.mesh";
23 const char *ref_file = "";
24 int ref_levels = -1;
25 int order = 1;
26 bool visualization = true;
27
28 OptionsParser args(argc, argv);
29 args.AddOption(&mesh_file, "-m", "--mesh",
30 "Mesh file to use.");
31 args.AddOption(&ref_levels, "-r", "--refine",
32 "Number of times to refine the mesh uniformly, -1 for auto.");
33 args.AddOption(&ref_file, "-rf", "--ref-file",
34 "File with refinement data");
35 args.AddOption(&order, "-o", "--order",
36 "NURBS order (polynomial degree) or -1 for");
37 args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
38 "--no-visualization",
39 "Enable or disable GLVis visualization."); // Dummy arg for `make test`
40 args.Parse();
41 if (!args.Good())
42 {
43 args.PrintUsage(cout);
44 return 1;
45 }
46
47 // Read the mesh
48 Mesh mesh(mesh_file, 1, 1);
49 NURBSExtension *ext = mesh.NURBSext;
50
51 if (!ext)
52 {
53 mfem_error("Mesh is not a NURBS mesh.");
54 }
55
56 // Refine the mesh as specified
57 mesh.DegreeElevate(16, order);
58
59 if (mesh.NURBSext && (strlen(ref_file) != 0))
60 {
61 mesh.RefineNURBSFromFile(ref_file);
62 }
63
64 for (int l = 0; l < ref_levels; l++)
65 {
66 mesh.UniformRefinement();
67 }
68
69 // Print mesh info
70 mesh.PrintInfo();
71
72 // Print patch info
73 mfem::out<<"=======================================;"<<endl;
74 mfem::out<<" Patch info"<<endl;
75 mfem::out<<"=======================================;"<<endl;
76 for (int p = 0; p < ext->GetNP(); p++)
77 {
79 ext->GetPatchKnotVectors(p, kv);
80
81 mfem::out<<p<<": Order = "<<kv[0]->GetOrder();
82 for (int k = 1; k < kv.Size(); k++)
83 {
84 mfem::out<<"x"<<kv[k]->GetOrder();
85 }
86 mfem::out<<" : DOFs = "<<kv[0]->GetNCP();
87 for (int k = 1; k < kv.Size(); k++)
88 {
89 mfem::out<<"x"<<kv[k]->GetNCP();
90 }
91 mfem::out<<endl;
92 }
93
94 // Print knotvector info
95 for (int k = 0; k < ext->GetNKV() ; k++)
96 {
97 mfem::out<<"=======================================;"<<endl;
98 mfem::out<<" KnotVector "<<k<<endl;
99 mfem::out<<"=======================================;"<<endl;
100 const KnotVector &kv = *ext->GetKnotVector(k);
101 mfem::out<<"Knotvector : "; kv.Print(mfem::out);
102
103 std::string gnuplot = "plot 0";
104 Vector a(kv.GetNCP());
105 for (int i = 0; i < kv.GetNCP(); i++)
106 {
107 a = 0.0;
108 a[i] = 1.0;
109 std::string filename = "k" + std::to_string(k) +"_n" + std::to_string(
110 i) + ".dat";
111 mfem::out<<"Write shape function to: "<<filename<<"\n";
112 std::ofstream ofs(filename);
113 kv.PrintFunction(ofs, a, 201);
114 ofs.close();
115 gnuplot += ", '" + filename+"' u 1:2 w l";
116 }
117 mfem::out<<gnuplot<<endl;
118
119 // Greville
120 Vector greville(kv.GetNCP());
121 for (int i = 0; i < kv.GetNCP(); i++)
122 {
123 greville[i] = kv.GetGreville(i);
124 }
125 mfem::out<<"Greville points : "; greville.Print(mfem::out, 32);
126
127 // Botella
128 Vector botella(kv.GetNCP());
129 for (int i = 0; i < kv.GetNCP(); i++)
130 {
131 botella[i] = kv.GetBotella(i);
132 }
133 mfem::out<<"Botella points : "; botella.Print(mfem::out, 32);
134
135 // Demko
136 Vector demko(kv.GetNCP());
137 for (int i = 0; i < kv.GetNCP(); i++)
138 {
139 demko[i] = kv.GetDemko(i);
140 }
141 mfem::out<<"Demko points : "; demko.Print(mfem::out, 32);
142
143 // Chebyshev spline
144 Vector x(kv.GetNCP());
145 for ( int i = 0; i <kv.GetNCP(); i++)
146 {
147 x[i] = std::pow(-1.0, i);
148 }
149 kv.GetInterpolant(x, demko, a);
150 mfem::out<<"Chebyshev spline coeff : "; a.Print(mfem::out, 32);
151
152 std::string filename = "k" + std::to_string(k) +"_cheby.dat";
153 mfem::out<<"Write Chebyshev spline to: "<<filename<<"\n";
154 std::ofstream ofs(filename);
155 kv.PrintFunction(ofs, a, 201);
156 ofs.close();
157 }
158
159}
int Size() const
Return the logical size of the array.
Definition array.hpp:192
A vector of knots in one dimension, with B-spline basis functions of a prescribed order.
Definition nurbs.hpp:38
void GetInterpolant(Array< Vector * > &x, const Vector &u, bool reuse_inverse=false) const
Global curve interpolation through the points x (overwritten) at the knot location u....
Definition nurbs.cpp:1092
void PrintFunction(std::ostream &os, const Vector &a, int samples=11) const
Definition nurbs.cpp:669
real_t GetBotella(int i) const
Definition nurbs.cpp:230
real_t GetDemko(int i) const
Definition nurbs.cpp:281
real_t GetGreville(int i) const
Definition nurbs.cpp:213
int GetNCP() const
Return the number of control points.
Definition nurbs.hpp:111
void Print(std::ostream &os) const
Print the order, number of control points, and knots.
Definition nurbs.cpp:632
Mesh data type.
Definition mesh.hpp:67
NURBSExtension * NURBSext
Optional NURBS mesh extension.
Definition mesh.hpp:317
void RefineNURBSFromFile(std::string ref_file)
Definition mesh.cpp:6375
void DegreeElevate(int rel_degree, int degree=16)
Definition mesh.cpp:6551
virtual void PrintInfo(std::ostream &os=mfem::out)
In serial, this method calls PrintCharacteristics(). In parallel, additional information about the pa...
Definition mesh.hpp:2699
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:12125
NURBSExtension generally contains multiple NURBSPatch objects spanning an entire Mesh....
Definition nurbs.hpp:575
int GetNP() const
Return the number of patches.
Definition nurbs.hpp:936
int GetNKV() const
Return the number of KnotVectors.
Definition nurbs.hpp:949
void GetPatchKnotVectors(int p, Array< KnotVector * > &kv)
Return KnotVectors in kv in each dimension for patch p.
Definition nurbs.cpp:4017
const KnotVector * GetKnotVector(int i) const
KnotVector read-only access function.
Definition nurbs.hpp:985
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
Definition optparser.hpp:82
bool Good() const
Return true if the command line options were parsed successfully.
Vector data type.
Definition vector.hpp:82
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
Definition vector.cpp:870
int main()
real_t a
Definition lissajous.cpp:41
void mfem_error(const char *msg)
Definition error.cpp:154
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
STL namespace.
real_t p(const Vector &x, real_t t)