Skip to content

Commit

Permalink
* NL: Added low-level access to matrix in OpenNL
Browse files Browse the repository at this point in the history
* periodic.h: added access to nb_vertices_non_periodic()
* cleanup
  • Loading branch information
BrunoLevy committed Nov 4, 2024
1 parent 2af7e14 commit 0ed6b85
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 16 deletions.
26 changes: 26 additions & 0 deletions src/lib/geogram/NL/nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,32 @@ extern "C" {
*/
NLAPI void NLAPIENTRY nlPrintfFuncs(NLprintfFunc f1, NLfprintfFunc f2);

/**
* @}
* \name Low-level access
* @{
*/

/**
* \brief Forward declaration of Matrix structure
* \details Standard usage does not need to access the
* structure. For advanced users, it is declared in
* nl_matrix.h.
*/
struct NLMatrixStruct;

/**
* \brief Opaque handle to a matrix
*/
typedef struct NLMatrixStruct* NLMatrix;

/**
* \brief Gets the current matrix
* \details for advanced low-level matrix manipulation
* \return a pointer to the current matrix, can be a NLSparseMatrix
* or a NLCRSMatrix depending on whether pattern was pre-created.
*/
NLAPI NLMatrix NLAPIENTRY nlGetCurrentMatrix(void);

/**
* @}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/geogram/NL/nl_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ static NLCRSMatrix* nlGetCurrentCRSMatrix(void) {

/*****************************************************************************/

NLMatrix nlGetCurrentMatrix(void) {
return nlCurrentContext->has_matrix_pattern ?
(NLMatrix) nlGetCurrentCRSMatrix() :
(NLMatrix) nlGetCurrentSparseMatrix() ;
}

/*****************************************************************************/

NLboolean nlInitExtension(const char* extension) {
if(!strcmp(extension, "SUPERLU")) {
return nlInitExtension_SUPERLU();
Expand Down
13 changes: 10 additions & 3 deletions src/lib/geogram/basic/geofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,18 @@ namespace GEO {
if(ascii_) {
if(comment == nullptr) {
if(fprintf(ascii_file_, "\"%s\"\n", encode(str).c_str()) == 0) {
throw GeoFileException("Could not write string data to file");
throw GeoFileException(
"Could not write string data to file"
);
}
} else {
if(fprintf(ascii_file_, "\"%s\" # this is %s\n", encode(str).c_str(), comment) == 0) {
throw GeoFileException("Could not write string data to file");
if(fprintf(
ascii_file_, "\"%s\" # this is %s\n",
encode(str).c_str(), comment) == 0
) {
throw GeoFileException(
"Could not write string data to file"
);
}
}
return;
Expand Down
14 changes: 8 additions & 6 deletions src/lib/geogram/basic/stopwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@ namespace GEO {
double Stopwatch::elapsed_time() const {
auto now(std::chrono::system_clock::now());
auto elapsed = now-start_;
auto elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
elapsed
);
auto elapsed_milliseconds =
std::chrono::duration_cast<std::chrono::milliseconds>(
elapsed
);
return 0.001 * double(elapsed_milliseconds.count());
}

double Stopwatch::now() {
auto now(std::chrono::system_clock::now());
auto elapsed = now.time_since_epoch();
auto elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
elapsed
);
auto elapsed_milliseconds =
std::chrono::duration_cast<std::chrono::milliseconds>(
elapsed
);
return 0.001 * double(elapsed_milliseconds.count());
}

Expand Down
4 changes: 1 addition & 3 deletions src/lib/geogram/delaunay/parallel_delaunay_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ namespace GEO {
* \return a poiner to the \p t th thread
*/
Delaunay3dThread* thread(index_t t) {
return static_cast<Delaunay3dThread*>(
master_->threads_[t].get()
);
return static_cast<Delaunay3dThread*>(master_->threads_[t].get());
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/lib/geogram/delaunay/periodic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ namespace GEO {
class GEOGRAM_API Periodic {
public:

/**
* \brief Gets the number of non-periodic vertices
* \details in periodic mode, nb_vertices() returns
* the total number of vertices, real ones and
* periodic instances. This function gets the number
* of real vertices.
* \return the number of non-periodic vertices
*/
index_t nb_vertices_non_periodic() const {
return nb_vertices_non_periodic_;
}

/**
* \brief Gets the instance from a periodic vertex.
* \return the instance in 0..26
Expand Down
11 changes: 7 additions & 4 deletions src/lib/geogram/delaunay/periodic_delaunay_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,7 @@ namespace GEO {


/**
* \brief Creates a star of tetrahedra filling the conflict
* zone.
* \brief Creates a star of tetrahedra filling the conflict zone.
* \param[in] v the index of the point to be inserted
* \details This function is used when the Cavity computed
* when traversing the conflict zone is OK, that is to say
Expand Down Expand Up @@ -949,7 +948,7 @@ namespace GEO {
)
);

// At this point, this threads owns all the tets in conflict and
// At this point, this thread owns all the tets in conflict and
// their neighbors, therefore no other thread can interfere, and
// we can update the triangulation.

Expand Down Expand Up @@ -3423,11 +3422,13 @@ namespace GEO {

// Create periodic_v_to_cell_ structure in compressed row
// storage format.

// It was used in previous version for handling periodic boundary
// conditions based on ConvexCell, it is no longer the case, new
// code solely uses tetrahedra. It is kept here for reference for
// implementing the distributed version (using ConvexCell can save
// points tranfers).

if(update_periodic_v_to_cell_) {
periodic_v_to_cell_rowptr_.resize(nb_vertices_non_periodic_ + 1);
periodic_v_to_cell_rowptr_[0] = 0;
Expand Down Expand Up @@ -3943,6 +3944,8 @@ namespace GEO {

// Local tet vertex indices from facet and vertex in facet indices.
// Carefully chosen in such a way that f[(lv+1)%3][2] == lv
// This is used in the code block below, that handles tets with
// a vertex at infinity
static GEO::index_t fv[4][3] = {
{1,2,3},
{3,2,0},
Expand Down Expand Up @@ -4181,7 +4184,7 @@ namespace GEO {
std::abs(Ty2 - Ty1) >= 2 ||
std::abs(Tz2 - Tz1) >= 2
) {
// Here we could use -1 to encore large displacements,
// Here we could use -1 to encode large displacements,
// and issue an error message (for now they are ignored)
continue;
}
Expand Down

0 comments on commit 0ed6b85

Please sign in to comment.