Using RAII to remove file.close
This commit is contained in:
parent
a71af09b16
commit
2e0b7c8b58
@ -279,6 +279,7 @@ void NETGENPlugin_NETGEN_3D::exportElementOrientation(SMESH_Mesh& aMesh,
|
||||
} // loop on elements on a face
|
||||
} // loop on faces of a SOLID or SHELL
|
||||
|
||||
{
|
||||
std::ofstream df(output_file, ios::out|ios::binary);
|
||||
int size=elemOrientation.size();
|
||||
|
||||
@ -287,7 +288,7 @@ void NETGENPlugin_NETGEN_3D::exportElementOrientation(SMESH_Mesh& aMesh,
|
||||
df.write((char*)&id, sizeof(vtkIdType));
|
||||
df.write((char*)&orient, sizeof(bool));
|
||||
}
|
||||
df.close();
|
||||
}
|
||||
}
|
||||
|
||||
int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
|
||||
@ -363,10 +364,10 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
|
||||
//std::cout << cmd << std::endl;
|
||||
|
||||
// Writing command in log
|
||||
{
|
||||
std::ofstream flog(log_file.string());
|
||||
flog << cmd << endl;
|
||||
flog.close();
|
||||
|
||||
}
|
||||
// TODO: Replace system by something else to handle redirection for windows
|
||||
int ret = system(cmd.c_str());
|
||||
auto time5 = std::chrono::high_resolution_clock::now();
|
||||
@ -382,6 +383,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
|
||||
}
|
||||
|
||||
aMesh.Lock();
|
||||
{
|
||||
std::ifstream df(new_element_file.string(), ios::binary);
|
||||
|
||||
int Netgen_NbOfNodes;
|
||||
@ -412,11 +414,6 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
|
||||
nodeVec.at(nodeIndex) = meshDS->FindNode(nodeID);
|
||||
}
|
||||
|
||||
auto time6 = std::chrono::high_resolution_clock::now();
|
||||
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time6-time5);
|
||||
std::cout << "Time for exec of nodeVec: " << elapsed.count() * 1e-9 << std::endl;
|
||||
|
||||
|
||||
// Add new points and update nodeVec
|
||||
for (int nodeIndex = Netgen_NbOfNodes +1 ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
|
||||
{
|
||||
@ -439,9 +436,9 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
|
||||
nodeVec.at( Netgen_tetrahedron[2] ),
|
||||
nodeVec.at( Netgen_tetrahedron[3] ));
|
||||
}
|
||||
df.close();
|
||||
}
|
||||
auto time7 = std::chrono::high_resolution_clock::now();
|
||||
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time7-time6);
|
||||
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time7-time5);
|
||||
std::cout << "Time for exec of add_in_mesh: " << elapsed.count() * 1e-9 << std::endl;
|
||||
|
||||
fs::remove_all(tmp_folder);
|
||||
|
@ -315,6 +315,8 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
}
|
||||
|
||||
// Get list of elements + their orientation from element_orientation file
|
||||
std::map<vtkIdType, bool> elemOrientation;
|
||||
{
|
||||
std::ifstream df(element_orientation_file, ios::binary|ios::in);
|
||||
int nbElement;
|
||||
bool orient;
|
||||
@ -323,7 +325,6 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
// Sizeof was the same but how he othered the type was different
|
||||
// Maybe using another type (uint64_t) instead would be better
|
||||
vtkIdType id;
|
||||
std::map<vtkIdType, bool> elemOrientation;
|
||||
df.read((char*)&nbElement, sizeof(int));
|
||||
|
||||
for(int ielem=0;ielem<nbElement;++ielem){
|
||||
@ -331,7 +332,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
df.read((char*) &orient, sizeof(bool));
|
||||
elemOrientation[id] = orient;
|
||||
}
|
||||
df.close();
|
||||
}
|
||||
|
||||
// Adding elements from Mesh
|
||||
SMDS_ElemIteratorPtr iteratorElem = meshDS->elementsIterator(SMDSAbs_Face);
|
||||
@ -548,7 +549,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
double Netgen_point[3];
|
||||
int Netgen_tetrahedron[4];
|
||||
|
||||
// Writing nodevec (correspondance netgen numbering mesh numbering)
|
||||
// Writing nodevec (correspondence netgen numbering mesh numbering)
|
||||
// Number of nodes
|
||||
df.write((char*) &Netgen_NbOfNodes, sizeof(int));
|
||||
df.write((char*) &Netgen_NbOfNodesNew, sizeof(int));
|
||||
@ -574,7 +575,6 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
|
||||
df.write((char*) &Netgen_tetrahedron, sizeof(int)*4);
|
||||
}
|
||||
df.close();
|
||||
}
|
||||
auto time3 = std::chrono::high_resolution_clock::now();
|
||||
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time3-time2);
|
||||
@ -775,6 +775,7 @@ int netgen2d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
occgeoComm.vmap.Clear();
|
||||
|
||||
// Reading list of element to integrate into netgen mesh
|
||||
{
|
||||
std::ifstream df(element_orientation_file, ios::in|ios::binary);
|
||||
int nbElement;
|
||||
vtkIdType id;
|
||||
@ -786,7 +787,7 @@ int netgen2d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
|
||||
df.read((char*) &orient, sizeof(bool));
|
||||
elemOrientation[id] = orient;
|
||||
}
|
||||
df.close();
|
||||
}
|
||||
|
||||
bool isIn;
|
||||
// set local size according to size of existing segments
|
||||
|
Loading…
Reference in New Issue
Block a user