snap_mesh.cc File Reference
#include "generic.h"
#include "solid.h"
#include "constitutive.h"
#include "navier_stokes.h"
#include "poisson.h"
#include "linear_elasticity.h"
#include "mesh_smoothing.h"
#include "meshes/tetgen_mesh.h"

Functions

void demo_smoothing_with_linear_elasticity ()
 
void demo_smoothing_with_poisson ()
 
void demo_smoothing_with_nonlinear_elasticity ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ demo_smoothing_with_linear_elasticity()

void demo_smoothing_with_linear_elasticity ( )

=============================================================

Demonstrate mesh smoothing with linear elasticity

Storage for mesh

51  {
52 
53  // Label for output
54  DocInfo doc_info;
55 
56 
57  // Read boundary enumeration, generated by xda_to_poly_fsi
58  //--------------------------------------------------------
59  string input_string;
60 
61  // Open input file
62  ifstream* input_file_pt=new
63  ifstream("short_coarse_mesh_files/boundary_enumeration.dat");
64 
65  // Check if it's been opened succesfully
66  if (input_file_pt==0)
67  {
68  oomph_info << "ERROR while trying to open boundary enumeration file "
69  << std::endl;
70  exit(1);
71  }
72 
73  getline(*input_file_pt,input_string,' ');
74  unsigned fluid_fsi_lo=atoi(input_string.c_str());
75  getline(*input_file_pt,input_string,'#');
76  unsigned fluid_fsi_hi=atoi(input_string.c_str());
77  input_file_pt->ignore(80,'\n');
78 
79  getline(*input_file_pt,input_string,' ');
80  //unsigned fluid_in_lo=atoi(input_string.c_str());
81  getline(*input_file_pt,input_string,'#');
82  //unsigned fluid_in_hi=atoi(input_string.c_str());
83  input_file_pt->ignore(80,'\n');
84 
85  getline(*input_file_pt,input_string,' ');
86  //unsigned fluid_out_lo=atoi(input_string.c_str());
87  input_file_pt->ignore(80,'\n');
88  getline(*input_file_pt,input_string,' ');
89  getline(*input_file_pt,input_string,'#');
90  //unsigned fluid_out_hi=atoi(input_string.c_str());
91  input_file_pt->ignore(80,'\n');
92 
93  getline(*input_file_pt,input_string,' ');
94  unsigned solid_fsi_lo=atoi(input_string.c_str());
95  getline(*input_file_pt,input_string,'#');
96  unsigned solid_fsi_hi=atoi(input_string.c_str());
97  input_file_pt->ignore(80,'\n');
98 
99  getline(*input_file_pt,input_string,' ');
100  //unsigned solid_pin_lo=atoi(input_string.c_str());
101  input_file_pt->ignore(80,'\n');
102  input_file_pt->ignore(80,'\n');
103  getline(*input_file_pt,input_string,' ');
104  getline(*input_file_pt,input_string,'#');
105  //unsigned solid_pin_hi=atoi(input_string.c_str());
106  input_file_pt->ignore(80,'\n');
107 
108  getline(*input_file_pt,input_string,' ');
109  unsigned solid_outer_lo=atoi(input_string.c_str());
110  getline(*input_file_pt,input_string,'#');
111  unsigned solid_outer_hi=atoi(input_string.c_str());
112  input_file_pt->ignore(80,'\n');
113 
114  delete input_file_pt;
115 
116  // Identify boundaries that make up the FSI interfaces in the
117  // fluid and solid meshes
118  Vector<unsigned> fluid_fsi_boundary_id;
119  Vector<unsigned> solid_fsi_boundary_id;
120  Vector<unsigned> solid_outer_boundary_id;
121 
122  // The FSI boundaries of the fluid mesh
123  unsigned nfluid_fsi=fluid_fsi_hi-fluid_fsi_lo+1;
124  fluid_fsi_boundary_id.resize(nfluid_fsi);
125  for(unsigned i=0; i<nfluid_fsi; i++)
126  {
127  fluid_fsi_boundary_id[i]=fluid_fsi_lo+i;
128  }
129 
130  // The solid and fluid fsi boundaries are numbered in the same way.
131  unsigned nsolid_fsi=solid_fsi_hi-solid_fsi_lo+1;
132  solid_fsi_boundary_id.resize(nsolid_fsi);
133  for(unsigned i=0; i<nsolid_fsi; i++)
134  {
135  solid_fsi_boundary_id[i]=solid_fsi_lo+i;
136  }
137 
138  // Outer solid boundary
139  unsigned nsolid_outer=solid_outer_hi-solid_outer_lo+1;
140  solid_outer_boundary_id.resize(nsolid_outer);
141  for(unsigned i=0; i<nsolid_outer; i++)
142  {
143  solid_outer_boundary_id[i]=solid_outer_lo+i;
144  }
145 
146 
147  // Variables to create meshes
148  string node_file_name;
149  string element_file_name;
150  string face_file_name;
151  bool split_corner_elements;
152  bool switch_normal;
153 
155  SolidTetgenMesh<TPVDElement<3,3> >* Orig_mesh_pt;
156 
157  // Loop over fluid and solid meshes
158  for (unsigned do_solid=0;do_solid<2;do_solid++)
159  {
160 
161  // Build original meshes
162  if (do_solid==1)
163  {
164 
165  oomph_info << "Doing solid\n";
166 
167  // Output directory
168  doc_info.set_directory("RESLT_solid_with_linear_elasticity");
169 
170  //Create bulk mesh, sub-dividing "corner" elements
171  node_file_name="short_coarse_mesh_files/solid.1.node";
172  element_file_name="short_coarse_mesh_files/solid.1.ele";
173  face_file_name="short_coarse_mesh_files/solid.1.face";
174  split_corner_elements=true;
175  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
176  element_file_name,
177  face_file_name,
178  split_corner_elements);
179  }
180  else
181  {
182 
183  oomph_info << "Doing fluid\n";
184 
185  // Output directory
186  doc_info.set_directory("RESLT_fluid_with_linear_elasticity");
187 
188  //Create bulk mesh, sub-dividing "corner" elements
189  node_file_name="short_coarse_mesh_files/fluid.1.node";
190  element_file_name="short_coarse_mesh_files/fluid.1.ele";
191  face_file_name="short_coarse_mesh_files/fluid.1.face";
192  split_corner_elements=true;
193  switch_normal=true;
194  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
195  element_file_name,
196  face_file_name,
197  split_corner_elements,
198  switch_normal);
199  }
200 
201 
202  // Check for inverted elements before quadratic trafo
204  filename=doc_info.directory();
205  filename+="/mesh_before_snap.dat";
206  Orig_mesh_pt->output(filename.c_str());
207  bool mesh_has_inverted_elements;
208  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements);
209  cout << "Before quadratic snapping mesh does ";
210  if (!mesh_has_inverted_elements) cout << "not ";
211  cout << "have inverted elements. \n";
212 
213 
214  if (do_solid==1)
215  {
216  // Snap FSI interface to quadratic surface
217  switch_normal=false;
218  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
219  solid_fsi_boundary_id,
220  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
221  switch_normal);
222 
223  // Snap outer solid interface to quadratic surface
224  switch_normal=true;
225  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
226  solid_outer_boundary_id,
227  "short_coarse_mesh_files/quadratic_outer_solid_boundary.dat",
228  switch_normal);
229  }
230  else
231  {
232  // Snap FSI interface to quadratic surface
233  switch_normal=false;
234  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
235  fluid_fsi_boundary_id,
236  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
237  switch_normal);
238  }
239 
240 
241  // Check
242  filename=doc_info.directory();
243  filename+="/mesh_after_snap.dat";
244  Orig_mesh_pt->output(filename.c_str());
245  std::ofstream inverted_mesh_elements;
246  filename=doc_info.directory();
247  filename+="/inverted_elements_after_snap.dat";
248  inverted_mesh_elements.open(filename.c_str());
249  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
250  inverted_mesh_elements);
251  inverted_mesh_elements.close();
252  cout << "After quadratic snapping mesh does ";
253  if (!mesh_has_inverted_elements) cout << "not ";
254  cout << "have inverted elements. \n";
255 
256 
257 
258  // Smooth it:
259  //-----------
260 
261 
262  // Create set containing the nodes whose displacements are contrained
263  // (nodes on quadratic boundaries)
264  std::set<Node*> pinned_nodes;
265 
266  if (do_solid==1)
267  {
268 
269  // Loop over nodes on the FSI boundary in the solid mesh
270  unsigned nbound_pinned=solid_fsi_boundary_id.size();
271  for(unsigned i=0;i<nbound_pinned;i++)
272  {
273  //Get the mesh boundary
274  unsigned b = solid_fsi_boundary_id[i];
275  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
276  for (unsigned inod=0;inod<num_nod;inod++)
277  {
278  // Get node
279  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
280  }
281  }
282 
283  // Loop over nodes on outer boundary of solid mesh
284  nbound_pinned=solid_outer_boundary_id.size();
285  for(unsigned i=0;i<nbound_pinned;i++)
286  {
287  //Get the mesh boundary
288  unsigned b = solid_outer_boundary_id[i];
289  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
290  for (unsigned inod=0;inod<num_nod;inod++)
291  {
292  // Get node
293  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
294  }
295  }
296 
297  }
298  else
299  {
300  // Loop over nodes on the FSI boundary in the solid mesh
301  unsigned nbound_pinned=fluid_fsi_boundary_id.size();
302  for(unsigned i=0;i<nbound_pinned;i++)
303  {
304  //Get the mesh boundary
305  unsigned b = fluid_fsi_boundary_id[i];
306  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
307  for (unsigned inod=0;inod<num_nod;inod++)
308  {
309  // Get node
310  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
311  }
312  }
313  }
314 
315  // Smooth
317  pinned_nodes);
318 
319  // Check
320  filename=doc_info.directory();
321  filename+="/mesh_after_smooth.dat";
322  Orig_mesh_pt->output(filename.c_str());
323  filename=doc_info.directory();
324  filename+="/inverted_elements_after_smooth.dat";
325  inverted_mesh_elements.open(filename.c_str());
326  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
327  inverted_mesh_elements);
328  inverted_mesh_elements.close();
329  cout << "After smoothing mesh does ";
330  if (!mesh_has_inverted_elements) cout << "not ";
331  cout << "have inverted elements. \n";
332 
333  // Cleanup
334  delete Orig_mesh_pt;
335  Orig_mesh_pt=0;
336 
337  }
338 
339  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: oomph_utilities.h:499
std::string directory() const
Output directory.
Definition: oomph_utilities.h:524
void set_directory(const std::string &directory)
Definition: oomph_utilities.cc:298
Definition: mesh_smooth.h:524
unsigned long nboundary_node(const unsigned &ibound) const
Return number of nodes on a particular boundary.
Definition: mesh.h:833
void check_inverted_elements(bool &mesh_has_inverted_elements, std::ofstream &inverted_element_file)
Definition: mesh.cc:870
void output(std::ostream &outfile)
Output for all elements.
Definition: mesh.cc:2027
SolidNode * boundary_node_pt(const unsigned &b, const unsigned &n)
Return n-th SolidNodes on b-th boundary.
Definition: mesh.h:2612
Definition: tetgen_mesh.template.h:741
string filename
Definition: MergeRestartFiles.py:39
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References b, oomph::SolidMesh::boundary_node_pt(), oomph::Mesh::check_inverted_elements(), oomph::DocInfo::directory(), MergeRestartFiles::filename, i, oomph::Mesh::nboundary_node(), oomph::oomph_info, oomph::Mesh::output(), oomph::DocInfo::set_directory(), and oomph::Global_string_for_annotation::string().

Referenced by main().

◆ demo_smoothing_with_nonlinear_elasticity()

void demo_smoothing_with_nonlinear_elasticity ( )

/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// =============================================================

Demonstrate smoothing with nonlinear elasticity

Storage for mesh and copy

...and another copy

...and another copy

650  {
651 
652  // Label for output
653  DocInfo doc_info;
654 
655 
656  // Read boundary enumeration, generated by xda_to_poly_fsi
657  //--------------------------------------------------------
658  string input_string;
659 
660  // Open input file
661  ifstream* input_file_pt=new
662  ifstream("short_coarse_mesh_files/boundary_enumeration.dat");
663 
664  // Check if it's been opened succesfully
665  if (input_file_pt==0)
666  {
667  oomph_info << "ERROR while trying to open boundary enumeration file "
668  << std::endl;
669  exit(1);
670  }
671 
672 
673  getline(*input_file_pt,input_string,' ');
674  unsigned fluid_fsi_lo=atoi(input_string.c_str());
675  getline(*input_file_pt,input_string,'#');
676  unsigned fluid_fsi_hi=atoi(input_string.c_str());
677  input_file_pt->ignore(80,'\n');
678 
679  getline(*input_file_pt,input_string,' ');
680  //unsigned fluid_in_lo=atoi(input_string.c_str());
681  getline(*input_file_pt,input_string,'#');
682  //unsigned fluid_in_hi=atoi(input_string.c_str());
683  input_file_pt->ignore(80,'\n');
684 
685  getline(*input_file_pt,input_string,' ');
686  //unsigned fluid_out_lo=atoi(input_string.c_str());
687  input_file_pt->ignore(80,'\n');
688  getline(*input_file_pt,input_string,' ');
689  getline(*input_file_pt,input_string,'#');
690  //unsigned fluid_out_hi=atoi(input_string.c_str());
691  input_file_pt->ignore(80,'\n');
692 
693  getline(*input_file_pt,input_string,' ');
694  unsigned solid_fsi_lo=atoi(input_string.c_str());
695  getline(*input_file_pt,input_string,'#');
696  unsigned solid_fsi_hi=atoi(input_string.c_str());
697  input_file_pt->ignore(80,'\n');
698 
699  getline(*input_file_pt,input_string,' ');
700  //unsigned solid_pin_lo=atoi(input_string.c_str());
701  input_file_pt->ignore(80,'\n');
702  input_file_pt->ignore(80,'\n');
703  getline(*input_file_pt,input_string,' ');
704  getline(*input_file_pt,input_string,'#');
705  //unsigned solid_pin_hi=atoi(input_string.c_str());
706  input_file_pt->ignore(80,'\n');
707 
708  getline(*input_file_pt,input_string,' ');
709  //unsigned solid_outer_lo=atoi(input_string.c_str());
710  getline(*input_file_pt,input_string,'#');
711  //unsigned solid_outer_hi=atoi(input_string.c_str());
712  input_file_pt->ignore(80,'\n');
713 
714  delete input_file_pt;
715 
716  // Identify boundaries that make up the FSI interfaces in the
717  // fluid and solid meshes
718  Vector<unsigned> fluid_fsi_boundary_id;
719  Vector<unsigned> solid_fsi_boundary_id;
720 
721  // The FSI boundaries of the fluid mesh
722  unsigned nfluid_fsi=fluid_fsi_hi-fluid_fsi_lo+1;
723  fluid_fsi_boundary_id.resize(nfluid_fsi);
724  for(unsigned i=0; i<nfluid_fsi; i++)
725  {
726  fluid_fsi_boundary_id[i]=fluid_fsi_lo+i;
727  }
728 
729  // The solid and fluid fsi boundaries are numbered in the same way.
730  unsigned nsolid_fsi=solid_fsi_hi-solid_fsi_lo+1;
731  solid_fsi_boundary_id.resize(nsolid_fsi);
732  for(unsigned i=0; i<nsolid_fsi; i++)
733  {
734  solid_fsi_boundary_id[i]=solid_fsi_lo+i;
735  }
736 
737  // Variables to create meshes
738  string node_file_name;
739  string element_file_name;
740  string face_file_name;
741  bool split_corner_elements;
742  bool switch_normal;
743 
745  SolidTetgenMesh<TPVDElement<3,3> >* Orig_mesh_pt;
746  SolidTetgenMesh<TPVDElement<3,3> >* Copy_of_mesh_pt;
747 
748  // Loop over fluid and solid meshes
749  for (unsigned do_solid=0;do_solid<2;do_solid++)
750  {
751 
752  // Build original meshes
753  if (do_solid==1)
754  {
755 
756  oomph_info << "Doing solid\n";
757 
758  // Output directory
759  doc_info.set_directory("RESLT_solid");
760 
761  //Create bulk mesh, sub-dividing "corner" elements
762  node_file_name="short_coarse_mesh_files/solid.1.node";
763  element_file_name="short_coarse_mesh_files/solid.1.ele";
764  face_file_name="short_coarse_mesh_files/solid.1.face";
765  split_corner_elements=true;
766  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
767  element_file_name,
768  face_file_name,
769  split_corner_elements);
771  Copy_of_mesh_pt=new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
772  element_file_name,
773  face_file_name,
774  split_corner_elements);
775  }
776  else
777  {
778 
779  oomph_info << "Doing fluid\n";
780 
781  // Output directory
782  doc_info.set_directory("RESLT_fluid");
783 
784  //Create bulk mesh, sub-dividing "corner" elements
785  node_file_name="short_coarse_mesh_files/fluid.1.node";
786  element_file_name="short_coarse_mesh_files/fluid.1.ele";
787  face_file_name="short_coarse_mesh_files/fluid.1.face";
788  split_corner_elements=true;
789  switch_normal=true;
790  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
791  element_file_name,
792  face_file_name,
793  split_corner_elements,
794  switch_normal);
796  Copy_of_mesh_pt=new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
797  element_file_name,
798  face_file_name,
799  split_corner_elements,
800  switch_normal);
801  }
802 
803 
804  // Check for inverted elements before quadratic trafo
806  filename=doc_info.directory();
807  filename+="/mesh_before_snap.dat";
808  Orig_mesh_pt->output(filename.c_str());
809  bool mesh_has_inverted_elements;
810  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements);
811  cout << "Before quadratic snapping mesh does ";
812  if (!mesh_has_inverted_elements) cout << "not ";
813  cout << "have inverted elements. \n";
814 
815  // Snap FSI interface to quadratic surface
816  if (do_solid==1)
817  {
818  switch_normal=false;
819  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
820  solid_fsi_boundary_id,
821  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
822  switch_normal);
823  }
824  else
825  {
826  switch_normal=false;
827  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
828  fluid_fsi_boundary_id,
829  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
830  switch_normal);
831  }
832 
833 
834  // Check
835  filename=doc_info.directory();
836  filename+="/mesh_after_snap.dat";
837  Orig_mesh_pt->output(filename.c_str());
838  std::ofstream inverted_mesh_elements;
839  filename=doc_info.directory();
840  filename+="/inverted_elements_after_snap.dat";
841  inverted_mesh_elements.open(filename.c_str());
842  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
843  inverted_mesh_elements);
844  inverted_mesh_elements.close();
845  cout << "After quadratic snapping mesh does ";
846  if (!mesh_has_inverted_elements) cout << "not ";
847  cout << "have inverted elements. \n";
848 
849  // Smooth it: Specify the two meshes (the original and a working
850  // copy that can get deleted afterwards and the boundary IDs
851  // of the fsi boundary (same in fluid and solid!)
852  unsigned max_steps=100;
853  if (CommandLineArgs::Argc!=1)
854  {
855  cout << "Validation, just doing one step of mesh smoothing\n";
856  max_steps=1;
857  }
859  Copy_of_mesh_pt,
860  solid_fsi_boundary_id,
861  doc_info,
862  max_steps);
863 
864 
865  // Check
866  filename=doc_info.directory();
867  filename+="/mesh_after_smooth.dat";
868  Orig_mesh_pt->output(filename.c_str());
869 
870  filename=doc_info.directory();
871  filename+="/inverted_elements_after_smooth.dat";
872  inverted_mesh_elements.open(filename.c_str());
873  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
874  inverted_mesh_elements);
875  inverted_mesh_elements.close();
876  cout << "After smoothing mesh does ";
877  if (!mesh_has_inverted_elements) cout << "not ";
878  cout << "have inverted elements. \n";
879 
880 
881  filename=doc_info.directory();
882  filename+="/new_nodal_positions.dat";
883  ofstream node_file;
884  node_file.open(filename.c_str());
885  unsigned nnod=Orig_mesh_pt->nnode();
886  for (unsigned j=0;j<nnod;j++)
887  {
888  Node* nod_pt=Orig_mesh_pt->node_pt(j);
889  node_file << nod_pt->x(0) << " "
890  << nod_pt->x(1) << " "
891  << nod_pt->x(2) << " "
892  << std::endl;
893  }
894  node_file.close();
895 
896 
897  // Cleanup
898  delete Orig_mesh_pt;
899  Orig_mesh_pt=0;
900  delete Copy_of_mesh_pt;
901  Copy_of_mesh_pt=0;
902 
903  }
904 
905 }
unsigned long nnode() const
Return number of nodes in the mesh.
Definition: mesh.h:596
Definition: nodes.h:906
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition: nodes.h:1060
Definition: mesh_smooth.h:98
SolidNode * node_pt(const unsigned long &n)
Return a pointer to the n-th global SolidNode.
Definition: mesh.h:2594
int Argc
Number of arguments + 1.
Definition: oomph_utilities.cc:407
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::CommandLineArgs::Argc, oomph::Mesh::check_inverted_elements(), oomph::DocInfo::directory(), MergeRestartFiles::filename, i, j, oomph::Mesh::nnode(), oomph::SolidMesh::node_pt(), oomph::oomph_info, oomph::Mesh::output(), oomph::DocInfo::set_directory(), oomph::Global_string_for_annotation::string(), and oomph::Node::x().

Referenced by main().

◆ demo_smoothing_with_poisson()

void demo_smoothing_with_poisson ( )

/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// =============================================================

Demonstrate smoothing with Poisson

Storage for mesh

350  {
351 
352  // Label for output
353  DocInfo doc_info;
354 
355 
356  // Read boundary enumeration, generated by xda_to_poly_fsi
357  //--------------------------------------------------------
358  string input_string;
359 
360  // Open input file
361  ifstream* input_file_pt=new
362  ifstream("short_coarse_mesh_files/boundary_enumeration.dat");
363 
364  // Check if it's been opened succesfully
365  if (input_file_pt==0)
366  {
367  oomph_info << "ERROR while trying to open boundary enumeration file "
368  << std::endl;
369  exit(1);
370  }
371 
372 
373  getline(*input_file_pt,input_string,' ');
374  unsigned fluid_fsi_lo=atoi(input_string.c_str());
375  getline(*input_file_pt,input_string,'#');
376  unsigned fluid_fsi_hi=atoi(input_string.c_str());
377  input_file_pt->ignore(80,'\n');
378 
379  getline(*input_file_pt,input_string,' ');
380  //unsigned fluid_in_lo=atoi(input_string.c_str());
381  getline(*input_file_pt,input_string,'#');
382  //unsigned fluid_in_hi=atoi(input_string.c_str());
383  input_file_pt->ignore(80,'\n');
384 
385  getline(*input_file_pt,input_string,' ');
386  //unsigned fluid_out_lo=atoi(input_string.c_str());
387  input_file_pt->ignore(80,'\n');
388  getline(*input_file_pt,input_string,' ');
389  getline(*input_file_pt,input_string,'#');
390  //unsigned fluid_out_hi=atoi(input_string.c_str());
391  input_file_pt->ignore(80,'\n');
392 
393  getline(*input_file_pt,input_string,' ');
394  unsigned solid_fsi_lo=atoi(input_string.c_str());
395  getline(*input_file_pt,input_string,'#');
396  unsigned solid_fsi_hi=atoi(input_string.c_str());
397  input_file_pt->ignore(80,'\n');
398 
399  getline(*input_file_pt,input_string,' ');
400  //unsigned solid_pin_lo=atoi(input_string.c_str());
401  input_file_pt->ignore(80,'\n');
402  input_file_pt->ignore(80,'\n');
403  getline(*input_file_pt,input_string,' ');
404  getline(*input_file_pt,input_string,'#');
405  //unsigned solid_pin_hi=atoi(input_string.c_str());
406  input_file_pt->ignore(80,'\n');
407 
408  getline(*input_file_pt,input_string,' ');
409  unsigned solid_outer_lo=atoi(input_string.c_str());
410  getline(*input_file_pt,input_string,'#');
411  unsigned solid_outer_hi=atoi(input_string.c_str());
412  input_file_pt->ignore(80,'\n');
413 
414  delete input_file_pt;
415 
416  // Identify boundaries that make up the FSI interfaces in the
417  // fluid and solid meshes
418  Vector<unsigned> fluid_fsi_boundary_id;
419  Vector<unsigned> solid_fsi_boundary_id;
420  Vector<unsigned> solid_outer_boundary_id;
421 
422  // The FSI boundaries of the fluid mesh
423  unsigned nfluid_fsi=fluid_fsi_hi-fluid_fsi_lo+1;
424  fluid_fsi_boundary_id.resize(nfluid_fsi);
425  for(unsigned i=0; i<nfluid_fsi; i++)
426  {
427  fluid_fsi_boundary_id[i]=fluid_fsi_lo+i;
428  }
429 
430  // The solid and fluid fsi boundaries are numbered in the same way.
431  unsigned nsolid_fsi=solid_fsi_hi-solid_fsi_lo+1;
432  solid_fsi_boundary_id.resize(nsolid_fsi);
433  for(unsigned i=0; i<nsolid_fsi; i++)
434  {
435  solid_fsi_boundary_id[i]=solid_fsi_lo+i;
436  }
437 
438  // Outer solid boundary
439  unsigned nsolid_outer=solid_outer_hi-solid_outer_lo+1;
440  solid_outer_boundary_id.resize(nsolid_outer);
441  for(unsigned i=0; i<nsolid_outer; i++)
442  {
443  solid_outer_boundary_id[i]=solid_outer_lo+i;
444  }
445 
446 
447  // Variables to create meshes
448  string node_file_name;
449  string element_file_name;
450  string face_file_name;
451  bool split_corner_elements;
452  bool switch_normal;
453 
455  SolidTetgenMesh<TPVDElement<3,3> >* Orig_mesh_pt;
456 
457  // Loop over fluid and solid meshes
458  for (unsigned do_solid=0;do_solid<2;do_solid++)
459  {
460 
461  // Build original meshes
462  if (do_solid==1)
463  {
464 
465  oomph_info << "Doing solid\n";
466 
467  // Output directory
468  doc_info.set_directory("RESLT_solid_with_poisson");
469 
470  //Create bulk mesh, sub-dividing "corner" elements
471  node_file_name="short_coarse_mesh_files/solid.1.node";
472  element_file_name="short_coarse_mesh_files/solid.1.ele";
473  face_file_name="short_coarse_mesh_files/solid.1.face";
474  split_corner_elements=true;
475  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
476  element_file_name,
477  face_file_name,
478  split_corner_elements);
479  }
480  else
481  {
482 
483  oomph_info << "Doing fluid\n";
484 
485  // Output directory
486  doc_info.set_directory("RESLT_fluid_with_poisson");
487 
488  //Create bulk mesh, sub-dividing "corner" elements
489  node_file_name="short_coarse_mesh_files/fluid.1.node";
490  element_file_name="short_coarse_mesh_files/fluid.1.ele";
491  face_file_name="short_coarse_mesh_files/fluid.1.face";
492  split_corner_elements=true;
493  switch_normal=true;
494  Orig_mesh_pt = new SolidTetgenMesh<TPVDElement<3,3> >(node_file_name,
495  element_file_name,
496  face_file_name,
497  split_corner_elements,
498  switch_normal);
499  }
500 
501 
502  // Check for inverted elements before quadratic trafo
504  filename=doc_info.directory();
505  filename+="/mesh_before_snap.dat";
506  Orig_mesh_pt->output(filename.c_str());
507  bool mesh_has_inverted_elements;
508  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements);
509  cout << "Before quadratic snapping mesh does ";
510  if (!mesh_has_inverted_elements) cout << "not ";
511  cout << "have inverted elements. \n";
512 
513 
514  if (do_solid==1)
515  {
516  // Snap FSI interface to quadratic surface
517  switch_normal=false;
518  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
519  solid_fsi_boundary_id,
520  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
521  switch_normal);
522 
523  // Snap outer solid interface to quadratic surface
524  switch_normal=true;
525  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
526  solid_outer_boundary_id,
527  "short_coarse_mesh_files/quadratic_outer_solid_boundary.dat",
528  switch_normal);
529  }
530  else
531  {
532  // Snap FSI interface to quadratic surface
533  switch_normal=false;
534  Orig_mesh_pt->template snap_to_quadratic_surface<TPVDElement<3,3> >(
535  fluid_fsi_boundary_id,
536  "short_coarse_mesh_files/quadratic_fsi_boundary.dat",
537  switch_normal);
538  }
539 
540 
541  // Check
542  filename=doc_info.directory();
543  filename+="/mesh_after_snap.dat";
544  Orig_mesh_pt->output(filename.c_str());
545  std::ofstream inverted_mesh_elements;
546  filename=doc_info.directory();
547  filename+="/inverted_elements_after_snap.dat";
548  inverted_mesh_elements.open(filename.c_str());
549  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
550  inverted_mesh_elements);
551  inverted_mesh_elements.close();
552  cout << "After quadratic snapping mesh does ";
553  if (!mesh_has_inverted_elements) cout << "not ";
554  cout << "have inverted elements. \n";
555 
556 
557 
558  // Smooth it:
559  //-----------
560 
561  // Create set containing the nodes whose displacements are contrained
562  // (nodes on quadratic boundaries)
563  std::set<Node*> pinned_nodes;
564 
565  if (do_solid==1)
566  {
567 
568  // Loop over nodes on the FSI boundary in the solid mesh
569  unsigned nbound_pinned=solid_fsi_boundary_id.size();
570  for(unsigned i=0;i<nbound_pinned;i++)
571  {
572  //Get the mesh boundary
573  unsigned b = solid_fsi_boundary_id[i];
574  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
575  for (unsigned inod=0;inod<num_nod;inod++)
576  {
577  // Get node
578  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
579  }
580  }
581 
582  // Loop over nodes on outer boundary of solid mesh
583  nbound_pinned=solid_outer_boundary_id.size();
584  for(unsigned i=0;i<nbound_pinned;i++)
585  {
586  //Get the mesh boundary
587  unsigned b = solid_outer_boundary_id[i];
588  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
589  for (unsigned inod=0;inod<num_nod;inod++)
590  {
591  // Get node
592  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
593  }
594  }
595 
596  }
597  else
598  {
599  // Loop over nodes on the FSI boundary in the solid mesh
600  unsigned nbound_pinned=fluid_fsi_boundary_id.size();
601  for(unsigned i=0;i<nbound_pinned;i++)
602  {
603  //Get the mesh boundary
604  unsigned b = fluid_fsi_boundary_id[i];
605  unsigned num_nod=Orig_mesh_pt->nboundary_node(b);
606  for (unsigned inod=0;inod<num_nod;inod++)
607  {
608  // Get node
609  pinned_nodes.insert(Orig_mesh_pt->boundary_node_pt(b,inod));
610  }
611  }
612  }
613 
614  // Smooth
615  PoissonSmoothMesh<TPoissonElement<3,3> >()(Orig_mesh_pt,pinned_nodes);
616 
617 
618  // Check
619  filename=doc_info.directory();
620  filename+="/mesh_after_smooth.dat";
621  Orig_mesh_pt->output(filename.c_str());
622  filename=doc_info.directory();
623  filename+="/inverted_elements_after_smooth.dat";
624  inverted_mesh_elements.open(filename.c_str());
625  Orig_mesh_pt->check_inverted_elements(mesh_has_inverted_elements,
626  inverted_mesh_elements);
627  inverted_mesh_elements.close();
628  cout << "After smoothing mesh does ";
629  if (!mesh_has_inverted_elements) cout << "not ";
630  cout << "have inverted elements. \n";
631 
632  // Cleanup
633  delete Orig_mesh_pt;
634  Orig_mesh_pt=0;
635 
636  }
637 
638  }
Definition: mesh_smooth.h:659

References b, oomph::SolidMesh::boundary_node_pt(), oomph::Mesh::check_inverted_elements(), oomph::DocInfo::directory(), MergeRestartFiles::filename, i, oomph::Mesh::nboundary_node(), oomph::oomph_info, oomph::Mesh::output(), oomph::DocInfo::set_directory(), and oomph::Global_string_for_annotation::string().

Referenced by main().

◆ main()

int main ( int argc  ,
char **  argv 
)

/////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// Demonstrate how to update FSI fluid and solid meshes to quadratic representation of FSI interface.

918 {
919  // Store command line arguments
920  CommandLineArgs::setup(argc,argv);
921 
922  // Demonstrate smoothing with nonlinear elastictiy
924 
925  // Demonstrate smoothing with nonlinear elastictiy
927 
928  // Demonstrate smoothing with nonlinear elastictiy
930 
931 }
void setup(Time *time_pt)
Create all GeomObjects needed to define the cylinder and the flag.
Definition: turek_flag_non_fsi.cc:277
void demo_smoothing_with_linear_elasticity()
Definition: snap_mesh.cc:50
void demo_smoothing_with_nonlinear_elasticity()
Definition: snap_mesh.cc:649
void demo_smoothing_with_poisson()
Definition: snap_mesh.cc:349

References demo_smoothing_with_linear_elasticity(), demo_smoothing_with_nonlinear_elasticity(), demo_smoothing_with_poisson(), and Flag_definition::setup().