Skip to content

Added sliding boundary nodes to VariationalMeshSmoother #4216

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

Open
wants to merge 38 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4a50ef6
Sliding boundary nodes working for 2D and 3D (coplanar edges only for…
pbehne Jun 22, 2025
ecad271
Moved logic to constrain node to plane into dedicated function.
pbehne Jun 22, 2025
eb7459c
Added method to constrain nodes to lines in 3D.
pbehne Jun 22, 2025
d76ad06
documentation
pbehne Jun 23, 2025
1262cf6
Added logic where only nodes that share the same bid with neighbors a…
pbehne Jun 28, 2025
405e516
Added equilateral triangle as the target element for TRI3s.
pbehne Jun 28, 2025
11331fb
Cleaned up constrints, added relative_fuzzy_equals to multiple subdom…
pbehne Jun 29, 2025
a9f92bb
Nodes on internal subdomain boundaries are now allowed to slide.
pbehne Jun 30, 2025
3e11730
Fixed bug in constraints where the correct common element and matched…
pbehne Jun 30, 2025
ed5b413
Eliminated a level of indentation.
pbehne Jul 2, 2025
0ea66cb
Moved subdomain constraints ahead of boundary constraints. Result loo…
pbehne Jul 2, 2025
1c3b0bf
Saving current changes that almost fix constraint issues, but not quite.
pbehne Jul 8, 2025
c6e42e7
Refactored variational smoother constraints.
pbehne Jul 15, 2025
4c07077
Fixed bug causing 'node already constrained' error.
pbehne Jul 16, 2025
702e58d
Generalized DistortSquare, now distort sliding boundary nodes.
pbehne Jul 17, 2025
15cf24a
Increased the complexity of the subdomain boundary test.
pbehne Jul 17, 2025
c6e37e4
Added fallback to fixed node constraint in event that constrints do n…
pbehne Jul 17, 2025
6c5303c
Updated identification of subdomain boundary node neighbors.
pbehne Jul 17, 2025
86eee47
Added 1D and 3D tests for the VariationalMeshSmoother.
pbehne Jul 17, 2025
c9973d1
Include variant.
pbehne Jul 17, 2025
db4b69d
Removed some assertions that don't apply in 1D.
pbehne Jul 17, 2025
92200b5
Addressed maybe-uninitialized error.
pbehne Jul 17, 2025
7aeaa2b
Separated testSmoother function into testVariationalSmoother and test…
pbehne Jul 17, 2025
d4e397b
Swaped doxygen syntax from '///' to '/***/'
pbehne Jul 18, 2025
b32de64
Added documentation for Point/Line/PlaneConstraint operators < and ==.
pbehne Jul 18, 2025
3533633
Document the throwing of error in *Constraint structs.
pbehne Jul 18, 2025
899e743
Made *Constraint struct operator< symmetric and compatible with opera…
pbehne Jul 18, 2025
0720610
Changed try/catch to libmesh_try/libmesh_catch.
pbehne Jul 18, 2025
4153e1e
Changed Point/Line/PlaneConstraint structs to classes, made attribute…
pbehne Jul 18, 2025
cf08059
Added _tol attibute to Point/Line/Plane constraints.
pbehne Jul 18, 2025
e6a353f
Silenced variational smoother solver.
pbehne Jul 23, 2025
bca5f98
Added dummy InvalidConstraint class to eliminate dependent on thrown …
pbehne Jul 23, 2025
73e927c
Added explanatory comment.
pbehne Jul 23, 2025
57c7c4e
clang-format on variational_smoother_constraint.C
pbehne Jul 23, 2025
e2d026a
clang-format on mesh_smoother_test.C
pbehne Jul 23, 2025
ea104ce
Addressed John's review.
pbehne Jul 24, 2025
505bb55
indented contents of switch statement.
pbehne Jul 24, 2025
f8c37d4
reindeneted some unindents.
pbehne Jul 24, 2025
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
Prev Previous commit
Next Next commit
Swaped doxygen syntax from '///' to '/***/'
  • Loading branch information
pbehne committed Jul 18, 2025
commit d4e397b4f3ae18953d8c0f5dbd8ccf579117736b
243 changes: 144 additions & 99 deletions include/systems/variational_smoother_constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,124 +32,159 @@ struct PointConstraint;
struct LineConstraint;
struct PlaneConstraint;

/// Type used to store a constraint that may be a PlaneConstraint,
/// LineConstraint, or PointConstraint
/**
* Type used to store a constraint that may be a PlaneConstraint,
* LineConstraint, or PointConstraint
*/
using ConstraintVariant =
std::variant<PointConstraint, LineConstraint, PlaneConstraint>;

/// Represents a fixed point constraint.
/**
* Represents a fixed point constraint.
*/
struct PointConstraint {
Point location;

PointConstraint() = default;

/// Constructor
/// @parm p The point defining the constraint.
/**
* Constructor
* @param p The point defining the constraint.
*/
PointConstraint(const Point &p);

bool operator<(const PointConstraint &other) const;

bool operator==(const PointConstraint &other) const;

/// Computes the intersection of this point with another constraint.
/// Handles intersection with PointConstraint, LineConstraint, or
/// PlaneConstraint.
/// @param other The constraint to intersect with.
/// @return The most specific ConstraintVariant that satisfies both
/// constraints.
/**
* Computes the intersection of this point with another constraint.
* Handles intersection with PointConstraint, LineConstraint, or
* PlaneConstraint.
* @param other The constraint to intersect with.
* @return The most specific ConstraintVariant that satisfies both
* constraints.
*/
ConstraintVariant intersect(const ConstraintVariant &other) const;
};

/// Represents a line constraint defined by a base point and direction vector.
/**
* Represents a line constraint defined by a base point and direction vector.
*/
struct LineConstraint {
Point r0;
Point dir;

LineConstraint() = default;

/// Constructor
/// @parm p A point on the constraining line.
/// @param d the direction of the constraining line.
/**
* Constructor
* @param p A point on the constraining line.
* @param d the direction of the constraining line.
*/
LineConstraint(const Point &p, const Point &d);

bool operator<(const LineConstraint &other) const;

bool operator==(const LineConstraint &other) const;

/// Query whether a point lies on the line.
/// @param p The point in question
/// @return bool indicating whether p lies on the line.
/**
* Query whether a point lies on the line.
* @param p The point in question
* @return bool indicating whether p lies on the line.
*/
bool contains_point(const PointConstraint &p) const;

/// Query whether a line is parallel to this line
/// @ param l The line in question
/// @ return bool indicating whether l is parallel to this line.
/**
* Query whether a line is parallel to this line
* @param l The line in question
* @return bool indicating whether l is parallel to this line.
*/
bool is_parallel(const LineConstraint &l) const;

/// Query whether a plane is parallel to this line
/// @ param p The plane in question
/// @ return bool indicating whether p is parallel to this line.
/**
* Query whether a plane is parallel to this line
* @param p The plane in question
* @return bool indicating whether p is parallel to this line.
*/
bool is_parallel(const PlaneConstraint &p) const;

/// Computes the intersection of this line with another constraint.
/// Handles intersection with LineConstraint, PlaneConstraint, or
/// PointConstraint.
/// @param other The constraint to intersect with.
/// @return The most specific ConstraintVariant that satisfies both
/// constraints.
/**
* Computes the intersection of this line with another constraint.
* Handles intersection with LineConstraint, PlaneConstraint, or
* PointConstraint.
* @param other The constraint to intersect with.
* @return The most specific ConstraintVariant that satisfies both
* constraints.
*/
ConstraintVariant intersect(const ConstraintVariant &other) const;
};

/// Represents a plane constraint defined by a point and normal vector.
/**
* Represents a plane constraint defined by a point and normal vector.
*/
struct PlaneConstraint {
Point point;
Point normal;

PlaneConstraint() = default;

/// Constructor
/// @parm p A point on the constraining plane.
/// @param n the direction normal to the constraining plane.
/**
* Constructor
* @param p A point on the constraining plane.
* @param n the direction normal to the constraining plane.
*/
PlaneConstraint(const Point &p, const Point &n);

bool operator<(const PlaneConstraint &other) const;

bool operator==(const PlaneConstraint &other) const;

/// Query whether a point lies on the plane.
/// @param p The point in question
/// @return bool indicating whether p lies on the plane.
/**
* Query whether a point lies on the plane.
* @param p The point in question
* @return bool indicating whether p lies on the plane.
*/
bool contains_point(const PointConstraint &p) const;

/// Query whether a line lies on the plane.
/// @param l The line in question
/// @return bool indicating whether l lies on the plane.
/**
* Query whether a line lies on the plane.
* @param l The line in question
* @return bool indicating whether l lies on the plane.
*/
bool contains_line(const LineConstraint &l) const;

/// Query whether a plane is parallel to this plane
/// @ param p The plane in question
/// @ return bool indicating whether p is parallel to this plane.
/**
* Query whether a plane is parallel to this plane
* @param p The plane in question
* @return bool indicating whether p is parallel to this plane.
*/
bool is_parallel(const PlaneConstraint &p) const;

/// Query whether a line is parallel to this plane
/// @ param l The line in question
/// @ return bool indicating whether l is parallel to this plane.
/**
* Query whether a line is parallel to this plane
* @param l The line in question
* @return bool indicating whether l is parallel to this plane.
*/
bool is_parallel(const LineConstraint &l) const;

/// Computes the intersection of this plane with another constraint.
/// Handles intersection with PlaneConstraint, LineConstraint, or
/// PointConstraint.
/// @param other The constraint to intersect with.
/// @return The most specific ConstraintVariant that satisfies both
/// constraints.
/**
* Computes the intersection of this plane with another constraint.
* Handles intersection with PlaneConstraint, LineConstraint, or
* PointConstraint.
* @param other The constraint to intersect with.
* @return The most specific ConstraintVariant that satisfies both
* constraints.
*/
ConstraintVariant intersect(const ConstraintVariant &other) const;
};

/// Dispatch intersection between two constraint variants.
/// Resolves to the appropriate method based on the type of the first operand.
/// @param a First constraint.
/// @param b Constraint to combine with a.
/// @return Combination (intersection) of constraint a and b.
/**
* Dispatch intersection between two constraint variants.
* Resolves to the appropriate method based on the type of the first operand.
* @param a First constraint.
* @param b Constraint to combine with a.
* @return Combination (intersection) of constraint a and b.
*/
inline ConstraintVariant intersect_constraints(const ConstraintVariant &a,
const ConstraintVariant &b) {
return std::visit(
Expand All @@ -159,29 +194,31 @@ inline ConstraintVariant intersect_constraints(const ConstraintVariant &a,
a, b);
}

/*
/**
* Constraint class for the VariationalMeshSmoother.
*
* Currently, all mesh boundary nodes are constrained to not move during smoothing.
* If requested (preserve_subdomain_boundaries = true), nodes on subdomain boundaries
* are also constrained to not move.
* Currently, all mesh boundary nodes are constrained to not move during
* smoothing. If requested (preserve_subdomain_boundaries = true), nodes on
* subdomain boundaries are also constrained to not move.
*/
class VariationalSmootherConstraint : public System::Constraint
{
private:

System & _sys;

/// Whether nodes on subdomain boundaries are subject to change via smoothing
/**
* Whether nodes on subdomain boundaries are subject to change via smoothing
*/
const bool _preserve_subdomain_boundaries;

/*
/**
* Constrain (i.e., fix) a node to not move during mesh smoothing.
* @param node Node to fix.
*/
void fix_node(const Node & node);

/*
/**
* Constrain a node to remain in the given plane during mesh smoothing.
* @param node Node to constrain
* @param ref_normal_vec Reference normal vector to the constraining plane.
Expand All @@ -190,7 +227,7 @@ class VariationalSmootherConstraint : public System::Constraint
*/
void constrain_node_to_plane(const Node & node, const Point & ref_normal_vec);

/*
/**
* Constrain a node to remain on the given line during mesh smoothing.
* @param node Node to constrain
* @param line_vec vector parallel to the constraining line.
Expand All @@ -199,7 +236,7 @@ class VariationalSmootherConstraint : public System::Constraint
*/
void constrain_node_to_line(const Node & node, const Point & line_vec);

/*
/**
* Determines whether two neighboring nodes share a common boundary id.
* @param boundary_node The first of the two prospective nodes.
* @param neighbor_node The second of the two prospective nodes.
Expand All @@ -213,60 +250,68 @@ class VariationalSmootherConstraint : public System::Constraint
const Elem & containing_elem,
const BoundaryInfo & boundary_info);

/// Get the relevant nodal neighbors for a subdomain constraint.
/// @param mesh The mesh being smoothed.
/// @param node The node (on the subdomain boundary) being constrained.
/// @param sub_id The subdomain id of the block on one side of the subdomain
/// boundary.
/// @param nodes_to_elem_map A mapping from node id to containing element ids.
/// @return A set of node pointer sets containing nodal neighbors to 'node' on
/// the sub_id1-sub_id2 boundary. The subsets are grouped by element faces
/// that form the subdomain boundary. Note that 'node' itself does not appear
/// in this set.
/**
* Get the relevant nodal neighbors for a subdomain constraint.
* @param mesh The mesh being smoothed.
* @param node The node (on the subdomain boundary) being constrained.
* @param sub_id The subdomain id of the block on one side of the subdomain
* boundary.
* @param nodes_to_elem_map A mapping from node id to containing element ids.
* @return A set of node pointer sets containing nodal neighbors to 'node' on
* the sub_id1-sub_id2 boundary. The subsets are grouped by element faces
* that form the subdomain boundary. Note that 'node' itself does not appear
* in this set.
*/
static std::set<std::set<const Node *>>
get_neighbors_for_subdomain_constraint(
const MeshBase &mesh, const Node &node, const subdomain_id_type sub_id,
const std::unordered_map<dof_id_type, std::vector<const Elem *>>
&nodes_to_elem_map);

/// Get the relevant nodal neighbors for an external boundary constraint.
/// @param mesh The mesh being smoothed.
/// @param node The node (on the external boundary) being constrained.
/// @param boundary_node_ids The set of mesh's external boundary node ids.
/// @param boundary_info The mesh's BoundaryInfo.
/// @param nodes_to_elem_map A mapping from node id to containing element ids.
/// @return A set of node pointer sets containing nodal neighbors to 'node' on
/// the external boundary. The subsets are grouped by element faces that form
/// the external boundary. Note that 'node' itself does not appear in this
/// set.
/**
* Get the relevant nodal neighbors for an external boundary constraint.
* @param mesh The mesh being smoothed.
* @param node The node (on the external boundary) being constrained.
* @param boundary_node_ids The set of mesh's external boundary node ids.
* @param boundary_info The mesh's BoundaryInfo.
* @param nodes_to_elem_map A mapping from node id to containing element ids.
* @return A set of node pointer sets containing nodal neighbors to 'node' on
* the external boundary. The subsets are grouped by element faces that form
* the external boundary. Note that 'node' itself does not appear in this
* set.
*/
static std::set<std::set<const Node *>> get_neighbors_for_boundary_constraint(
const MeshBase &mesh, const Node &node,
const std::unordered_set<dof_id_type> &boundary_node_ids,
const BoundaryInfo &boundary_info,
const std::unordered_map<dof_id_type, std::vector<const Elem *>>
&nodes_to_elem_map);

/// Determines the appropriate constraint (PointConstraint, LineConstraint, or
/// PlaneConstraint) for a node based on its neighbors.
/// @param node The node to constrain.
/// @param dim The mesh dimension.
/// @return The best-fit constraint for the given geometry.
/**
* Determines the appropriate constraint (PointConstraint, LineConstraint, or
* PlaneConstraint) for a node based on its neighbors.
* @param node The node to constrain.
* @param dim The mesh dimension.
* @return The best-fit constraint for the given geometry.
*/
static ConstraintVariant determine_constraint(
const Node &node, const unsigned int dim,
const std::set<std::set<const Node *>> &side_grouped_boundary_neighbors);

/// Applies a given constraint to a node (e.g., fixing it, restricting it to a
/// line or plane).
/// @param node The node to constrain.
/// @param constraint The geometric constraint variant to apply.
/**
* Applies a given constraint to a node (e.g., fixing it, restricting it to a
* line or plane).
* @param node The node to constrain.
* @param constraint The geometric constraint variant to apply.
*/
void impose_constraint(const Node &node, const ConstraintVariant &constraint);

public:

/*
/**
* Constructor
* @param sys System to constrain.
* @param preserve_subdomain_boundaries Whether to constrain nodes on subdomain boundaries to not move.
* @param preserve_subdomain_boundaries Whether to constrain nodes on
* subdomain boundaries to not move.
*/
VariationalSmootherConstraint(System & sys, const bool & preserve_subdomain_boundaries);

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy