LCOV - code coverage report
Current view: top level - src/io - WriteAns.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 1 212 0.5 %
Date: 2020-12-16 07:07:30 Functions: 2 6 33.3 %
Branches: 2 1154 0.2 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
       3                 :            :  * storing and accessing finite element mesh data.
       4                 :            :  *
       5                 :            :  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
       6                 :            :  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
       7                 :            :  * retains certain rights in this software.
       8                 :            :  *
       9                 :            :  * This library is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public
      11                 :            :  * License as published by the Free Software Foundation; either
      12                 :            :  * version 2.1 of the License, or (at your option) any later version.
      13                 :            :  *
      14                 :            :  */
      15                 :            : 
      16                 :            : #ifdef WIN32
      17                 :            : #ifdef _DEBUG
      18                 :            : // turn off warnings that say they debugging identifier has been truncated
      19                 :            : // this warning comes up when using some STL containers
      20                 :            : #pragma warning( disable : 4786 )
      21                 :            : #endif
      22                 :            : #endif
      23                 :            : 
      24                 :            : #include "WriteAns.hpp"
      25                 :            : 
      26                 :            : #include <utility>
      27                 :            : #include <algorithm>
      28                 :            : #include <time.h>
      29                 :            : #include <string>
      30                 :            : #include <vector>
      31                 :            : #include <stdio.h>
      32                 :            : #include <iostream>
      33                 :            : #include <fstream>
      34                 :            : #include <iomanip>
      35                 :            : 
      36                 :            : #include "moab/Interface.hpp"
      37                 :            : #include "moab/Range.hpp"
      38                 :            : #include "assert.h"
      39                 :            : #include "Internals.hpp"
      40                 :            : #include "ExoIIUtil.hpp"
      41                 :            : #include "MBTagConventions.hpp"
      42                 :            : 
      43                 :            : #define INS_ID( stringvar, prefix, id ) sprintf( stringvar, prefix, id )
      44                 :            : 
      45                 :            : namespace moab
      46                 :            : {
      47                 :            : 
      48                 :          0 : WriterIface* WriteAns::factory( Interface* iface )
      49                 :            : {
      50         [ #  # ]:          0 :     return new WriteAns( iface );
      51                 :            : }
      52                 :            : 
      53         [ #  # ]:          0 : WriteAns::WriteAns( Interface* impl ) : mbImpl( impl ), mCurrentMeshHandle( 0 ), mGlobalIdTag( 0 ), mMatSetIdTag( 0 )
      54                 :            : {
      55         [ #  # ]:          0 :     assert( impl != NULL );
      56                 :            : 
      57                 :            :     // impl->query_interface( mWriteIface );
      58                 :            : 
      59                 :            :     // initialize in case tag_get_handle fails below
      60                 :            :     //! get and cache predefined tag handles
      61                 :          0 :     const int negone = -1;
      62                 :            :     impl->tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mMaterialSetTag, MB_TAG_SPARSE | MB_TAG_CREAT,
      63         [ #  # ]:          0 :                           &negone );
      64                 :            : 
      65                 :            :     impl->tag_get_handle( DIRICHLET_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mDirichletSetTag, MB_TAG_SPARSE | MB_TAG_CREAT,
      66         [ #  # ]:          0 :                           &negone );
      67                 :            : 
      68                 :            :     impl->tag_get_handle( NEUMANN_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mNeumannSetTag, MB_TAG_SPARSE | MB_TAG_CREAT,
      69         [ #  # ]:          0 :                           &negone );
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : WriteAns::~WriteAns()
      73                 :            : {
      74                 :            :     // mbImpl->release_interface(mWriteIface);
      75         [ #  # ]:          0 : }
      76                 :            : 
      77                 :          0 : ErrorCode WriteAns::write_file( const char* file_name, const bool /* overwrite (commented out to remove warning) */,
      78                 :            :                                 const FileOptions&, const EntityHandle* ent_handles, const int num_sets,
      79                 :            :                                 const std::vector< std::string >&, const Tag*, int, int )
      80                 :            : {
      81 [ #  # ][ #  # ]:          0 :     assert( 0 != mMaterialSetTag && 0 != mNeumannSetTag && 0 != mDirichletSetTag );
                 [ #  # ]
      82                 :            : 
      83                 :            :     ErrorCode result;
      84                 :            : 
      85                 :            :     // set SOLID45 element type to #60000, hope nobody has already...
      86                 :          0 :     const char* ETSolid45 = "60045";
      87                 :          0 :     const char* ETSolid92 = "60042";
      88                 :          0 :     const char* ETSolid95 = "60095";
      89                 :            : 
      90                 :            :     // set Material id # to be used as default for all elements
      91                 :            :     // will need to be subsequently reassigned inside ANSYS
      92                 :            :     // Can, although have not, declare similar defaults for other attributes
      93                 :          0 :     const char* MATDefault = "1";
      94                 :            : 
      95                 :            :     // create file streams for writing
      96         [ #  # ]:          0 :     std::ofstream node_file;
      97         [ #  # ]:          0 :     std::ofstream elem_file;
      98         [ #  # ]:          0 :     std::ofstream ans_file;
      99                 :            : 
     100                 :            :     // get base filename from filename.ans
     101         [ #  # ]:          0 :     std::string temp_string;
     102         [ #  # ]:          0 :     std::string base_string;
     103         [ #  # ]:          0 :     base_string.assign( file_name );
     104 [ #  # ][ #  # ]:          0 :     base_string.replace( base_string.find_last_of( ".ans" ) - 3, 4, "" );
     105                 :            : 
     106                 :            :     // open node file for writing
     107 [ #  # ][ #  # ]:          0 :     temp_string = base_string + ".node";
     108 [ #  # ][ #  # ]:          0 :     node_file.open( temp_string.c_str() );
     109         [ #  # ]:          0 :     node_file.setf( std::ios::scientific, std::ios::floatfield );
     110         [ #  # ]:          0 :     node_file.precision( 13 );
     111                 :            : 
     112                 :            :     // open elem file for writing
     113 [ #  # ][ #  # ]:          0 :     temp_string = base_string + ".elem";
     114 [ #  # ][ #  # ]:          0 :     elem_file.open( temp_string.c_str() );
     115                 :            : 
     116                 :            :     // open ans file for writing
     117 [ #  # ][ #  # ]:          0 :     ans_file.open( file_name );
     118 [ #  # ][ #  # ]:          0 :     ans_file << "/prep7" << std::endl;
     119                 :            : 
     120                 :            :     // gather single output set
     121                 :          0 :     EntityHandle output_set = 0;
     122 [ #  # ][ #  # ]:          0 :     if( ent_handles && num_sets > 0 )
     123                 :            :     {
     124         [ #  # ]:          0 :         for( int i = 0; i < num_sets; i++ )
     125                 :            :         {
     126                 :            :             // from template, maybe can be removed
     127         [ #  # ]:          0 :             result = mbImpl->unite_meshset( output_set, ent_handles[i] );
     128         [ #  # ]:          0 :             if( result != MB_SUCCESS ) return result;
     129                 :            :         }
     130                 :            :     }
     131                 :            : 
     132                 :            :     // search for all nodes
     133         [ #  # ]:          0 :     Range node_range;
     134         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type( output_set, MBVERTEX, node_range, true );
     135         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     136                 :            : 
     137                 :            :     // Commented out until Seg Fault taken care of in gather_nodes...
     138                 :            :     // get any missing nodes which are needed for elements
     139                 :            :     // Range all_ent_range,missing_range;
     140                 :            :     // result=mbImpl->get_entities_by_handle(output_set,all_ent_range,true);
     141                 :            :     // if(result !=MB_SUCCESS) return result;
     142                 :            :     // result=mWriteIface->gather_nodes_from_elements(all_ent_range,0,missing_range);
     143                 :            :     // node_range.merge(missing_range);
     144                 :            : 
     145                 :            :     // write the nodes
     146                 :            :     double coord[3];
     147 [ #  # ][ #  # ]:          0 :     for( Range::iterator it = node_range.begin(); it != node_range.end(); ++it )
         [ #  # ][ #  # ]
                 [ #  # ]
     148                 :            :     {
     149         [ #  # ]:          0 :         EntityHandle node_handle = *it;
     150                 :            : 
     151         [ #  # ]:          0 :         result = mbImpl->get_coords( &node_handle, 1, coord );
     152         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     153                 :            : 
     154         [ #  # ]:          0 :         node_file.width( 8 );
     155 [ #  # ][ #  # ]:          0 :         node_file << mbImpl->id_from_handle( node_handle );
     156         [ #  # ]:          0 :         node_file.width( 20 );
     157         [ #  # ]:          0 :         node_file << coord[0];
     158         [ #  # ]:          0 :         node_file.width( 20 );
     159         [ #  # ]:          0 :         node_file << coord[1];
     160         [ #  # ]:          0 :         node_file.width( 20 );
     161 [ #  # ][ #  # ]:          0 :         node_file << coord[2] << std::endl;
     162                 :            :     }
     163                 :            : 
     164                 :            :     // update header to load nodes
     165 [ #  # ][ #  # ]:          0 :     ans_file << "nread," << base_string << ",node" << std::endl;
         [ #  # ][ #  # ]
     166                 :            : 
     167                 :            :     // search for all node sets (Dirichlet Sets)
     168         [ #  # ]:          0 :     Range node_mesh_sets;
     169                 :            :     int ns_id;
     170         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &mDirichletSetTag, NULL, 1, node_mesh_sets );
     171         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     172                 :            : 
     173 [ #  # ][ #  # ]:          0 :     for( Range::iterator ns_it = node_mesh_sets.begin(); ns_it != node_mesh_sets.end(); ++ns_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         result = mbImpl->tag_get_data( mDirichletSetTag, &( *ns_it ), 1, &ns_id );
     176         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     177         [ #  # ]:          0 :         std::vector< EntityHandle > node_vector;
     178 [ #  # ][ #  # ]:          0 :         result = mbImpl->get_entities_by_handle( *ns_it, node_vector, true );
     179         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     180                 :            :         // for every nodeset found, cycle through nodes in set:
     181 [ #  # ][ #  # ]:          0 :         for( std::vector< EntityHandle >::iterator node_it = node_vector.begin(); node_it != node_vector.end();
                 [ #  # ]
     182                 :            :              ++node_it )
     183                 :            :         {
     184 [ #  # ][ #  # ]:          0 :             int ns_node_id = mbImpl->id_from_handle( *node_it );
     185 [ #  # ][ #  # ]:          0 :             if( node_it == node_vector.begin() )
     186                 :            :             {
     187                 :            :                 // select first node in new list
     188 [ #  # ][ #  # ]:          0 :                 ans_file << "nsel,s,node,," << std::setw( 8 ) << ns_node_id << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     189                 :            :             }
     190                 :            :             else
     191                 :            :             {
     192                 :            :                 // append node to list
     193 [ #  # ][ #  # ]:          0 :                 ans_file << "nsel,a,node,," << std::setw( 8 ) << ns_node_id << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     194                 :            :             }
     195                 :            :         }
     196                 :            :         // create NS(#) nodeset
     197 [ #  # ][ #  # ]:          0 :         ans_file << "cm,NS" << ns_id << ",node" << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     198                 :          0 :     }
     199                 :            : 
     200                 :            :     // ANSYS Element format:
     201                 :            :     // I, J, K, L, M, N, O, P,etc... MAT, TYPE, REAL, SECNUM, ESYS, IEL
     202                 :            :     // I-P are nodes of element
     203                 :            :     // MAT = material number
     204                 :            :     // TYPE = Element type number
     205                 :            :     // REAL = Real constant set number
     206                 :            :     // SECNUM = section attribute number
     207                 :            :     // ESYS = coordinate system for nodes
     208                 :            :     // IEL = element # (unique?)
     209                 :            :     // For all nodes past 8, write on second line
     210                 :            : 
     211                 :            :     // Write all MBTET elements
     212         [ #  # ]:          0 :     Range tet_range;
     213         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type( output_set, MBTET, tet_range, true );
     214         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     215 [ #  # ][ #  # ]:          0 :     for( Range::iterator elem_it = tet_range.begin(); elem_it != tet_range.end(); ++elem_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     216                 :            :     {
     217         [ #  # ]:          0 :         EntityHandle elem_handle = *elem_it;
     218         [ #  # ]:          0 :         int elem_id              = mbImpl->id_from_handle( elem_handle );
     219         [ #  # ]:          0 :         std::vector< EntityHandle > conn;
     220         [ #  # ]:          0 :         result = mbImpl->get_connectivity( &elem_handle, 1, conn, false );
     221         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     222                 :            :         // make sure 4 or 10 node tet
     223 [ #  # ][ #  # ]:          0 :         if( conn.size() != 4 && conn.size() != 10 )
                 [ #  # ]
     224                 :            :         {
     225         [ #  # ]:          0 :             std::cout << "Support not added for element type. \n";
     226                 :          0 :             return MB_FAILURE;
     227                 :            :         }
     228                 :            :         // write information for 4 node tet
     229         [ #  # ]:          0 :         if( conn.size() == 4 )
     230                 :            :         {
     231 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[0] << std::setw( 8 ) << conn[1];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     232 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[2] << std::setw( 8 ) << conn[2];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     233 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[3] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     234 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[3] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     235                 :            : 
     236 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << MATDefault << std::setw( 8 ) << ETSolid45;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     237 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "1" << std::setw( 8 ) << "1";
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     238 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "0" << std::setw( 8 ) << elem_id;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     239         [ #  # ]:          0 :             elem_file << std::endl;
     240                 :            :         }
     241                 :            : 
     242                 :            :         // write information for 10 node tet
     243         [ #  # ]:          0 :         if( conn.size() == 10 )
     244                 :            :         {
     245 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[0] << std::setw( 8 ) << conn[1];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     246 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[2] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     247 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[4] << std::setw( 8 ) << conn[5];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     248 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[6] << std::setw( 8 ) << conn[7];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << MATDefault << std::setw( 8 ) << ETSolid92;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     251 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "1" << std::setw( 8 ) << "1";
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     252 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "0" << std::setw( 8 ) << elem_id;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     253         [ #  # ]:          0 :             elem_file << std::endl;
     254                 :            : 
     255 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[8] << std::setw( 8 ) << conn[9];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     256 [ #  # ][ #  # ]:          0 :             elem_file << std::endl;
     257                 :            :         }
     258                 :          0 :     }
     259                 :            : 
     260                 :            :     // Write all MBHEX elements
     261         [ #  # ]:          0 :     Range hex_range;
     262         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type( output_set, MBHEX, hex_range, true );
     263         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     264 [ #  # ][ #  # ]:          0 :     for( Range::iterator elem_it = hex_range.begin(); elem_it != hex_range.end(); ++elem_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     265                 :            :     {
     266         [ #  # ]:          0 :         EntityHandle elem_handle = *elem_it;
     267         [ #  # ]:          0 :         int elem_id              = mbImpl->id_from_handle( elem_handle );
     268         [ #  # ]:          0 :         std::vector< EntityHandle > conn;
     269         [ #  # ]:          0 :         result = mbImpl->get_connectivity( &elem_handle, 1, conn, false );
     270         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     271                 :            :         // make sure supported hex type
     272 [ #  # ][ #  # ]:          0 :         if( conn.size() != 8 && conn.size() != 20 )
                 [ #  # ]
     273                 :            :         {
     274         [ #  # ]:          0 :             std::cout << "Support not added for element type. \n";
     275                 :          0 :             return MB_FAILURE;
     276                 :            :         }
     277                 :            : 
     278                 :            :         // write information for 8 node hex
     279         [ #  # ]:          0 :         if( conn.size() == 8 )
     280                 :            :         {
     281 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[0] << std::setw( 8 ) << conn[1];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     282 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[2] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     283 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[4] << std::setw( 8 ) << conn[5];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     284 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[6] << std::setw( 8 ) << conn[7];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     285                 :            : 
     286 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << MATDefault << std::setw( 8 ) << ETSolid45;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     287 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "1" << std::setw( 8 ) << "1";
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     288 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "0" << std::setw( 8 ) << elem_id;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     289         [ #  # ]:          0 :             elem_file << std::endl;
     290                 :            :         }
     291                 :            : 
     292                 :            :         // write information for 20 node hex
     293         [ #  # ]:          0 :         if( conn.size() == 20 )
     294                 :            :         {
     295                 :            : 
     296 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[4] << std::setw( 8 ) << conn[5];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     297 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[1] << std::setw( 8 ) << conn[0];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     298 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[7] << std::setw( 8 ) << conn[6];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     299 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[2] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     300                 :            : 
     301 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << MATDefault << std::setw( 8 ) << ETSolid95;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     302 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "1" << std::setw( 8 ) << "1";
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     303 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "0" << std::setw( 8 ) << elem_id;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     304         [ #  # ]:          0 :             elem_file << std::endl;
     305                 :            : 
     306 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[16] << std::setw( 8 ) << conn[13];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     307 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[8] << std::setw( 8 ) << conn[12];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     308 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[18] << std::setw( 8 ) << conn[14];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     309 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[10] << std::setw( 8 ) << conn[15];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     310 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[19] << std::setw( 8 ) << conn[17];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     311 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[9] << std::setw( 8 ) << conn[11];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     312 [ #  # ][ #  # ]:          0 :             elem_file << std::endl;
     313                 :            :         }
     314                 :          0 :     }
     315                 :            :     // Write all MBPRISM elements
     316         [ #  # ]:          0 :     Range prism_range;
     317         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type( output_set, MBPRISM, prism_range, true );
     318         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     319 [ #  # ][ #  # ]:          0 :     for( Range::iterator elem_it = prism_range.begin(); elem_it != prism_range.end(); ++elem_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     320                 :            :     {
     321         [ #  # ]:          0 :         EntityHandle elem_handle = *elem_it;
     322         [ #  # ]:          0 :         int elem_id              = mbImpl->id_from_handle( elem_handle );
     323         [ #  # ]:          0 :         std::vector< EntityHandle > conn;
     324         [ #  # ]:          0 :         result = mbImpl->get_connectivity( &elem_handle, 1, conn, false );
     325         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     326                 :            :         // make sure supported prism type
     327         [ #  # ]:          0 :         if( conn.size() != 6 )
     328                 :            :         {
     329         [ #  # ]:          0 :             std::cout << "Support not added for element type. \n";
     330                 :          0 :             return MB_FAILURE;
     331                 :            :         }
     332                 :            : 
     333                 :            :         // write information for 6 node prism
     334         [ #  # ]:          0 :         if( conn.size() == 6 )
     335                 :            :         {
     336 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[0] << std::setw( 8 ) << conn[3];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     337 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[4] << std::setw( 8 ) << conn[4];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     338 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[1] << std::setw( 8 ) << conn[2];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     339 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << conn[5] << std::setw( 8 ) << conn[5];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     340                 :            : 
     341 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << MATDefault << std::setw( 8 ) << ETSolid45;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     342 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "1" << std::setw( 8 ) << "1";
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     343 [ #  # ][ #  # ]:          0 :             elem_file << std::setw( 8 ) << "0" << std::setw( 8 ) << elem_id;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     344 [ #  # ][ #  # ]:          0 :             elem_file << std::endl;
     345                 :            :         }
     346                 :          0 :     }
     347                 :            : 
     348                 :            :     // create element types (for now writes all, even if not used)
     349 [ #  # ][ #  # ]:          0 :     ans_file << "et," << ETSolid45 << ",SOLID45" << std::endl;
         [ #  # ][ #  # ]
     350 [ #  # ][ #  # ]:          0 :     ans_file << "et," << ETSolid92 << ",SOLID92" << std::endl;
         [ #  # ][ #  # ]
     351 [ #  # ][ #  # ]:          0 :     ans_file << "et," << ETSolid95 << ",SOLID95" << std::endl;
         [ #  # ][ #  # ]
     352                 :            : 
     353                 :            :     // xxx pyramids, other elements later...
     354                 :            : 
     355                 :            :     // write header to load elements
     356 [ #  # ][ #  # ]:          0 :     ans_file << "eread," << base_string << ",elem" << std::endl;
         [ #  # ][ #  # ]
     357                 :            : 
     358                 :            :     // search for all side sets (Neumann)
     359         [ #  # ]:          0 :     Range side_mesh_sets;
     360                 :            :     int ss_id;
     361         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &mNeumannSetTag, NULL, 1, side_mesh_sets );
     362         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     363                 :            :     // cycle through all sets found
     364 [ #  # ][ #  # ]:          0 :     for( Range::iterator ss_it = side_mesh_sets.begin(); ss_it != side_mesh_sets.end(); ++ss_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     365                 :            :     {
     366 [ #  # ][ #  # ]:          0 :         result = mbImpl->tag_get_data( mNeumannSetTag, &( *ss_it ), 1, &ss_id );
     367         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     368         [ #  # ]:          0 :         std::vector< EntityHandle > elem_vector;
     369 [ #  # ][ #  # ]:          0 :         result = mbImpl->get_entities_by_handle( *ss_it, elem_vector, true );
     370         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     371                 :            : 
     372                 :            :         // cycle through elements in current side set
     373 [ #  # ][ #  # ]:          0 :         for( std::vector< EntityHandle >::iterator elem_it = elem_vector.begin(); elem_it != elem_vector.end();
                 [ #  # ]
     374                 :            :              ++elem_it )
     375                 :            :         {
     376         [ #  # ]:          0 :             EntityHandle elem_handle = *elem_it;
     377                 :            : 
     378                 :            :             // instead of selecting current element in set, select its nodes...
     379         [ #  # ]:          0 :             std::vector< EntityHandle > conn;
     380         [ #  # ]:          0 :             result = mbImpl->get_connectivity( &elem_handle, 1, conn );
     381         [ #  # ]:          0 :             if( result != MB_SUCCESS ) return result;
     382 [ #  # ][ #  # ]:          0 :             if( elem_it == elem_vector.begin() )
     383                 :            :             {
     384 [ #  # ][ #  # ]:          0 :                 ans_file << "nsel,s,node,," << std::setw( 8 ) << conn[0] << std::endl;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     385         [ #  # ]:          0 :                 for( unsigned int i = 1; i < conn.size(); i++ )
     386                 :            :                 {
     387 [ #  # ][ #  # ]:          0 :                     ans_file << "nsel,a,node,," << std::setw( 8 ) << conn[i] << std::endl;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     388                 :            :                 }
     389                 :            :             }
     390                 :            :             else
     391                 :            :             {
     392 [ #  # ][ #  # ]:          0 :                 for( unsigned int i = 0; i < conn.size(); i++ )
     393                 :            :                 {
     394 [ #  # ][ #  # ]:          0 :                     ans_file << "nsel,a,node,," << std::setw( 8 ) << conn[i] << std::endl;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     395                 :            :                 }
     396                 :            :             }
     397                 :          0 :         }
     398                 :            :         // create SS(#) node set
     399 [ #  # ][ #  # ]:          0 :         ans_file << "cm,SS" << ss_id << ",node" << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     400                 :          0 :     }
     401                 :            : 
     402                 :            :     // Gather all element blocks
     403         [ #  # ]:          0 :     Range matset;
     404                 :            :     int mat_id;
     405         [ #  # ]:          0 :     result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &mMaterialSetTag, NULL, 1, matset );
     406         [ #  # ]:          0 :     if( result != MB_SUCCESS ) return result;
     407                 :            :     // cycle through all elem blocks
     408 [ #  # ][ #  # ]:          0 :     for( Range::iterator mat_it = matset.begin(); mat_it != matset.end(); ++mat_it )
         [ #  # ][ #  # ]
                 [ #  # ]
     409                 :            :     {
     410         [ #  # ]:          0 :         EntityHandle matset_handle = *mat_it;
     411         [ #  # ]:          0 :         result                     = mbImpl->tag_get_data( mMaterialSetTag, &matset_handle, 1, &mat_id );
     412         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     413         [ #  # ]:          0 :         std::vector< EntityHandle > mat_vector;
     414 [ #  # ][ #  # ]:          0 :         result = mbImpl->get_entities_by_handle( *mat_it, mat_vector, true );
     415         [ #  # ]:          0 :         if( result != MB_SUCCESS ) return result;
     416                 :            :         // cycle through elements in current mat set
     417 [ #  # ][ #  # ]:          0 :         for( std::vector< EntityHandle >::iterator elem_it = mat_vector.begin(); elem_it != mat_vector.end();
                 [ #  # ]
     418                 :            :              ++elem_it )
     419                 :            :         {
     420         [ #  # ]:          0 :             EntityHandle elem_handle = *elem_it;
     421         [ #  # ]:          0 :             int elem_id              = mbImpl->id_from_handle( elem_handle );
     422 [ #  # ][ #  # ]:          0 :             if( elem_it == mat_vector.begin() )
     423 [ #  # ][ #  # ]:          0 :             { ans_file << "esel,s,elem,," << std::setw( 8 ) << elem_id << std::endl; }
         [ #  # ][ #  # ]
                 [ #  # ]
     424                 :            :             else
     425                 :            :             {
     426 [ #  # ][ #  # ]:          0 :                 ans_file << "esel,a,elem,," << std::setw( 8 ) << elem_id << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     427                 :            :             }
     428                 :            :         }
     429                 :            :         // for each matset, write block command
     430 [ #  # ][ #  # ]:          0 :         ans_file << "cm,EB" << mat_id << ",elem" << std::endl;
         [ #  # ][ #  # ]
                 [ #  # ]
     431                 :          0 :     }
     432                 :            : 
     433                 :            :     // close all file streams
     434         [ #  # ]:          0 :     node_file.close();
     435         [ #  # ]:          0 :     elem_file.close();
     436         [ #  # ]:          0 :     ans_file.close();
     437                 :            : 
     438                 :          0 :     return MB_SUCCESS;
     439                 :            : }
     440                 :            : 
     441 [ +  - ][ +  - ]:        228 : }  // namespace moab

Generated by: LCOV version 1.11