7 #include <boost/foreach.hpp>
8 #include <boost/tokenizer.hpp>
9 #include <boost/regex.hpp>
46 using namespace common;
61 options().
add(
"part", PE::Comm::instance().rank() )
62 .description(
"Number of the part of the mesh to read. (e.g. rank of processor)")
65 options().
add(
"nb_parts", PE::Comm::instance().size() )
66 .description(
"Total number of parts. (e.g. number of processors)")
67 .pretty_name(
"nb_parts");
70 .description(
"Read the data from the mesh")
71 .pretty_name(
"Read Fields")
76 properties()[
"brief"] = std::string(
"Gmsh file reader component");
79 desc +=
"This component can read in parallel.\n";
80 desc +=
"It can also read multiple files in serial, combining them in one large mesh.\n";
81 desc +=
"Available coolfluid-element types are:\n";
83 desc +=
" - " + supported_type +
"\n";
93 std::vector<std::string> extensions;
94 extensions.push_back(
".msh");
104 boost::filesystem::path fp (file.
path());
105 if( boost::filesystem::exists(fp) )
108 m_file.open(fp,std::ios_base::in);
112 throw boost::filesystem::filesystem_error( fp.string() +
" does not exist", boost::system::error_code() );
136 if (
options().value<bool>(
"read_fields"))
162 std::string region_names(
"$PhysicalNames");
163 std::string
nodes(
"$Nodes");
164 std::string elements(
"$Elements");
165 std::string element_data(
"$ElementData");
166 std::string node_data(
"$NodeData");
167 std::string element_node_data(
"$ElementNodeData");
179 if (line.find(region_names)!=std::string::npos) {
195 Uint phys_group_dimensionality;
196 Uint phys_group_index;
197 std::string phys_group_name;
198 m_file >> phys_group_dimensionality >> phys_group_index >> phys_group_name;
199 m_region_list[phys_group_index-1].dim=phys_group_dimensionality;
202 m_region_list[phys_group_index-1].name=phys_group_name.substr(1,phys_group_name.length()-2);
207 else if (line.find(nodes)!=std::string::npos) {
213 else if (line.find(elements)!=std::string::npos)
220 m_hash = create_component<MergedParallelDistribution>(
"hash");
221 std::vector<Uint> num_obj(2);
224 m_hash->options().set(
"nb_parts",
options().value<Uint>(
"nb_parts"));
225 m_hash->options().set(
"nb_obj",num_obj);
228 Uint elem_idx, elem_type, nb_tags, phys_tag;
244 else if (line.find(element_data)!=std::string::npos)
248 else if (line.find(node_data)!=std::string::npos)
252 else if (line.find(element_node_data)!=std::string::npos)
269 typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
270 boost::char_separator<char> sep(
"/");
271 Tokenizer tokens(relative_path, sep);
274 for (Tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
276 std::string
name = *tok_iter;
302 Uint elementNumber, elementType, nbElementNodes;
303 Uint gmsh_node_number, nb_tags, phys_tag, other_tag;
324 m_file >> elementNumber >> elementType;
331 for(
Uint itag = 0; itag < (nb_tags-1); ++itag)
334 for (
Uint j=0; j<nbElementNodes; ++j)
336 m_file >> gmsh_node_number;
371 std::stringstream ss(line);
372 ss >> gmsh_node_number;
421 std::set<Uint>::const_iterator it;
424 Uint gmsh_node_number;
439 std::stringstream ss(line);
440 ss >> gmsh_node_number;
448 if(m_mesh_dimension <
DIM_3D) getline(ss,line);
450 nodes.
rank()[coord_idx] = part;
451 nodes.
glb_idx()[coord_idx] = gmsh_node_number-1;
460 std::stringstream ss(line);
461 ss >> gmsh_node_number;
469 if(m_mesh_dimension <
DIM_3D) getline(ss, line);
471 nodes.
rank()[coord_idx] =
m_hash->subhash(
NODES).part_of_obj(node_idx);
472 nodes.
glb_idx()[coord_idx] = gmsh_node_number-1;
511 std::vector<std::map<Uint, Entities* > > conn_table_idx;
515 conn_table_idx[ir].clear();
518 std::map<Uint, Entities*>::iterator elem_table_iter;
545 boost::shared_ptr< ElementType > allocated_type = build_component_abstract_type<ElementType>(cf_elem_name,
"tmp");
546 boost::shared_ptr< Entities > elements;
547 if (allocated_type->dimensionality() == allocated_type->dimension()-1)
548 elements = build_component_abstract_type<Entities>(
"cf3.mesh.Faces",
"elements_"+allocated_type->derived_type_name());
549 else if(allocated_type->dimensionality() == allocated_type->dimension())
550 elements = build_component_abstract_type<Entities>(
"cf3.mesh.Cells",
"elements_"+allocated_type->derived_type_name());
552 elements = build_component_abstract_type<Entities>(
"cf3.mesh.Elements",
"elements_"+allocated_type->derived_type_name());
553 region->add_component(elements);
554 elements->initialize(cf_elem_name,nodes);
561 conn_table_idx[ir].insert(std::pair<Uint,Entities*>(etype,elements.get()));
566 std::string etype_CF;
567 std::set<Uint>::const_iterator it;
568 std::vector<Uint> cf_element;
569 Uint element_number, gmsh_element_type, nb_element_nodes;
570 Uint gmsh_node_number, nb_tags, phys_tag, other_tag;
597 m_file >> element_number >> gmsh_element_type;
606 for(
Uint itag = 0; itag < (nb_tags-1); ++itag)
615 cf_element.resize(nb_element_nodes);
616 for (
Uint j=0; j<nb_element_nodes; ++j)
619 m_file >> gmsh_node_number;
621 cf_element[cf_idx] = cf_node_number;
628 elem_table_iter = conn_table_idx[phys_tag-1].find(gmsh_element_type);
632 Connectivity::Row element_nodes = elements_region->geometry_space().connectivity()[row_idx];
636 for(
Uint node = 0; node < nb_element_nodes; ++node)
638 element_nodes[node] = cf_element[node];
641 elements_region->rank()[row_idx] = part;
642 elements_region->glb_idx()[row_idx] = element_number-1;
675 std::map<std::string,Reader::Field> gmsh_fields;
679 m_file.seekg(element_node_data_position,std::ios::beg);
684 if (gmsh_fields.size())
706 dict = m_mesh->create_discontinuous_space(gmsh_field.
dict_name(),gmsh_field.
space_lib_name()).handle<Dictionary>();
721 Uint gmsh_nb_elem_nodes;
726 std::vector<Real> data(gmsh_field.
var_types[var]);
730 m_file >> gmsh_elem_idx >> gmsh_nb_elem_nodes;
735 boost::tie(elements,cf_idx) = it->second;
736 const Space& space = elements->space(*dict);
738 cf3_assert(elements->element_type().nb_nodes() == gmsh_nb_elem_nodes);
740 for (n=0; n<gmsh_nb_elem_nodes; ++
n)
743 for (d=0; d<data.size(); ++d)
754 for(
Uint v=var_begin;
v<var_end; ++
v)
755 field_data[
v] = data[d++];
787 std::map<std::string,Reader::Field>
fields;
791 m_file.seekg(element_data_position,std::ios::beg);
801 std::vector<std::string> var_types_str;
817 std::vector<Real> data(gmsh_field.
var_types[i]);
822 for (d=0; d<data.size(); ++d)
828 boost::tie(elements,cf_idx) = it->second;
833 for(
Uint v=var_begin;
v<var_end; ++
v)
834 field_data[
v] = data[d++];
864 std::map<std::string,Field>
fields;
868 m_file.seekg(node_data_position,std::ios::beg);
887 std::vector<Real> data(gmsh_field.
var_types[i]);
892 for (d=0; d<data.size(); ++d)
907 for(
Uint v=var_begin;
v<var_end; ++
v)
908 field_data[
v] = data[d++];
922 Uint nb_string_tags(0);
923 std::string var_name(
"field");
924 std::string field_name(
"field");
925 std::string interpolation_scheme(
"unknown");
926 Uint nb_real_tags(0);
928 Uint nb_integer_tags(0);
929 Uint field_time_step(0);
938 if (nb_string_tags > 0)
941 var_name = var_name.substr(1,var_name.length()-2);
942 field_name = var_name;
943 if (nb_string_tags > 1)
945 m_file >> interpolation_scheme;
946 std::string tmp = interpolation_scheme;
947 while(interpolation_scheme[0] ==
'"' && interpolation_scheme[interpolation_scheme.size()-1] !=
'"')
950 interpolation_scheme +=
" "+tmp;
953 if (nb_string_tags > 2)
956 field_name = field_name.substr(1,field_name.length()-2);
959 if (nb_string_tags > 3)
961 for (
Uint i=2; i<nb_string_tags; ++i)
971 if (nb_real_tags > 0)
973 if (nb_real_tags != 1)
980 m_file >> nb_integer_tags;
981 if (nb_integer_tags > 0)
983 if (nb_integer_tags >= 3)
985 m_file >> field_time_step >> var_type >> nb_entries;
987 if (nb_integer_tags < 3)
988 throw ParsingFailed(
FromHere(),
"Data must have 3 integer tags (time_step, variable_type, nb_entries)");
992 Field& field = fields[field_name];
993 field.
name=field_name;
997 field.
time=field_time;
1002 CFdebug <<
" - found variable " << var_name <<
" from discontinuous field " << field_name <<
" at time " << field_time <<
CFendl;
1016 std::vector<Uint> tmp_nodes(nb_nodes_per_elem);
1020 if (jacobian_determinant < 0)
1023 for (
Uint n=0;
n<nb_nodes_per_elem; ++
n)
1048 const boost::regex pattern(
"([[:word:]]+)([[:space:]]+\\[(.*)\\])?");
1049 boost::match_results<std::string::const_iterator> what;
1059 if (interpolation_scheme ==
"unknown")
1062 const boost::regex pattern(
"([[:word:]]+)([[:space:]]+\\[(.*)\\])?");
1063 boost::match_results<std::string::const_iterator> what;
1064 if (boost::regex_search(interpolation_scheme,what,pattern))
1066 if ( std::string(what[3]).empty() )
return "unknown";
#define CFinfo
these are always defined
const ShapeFunction & shape_function() const
std::string name(ComponentWrapper &self)
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
std::string space_lib_name() const
boost::proto::terminal< SFOp< JacobianDeterminantOp > >::type const jacobian_determinant
std::vector< std::streampos > m_element_node_data_positions
std::string var_name(Uint i=0) const
std::streampos m_coordinates_position
bool is_null(T ptr)
predicate for comparison to nullptr
Helper class to create the Builder and place it in the factory.
Space & geometry_space() const
virtual Real jacobian_determinant(const RealVector &mapped_coord, const RealMatrix &nodes) const =0
virtual const RealMatrix & local_coordinates() const =0
Handle< MergedParallelDistribution > m_hash
virtual std::string derived_type_name() const =0
ElementType & element_type() const
return the elementType
Handle< Region > create_region(std::string const &relative_path)
common::List< Uint > & rank()
Return the rank of every field row.
#define boost_foreach
lowercase version of BOOST_FOREACH
const std::string & name() const
Access the name of the component.
const Field & coordinates() const
#define foreach_container(VARS, COL)
boost_foreach version that allows to use std::map's, boost::tuple's, std::pair's internal variables ...
Conversions from and to std::string.
Real max(const Real a, const Real b)
Maximum between two scalars.
static const Uint m_nodes_in_gmsh_elem[nb_gmsh_types]
Real e()
Definition of the Unit charge [C].
std::streampos m_region_names_position
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
std::string m_file_basename
boost::filesystem::fstream m_file
common::Libraries & libraries() const
Reader(const std::string &name)
constructor
std::string description() const
static std::string gmsh_name_to_cf_name(const Uint dim, const Uint gmsh_type)
void get_file_positions()
Uint size() const
return the number of elements
std::map< Uint, std::pair< Handle< Elements >, Uint > > m_elem_idx_gmsh_to_cf
std::vector< std::string > m_supported_types
PropertyList & properties()
std::string interpolation_scheme
Handle< Region > m_region
ComponentIterator class, can linearize a complete tree of components
const Handle< Space const > & space(const Handle< Entities const > &entities) const
Handle< Component > get_child(const std::string &name)
std::vector< std::streampos > m_node_data_positions
VarType var_length(const std::string &vname) const
Return the length (in number of Real values occupied in the data row) of the variable of the given na...
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
std::vector< std::vector< Uint > > m_nodes_gmsh_to_cf
common::List< Uint > & glb_idx()
Return the global index of every field row.
static const Uint nb_gmsh_types
std::vector< std::string > var_names
void read_element_node_data()
RealMatrix get_coordinates(const Uint elem_idx) const
Lookup element coordinates.
TableRow< Uint >::type Row
the type of a row in the internal structure of the table
std::vector< std::streampos > m_element_data_positions
std::set< Uint > m_ghost_nodes
std::string dict_name() const
LoadBalance::LoadBalance(const std::string &name) std::string desc
std::set< Uint > m_used_nodes
std::vector< URI > fields
void set_row_size(const Uint nb_cols)
boost::shared_ptr< Component > remove_component(const std::string &name)
Remove a (sub)component of this component.
unsigned int Uint
typedef for unsigned int
Handle< Library > autoload_library_with_namespace(const std::string &libnamespace)
Uint var_offset(const std::string &vname) const
Return the start index of a given variable.
std::vector< Uint > var_types
std::vector< std::vector< Uint > > m_nb_gmsh_elem_in_region
void read_variable_header(std::map< std::string, Field > &fields)
virtual void do_read_mesh_into(const common::URI &fp, Mesh &mesh)
void resize(const Uint size)
Resize the contained fields.
std::vector< RegionData > m_region_list
std::map< Uint, Uint > m_node_idx_gmsh_to_cf
cf3::common::ComponentBuilder< gmsh::Reader, MeshReader, LibGmsh > aGmshReader_Builder
Region & topology() const
Handle< Component > handle()
Get a handle to the component.
virtual std::vector< std::string > get_extensions()
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Base class for defining CF components.
void fix_negative_volumes(Mesh &mesh)
Connectivity & connectivity()
connectivity table to dictionary entries
std::streampos m_elements_position
bool is_not_null(T ptr)
predicate for comparison to nullptr
std::vector< std::streampos > file_data_positions
virtual void resize(const Uint nb_rows)