18 #if !defined(KRATOS_IO_UTILITIES_H_INCLUDED)
19 #define KRATOS_IO_UTILITIES_H_INCLUDED
97 KRATOS_INFO(
"[TopOpt]") <<
"::[Saving optimization results as restart file]::"<< std::endl;
100 std::ofstream FileToBeCreated;
101 FileToBeCreated.open(RestartOutputFile, std::ios::trunc);
104 std::ifstream FileToBeRead(RestartInputFile);
105 if(!FileToBeRead.is_open())
106 KRATOS_THROW_ERROR(std::invalid_argument,
"Specified restart input file does not exist: ",RestartInputFile);
109 bool DensityBlockActive =
false;
110 std::string LineString;
111 while (std::getline(FileToBeRead, LineString))
113 if(LineString.find(
"Begin ElementalData X_PHYS")!=std::string::npos)
114 DensityBlockActive =
true;
115 else if(LineString.find(
"End ElementalData")!=std::string::npos and DensityBlockActive)
117 DensityBlockActive =
false;
120 else if(DensityBlockActive ==
false)
121 FileToBeCreated << LineString <<
"\n";
125 FileToBeCreated <<
"\nBegin ElementalData X_PHYS\n";
126 for(ModelPart::ElementsContainerType::iterator elem_i = rModelPart.
ElementsBegin(); elem_i!=rModelPart.
ElementsEnd(); elem_i++)
128 FileToBeCreated <<
" " << elem_i->Id() <<
" " << elem_i->GetValue(X_PHYS) <<
"\n";
130 FileToBeCreated <<
"End ElementalData\n";
133 FileToBeCreated.close();
134 FileToBeRead.close();
136 KRATOS_INFO(
"[TopOpt]") <<
" Restart File succesfully generated under the name " << RestartOutputFile <<std::endl;
150 KRATOS_INFO(
"[TopOpt]") <<
"\n::[Generating STL file]::"<<std::endl;
153 std::ofstream myfile;
155 myfile <<
"solid Layer0\n";
159 myfile <<
" facet normal " << area_normal[0] <<
" " << area_normal[1] <<
" " << area_normal[2] <<
"\n";
160 myfile <<
" outer loop\n";
163 if (rNodes.
size()==3)
165 for(
unsigned int i = 0;
i<rNodes.
size();
i++)
166 myfile <<
" vertex "<< rNodes[
i].
X() <<
" " << rNodes[
i].Y() <<
" " << rNodes[
i].Z() <<
"\n";
168 myfile <<
" end loop\n";
169 myfile <<
" end facet\n";
173 KRATOS_ERROR <<
"The number of nodes is: "<< rNodes.
size() <<
". This is not feasible for STL files!"<< std::endl;
177 myfile <<
"endsolid Layer0\n";
180 KRATOS_INFO(
"[TopOpt]") <<
" STL File succesfully generated under the name " <<
file_name <<std::endl;
200 virtual std::string
Info()
const
202 return "IOUtilities";
208 rOStream <<
"IOUtilities";
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Solution utility to filter results.
Definition: io_utilities.h:57
virtual ~IOUtilities()
Destructor.
Definition: io_utilities.h:76
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: io_utilities.h:206
IOUtilities()
Default constructor.
Definition: io_utilities.h:71
virtual std::string Info() const
Turn back information as a string.
Definition: io_utilities.h:200
void SaveOptimizationResults(const char *RestartInputFile, ModelPart &rModelPart, const char *RestartOutputFile)
Definition: io_utilities.h:93
void WriteSurfaceAsSTLFile(const char *file_name, ModelPart &rSurfaceModelPart)
Generates a .STL file from a a provided surface mesh.
Definition: io_utilities.h:146
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: io_utilities.h:212
KRATOS_CLASS_POINTER_DEFINITION(IOUtilities)
Pointer definition of IOUtilities.
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
ElementIterator ElementsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1179
MeshType::ConditionIterator ConditionIterator
Definition: model_part.h:189
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
string file_name
Definition: sp_statistics.py:6
integer i
Definition: TensorModule.f:17