Skip to content

Commit

Permalink
add gsFitting
Browse files Browse the repository at this point in the history
add gsOptionList
add gsQuadRule
fix gsNurbsCreator
fix gsSparseMatrix
  • Loading branch information
hverhelst committed Dec 11, 2024
1 parent aaeeb32 commit 6c88042
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Cgismo.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// gsNurbs
#include <gsCInterface/gsCKnotVector.h>
#include <gsCInterface/gsCNurbsCreator.h>

// gsCore
#include <gsCInterface/gsCFunctionSet.h>
Expand All @@ -27,6 +28,15 @@
// gsPde
#include <gsCInterface/gsCBoundaryConditions.h>

// gsAssembler
#include <gsCInterface/gsCQuadRule.h>

// gsIO
#include <gsCInterface/gsCOptionList.h>

// gsModelling
#include <gsCInterface/gsCFitting.h>

@gsOptional_includes@

//
Expand All @@ -36,6 +46,7 @@
gsCKnotVector *: gsKnotVector_print, \
gsCFunctionSet *: gsFunctionSet_print, \
gsCBoundaryConditions *: gsBoundaryConditions_print, \
gsCOptionList *: gsOptionList_print, \
gsCMatrix *: gsMatrix_print)(X)

#define rows(X) _Generic((X), \
Expand Down Expand Up @@ -71,6 +82,7 @@
#define destroy(X) _Generic((X), \
gsCFunctionSet * : gsFunctionSet_delete, \
gsCBoundaryConditions * : gsBoundaryConditions_delete, \
gsCOptionList * : gsOptionList_delete, \
gsCKnotVector * : gsKnotVector_delete, \
gsCVector * : gsVector_delete, \
gsCVectorInt * : gsVectorInt_delete, \
Expand Down
69 changes: 69 additions & 0 deletions src/gsCFitting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

#include <gismo.h>
#include <gsCInterface/gsCTypes.h>
#include <gsCInterface/gsMacros.h>
#include <gsCInterface/gsCFitting.h>

#ifdef __cplusplus
extern "C"
{
#endif

GISMO_EXPORT gsCFitting * gsFitting_create(gsCMatrix * param_values, gsCMatrix * points, gsCBasis * basis)
{
auto * param_values_ptr = RICAST_M(param_values);
auto * points_ptr = RICAST_M(points);
auto * basis_ptr = RICAST_B(basis);
return reinterpret_cast<gsCFitting*>(new gismo::gsFitting<double>(*param_values_ptr, *points_ptr, *basis_ptr));
}

GISMO_EXPORT void gsFitting_delete(gsCFitting * fitter)
{
delete reinterpret_cast<gismo::gsFitting<double>*>(fitter);
}

GISMO_EXPORT void gsFitting_compute(gsCFitting * fitter, double lambda)
{
reinterpret_cast<gismo::gsFitting<double>*>(fitter)->compute(lambda);
}

GISMO_EXPORT void gsFitting_parameterCorrection(gsCFitting * fitter, double accuracy, int maxIter, double tolOrth)
{
reinterpret_cast<gismo::gsFitting<double>*>(fitter)->parameterCorrection(accuracy, maxIter, tolOrth);
}

GISMO_EXPORT void gsFitting_computeErrors(gsCFitting * fitter)
{
reinterpret_cast<gismo::gsFitting<double>*>(fitter)->computeErrors();
}

GISMO_EXPORT double gsFitting_minPointError(gsCFitting * fitter)
{
return reinterpret_cast<gismo::gsFitting<double>*>(fitter)->minPointError();
}

GISMO_EXPORT double gsFitting_maxPointError(gsCFitting * fitter)
{
return reinterpret_cast<gismo::gsFitting<double>*>(fitter)->maxPointError();
}

GISMO_EXPORT double* gsFitting_pointWiseErrors(gsCFitting * fitter)
{
const double * errors = reinterpret_cast< const double* >(reinterpret_cast<gismo::gsFitting<double>*>(fitter)->pointWiseErrors().data());
return const_cast<double *>(errors);
}

GISMO_EXPORT int gsFitting_numPointsBelow(gsCFitting * fitter, double threshold)
{
return reinterpret_cast<gismo::gsFitting<double>*>(fitter)->numPointsBelow(threshold);
}

GISMO_EXPORT gsCGeometry* gsFitting_result(gsCFitting * fitter)
{
auto * result = reinterpret_cast<gismo::gsFitting<double>*>(fitter)->result();
return RICAST_CG(result->clone().release());
}

#ifdef __cplusplus
}
#endif
24 changes: 24 additions & 0 deletions src/gsCFitting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#ifdef __cplusplus
extern "C"
{
#endif

GISMO_EXPORT gsCFitting* gsFitting_create(gsCMatrix * param_values, gsCMatrix * points, gsCBasis * basis);
GISMO_EXPORT void gsFitting_delete(gsCFitting * fitter);

GISMO_EXPORT void gsFitting_compute(gsCFitting* fitter, double lambda);
GISMO_EXPORT void gsFitting_parameterCorrection(gsCFitting* fitter, double accuracy, int maxIter, double tolOrth);

GISMO_EXPORT void gsFitting_computeErrors(gsCFitting* fitter);

GISMO_EXPORT double gsFitting_minPointError(gsCFitting* fitter);
GISMO_EXPORT double gsFitting_maxPointError(gsCFitting* fitter);
GISMO_EXPORT double* gsFitting_pointWiseErrors(gsCFitting* fitter);
GISMO_EXPORT int gsFitting_numPointsBelow(gsCFitting* fitter, double threshold);

GISMO_EXPORT gsCGeometry* gsFitting_result(gsCFitting* fitter);

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions src/gsCFunctionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ GISMO_EXPORT void gsFunctionSet_delete(gsCFunctionSet * ptr)
{ delete RICAST_F(ptr); }

GISMO_EXPORT int gsFunctionSet_domainDim(gsCFunctionSet * fs)
{ return RICAST_G(fs)->domainDim(); }
{ return RICAST_F(fs)->domainDim(); }

GISMO_EXPORT int gsFunctionSet_targetDim(gsCFunctionSet * fs)
{ return RICAST_G(fs)->targetDim(); }
{ return RICAST_F(fs)->targetDim(); }

GISMO_EXPORT gsCMatrix* gsFunctionSet_support(gsCFunctionSet * fs)
{ return RICAST_CM( new gismo::gsMatrix<double>(RICAST_F(fs)->support()) ); }
Expand Down
8 changes: 4 additions & 4 deletions src/gsCKnotVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ GISMO_EXPORT void gsKnotVector_print(gsCKnotVector * kv)
reinterpret_cast<gismo::gsKnotVector<double>*>(kv)->print(gsInfo);
}

// GISMO_EXPORT double* gsKnotVector_data(gsCKnotVector * kv)
// {
// return reinterpret_cast<gismo::gsKnotVector<double>*>(kv)->get().data();
// }
GISMO_EXPORT double* gsKnotVector_data(gsCKnotVector * kv)
{
return const_cast<double *>(reinterpret_cast<gismo::gsKnotVector<double>*>(kv)->get().data());
}

GISMO_EXPORT int gsKnotVector_size(gsCKnotVector * kv)
{
Expand Down
2 changes: 1 addition & 1 deletion src/gsCKnotVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C"
GISMO_EXPORT gsCKnotVector * gsKnotVector_create(double* knots, int size);
GISMO_EXPORT void gsKnotVector_delete(gsCKnotVector * kv);
GISMO_EXPORT void gsKnotVector_print(gsCKnotVector * kv);
// GISMO_EXPORT double* gsKnotVector_data(gsCKnotVector * kv);
GISMO_EXPORT double* gsKnotVector_data(gsCKnotVector * kv);
GISMO_EXPORT int gsKnotVector_size(gsCKnotVector * kv);
GISMO_EXPORT int gsKnotVector_uSize(gsCKnotVector * kv);
GISMO_EXPORT int gsKnotVector_numElements(gsCKnotVector * kv);
Expand Down
87 changes: 87 additions & 0 deletions src/gsCNurbsCreator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

#include <gismo.h>
#include <gsCInterface/gsCTypes.h>
#include <gsCInterface/gsCMatrix.h>
#include <gsCInterface/gsCGeometry.h>
#include <gsCInterface/gsCKnotVector.h>
#include <gsCInterface/gsCBasis.h>
#include <gsCInterface/gsMacros.h>

#ifdef __cplusplus
extern "C"
{
#endif

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineUnitInterval(int deg)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineUnitInterval(deg).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineRectangle(double low_x, double low_y, double upp_x, double upp_y, double turndeg)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineRectangle(low_x, low_y, upp_x, upp_y, turndeg).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineTrapezium(double Lbot, double Ltop, double H, double d, double turndeg)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineTrapezium(Lbot, Ltop, H, d, turndeg).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineSquare(double r, double x, double y)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineSquare(r, x, y).release());
}

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineSquareGrid(int n, int m, double r, double lx, double ly)
{
return RICAST_CMP(new gismo::gsMultiPatch<double>(gismo::gsNurbsCreator<double>::BSplineSquareGrid(n, m, r, lx, ly)));
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineCube(double r, double x, double y, double z)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineCube(r, x, y, z).release());
}

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineCubeGrid(int n, int m, int p, double r, double lx, double ly, double lz)
{
return RICAST_CMP(new gismo::gsMultiPatch<double>(gismo::gsNurbsCreator<double>::BSplineCubeGrid(n, m, p, r, lx, ly, lz)));
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsQuarterAnnulus(double r0, double r1)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::NurbsQuarterAnnulus(r0, r1).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsAnnulus(double r0, double r1)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::NurbsAnnulus(r0, r1).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineSaddle()
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineSaddle().release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsSphere(double r, double x, double y, double z)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::NurbsSphere(r, x, y, z).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsCircle(double r, double x, double y)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::NurbsCircle(r, x, y).release());
}

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineTriangle(double H, double W)
{
return RICAST_CG(gismo::gsNurbsCreator<double>::BSplineTriangle(H, W).release());
}

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineStar(int N, double R0, double R1)
{
return RICAST_CMP(new gismo::gsMultiPatch<double>(gismo::gsNurbsCreator<double>::BSplineStar(N, R0, R1)));
}

#ifdef __cplusplus
}
#endif
37 changes: 37 additions & 0 deletions src/gsCNurbsCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#ifdef __cplusplus
extern "C"
{
#endif

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineUnitInterval(int);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineRectangle(double, double, double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineTrapezium(double, double, double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineSquare(double, double, double);

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineSquareGrid(int, int, double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineCube(double, double, double, double);

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineCubeGrid(int, int, int, double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsQuarterAnnulus(double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsAnnulus(double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineSaddle();

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsSphere(double, double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_NurbsCircle(double, double, double);

GISMO_EXPORT gsCGeometry* gsNurbsCreator_BSplineTriangle(double, double);

GISMO_EXPORT gsCMultiPatch* gsNurbsCreator_BSplineStar(int, double, double);

#ifdef __cplusplus
}
#endif
89 changes: 89 additions & 0 deletions src/gsCOptionList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

#include <gismo.h>
#include <gsCInterface/gsCTypes.h>
#include <gsCInterface/gsMacros.h>
#include <gsCInterface/gsCOptionList.h>

#ifdef __cplusplus
extern "C"
{
#endif

GISMO_EXPORT gsCOptionList * gsOptionList_create()
{
return reinterpret_cast<gsCOptionList*>(new gismo::gsOptionList());
}

GISMO_EXPORT void gsOptionList_delete(gsCOptionList * ol)
{
delete reinterpret_cast<gismo::gsOptionList*>(ol);
}

GISMO_EXPORT void gsOptionList_print(gsCOptionList * ol)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->print(gsInfo);
}

GISMO_EXPORT void gsOptionList_addString(gsCOptionList * ol, const char * label, const char * description, const char * value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->addString(label, description, value);
}

GISMO_EXPORT void gsOptionList_addInt(gsCOptionList * ol, const char * label, const char * description, int value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->addInt(label, description, value);
}

GISMO_EXPORT void gsOptionList_addReal(gsCOptionList * ol, const char * label, const char * description, double value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->addReal(label, description, value);
}

GISMO_EXPORT void gsOptionList_addSwitch(gsCOptionList * ol, const char * label, const char * description, int value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->addSwitch(label, description, value);
}

GISMO_EXPORT void gsOptionList_setString(gsCOptionList * ol, const char * label, const char * value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->setString(label, value);
}

GISMO_EXPORT void gsOptionList_setInt(gsCOptionList * ol, const char * label, int value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->setInt(label, value);
}

GISMO_EXPORT void gsOptionList_setReal(gsCOptionList * ol, const char * label, double value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->setReal(label, value);
}

GISMO_EXPORT void gsOptionList_setSwitch(gsCOptionList * ol, const char * label, int value)
{
reinterpret_cast<gismo::gsOptionList*>(ol)->setSwitch(label, value);
}

GISMO_EXPORT char* gsOptionList_getString(gsCOptionList * ol, const char * label)
{
return const_cast<char*>(reinterpret_cast<gismo::gsOptionList*>(ol)->getString(label).c_str());
}

GISMO_EXPORT int gsOptionList_getInt(gsCOptionList * ol, const char * label)
{
return reinterpret_cast<gismo::gsOptionList*>(ol)->getInt(label);
}

GISMO_EXPORT double gsOptionList_getReal(gsCOptionList * ol, const char * label)
{
return reinterpret_cast<gismo::gsOptionList*>(ol)->getReal(label);
}

GISMO_EXPORT int gsOptionList_getSwitch(gsCOptionList * ol, const char * label)
{
return reinterpret_cast<gismo::gsOptionList*>(ol)->getSwitch(label);
}

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 6c88042

Please sign in to comment.