MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
nastran_io.h
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef __mast_nastran_io_h__
21 #define __mast_nastran_io_h__
22 
23 // C++ includes.
24 #include <iostream>
25 #include <map>
26 #include <list>
27 
28 // libMesh includes.
29 #include <libmesh/libmesh_common.h>
30 #include <libmesh/mesh_input.h>
31 #include <libmesh/elem.h>
32 
33 #include "base/mast_config.h"
34 
35 // Python includes.
36 #include <Python.h>
37 
38 // MAST includes.
39 #include "mesh/nastran_io.h"
40 #include "mesh/pynastran_io.h"
41 
42 
43 namespace MAST {
44 
62 class NastranIO : public libMesh::MeshInput<libMesh::MeshBase> {
63  public:
64 
71  explicit NastranIO(libMesh::MeshBase& mesh, const bool python_preinit=false);
72 
76  virtual ~NastranIO();
77 
82  virtual void read(const std::string & filename) override;
83 
88  virtual void read(BDFModel* model);
89 
94  std::map<uint64_t, libMesh::Node*> get_nastran_to_libmesh_node_map();
95 
100  std::map<const libMesh::Node*, uint64_t> get_libmesh_to_nastran_node_map();
101 
107  std::map<uint64_t, libMesh::Elem*> get_nastran_to_libmesh_elem_map();
108 
114  std::map<libMesh::Elem*, uint64_t> get_libmesh_to_nastran_elem_map();
115 
126  std::map<std::pair<int,int>, int> get_nastran_pid_elemtype_to_libmesh_subdomain_map();
127 
138  std::map<int, std::set<int>> get_nastran_property_to_libmesh_subdomains_map();
139 
148 
149  private:
150 
152  const bool python_preinitialized = false;
154  bool python_initialized = false;
155 
157  std::map<uint64_t, libMesh::Node*> nastran_to_libmesh_node_map;
159  std::map<const libMesh::Node*, uint64_t> libmesh_to_nastran_node_map;
161  std::map<uint64_t, libMesh::Elem*> nastran_to_libmesh_elem_map;
163  std::map<libMesh::Elem*, uint64_t> libmesh_to_nastran_elem_map;
164 
175  std::map<std::pair<int, int>, int> nastran_pid_elemtype_to_libmesh_subdomain_map = {};
176 
177  void read_nodes(BDFModel* model, libMesh::MeshBase& the_mesh);
178  void read_elements(BDFModel* model, libMesh::MeshBase& the_mesh);
179  void read_node_boundaries(BDFModel* model, libMesh::MeshBase& the_mesh);
180 
185  std::map<std::string, libMesh::ElemType> nastran_to_libmesh_elem_type_map = {
186 
187  // 0D Elements (i.e. Ground Springs)
188  {"CELAS1_1", libMesh::NODEELEM}, {"CELAS2_1", libMesh::NODEELEM},
189  {"CELAS3_1", libMesh::NODEELEM}, {"CELAS4_1", libMesh::NODEELEM},
190  {"CBUSH_1", libMesh::NODEELEM}, {"CBUSH1D_1", libMesh::NODEELEM},
191 
192  // 1D Elements
193  {"CELAS1_2", libMesh::EDGE2}, {"CELAS2_2", libMesh::EDGE2},
194  {"CELAS3_2", libMesh::EDGE2}, {"CELAS4_2", libMesh::EDGE2},
195  {"CBUSH_2", libMesh::EDGE2}, {"CBUSH1D_2", libMesh::EDGE2},
196  {"CBUSH2D_2",libMesh::EDGE2},
197  {"CROD_2", libMesh::EDGE2}, {"CBAR_2", libMesh::EDGE2},
198  {"CBEAM_2", libMesh::EDGE2}, {"CBEAM3_3", libMesh::EDGE3},
199 
200  // 2D Elements
201  {"CTRIA3_3", libMesh::TRI3}, {"CTRIA6_6", libMesh::TRI6},
202  {"CTRIAR_3", libMesh::TRI3},
203  {"CQUAD4_4", libMesh::QUAD4}, {"CQUAD8_8", libMesh::QUAD8},
204  {"CQUADR_4", libMesh::QUADSHELL4}, {"CQUAD_4", libMesh::QUAD4},
205  {"CQUAD_8", libMesh::QUAD8}, {"CQUAD_9", libMesh::QUAD9},
206  {"CQUADX_4", libMesh::QUAD4}, {"CQUADX_8", libMesh::QUAD8},
207  {"CQUADX_9", libMesh::QUAD9},
208 
209  // 3D Elements
210  {"CTETRA_4", libMesh::TET4}, {"CTETRA_10", libMesh::TET10},
211  {"CPENTA_6", libMesh::PRISM6}, {"CPENTA_15", libMesh::PRISM15},
212  {"CPYRAM_5", libMesh::PYRAMID5}, {"CPYRAM_13", libMesh::PYRAMID13},
213  {"CHEXA_8", libMesh::HEX8}, {"CHEXA_20", libMesh::HEX20}
214  };
215 
216  void initialize_python();
217  void finalize_python();
218  };
219 
220  // Utility functions.
221  void printElementMap(std::map<std::string, std::vector<std::vector<int>>> elementMap);
222  void printNodeCoords(std::vector<std::vector<double>> nodes);
223 }
224 
225 #endif // __mast_nastran_io_h__
void print_pid_to_subdomain_id_map()
Print map between Nastran property ID&#39;s (PID) to libMesh subdomain ID&#39;s (SID) to libMesh::out.
Definition: nastran_io.cpp:292
NastranIO(libMesh::MeshBase &mesh, const bool python_preinit=false)
Constructor.
Definition: nastran_io.cpp:41
std::map< uint64_t, libMesh::Node * > nastran_to_libmesh_node_map
Mapping from Nastran grid IDs from BDF input to pointers to libMesh/MAST nodes.
Definition: nastran_io.h:157
std::map< const libMesh::Node *, uint64_t > get_libmesh_to_nastran_node_map()
Returns mapping between libMesh/MAST nodes and Nastran BDF grid ID&#39;s.
Definition: nastran_io.cpp:68
std::map< uint64_t, libMesh::Elem * > nastran_to_libmesh_elem_map
Mapping from Nastran element IDs from BDF input to pointers to libMesh/MAST elements.
Definition: nastran_io.h:161
void read_node_boundaries(BDFModel *model, libMesh::MeshBase &the_mesh)
Definition: nastran_io.cpp:199
void printNodeCoords(std::vector< std::vector< double >> nodes)
Definition: nastran_io.cpp:331
Nastran BDF mesh input.
Definition: nastran_io.h:62
virtual ~NastranIO()
Destructor.
Definition: nastran_io.cpp:53
void read_elements(BDFModel *model, libMesh::MeshBase &the_mesh)
Definition: nastran_io.cpp:128
std::map< libMesh::Elem *, uint64_t > get_libmesh_to_nastran_elem_map()
Returns mapping between libMesh/MAST elements and Nastran BDF element ID&#39;s.
Definition: nastran_io.cpp:80
void read_nodes(BDFModel *model, libMesh::MeshBase &the_mesh)
Definition: nastran_io.cpp:105
std::map< std::pair< int, int >, int > get_nastran_pid_elemtype_to_libmesh_subdomain_map()
Provides mapping between Nastran property ID & element-type pairs and corresponding libMesh/MAST subdomai...
Definition: nastran_io.cpp:100
std::map< std::string, libMesh::ElemType > nastran_to_libmesh_elem_type_map
Map from Nastran elements to equivalent libMesh/MAST element types.
Definition: nastran_io.h:185
std::map< libMesh::Elem *, uint64_t > libmesh_to_nastran_elem_map
Mapping from libMesh/MAST element pointers to Nastran element IDs from BDF input. ...
Definition: nastran_io.h:163
void initialize_python()
Definition: nastran_io.cpp:264
bool python_initialized
Indicates is Python has been initialized.
Definition: nastran_io.h:154
void printElementMap(std::map< std::string, std::vector< std::vector< int >>> elementMap)
Definition: nastran_io.cpp:309
std::map< uint64_t, libMesh::Elem * > get_nastran_to_libmesh_elem_map()
Returns mapping between Nastran BDF element ID&#39;s and libMesh/MAST elements.
Definition: nastran_io.cpp:74
virtual void read(const std::string &filename) override
Read ASCII NASTRAN BDF given by filename.
Definition: nastran_io.cpp:217
std::map< uint64_t, libMesh::Node * > get_nastran_to_libmesh_node_map()
Returns mapping between Nastran BDF grid ID&#39;s and libMesh/MAST nodes.
Definition: nastran_io.cpp:62
void finalize_python()
Definition: nastran_io.cpp:285
const bool python_preinitialized
Indicates if Python was initialized outside of NastranIO class.
Definition: nastran_io.h:152
std::map< const libMesh::Node *, uint64_t > libmesh_to_nastran_node_map
Mapping from libMesh/MAST node pointers to Nastran grid IDs from BDF input.
Definition: nastran_io.h:159
std::map< std::pair< int, int >, int > nastran_pid_elemtype_to_libmesh_subdomain_map
Mapping from Nastran property ID/element-type pair to libMesh/MAST subdomain.
Definition: nastran_io.h:175
std::map< int, std::set< int > > get_nastran_property_to_libmesh_subdomains_map()
Returns mapping between Nastran property ID&#39;s and sets of libMesh/MAST subdomains.
Definition: nastran_io.cpp:86