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

Annotated source file

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

#include <gismo.h>
using namespace gismo;
int main(int argc, char* argv[])
{
index_t p = 3; // Degree
index_t k = 3; // Number of interor knots (more knots --> better approximation)
index_t s = 1000; // samples for plotting
std::string func_name_x("x");
std::string func_name_y("y");
std::string func_name_z("z");
index_t d = 3; //dimension
gsCmdLine cmd("Input is coordinate functions X(x,y,z), Y(x,y,z). Z(x,y,z), or"
"X(x,y), Y(x,y). Z(x,y), or X(x), Y(x). Z(x). This is controlled by"
"the dimension parameter d. The parameters take values in the interval [0,1]");
cmd.addInt("p", "degree", "this is the degree", p);
cmd.addInt("k", "knots", "This is the number of interior knots", k);
cmd.addInt("d", "dim", "this is the parametric dimension", d);
cmd.addInt("s", "samples", "this is samples for paraview", s);
cmd.addString("X", "f1", "The X-coordinate of the function", func_name_x);
cmd.addString("Y", "f2", "The Y-coordinate of the function", func_name_y);
cmd.addString("Z", "f3", "The Z-coordinate of the function", func_name_z);
try { cmd.getValues(argc,argv); } catch (int rv) { return rv; }
// Define a function R^d --> R^2
gsFunctionExpr<> func(func_name_x, func_name_y, func_name_z, d);
// Define a B-spline space of dimension 2
// start, end, numInt, multiplicities at end-points
gsKnotVector<> KV(0.0, 1.0, k, p+1);
switch (d) // static dispatch..
{
case 1:
tBasis = gsBSplineBasis<>::make(KV);
break;
case 2:
break;
case 3:
break;
default:
{
gsWarn<<"Dimension must be 1, 2 or 3.";
return 0;
}
};
gsInfo <<"We are going to interpolate "<< func <<"\n";
// Support: 2x2 matrix, first column is the lower left
// point of the parametric domain (eg. 0,0)
// second column is the upper right corner of the support (eg. 1,1)
// gsMatrix<> support = tBasis->support();
// Points to interpolate at (Greville points):
gsMatrix<> intGrid = tBasis->anchors();
gsInfo <<"Int. grid dim: "<< intGrid.dim() <<"\n";
// Evaluate f at the Greville points
gsMatrix<> fValues = func.eval(intGrid);
gsInfo <<"Function values dim: "<< fValues.dim() <<"\n";
// Returns a geometry with basis = tBasis
// and coefficients being
// computed as the interpolant of \a funct
gsGeometry<>::uPtr interpolant = tBasis->interpolateAtAnchors(fValues);
gsInfo << "Result :"<< *interpolant <<"\n";
// Save the result as an XML file
mp.addPatch(give(interpolant));
fd << mp;
std::string remark("Made by interpolation from function: ( ");
for (index_t i = 0; i<3; ++i)
{
remark += func.expression(i);
remark += ( i==2 ? " )" : " , ");
}
fd.addComment( remark );
fd.save("interpolant_spline");
gsInfo <<"Result saved as interpolant_spline.xml \n";
// Produce Paraview file for the interpolant
//gsWriteParaview( *interpolant, support, "interpolant", s );
return 0;
}
A univariate B-spline basis.
Definition gsBSplineBasis.h:700
memory::unique_ptr< gsBasis > uPtr
Unique pointer for gsBasis.
Definition gsBasis.h:89
gsMatrix< T > anchors() const
Returns the anchor points that represent the members of the basis. There is exactly one anchor point ...
Definition gsBasis.h:437
virtual memory::unique_ptr< gsGeometry< T > > interpolateAtAnchors(gsMatrix< T > const &vals) const
Applies interpolation of values pts using the anchors as parameter points. May be reimplemented in de...
Definition gsBasis.hpp:267
Class for command-line argument parsing.
Definition gsCmdLine.h:57
This class represents an XML data tree which can be read from or written to a (file) stream.
Definition gsFileData.h:34
Class defining a multivariate (real or vector) function given by a string mathematical expression.
Definition gsFunctionExpr.h:52
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition gsGeometry.h:100
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
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
Main header to be included by clients using the G+Smo library.
#define index_t
Definition gsConfig.h:32
#define gsWarn
Definition gsDebug.h:50
#define gsInfo
Definition gsDebug.h:43
unique_ptr< T > make_unique(T *x)
Definition gsMemory.h:198
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266