glued_mesh_stuff.h
Go to the documentation of this file.
1 // hierher temporary header simply for inclusion of
2 // common code into multiple drivers; tidy up
3 
4 
8 
9 
10 //=========================================================================
19 //=========================================================================
20 class GluedSolidMesh : public virtual SolidMesh {
23  Vector<SolidMesh *> Constituent_mesh_pt;
24 
25 public:
26 
29  GluedSolidMesh(Vector<SolidMesh *> solid_mesh_pt) :
30  Constituent_mesh_pt(solid_mesh_pt) {
31  // Copy all nodes
32  unsigned n_mesh = solid_mesh_pt.size();
33  unsigned total_nnode = 0;
34  for (unsigned i_mesh = 0; i_mesh < n_mesh; i_mesh++) {
35  total_nnode += solid_mesh_pt[i_mesh]->nnode();
36  }
37  Node_pt.resize(total_nnode);
38 
39  unsigned node_count = 0;
40  for (unsigned i_mesh = 0; i_mesh < n_mesh; i_mesh++) {
41  unsigned nnode = solid_mesh_pt[i_mesh]->nnode();
42  for (unsigned j = 0; j < nnode; j++) {
43  Node_pt[node_count] = solid_mesh_pt[i_mesh]->node_pt(j);
44  node_count++;
45  }
46  }
47 
48  // Copy all elements
49  unsigned total_nel = 0;
50  for (unsigned i_mesh = 0; i_mesh < n_mesh; i_mesh++) {
51  total_nel += solid_mesh_pt[i_mesh]->nelement();
52  }
53  Element_pt.resize(total_nel);
54 
55  unsigned el_count = 0;
56  for (unsigned i_mesh = 0; i_mesh < n_mesh; i_mesh++) {
57  unsigned nel = solid_mesh_pt[i_mesh]->nelement();
58  for (unsigned e = 0; e < nel; e++) {
59  Element_pt[el_count] = solid_mesh_pt[i_mesh]->element_pt(e);
60  el_count++;
61  }
62  }
63  }
64 
65 
72  void glue(const Vector<Node *> glue_node_pt,
73  const unsigned &i_mesh_replace) {
74  double t_start = TimingHelpers::timer();
75 
76  // Make input parameter
77  double tol = 1.0e-10;
78 
79  // Map from original to replacement node:
80  // Usage: replacement_node_pt[replaced_node_pt]=nod_pt
81  std::map<Node *, Node *> replacement_node_pt;
82 
83  // Brute force it:
84  //================
85  unsigned nnod_glue = glue_node_pt.size();
86  for (unsigned j = 0; j < nnod_glue; j++) {
87  Node *nod_pt = glue_node_pt[j];
88  unsigned dim = nod_pt->ndim();
89  Node *node_to_be_replaced_pt = 0;
90  unsigned jj_replace_index = 0;
91  unsigned nnod_candidate = Constituent_mesh_pt[i_mesh_replace]->nnode();
92  for (unsigned jj = 0; jj < nnod_candidate; jj++) {
93  Node *nod_alt_pt = Constituent_mesh_pt[i_mesh_replace]->node_pt(jj);
94  double dist_squared = 0.0;
95  for (unsigned i = 0; i < 3; i++) {
96  dist_squared +=
97  (nod_alt_pt->x(i) - nod_pt->x(i)) *
98  (nod_alt_pt->x(i) - nod_pt->x(i));
99  }
100  if (sqrt(dist_squared) < tol) {
101  node_to_be_replaced_pt = nod_alt_pt;
102  jj_replace_index = jj;
103  break;
104  }
105  }
106  if (node_to_be_replaced_pt == 0) {
107  oomph_info << "ERROR: Not found a replacement node for node at ";
108  for (unsigned i = 0; i < dim; i++) {
109  oomph_info << nod_pt->x(i) << " ";
110  }
111  oomph_info << std::endl;
112  // hierher throw proper error
113  abort();
114  }
115 
116  // Replace node in constituent mesh
117  Node *replaced_node_pt =
118  Constituent_mesh_pt[i_mesh_replace]->node_pt(jj_replace_index);
119  dynamic_cast<Mesh *>(Constituent_mesh_pt[i_mesh_replace])->
120  node_pt(jj_replace_index) = nod_pt;
121  replacement_node_pt[replaced_node_pt] = nod_pt;
122 
123  // Replace node in elements
124  unsigned nel = Constituent_mesh_pt[i_mesh_replace]->nelement();
125  for (unsigned e = 0; e < nel; e++) {
126  FiniteElement *fe_pt =
127  Constituent_mesh_pt[i_mesh_replace]->finite_element_pt(e);
128  unsigned nod_el = fe_pt->nnode();
129  for (unsigned j_in_el = 0; j_in_el < nod_el; j_in_el++) {
130  if (fe_pt->node_pt(j_in_el) == node_to_be_replaced_pt) {
131  fe_pt->node_pt(j_in_el) = nod_pt;
132  }
133  }
134  }
135 
136  // Replace node in original mesh's boundary lookup scheme
137  unsigned nb = Constituent_mesh_pt[i_mesh_replace]->nboundary();
138  for (unsigned b = 0; b < nb; b++) {
139  unsigned nnod = Constituent_mesh_pt[i_mesh_replace]->nboundary_node(b);
140  for (unsigned j = 0; j < nnod; j++) {
141  Node *potentially_replaced_node_pt =
142  Constituent_mesh_pt[i_mesh_replace]->boundary_node_pt(b, j);
143  std::map<Node *, Node *>::iterator it;
144  it = replacement_node_pt.find(potentially_replaced_node_pt);
145  if (it == replacement_node_pt.end()) {
146  //oomph_info << "Node in boundary lookup scheme was not replaced\n";
147  } else {
148  // oomph_info << "Replace node "
149  // << potentially_replaced_node_pt << " at: "
150  // << (it->second)->x(0) << " "
151  // << (it->second)->x(1) << " "
152  // << (it->second)->x(2) << " "
153  // << "with " << it->second
154  // << std::endl;
155 
156  // hierher: SolidMesh needs an overload of the read/write version
157  // to this function
158  dynamic_cast<Mesh *>(Constituent_mesh_pt[i_mesh_replace])->
159  boundary_node_pt(b, j) = it->second;
160  }
161  }
162  }
163 
164 
165  // Remove it from the glued mesh's compound Node_pt vector:
166  Vector<Node *> tmp_node_pt(Node_pt);
167  unsigned nnod = tmp_node_pt.size();
168  Node_pt.resize(nnod - 1);
169  unsigned count = 0;
170  for (unsigned jj = 0; jj < nnod; jj++) {
171  if (tmp_node_pt[jj] != node_to_be_replaced_pt) {
172  Node_pt[count] = tmp_node_pt[jj];
173  count++;
174  }
175  }
176 
177  // Now kill node
178  // hierher REINSTATE deletion
179  delete node_to_be_replaced_pt;
180  }
181 
182  // oomph_info << "After gluing glued mesh has " << Node_pt.size()
183  // << " nodes" << std::endl;
184 
185 
186  // Tell us how bad it was; do you fancy implementing the optimised
187  // search scheme?
188  double t_end = TimingHelpers::timer();
189  oomph_info << "Time for (inefficient!) mesh gluing: "
190  << t_end - t_start << std::endl;
191 
192 
193  }
194 };
195 
196 
197 
201 
202 
203 //=========================================================================
205 //=========================================================================
206 template<class ELEMENT>
207 class SolidCubicMesh : public virtual SimpleCubicMesh<ELEMENT>,
208  public virtual SolidMesh {
209 
210 public:
211 
213  SolidCubicMesh(const unsigned &nx, const unsigned &ny,
214  const unsigned &nz,
215  const double &a,
216  const double &b,
217  const double &c,
218  TimeStepper *time_stepper_pt =
219  &Mesh::Default_TimeStepper) :
220  SimpleCubicMesh<ELEMENT>(nx, ny, nz, -a, a, -b, b, -c, c, time_stepper_pt),
221  SolidMesh() {
222  //Assign the initial lagrangian coordinates
223  set_lagrangian_nodal_coordinates();
224  }
225 
226 
228  SolidCubicMesh(const unsigned &nx,
229  const unsigned &ny,
230  const unsigned &nz,
231  const double &x_min,
232  const double &x_max,
233  const double &y_min,
234  const double &y_max,
235  const double &z_min,
236  const double &z_max,
237  TimeStepper *time_stepper_pt =
238  &Mesh::Default_TimeStepper) :
239  SimpleCubicMesh<ELEMENT>(nx, ny, nz,
240  x_min, x_max,
241  y_min, y_max,
242  z_min, z_max,
243  time_stepper_pt),
244  SolidMesh() {
245  //Assign the initial lagrangian coordinates
246  set_lagrangian_nodal_coordinates();
247  }
248 
250  virtual ~SolidCubicMesh() {}
251 
252 };
253 
254 
Definition: glued_mesh_stuff.h:20
void glue(const Vector< Node * > glue_node_pt, const unsigned &i_mesh_replace)
Definition: glued_mesh_stuff.h:72
Vector< SolidMesh * > Constituent_mesh_pt
Definition: glued_mesh_stuff.h:23
GluedSolidMesh(Vector< SolidMesh * > solid_mesh_pt)
Definition: glued_mesh_stuff.h:29
Simple cubic mesh upgraded to become a solid mesh.
Definition: glued_mesh_stuff.h:208
virtual ~SolidCubicMesh()
Empty Destructor.
Definition: glued_mesh_stuff.h:250
SolidCubicMesh(const unsigned &nx, const unsigned &ny, const unsigned &nz, const double &a, const double &b, const double &c, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor: Specify half widths.
Definition: glued_mesh_stuff.h:213
SolidCubicMesh(const unsigned &nx, const unsigned &ny, const unsigned &nz, const double &x_min, const double &x_max, const double &y_min, const double &y_max, const double &z_min, const double &z_max, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Constructor:
Definition: glued_mesh_stuff.h:228
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51