34 return Record(
"gmsh",
"Parameters of gmsh output format.")
46 this->enable_refinement_ =
false;
47 this->header_written =
false;
57 this->write_time_frame();
67 ofstream &file = this->_base_file;
70 file <<
"$MeshFormat" << endl;
71 file <<
"2" <<
" 0 " <<
sizeof(double) << endl;
72 file <<
"$EndMeshFormat" << endl;
77 ofstream &file = this->_base_file;
80 file <<
"$Nodes" << endl;
81 file << this->nodes_->n_values() << endl;
82 auto permutation_vec = output_mesh_->orig_mesh_->node_permutations();
83 bool is_corner_output = (this->nodes_->n_values() != permutation_vec.size());
84 unsigned int i_gmsh_node;
85 auto &id_node_vec = *( this->node_ids_->get_data().get() );
86 for(
unsigned int i_node=0; i_node < id_node_vec.size(); ++i_node) {
87 if (is_corner_output) i_gmsh_node = i_node;
88 else i_gmsh_node = permutation_vec[i_node];
89 file << id_node_vec[i_gmsh_node] <<
" ";
90 this->nodes_->print_ascii(file, i_gmsh_node);
93 file <<
"$EndNodes" << endl;
98 ofstream &file = this->_base_file;
99 const static unsigned int gmsh_simplex_types_[4] = {0, 1, 2, 4};
100 auto &id_elem_vec = *( this->elem_ids_->get_data().get() );
101 auto &id_node_vec = *( this->node_ids_->get_data().get() );
102 auto &connectivity_vec = *( this->connectivity_->get_data().get() );
103 auto &offsets_vec = *( this->offsets_->get_data().get() );
104 auto ®ions_vec = *( this->region_ids_->get_data().get() );
105 auto &partition_vec = *( this->partitions_->get_data().get() );
107 unsigned int n_nodes, i_node=0;
110 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
111 n_nodes = offsets_vec[i_elm+1]-offsets_vec[i_elm];
112 auto &new_to_old_node = output_mesh_->orig_mesh_->element_accessor(i_elm).orig_nodes_order();
113 for(
unsigned int i=0; i<n_nodes; i++, i_node++) {
116 uint old_i = new_to_old_node[i];
117 gmsh_connectivity[4*i_elm+old_i] = connectivity_vec[i_node];
123 file <<
"$Elements" << endl;
124 file << this->offsets_->n_values()-1 << endl;
126 bool is_corner_output = (this->nodes_->n_values() != output_mesh_->orig_mesh_->node_permutations().size());
127 unsigned int gmsh_id;
128 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
129 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
130 unsigned int i_gmsh_elm = permutation_vec[i_elm];
131 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
133 if (is_corner_output) gmsh_id = i_elm;
134 else gmsh_id = id_elem_vec[i_gmsh_elm];
136 <<
" " << gmsh_simplex_types_[ n_nodes-1 ]
137 <<
" 3 " << regions_vec[i_gmsh_elm] <<
" " << regions_vec[i_gmsh_elm] <<
" " << partition_vec[i_gmsh_elm];
139 for(
unsigned int i=4*i_gmsh_elm; i<4*i_gmsh_elm+n_nodes; i++) {
140 file <<
" " << id_node_vec[gmsh_connectivity[i]];
144 file <<
"$EndElements" << endl;
152 ofstream &file = this->_base_file;
153 auto &id_vec = *( id_cache->get_data().get() );
155 for(
unsigned int i=0; i < output_data->n_values(); ++i) {
156 i_gmsh = permutations[i];
157 file << id_vec[i_gmsh] <<
" ";
158 output_data->print_ascii(file, i_gmsh);
166 ofstream &file = this->_base_file;
167 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
168 time_fixed /= this->time_unit_converter->get_coef();
170 file <<
"$NodeData" << endl;
173 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
176 file << time_fixed << endl;
179 file << this->current_step << endl;
180 file << output_data->n_comp() << endl;
181 file << output_data->n_values() << endl;
183 auto permutation_vec = output_mesh_->orig_mesh_->node_permutations();
184 this->write_msh_ascii_data(this->node_ids_, output_data, permutation_vec);
194 file <<
"$EndNodeData" << endl;
200 ofstream &file = this->_base_file;
201 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
203 file <<
"$ElementNodeData" << endl;
206 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
209 file << time_fixed << endl;
212 file << this->current_step << endl;
213 file << output_data->n_comp() << endl;
214 file << this->offsets_->n_values()-1 << endl;
217 auto &id_vec = *( this->elem_ids_->get_data().get() );
218 auto &offsets_vec = *( this->offsets_->get_data().get() );
219 unsigned int n_nodes, i_corner;
220 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
221 for(
unsigned int i=0; i < id_vec.size(); ++i) {
222 unsigned int i_gmsh_elm = permutation_vec[i];
223 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
224 i_corner = offsets_vec[i_gmsh_elm];
225 file << id_vec[i] <<
" " << n_nodes <<
" ";
226 for (
unsigned int j=0; j<n_nodes; j++)
227 output_data->print_ascii(file, i_corner++);
231 file <<
"$EndElementNodeData" << endl;
236 ofstream &file = this->_base_file;
237 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
239 file <<
"$ElementData" << endl;
242 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
245 file << time_fixed << endl;
248 file << this->current_step << endl;
249 file << output_data->n_comp() << endl;
250 file << output_data->n_values() << endl;
252 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
253 this->write_msh_ascii_data(this->elem_ids_, output_data, permutation_vec);
263 file <<
"$EndElementData" << endl;
268 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
270 this->write_msh_header();
272 this->write_msh_geometry();
274 this->write_msh_topology();
284 if (this->rank_ != 0) {
289 if(this->header_written ==
false) {
290 this->fix_main_file_extension(
".msh");
292 this->_base_filename.open_stream( this->_base_file );
293 this->set_stream_precision(this->_base_file);
294 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input_record_)
297 this->header_written =
true;
300 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
303 auto &node_data_list = this->output_data_vec_[NODE_DATA];
304 for(
auto data_it = node_data_list.begin(); data_it != node_data_list.end(); ++data_it) {
305 write_node_data(*data_it);
307 auto &corner_data_list = this->output_data_vec_[CORNER_DATA];
308 for(
auto data_it = corner_data_list.begin(); data_it != corner_data_list.end(); ++data_it) {
309 write_corner_data(*data_it);
311 auto &elem_data_list = this->output_data_vec_[ELEM_DATA];
312 for(
auto data_it = elem_data_list.begin(); data_it != elem_data_list.end(); ++data_it) {
313 write_elem_data(*data_it);
317 this->_base_file.flush();
335 mesh_ptr->get_master_mesh()->create_id_caches();
336 this->node_ids_ = mesh_ptr->get_master_mesh()->node_ids_;
337 this->elem_ids_ = mesh_ptr->get_master_mesh()->elem_ids_;
338 this->region_ids_ = mesh_ptr->get_master_mesh()->region_ids_;
339 this->partitions_ = mesh_ptr->get_master_mesh()->partitions_;