hexed 0.3.0
 
Loading...
Searching...
No Matches
hexed::Accessible_mesh Class Reference

A mesh that supports access to the actual elements with the numerical data they contain. More...

#include <Accessible_mesh.hpp>

Inheritance diagram for hexed::Accessible_mesh:
hexed::Mesh

Classes

class  Masked_mesh
 Creates a mask that allows kernel operations to be performed on a subset of the elements. More...
 

Public Types

typedef Vector_view< Vertex &, Vertex::Non_transferable_ptr, &ptr_convert< Vertex &, Vertex::Non_transferable_ptr > > vertex_view
 convenience typedef for the Vector_view used to access Vertex objects
 

Public Member Functions

 Accessible_mesh (Storage_params params, double root_size)
 
 Accessible_mesh (std::string file_name, std::vector< Flow_bc * > extremal_bcs, Surface_geom *=nullptr, Flow_bc *surface_bc=nullptr)
 Reads mesh from a file created by Mesh::write.
 
 Accessible_mesh (std::string file_name, std::vector< Flow_bc * >, std::vector< Mesh_bc * >)
 Reads mesh from a file created by Mesh::write.
 
double root_size () override
 
Storage_params storage_params ()
 
View_by_type< Element > & cartesian ()
 
View_by_type< Deformed_element > & deformed ()
 
int add_element (int ref_level, bool is_deformed, std::vector< int > position) override
 
Elementelement (int ref_level, bool is_deformed, int serial_n)
 Access an element. If the parameters to not describe an existing element, throw an exception.
 
Sequence< Element & > & elements ()
 access all elements, both Cartesian and deformed
 
Sequence< Kernel_element & > & kernel_elements ()
 
void connect_cartesian (int ref_level, std::array< int, 2 > serial_n, Con_dir< Element > dir, std::array< bool, 2 > is_deformed={false, false}) override
 
void connect_deformed (int ref_level, std::array< int, 2 > serial_n, Con_dir< Deformed_element > direction) override
 Specify that two elements are connected via a deformed face. Requires both elements to be deformed.
 
void connect_hanging (int coarse_ref_level, int coarse_serial, std::vector< int > fine_serial, Con_dir< Deformed_element >, bool coarse_deformed=false, std::vector< bool > fine_deformed={false, false, false, false}, std::array< bool, 2 > stretch={false, false}) override
 
Sequence< Element_connection & > & element_connections ()
 
int add_boundary_condition (Flow_bc *, Mesh_bc *) override
 Acquires owenership of *flow_bc and *mesh_bc and constructs a Boundary_condition from them.
 
void connect_boundary (int ref_level, bool is_deformed, int element_serial_n, int i_dim, int face_sign, int bc_serial_n) override
 Connect a face of an element to a boundary condition.
 
void disconnect_boundary (int bc_sn) override
 delete all boundary connections involving a certain boundary condition
 
void cleanup () override
 Does some work that has to happen after you manually add elements and/or connections.
 
void add_tree (std::vector< Flow_bc * > extremal_bcs, Mat<> origin=Mat<>::Zero(3)) override
 Initializes meshing with bin/quad/octree topology.
 
void set_surface (Surface_geom *geometry, Flow_bc *surface_bc, Eigen::VectorXd flood_fill_start=Eigen::VectorXd::Zero(3)) override
 Defines the surface geometry to be meshed as a boundary.
 
void relax_and_match (int n_relax=0, double factor=.9) override
 
void set_unref_locks (std::function< bool(Element &)> lock_if=criteria::never) override
 
bool update (std::function< bool(Element &)> refine_criterion=criteria::always, std::function< bool(Element &)> unrefine_criterion=criteria::never) override
 Updates tree mesh based on user-supplied (un)refinement criteria.
 
void set_all_smooth () override
 sets need_smooth to true for all vertices to perform global relaxation
 
void relax (double factor=0.9) override
 Relax the vertices to improve mesh quality.
 
int surface_bc_sn () override
 what is the serial number of the geometry surface BC?
 
Surface_geomsurface_geometry ()
 
void reset_masks ()
 Resets effective number of masks created to 0 and invalidates existing masks.
 
std::vector< std::unique_ptr< Masked_mesh > > preti_masks (const Basis &)
 Experimental feature. Ignore for now.
 
Vector_view< Boundary_condition &, Boundary_conditionboundary_conditions ()
 
Boundary_conditionboundary_condition (int bc_sn)
 get a boundary condition owned by this mesh by its serial number
 
Sequence< Boundary_connection & > & boundary_connections ()
 
Sequence< Refined_face & > & refined_faces ()
 
Sequence< Hanging_vertex_matcher & > & hanging_vertex_matchers ()
 
int n_elements () override
 number of elements currently in the mesh
 
Connection_validity valid () override
 Returns a Connection_validity object describing whether the mesh connectivity is valid.
 
vertex_view vertices ()
 
void extrude (bool collapse=false, double offset=0, bool force=false) override
 
void connect_rest (int bc_sn) override
 connects all yet-unconnected faces to a boundary condition specified by serial number
 
std::vector< elem_handleelem_handles () override
 get handles for all elements currently in the mesh, in no particular order (mostly for testing/debugging)
 
Vector_view< Element_connection &, Element_face_connection< Deformed_element > *, ptr_convert< Element_connection &, Element_face_connection< Deformed_element > * > > extruded_connections ()
 
void write (std::string file_name) override
 
void export_polymesh (std::string dir_name) override
 write the mesh in the OpenFOAM PolyMesh format
 
const Stopwatch_treestopwatch_tree () const override
 Obtain performance data.
 
template<>
Mesh_by_type< Element > & mbt ()
 
template<>
Mesh_by_type< Deformed_element > & mbt ()
 
- Public Member Functions inherited from hexed::Mesh
void extrude (Layer_sequence layers)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Public Attributes

double buffer_dist
 how far must the center of an element be from the geometry relative to the nominal size
 

Protected Member Functions

void reset_verts () override
 
void restore_verts () override
 

Detailed Description

A mesh that supports access to the actual elements with the numerical data they contain.

This level of access is required by the numerical scheme but should be hidden from the library user, who should not be concerned with numerical details.

Constructor & Destructor Documentation

◆ Accessible_mesh() [1/3]

hexed::Accessible_mesh::Accessible_mesh ( Storage_params params,
double root_size )
Parameters
paramsparameters specifying what data is stored in each Element (row size, number of dimensions, etc.)
root_sizedefines the root_size of the mesh.

◆ Accessible_mesh() [2/3]

hexed::Accessible_mesh::Accessible_mesh ( std::string file_name,
std::vector< Flow_bc * > extremal_bcs,
Surface_geom * geometry = nullptr,
Flow_bc * surface_bc = nullptr )

Reads mesh from a file created by Mesh::write.

Acquires ownership of boundary condition pointers. This variant is only for tree meshing. The surface boundary condition and geometry arguments must be specified iff the original mesh had a surface geometry (else exception).

◆ Accessible_mesh() [3/3]

hexed::Accessible_mesh::Accessible_mesh ( std::string file_name,
std::vector< Flow_bc * > flow_bcs,
std::vector< Mesh_bc * > mesh_bcs )

Reads mesh from a file created by Mesh::write.

Acquires ownership of boundary condition pointers. This variant is not for tree meshing.

Member Function Documentation

◆ add_boundary_condition()

int hexed::Accessible_mesh::add_boundary_condition ( Flow_bc * flow_bc,
Mesh_bc * mesh_bc )
overridevirtual

Acquires owenership of *flow_bc and *mesh_bc and constructs a Boundary_condition from them.

Returns a serial number which uniquely identifies the new boundary condition among this Mesh's boundary conditions. It is recommended to use this with new, like the constructor for std::unique_ptr.

Implements hexed::Mesh.

◆ add_element()

int hexed::Accessible_mesh::add_element ( int ref_level,
bool is_deformed,
std::vector< int > position )
overridevirtual

Add an element at specified nominal position and serial number which uniquely identifies it among elements of this mesh with the same refinement level and deformedness.

Implements hexed::Mesh.

◆ add_tree()

void hexed::Accessible_mesh::add_tree ( std::vector< Flow_bc * > extremal_bcs,
Mat<> origin = Mat<>::Zero(3) )
overridevirtual

Initializes meshing with bin/quad/octree topology.

Creates a tree initialized with one element with ref level 0. Technically, free-form elements can also be created in the same mesh, but they will not be connected to the tree. Only one tree can be created. Connections and boundary conditions are set automatically for tree elements, so tree meshes should always automatically be valid unless you explicitly invalidate it with Mesh::disconnect_boundary.

Parameters
extremal_bcsBoundary conditions to apply to elements with exposed faces at the extremal boundaries of the tree. Takes ownership of objects that the vector entries point to. It must contain exactly 2*n_dim entries. E.g. extremal_bcs[0] is the boundary condition to apply to the minimum \(x_0\) face, extremal_bcs[1] is the BC for the maximum \(x_0\) face, extremal_bcs[2] is for minimum \(x_1\).
originThe minimal corner of the tree root will be located at origin.

Implements hexed::Mesh.

◆ boundary_conditions()

Vector_view< Boundary_condition &, Boundary_condition > hexed::Accessible_mesh::boundary_conditions ( )
inline
Returns
a view of all Bounday_condition objects owned by this mesh

◆ boundary_connections()

Sequence< Boundary_connection & > & hexed::Accessible_mesh::boundary_connections ( )
inline
Returns
a view of all connections between an element and a boundary condition

◆ cartesian()

View_by_type< Element > & hexed::Accessible_mesh::cartesian ( )
inline
Returns
a View_by_type containing only the Cartesian elements in the mesh

◆ cleanup()

void hexed::Accessible_mesh::cleanup ( )
overridevirtual

Does some work that has to happen after you manually add elements and/or connections.

Implements hexed::Mesh.

◆ connect_boundary()

void hexed::Accessible_mesh::connect_boundary ( int ref_level,
bool is_deformed,
int element_serial_n,
int i_dim,
int face_sign,
int bc_serial_n )
overridevirtual

Connect a face of an element to a boundary condition.

This BC will now be applied to that face. i_dim and face_sign are used to identify which face of the element is participating in the boundary condition.

Implements hexed::Mesh.

◆ connect_cartesian()

void hexed::Accessible_mesh::connect_cartesian ( int ref_level,
std::array< int, 2 > serial_n,
Con_dir< Element > dir,
std::array< bool, 2 > is_deformed = {false, false} )
overridevirtual

Specify that two elements are connected via a Cartesian face. Note: although the interface is stipulated to be Cartesian, the elements themselves can be deformed

Implements hexed::Mesh.

◆ connect_deformed()

void hexed::Accessible_mesh::connect_deformed ( int ref_level,
std::array< int, 2 > serial_n,
Con_dir< Deformed_element > direction )
overridevirtual

Specify that two elements are connected via a deformed face. Requires both elements to be deformed.

Implements hexed::Mesh.

◆ connect_hanging()

void hexed::Accessible_mesh::connect_hanging ( int coarse_ref_level,
int coarse_serial,
std::vector< int > fine_serial,
Con_dir< Deformed_element > ,
bool coarse_deformed = false,
std::vector< bool > fine_deformed = {false, false, false, false},
std::array< bool, 2 > stretch = {false, false} )
overridevirtual

specify that an element of refinement level coarse_ref_level is connected to some elements of refinement level coarse_ref_level + 1. Coarse element comes first in Con_dir. coarse_deformed and fine_deformed specify whether the elements are Cartesian or deformed. If any of the elements are Cartesian, the entire face is assumed to be Cartesian. In this case, all the vertices must occupy their nominal positions and the Con_dir must be appropriate for a Cartesian connection. If these requirements are not satisfied, the invocation is incorrect. The number of fine elements can be any power of 2 (with a maximum of 2^(n_dim - 1)). In order to match the faces when less than the maximum number of elements is used, stretch specifies along which dimensions the fine elements are to be stretched to match the coarse. Only the first n_dim - 1 elements of stretch are meaningful. The rest are ignored.

Implements hexed::Mesh.

◆ connect_rest()

void hexed::Accessible_mesh::connect_rest ( int bc_sn)
overridevirtual

connects all yet-unconnected faces to a boundary condition specified by serial number

Implements hexed::Mesh.

◆ deformed()

View_by_type< Deformed_element > & hexed::Accessible_mesh::deformed ( )
inline
Returns
a View_by_type containing only the deformed elements in the mesh

◆ disconnect_boundary()

void hexed::Accessible_mesh::disconnect_boundary ( int bc_sn)
overridevirtual

delete all boundary connections involving a certain boundary condition

Implements hexed::Mesh.

◆ elem_handles()

std::vector< Mesh::elem_handle > hexed::Accessible_mesh::elem_handles ( )
overridevirtual

get handles for all elements currently in the mesh, in no particular order (mostly for testing/debugging)

Implements hexed::Mesh.

◆ element_connections()

Sequence< Element_connection & > & hexed::Accessible_mesh::element_connections ( )
inline
Returns
a view of all connections between elements, including one connection for every fine element in hanging node connections.

◆ export_polymesh()

void hexed::Accessible_mesh::export_polymesh ( std::string dir_name)
overridevirtual

write the mesh in the OpenFOAM PolyMesh format

Implements hexed::Mesh.

◆ extrude()

void hexed::Accessible_mesh::extrude ( bool collapse = false,
double offset = 0,
bool force = false )
overridevirtual

Extrudes a layer of elements from unconnected faces:

  1. Extrudes one deformed element from every unconnected face of every deformed element.
  2. Connects the new elements to the faces they were generated from.
  3. Connects the new elements to each other to maintain the connectivity of the faces they were generated from.
  4. If the parent elements have any boundary connections, those are also applied to the corresponding faces of the extruded elements. When this is complete, the number of unconnected faces (of deformed elements) remains unchanged, but the unconnected faces now belong to new, extruded elements which can be snapped to surface geometry in a well-conditioned fashion. If collapse == true then the new elements will be collapsed in the extrusion direction, such that they have zero volume and exist purely on the extruded face. If the mesh has already been extruded once and offset is specified, the interior vertices of the extruded element will then be moved some distance toward the interior neighbor depending on the value of offset, where offset == 0 yields no motion and offset == 1 moves them exactly to the neighbor. If the mesh has not been extruded, the vertices shall be moved in an unspecified manner (but maintaining a valid mesh state). Offsetting thus provides a rudimentary way of creating anisotropic wall layers. If force == false (default) then in a tree mesh, only tree elements will be extruded from (which is necessary because some of the extruded elements from the previous refinement sweep may have non-surface-facing exposed faces). If force == true then all exposed faces will be extruded from.
Todo
apparently the mesh needs to know about the basis after all...

Implements hexed::Mesh.

◆ extruded_connections()

Vector_view< Element_connection &, Element_face_connection< Deformed_element > *, ptr_convert< Element_connection &, Element_face_connection< Deformed_element > * > > hexed::Accessible_mesh::extruded_connections ( )
inline
Returns
a view of all Element_connection between extruded elements and the elemens they were extruded from

◆ hanging_vertex_matchers()

Sequence< Hanging_vertex_matcher & > & hexed::Accessible_mesh::hanging_vertex_matchers ( )
inline
Returns
a view of all Hanging_vertex_matcher objects owned by this mesh (there will be one for every hanging node connection)

◆ n_elements()

int hexed::Accessible_mesh::n_elements ( )
inlineoverridevirtual

number of elements currently in the mesh

Implements hexed::Mesh.

◆ preti_masks()

std::vector< std::unique_ptr< Accessible_mesh::Masked_mesh > > hexed::Accessible_mesh::preti_masks ( const Basis & basis)

Experimental feature. Ignore for now.

Has to do with an experimental performance-enhancing feature where anisotropic elements are updated more frequently than isotropic ones. Not ready for production use, although it was the motivation for the Masked_mesh feature.

◆ refined_faces()

Sequence< Refined_face & > & hexed::Accessible_mesh::refined_faces ( )
inline
Returns
a view of all Refined_face objects owned by this mesh (there will be one for every hanging node connection)

◆ relax()

void hexed::Accessible_mesh::relax ( double factor = 0.9)
overridevirtual

Relax the vertices to improve mesh quality.

By default, relaxation is performed incrementally—only vertices of elements that are new in the most recent update() cycle are smoothed. To smooth all, call set_all_smooth().

Parameters
factorA larger number yields more change in the mesh. 0 => no update, 1 => "full" update, > 1 allowed but suspect

Implements hexed::Mesh.

◆ relax_and_match()

void hexed::Accessible_mesh::relax_and_match ( int n_relax = 0,
double factor = .9 )
overridevirtual

Implements hexed::Mesh.

◆ reset_masks()

void hexed::Accessible_mesh::reset_masks ( )

Resets effective number of masks created to 0 and invalidates existing masks.

See also
Masked_mesh

◆ reset_verts()

void hexed::Accessible_mesh::reset_verts ( )
overrideprotectedvirtual

Implements hexed::Mesh.

◆ restore_verts()

void hexed::Accessible_mesh::restore_verts ( )
overrideprotectedvirtual

Implements hexed::Mesh.

◆ root_size()

double hexed::Accessible_mesh::root_size ( )
inlineoverridevirtual
Returns
Nominal size ( \(\Delta h\)) of elements with refinement level 0.

Implements hexed::Mesh.

◆ set_all_smooth()

void hexed::Accessible_mesh::set_all_smooth ( )
overridevirtual

sets need_smooth to true for all vertices to perform global relaxation

(only effective until the next update() cycle)

Implements hexed::Mesh.

◆ set_surface()

void hexed::Accessible_mesh::set_surface ( Surface_geom * geometry,
Flow_bc * surface_bc,
Eigen::VectorXd flood_fill_start = Eigen::VectorXd::Zero(3) )
overridevirtual

Defines the surface geometry to be meshed as a boundary.

Acquires ownership of the objects pointed to geometry and surface_bc. The geometric surface represented by geometry is now a boundary of the domain and its boundary condition is surface_bc. The flood fill algorithm is then executed starting at flood_fill_start to determine which elements are in the domain and extrusion is executed to create a suitably body-fitted mesh. flood_fill_start must have at least n_dim entries and extra entries are ignored. If the mesh is excessively coarse, there may be no elements in the domain as they are all too close to the surfaces. So, Mesh::update should be calling a few times before Mesh::set_surfaces. Any surfaces defined by previous invokations of set_surface are forgotten. sets the Element::unrefinement_locked member of all elements

Implements hexed::Mesh.

◆ set_unref_locks()

void hexed::Accessible_mesh::set_unref_locks ( std::function< bool(Element &)> lock_if = criteria::never)
overridevirtual

Implements hexed::Mesh.

◆ stopwatch_tree()

const Stopwatch_tree & hexed::Accessible_mesh::stopwatch_tree ( ) const
inlineoverridevirtual

Obtain performance data.

Implements hexed::Mesh.

◆ surface_bc_sn()

int hexed::Accessible_mesh::surface_bc_sn ( )
inlineoverridevirtual

what is the serial number of the geometry surface BC?

Implements hexed::Mesh.

◆ update()

bool hexed::Accessible_mesh::update ( std::function< bool(Element &)> refine_criterion = criteria::always,
std::function< bool(Element &)> unrefine_criterion = criteria::never )
overridevirtual

Updates tree mesh based on user-supplied (un)refinement criteria.

Evaluates refine_criterion and unrefine_criterion on every element in the tree (if a tree exists). Whenever refine_criterion is true and unrefine_criterion is false, that element is refined. Whenever unrefine_criterion is true and refine_criterion is false for a complete group of sibling elements, that group is unrefined. Since extruded elements cannot be directly refined or unrefined, their extrusion parents inherit their (un)refinement flags and any unrefinement locks. In order to satisfy some criteria regarding the refinement level of neighbors, some additional elements may be refined and some elements may not be unrefined. Both criteria must be thread-safe and must not depend on the order in which elements are processed. The flood fill and extrusion are also updated.

Returns
true if the mesh was changed, else false

Implements hexed::Mesh.

◆ valid()

Mesh::Connection_validity hexed::Accessible_mesh::valid ( )
overridevirtual

Returns a Connection_validity object describing whether the mesh connectivity is valid.

Suggested uses:

  • if (mesh.valid()) {\\...do something that requires a valid mesh}
  • mesh.valid().assert_valid();

Implements hexed::Mesh.

◆ vertices()

Accessible_mesh::vertex_view hexed::Accessible_mesh::vertices ( )
Returns
a view of all Vertex objects used by elements in this mesh. Each vertex will appear exactly once, even if it is shared by multiple elements.

◆ write()

void hexed::Accessible_mesh::write ( std::string file_name)
overridevirtual

Implements hexed::Mesh.

Member Data Documentation

◆ buffer_dist

double hexed::Accessible_mesh::buffer_dist

how far must the center of an element be from the geometry relative to the nominal size

Defaults to \( \frac{\sqrt{n_d}}{2} \). You can modify it, but it cannot be less than this.


The documentation for this class was generated from the following files: