Skip to content

Commit

Permalink
add HBSpline(basis)
Browse files Browse the repository at this point in the history
add several functions for bases, geometries
Fix small inconsistencies with h and cpp files
  • Loading branch information
hverhelst committed May 24, 2024
1 parent 20c58a5 commit 20fda09
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 22 deletions.
200 changes: 199 additions & 1 deletion src/gsCBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,57 @@ GISMO_EXPORT gsCBasis* gsTHBSplineBasis4_create(gsCBasis* b)
return RICAST_CB(new gismo::gsTHBSplineBasis<4,double>(*basis_ptr,false));
}

GISMO_EXPORT gsCBasis* gsHBSplineBasis1_create(gsCBasis* b)
{
auto * basis_ptr = reinterpret_cast< gismo::gsTensorBSplineBasis<1,double>* >(b);
return RICAST_CB(new gismo::gsHBSplineBasis<1,double>(*basis_ptr,false));
}

GISMO_EXPORT gsCBasis* gsHBSplineBasis2_create(gsCBasis* b)
{
auto * basis_ptr = reinterpret_cast< gismo::gsTensorBSplineBasis<2,double>* >(b);
return RICAST_CB(new gismo::gsHBSplineBasis<2,double>(*basis_ptr,false));
}

GISMO_EXPORT gsCBasis* gsHBSplineBasis3_create(gsCBasis* b)
{
auto * basis_ptr = reinterpret_cast< gismo::gsTensorBSplineBasis<3,double>* >(b);
return RICAST_CB(new gismo::gsHBSplineBasis<3,double>(*basis_ptr,false));
}

GISMO_EXPORT gsCBasis* gsHBSplineBasis4_create(gsCBasis* b)
{
auto * basis_ptr = reinterpret_cast< gismo::gsTensorBSplineBasis<4,double>* >(b);
return RICAST_CB(new gismo::gsHBSplineBasis<4,double>(*basis_ptr,false));
}

//
// Methods
// Methods, gsBasis
//

GISMO_EXPORT void gsBasis_active_into(gsCBasis * b,
gsCMatrix * u,
gsCMatrixInt * result)
{ RICAST_B(b)->active_into(*RICAST_M(u), *RICAST_Mi(result) ); }

GISMO_EXPORT void gsBasis_evalSingle_into(gsCBasis * b,
int i,
gsCMatrix * u,
gsCMatrix * result)
{ RICAST_B(b)->evalSingle_into(i,*RICAST_M(u), *RICAST_M(result) ); }

GISMO_EXPORT void gsBasis_derivSingle_into(gsCBasis * b,
int i,
gsCMatrix * u,
gsCMatrix * result)
{ RICAST_B(b)->derivSingle_into(i,*RICAST_M(u), *RICAST_M(result) ); }

GISMO_EXPORT void gsBasis_deriv2Single_into(gsCBasis * b,
int i,
gsCMatrix * u,
gsCMatrix * result)
{ RICAST_B(b)->deriv2Single_into(i,*RICAST_M(u), *RICAST_M(result) ); }

GISMO_EXPORT gsCBasis * gsBasis_component(gsCBasis * b, int dir)
{
gismo::gsBasis<double> * c = & RICAST_B(b)->component(dir);
Expand All @@ -87,9 +129,15 @@ GISMO_EXPORT int gsBasis_degree(gsCBasis * b, int dir)
GISMO_EXPORT int gsBasis_numElements(gsCBasis * b)
{ return RICAST_B(b)->numElements(); }

GISMO_EXPORT int gsBasis_dim(gsCBasis * b)
{ return RICAST_B(b)->dim(); }

GISMO_EXPORT int gsBasis_size(gsCBasis * b)
{ return RICAST_B(b)->size(); }

GISMO_EXPORT gsCMatrix* gsBasis_support(gsCBasis * b, int i)
{ return reinterpret_cast<gsCMatrix*>( new gismo::gsMatrix<double>(RICAST_B(b)->support(i)) ); }

GISMO_EXPORT void gsBasis_uniformRefine(gsCBasis * b, int numKnots, int mul, int dir)
{ RICAST_B(b)->uniformRefine(numKnots, mul, dir); }

Expand All @@ -99,6 +147,156 @@ GISMO_EXPORT void gsBasis_refineElements(gsCBasis * b, int * boxData, int boxSiz
RICAST_B(b)->refineElements(boxes);
}

GISMO_EXPORT void gsBasis_refine(gsCBasis * b, gsCMatrix * boxes, int refExt)
{ RICAST_B(b)->refine(*RICAST_M(boxes),refExt); }

//
// Methods, Other
//

GISMO_EXPORT gsCKnotVector * gsBSplineBasis_knots(gsCBasis * b)
{
gismo::gsKnotVector<double> * KV= &reinterpret_cast< gismo::gsBSplineBasis<double>* >(b)->knots();
return reinterpret_cast<gsCKnotVector*>(KV);
}

GISMO_EXPORT gsCKnotVector * gsTensorBSplineBasis_knots(gsCBasis * b, int dir)
{
gismo::gsKnotVector<double> * KV=NULL;
GISMO_ASSERT(RICAST_B(b)->domainDim()>=dir,"gsTensorBSplineBasis_knots: dir out of range");
switch (RICAST_B(b)->domainDim())
{
case 2:
KV = &reinterpret_cast< gismo::gsTensorBSplineBasis<2,double>* >(b)->knots(dir);
case 3:
KV = &reinterpret_cast< gismo::gsTensorBSplineBasis<3,double>* >(b)->knots(dir);
case 4:
KV = &reinterpret_cast< gismo::gsTensorBSplineBasis<4,double>* >(b)->knots(dir);
}

return reinterpret_cast<gsCKnotVector*>(KV);
}

GISMO_EXPORT int gsHTensorBasis_numLevels(gsCBasis * b)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
return reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->numLevels();
case 2:
return reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->numLevels();
case 3:
return reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->numLevels();
case 4:
return reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->numLevels();
default:
GISMO_ERROR("gsHTensorBasis_numLevels: domainDim not supported");
}
}

GISMO_EXPORT int gsHTensorBasis_maxLevel(gsCBasis * b)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
return reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->maxLevel();
case 2:
return reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->maxLevel();
case 3:
return reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->maxLevel();
case 4:
return reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->maxLevel();
default:
GISMO_ERROR("gsHTensorBasis_maxLevel: domainDim not supported");
}
}

GISMO_EXPORT int gsHTensorBasis_levelOf(gsCBasis * b, int i)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
return reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->levelOf(i);
case 2:
return reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->levelOf(i);
case 3:
return reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->levelOf(i);
case 4:
return reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->levelOf(i);
default:
GISMO_ERROR("gsHTensorBasis_levelOf: domainDim not supported");
}
}

GISMO_EXPORT int gsHTensorBasis_getLevelAtPoint(gsCBasis * b, gsCMatrix * Pt)
{
auto * m = RICAST_M(Pt);
switch (RICAST_B(b)->domainDim())
{
case 1:
return reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->getLevelAtPoint(*m);
case 2:
return reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->getLevelAtPoint(*m);
case 3:
return reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->getLevelAtPoint(*m);
case 4:
return reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->getLevelAtPoint(*m);
default:
GISMO_ERROR("gsHTensorBasis_getLevelAtPoint: domainDim not supported");
}
}

GISMO_EXPORT gsCBasis * gsHTensorBasis_tensorLevel(gsCBasis * b, int l)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
return RICAST_CB(new gismo::gsBSplineBasis<double>(reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->tensorLevel(l)));
case 2:
return RICAST_CB(new gismo::gsTensorBSplineBasis<2,double>(reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->tensorLevel(l)));
case 3:
return RICAST_CB(new gismo::gsTensorBSplineBasis<3,double>(reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->tensorLevel(l)));
case 4:
return RICAST_CB(new gismo::gsTensorBSplineBasis<4,double>(reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->tensorLevel(l)));
default:
GISMO_ERROR("gsHTensorBasis_tensorLevel: domainDim not supported");
}
}

GISMO_EXPORT void gsHTensorBasis_treeLeafSize(gsCBasis * b)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->tree().leafSize();
case 2:
reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->tree().leafSize();
case 3:
reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->tree().leafSize();
case 4:
reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->tree().leafSize();
default:
GISMO_ERROR("gsHTensorBasis_treeLeaveSize: domainDim not supported");
}
}

GISMO_EXPORT void gsHTensorBasis_treePrintLeaves(gsCBasis * b)
{
switch (RICAST_B(b)->domainDim())
{
case 1:
reinterpret_cast< gismo::gsHTensorBasis<1,double>* >(b)->tree().printLeaves();
case 2:
reinterpret_cast< gismo::gsHTensorBasis<2,double>* >(b)->tree().printLeaves();
case 3:
reinterpret_cast< gismo::gsHTensorBasis<3,double>* >(b)->tree().printLeaves();
case 4:
reinterpret_cast< gismo::gsHTensorBasis<4,double>* >(b)->tree().printLeaves();
default:
GISMO_ERROR("gsHTensorBasis_treePrintLeaves: domainDim not supported");
}
}

#ifdef __cplusplus
}
#endif
42 changes: 38 additions & 4 deletions src/gsCBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,54 @@ extern "C"
GISMO_EXPORT gsCBasis* gsTensorBSplineBasis3_create(gsCKnotVector* KV1, gsCKnotVector* KV2, gsCKnotVector* KV3);
GISMO_EXPORT gsCBasis* gsTensorBSplineBasis4_create(gsCKnotVector* KV1, gsCKnotVector* KV2, gsCKnotVector* KV3, gsCKnotVector* KV4);

GISMO_EXPORT gsCBasis* THBSplineBasis1_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* THBSplineBasis2_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* THBSplineBasis3_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* THBSplineBasis4_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsTHBSplineBasis1_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsTHBSplineBasis2_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsTHBSplineBasis3_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsTHBSplineBasis4_create(gsCBasis* basis);

GISMO_EXPORT gsCBasis* gsHBSplineBasis1_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsHBSplineBasis2_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsHBSplineBasis3_create(gsCBasis* basis);
GISMO_EXPORT gsCBasis* gsHBSplineBasis4_create(gsCBasis* basis);

//
// Methods, gsBasis
//
GISMO_EXPORT void gsBasis_active_into(gsCBasis * b, gsCMatrix * u, gsCMatrixInt * result);

GISMO_EXPORT void gsBasis_evalSingle_into(gsCBasis * b, int i, gsCMatrix * u, gsCMatrix * result);
GISMO_EXPORT void gsBasis_derivSingle_into(gsCBasis * b, int i, gsCMatrix * u, gsCMatrix * result);
GISMO_EXPORT void gsBasis_deriv2Single_into(gsCBasis * b, int i, gsCMatrix * u, gsCMatrix * result);

GISMO_EXPORT gsCBasis * gsBasis_component(gsCBasis * b, int dir);
GISMO_EXPORT int gsBasis_degree(gsCBasis * b, int dir);
GISMO_EXPORT int gsBasis_numElements(gsCBasis * b);
GISMO_EXPORT int gsBasis_dim(gsCBasis * b);
GISMO_EXPORT int gsBasis_size(gsCBasis * b);
GISMO_EXPORT gsCMatrix* gsBasis_support(gsCBasis * b, int i);

GISMO_EXPORT void gsBasis_uniformRefine(gsCBasis * b, int numKnots, int mul, int dir);
GISMO_EXPORT void gsBasis_refineElements(gsCBasis * b, int * boxData, int boxSize);
GISMO_EXPORT void gsBasis_refine(gsCBasis * b, gsCMatrix * boxes, int refExt);

// TODO:
// - DegreeElevate

//
// Methods, Other
//
GISMO_EXPORT gsCKnotVector * gsBSplineBasis_knots(gsCBasis * b);
GISMO_EXPORT gsCKnotVector * gsTensorBSplineBasis_knots(gsCBasis * b, int dir);


GISMO_EXPORT int gsHTensorBasis_numLevels(gsCBasis * b);
GISMO_EXPORT int gsHTensorBasis_maxLevel(gsCBasis * b);
GISMO_EXPORT int gsHTensorBasis_levelOf(gsCBasis * b, int i);
GISMO_EXPORT int gsHTensorBasis_getLevelAtPoint(gsCBasis * b, gsCMatrix * Pt);
GISMO_EXPORT gsCBasis * gsHTensorBasis_tensorLevel(gsCBasis * b, int l);
GISMO_EXPORT void gsHTensorBasis_treeLeafSize(gsCBasis * b);
GISMO_EXPORT void gsHTensorBasis_treePrintLeaves(gsCBasis * b);


#ifdef __cplusplus
}
Expand Down
3 changes: 3 additions & 0 deletions src/gsCFunctionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ GISMO_EXPORT int gsFunctionSet_domainDim(gsCFunctionSet * fs)
GISMO_EXPORT int gsFunctionSet_targetDim(gsCFunctionSet * fs)
{ return RICAST_G(fs)->targetDim(); }

GISMO_EXPORT gsCMatrix* gsFunctionSet_support(gsCFunctionSet * fs)
{ return reinterpret_cast<gsCMatrix*>( new gismo::gsMatrix<double>(RICAST_F(fs)->support()) ); }

GISMO_EXPORT void gsFunctionSet_eval_into(gsCFunctionSet * fs,
gsCMatrix * u,
gsCMatrix * result)
Expand Down
6 changes: 1 addition & 5 deletions src/gsCFunctionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C"
GISMO_EXPORT int gsFunctionSet_domainDim(gsCFunctionSet * fs);
GISMO_EXPORT int gsFunctionSet_targetDim(gsCFunctionSet * fs);

GISMO_EXPORT gsCBasis * gsFunctionSet_basis(gsCFunctionSet * fs, int i);
GISMO_EXPORT gsCMatrix* gsFunctionSet_support(gsCFunctionSet * fs);

GISMO_EXPORT void gsFunctionSet_eval_into(gsCFunctionSet * fs,
gsCMatrix * u,
Expand All @@ -19,10 +19,6 @@ extern "C"
gsCMatrix * u,
gsCMatrix * result);

GISMO_EXPORT void gsFunctionSet_normal_into(gsCFunctionSet * fs,
gsCMatrix * u,
gsCMatrix * result);

#ifdef __cplusplus
}
#endif
28 changes: 28 additions & 0 deletions src/gsCGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ GISMO_EXPORT gsCGeometry* gsTHBSpline4_create(gsCBasis* b, gsCMatrix * coefs)
return RICAST_CG(new gismo::gsTHBSpline<4,double>(*basis_ptr,*m));
}

GISMO_EXPORT gsCGeometry* gsHBSpline1_create(gsCBasis* b, gsCMatrix * coefs)
{
auto * basis_ptr = reinterpret_cast< gismo::gsHBSplineBasis<1,double>* >(b);
auto * m = RICAST_M(coefs);
return RICAST_CG(new gismo::gsHBSpline<1,double>(*basis_ptr,*m));
}

GISMO_EXPORT gsCGeometry* gsHBSpline2_create(gsCBasis* b, gsCMatrix * coefs)
{
auto * basis_ptr = reinterpret_cast< gismo::gsHBSplineBasis<2,double>* >(b);
auto * m = RICAST_M(coefs);
return RICAST_CG(new gismo::gsHBSpline<2,double>(*basis_ptr,*m));
}

GISMO_EXPORT gsCGeometry* gsHBSpline3_create(gsCBasis* b, gsCMatrix * coefs)
{
auto * basis_ptr = reinterpret_cast< gismo::gsHBSplineBasis<3,double>* >(b);
auto * m = RICAST_M(coefs);
return RICAST_CG(new gismo::gsHBSpline<3,double>(*basis_ptr,*m));
}

GISMO_EXPORT gsCGeometry* gsHBSpline4_create(gsCBasis* b, gsCMatrix * coefs)
{
auto * basis_ptr = reinterpret_cast< gismo::gsHBSplineBasis<4,double>* >(b);
auto * m = RICAST_M(coefs);
return RICAST_CG(new gismo::gsHBSpline<4,double>(*basis_ptr,*m));
}

GISMO_EXPORT gsCBasis* gsGeometry_basis(gsCGeometry * g)
{ return RICAST_CB(&RICAST_G(g)->basis()); }

Expand Down
5 changes: 5 additions & 0 deletions src/gsCGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ extern "C"
GISMO_EXPORT gsCGeometry* gsTHBSpline3_create(gsCBasis* b, gsCMatrix * coef);
GISMO_EXPORT gsCGeometry* gsTHBSpline4_create(gsCBasis* b, gsCMatrix * coef);

GISMO_EXPORT gsCGeometry* gsHBSpline1_create(gsCBasis* b, gsCMatrix * coef);
GISMO_EXPORT gsCGeometry* gsHBSpline2_create(gsCBasis* b, gsCMatrix * coef);
GISMO_EXPORT gsCGeometry* gsHBSpline3_create(gsCBasis* b, gsCMatrix * coef);
GISMO_EXPORT gsCGeometry* gsHBSpline4_create(gsCBasis* b, gsCMatrix * coef);

GISMO_EXPORT gsCBasis* gsGeometry_basis(gsCGeometry * g);

GISMO_EXPORT void gsGeometry_coefs_into(gsCGeometry * g, gsCMatrix * coef);
Expand Down
2 changes: 1 addition & 1 deletion src/gsCMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GISMO_EXPORT void gsMatrix_print(gsCMatrix * m)
GISMO_EXPORT double * gsMatrix_data(gsCMatrix * m)
{ return RICAST_M(m)->data(); }

GISMO_EXPORT void transposeInPlace(gsCMatrix * m)
GISMO_EXPORT void gsMatrix_transposeInPlace(gsCMatrix * m)
{ return RICAST_M(m)->transposeInPlace(); }

GISMO_EXPORT int gsMatrix_rows(gsCMatrix * m)
Expand Down
2 changes: 1 addition & 1 deletion src/gsCMatrixInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GISMO_EXPORT void gsMatrixInt_print(gsCMatrixInt * m)
GISMO_EXPORT int * gsMatrixInt_data(gsCMatrixInt * m)
{ return RICAST_Mi(m)->data(); }

GISMO_EXPORT void transposeInPlace(gsCMatrixInt * m)
GISMO_EXPORT void gsMatrixInt_transposeInPlace(gsCMatrixInt * m)
{ return RICAST_Mi(m)->transposeInPlace(); }

GISMO_EXPORT int gsMatrixInt_rows(gsCMatrixInt * m)
Expand Down
6 changes: 6 additions & 0 deletions src/gsCMultiPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ GISMO_EXPORT gsCGeometry * gsMultiPatch_patch(gsCMultiPatch * mp, int i)
return RICAST_CG(&mp_ptr->patch(i));
}

GISMO_EXPORT void gsMultiPatch_delete(gsCMultiPatch * mp)
{
auto * mp_ptr = RICAST_MP(mp);
mp_ptr->clear();
}

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 20fda09

Please sign in to comment.