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 unsigned int perm_idx;
145 ofstream &file = this->_base_file;
146 auto &id_vec = *( id_cache->get_data().get() );
148 bool is_corner_output = (this->nodes_->n_values() != output_mesh_->orig_mesh_->node_permutations().size());
149 bool permute_data = output_data->n_values() == permutations.size();
150 for(
unsigned int i=0; i < output_data->n_values(); ++i) {
152 if (is_corner_output) i_gmsh = i;
153 else i_gmsh = permutations[i];
155 if (permute_data) perm_idx = permutations[i];
158 file << id_vec[i_gmsh] <<
" ";
159 output_data->print_ascii(file, perm_idx);
167 ofstream &file = this->_base_file;
168 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
169 time_fixed /= this->time_unit_converter->get_coef();
171 file <<
"$NodeData" << endl;
174 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
177 file << time_fixed << endl;
180 file << this->current_step << endl;
181 file << output_data->n_comp() << endl;
182 file << output_data->n_values() << endl;
184 auto permutation_vec = output_mesh_->orig_mesh_->node_permutations();
185 this->write_msh_ascii_data(this->node_ids_, output_data, permutation_vec);
187 file <<
"$EndNodeData" << endl;
193 ofstream &file = this->_base_file;
194 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
196 file <<
"$ElementNodeData" << endl;
199 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
202 file << time_fixed << endl;
205 file << this->current_step << endl;
206 file << output_data->n_comp() << endl;
207 file << this->offsets_->n_values()-1 << endl;
210 auto &id_vec = *( this->elem_ids_->get_data().get() );
211 auto &offsets_vec = *( this->offsets_->get_data().get() );
212 unsigned int n_nodes, i_corner;
213 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
214 for(
unsigned int i=0; i < id_vec.size(); ++i) {
215 unsigned int i_gmsh_elm = permutation_vec[i];
216 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
217 i_corner = offsets_vec[i_gmsh_elm];
218 file << id_vec[i] <<
" " << n_nodes <<
" ";
219 for (
unsigned int j=0; j<n_nodes; j++)
220 output_data->print_ascii(file, i_corner++);
224 file <<
"$EndElementNodeData" << endl;
229 ofstream &file = this->_base_file;
230 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
232 file <<
"$ElementData" << endl;
235 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
238 file << time_fixed << endl;
241 file << this->current_step << endl;
242 file << output_data->n_comp() << endl;
243 file << output_data->n_values() << endl;
245 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
246 this->write_msh_ascii_data(this->elem_ids_, output_data, permutation_vec);
248 file <<
"$EndElementData" << endl;
253 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
255 this->write_msh_header();
257 this->write_msh_geometry();
259 this->write_msh_topology();
269 if (this->rank_ != 0) {
274 if(this->header_written ==
false) {
275 this->fix_main_file_extension(
".msh");
277 this->_base_filename.open_stream( this->_base_file );
278 this->set_stream_precision(this->_base_file);
279 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input_record_)
282 this->header_written =
true;
285 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
288 auto &node_data_list = this->output_data_vec_[NODE_DATA];
289 for(
auto data_it = node_data_list.begin(); data_it != node_data_list.end(); ++data_it) {
290 write_node_data(*data_it);
292 auto &corner_data_list = this->output_data_vec_[CORNER_DATA];
293 for(
auto data_it = corner_data_list.begin(); data_it != corner_data_list.end(); ++data_it) {
294 write_corner_data(*data_it);
296 auto &elem_data_list = this->output_data_vec_[ELEM_DATA];
297 for(
auto data_it = elem_data_list.begin(); data_it != elem_data_list.end(); ++data_it) {
298 write_elem_data(*data_it);
302 this->_base_file.flush();
320 mesh_ptr->get_master_mesh()->create_id_caches();
321 this->node_ids_ = mesh_ptr->get_master_mesh()->node_ids_;
322 this->elem_ids_ = mesh_ptr->get_master_mesh()->elem_ids_;
323 this->region_ids_ = mesh_ptr->get_master_mesh()->region_ids_;
324 this->partitions_ = mesh_ptr->get_master_mesh()->partitions_;