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 this->write_msh_ascii_data(this->node_ids_, this->nodes_, permutation_vec);
84 file <<
"$EndNodes" << endl;
89 ofstream &file = this->_base_file;
90 const static unsigned int gmsh_simplex_types_[4] = {0, 1, 2, 4};
91 auto &id_elem_vec = *( this->elem_ids_->get_data().get() );
92 auto &id_node_vec = *( this->node_ids_->get_data().get() );
93 auto &connectivity_vec = *( this->connectivity_->get_data().get() );
94 auto &offsets_vec = *( this->offsets_->get_data().get() );
95 auto ®ions_vec = *( this->region_ids_->get_data().get() );
96 auto &partition_vec = *( this->partitions_->get_data().get() );
98 unsigned int n_nodes, i_node=0;
101 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
102 n_nodes = offsets_vec[i_elm+1]-offsets_vec[i_elm];
103 auto &new_to_old_node = output_mesh_->orig_mesh_->element_accessor(i_elm).orig_nodes_order();
104 for(
unsigned int i=0; i<n_nodes; i++, i_node++) {
107 uint old_i = new_to_old_node[i];
108 gmsh_connectivity[4*i_elm+old_i] = connectivity_vec[i_node];
114 file <<
"$Elements" << endl;
115 file << this->offsets_->n_values()-1 << endl;
117 bool is_corner_output = (this->nodes_->n_values() != output_mesh_->orig_mesh_->node_permutations().size());
118 unsigned int i_gmsh_elm, gmsh_id;
119 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
120 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
121 i_gmsh_elm = permutation_vec[i_elm];
122 if (is_corner_output) gmsh_id = id_elem_vec[i_elm];
123 else gmsh_id = id_elem_vec[i_gmsh_elm];
125 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
128 <<
" " << gmsh_simplex_types_[ n_nodes-1 ]
129 <<
" 3 " << regions_vec[i_gmsh_elm] <<
" " << regions_vec[i_gmsh_elm] <<
" " << partition_vec[i_gmsh_elm];
131 for(
unsigned int i=4*i_gmsh_elm; i<4*i_gmsh_elm+n_nodes; i++) {
132 file <<
" " << id_node_vec[gmsh_connectivity[i]];
136 file <<
"$EndElements" << endl;
144 ofstream &file = this->_base_file;
145 auto &id_vec = *( id_cache->get_data().get() );
147 bool is_corner_output = (this->nodes_->n_values() != output_mesh_->orig_mesh_->node_permutations().size());
148 for(
unsigned int i=0; i < output_data->n_values(); ++i) {
150 if (is_corner_output) i_gmsh = i;
151 else i_gmsh = permutations[i];
153 file << id_vec[i_gmsh] <<
" ";
154 output_data->print_ascii(file, i_gmsh);
162 ofstream &file = this->_base_file;
163 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
164 time_fixed /= this->time_unit_converter->get_coef();
166 file <<
"$NodeData" << endl;
169 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
172 file << time_fixed << endl;
175 file << this->current_step << endl;
176 file << output_data->n_comp() << endl;
177 file << output_data->n_values() << endl;
179 auto permutation_vec = output_mesh_->orig_mesh_->node_permutations();
180 this->write_msh_ascii_data(this->node_ids_, output_data, permutation_vec);
182 file <<
"$EndNodeData" << endl;
188 ofstream &file = this->_base_file;
189 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
191 file <<
"$ElementNodeData" << endl;
194 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
197 file << time_fixed << endl;
200 file << this->current_step << endl;
201 file << output_data->n_comp() << endl;
202 file << this->offsets_->n_values()-1 << endl;
205 auto &id_vec = *( this->elem_ids_->get_data().get() );
206 auto &offsets_vec = *( this->offsets_->get_data().get() );
207 unsigned int n_nodes, i_corner;
208 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
209 for(
unsigned int i=0; i < id_vec.size(); ++i) {
210 unsigned int i_gmsh_elm = permutation_vec[i];
211 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
212 i_corner = offsets_vec[i_gmsh_elm];
213 file << id_vec[i] <<
" " << n_nodes <<
" ";
214 for (
unsigned int j=0; j<n_nodes; j++)
215 output_data->print_ascii(file, i_corner++);
219 file <<
"$EndElementNodeData" << endl;
224 ofstream &file = this->_base_file;
225 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
227 file <<
"$ElementData" << endl;
230 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
233 file << time_fixed << endl;
236 file << this->current_step << endl;
237 file << output_data->n_comp() << endl;
238 file << output_data->n_values() << endl;
240 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
241 this->write_msh_ascii_data(this->elem_ids_, output_data, permutation_vec);
243 file <<
"$EndElementData" << endl;
248 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
250 this->write_msh_header();
252 this->write_msh_geometry();
254 this->write_msh_topology();
264 if (this->rank_ != 0) {
269 if(this->header_written ==
false) {
270 this->fix_main_file_extension(
".msh");
272 this->_base_filename.open_stream( this->_base_file );
273 this->set_stream_precision(this->_base_file);
274 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input_record_)
277 this->header_written =
true;
280 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
283 auto &node_data_list = this->output_data_vec_[NODE_DATA];
284 for(
auto data_it = node_data_list.begin(); data_it != node_data_list.end(); ++data_it) {
285 write_node_data(*data_it);
287 auto &corner_data_list = this->output_data_vec_[CORNER_DATA];
288 for(
auto data_it = corner_data_list.begin(); data_it != corner_data_list.end(); ++data_it) {
289 write_corner_data(*data_it);
291 auto &elem_data_list = this->output_data_vec_[ELEM_DATA];
292 for(
auto data_it = elem_data_list.begin(); data_it != elem_data_list.end(); ++data_it) {
293 write_elem_data(*data_it);
297 this->_base_file.flush();
315 mesh_ptr->get_master_mesh()->create_id_caches();
316 this->node_ids_ = mesh_ptr->get_master_mesh()->node_ids_;
317 this->elem_ids_ = mesh_ptr->get_master_mesh()->elem_ids_;
318 this->region_ids_ = mesh_ptr->get_master_mesh()->region_ids_;
319 this->partitions_ = mesh_ptr->get_master_mesh()->partitions_;