v0.14.0
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
MoFEM::EssentialPreProc< MPCsType > Struct Reference

Type generating multipoint constraints. More...

#include <src/boundary_conditions/EssentialMPCsData.hpp>

Collaboration diagram for MoFEM::EssentialPreProc< MPCsType >:
[legend]

Public Member Functions

 EssentialPreProc (MoFEM::Interface &m_field, boost::shared_ptr< FEMethod > fe_ptr, bool is_spatial_positions=false)
 
MoFEMErrorCode operator() ()
 
MoFEMErrorCode setMPCParentAdjacency ()
 

Static Public Member Functions

static MoFEMErrorCode loadFileWithMPCs (Interface &m_field, const char *file_name, const char *options)
 
static MoFEMErrorCode addLinksToPostProcMesh (Interface &m_field, moab::Interface &post_proc_mesh_interface, vector< std::string > field_names)
 

Protected Attributes

MoFEM::InterfacemField
 
boost::weak_ptr< FEMethodfePtr
 
bool isSpatialPositions
 

Detailed Description

Type generating multipoint constraints.

Definition at line 47 of file EssentialMPCsData.hpp.

Constructor & Destructor Documentation

◆ EssentialPreProc()

MoFEM::EssentialPreProc< MPCsType >::EssentialPreProc ( MoFEM::Interface m_field,
boost::shared_ptr< FEMethod fe_ptr,
bool  is_spatial_positions = false 
)

Definition at line 22 of file EssentialMPCsData.cpp.

25  : mField(m_field), fePtr(fe_ptr), isSpatialPositions(is_spatial_positions) {
26 }

Member Function Documentation

◆ addLinksToPostProcMesh()

MoFEMErrorCode MoFEM::EssentialPreProc< MPCsType >::addLinksToPostProcMesh ( Interface m_field,
moab::Interface &  post_proc_mesh_interface,
vector< std::string >  field_names 
)
static

Definition at line 227 of file EssentialMPCsData.cpp.

229  {
231 
232  // for each link vertex find entity in mfield database
233  // and add it to post_proc_mesh_interface
234  // for each field give in field_names save data on appropriate tag
235 
236  std::array<double, 9> def;
237  std::fill(def.begin(), def.end(), 0);
238 
239  auto get_tag = [&](const std::string name, size_t size) {
240  Tag th;
241  size = size <= 1 ? 1 : (size <= 3 ? 3 : 9);
242  CHKERR post_proc_mesh_interface.tag_get_handle(
243  name.c_str(), size, MB_TYPE_DOUBLE, th, MB_TAG_CREAT | MB_TAG_SPARSE,
244  def.data());
245  return th;
246  };
247 
248  // get links from meshsets
249  auto master_meshset_ptr =
250  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
251  std::regex((boost::format("%s(.*)") % "MPC_(.*)_LINKS").str()));
252  Range links_ents;
253  for (auto m : master_meshset_ptr) {
254  Range ents;
255  CHKERR m_field.get_moab().get_entities_by_type(m->getMeshset(), MBEDGE,
256  ents, true);
257  links_ents.merge(ents);
258  }
259 
260  if(links_ents.empty()) {
262  }
263 
264  // create edges in post_proc_mesh_interface
265  std::vector<EntityHandle> p_links_edges(links_ents.size()); // post_proc edges
266  std::vector<EntityHandle> o_nodes(links_ents.size() * 2); // original mesh nodes
267  std::vector<EntityHandle> p_nodes(links_ents.size() * 2); // post_proc nodes
268 
269  int dd = 0;
270  for (auto &link : links_ents) {
271  Range verts;
272  CHKERR m_field.get_moab().get_connectivity(&link, 1, verts, true);
273  ublas::vector<EntityHandle> edge_conn(2);
274  int gg = 0;
275  for (auto &vert : verts) {
276  VectorDouble coords(3);
277  // fill o_nodes with vertices
278  CHKERR m_field.get_moab().get_coords(&vert, 1, &coords[0]);
279  CHKERR post_proc_mesh_interface.create_vertex(&coords[0], edge_conn[gg]);
280  o_nodes[dd * 2 + gg] = vert;
281  p_nodes[dd * 2 + gg] = edge_conn[gg];
282  gg++;
283  }
284 
285  CHKERR post_proc_mesh_interface.create_element(MBEDGE, &edge_conn[0], 2,
286  p_links_edges[dd++]);
287  }
288 
289  const FieldEntity_multiIndex *field_ents;
290  CHKERR m_field.get_field_ents(&field_ents);
291  auto &field_ents_by_uid = field_ents->get<Unique_mi_tag>();
292 
293  for (auto field : field_names) {
294  auto field_ptr = m_field.get_field_structure(field);
295  const int nb_coefficients = field_ptr->getNbOfCoeffs();
296  Tag tag = get_tag(field, nb_coefficients);
297 
298  int gg = 0;
299  for (auto &node : o_nodes) {
300  VectorDouble data(nb_coefficients);
301  auto eit = field_ents_by_uid.find(FieldEntity::getLocalUniqueIdCalculate(
302  m_field.get_field_bit_number(field), node));
303  if (eit != field_ents_by_uid.end()) {
304  noalias(data) = (*eit)->getEntFieldData();
305  }
306  auto ent = p_nodes[gg++];
307  post_proc_mesh_interface.tag_set_data(tag, &ent, 1, &*data.begin());
308  }
309  }
310 
312 }

◆ loadFileWithMPCs()

MoFEMErrorCode MoFEM::EssentialPreProc< MPCsType >::loadFileWithMPCs ( Interface m_field,
const char *  file_name,
const char *  options 
)
static

Definition at line 28 of file EssentialMPCsData.cpp.

29  {
31 
32  auto simple = m_field.getInterface<Simple>();
33  auto &moab = m_field.get_moab();
34 
35  // CHKERR moab.load_file(file_name, 0, options);
36  CHKERR simple->loadFile("", file_name);
37 
38  constexpr bool is_debug = false;
39 
40  Range all_ents;
41  CHKERR moab.get_entities_by_handle(0, all_ents, false);
42 
43  if (m_field.get_comm_size() == 1)
45 
46  auto print_range_on_procs = [&](const Range &range, std::string name) {
47  if(!is_debug) return;
48  MOFEM_LOG("SYNC", Sev::inform)
49  << name << " on proc [" << m_field.get_comm_rank() << "] : \n"
50  << range;
51  MOFEM_LOG_SYNCHRONISE(m_field.get_comm());
52  };
53 
54  auto save_range_to_file = [&](const Range range, std::string name = "part") {
55  if(!is_debug) return;
56  int rr = m_field.get_comm_rank();
57  ostringstream ss;
58  ss << "out_" << name << "_" << rr << ".vtk";
59  MOFEM_LOG("SELF", Sev::inform) << "Save debug part mesh " << ss.str();
60  EntityHandle meshset;
61  CHKERR moab.create_meshset(MESHSET_SET, meshset);
62  CHKERR moab.add_entities(meshset, range);
63  if (!range.empty())
64  CHKERR moab.write_file(ss.str().c_str(), "VTK", "", &meshset, 1);
65  CHKERR moab.delete_entities(&meshset, 1);
66  };
67 
68  auto master_meshset_ptr =
69  m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
70  std::regex((boost::format("%s(.*)") % "MPC_(.*)_LINKS").str()));
71  Range mpc_ents, links_ents;
72  for (auto m : master_meshset_ptr) {
73 
74  Range ents;
75  CHKERR moab.get_entities_by_handle(m->getMeshset(), ents, true);
76 
77  links_ents.merge(ents);
78  for (auto &link : links_ents) {
79  Range verts;
80  CHKERR moab.get_connectivity(&link, 1, verts, true);
81  mpc_ents.merge(verts);
82  }
83  }
84 
85  if(mpc_ents.empty()) {
87  }
88 
89  save_range_to_file(all_ents, "all_ents");
90  print_range_on_procs(mpc_ents, "mpc_ents");
91  print_range_on_procs(links_ents, "links_ents");
92 
93  const int dim = simple->getDim();
94 
95  ParallelComm *pcomm =
96  ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
97  if (pcomm == NULL)
98  pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
99 
100  Tag part_tag = pcomm->part_tag();
101  Range tagged_sets, proc_ents, off_proc_ents, all_proc_ents;
102 
103  CHKERR moab.get_entities_by_type_and_tag(0, MBENTITYSET, &part_tag, NULL, 1,
104  tagged_sets, moab::Interface::UNION);
105  print_range_on_procs(tagged_sets, "tagged_sets");
106  for (auto &mit : tagged_sets) {
107  int part;
108  CHKERR moab.tag_get_data(part_tag, &mit, 1, &part);
109 
110  if (part == m_field.get_comm_rank()) {
111  CHKERR moab.get_entities_by_dimension(mit, dim, proc_ents, true);
112  CHKERR moab.get_entities_by_handle(mit, all_proc_ents, true);
113  } else {
114  CHKERR moab.get_entities_by_handle(mit, off_proc_ents, true);
115  }
116  }
117 
118  print_range_on_procs(proc_ents, "proc_ents");
119 
120  save_range_to_file(proc_ents);
121  save_range_to_file(off_proc_ents, "all_proc_ents");
122  all_proc_ents = subtract(all_proc_ents, links_ents);
123 
124  Range all_tets;
125  CHKERR moab.get_entities_by_handle(0, all_tets, true);
126 
127  Range tets_skin;
128  Skinner skin(&moab);
129  CHKERR skin.find_skin(0, all_tets.subset_by_dimension(dim), false, tets_skin);
130 
131 
132  // Find the skin of entities on this processor
133  Range proc_ents_skin[4]; // stores only entities shared with other processors
134  CHKERR skin.find_skin(0, proc_ents, false, proc_ents_skin[dim - 1]);
135 
136 
137  Range skin_verts, verts_to_add, edges_to_add;
138  CHKERR moab.get_connectivity(proc_ents_skin[dim - 1],
139  skin_verts); // FIXME: check for 3D
140  for (auto &link : links_ents) {
141  Range verts;
142  CHKERR moab.get_connectivity(&link, 1, verts);
143  for (auto &vert : verts)
144  if (skin_verts.find(vert) != skin_verts.end()) {
145  edges_to_add.insert(link);
146  verts_to_add.merge(verts);
147  }
148  }
149 
150  // Remove shared entities from the skin
151  proc_ents_skin[dim - 1] = subtract(proc_ents_skin[dim - 1], tets_skin);
152 
153  // Get adjacent entities and their connectivity
154 
155  // FIXME: these are NOT (!) only shared entities (includes outside)
156  if (dim > 2) {
157  CHKERR moab.get_adjacencies(proc_ents_skin[2], 1, false, proc_ents_skin[1],
158  moab::Interface::UNION);
159  }
160  Range adj_ents;
161  CHKERR moab.get_connectivity(proc_ents_skin[1], adj_ents, true);
162  proc_ents_skin[0].merge(adj_ents);
163 
164  proc_ents_skin[1].merge(edges_to_add);
165  proc_ents_skin[0].merge(verts_to_add);
166 
167  print_range_on_procs(edges_to_add, "edges_to_add");
168  print_range_on_procs(verts_to_add, "verts_to_add");
169 
170  // do it as early as possible
171  // it slows down all get_connectivity and get_adjacencies
172 
173  // Remove entities not part of this processor
174  save_range_to_file(proc_ents, "proc_ents");
175  save_range_to_file(off_proc_ents, "off_proc_ents");
176 
177  all_tets = off_proc_ents;
178 
179  if (edges_to_add.empty())
180  all_tets.merge(links_ents);
181 
182  save_range_to_file(proc_ents_skin[0], "proc_ents_skin0");
183  save_range_to_file(proc_ents_skin[1], "proc_ents_skin1");
184 
185  for (int dd = dim; dd >= 0; --dd) {
186  all_tets = subtract(all_tets, proc_ents_skin[dd]);
187  }
188  print_range_on_procs(proc_ents, "proc_ents");
189 
190  Range meshsets;
191  CHKERR moab.get_entities_by_type(0, MBENTITYSET, meshsets, true);
192  for (auto m : meshsets) {
193  CHKERR moab.remove_entities(m, all_tets);
194  }
195 
196  print_range_on_procs(all_tets.subset_by_dimension(2), "all_tets to delete");
197  save_range_to_file(all_tets.subset_by_dimension(2), "part_delete");
198 
199  // vertices do not need to be deleted
200  for (int dd = dim; dd > 0; --dd) {
201  CHKERR moab.delete_entities(all_tets.subset_by_dimension(dd));
202  }
203 
204  // Update parallel status tag
205  {
206  Range all_ents;
207  CHKERR moab.get_entities_by_handle(0, all_ents);
208  std::vector<unsigned char> pstat_tag(all_ents.size(), 0);
209  save_range_to_file(all_ents, "all_ents_part");
210  CHKERR moab.tag_set_data(pcomm->pstatus_tag(), all_ents,
211  &*pstat_tag.begin());
212  }
213 
214  Range all_ents_before;
215  CHKERR moab.get_entities_by_handle(0, all_ents_before);
216  save_range_to_file(all_ents_before, "all_ents_part_before");
217 
218  CHKERR pcomm->resolve_shared_ents(0, proc_ents, dim, -1, proc_ents_skin);
219 
220  Range all_ents_after;
221  CHKERR moab.get_entities_by_handle(0, all_ents_after);
222  save_range_to_file(all_ents_after, "all_ents_part_after");
223 
225 }

◆ operator()()

Definition at line 314 of file EssentialMPCsData.cpp.

314  {
315  MOFEM_LOG_CHANNEL("WORLD");
317 
318  if (isSpatialPositions) {
319  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED, "not implemented");
320  }
321 
322  MOFEM_LOG("BcMngWorld", Sev::warning)
323  << "EssentialPreProc<MPCsType> has no effect here. ";
324 
326 }

◆ setMPCParentAdjacency()

MoFEMErrorCode MoFEM::EssentialPreProc< MPCsType >::setMPCParentAdjacency ( )

Member Data Documentation

◆ fePtr

boost::weak_ptr<FEMethod> MoFEM::EssentialPreProc< MPCsType >::fePtr
protected

Definition at line 71 of file EssentialMPCsData.hpp.

◆ isSpatialPositions

bool MoFEM::EssentialPreProc< MPCsType >::isSpatialPositions
protected

Definition at line 72 of file EssentialMPCsData.hpp.

◆ mField

Definition at line 70 of file EssentialMPCsData.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:215
MoFEM::EssentialPreProc< MPCsType >::mField
MoFEM::Interface & mField
Definition: EssentialMPCsData.hpp:70
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
EntityHandle
MoFEM::th
Tag th
Definition: Projection10NodeCoordsOnField.cpp:122
FieldEntity_multiIndex
multi_index_container< boost::shared_ptr< FieldEntity >, indexed_by< ordered_unique< tag< Unique_mi_tag >, member< FieldEntity, UId, &FieldEntity::localUId > >, ordered_non_unique< tag< Ent_mi_tag >, const_mem_fun< FieldEntity::interface_type_RefEntity, EntityHandle, &FieldEntity::getEnt > > > > FieldEntity_multiIndex
MultiIndex container keeps FieldEntity.
Definition: FieldEntsMultiIndices.hpp:425
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MoFEM::FieldEntity::getLocalUniqueIdCalculate
UId getLocalUniqueIdCalculate()
Get the Local Unique Id Calculate object.
Definition: FieldEntsMultiIndices.hpp:136
MOFEM_LOG_SYNCHRONISE
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
Definition: LogManager.hpp:345
MoFEM::EssentialPreProc< MPCsType >::fePtr
boost::weak_ptr< FEMethod > fePtr
Definition: EssentialMPCsData.hpp:71
Range
FTensor::dd
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::EssentialPreProc< MPCsType >::isSpatialPositions
bool isSpatialPositions
Definition: EssentialMPCsData.hpp:72
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346