21 FILE* of = fopen(fileName,
"w");
26 << std::string(fileName);
31 std::set<int> nodes_set;
32 std::vector<chi_mesh::CellFace> faces_to_export;
37 for (
auto& face : cell.faces_)
39 if (not face.has_neighbor_)
41 faces_to_export.push_back(face);
43 for (
int vid : face.vertex_ids_)
44 nodes_set.insert(vid);
51 fprintf(of,
"# Exported mesh file from Extrusion script\n");
52 std::string str_file_name(fileName);
53 std::string file_base_name =
54 str_file_name.substr(0,str_file_name.find(
'.'));
55 fprintf(of,
"o %s\n",file_base_name.c_str());
61 for (
auto node : nodes_set)
64 int node_g_index = node;
65 node_mapping[node_g_index] = node_counter;
69 fprintf(of,
"v %9.6f %9.6f %9.6f\n",cur_v.
x,cur_v.
y,cur_v.
z);
73 for (
const auto& face : faces_to_export)
75 fprintf(of,
"vn %.4f %.4f %.4f\n",
83 for (
const auto& face : faces_to_export)
88 for (
auto v_g_index : face.vertex_ids_)
89 fprintf(of,
" %d//%d",node_mapping[v_g_index],normal_counter);
98 <<
"Exported Volume mesh to "
105 std::string str_file_name(fileName);
106 std::string file_base_name =
107 str_file_name.substr(0,str_file_name.find(
'.'));
112 <<
"ExportCellsToObj: No mesh will be exported because there "
113 <<
"are no physics materials present";
119 std::string mat_base_name = file_base_name +
122 std::string mat_file_name = mat_base_name +
124 FILE* of = fopen(mat_file_name.c_str(),
"w");
134 std::set<int> nodes_set;
135 std::vector<chi_mesh::CellFace> faces_to_export;
140 if (cell.material_id_ != mat)
continue;
142 for (
const auto& face : cell.faces_)
144 int adjcell_glob_index = face.neighbor_id_;
146 if (adjcell_glob_index<0)
148 faces_to_export.push_back(face);
150 for (
auto vid : face.vertex_ids_)
151 nodes_set.insert(vid);
155 auto& adj_cell =
cells[adjcell_glob_index];
157 if (adj_cell.material_id_ != mat)
161 for (
auto vid : face.vertex_ids_)
162 nodes_set.insert(vid);
170 fprintf(of,
"# Exported mesh file from Extrusion script\n");
171 fprintf(of,
"o %s\n",mat_base_name.c_str());
177 for (
auto node : nodes_set)
180 int node_g_index = node;
181 node_mapping[node_g_index] = node_counter;
185 fprintf(of,
"v %9.6f %9.6f %9.6f\n",cur_v.
x,cur_v.
y,cur_v.
z);
189 for (
const auto& face : faces_to_export)
191 fprintf(of,
"vn %.4f %.4f %.4f\n",
198 int normal_counter=0;
199 for (
const auto& face : faces_to_export)
204 for (
auto v_g_index : face.vertex_ids_)
205 fprintf(of,
" %d//%d",node_mapping[v_g_index],normal_counter);
214 <<
"Exported Material Volume mesh to "
static std::vector< chi_physics::MaterialPtr > material_stack
static void Exit(int error_code)
LogStream Log(LOG_LVL level=LOG_0)
void push_back(std::unique_ptr< chi_mesh::Cell > new_cell)
LocalCellHandler local_cells
uint64_t GetGlobalVertexCount() const
void ExportCellsToObj(const char *fileName, bool per_material=false, int options=0) const