33 return IT::Record(
"OutputMesh",
"Parameters of the refined output mesh. [Not impemented]")
35 "Maximal level of refinement of the output mesh.")
37 "Set true for using ``error_control_field``. Set false for global uniform refinement to max_level.")
39 "Name of an output field, according to which the output mesh will be refined. The field must be a SCALAR one.")
41 "Tolerance for element refinement by error. If tolerance is reached, refinement is stopped." 42 "Relative difference between error control field and its linear approximation on element is computed" 43 "and compared with tolerance.")
102 return nodes_->n_values();
107 unsigned int elm_idx[1];
108 unsigned int node_idx[1];
109 unsigned int region_idx[1];
111 elem_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"elements_ids", (
unsigned int)1, 1, this->
n_elements());
112 node_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"node_ids", (
unsigned int)1, 1, this->
n_nodes());
113 region_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"region_ids", (
unsigned int)1, 1, this->
n_elements());
114 partitions_ = std::make_shared< ElementDataCache<int> >(
"partitions", (
unsigned int)1, 1, this->
n_elements());
116 for (
unsigned int i = 0; i < this->
n_elements(); ++i, ++it) {
118 else elm_idx[0] = it->idx();
122 region_ids_->store_value( i, region_idx );
125 partitions_->store_value( i, partition );
128 for (
unsigned int j = 0; j < it->n_nodes(); ++j) {
130 else node_idx[0] = node_list[j];
131 node_ids_->store_value( node_list[j], node_idx );
166 DebugOut() <<
"Create outputmesh identical to computational one.";
172 unsigned int coord_id = 0,
174 auto &node_vec = *(
nodes_->get_component_data(0).get() );
179 node_vec[coord_id] = node->getX(); coord_id++;
180 node_vec[coord_id] = node->getY(); coord_id++;
181 node_vec[coord_id] = node->getZ(); coord_id++;
188 unsigned int ele_id = 0,
192 auto &offset_vec = *( offsets_->get_component_data(0).get() );
195 offset += ele->dim() + 1;
196 offset_vec[ele_id] = offset;
197 (*orig_element_indices_)[ele_id] = ele_id;
201 const unsigned int n_connectivities = offset_vec[offset_vec.size()-1];
203 1, n_connectivities);
204 auto &connect_vec = *(
connectivity_->get_component_data(0).get() );
206 for (li=0; li<ele->n_nodes(); li++) {
207 connect_vec[connect_id] = ele.node_accessor(li)->aux;
216 ASSERT(0).error(
"Not implemented yet.");
222 ASSERT(0).error(
"Not implemented yet.");
229 ASSERT(0).error(
"Not implemented yet.");
260 DebugOut() <<
"Create discontinuous outputmesh.";
267 unsigned int ele_id = 0,
273 auto &offset_vec = *( offsets_->get_component_data(0).get() );
276 offset += ele->dim() + 1;
277 offset_vec[ele_id] = offset;
278 (*orig_element_indices_)[ele_id] = ele_id;
283 const unsigned int n_corners = offset_vec[offset_vec.size()-1];
289 auto &node_vec = *(
nodes_->get_component_data(0).get() );
290 auto &conn_vec = *(
connectivity_->get_component_data(0).get() );
293 for (li=0; li<ele->n_nodes(); li++)
295 node = ele.node_accessor(li);
296 node_vec[coord_id] = node->
getX(); ++coord_id;
297 node_vec[coord_id] = node->
getY(); ++coord_id;
298 node_vec[coord_id] = node->
getZ(); ++coord_id;
300 conn_vec[corner_id] = corner_id;
311 DebugOut() <<
"Create refined discontinuous outputmesh.\n";
319 unsigned int last_offset = 0;
321 auto &node_vec = *(
nodes_->get_component_data(0).get() );
322 auto &conn_vec = *(
connectivity_->get_component_data(0).get() );
323 auto &offset_vec = *(
offsets_->get_component_data(0).get() );
337 aux_ele.
nodes.resize(ele->n_nodes());
341 for (li=0; li<ele->n_nodes(); li++) {
342 aux_ele.
nodes[li] = ele.node_accessor(li)->point();
348 case 1: this->refine_aux_element<1>(aux_ele, refinement, ele);
break;
349 case 2: this->refine_aux_element<2>(aux_ele, refinement, ele);
break;
350 case 3: this->refine_aux_element<3>(aux_ele, refinement, ele);
break;
351 default:
ASSERT(0 < dim && dim < 4);
356 unsigned int node_offset = node_vec.size(),
357 con_offset = conn_vec.size();
358 node_vec.resize(node_vec.size() + (refinement.size() * (dim+1))*
spacedim);
359 conn_vec.resize(conn_vec.size() + refinement.size()*(dim+1));
364 for(
unsigned int i=0; i < refinement.size(); i++)
366 last_offset += dim+1;
367 offset_vec.push_back(last_offset);
368 (*orig_element_indices_).push_back(ele_idx);
369 for(
unsigned int j=0; j < dim+1; j++)
371 unsigned int con = i*(dim+1) + j;
372 conn_vec[con_offset + con] = con_offset + con;
374 for(
unsigned int k=0; k <
spacedim; k++) {
375 node_vec[node_offset + con*spacedim + k] = refinement[i].nodes[j][k];
381 conn_vec.shrink_to_fit();
382 node_vec.shrink_to_fit();
383 offset_vec.shrink_to_fit();
387 offsets_->set_n_values(offset_vec.size());
412 static const unsigned int n_subelements = 1 << dim;
492 refinement.push_back(aux_element);
504 nodes.reserve(n_old_nodes+n_new_nodes);
507 for(
unsigned int e=0; e < n_new_nodes; e++)
511 nodes.push_back( p / 2.0);
515 unsigned int diagonal = 0;
518 double min_diagonal = arma::norm(nodes[4]-nodes[9],2);
519 double d = arma::norm(nodes[5]-nodes[8],2);
520 if(d < min_diagonal){
524 d = arma::norm(nodes[6]-nodes[7],2);
525 if(d < min_diagonal){
531 for(
unsigned int i=0; i < n_subelements; i++)
534 sub_ele.
nodes.resize(n_old_nodes);
538 for(
unsigned int j=0; j < n_old_nodes; j++)
540 unsigned int conn_id = (n_old_nodes)*i + j;
541 sub_ele.
nodes[j] = nodes[conn[dim+diagonal][conn_id]];
543 refine_aux_element<dim>(sub_ele, refinement, ele_acc);
551 DebugOut() <<
"Create output submesh containing only local elements.";
556 const unsigned int n_local_elements = el_ds->
lsize();
561 unsigned int ele_id = 0,
566 auto &offset_vec = *( offsets_->get_component_data(0).get() );
567 for (
unsigned int loc_el = 0; loc_el < n_local_elements; loc_el++) {
570 offset += ele->
dim() + 1;
571 offset_vec[ele_id] = offset;
572 (*orig_element_indices_)[ele_id] = el_4_loc[loc_el];
577 const unsigned int n_corners = offset_vec[offset_vec.size()-1];
583 auto &node_vec = *(
nodes_->get_component_data(0).get() );
584 auto &conn_vec = *(
connectivity_->get_component_data(0).get() );
586 for (
unsigned int loc_el = 0; loc_el < n_local_elements; loc_el++) {
588 for (li=0; li<ele->
n_nodes(); li++)
591 node_vec[coord_id] = node->
getX(); ++coord_id;
592 node_vec[coord_id] = node->
getY(); ++coord_id;
593 node_vec[coord_id] = node->
getZ(); ++coord_id;
595 conn_vec[corner_id] = corner_id;
620 for(
auto& v : aux_ele.
nodes ) centre += v;
621 centre = centre/aux_ele.
nodes.size();
643 point_list.push_back(centre);
644 point_list.insert(point_list.end(), ele.
nodes.begin(), ele.
nodes.end());
651 double average_val = 0.0;
652 for(
unsigned int i=1; i<ele.
nodes.size()+1; ++i)
653 average_val += val_list[i];
654 average_val = average_val / ele.
nodes.size();
656 double diff = std::abs((average_val - val_list[0])/val_list[0]);
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Classes for auxiliary output mesh.
void create_refined_mesh() override
Creates refined mesh.
static const unsigned int spacedim
Shortcut instead of spacedim template. We suppose only spacedim=3 at the moment.
unsigned int n_nodes() const
Iter< OutputElement > OutputElementIterator
Base class for Output mesh.
NodeAccessor< 3 > node_accessor(unsigned int ni) const
std::function< void(const std::vector< Space< spacedim >::Point > &, const ElementAccessor< spacedim > &, std::vector< double > &)> ErrorControlFieldFunc
bool refinement_criterion_error(const AuxElement &ele, const Space< spacedim >::Point ¢re, const ElementAccessor< spacedim > &ele_acc)
Refinement flag - measures discretisation error according to error control field. ...
unsigned int n_elements()
Returns number of element.
Mesh * orig_mesh_
Pointer to the computational mesh.
void create_mesh() override
Creates the output mesh identical to the orig mesh.
~OutputMeshDiscontinuous()
void create_mesh() override
Creates the output mesh identical to the orig mesh.
static const Input::Type::Record & get_input_type()
The specification of output mesh.
const unsigned int max_level_
Maximal level of refinement.
double refinement_error_tolerance_
Tolerance for error criterion refinement.
std::shared_ptr< ElementDataCache< unsigned int > > connectivity_
Vector maps the nodes to their coordinates in vector nodes_.
bool refinement_criterion(const AuxElement &ele, const ElementAccessor< spacedim > &ele_acc)
Collects different refinement criteria results.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
virtual unsigned int n_nodes() const
std::shared_ptr< ElementDataCache< unsigned int > > node_ids_
Vector gets ids of nodes. Data is used in GMSH output.
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
unsigned int n_nodes()
Returns number of nodes.
virtual ElementAccessor< 3 > element_accessor(unsigned int idx) const
Create and return ElementAccessor to element of given idx.
std::shared_ptr< ElementDataCache< double > > nodes_
Vector of node coordinates. [spacedim x n_nodes].
int find_elem_id(unsigned int pos) const
Return element id (in GMSH file) of element of given position in element vector.
ErrorControlFieldFunc error_control_field_func_
Refinement error control field function (hold value_list function of field).
arma::vec::fixed< spacedim > Point
static const IdxVector< (InDim >OutDim?InDim+1:dim-InDim) > interact(TInteraction< OutDim, InDim > interaction)
Auxiliary structure defining element of refined output mesh.
void refine_aux_element(const AuxElement &aux_element, std::vector< AuxElement > &refinement, const ElementAccessor< spacedim > &ele_acc)
Performs the actual refinement of AuxElement. Recurrent.
void set_error_control_field(ErrorControlFieldFunc error_control_field_func)
Selects the error control field computing function of output field set according to input record...
std::shared_ptr< ElementDataCache< unsigned int > > region_ids_
Vector gets ids of regions. Data is used in GMSH output.
bool refinement_criterion()
virtual ~OutputMeshBase()
virtual Range< ElementAccessor< 3 > > elements_range() const
Returns range of bulk elements.
void create_sub_mesh() override
Creates sub mesh.
Distribution * get_el_ds() const
OutputMeshDiscontinuous(Mesh &mesh)
Input::Record input_record_
Input record for output mesh.
General iterator template. Provides iterator over objects in some container.
bool refinement_criterion_uniform(const AuxElement &ele)
Refinement flag - checks only maximal level of refinement.
OutputElementIterator end()
Gives iterator to the LAST element of the output mesh.
Support classes for parallel programing.
friend class OutputElement
Friend provides access to vectors for element accessor class.
virtual unsigned int n_elements(bool boundary=false) const
Returns count of boundary or bulk elements.
std::shared_ptr< ElementDataCache< int > > partitions_
Vector gets partitions of elements. Data is used in GMSH output.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
bool refine_by_error_
True, if output mesh is to be refined by error criterion.
Class OutputElement and its iterator OutputElementIterator on the output mesh.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
Range< NodeAccessor< 3 > > node_range() const
Returns range of nodes.
MeshType mesh_type_
Type of OutputMesh.
std::vector< Space< spacedim >::Point > nodes
void create_id_caches()
Create nodes and elements data caches.
bool is_created()
Check if nodes_, connectivity_ and offsets_ data caches are created.
std::shared_ptr< ElementDataCache< unsigned int > > elem_ids_
Vector gets ids of elements. Data is used in GMSH output.
#define DebugOut()
Macro defining 'debug' record of log.
#define ASSERT_PTR_DBG(ptr)
Definition of assert macro checking non-null pointer (PTR) only for debug mode.
void create_refined_mesh() override
Creates discontinuous refined mesh.
LongIdx * get_el_4_loc() const
same as original (computational) mesh
Implementation of range helper class.
std::shared_ptr< std::vector< unsigned int > > orig_element_indices_
Vector of element indices in the computational mesh. (Important when refining.)
OutputElementIterator begin()
Gives iterator to the FIRST element of the output mesh.
void create_sub_mesh() override
Creates sub mesh.
int find_node_id(unsigned int pos) const
Return node id (in GMSH file) of node of given position in node vector.
OutputMeshBase(Mesh &mesh)
Constructor. Takes computational mesh as a parameter.
unsigned int lsize(int proc) const
get local size