MimmoGeometry.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #ifndef __MIMMOGEOMETRY_HPP__
25 #define __MIMMOGEOMETRY_HPP__
26 
27 #include "BaseManipulation.hpp"
28 #include "enum.hpp"
29 #include <typeinfo>
30 #include <type_traits>
31 
32 BETTER_ENUM(FileType, int, STL = 0, SURFVTU = 1, VOLVTU = 2, NAS = 3, PCVTU = 4, CURVEVTU = 5, MIMMO = 99);
33 
34 BETTER_ENUM(NastranElementType, int, GRID = 0, CTRIA = 1, CQUAD = 2, CBAR = 3, RBE2 = 4, RBE3 = 5);
35 
36 namespace mimmo{
37 
38 class NastranInterface;
39 
44 enum WFORMAT{
45  Short = 0,
46  Long = 1
47 };
48 
49 
150 // TODO ADD CUSTOM NUMBER OF PROCESSORS FOR INPUT/OUTPUT OF VTU FILES
152 
153 protected:
154  bool m_read;
157  bool m_write;
160  bool m_codex;
165  long m_refPID;
168  double m_tolerance;
169  bool m_clean;
173 public:
178  enum class IOMode{
179  READ = 0,
180  WRITE = 1,
181  CONVERT = 2
182  };
183 
185  MimmoGeometry(const bitpit::Config::Section & rootXML);
186  virtual ~MimmoGeometry();
187 
188  MimmoGeometry(const MimmoGeometry & other);
190 
191  void buildPorts();
192 
193  const MimmoGeometry * getCopy();
194 
195 public:
196  void setReadDir(std::string dir);
197  void setWriteDir(std::string dir);
198  void setReadFilename(std::string filename);
199  void setWriteFilename(std::string filename);
200 
201  void setDir(std::string dir);
202  void setFilename(std::string filename);
203  void setReadFileType(FileType type);
204  void setReadFileType(int type);
205  void setWriteFileType(FileType type);
206  void setWriteFileType(int type);
207  void setFileType(FileType type);
208  void setFileType(int type);
209  void setCodex(bool binary = true);
210  void setMultiSolidSTL(bool multi = true);
211 
212  void setTolerance(double tol);
213  void setClean(bool clean = true);
214  void setParallelRestore(bool parallelRestore = MIMMO_ENABLE_MPI);
215 
217  void setGeometry(int type=1);
218 
219  bitpit::PiercedVector<bitpit::Vertex> * getVertices();
220  bitpit::PiercedVector<bitpit::Cell> * getCells();
221 
222 
223  void setPID(livector1D pids);
224  void setPID(std::unordered_map<long,long> pidsMap);
225  void setReferencePID(long pid);
226 
227  void setFormatNAS(WFORMAT wform);
228 
229  void setBuildSkdTree(bool build);
230  void setBuildKdTree(bool build);
231 
232  bool isEmpty();
233  void clear();
234  bool write();
235  bool read();
236 
237  void execute();
238 
239  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="");
240  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="");
241 
242 protected:
243  void swap(MimmoGeometry & x) noexcept;
244  void setIOMode(IOMode mode);
245  void setIOMode(int mode);
246  void setDefaults();
247  void _setRead(bool read = true);
248  void _setWrite(bool write = true);
249  bool fileExist(const std::string & filename);
250 
251 };
252 
259  static const char nl = '\n';
260 public:
261 
264  std::map<NastranElementType, bool> m_enabled;
267 
268  void setWFormat(WFORMAT);
269  void writeKeyword(std::string key, std::ofstream& os);
270  void writeCoord(const darray3E & p, const long& pointI, std::ofstream& os);
271  void writeFace(std::string faceType, const livector1D& facePts, const long& nFace, std::ofstream& os, long PID);
272  bool writeGeometry(dvecarr3E &points,livector1D &pointsID, livector2D &faces, livector1D &facesID, std::ofstream &os, livector1D *PIDS = nullptr);
273  void writeFooter(std::ofstream& os, std::unordered_set<long>* PIDSSET = nullptr);
274  void write(std::string& outputDir, std::string& surfaceName, dvecarr3E& points, livector1D& pointsID, livector2D& faces, livector1D& facesID, livector1D* PIDS = nullptr, std::unordered_set<long>* PIDSSET = nullptr);
275  void read(std::string& inputDir, std::string& surfaceName, dvecarr3E& points, livector1D& pointsID, livector2D& faces, livector1D& facesID, livector1D& PIDS);
276 
277  std::string trim(std::string in);
278  std::string convertVertex(std::string in);
279 
280  void appendLineRecords(std::string & sread, std::size_t recordlength, std::vector<std::string> & records);
281  void absorbRBE2(std::vector<std::string> & records, long & ID, long & PID, std::vector<long> & connectivity, std::string & components);
282  void absorbRBE3(std::vector<std::string> & records, long & ID, long & PID, std::vector<long> & connectivity, std::string & components);
283  bool isInteger(std::string & str);
284 
285  bool isEnabled(NastranElementType type);
286 
287 protected:
288  void enable(NastranElementType type);
289  void disable(NastranElementType type);
290 
291 
297  template<class Type>
298  void writeValue (Type& value, std::ofstream& os){
299 
300  std::size_t offset = 5;
301  if (m_wformat == WFORMAT::Long) offset = 13;
302 
303  std::stringstream manip;
304  manip <<std::fixed<<std::setprecision(offset+3);
305  manip<<value;
306  std::string manips = manip.str();
307  std::string mantissa, expon;
308  std::size_t pos = manips.find("E");
309  if (pos < manips.size()){
310  mantissa = manips.substr(0,std::min(offset,pos));
311  expon = manips.substr(pos+1,manips.size());
312  manips = mantissa + expon;
313  }
314  pos = manips.find("e");
315  if (pos < manips.size()){
316  mantissa = manips.substr(0,std::min(offset,pos));
317  expon = manips.substr(pos+1,manips.size());
318  manips = mantissa + expon;
319  }
320  manips = manips.substr(0, offset+3);
321 
322  switch (m_wformat)
323  {
324  case Short:
325  {
326  os << std::setw(8) << manips;
327  break;
328  }
329  case Long:
330  {
331  os << std::setw(16) << manips;
332  break;
333  }
334  }
335  }
336 };
337 
338 REGISTER_PORT(M_GEOM, MC_SCALAR, MD_MIMMO_, __MIMMOGEOMETRY_HPP__)
339 REGISTER(BaseManipulation, MimmoGeometry, "mimmo.Geometry")
340 
341 };
342 
343 #endif /* __MIMMOGEOMETRY_HPP__ */
std::vector< livector1D > livector2D
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setClean(bool clean=true)
FileDataInfo is a struct to stock data relative to names of external files.
#define M_GEOM
void _setWrite(bool write=true)
void setGeometry(int type=1)
std::vector< darray3E > dvecarr3E
void setWriteFileType(FileType type)
void setBuildSkdTree(bool build)
void write(std::string &outputDir, std::string &surfaceName, dvecarr3E &points, livector1D &pointsID, livector2D &faces, livector1D &facesID, livector1D *PIDS=nullptr, std::unordered_set< long > *PIDSSET=nullptr)
std::vector< long > livector1D
void setReferencePID(long pid)
void setWriteDir(std::string dir)
void setFileType(FileType type)
void setBuildKdTree(bool build)
void writeFace(std::string faceType, const livector1D &facePts, const long &nFace, std::ofstream &os, long PID)
BaseManipulation is the base class of any manipulation object of the library.
void setWriteFilename(std::string filename)
void writeKeyword(std::string key, std::ofstream &os)
bitpit::PiercedVector< bitpit::Vertex > * getVertices()
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void writeValue(Type &value, std::ofstream &os)
void appendLineRecords(std::string &sread, std::size_t recordlength, std::vector< std::string > &records)
bool fileExist(const std::string &filename)
bool isInteger(std::string &str)
#define MC_SCALAR
void writeFooter(std::ofstream &os, std::unordered_set< long > *PIDSSET=nullptr)
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
void setReadFilename(std::string filename)
void setTolerance(double tol)
void swap(MimmoGeometry &x) noexcept
void setMultiSolidSTL(bool multi=true)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void writeCoord(const darray3E &p, const long &pointI, std::ofstream &os)
std::string convertVertex(std::string in)
void absorbRBE3(std::vector< std::string > &records, long &ID, long &PID, std::vector< long > &connectivity, std::string &components)
bool isEnabled(NastranElementType type)
void read(std::string &inputDir, std::string &surfaceName, dvecarr3E &points, livector1D &pointsID, livector2D &faces, livector1D &facesID, livector1D &PIDS)
void setParallelRestore(bool parallelRestore=0)
void setFilename(std::string filename)
void setCodex(bool binary=true)
MimmoGeometry(IOMode mode=IOMode::READ)
NastranInterface is an interface class for I/O handling of BDF bulk nastran format *....
void setFormatNAS(WFORMAT wform)
std::string trim(std::string in)
#define MD_MIMMO_
void setIOMode(IOMode mode)
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
void setPID(livector1D pids)
std::array< double, 3 > darray3E
const MimmoGeometry * getCopy()
void enable(NastranElementType type)
void absorbRBE2(std::vector< std::string > &records, long &ID, long &PID, std::vector< long > &connectivity, std::string &components)
void setReadFileType(FileType type)
bitpit::PiercedVector< bitpit::Cell > * getCells()
void disable(NastranElementType type)
void _setRead(bool read=true)
bool writeGeometry(dvecarr3E &points, livector1D &pointsID, livector2D &faces, livector1D &facesID, std::ofstream &os, livector1D *PIDS=nullptr)
MimmoGeometry & operator=(MimmoGeometry other)
void setDir(std::string dir)
void setReadDir(std::string dir)
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206
std::map< NastranElementType, bool > m_enabled