1 // Copyright (C) 2021-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MESHFORMATWRITER_HXX
21 #define MESHFORMATWRITER_HXX
27 #include "InterpKernelException.hxx"
28 #include "NormalizedUnstructuredMesh.hxx"
30 #include "MEDMESHConverterUtilities.hxx"
31 #include "libmesh5.hxx"
33 #include "MEDFileMesh.hxx"
38 class DataArrayDouble;
42 class MEDFileFieldMultiTS;
46 struct MeshFormatNode {
47 MeshFormatNode(double x, double y, double z=0, int id=0, int famId=0): _id(id), _famId(famId) {
56 //~inline friend bool operator==(const MeshFormatNode& a, const MeshFormatNode&b ) { return ((a._type == b._type) && (a._id == b._id));}
59 struct MeshFormatCell {
60 MeshFormatCell(INTERP_KERNEL::NormalizedCellType type, int id=0, int famId=0):_type(type), _id(id), _famId(famId) {}
61 INTERP_KERNEL::NormalizedCellType _type;
64 void setConn(const std::vector<MEDCoupling::mcIdType> cpy)
67 std::copy(cpy.begin(), cpy.end(), std::back_inserter(conn));
69 std::vector<MEDCoupling::mcIdType> conn;
73 class MeshFormatWriter
76 MEDLOADER_EXPORT MeshFormatWriter();
77 MEDLOADER_EXPORT MeshFormatWriter(const std::string& meshFileName, const std::vector<std::string>& fieldFileNames);
78 MEDLOADER_EXPORT ~MeshFormatWriter();
79 MEDLOADER_EXPORT void setMeshFileName(const std::string& meshFileName);
80 MEDLOADER_EXPORT std::string getMeshFileName() const;
81 MEDLOADER_EXPORT void setFieldFileNames(const std::vector<std::string>& fieldFileNames);
82 MEDLOADER_EXPORT std::vector<std::string> getFieldFileNames() const;
83 MEDLOADER_EXPORT void setMEDFileDS(MEDCoupling::MEDFileData* mfd);
85 MEDLOADER_EXPORT void write();
89 void getNodes( MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh0);
90 void getNSEG2( MEDCoupling::mcIdType nbEdgesNSEG2, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh1);
91 void getNSEG3( MEDCoupling::mcIdType nbEdgesNSEG2, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh1);
92 void getTRI3( MEDCoupling::mcIdType nbTRI3, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2);
93 void getTRI6( MEDCoupling::mcIdType nbTRI6, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2);
94 void getQUAD4( MEDCoupling::mcIdType nbQUAD4, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2);
95 void getQUAD8( MEDCoupling::mcIdType nbQUAD8, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2);
96 void getQUAD9( MEDCoupling::mcIdType nbQUAD9, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh2);
97 void getTETRA4( MEDCoupling::mcIdType nbTETRA4, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
98 void getTETRA10( MEDCoupling::mcIdType nbTETRA10, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
99 void getPYRA5( MEDCoupling::mcIdType nbPYRA5, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
100 void getHEXA8( MEDCoupling::mcIdType nbHEXA8, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
101 void getHEXA20( MEDCoupling::mcIdType nbHEXA20, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
102 void getHEXA27( MEDCoupling::mcIdType nbHEXA27, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
103 void getPENTA6( MEDCoupling::mcIdType nbPENTA6, MEDCoupling::MCAuto< MEDCoupling::MEDCouplingUMesh > umesh3);
104 int getGmfSolKwd(const int nbComp, const int dim);
105 MeshFormat::Status setFieldOnNodes(MEDCoupling::MEDFileFieldMultiTS * f, int iteration, int order, size_t compInfoSize);
106 MeshFormat::Status setFieldOnCells(MEDCoupling::MEDFileFieldMultiTS * f, int iteration, int order, std::vector<int> levs );
107 void extractSymetricTensor(double fullTensor[], double*& symTensor);
108 void linkFamilyToNodes();
109 void linkFamilyToCells();
112 bool checkFileName();
113 bool checkFieldFileName();
114 void forward_shift(std::vector<MEDCoupling::mcIdType> &conn);
115 MeshFormat::Status perform();
116 MeshFormat::Status performFields();
117 MeshFormat::Status addMessage(const std::string& msg, const bool isFatal = false);
119 std::string _meshFileName;
120 MeshFormat::MeshFormatParser _writer;
121 std::vector<std::string> _fieldFileNames;
122 MEDCoupling::MEDFileData* _mfd;
123 MEDCoupling::MCAuto< MEDCoupling::MEDFileMesh > _mesh;
124 std::vector< MEDCoupling::MCAuto< MEDCoupling::MEDFileFieldMultiTS > > _fields;
125 std::vector< std::string > _myErrorMessages;
126 MeshFormat::Status _myStatus;
127 int _myCurrentFileId, _dim, _version;
128 std::string _myCurrentOpenFile;
129 std::map<int, MeshFormatNode> _idNodeToNode;
130 std::map < INTERP_KERNEL::NormalizedCellType, std::map<int, MeshFormatCell> > _typeToIdCellToCell;
134 #endif //MESHFORMATWRITER_HXX