Skip to content

Commit

Permalink
Finalize implementation of edge properties
Browse files Browse the repository at this point in the history
  • Loading branch information
FloSewn committed Jun 21, 2024
1 parent 6183348 commit 475ee14
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 38 deletions.
5 changes: 4 additions & 1 deletion src/algorithm/Boundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ class Boundary : public EdgeList
ASSERT( (color >= 0),
"Boundary colors must be greater than zero");

Edge& new_edge = EdgeList::insert_edge(pos, v1, v2, color);
Edge& new_edge = EdgeList::insert_edge(pos, v1, v2,
color);

new_edge.add_property( EdgeProperty::on_boundary);

return new_edge;
}
Expand Down
38 changes: 19 additions & 19 deletions src/algorithm/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ class EdgeList;

/*********************************************************************
* Different properties for mesh edges
* Edges can be classified as:
* - Being located on the domain boundary ("on_boundary")
* If they are not located on the boundary, they are classified as
* internal edges (which is also the default condition)
* - Being "ghost"-edges ("is_ghost") - these are special internal
* edges, that are required for the placement of interior edges
* by the user
*********************************************************************/
enum class EdgeProperty : uint8_t {
no_property = 0b00000000,
on_front = 0b00000001,
on_boundary = 0b00000010,
is_interior = 0b00000100,
is_ghost = 0b00001000,
on_boundary = 0b00000001,
is_ghost = 0b00000010,
};

// Overloaded bitwise NOT operator
Expand All @@ -59,11 +64,16 @@ operator&=(EdgeProperty& lhs, EdgeProperty rhs)
return lhs;
}

// Overloaded bitwise AND operator for checking vertex properties
// Overloaded bitwise AND operator for checking edge properties
static inline bool
operator&(EdgeProperty lhs, EdgeProperty rhs)
{ return (static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs)) != 0; }

// Overloaded bitwise OR operator for checking edge properties
static inline bool
operator|(EdgeProperty lhs, EdgeProperty rhs)
{ return (static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs)) != 0; }


/*********************************************************************
* A simple edge class that is stored in the Container
Expand All @@ -84,12 +94,12 @@ class Edge : public ContainerEntry<Edge>
/*------------------------------------------------------------------
| Constructor
------------------------------------------------------------------*/
Edge(Vertex& v1, Vertex& v2, EdgeList& edgelist, int m)
Edge(Vertex& v1, Vertex& v2, EdgeList& edgelist, int color)
: ContainerEntry<Edge>( 0.5 * ( v1.xy()+v2.xy() ) )
, v1_ {&v1}
, v2_ {&v2}
, edgelist_ {&edgelist}
, color_ {m}
, color_ {color}
{
ASSERT((v1_ && v2_),
"Failed to create edge structure due to given nullptr." );
Expand Down Expand Up @@ -148,20 +158,10 @@ class Edge : public ContainerEntry<Edge>
bool has_no_property() const
{ return (properties_ == EdgeProperty::no_property); }

bool on_front() const { return has_property(EdgeProperty::on_front); }
//bool on_boundary() const { return has_property(EdgeProperty::on_boundary); }
//bool is_interior() const { return has_property(EdgeProperty::is_interior); }
bool on_boundary() const { return has_property(EdgeProperty::on_boundary); }
bool is_interior() const { return !on_boundary(); }
bool is_ghost() const { return has_property(EdgeProperty::is_ghost); }

/*------------------------------------------------------------------
| Function returns, if edges is located on a boundary
| or if it is in the interior of the domain
------------------------------------------------------------------*/
bool on_boundary() const
{ return ( color_ != INTERIOR_EDGE_COLOR ); }
bool is_interior() const
{ return !on_boundary(); }

/*------------------------------------------------------------------
| Get the next edge, that is connected to the ending vertex of
| this edge. The next edge must also have the same color
Expand Down
2 changes: 2 additions & 0 deletions src/algorithm/EdgeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class EdgeList
Edge& e1_new = this->insert_edge(edge.pos(), v1, v_new, color);
Edge& e2_new = this->insert_edge(edge.pos(), v_new, v2, color);

e1_new.set_property( edge.properties() );
e2_new.set_property( edge.properties() );

// Remove old edge
this->remove(edge);
Expand Down
3 changes: 3 additions & 0 deletions src/algorithm/EntityChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class EntityChecks
ASSERT( v2.has_property( VertexProperty::on_boundary ),
"EntityChecks::check_mesh_validity(): Missing "
"vertex property \"on_boundary\".");
ASSERT( e_ptr->has_property( EdgeProperty::on_boundary ),
"EntityChecks::check_mesh_validity(): Missing "
"edge property \"on_boundary\".");

bool check_1 = false; bool check_2 = false;

Expand Down
13 changes: 10 additions & 3 deletions src/algorithm/Front.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class Front : public EdgeList
Vertex& v2 = e_ptr->v2();
v1.add_property(VertexProperty::on_front);
v2.add_property(VertexProperty::on_front);
this->add_edge( v1, v2, e_ptr->color() );

Edge& e_new = this->add_edge( v1, v2, e_ptr->color() );
e_new.set_property( e_ptr->properties() );
}

} // Front::init_front()
Expand Down Expand Up @@ -498,6 +500,7 @@ class Front : public EdgeList
Vertex* v2 = new_vertices[i2];

Edge& e_new = this->add_edge( *v1, *v2, colors[i_edge] );
e_new.add_property( EdgeProperty::on_boundary );

new_edges.push_back(&e_new);
}
Expand Down Expand Up @@ -702,12 +705,16 @@ class Front : public EdgeList
v_n.add_property( VertexProperty::on_front );
v_n.add_property( VertexProperty::on_boundary );

this->insert_edge(e.pos(), *v_cur, v_n, e.color());
// Add new edge and set its properties
Edge& e_new = this->insert_edge(e.pos(), *v_cur, v_n, e.color());
e_new.add_property( EdgeProperty::on_boundary );

v_cur = &v_n;
}

this->insert_edge( e.pos(), *v_cur, e.v2(), e.color() );
// Add final edge and set its properties
Edge& e_new = this->insert_edge( e.pos(), *v_cur, e.v2(), e.color() );
e_new.add_property( EdgeProperty::on_boundary );

} // create_sub_edges()

Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/FrontUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class FrontUpdate
// -> Vertex now part of the advancing front
else
{
front_.add_edge(base.v1(), v_new);
front_.add_edge(v_new, base.v2());
front_.add_edge( base.v1(), v_new );
front_.add_edge( v_new, base.v2() );
}

update_front_state(base.v1());
Expand Down
11 changes: 9 additions & 2 deletions src/algorithm/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,20 @@ class Mesh
| Add new interior mesh edge
------------------------------------------------------------------*/
Edge& add_interior_edge(Vertex& v1, Vertex& v2)
{ return intr_edges_.add_edge(v1, v2, INTERIOR_EDGE_COLOR); }
{
Edge& new_edge = intr_edges_.add_edge(v1, v2, INTERIOR_EDGE_COLOR);
return new_edge;
}

/*------------------------------------------------------------------
| Add new boundary mesh edge
------------------------------------------------------------------*/
Edge& add_boundary_edge(Vertex& v1, Vertex& v2, int color)
{ return bdry_edges_.add_edge(v1, v2, color); }
{
Edge& new_edge = bdry_edges_.add_edge(v1, v2, color);
new_edge.add_property(EdgeProperty::on_boundary);
return new_edge;
}

/*------------------------------------------------------------------
| These functions remove mesh entities and makes sure, that the
Expand Down
1 change: 1 addition & 0 deletions src/algorithm/MeshBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class MeshBuilder
Vertex& v2 = e->v2();
int color = e->color();
Edge& e_new = mesh.boundary_edges().add_edge( v1, v2, color );
e_new.set_property( e->properties() );

ASSERT( v1.has_property( VertexProperty::on_boundary ),
"MeshBuilder::prepare_mesh(): Missing "
Expand Down
4 changes: 3 additions & 1 deletion src/algorithm/MeshMerger.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class MeshMerger
ASSERT(v1, "MeshMerger::copy_donor_interior_edges(): Invalid data structure.");
ASSERT(v2, "MeshMerger::copy_donor_interior_edges(): Invalid data structure.");

receiver_->interior_edges().add_edge( *v1, *v2 );
Edge& new_edge = receiver_->interior_edges().add_edge( *v1, *v2 );
new_edge.set_property( e_ptr->properties() );
}
} // copy_donor_interior_edges()

Expand Down Expand Up @@ -254,6 +255,7 @@ class MeshMerger
ASSERT(v2, "MeshBuilder::merge_meshes(): Invalid data structure.");

Edge& e_new = boundary_edges.add_edge(*v1, *v2, e_ptr->color());
e_new.set_property( e_ptr->properties() );

// Add interface to possible other receiver meshes
if ( e_twin )
Expand Down
26 changes: 18 additions & 8 deletions src/algorithm/QuadLayering.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,16 @@ class QuadLayerVertices
e_bdry_rem = tmp;

Edge* e1 = new_edges.first;
Edge& e1_new = mesh_bdry_edges.insert_edge(e_bdry_rem->pos(),
e1->v1(), e1->v2(),
e1->color());
e1_new.set_property( e1->properties() );

Edge* e2 = new_edges.second;
mesh_bdry_edges.insert_edge(e_bdry_rem->pos(),
e1->v1(), e1->v2(), e1->color());
mesh_bdry_edges.insert_edge(e_bdry_rem->pos(),
e2->v1(), e2->v2(), e2->color());
Edge& e2_new = mesh_bdry_edges.insert_edge(e_bdry_rem->pos(),
e2->v1(), e2->v2(),
e2->color());
e2_new.set_property( e2->properties() );
}

// Add new vertex to quad layer structure
Expand Down Expand Up @@ -442,11 +447,16 @@ class QuadLayerVertices
e_bdry_rem = tmp;

Edge* e1 = new_edges.first;
Edge& e1_new = bdry_edges.insert_edge(e_bdry_rem->pos(),
e1->v1(), e1->v2(),
e1->color());
e1_new.set_property( e1->properties() );

Edge* e2 = new_edges.second;
bdry_edges.insert_edge( e_bdry_rem->pos(),
e1->v1(), e1->v2(), e1->color() );
bdry_edges.insert_edge( e_bdry_rem->pos(),
e2->v1(), e2->v2(), e2->color() );
Edge& e2_new = bdry_edges.insert_edge(e_bdry_rem->pos(),
e2->v1(), e2->v2(),
e2->color());
e2_new.set_property( e2->properties() );
}

// Add new vertex to quad layer structure
Expand Down
6 changes: 4 additions & 2 deletions src/algorithm/RefinementStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ class QuadRefinement : public RefinementStrategy
for ( auto e : coarse_bdry_edges_ )
{
Vertex& v = mesh_->add_vertex( e->xy() );
mesh_->boundary_edges().add_edge( e->v1(), v, e->color() );
mesh_->boundary_edges().add_edge( v, e->v2(), e->color() );
mesh_->boundary_edges().add_edge( e->v1(), v, e->color() )
.add_property( EdgeProperty::on_boundary );
mesh_->boundary_edges().add_edge( v, e->v2(), e->color() )
.add_property( EdgeProperty::on_boundary );
e->sub_vertex( &v );

v.add_property( e->v1().properties() );
Expand Down
1 change: 1 addition & 0 deletions src/algorithm/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace TQMesh {
* CONSTANTS
*********************************************************************/
constexpr int INTERIOR_EDGE_COLOR = -1;
constexpr int DEFAULT_EDGE_COLOR = 0;
constexpr int DEFAULT_ELEMENT_COLOR = 0;
constexpr int DEFAULT_MESH_ID = 0;
constexpr double TQ_SMALL = 1.0E-13;
Expand Down

0 comments on commit 475ee14

Please sign in to comment.