G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
bSplineSurface_example.cpp

Annotated source file

Here is the full file examples/bSplineSurface_example.cpp. Clicking on a function or class name will lead you to its reference documentation.

#include <cmath>
#include <iostream>
#include <gismo.h>
using namespace gismo;
const double PI = 3.14159265;
int main(int argc, char* argv[])
{
index_t n = 5;
index_t m = 5;
index_t degree = 3;
std::string output("");
gsCmdLine cmd("Tutorial on gsTensorBSpline class.");
cmd.addInt ("n", "dof1", "Number of basis function in one direction" , n);
cmd.addInt ("m", "dof2", "Number of basis function in other direction", m);
cmd.addInt ("d", "degree", "Degree of a surface", degree);
cmd.addString("o", "output", "Name of the output file.", output);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
// Adjust values to the minimum required
degree = math::max( (index_t)(0), degree );
n = math::max(n, degree + 1);
m = math::max(m, degree + 1);
gsInfo << "----------------------\n\n"
<< "n: " << n << "\n\n"
<< "m: " << m << "\n\n"
<< "degree: " << degree << "\n\n"
<< "output: " << output << "\n\n"
<< "----------------------\n\n";
// 1. construction of a knot vector for each direction
gsKnotVector<> kv1(0, 1, n - degree - 1, degree + 1);
gsKnotVector<> kv2(0, 1, m - degree - 1, degree + 1);
// 2. construction of a basis
// 3. construction of a coefficients
gsMatrix<> greville = basis.anchors();
gsMatrix<> coefs (greville.cols(), 3);
for (index_t col = 0; col != greville.cols(); col++)
{
real_t x = greville(0, col);
real_t y = greville(1, col);
coefs(col, 0) = x;
coefs(col, 1) = y;
coefs(col, 2) = math::sin(x * 2 * PI) * math::sin(y * 2 * PI);
}
// 4. putting basis and coefficients toghether
gsTensorBSpline<2, real_t> surface(basis, coefs);
// 5. saving surface, basis and control net to a file
if (output != "")
{
std::string out = output + "Geometry";
gsInfo << "Writing the surface to a paraview file: " << out
<< "\n\n";
gsWriteParaview(surface, out, 10000);
out = output + "Basis";
gsInfo << "Writing the basis to a paraview file: " << out
<< "\n\n";
gsWriteParaview(basis, out);
out = output + "ContolNet";
gsInfo << "Writing the control net to a paraview file: " << out
<< "\n" << "\n";
gsMesh<> mesh;
surface.controlNet(mesh);
gsWriteParaview(mesh, out);
out = output + "Coefficients";
gsMatrix <> coefs = surface.coefs();
coefs.transposeInPlace();
gsWriteParaviewPoints(coefs, out);
}
else
{
gsInfo << "Done. No output created, re-run with --output <filename> to get a ParaView "
"file containing the solution.\n";
}
return 0;
}
Class for command-line argument parsing.
Definition gsCmdLine.h:57
Class for representing a knot vector.
Definition gsKnotVector.h:80
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition gsTensorBSpline.h:45
Main header to be included by clients using the G+Smo library.
#define index_t
Definition gsConfig.h:32
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
void gsWriteParaviewPoints(gsMatrix< T > const &X, gsMatrix< T > const &Y, std::string const &fn)
Export 2D Point set to Paraview file.
Definition gsWriteParaview.hpp:1383