From 7ea28853403aa32d8a55f275e418b8fc679ad664 Mon Sep 17 00:00:00 2001 From: Anthony Royer <anthony.royer@uliege.be> Date: Wed, 6 May 2020 15:27:34 +0200 Subject: [PATCH] Add 'gmsh::model::mesh::getNumberOfOrientations' --- Common/gmsh.cpp | 27 +++++++++++++++++++++++++++ api/gen.py | 3 +++ api/gmsh.h | 7 +++++++ api/gmsh.h_cwrap | 11 +++++++++++ api/gmsh.jl | 17 +++++++++++++++++ api/gmsh.py | 21 +++++++++++++++++++++ api/gmshc.cpp | 13 +++++++++++++ api/gmshc.h | 6 ++++++ doc/texinfo/api.texi | 13 +++++++++++++ 9 files changed, 118 insertions(+) diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp index 4b28552f6c..19ce09c27a 100644 --- a/Common/gmsh.cpp +++ b/Common/gmsh.cpp @@ -2814,6 +2814,33 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElements( return; } +GMSH_API int gmsh::model::mesh::getNumberOfOrientations(const int elementType, + const std::string & functionSpaceType) +{ + if(!_isInitialized()) { throw - 1; } + + int basisOrder = 0; + std::string fsName = ""; + int numComponents = 0; + if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder, + numComponents)) { + Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str()); + throw 2; + } + + if(fsName == "Lagrange" || fsName == "GradLagrange") { // Lagrange type + return 1; + } + else { // Hierarchical type + const int familyType = ElementType::getParentType(elementType); + const unsigned int numVertices = ElementType::getNumVertices(ElementType::getType(familyType, 1, false)); + const std::size_t factorial[8] = {1, 1, 2, 6, 24, 120, 720, 5040}; + return factorial[numVertices]; + } + + return 0; +} + GMSH_API void gmsh::model::mesh::preallocateBasisFunctionsOrientationForElements( const int elementType, std::vector<int> &basisFunctionsOrientation, diff --git a/api/gen.py b/api/gen.py index 4af8b57bbc..7bd28efa18 100644 --- a/api/gen.py +++ b/api/gen.py @@ -317,6 +317,9 @@ mesh.add('getBasisFunctions', doc, None, iint('elementType'), ivectordouble('loc doc = '''Get the orientation index of the elements of type `elementType' in the entity of tag `tag'. The arguments have the same meaning as in `getBasisFunctions'. `basisFunctionsOrientation' is a vector giving for each element the orientation index in the values returned by `getBasisFunctions'. For Lagrange basis functions the call is superfluous as it will return a vector of zeros.''' mesh.add('getBasisFunctionsOrientationForElements', doc, None, iint('elementType'), istring('functionSpaceType'), ovectorint('basisFunctionsOrientation'), iint('tag','-1'), isize('task', '0'), isize('numTasks', '1')) +doc = '''Get the number of possible orientations for elements of type `elementType' and function space named `functionSpaceType'.''' +mesh.add('getNumberOfOrientations', doc, oint, iint('elementType'), istring('functionSpaceType')) + doc = '''Preallocate data before calling `getBasisFunctionsOrientationForElements' with `numTasks' > 1. For C and C++ only.''' mesh.add_special('preallocateBasisFunctionsOrientationForElements', doc, ['onlycc++'], None, iint('elementType'), ovectorint('basisFunctionsOrientation'), iint('tag', '-1')) diff --git a/api/gmsh.h b/api/gmsh.h index 8b4855ad8b..8f6280453e 100644 --- a/api/gmsh.h +++ b/api/gmsh.h @@ -953,6 +953,13 @@ namespace gmsh { // Top-level functions const std::size_t task = 0, const std::size_t numTasks = 1); + // gmsh::model::mesh::getNumberOfOrientations + // + // Get the number of possible orientations for elements of type `elementType' + // and function space named `functionSpaceType'. + GMSH_API int getNumberOfOrientations(const int elementType, + const std::string & functionSpaceType); + // gmsh::model::mesh::preallocateBasisFunctionsOrientationForElements // // Preallocate data before calling `getBasisFunctionsOrientationForElements' diff --git a/api/gmsh.h_cwrap b/api/gmsh.h_cwrap index 4653fec5f0..d3d3887a26 100644 --- a/api/gmsh.h_cwrap +++ b/api/gmsh.h_cwrap @@ -1444,6 +1444,17 @@ namespace gmsh { // Top-level functions basisFunctionsOrientation.assign(api_basisFunctionsOrientation_, api_basisFunctionsOrientation_ + api_basisFunctionsOrientation_n_); gmshFree(api_basisFunctionsOrientation_); } + // Get the number of possible orientations for elements of type `elementType' + // and function space named `functionSpaceType'. + inline int getNumberOfOrientations(const int elementType, + const std::string & functionSpaceType) + { + int ierr = 0; + int result_api_ = gmshModelMeshGetNumberOfOrientations(elementType, functionSpaceType.c_str(), &ierr); + if(ierr) throw ierr; + return result_api_; + } + // Preallocate data before calling `getBasisFunctionsOrientationForElements' // with `numTasks' > 1. For C and C++ only. inline void preallocateBasisFunctionsOrientationForElements(const int elementType, diff --git a/api/gmsh.jl b/api/gmsh.jl index 7dc02ae0c1..d18a22f961 100644 --- a/api/gmsh.jl +++ b/api/gmsh.jl @@ -1803,6 +1803,23 @@ function getBasisFunctionsOrientationForElements(elementType, functionSpaceType, return basisFunctionsOrientation end +""" + gmsh.model.mesh.getNumberOfOrientations(elementType, functionSpaceType) + +Get the number of possible orientations for elements of type `elementType` and +function space named `functionSpaceType`. + +Return an integer value. +""" +function getNumberOfOrientations(elementType, functionSpaceType) + ierr = Ref{Cint}() + api__result__ = ccall((:gmshModelMeshGetNumberOfOrientations, gmsh.lib), Cint, + (Cint, Ptr{Cchar}, Ptr{Cint}), + elementType, functionSpaceType, ierr) + ierr[] != 0 && error("gmshModelMeshGetNumberOfOrientations returned non-zero error code: $(ierr[])") + return api__result__ +end + """ gmsh.model.mesh.getEdgeNumber(edgeNodes) diff --git a/api/gmsh.py b/api/gmsh.py index 52d33510e0..c74dcf90d0 100644 --- a/api/gmsh.py +++ b/api/gmsh.py @@ -2330,6 +2330,27 @@ class model: ierr.value) return _ovectorint(api_basisFunctionsOrientation_, api_basisFunctionsOrientation_n_.value) + @staticmethod + def getNumberOfOrientations(elementType, functionSpaceType): + """ + gmsh.model.mesh.getNumberOfOrientations(elementType, functionSpaceType) + + Get the number of possible orientations for elements of type `elementType' + and function space named `functionSpaceType'. + + Return an integer value. + """ + ierr = c_int() + api__result__ = lib.gmshModelMeshGetNumberOfOrientations( + c_int(elementType), + c_char_p(functionSpaceType.encode()), + byref(ierr)) + if ierr.value != 0: + raise ValueError( + "gmshModelMeshGetNumberOfOrientations returned non-zero error code: ", + ierr.value) + return api__result__ + @staticmethod def getEdgeNumber(edgeNodes): """ diff --git a/api/gmshc.cpp b/api/gmshc.cpp index 005283731c..2db6cd2ee5 100644 --- a/api/gmshc.cpp +++ b/api/gmshc.cpp @@ -1230,6 +1230,19 @@ GMSH_API void gmshModelMeshGetBasisFunctionsOrientationForElements(const int ele } } +GMSH_API int gmshModelMeshGetNumberOfOrientations(const int elementType, const char * functionSpaceType, int * ierr) +{ + int result_api_ = 0; + if(ierr) *ierr = 0; + try { + result_api_ = gmsh::model::mesh::getNumberOfOrientations(elementType, functionSpaceType); + } + catch(int api_ierr_){ + if(ierr) *ierr = api_ierr_; + } + return result_api_; +} + GMSH_API void gmshModelMeshPreallocateBasisFunctionsOrientationForElements(const int elementType, int ** basisFunctionsOrientation, size_t * basisFunctionsOrientation_n, const int tag, int * ierr) { if(ierr) *ierr = 0; diff --git a/api/gmshc.h b/api/gmshc.h index 185caece3b..41ddb6e583 100644 --- a/api/gmshc.h +++ b/api/gmshc.h @@ -832,6 +832,12 @@ GMSH_API void gmshModelMeshGetBasisFunctionsOrientationForElements(const int ele const size_t numTasks, int * ierr); +/* Get the number of possible orientations for elements of type `elementType' + * and function space named `functionSpaceType'. */ +GMSH_API int gmshModelMeshGetNumberOfOrientations(const int elementType, + const char * functionSpaceType, + int * ierr); + /* Preallocate data before calling `getBasisFunctionsOrientationForElements' * with `numTasks' > 1. For C and C++ only. */ GMSH_API void gmshModelMeshPreallocateBasisFunctionsOrientationForElements(const int elementType, diff --git a/doc/texinfo/api.texi b/doc/texinfo/api.texi index 821a047319..522b672923 100644 --- a/doc/texinfo/api.texi +++ b/doc/texinfo/api.texi @@ -1464,6 +1464,19 @@ as it will return a vector of zeros. - @end table +@item gmsh/model/mesh/getNumberOfOrientations +Get the number of possible orientations for elements of type @code{elementType} +and function space named @code{functionSpaceType}. + +@table @asis +@item Input: +@code{elementType}, @code{functionSpaceType} +@item Output: +- +@item Return: +integer value +@end table + @item gmsh/model/mesh/preallocateBasisFunctionsOrientationForElements Preallocate data before calling @code{getBasisFunctionsOrientationForElements} with @code{numTasks} > 1. For C and C++ only. -- GitLab