Flow123d  jenkins-Flow123d-windows32-release-multijob-51
output_msh.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id: output_msh.cc 2505 2013-09-13 14:52:27Z jiri.hnidek $
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file output_msh.cc
26  * @brief The functions for outputs to GMSH files.
27  *
28  */
29 
30 #include "io/output.h"
31 #include "io/output_msh.h"
32 #include "system/xio.h"
33 #include "mesh/mesh.h"
34 
35 
36 using namespace Input::Type;
37 
39  = Record("gmsh", "Parameters of gmsh output format.")
40  // It is derived from abstract class
42 
43 
45 {
46  ofstream &file = this->get_base_file();
47 
48  // Write simple header
49  file << "$MeshFormat" << endl;
50  file << "2" << " 0 " << sizeof(double) << endl;
51  file << "$EndMeshFormat" << endl;
52 }
53 
55 {
56  ofstream &file = this->get_base_file();
57  Mesh* mesh = this->get_mesh();
58 
59  // Write information about nodes
60  file << "$Nodes" << endl;
61  file << mesh->node_vector.size() << endl;
62  FOR_NODES(mesh, nod) {
63  file << NODE_FULL_ITER(mesh, nod).id() << " " << nod->getX() << " " << nod->getY() << " " << nod->getZ() << endl;
64  }
65  file << "$EndNodes" << endl;
66 }
67 
69 {
70  ofstream &file = this->get_base_file();
71  Mesh* mesh = this->get_mesh();
72  unsigned int i;
73  const static unsigned int gmsh_simplex_types_[4] = {0, 1, 2, 4};
74 
75  // Write information about elements
76  file << "$Elements" << endl;
77  file << mesh->n_elements() << endl;
78  FOR_ELEMENTS(mesh, elm) {
79  // element_id element_type 3_other_tags material region partition
80  file << ELEM_FULL_ITER(mesh, elm).id()
81  << " " << gmsh_simplex_types_[ elm->dim() ]
82  << " 3 " << elm->region().id() << " " << elm->region().id() << " " << elm->pid;
83 
84  FOR_ELEMENT_NODES(elm, i)
85  file << " " << NODE_FULL_ITER(mesh, elm->node[i]).id();
86  file << endl;
87  }
88  file << "$EndElements" << endl;
89 }
90 
91 
92 template<class element>
94 {
95  ofstream &file = this->get_base_file();
96 
97  /* Set precision to max */
98  //file.precision(std::numeric_limits<float>::digits10);
99  file.precision(std::numeric_limits<double>::digits10);
100 
101 
102  for(unsigned int i=0; i < output_data->n_values; i ++) {
103  file << vec(i).id() << " ";
104  output_data->print(file, i);
105  file << std::endl;
106  }
107 
108 }
109 
110 
112 {
113  Mesh *mesh = this->get_mesh();
114  ofstream &file = this->get_base_file();
115 
116  /* Set precision to max */
117  //file.precision(std::numeric_limits<float>::digits10);
118  file.precision(std::numeric_limits<double>::digits10);
119 
120  /* Write ascii data */
121  unsigned int i_node;
122  unsigned int i_corner=0;
123  FOR_ELEMENTS(mesh, ele) {
124  file << ele.id() << " " << ele->n_nodes() << " ";
125 
126  FOR_ELEMENT_NODES(ele, i_node) {
127  output_data->print(file, i_corner++);
128  }
129 
130  file << std::endl;
131  }
132 }
133 
134 
135 void OutputMSH::write_msh_node_data(double time, int step)
136 {
137  ofstream &file = this->get_base_file();
138  Mesh *mesh = this->get_mesh();
139  OutputDataBase *output_data;
140 
141  double time_fixed = isfinite(time)?time:0;
142 
143  if(this->node_data.empty() == false) {
144  for(vector<OutputDataBase*>::iterator data = this->node_data.begin();
145  data != this->node_data.end();
146  ++data)
147  {
148  output_data = *data;
149 
150  file << "$NodeData" << endl;
151 
152  file << "1" << endl; // one string tag
153  file << "\"" << output_data->output_field_name <<"\"" << endl;
154 
155  file << "1" << endl; // one real tag
156  file << time_fixed << endl; // first real tag = time
157 
158  file << "3" << endl; // 3 integer tags
159  file << step << endl; // step number (start = 0)
160  file << output_data->n_elem_ << endl; // number of components
161  file << output_data->n_values << endl; // number of values
162 
163  this->write_msh_ascii_cont_data(mesh->node_vector, output_data);
164 
165  file << "$EndNodeData" << endl;
166  }
167  } else if(this->corner_data.empty() == false) {
168  for(vector<OutputDataBase*>::iterator data = this->corner_data.begin();
169  data != this->corner_data.end();
170  ++data)
171  {
172  output_data = *data;
173 
174  file << "$ElementNodeData" << endl;
175 
176  file << "1" << endl; // one string tag
177  file << "\"" << output_data->output_field_name <<"\"" << endl;
178 
179  file << "1" << endl; // one real tag
180  file << time_fixed << endl; // first real tag = time
181 
182  file << "3" << endl; // 3 integer tags
183  file << step << endl; // step number (start = 0)
184  file << output_data->n_elem_ << endl; // number of components
185  file << mesh->n_elements() << endl; // number of values
186 
187  this->write_msh_ascii_discont_data(output_data);
188 
189  file << "$EndElementNodeData" << endl;
190  }
191  }
192 }
193 
194 void OutputMSH::write_msh_elem_data(double time, int step)
195 {
196  OutputDataBase* output_data;
197  ofstream &file = this->get_base_file();
198 
199  double time_fixed = isfinite(time)?time:0;
200 
201  if(this->elem_data.empty() == false) {
202  for(vector<OutputDataBase*>::iterator data = this->elem_data.begin();
203  data != this->elem_data.end();
204  ++data)
205  {
206  output_data = *data;
207  file << "$ElementData" << endl;
208 
209  file << "1" << endl; // one string tag
210  file << "\"" << output_data->output_field_name <<"\"" << endl;
211 
212  file << "1" << endl; // one real tag
213  file << time_fixed << endl; // first real tag = time
214 
215  file << "3" << endl; // 3 integer tags
216  file << step << endl; // step number (start = 0)
217  file << output_data->n_elem_ << endl; // number of components
218  file << output_data->n_values << endl; // number of values
219 
220  this->write_msh_ascii_cont_data(this->get_mesh()->element, output_data);
221 
222  file << "$EndElementData" << endl;
223  }
224  }
225 }
226 
228 {
229  xprintf(MsgLog, "%s: Writing output file %s ... ", __func__, this->base_filename()->c_str());
230 
231  this->write_msh_header();
232 
233  this->write_msh_geometry();
234 
235  this->write_msh_topology();
236 
237  xprintf(MsgLog, "O.K.\n");
238 
239  return 1;
240 }
241 
243 {
244  xprintf(MsgLog, "%s: Writing output file %s ... ", __func__, this->base_filename()->c_str());
245 
246  // Write header with mesh, when it hasn't been written to output file yet
247  if(this->header_written == false) {
248  this->write_head();
249  this->header_written = true;
250  }
251 
252  this->write_msh_node_data(this->time, this->current_step);
253  this->write_msh_elem_data(this->time, this->current_step);
254 
255  // Flush stream to be sure everything is in the file now
256  this->get_base_file().flush();
257 
258  xprintf(MsgLog, "O.K.\n");
259 
260  return 1;
261 }
262 
264 {
265  return 1;
266 }
267 
269 {
271  this->header_written = false;
272 }
273 
275 {
276  this->write_tail();
277 }
278 
void write_msh_header(void)
This function write header of GMSH (.msh) file format.
Definition: output_msh.cc:44
Common parent class for templated OutputData.
static Input::Type::AbstractRecord input_format_type
The specification of output file format.
Definition: output_time.hh:62
void write_msh_elem_data(double time, int step)
This function write all data on elements to output file. This function is used for static and dynamic...
Definition: output_msh.cc:194
#define FOR_ELEMENT_NODES(i, j)
Definition: elements.h:150
Header: The functions for all outputs.
#define NODE_FULL_ITER(_mesh_, i)
Definition: mesh.h:79
OutputMSH()
The constructor of this class.
std::string output_field_name
#define FOR_ELEMENTS(_mesh_, __i)
Definition: mesh.h:357
void write_msh_geometry(void)
This function writes geometry (position of nodes) to GMSH (.msh) file format.
Definition: output_msh.cc:54
#define ELEM_FULL_ITER(_mesh_, i)
Definition: mesh.h:91
int write_tail(void)
This method should write tail of GMSH (.msh) file format.
Definition: output_msh.cc:263
Small extension of Vector container with support to Id numbers.
Definition: sys_vector.hh:164
static Input::Type::Record input_type
The definition of input record for gmsh file format.
Definition: output_msh.h:59
???
Definition: mesh.h:108
Record & derive_from(AbstractRecord &parent)
Definition: type_record.cc:169
unsigned int n_values
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
Definition: system.hh:72
void write_msh_ascii_cont_data(flow::VectorId< element > &vec, OutputDataBase *output_data)
This function writes continuous ascii data to GMSH (.msh) output file.
Definition: output_msh.cc:93
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
Definition: sys_vector.hh:401
unsigned int n_elements() const
Definition: mesh.h:137
void write_msh_topology(void)
This function writes topology (connection of nodes) to the GMSH (.msh) file format.
Definition: output_msh.cc:68
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
#define xprintf(...)
Definition: system.hh:100
Header: The functions for MSH (GMSH) outputs.
void write_msh_ascii_discont_data(OutputDataBase *output_data)
This function writes discontinuous ascii data to GMSH (.msh) output file.
Definition: output_msh.cc:111
bool header_written
Definition: output_msh.h:91
void write_msh_node_data(double time, int step)
This function write all data on nodes to output file. This function is used for static and dynamic da...
Definition: output_msh.cc:135
~OutputMSH()
The destructor of this class.
Definition: output_msh.cc:274
The class for outputing data during time.
Definition: output_time.hh:37
#define FOR_NODES(_mesh_, i)
Definition: mesh.h:71
OutFileFormat file_format
Definition: output_time.hh:263
int write_data(void)
This method writes data to GMSH (.msh) file format for current time.
Definition: output_msh.cc:242
Record type proxy class.
Definition: type_record.hh:161
int write_head(void)
This method writes head of GMSH (.msh) file format.
Definition: output_msh.cc:227
virtual void print(ostream &out_stream, unsigned int idx)=0
NodeVector node_vector
Vector of nodes of the mesh.
Definition: mesh.h:196