convert_geom_file.cc
Go to the documentation of this file.
1 //LIC// ====================================================================
2 //LIC// This file forms part of oomph-lib, the object-oriented,
3 //LIC// multi-physics finite-element library, available
4 //LIC// at http://www.oomph-lib.org.
5 //LIC//
6 //LIC// Copyright (C) 2006-2024 Matthias Heil and Andrew Hazel
7 //LIC//
8 //LIC// This library is free software; you can redistribute it and/or
9 //LIC// modify it under the terms of the GNU Lesser General Public
10 //LIC// License as published by the Free Software Foundation; either
11 //LIC// version 2.1 of the License, or (at your option) any later version.
12 //LIC//
13 //LIC// This library is distributed in the hope that it will be useful,
14 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 //LIC// Lesser General Public License for more details.
17 //LIC//
18 //LIC// You should have received a copy of the GNU Lesser General Public
19 //LIC// License along with this library; if not, write to the Free Software
20 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 //LIC// 02110-1301 USA.
22 //LIC//
23 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 //LIC//
25 //LIC//====================================================================
26 // Create an output file that can be read with geomview
27 // Change the infile name and the output name to use it
28 
29 
30 #include<iostream>
31 #include<fstream>
32 #include<vector>
33 #include<math.h>
34 using namespace std;
35 
36 int main(int argc, char* argv[])
37  {
38 
39  // Convert argument to strings that specify the input file name
40  string mesh_file_name(argv[1]);
41 
42 // Read the output mesh file to find informations about the nodes
43 // and elements of the mesh
44 
45 ifstream infile(mesh_file_name.c_str(), ios_base::in);
46 unsigned n_node;
47 infile>>n_node;
48 vector<double> x(n_node);
49 vector<double> y(n_node);
50 vector<int> vertinfo(n_node);
51  for(unsigned i=0;i<n_node;i++)
52  {
53  infile>>x[i];
54  infile>>y[i];
55  infile>>vertinfo[i];
56  }
57 unsigned n_vx;
58 infile>>n_vx;
59 vector<int> nodecode(n_vx);
60 vector<int> icurv(n_vx);
61 vector<double> ucurv(n_vx);
62  for(unsigned i=0;i<n_vx;i++)
63  {
64  infile>>nodecode[i];
65  infile>>icurv[i];
66  infile>>ucurv[i];
67  }
68 unsigned n_local_node;
69 infile>>n_local_node;
70 unsigned n_element;
71 infile>>n_element;
72 unsigned b=n_local_node*n_element;
73 vector<int> v(b);
74 vector<int> edgeinfo(b);
75 unsigned k=0;
76 for(unsigned i=0;i<n_element;i++)
77  {
78  for(unsigned j=0;j<n_local_node;j++)
79  {
80  infile>>v[k];
81  k++;
82  }
83  }
84 unsigned l=0;
85 for(unsigned i=0;i<n_element;i++)
86  {
87  for(unsigned j=0;j<n_local_node;j++)
88  {
89  infile>>edgeinfo[l];
90  l++;
91  }
92  }
93 
94 infile.close();
95 
96 // Create a file of type ".quad" to visualize the mesh with geomview
97 
98 
99  unsigned nn=0;
100  char result[20];
101  sprintf(result,"%s","mesh.quad");
102  ofstream outfile(result,ios_base::out);
103  outfile<<"QUAD"<<'\n';
104  for(unsigned i=0;i<n_element;i++)
105  {
106  for(unsigned j=0;j<n_local_node;j++)
107  {
108  outfile<<x[v[nn]-1]<<" "<<y[v[nn]-1]<<" 0 ";
109  nn++;
110  }
111  outfile<<'\n';
112  }
113  outfile.close();
114 
115 
116 
117 } //end of main
int main(int argc, char *argv[])