c_style_output.cc File Reference

Classes

class  ElasticRefineableQuarterCircleSectorMesh< ELEMENT >
 
class  SimpleRefineableRectangularQuadMesh< ELEMENT >
 

Functions

void output_both_versions (const string &file_root, Mesh *mesh_pt, const unsigned &npts)
 Global output function to compare C++ and C-style output routines. More...
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// Ugly driver code – brutally loop over lots of mesh/element combinations and produce C/C++-style output.

///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////

265 {
266 
267  unsigned nplot=5;
268  unsigned nelem=1000;
269 
270 
273 
274  {
275  // Set the undeformed beam to be a straight line at y=0
276  GeomObject* undef_beam_pt=new StraightLine(0.0);
277 
278  // Build and assign mesh
279  double L=1.0;
280  Mesh* mesh_pt =
281  new OneDLagrangianMesh<HermiteBeamElement>(nelem,L,undef_beam_pt);
282 
283  //Assign undeformed geometry
284  for(unsigned i=0;i<nelem;i++)
285  {
286  //Cast to proper element type
287  HermiteBeamElement* elem_pt =
288  dynamic_cast<HermiteBeamElement*>(mesh_pt->element_pt(i));
289 
290  //Assign the undeformed beam shape
291  elem_pt->undeformed_beam_pt() = undef_beam_pt;
292  }
293 
294  // Filename for output
295  string file_root="beam";
296 
297  // Compare output
298  output_both_versions(file_root,mesh_pt,nplot);
299 
300  delete mesh_pt;
301  }
302 
303 
306 
307  {
308 
309  // Build the geometric object that describes the outer wall
310  GeomObject* curved_boundary_pt = new Ellipse(1.0,1.0);
311 
312  // The curved boundary of the mesh is defined by the geometric object
313  // What follows are the start and end coordinates on the geometric object:
314  double xi_lo=0.0;
315  double xi_hi=2.0*atan(1.0);
316 
317  // Fraction along geometric object at which the radial dividing line
318  // is placed
319  double fract_mid=0.5;
320 
321 
322  //--------------------------------------------------
323  {
324  // Build and assign mesh
325  Mesh* mesh_pt =
327  (curved_boundary_pt,xi_lo,fract_mid,xi_hi);
328 
329  // Filename for output
330  string file_root="adapt_solid_pvd_2";
331 
332  // Compare output
333  output_both_versions(file_root,mesh_pt,nplot);
334 
335  delete mesh_pt;
336  }
337 
338  //--------------------------------------------------
339  {
340  // Build and assign mesh
341  Mesh* mesh_pt =
343  (curved_boundary_pt,xi_lo,fract_mid,xi_hi);
344 
345  // Filename for output
346  string file_root="adapt_solid_pvd_3";
347 
348  // Compare output
349  output_both_versions(file_root,mesh_pt,nplot);
350 
351  delete mesh_pt;
352  }
353 
354 
355  //--------------------------------------------------
356  {
357  // Build and assign mesh
358  Mesh* mesh_pt =
360  (curved_boundary_pt,xi_lo,fract_mid,xi_hi);
361 
362  // Filename for output
363  string file_root="adapt_solid_pvd_4";
364 
365  // Compare output
366  output_both_versions(file_root,mesh_pt,nplot);
367 
368  delete mesh_pt;
369  }
370 
371  //--------------------------------------------------
372  {
373  // Build and assign mesh
374  Mesh* mesh_pt =
377  curved_boundary_pt,xi_lo,fract_mid,xi_hi);
378 
379  // Filename for output
380  string file_root="adapt_solid_pvd_cp";
381 
382  // Compare output
383  output_both_versions(file_root,mesh_pt,nplot);
384 
385  delete mesh_pt;
386  }
387 
388 
389  //--------------------------------------------------
390  {
391  // Build and assign mesh
392  Mesh* mesh_pt =
395  curved_boundary_pt,xi_lo,fract_mid,xi_hi);
396 
397  // Filename for output
398  string file_root="adapt_solid_pvd_p";
399 
400  // Compare output
401  output_both_versions(file_root,mesh_pt,nplot);
402 
403  delete mesh_pt;
404  }
405 
406  }
407 
408 
411 
412 
413 
414  // # of elements in x-direction
415  unsigned n_x=10;
416 
417  // # of elements in y-direction
418  unsigned n_y=10;
419 
420  // Domain length in x-direction
421  double l_x=1.0;
422 
423  // Domain length in y-direction
424  double l_y=2.0;
425 
426 
427  // Create geom object
428  double L_up=1.0;
429  double L=5.0;
430  double L_down=5.0;
431  TimeStepper* time_stepper_pt=new Steady<0>;
432 
433  GeomObject* Wall_pt=new
434  EllipticalTube(1.0,1.0);
435 
436 
437  // Boundaries on object: quarter tube
438  Vector<double> xi_lo(2);
439  xi_lo[0]=0.0;
440  xi_lo[1]=0.0;
441 
442  Vector<double> xi_hi(2);
443  xi_hi[0]=L_up+L+L_down;
444  xi_hi[1]=0.5*4.0*atan(1.0);
445  double frac_mid=0.5;
446  unsigned nlayer=11;
447 
448 
449  //-------------------------------------------------------------
450  {
451 
452  // Build and assign mesh
454  (Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
455 
456 
457  // Filename for output
458  string file_root="adapt_taylor_hood_3";
459 
460  // Compare output
461  output_both_versions(file_root,mesh_pt,nplot);
462 
463  delete mesh_pt;
464 
465  }
466 
467  //-------------------------------------------------------------
468  {
469 
470  // Build and assign mesh
471  Mesh* mesh_pt=
473  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
474 
475 
476  // Filename for output
477  string file_root="adapt_crozier_raviart_3";
478 
479  // Compare output
480  output_both_versions(file_root,mesh_pt,nplot);
481 
482  delete mesh_pt;
483 
484  }
485 
486 
487  //--------------------------------------------------
488  {
489  // Build and assign mesh
490  Mesh* mesh_pt =
492 
493  // Filename for output
494  string file_root="taylor_hood_2";
495 
496  // Compare output
497  output_both_versions(file_root,mesh_pt,nplot);
498 
499  delete mesh_pt;
500  }
501 
502 
503  //--------------------------------------------------
504  {
505  // Build and assign mesh
506  Mesh* mesh_pt =
508 
509  // Filename for output
510  string file_root="crozier_raviart_2";
511 
512  // Compare output
513  output_both_versions(file_root,mesh_pt,nplot);
514 
515  delete mesh_pt;
516  }
517 
518  //--------------------------------------------------
519  {
520  // Build and assign mesh
521  Mesh* mesh_pt =
523  <RefineableQCrouzeixRaviartElement<2> >(n_x,n_y,l_x,l_y);
524 
525  // Filename for output
526  string file_root="adapt_crozier_raviart_2";
527 
528  // Compare output
529  output_both_versions(file_root,mesh_pt,nplot);
530 
531  delete mesh_pt;
532  }
533 
534 
535  //--------------------------------------------------
536  {
537  // Build and assign mesh
538  Mesh* mesh_pt =
540  <RefineableQTaylorHoodElement<2> >(n_x,n_y,l_x,l_y);
541 
542  // Filename for output
543  string file_root="adapt_taylor_hood_2";
544 
545  // Compare output
546  output_both_versions(file_root,mesh_pt,nplot);
547 
548  delete mesh_pt;
549  }
550 
551 
552  //-------------------------------------------------------------
553  {
554 
555  // Build and assign mesh
557  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
558 
559 
560  // Filename for output
561  string file_root="poisson_3_2";
562 
563  // Compare output
564  output_both_versions(file_root,mesh_pt,nplot);
565 
566  delete mesh_pt;
567 
568  }
569 
570  //-------------------------------------------------------------
571  {
572 
573  // Build and assign mesh
575  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
576 
577 
578  // Filename for output
579  string file_root="poisson_3_3";
580 
581  // Compare output
582  output_both_versions(file_root,mesh_pt,nplot);
583 
584  delete mesh_pt;
585  }
586 
587  //-------------------------------------------------------------
588  {
589 
590  // Build and assign mesh
592  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
593 
594 
595  // Filename for output
596  string file_root="poisson_3_4";
597 
598  // Compare output
599  output_both_versions(file_root,mesh_pt,nplot);
600 
601  delete mesh_pt;
602 
603  }
604 
605 
606  //-------------------------------------------------------------
607  {
608 
609  // Build and assign mesh
611  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
612 
613 
614  // Filename for output
615  string file_root="adapt_poisson_3_2";
616 
617  // Compare output
618  output_both_versions(file_root,mesh_pt,nplot);
619 
620  delete mesh_pt;
621 
622  }
623 
624  //-------------------------------------------------------------
625  {
626 
627  // Build and assign mesh
629  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
630 
631 
632  // Filename for output
633  string file_root="adapt_poisson_3_3";
634 
635  // Compare output
636  output_both_versions(file_root,mesh_pt,nplot);
637 
638  delete mesh_pt;
639 
640  }
641 
642  //-------------------------------------------------------------
643  {
644 
645  // Build and assign mesh
647  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
648 
649 
650  // Filename for output
651  string file_root="adapt_poisson_3_4";
652 
653  // Compare output
654  output_both_versions(file_root,mesh_pt,nplot);
655 
656  delete mesh_pt;
657 
658  }
659 
660 
661  //--------------------------------------------------
662  {
663  // Build mesh and store pointer
664  Mesh* mesh_pt=new OneDMesh<QPoissonElement<1,2> >(nelem,1.0);
665 
666  // Filename for output
667  string file_root="poisson_1_2";
668 
669  // Compare output
670  output_both_versions(file_root,mesh_pt,nplot);
671 
672  delete mesh_pt;
673  }
674 
675 
676  //--------------------------------------------------
677  {
678  // Build mesh and store pointer
679  Mesh* mesh_pt=new OneDMesh<QPoissonElement<1,3> >(nelem,1.0);
680 
681  // Filename for output
682  string file_root="poisson_1_3";
683 
684  // Compare output
685  output_both_versions(file_root,mesh_pt,nplot);
686 
687  delete mesh_pt;
688  }
689 
690 
691  //--------------------------------------------------
692  {
693  // Build mesh and store pointer
694  Mesh* mesh_pt=new OneDMesh<QPoissonElement<1,4> >(nelem,1.0);
695 
696  // Filename for output
697  string file_root="poisson_1_4";
698 
699  // Compare output
700  output_both_versions(file_root,mesh_pt,nplot);
701 
702  delete mesh_pt;
703  }
704 
705 
706  //--------------------------------------------------
707  {
708  // Build and assign mesh
709  Mesh* mesh_pt =
710  new SimpleRectangularQuadMesh<QPoissonElement<2,2> >(n_x,n_y,l_x,l_y);
711 
712  // Filename for output
713  string file_root="poisson_2_2";
714 
715  // Compare output
716  output_both_versions(file_root,mesh_pt,nplot);
717 
718  delete mesh_pt;
719  }
720 
721 
722 
723  //--------------------------------------------------
724  {
725  // Build and assign mesh
726  Mesh* mesh_pt =
727  new SimpleRectangularQuadMesh<QPoissonElement<2,3> >(n_x,n_y,l_x,l_y);
728 
729  // Filename for output
730  string file_root="poisson_2_3";
731 
732  // Compare output
733  output_both_versions(file_root,mesh_pt,nplot);
734 
735  delete mesh_pt;
736  }
737 
738 
739 
740  //--------------------------------------------------
741  {
742  // Build and assign mesh
743  Mesh* mesh_pt =
744  new SimpleRectangularQuadMesh<QPoissonElement<2,4> >(n_x,n_y,l_x,l_y);
745 
746  // Filename for output
747  string file_root="poisson_2_4";
748 
749  // Compare output
750  output_both_versions(file_root,mesh_pt,nplot);
751 
752  delete mesh_pt;
753  }
754 
755 
756 //--------------------------------------------------
757  {
758  // Build and assign mesh
759  Mesh* mesh_pt =
761  (n_x,n_y,l_x,l_y);
762 
763  // Filename for output
764  string file_root="adapt_poisson_2_2";
765 
766  // Compare output
767  output_both_versions(file_root,mesh_pt,nplot);
768 
769  delete mesh_pt;
770  }
771 
772 
773 
774  //--------------------------------------------------
775  {
776  // Build and assign mesh
777  Mesh* mesh_pt =
779  (n_x,n_y,l_x,l_y);
780 
781  // Filename for output
782  string file_root="adapt_poisson_2_3";
783 
784  // Compare output
785  output_both_versions(file_root,mesh_pt,nplot);
786 
787  delete mesh_pt;
788  }
789 
790 
791 
792  //--------------------------------------------------
793  {
794  // Build and assign mesh
795  Mesh* mesh_pt =
797  (n_x,n_y,l_x,l_y);
798 
799  // Filename for output
800  string file_root="adapt_poisson_2_4";
801 
802  // Compare output
803  output_both_versions(file_root,mesh_pt,nplot);
804 
805  delete mesh_pt;
806  }
807 
808 
809 
810 
814 
815 
816  //-------------------------------------------------------------
817  {
818 
819  // Build and assign mesh
821  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
822 
823 
824  // Filename for output
825  string file_root="unsteady_heat_3_2";
826 
827  // Compare output
828  output_both_versions(file_root,mesh_pt,nplot);
829 
830  delete mesh_pt;
831 
832  }
833 
834  //-------------------------------------------------------------
835  {
836 
837  // Build and assign mesh
839  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
840 
841 
842  // Filename for output
843  string file_root="unsteady_heat_3_3";
844 
845  // Compare output
846  output_both_versions(file_root,mesh_pt,nplot);
847 
848  delete mesh_pt;
849 
850  }
851 
852  //-------------------------------------------------------------
853  {
854 
855  // Build and assign mesh
857  Wall_pt,xi_lo,frac_mid,xi_hi,nlayer,time_stepper_pt);
858 
859 
860  // Filename for output
861  string file_root="unsteady_heat_3_4";
862 
863  // Compare output
864  output_both_versions(file_root,mesh_pt,nplot);
865 
866  delete mesh_pt;
867 
868  }
869 
871 
872 
873  //--------------------------------------------------
874  {
875  // Build mesh and store pointer
876  Mesh* mesh_pt=new OneDMesh<QUnsteadyHeatElement<1,2> >(nelem,1.0);
877 
878  // Filename for output
879  string file_root="unsteady_heat_1_2";
880 
881  // Compare output
882  output_both_versions(file_root,mesh_pt,nplot);
883 
884  delete mesh_pt;
885  }
886 
887 
888  //--------------------------------------------------
889  {
890  // Build mesh and store pointer
891  Mesh* mesh_pt=new OneDMesh<QUnsteadyHeatElement<1,3> >(nelem,1.0);
892 
893  // Filename for output
894  string file_root="unsteady_heat_1_3";
895 
896  // Compare output
897  output_both_versions(file_root,mesh_pt,nplot);
898 
899  delete mesh_pt;
900  }
901 
902 
903  //--------------------------------------------------
904  {
905  // Build mesh and store pointer
906  Mesh* mesh_pt=new OneDMesh<QUnsteadyHeatElement<1,4> >(nelem,1.0);
907 
908  // Filename for output
909  string file_root="unsteady_heat_1_4";
910 
911  // Compare output
912  output_both_versions(file_root,mesh_pt,nplot);
913 
914  delete mesh_pt;
915  }
916 
917 
918 
919  //--------------------------------------------------
920  {
921  // Build and assign mesh
922  Mesh* mesh_pt =
924 
925  // Filename for output
926  string file_root="unsteady_heat_2_2";
927 
928  // Compare output
929  output_both_versions(file_root,mesh_pt,nplot);
930 
931  delete mesh_pt;
932  }
933 
934  //--------------------------------------------------
935  {
936  // Build and assign mesh
937  Mesh* mesh_pt =
939 
940  // Filename for output
941  string file_root="unsteady_heat_2_3";
942 
943  // Compare output
944  output_both_versions(file_root,mesh_pt,nplot);
945 
946  delete mesh_pt;
947  }
948 
949 
950 
951  //--------------------------------------------------
952  {
953  // Build and assign mesh
954  Mesh* mesh_pt =
956 
957  // Filename for output
958  string file_root="unsteady_heat_2_4";
959 
960  // Compare output
961  output_both_versions(file_root,mesh_pt,nplot);
962 
963  delete mesh_pt;
964  }
965 
966 
967  //--------------------------------------------------
968  {
969  // Build and assign mesh
970  Mesh* mesh_pt =
972  <RefineableQUnsteadyHeatElement<2,2> >(n_x,n_y,l_x,l_y);
973 
974  // Filename for output
975  string file_root="adapt_unsteady_heat_2_2";
976 
977  // Compare output
978  output_both_versions(file_root,mesh_pt,nplot);
979 
980  delete mesh_pt;
981  }
982 
983 
984 
985  //--------------------------------------------------
986  {
987  // Build and assign mesh
988  Mesh* mesh_pt =
990  <RefineableQUnsteadyHeatElement<2,3> >(n_x,n_y,l_x,l_y);
991 
992  // Filename for output
993  string file_root="adapt_unsteady_heat_2_3";
994 
995  // Compare output
996  output_both_versions(file_root,mesh_pt,nplot);
997 
998  delete mesh_pt;
999  }
1000 
1001 
1002 
1003  //--------------------------------------------------
1004  {
1005  // Build and assign mesh
1006  Mesh* mesh_pt =
1008  <RefineableQUnsteadyHeatElement<2,4> >(n_x,n_y,l_x,l_y);
1009 
1010  // Filename for output
1011  string file_root="adapt_unsteady_heat_2_4";
1012 
1013  // Compare output
1014  output_both_versions(file_root,mesh_pt,nplot);
1015 
1016  delete mesh_pt;
1017  }
1018 
1019 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
MatrixXd L
Definition: LLT_example.cpp:6
void output_both_versions(const string &file_root, Mesh *mesh_pt, const unsigned &npts)
Global output function to compare C++ and C-style output routines.
Definition: c_style_output.cc:180
Definition: c_style_output.cc:76
Definition: mpi/distribution/hanging_node_reconciliation/hp_adaptive_driven_cavity.cc:63
Definition: geom_objects.h:644
Definition: geom_objects.h:1131
Definition: geom_objects.h:101
Definition: beam_elements.h:313
GeomObject *& undeformed_beam_pt()
Definition: beam_elements.h:253
Definition: mesh.h:67
GeneralisedElement *& element_pt(const unsigned long &e)
Return pointer to element e.
Definition: mesh.h:448
Definition: one_d_lagrangian_mesh.template.h:46
Definition: one_d_mesh.template.h:52
Definition: quarter_tube_mesh.template.h:65
Definition: refineable_solid_elements.h:826
Definition: refineable_solid_elements.h:436
Definition: refineable_unsteady_heat_elements.h:197
Definition: quarter_tube_mesh.template.h:162
Definition: simple_rectangular_quadmesh.template.h:58
Definition: geom_objects.h:452
Definition: timesteppers.h:231
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 atan(const bfloat16 &a)
Definition: BFloat16.h:636

◆ output_both_versions()

void output_both_versions ( const string &  file_root,
Mesh mesh_pt,
const unsigned npts 
)

Global output function to compare C++ and C-style output routines.

/////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////

182 {
183 
184 
185  cout << std::endl << "=============================================="
186  << std::endl << std::endl;
187 
188  cout << file_root << std::endl << std::endl;
189  DocInfo doc_info;
190  char filename[100];
191 
192  ofstream some_file;
193 
194  double total_time_old, total_time_new;
195 
196  // C style output
197  //-----------------
198  {
199  cout << "C style" << std::endl;
200  doc_info.set_directory("RESLT_C_style");
201 
202  // Output solution
203  sprintf(filename,"%s/%s.dat",doc_info.directory().c_str(),
204  file_root.c_str());
205  FILE* file_pt = fopen(filename,"w");
206  clock_t t_start = clock();
207  mesh_pt->output(file_pt,npts);
208  clock_t t_end = clock();
209  total_time_new=double(t_end-t_start)/CLOCKS_PER_SEC;
210  cout << "CPU time [sec]: "
211  << total_time_new << std::endl << std::endl;
212  fclose(file_pt);
213 
214 
215 
216  }
217  // C++ style output
218  //-----------------
219  {
220  cout << "C++ style" << std::endl;
221  doc_info.set_directory("RESLT_Cpp_style");
222 
223  // Output solution
224  sprintf(filename,"%s/%s.dat",doc_info.directory().c_str(),
225  file_root.c_str());
226  some_file.open(filename);
227  clock_t t_start = clock();
228  mesh_pt->output(some_file,npts);
229  clock_t t_end = clock();
230  total_time_old=double(t_end-t_start)/CLOCKS_PER_SEC;
231  cout << "CPU time [sec]: "
232  << total_time_old << std::endl << std::endl;
233  some_file.close();
234  }
235 
236  cout << " RATIO: " << total_time_old/total_time_new
237  << std::endl;
238 
239 }
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
void output(std::ostream &outfile)
Output for all elements.
Definition: mesh.cc:2027
string filename
Definition: MergeRestartFiles.py:39

References oomph::DocInfo::directory(), MergeRestartFiles::filename, oomph::Mesh::output(), and oomph::DocInfo::set_directory().

Referenced by ElasticRefineableQuarterCircleSectorMesh< ELEMENT >::ElasticRefineableQuarterCircleSectorMesh().