35 return Record(
"gmsh",
"Parameters of gmsh output format.")
47 this->enable_refinement_ =
false;
48 this->header_written =
false;
65 ofstream &file = this->_base_file;
68 file <<
"$MeshFormat" << endl;
69 file <<
"2" <<
" 0 " <<
sizeof(double) << endl;
70 file <<
"$EndMeshFormat" << endl;
75 ofstream &file = this->_base_file;
78 file <<
"$Nodes" << endl;
79 file << this->nodes_->n_values() << endl;
80 auto &id_node_vec = *( this->node_ids_->get_component_data(0).get() );
81 for(
unsigned int i_node=0; i_node < id_node_vec.size(); ++i_node) {
82 file << id_node_vec[i_node] <<
" ";
83 this->nodes_->print_ascii(file, i_node);
86 file <<
"$EndNodes" << endl;
91 ofstream &file = this->_base_file;
92 const static unsigned int gmsh_simplex_types_[4] = {0, 1, 2, 4};
93 auto &id_elem_vec = *( this->elem_ids_->get_component_data(0).get() );
94 auto &id_node_vec = *( this->node_ids_->get_component_data(0).get() );
95 auto &connectivity_vec = *( this->connectivity_->get_component_data(0).get() );
96 auto &offsets_vec = *( this->offsets_->get_component_data(0).get() );
97 auto ®ions_vec = *( this->region_ids_->get_component_data(0).get() );
98 auto &partition_vec = *( this->partitions_->get_component_data(0).get() );
100 unsigned int n_nodes, i_node=0;
103 file <<
"$Elements" << endl;
104 file << this->offsets_->n_values() << endl;
106 for(
unsigned int i_elm=0; i_elm < id_elem_vec.size(); ++i_elm) {
107 n_nodes = (i_elm==0) ? (offsets_vec[0]) : (offsets_vec[i_elm]-offsets_vec[i_elm-1]);
109 file << id_elem_vec[i_elm]
110 <<
" " << gmsh_simplex_types_[ n_nodes-1 ]
111 <<
" 3 " << regions_vec[i_elm] <<
" " << regions_vec[i_elm] <<
" " << partition_vec[i_elm];
113 for(
unsigned int i=0; i<n_nodes; i++, i_node++) {
114 file <<
" " << id_node_vec[connectivity_vec[i_node]];
118 file <<
"$EndElements" << endl;
124 ofstream &file = this->_base_file;
125 auto &id_vec = *( id_cache->get_component_data(0).get() );
128 auto &offsets_vec = *( this->offsets_->get_component_data(0).get() );
129 unsigned int n_nodes, i_corner=0;
130 for(
unsigned int i=0; i < id_vec.size(); ++i) {
131 n_nodes = (i==0) ? (offsets_vec[0]) : (offsets_vec[i]-offsets_vec[i-1]);
132 file << id_vec[i] <<
" " << n_nodes <<
" ";
133 for (
unsigned int j=0; j<n_nodes; j++)
134 output_data->print_ascii(file, i_corner++);
138 for(
unsigned int i=0; i < output_data->n_values(); ++i) {
139 file << id_vec[i] <<
" ";
140 output_data->print_ascii(file, i);
150 ofstream &file = this->_base_file;
151 double time_fixed = isfinite(this->time)?this->time:0;
154 file <<
"$NodeData" << endl;
157 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
160 file << time_fixed << endl;
163 file << this->current_step << endl;
164 file << output_data->n_comp() << endl;
165 file << output_data->n_values() << endl;
167 this->write_msh_ascii_data(this->node_ids_, output_data);
169 file <<
"$EndNodeData" << endl;
175 ofstream &file = this->_base_file;
176 double time_fixed = isfinite(this->time)?this->time:0;
178 file <<
"$ElementNodeData" << endl;
181 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
184 file << time_fixed << endl;
187 file << this->current_step << endl;
188 file << output_data->n_comp() << endl;
189 file << this->offsets_->n_values() << endl;
191 this->write_msh_ascii_data(this->elem_ids_, output_data,
true);
193 file <<
"$EndElementNodeData" << endl;
198 ofstream &file = this->_base_file;
199 double time_fixed = isfinite(this->time)?this->time:0;
201 file <<
"$ElementData" << endl;
204 file <<
"\"" << output_data->field_input_name() <<
"\"" << endl;
207 file << time_fixed << endl;
210 file << this->current_step << endl;
211 file << output_data->n_comp() << endl;
212 file << output_data->n_values() << endl;
214 this->write_msh_ascii_data(this->elem_ids_, output_data);
216 file <<
"$EndElementData" << endl;
221 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
223 this->write_msh_header();
225 this->write_msh_geometry();
227 this->write_msh_topology();
237 if (this->rank_ != 0) {
242 if(this->header_written ==
false) {
243 this->fix_main_file_extension(
".msh");
245 this->_base_filename.open_stream( this->_base_file );
246 this->set_stream_precision(this->_base_file);
247 }
INPUT_CATCH(FilePath::ExcFileOpen, FilePath::EI_Address_String, input_record_)
250 this->header_written =
true;
253 LogOut() << __func__ <<
": Writing output file " << this->_base_filename <<
" ... ";
256 auto &node_data_list = this->output_data_vec_[NODE_DATA];
257 for(
auto data_it = node_data_list.begin(); data_it != node_data_list.end(); ++data_it) {
258 write_node_data(*data_it);
260 auto &corner_data_list = this->output_data_vec_[CORNER_DATA];
261 for(
auto data_it = corner_data_list.begin(); data_it != corner_data_list.end(); ++data_it) {
262 write_corner_data(*data_it);
264 auto &elem_data_list = this->output_data_vec_[ELEM_DATA];
265 for(
auto data_it = elem_data_list.begin(); data_it != elem_data_list.end(); ++data_it) {
266 write_elem_data(*data_it);
270 this->_base_file.flush();
288 mesh_ptr->get_master_mesh()->create_id_caches();
289 this->node_ids_ = mesh_ptr->get_master_mesh()->node_ids_;
290 this->elem_ids_ = mesh_ptr->get_master_mesh()->elem_ids_;
291 this->region_ids_ = mesh_ptr->get_master_mesh()->region_ids_;
292 this->partitions_ = mesh_ptr->get_master_mesh()->partitions_;