32 return IT::Record(
"OutputMesh",
"Parameters of the refined output mesh. [Not impemented]")
34 "Maximal level of refinement of the output mesh.")
36 "Set true for using ``error_control_field``. Set false for global uniform refinement to max_level.")
38 "Name of an output field, according to which the output mesh will be refined. The field must be a SCALAR one.")
40 "Tolerance for element refinement by error. If tolerance is reached, refinement is stopped." 41 "Relative difference between error control field and its linear approximation on element is computed" 42 "and compared with tolerance.")
110 return nodes_->n_values();
115 unsigned int elm_idx[1];
116 unsigned int node_idx[1];
117 unsigned int region_idx[1];
119 elem_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"elements_ids", (
unsigned int)1, this->
n_elements());
120 node_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"node_ids", (
unsigned int)1, this->
n_nodes());
121 region_ids_ = std::make_shared< ElementDataCache<unsigned int> >(
"region_ids", (
unsigned int)1, this->
n_elements());
122 partitions_ = std::make_shared< ElementDataCache<int> >(
"partitions", (
unsigned int)1, this->
n_elements());
124 for (
unsigned int i = 0; i < this->
n_elements(); ++i, ++it) {
126 else elm_idx[0] = it->idx();
130 region_ids_->store_value( i, region_idx );
133 partitions_->store_value( i, partition );
136 for (
unsigned int j = 0; j < it->n_nodes(); ++j) {
138 else node_idx[0] = node_list[j];
139 node_ids_->store_value( node_list[j], node_idx );
155 DebugOut() <<
"Create output submesh containing only local elements.";
157 unsigned int ele_id = 0,
169 const unsigned int n_local_elements =
el_ds_->
lsize();
176 auto &offset_vec = *( offsets_->get_component_data(0).get() );
178 for (
unsigned int loc_el = 0; loc_el < n_local_elements; loc_el++) {
181 offset += elm->
dim() + 1;
182 offset_vec[ele_id] = offset;
183 (*orig_element_indices_)[ele_id] =
el_4_loc_[loc_el];
188 offset_vec[offset_vec.size()-1]);
189 auto &connectivity_vec = *(
connectivity_->get_component_data(0).get() );
190 for (
unsigned int loc_el = 0; loc_el < n_local_elements; loc_el++) {
192 for (
unsigned int li=0; li<elm->
n_nodes(); li++) {
194 connectivity_vec[conn_id++] = local_nodes_map[ elm.
node_accessor(li).idx() ];
200 auto &node_vec = *(
nodes_->get_component_data(0).get() );
202 for(
unsigned int i_node=0; i_node<local_nodes_map.size(); ++i_node) {
205 coord_id = 3*local_nodes_map[i_node];
206 node_vec[coord_id++] = node->
getX();
207 node_vec[coord_id++] = node->
getY();
208 node_vec[coord_id] = node->
getZ();
216 std::shared_ptr<ElementDataCache<unsigned int>> global_offsets;
224 master_mesh_->orig_element_indices_ = std::make_shared<std::vector<unsigned int>>(n_elems);
226 auto &offsets_vec = *(
master_mesh_->offsets_->get_component_data(0).get() );
227 auto &elems_n_nodes_vec = *( elems_n_nodes->get_component_data(0).get() );
228 unsigned int offset=0;
229 for (
unsigned int i=0; i<n_elems; ++i) {
230 offset += elems_n_nodes_vec[i];
231 offsets_vec[i] = offset;
243 master_mesh_->connectivity_ = serial_connectivity_cache;
255 auto &local_elems_n_nodes_vec = *( local_elems_n_nodes.get_component_data(0).get() );
256 auto &offset_vec = *(
offsets_->get_component_data(0).get() );
257 for (
unsigned int i=offset_vec.size()-1; i>0; --i) local_elems_n_nodes_vec[i] = offset_vec[i] - offset_vec[i-1];
258 local_elems_n_nodes_vec[0] = offset_vec[0];
261 std::shared_ptr<ElementDataCache<unsigned int>> global_elems_n_nodes;
264 return global_elems_n_nodes;
292 ASSERT(0).error(
"Not implemented yet.");
297 ASSERT(0).error(
"Not implemented yet.");
304 return std::make_shared<OutputMesh>(*orig_mesh_);
310 std::shared_ptr<ElementDataCache<double>> serial_nodes_cache;
316 return serial_nodes_cache;
322 std::shared_ptr<ElementDataCache<unsigned int>> serial_connectivity_cache;
325 auto &conn_vec = *(
connectivity_->get_component_data(0).get() );
327 auto &global_conn_vec = *( global_conn.get_component_data(0).get() );
328 for(
unsigned int i=0; i<conn_vec.size(); i++) {
333 auto &local_offset_vec = *(
offsets_->get_component_data(0).get() );
334 auto global_fix_size_conn = global_conn.element_node_cache_fixed_size(local_offset_vec);
335 auto collective_conn = global_fix_size_conn->gather(
el_ds_,
el_4_loc_);
338 auto &offset_vec = *( global_offsets->get_component_data(0).get() );
339 serial_connectivity_cache = std::dynamic_pointer_cast<
ElementDataCache<unsigned int> >( collective_conn->element_node_cache_optimize_size(offset_vec) );
341 return serial_connectivity_cache;
370 static const unsigned int n_subelements = 1 << dim;
450 refinement.push_back(aux_element);
462 nodes.reserve(n_old_nodes+n_new_nodes);
465 for(
unsigned int e=0; e < n_new_nodes; e++)
469 nodes.push_back( p / 2.0);
473 unsigned int diagonal = 0;
476 double min_diagonal = arma::norm(nodes[4]-nodes[9],2);
477 double d = arma::norm(nodes[5]-nodes[8],2);
478 if(d < min_diagonal){
482 d = arma::norm(nodes[6]-nodes[7],2);
483 if(d < min_diagonal){
489 for(
unsigned int i=0; i < n_subelements; i++)
492 sub_ele.
nodes.resize(n_old_nodes);
496 for(
unsigned int j=0; j < n_old_nodes; j++)
498 unsigned int conn_id = (n_old_nodes)*i + j;
499 sub_ele.
nodes[j] = nodes[conn[dim+diagonal][conn_id]];
501 refine_aux_element<dim>(sub_ele, refinement, ele_acc);
525 for(
auto& v : aux_ele.
nodes ) centre += v;
526 centre = centre/aux_ele.
nodes.size();
548 point_list.push_back(centre);
549 point_list.insert(point_list.end(), ele.
nodes.begin(), ele.
nodes.end());
556 double average_val = 0.0;
557 for(
unsigned int i=1; i<ele.
nodes.size()+1; ++i)
558 average_val += val_list[i];
559 average_val = average_val / ele.
nodes.size();
561 double diff = std::abs((average_val - val_list[0])/val_list[0]);
570 return std::make_shared<OutputMeshDiscontinuous>(*orig_mesh_);
576 std::shared_ptr<ElementDataCache<double>> serial_nodes_cache;
579 std::shared_ptr< ElementDataCache<double> > discont_node_cache = std::make_shared<ElementDataCache<double>>(
"",
581 auto &discont_node_vec = *( discont_node_cache->get_component_data(0).get() );
582 auto &local_nodes_vec = *( this->
nodes_->get_component_data(0).get() );
583 auto &local_conn_vec = *( this->
connectivity_->get_component_data(0).get() );
584 auto &local_offset_vec = *( this->
offsets_->get_component_data(0).get() );
585 unsigned int i_old, i_new;
586 for (
unsigned int i_conn=0; i_conn<this->
connectivity_->n_values(); ++i_conn) {
590 discont_node_vec[i_new+i] = local_nodes_vec[i_old+i];
594 auto fix_size_node_cache = discont_node_cache->element_node_cache_fixed_size(local_offset_vec);
595 auto collect_fix_size_node_cache = fix_size_node_cache->gather(
el_ds_,
el_4_loc_);
598 auto &offset_vec = *( global_offsets->get_component_data(0).get() );
599 serial_nodes_cache = std::dynamic_pointer_cast<
ElementDataCache<double> >(collect_fix_size_node_cache->element_node_cache_optimize_size(offset_vec));
601 return serial_nodes_cache;
607 std::shared_ptr<ElementDataCache<unsigned int>> serial_connectivity_cache;
610 auto &offset_vec = *( global_offsets->get_component_data(0).get() );
612 offset_vec[offset_vec.size()-1]);
613 auto &conn_vec = *( serial_connectivity_cache->get_component_data(0).get() );
614 for (
unsigned int i=0; i<conn_vec.size(); ++i) conn_vec[i] = i;
616 return serial_connectivity_cache;
624 DebugOut() <<
"Create refined discontinuous submesh containing only local elements.";
632 unsigned int last_offset = 0;
634 auto &node_vec = *(
nodes_->get_component_data(0).get() );
635 auto &conn_vec = *(
connectivity_->get_component_data(0).get() );
636 auto &offset_vec = *(
offsets_->get_component_data(0).get() );
645 for (
unsigned int loc_el = 0; loc_el < n_local_elements; loc_el++) {
652 aux_ele.
nodes.resize(ele->n_nodes());
656 for (li=0; li<ele->n_nodes(); li++) {
657 aux_ele.
nodes[li] = ele.node_accessor(li)->point();
663 case 1: this->refine_aux_element<1>(aux_ele, refinement, ele);
break;
664 case 2: this->refine_aux_element<2>(aux_ele, refinement, ele);
break;
665 case 3: this->refine_aux_element<3>(aux_ele, refinement, ele);
break;
666 default:
ASSERT(0 < dim && dim < 4);
671 unsigned int node_offset = node_vec.size(),
672 con_offset = conn_vec.size();
673 node_vec.resize(node_vec.size() + (refinement.size() * (dim+1))*
spacedim);
674 conn_vec.resize(conn_vec.size() + refinement.size()*(dim+1));
679 for(
unsigned int i=0; i < refinement.size(); i++)
681 last_offset += dim+1;
682 offset_vec.push_back(last_offset);
683 (*orig_element_indices_).push_back(ele_idx);
684 for(
unsigned int j=0; j < dim+1; j++)
686 unsigned int con = i*(dim+1) + j;
687 conn_vec[con_offset + con] = con_offset + con;
689 for(
unsigned int k=0; k <
spacedim; k++) {
690 node_vec[node_offset + con*spacedim + k] = refinement[i].nodes[j][k];
696 conn_vec.shrink_to_fit();
697 node_vec.shrink_to_fit();
698 offset_vec.shrink_to_fit();
702 offsets_->set_n_values(offset_vec.size());
710 for (
unsigned int i=0; i<
el_ds_->
lsize(); ++i, ++global_el_idx) {
715 for (
unsigned int i=0; i<node_ds_->
lsize(); ++i, ++global_node_idx) {
729 auto &conn_vec = *( this->
connectivity_->get_component_data(0).get() );
732 auto &master_conn_vec = *(
master_mesh_->connectivity_->get_component_data(0).get() );
733 for (
unsigned int i=0; i<master_conn_vec.size(); ++i) master_conn_vec[i] = i;
736 auto &node_vec = *( this->
nodes_->get_component_data(0).get() );
737 auto &master_node_vec = *(
master_mesh_->nodes_->get_component_data(0).get() );
738 unsigned int i_own, i_master, j;
739 for (
unsigned int i=0; i<conn_vec.size(); ++i) {
743 master_node_vec[i_master+j] = node_vec[i_own+j];
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Classes for auxiliary output 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.
Distribution * el_ds_
Parallel distribution of elements.
std::shared_ptr< ElementDataCache< double > > make_serial_nodes_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets) override
Implements OutputMeshBase::make_serial_nodes_cache.
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.
std::shared_ptr< ElementDataCache< double > > make_serial_nodes_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets) override
Implements OutputMeshBase::make_serial_nodes_cache.
Mesh * orig_mesh_
Pointer to the computational mesh.
LongIdx * get_node_4_loc() const
static const unsigned int undef_idx
NodeAccessor< 3 > node_accessor(unsigned int idx) const
Create and return NodeAccessor to node of given idx.
~OutputMeshDiscontinuous()
std::shared_ptr< ElementDataCache< unsigned int > > make_serial_connectivity_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets) override
Implements OutputMeshBase::make_serial_connectivity_cache.
static const Input::Type::Record & get_input_type()
The specification of output mesh.
const unsigned int max_level_
Maximal level of refinement.
unsigned int n_local_nodes() const
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.
virtual std::shared_ptr< ElementDataCache< double > > make_serial_nodes_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets)=0
Distribution * node_ds_
Parallel distribution of nodes. Depends on elements distribution.
std::shared_ptr< ElementDataCache< unsigned int > > offsets_
Vector of offsets of node indices of elements. Maps elements to their nodes in connectivity_.
std::shared_ptr< ElementDataCache< unsigned int > > make_serial_connectivity_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets) override
Implements OutputMeshBase::make_serial_connectivity_cache.
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.
std::shared_ptr< ElementDataCacheBase > gather(Distribution *distr, LongIdx *local_to_global) override
Implements ElementDataCacheBase::gather.
ErrorControlFieldFunc error_control_field_func_
Refinement error control field function (hold value_list function of field).
arma::vec::fixed< spacedim > Point
std::shared_ptr< OutputMeshBase > construct_mesh() override
Implements OutputMeshBase::construct_mesh.
unsigned int begin(int proc) const
get starting local index
static const IdxVector< (InDim >OutDim?InDim+1:dim-InDim) > interact(TInteraction< OutDim, InDim > interaction)
Auxiliary structure defining element of refined output mesh.
void make_parallel_master_mesh() override
Overrides OutputMeshBase::make_parallel_master_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...
void create_refined_sub_mesh() override
Implements OutputMeshBase::create_refined_sub_mesh.
void make_serial_master_mesh()
Synchronize parallel data and create serial COLECTIVE output mesh on zero process.
std::shared_ptr< ElementDataCache< unsigned int > > region_ids_
Vector gets ids of regions. Data is used in GMSH output.
bool refinement_criterion()
virtual ~OutputMeshBase()
unsigned int np() const
get num of processors
Distribution * get_el_ds() const
LongIdx * node_4_loc_
Index set assigning to local node index its global index.
OutputMeshDiscontinuous(Mesh &mesh)
Input::Record input_record_
Input record for output mesh.
virtual std::shared_ptr< OutputMeshBase > construct_mesh()=0
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.
unsigned int myp() const
get my processor
unsigned int end(int proc) const
get last local index +1
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.
std::shared_ptr< OutputMeshBase > master_mesh_
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
void create_refined_sub_mesh() override
Implements OutputMeshBase::create_refined_sub_mesh.
virtual std::shared_ptr< ElementDataCache< unsigned int > > make_serial_connectivity_cache(std::shared_ptr< ElementDataCache< unsigned int >> global_offsets)=0
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...
MeshType mesh_type_
Type of OutputMesh.
LongIdx * el_4_loc_
Index set assigning to local element index its global index.
std::shared_ptr< ElementDataCache< unsigned int > > get_elems_n_nodes()
Compute and return number of nodes for each elements (compute from offsets)
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.
Distribution * get_node_ds() const
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.
LongIdx * get_el_4_loc() const
General iterator template. Provides iterator over objects of type ObjectIn in some container...
Implementation of range helper class.
unsigned int n_local_nodes_
Hold number of local nodes (own + ghost), value is equal with size of node_4_loc array.
std::shared_ptr< std::vector< unsigned int > > orig_element_indices_
Vector of element indices in the computational mesh. (Important when refining.)
std::shared_ptr< OutputMeshBase > construct_mesh() override
Implements OutputMeshBase::construct_mesh.
OutputElementIterator begin()
Gives iterator to the FIRST element of the output 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