Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 342 fix curvedblocking copy ids #356

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions blocking/inc/gmds/blocking/CurvedBlocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ namespace gmds {
/*----------------------------------------------------------------------------*/
namespace blocking {
/*----------------------------------------------------------------------------*/
class Counter{
public:
Counter(int c)
: m_counter_global_id(c){}
int get_and_increment_id(){return m_counter_global_id++;}
int value(){return m_counter_global_id;}
private:
int m_counter_global_id;
};
/**@struct CellInfo
* @brief This structure gather the pieces of data that are shared by any
* blocking cell. Each cell is defined by:
Expand All @@ -41,22 +50,29 @@ struct CellInfo
int topo_id;
/*** link to the cad manager to have access to geometric cells */
cad::GeomManager* geom_manager;
/*** link to the counter used to assign a unique id to each entity */
Counter* counter;
/*** dimension of the geometrical cell we are classifid on */
int geom_dim;
/*** unique id of the geomtrical cell */
int geom_id;
/*** global counter used to assign an unique id to each block */
static int m_counter_global_id;

/** @brief Constructor
* @param Ac the id counter; the CGAL gmap copy constructor requires a CellInfo()
* call with no params
* @param AManager the geometric manager to access cells
* @param ATopoDim Cell dimension
* @param AGeomDim on-classify geometric cell dimension (4 if not classified)
* @param AGeomId on-classify geometric cell unique id
*/
CellInfo(cad::GeomManager* AManager, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
topo_dim(ATopoDim), topo_id(m_counter_global_id++), geom_manager(AManager),geom_dim(AGeomDim), geom_id(AGeomId)
CellInfo(Counter* Ac=nullptr, cad::GeomManager* AManager=nullptr, const int ATopoDim = 4, const int AGeomDim = 4, const int AGeomId = NullID) :
topo_dim(ATopoDim), geom_manager(AManager), counter(Ac), geom_dim(AGeomDim), geom_id(AGeomId)
{
if(Ac != nullptr) {
topo_id = Ac->get_and_increment_id();
} else {
topo_id = -1;
}
}
};
/*----------------------------------------------------------------------------*/
Expand All @@ -69,13 +85,15 @@ struct NodeInfo : CellInfo
/*** node location in space, i.e. a single point */
math::Point point;
/** @brief Constructor
* @param Ac the id counter; the CGAL gmap copy constructor requires a CellInfo()
* call with no params
* @param AManager the geometric manager to access cells
* @param AGeomDim on-classify geometric cell dimension (4 if not classified)
* @param AGeomId on-classify geometric cell unique id
* @param APoint geometric location
*/
NodeInfo(cad::GeomManager* AManager, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
CellInfo(AManager, 0, AGeomDim, AGeomId), point(APoint)
NodeInfo(Counter* Ac=nullptr, cad::GeomManager* AManager=nullptr, const int AGeomDim = 4, const int AGeomId = NullID, const math::Point &APoint = math::Point(0, 0, 0)) :
CellInfo(Ac, AManager, 0, AGeomDim, AGeomId), point(APoint)
{
}
};
Expand Down Expand Up @@ -208,8 +226,7 @@ struct SplitFunctor
ca2.info().geom_dim = ca1.info().geom_dim;
ca2.info().geom_id = ca1.info().geom_id;
ca2.info().topo_dim = ca1.info().topo_dim;
ca2.info().topo_id = CellInfo::m_counter_global_id++;

ca2.info().topo_id = ca1.info().counter->get_and_increment_id();
}
};

Expand All @@ -227,7 +244,7 @@ struct SplitFunctorNode
ca2.info().geom_id = ca1.info().geom_id;
ca2.info().point = ca1.info().point;
ca2.info().topo_dim = ca1.info().topo_dim;
ca2.info().topo_id = CellInfo::m_counter_global_id++;
ca2.info().topo_id = ca1.info().counter->get_and_increment_id();
}
};
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -278,6 +295,8 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
*/
CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox = false);

CurvedBlocking(const CurvedBlocking &ABl);

/** @brief Destructor
*/
virtual ~CurvedBlocking();
Expand Down Expand Up @@ -685,6 +704,11 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
*/
std::vector<std::pair<double, double>> get_projection_info(math::Point &AP, std::vector<CurvedBlocking::Edge> &AEdges);

Counter* getCounter()
{
return &m_counter;
}

private:

/**@brief Mark with @p AMark all the darts of orbit <0,1>(@p ADart)
Expand Down Expand Up @@ -736,6 +760,9 @@ class LIB_GMDS_BLOCKING_API CurvedBlocking
cad::GeomManager *m_geom_model;
/*** the underlying n-g-map model*/
GMap3 m_gmap;

/*** id counter*/
Counter m_counter;
};
/*----------------------------------------------------------------------------*/
} // namespace blocking
Expand Down
36 changes: 29 additions & 7 deletions blocking/src/CurvedBlocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using namespace gmds;
using namespace gmds::blocking;
/*----------------------------------------------------------------------------*/
int CellInfo::m_counter_global_id = 0;
//int CellInfo::m_counter_global_id = 0;

/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox) : m_geom_model(AGeomModel) {
CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundingBox)
: m_geom_model(AGeomModel), m_counter(0)
{
if (AInitAsBoundingBox) {
TCoord min[3] = {MAXFLOAT, MAXFLOAT, MAXFLOAT};
TCoord max[3] = {-MAXFLOAT, -MAXFLOAT, -MAXFLOAT};
Expand All @@ -32,7 +34,27 @@ CurvedBlocking::CurvedBlocking(cad::GeomManager *AGeomModel, bool AInitAsBoundin
create_block(p1, p2, p3, p4, p5, p6, p7, p8);
}
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::CurvedBlocking(const CurvedBlocking &ABl)
: m_geom_model(ABl.m_geom_model), m_gmap(ABl.m_gmap), m_counter(ABl.m_counter)
{
auto listBlocks = get_all_blocks();
for(auto b : listBlocks){
b->info().counter = &m_counter;
}
auto listFaces = get_all_faces();
for(auto b : listFaces){
b->info().counter = &m_counter;
}
auto listEdges = get_all_edges();
for(auto b : listEdges){
b->info().counter = &m_counter;
}
auto listNodes = get_all_nodes();
for(auto b : listNodes){
b->info().counter = &m_counter;
}
}
/*----------------------------------------------------------------------------*/
CurvedBlocking::~CurvedBlocking() {}

Expand All @@ -51,25 +73,25 @@ CurvedBlocking::geom_model() {
/*----------------------------------------------------------------------------*/
CurvedBlocking::Node
CurvedBlocking::create_node(const int AGeomDim, const int AGeomId, const math::Point &APoint) {
return m_gmap.create_attribute<0>(NodeInfo(m_geom_model,AGeomDim, AGeomId, APoint));
return m_gmap.create_attribute<0>(NodeInfo(this->getCounter(),m_geom_model,AGeomDim, AGeomId, APoint));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Edge
CurvedBlocking::create_edge(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<1>(CellInfo(m_geom_model,1, AGeomDim, AGeomId));
return m_gmap.create_attribute<1>(CellInfo(this->getCounter(),m_geom_model,1, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Face
CurvedBlocking::create_face(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<2>(CellInfo(m_geom_model,2, AGeomDim, AGeomId));
return m_gmap.create_attribute<2>(CellInfo(this->getCounter(),m_geom_model,2, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
CurvedBlocking::Block
CurvedBlocking::create_block(const int AGeomDim, const int AGeomId) {
return m_gmap.create_attribute<3>(CellInfo(m_geom_model,3, AGeomDim, AGeomId));
return m_gmap.create_attribute<3>(CellInfo(this->getCounter(),m_geom_model,3, AGeomDim, AGeomId));
}

/*----------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion blocking/src/CurvedBlockingClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ std::vector<std::pair<TCellID ,double>>
CurvedBlockingClassifier::list_Possible_Cuts()
{
std::vector<std::pair<TCellID ,double>> list_actions;
auto no_capt_elements = classify();
auto no_capt_elements = this->classify();
auto no_points_capt = no_capt_elements.non_captured_points;
auto no_curves_capt = no_capt_elements.non_captured_curves;

Expand Down
81 changes: 81 additions & 0 deletions blocking/tst/ExecutionActionsTestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,84 @@ TEST(ExecutionActionsTestSuite,cb5){
vtk_writer_edges.write("debug_blocking_edges.vtk");
}



TEST(ExecutionActionsTestSuite,cb2_auto) {
gmds::cad::FACManager geom_model;
set_up_file(&geom_model,"cb2.vtk");
gmds::blocking::CurvedBlocking bl(&geom_model,true);
gmds::blocking::CurvedBlockingClassifier classifier(&bl);


classifier.clear_classification();

auto errors = classifier.classify();


//Check nb points of the geometry and nb nodes of the blocking
ASSERT_EQ(16,geom_model.getNbPoints());
ASSERT_EQ(24,geom_model.getNbCurves());
ASSERT_EQ(10,geom_model.getNbSurfaces());
ASSERT_EQ(8,bl.get_all_nodes().size());
ASSERT_EQ(12,bl.get_all_edges().size());
ASSERT_EQ(6,bl.get_all_faces().size());



//Check elements class and captured
//Check nb nodes/edges/faces no classified
ASSERT_EQ(0,errors.non_classified_nodes.size());
ASSERT_EQ(0,errors.non_classified_edges.size());
ASSERT_EQ(6,errors.non_classified_faces.size());

//Check nb points/curves/surfaces no captured
ASSERT_EQ(8,errors.non_captured_points.size());
ASSERT_EQ(12,errors.non_captured_curves.size());
ASSERT_EQ(10,errors.non_captured_surfaces.size());

auto listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);


classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);

classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);

classifier.classify();

listEdgesCut = classifier.list_Possible_Cuts();
//Do 1 cut
bl.cut_sheet(listEdgesCut.front().first,listEdgesCut.front().second);


gmds::Mesh m(gmds::MeshModel(gmds::DIM3|gmds::N|gmds::E|gmds::F|gmds::R|gmds::E2N|gmds::F2N|gmds::R2N));
bl.convert_to_mesh(m);


gmds::IGMeshIOService ios(&m);
gmds::VTKWriter vtk_writer(&ios);
vtk_writer.setCellOptions(gmds::N|gmds::R);
vtk_writer.setDataOptions(gmds::N|gmds::R);
vtk_writer.write("cb2_debug_blocking.vtk");
gmds::VTKWriter vtk_writer_edges(&ios);
vtk_writer_edges.setCellOptions(gmds::N|gmds::E);
vtk_writer_edges.setDataOptions(gmds::N|gmds::E);
vtk_writer_edges.write("cb2_debug_blocking_edges.vtk");
gmds::VTKWriter vtk_writer_faces(&ios);
vtk_writer_faces.setCellOptions(gmds::N|gmds::F);
vtk_writer_faces.setDataOptions(gmds::N|gmds::F);
vtk_writer_faces.write("cb2_debug_blocking_faces.vtk");


}


15 changes: 14 additions & 1 deletion rlBlocking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ set(GMDS_INC
inc/gmds/rlBlocking/BlockingQuality.h
inc/gmds/rlBlocking/LinkerBlockingGeom.h
inc/gmds/rlBlocking/ValidBlocking.h
inc/gmds/rlBlocking/MCTSAlgorithm.h
inc/gmds/rlBlocking/MCTSState.h
inc/gmds/rlBlocking/MCTSTree.h
inc/gmds/rlBlocking/MCTSMove.h
inc/gmds/rlBlocking/MCTSMovePolycube.h
inc/gmds/rlBlocking/MCTSStatePolycube.h
inc/gmds/rlBlocking/MCTSAgent.h
)
set(GMDS_SRC
src/BlockingQuality.cpp
src/LinkerBlockingGeom.cpp
src/ValidBlocking.cpp)
src/ValidBlocking.cpp
src/MCTSTree.cpp
src/MCTSAlgorithm.cpp
src/MCTSMovePolycube.cpp
src/MCTSStatePolycube.cpp
src/MCTSAgent.cpp
)
#==============================================================================
add_library(${GMDS_LIB} ${GMDS_INC} ${GMDS_SRC})
#==============================================================================
Expand Down
26 changes: 26 additions & 0 deletions rlBlocking/inc/gmds/rlBlocking/MCTSAgent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef GMDS_MCTSAGENT_H
#define GMDS_MCTSAGENT_H

#include <gmds/rlBlocking/MCTSTree.h>
#include <iostream>
#include <random>
/*----------------------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------------------*/
class LIB_GMDS_RLBLOCKING_API MCTSAgent
{
// example of an agent based on the MCTS_tree. One can also use the tree directly.
MCTSTree *tree;
int max_iter, max_seconds, max_same_quality;

public:
MCTSAgent(MCTSState *starting_state, int max_iter = 100000, int max_seconds = 30, int max_same_quality=3);
~MCTSAgent();
const MCTSMove *genmove();
const MCTSState *get_current_state() const;
void feedback() const {tree->print_stats();}
};
}
/*----------------------------------------------------------------------------------------*/
#endif // GMDS_MCTSAGENT_H
/*----------------------------------------------------------------------------------------*/
47 changes: 47 additions & 0 deletions rlBlocking/inc/gmds/rlBlocking/MCTSAlgorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------------------*/
#ifndef GMDS_MCTSALGORITHM_H
#define GMDS_MCTSALGORITHM_H
/*----------------------------------------------------------------------------------------*/
#include "LIB_GMDS_RLBLOCKING_export.h"
#include <gmds/rlBlocking/MCTSTree.h>
#include <gmds/rlBlocking/MCTSAgent.h>
#include <gmds/rlBlocking/MCTSStatePolycube.h>
/*----------------------------------------------------------------------------------------*/
namespace gmds {
/*----------------------------------------------------------------------------------------*/
/** @class MCTSAlgorithm
* @brief Class that provides ....
*/
class LIB_GMDS_RLBLOCKING_API MCTSAlgorithm
{
MCTSTree *tree;
int max_iter, max_seconds,max_same_quality;
public:

/*------------------------------------------------------------------------*/
/** @brief Constructor.
* @param
*/
MCTSAlgorithm(gmds::cad::GeomManager *AGeom,gmds::blocking::CurvedBlocking *ABlocking,int max_iter = 100000, int max_seconds = 30,int max_same_quality = 10);

/*------------------------------------------------------------------------*/
/** @brief Destructor. */
~MCTSAlgorithm();

/*------------------------------------------------------------------------*/
/** @brief Performs the MCTS algorithm
*/
void execute();

private:
/** a geom */
gmds::cad::GeomManager *m_geom;
/** a blocking */
gmds::blocking::CurvedBlocking *m_blocking;

};
/*----------------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------------------*/
#endif // GMDS_MCTSALGORITHM_H
/*----------------------------------------------------------------------------------------*/
Loading
Loading