25 #include <libmesh/point.h> 26 #include <libmesh/elem.h> 27 #include <libmesh/string_to_enum.h> 28 #include <libmesh/boundary_info.h> 30 #include <libmesh/libmesh_common.h> 31 #include <libmesh/mesh_input.h> 38 #include "libfort/fort.hpp" 42 libMesh::MeshInput<libMesh::MeshBase> (mesh),
43 python_preinitialized(python_preinit)
88 std::map<int, std::set<int>> property_id_to_subdomain_id_map;
91 int pid = item.first.first;
92 int sid = item.second;
93 property_id_to_subdomain_id_map[pid].insert(sid);
96 return property_id_to_subdomain_id_map;
108 std::vector<std::vector<double>> nodes =
getNodes(model);
111 the_mesh.reserve_nodes(model->
nNodes);
115 for (
const auto& node : nodes)
117 double x=node[1], y=node[2], z=node[3];
118 uint64_t nid=node[0];
119 the_mesh.add_point(libMesh::Point(x, y, z), nid);
131 the_mesh.reserve_elem(model->
nElems);
136 std::map<std::string, std::vector<std::vector<int>>> elements =
getElements(model);
141 for (
const auto& item : elements)
144 libMesh::ElemType elem_type;
148 libmesh_error_msg(
"ERROR: " << item.first
149 <<
" not found in nastran_to_libmesh_elem_type_map map in nastran_io.h");
157 for (uint i=0; i<item.second.size(); i++)
160 libMesh::Elem * elem = the_mesh.add_elem(libMesh::Elem::build(elem_type).release());
161 const libMesh::dof_id_type eid = item.second[i][0];
172 const libMesh::subdomain_id_type pid = item.second[i][1];
173 const int elemtype = int(elem->type());
183 elem->subdomain_id() = sid;
186 for (uint j=2; j<(item.second[i].size()); j++)
188 uint node_num = item.second[i][j];
190 elem->set_node(j-2) = the_mesh.node_ptr(nid);
204 std::map<std::string, std::vector<int>> SPCs =
getSPCs(model);
206 for (
const auto& spc : SPCs)
208 for (uint i=0; i<spc.second.size(); i++)
220 libMesh::MeshBase& the_mesh = MeshInput<libMesh::MeshBase>::mesh();
229 the_mesh.set_mesh_dimension(model->
nDims);
241 the_mesh.prepare_for_use();
248 libMesh::MeshBase& the_mesh = MeshInput<libMesh::MeshBase>::mesh();
254 the_mesh.set_mesh_dimension(model->
nDims);
268 int status = PyImport_AppendInittab(
"pynastran_io", PyInit_pynastran_io);
270 libmesh_error_msg(
"ERROR: During Python import for pynastran_io.");
274 PyObject* pynastran_module = PyImport_ImportModule(
"pynastran_io");
276 if(pynastran_module==NULL){
279 libmesh_error_msg(
"ERROR: During Python initialization for pynastran_io.");
294 table << fort::header <<
"Nastran Property ID" <<
"libMesh/MAST Subdomain ID" << fort::endr;
298 table << std::to_string(id_pair.first);
299 for (
const auto& sid: id_pair.second) {
300 sid_str.append(std::to_string(sid) +
" ");
302 table << sid_str << fort::endr;
304 libMesh::out << std::endl <<
"DOMAIN MAPPING" << std::endl;
305 libMesh::out << table.to_string() << std::endl;
312 for (
const auto& item : elementMap)
314 libMesh::out <<
"Element Type: " << item.first << std::endl;
317 for (
const auto& elem : item.second)
319 libMesh::out <<
"Element ID: " << elem[0] <<
"\tPID: " << elem[1] <<
"\tNodes: ";
321 for (uint j=2; j<elem.size(); j++)
323 libMesh::out << elem[j] <<
"\t";
325 libMesh::out <<
"" << std::endl;
334 for (
const auto& node : nodes)
336 libMesh::out <<
"Node # " << node[0] <<
":\t" << node[1] <<
"\t" << node[2] <<
"\t" << node[3] <<
"\t" << std::endl;
void print_pid_to_subdomain_id_map()
Print map between Nastran property ID's (PID) to libMesh subdomain ID's (SID) to libMesh::out.
NastranIO(libMesh::MeshBase &mesh, const bool python_preinit=false)
Constructor.
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.
std::map< const libMesh::Node *, uint64_t > get_libmesh_to_nastran_node_map()
Returns mapping between libMesh/MAST nodes and Nastran BDF grid ID's.
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.
void read_node_boundaries(BDFModel *model, libMesh::MeshBase &the_mesh)
__PYX_EXTERN_C std::map< std::string, std::vector< std::vector< int > > > getElements(struct BDFModel *)
__PYX_EXTERN_C std::vector< std::vector< double > > getNodes(struct BDFModel *)
void printNodeCoords(std::vector< std::vector< double >> nodes)
virtual ~NastranIO()
Destructor.
void read_elements(BDFModel *model, libMesh::MeshBase &the_mesh)
std::map< libMesh::Elem *, uint64_t > get_libmesh_to_nastran_elem_map()
Returns mapping between libMesh/MAST elements and Nastran BDF element ID's.
__PYX_EXTERN_C struct BDFModel * buildBDFModel(std::string)
void read_nodes(BDFModel *model, libMesh::MeshBase &the_mesh)
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...
std::map< std::string, libMesh::ElemType > nastran_to_libmesh_elem_type_map
Map from Nastran elements to equivalent libMesh/MAST element types.
std::map< libMesh::Elem *, uint64_t > libmesh_to_nastran_elem_map
Mapping from libMesh/MAST element pointers to Nastran element IDs from BDF input. ...
__PYX_EXTERN_C std::map< std::string, std::vector< int > > getSPCs(struct BDFModel *)
bool python_initialized
Indicates is Python has been initialized.
void printElementMap(std::map< std::string, std::vector< std::vector< int >>> elementMap)
std::map< uint64_t, libMesh::Elem * > get_nastran_to_libmesh_elem_map()
Returns mapping between Nastran BDF element ID's and libMesh/MAST elements.
virtual void read(const std::string &filename) override
Read ASCII NASTRAN BDF given by filename.
std::map< uint64_t, libMesh::Node * > get_nastran_to_libmesh_node_map()
Returns mapping between Nastran BDF grid ID's and libMesh/MAST nodes.
const bool python_preinitialized
Indicates if Python was initialized outside of NastranIO class.
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.
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.
std::map< int, std::set< int > > get_nastran_property_to_libmesh_subdomains_map()
Returns mapping between Nastran property ID's and sets of libMesh/MAST subdomains.