tmp
This commit is contained in:
parent
c3b2701bba
commit
4aaea1cf33
108
lib/io/gmsh_io.h
108
lib/io/gmsh_io.h
@ -65,6 +65,7 @@ namespace gctl
|
||||
|
||||
template <typename A> void read_node(array<vertex<point2dc, A>> &out_nodes);
|
||||
template <typename A> void read_node(array<vertex<point3dc, A>> &out_nodes);
|
||||
template <typename E, typename A> void read_element(array<type_edge2d<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag = nullptr);
|
||||
template <typename E, typename A> void read_element(array<type_triangle2d<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag = nullptr);
|
||||
template <typename E, typename A> void read_element(array<type_triangle2d2o<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag = nullptr);
|
||||
template <typename E, typename A> void read_element(array<type_rectangle2d<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag = nullptr);
|
||||
@ -151,6 +152,14 @@ namespace gctl
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename E, typename A>
|
||||
void gmshio::read_element(array<type_edge2d<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag)
|
||||
{
|
||||
initialized(Input);
|
||||
read_gmsh_element(gmsh_in, out_elements, nodes, in_packed, ele_tag);
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename E, typename A>
|
||||
void gmshio::read_element(array<type_triangle2d<E>> &out_elements, const array<vertex<point2dc, A>> &nodes, _2i_vector *ele_tag)
|
||||
{
|
||||
@ -1135,6 +1144,105 @@ namespace gctl
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read element index from a Gmsh file.
|
||||
*
|
||||
* @param[in] infile The input file stream
|
||||
* @param element The output element object array
|
||||
* @param node The node array
|
||||
* @param[in] packed Indicates whether the index in the node file starts from zero. The
|
||||
* index is deemed to be started with one if this option is false. The default value of this
|
||||
* variable is true.
|
||||
* @param[in] ele_tag Return elements' tags by a 2D integer vector.
|
||||
*
|
||||
*/
|
||||
template <typename E, typename A>
|
||||
void read_gmsh_element(std::ifstream &infile, array<type_edge2d<E>> &element,
|
||||
const array<vertex<point2dc, A>> &node, index_packed_e packed = Packed,
|
||||
_2i_vector *ele_tag = nullptr)
|
||||
{
|
||||
if (node.empty())
|
||||
throw runtime_error("The input array is empty. From gctl::read_gmsh_element(...)");
|
||||
|
||||
// 重置数据
|
||||
if (!element.empty()) element.clear();
|
||||
// 重置标签
|
||||
if (ele_tag != nullptr && !ele_tag->empty()) ele_tag->clear();
|
||||
|
||||
// 将文件指针重置到文件头
|
||||
infile.clear(std::ios::goodbit);
|
||||
infile.seekg(std::ios::beg);
|
||||
|
||||
int i_size = 0, ele_count = 0;
|
||||
int tmp_int, ele_type, attri_num;
|
||||
int tmp_index[2];
|
||||
std::string tmp_str;
|
||||
std::stringstream tmp_ss;
|
||||
while(getline(infile,tmp_str))
|
||||
{
|
||||
if (tmp_str == "$Elements") //读入模型空间顶点集 msh文件版本为2.2
|
||||
{
|
||||
getline(infile,tmp_str);
|
||||
gctl::str2ss(tmp_str, tmp_ss);
|
||||
tmp_ss >> i_size; //第一个数为顶点的个数
|
||||
|
||||
// 我们先用一个临时的向量来储存元素
|
||||
edge2d tmp_edge;
|
||||
std::vector<edge2d> element_vec;
|
||||
std::vector<int> tmp_tag;
|
||||
|
||||
for (int i = 0; i < i_size; i++)
|
||||
{
|
||||
getline(infile,tmp_str);
|
||||
str2ss(tmp_str, tmp_ss);
|
||||
tmp_ss >> tmp_int >> ele_type >> attri_num;
|
||||
if (ele_type == 1)
|
||||
{
|
||||
tmp_edge.id = ele_count;
|
||||
|
||||
tmp_tag.clear();
|
||||
for (int a = 0; a < attri_num; a++)
|
||||
{
|
||||
tmp_ss >> tmp_int;
|
||||
tmp_tag.push_back(tmp_int);
|
||||
}
|
||||
|
||||
if (ele_tag != nullptr)
|
||||
ele_tag->push_back(tmp_tag);
|
||||
|
||||
tmp_ss >> tmp_index[0] >> tmp_index[1];
|
||||
|
||||
if (packed == NotPacked)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
tmp_edge.vert[j] = node.get(tmp_index[j]-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
tmp_edge.vert[j] = node.get(tmp_index[j]);
|
||||
}
|
||||
element_vec.push_back(tmp_edge);
|
||||
|
||||
ele_count++;
|
||||
}
|
||||
}
|
||||
|
||||
//将元素转移到向量上来
|
||||
element.resize(element_vec.size());
|
||||
for (int i = 0; i < element.size(); i++)
|
||||
{
|
||||
element[i].id = element_vec[i].id;
|
||||
for (int j = 0; j < 2; j++)
|
||||
element[i].vert[j] = element_vec[i].vert[j];
|
||||
}
|
||||
destroy_vector(element_vec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read element index from a Gmsh file.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user