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-2025 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>
34using namespace std;
35
36int 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
45ifstream infile(mesh_file_name.c_str(), ios_base::in);
46unsigned n_node;
47infile>>n_node;
48vector<double> x(n_node);
49vector<double> y(n_node);
50vector<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 }
57unsigned n_vx;
58infile>>n_vx;
59vector<int> nodecode(n_vx);
60vector<int> icurv(n_vx);
61vector<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 }
68unsigned n_local_node;
69infile>>n_local_node;
70unsigned n_element;
71infile>>n_element;
72unsigned b=n_local_node*n_element;
73vector<int> v(b);
74vector<int> edgeinfo(b);
75unsigned k=0;
76for(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 }
84unsigned l=0;
85for(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
94infile.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 snprintf(result, sizeof(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[])