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_component_data(0).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_component_data(0).get() );
101 auto &id_node_vec = *( this->node_ids_->get_component_data(0).get() );
102 auto &connectivity_vec = *( this->connectivity_->get_component_data(0).get() );
103 auto &offsets_vec = *( this->offsets_->get_component_data(0).get() );
104 auto ®ions_vec = *( this->region_ids_->get_component_data(0).get() );
105 auto &partition_vec = *( this->partitions_->get_component_data(0).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 for(
unsigned int i=4*i_elm; i<4*i_elm+n_nodes; i++, i_node++) {
113 gmsh_connectivity[i] = connectivity_vec[i_node];
119 file <<
"$Elements" << endl;
120 file << this->offsets_->n_values()-1 << endl;
122 bool is_corner_output = (this->nodes_->n_values() != output_mesh_->orig_mesh_->node_permutations().size());
123 unsigned int gmsh_id;
124 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
125 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
126 unsigned int i_gmsh_elm = permutation_vec[i_elm];
127 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
129 if (is_corner_output) gmsh_id = i_elm;
130 else gmsh_id = id_elem_vec[i_gmsh_elm];
132 <<
" " << gmsh_simplex_types_[ n_nodes-1 ]
133 <<
" 3 " << regions_vec[i_gmsh_elm] <<
" " << regions_vec[i_gmsh_elm] <<
" " << partition_vec[i_gmsh_elm];
135 for(
unsigned int i=4*i_gmsh_elm; i<4*i_gmsh_elm+n_nodes; i++) {
136 file <<
" " << id_node_vec[gmsh_connectivity[i]];
140 file <<
"$EndElements" << endl;
148 ofstream &file = this->_base_file;
149 auto &id_vec = *( id_cache->get_component_data(0).get() );
151 for(
unsigned int i=0; i < output_data->n_values(); ++i) {
152 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);
190 file <<
"$EndNodeData" << endl;
196 ofstream &file = this->_base_file;
197 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
199 file <<
"$ElementNodeData" << endl;
202 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
205 file << time_fixed << endl;
208 file << this->current_step << endl;
209 file << output_data->n_comp() << endl;
210 file << this->offsets_->n_values()-1 << endl;
213 auto &id_vec = *( this->elem_ids_->get_component_data(0).get() );
214 auto &offsets_vec = *( this->offsets_->get_component_data(0).get() );
215 unsigned int n_nodes, i_corner;
216 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
217 for(
unsigned int i=0; i < id_vec.size(); ++i) {
218 unsigned int i_gmsh_elm = permutation_vec[i];
219 n_nodes = offsets_vec[i_gmsh_elm+1]-offsets_vec[i_gmsh_elm];
220 i_corner = offsets_vec[i_gmsh_elm];
221 file << id_vec[i] <<
" " << n_nodes <<
" ";
222 for (
unsigned int j=0; j<n_nodes; j++)
223 output_data->print_ascii(file, i_corner++);
227 file <<
"$EndElementNodeData" << endl;
232 ofstream &file = this->_base_file;
233 double time_fixed = isfinite(this->registered_time_)?this->registered_time_:0;
235 file <<
"$ElementData" << endl;
238 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
241 file << time_fixed << endl;
244 file << this->current_step << endl;
245 file << output_data->n_comp() << endl;
246 file << output_data->n_values() << endl;
248 auto permutation_vec = output_mesh_->orig_mesh_->element_permutations();
249 this->write_msh_ascii_data(this->elem_ids_, output_data, permutation_vec);
259 file <<
"$EndElementData" << endl;
264 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
266 this->write_msh_header();
268 this->write_msh_geometry();
270 this->write_msh_topology();
280 if (this->rank_ != 0) {
285 if(this->header_written ==
false) {
286 this->fix_main_file_extension(
".msh");
288 this->_base_filename.open_stream( this->_base_file );
289 this->set_stream_precision(this->_base_file);
290 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input_record_)
293 this->header_written =
true;
296 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
299 auto &node_data_list = this->output_data_vec_[NODE_DATA];
300 for(
auto data_it = node_data_list.begin(); data_it != node_data_list.end(); ++data_it) {
301 write_node_data(*data_it);
303 auto &corner_data_list = this->output_data_vec_[CORNER_DATA];
304 for(
auto data_it = corner_data_list.begin(); data_it != corner_data_list.end(); ++data_it) {
305 write_corner_data(*data_it);
307 auto &elem_data_list = this->output_data_vec_[ELEM_DATA];
308 for(
auto data_it = elem_data_list.begin(); data_it != elem_data_list.end(); ++data_it) {
309 write_elem_data(*data_it);
313 this->_base_file.flush();
331 mesh_ptr->get_master_mesh()->create_id_caches();
332 this->node_ids_ = mesh_ptr->get_master_mesh()->node_ids_;
333 this->elem_ids_ = mesh_ptr->get_master_mesh()->elem_ids_;
334 this->region_ids_ = mesh_ptr->get_master_mesh()->region_ids_;
335 this->partitions_ = mesh_ptr->get_master_mesh()->partitions_;