MOAB: Mesh Oriented datABase  (version 5.4.1)
WriteTemplate.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 //-------------------------------------------------------------------------
00017 // Filename      : WriteTemplate.hpp
00018 //
00019 // Purpose       : ExodusII writer
00020 //
00021 // Special Notes : Lots of code taken from verde implementation
00022 //
00023 // Creator       : Corey Ernst
00024 //
00025 // Date          : 8/02
00026 //
00027 // Owner         : Corey Ernst
00028 //-------------------------------------------------------------------------
00029 
00030 #ifndef WRITETemplate_HPP
00031 #define WRITETemplate_HPP
00032 
00033 #ifndef IS_BUILDING_MB
00034 #error "WriteTemplate.hpp isn't supposed to be included into an application"
00035 #endif
00036 
00037 #include <vector>
00038 #include <string>
00039 
00040 #include "moab/Forward.hpp"
00041 #include "moab/Range.hpp"
00042 #include "moab/ExoIIInterface.hpp"
00043 #include "moab/WriterIface.hpp"
00044 
00045 namespace moab
00046 {
00047 
00048 class WriteUtilIface;
00049 
00050 class WriteTemplate : public WriterIface
00051 {
00052 
00053   public:
00054     //! Constructor
00055     WriteTemplate( Interface* impl );
00056 
00057     //! Destructor
00058     virtual ~WriteTemplate();
00059 
00060     static WriterIface* factory( Interface* );
00061 
00062     //! writes out a file
00063     ErrorCode write_file( const char* file_name,
00064                           const bool overwrite,
00065                           const FileOptions& opts,
00066                           const EntityHandle* output_list,
00067                           const int num_sets,
00068                           const std::vector< std::string >& qa_list,
00069                           const Tag* tag_list  = NULL,
00070                           int num_tags         = 0,
00071                           int export_dimension = 3 );
00072 
00073     //! struct used to hold data for each block to be output; used by
00074     //! initialize_file to initialize the file header for increased speed
00075     struct MaterialSetData
00076     {
00077         int id;
00078         int number_elements;
00079         int number_nodes_per_element;
00080         int number_attributes;
00081         ExoIIElementType element_type;
00082         EntityType moab_type;
00083         Range* elements;
00084     };
00085 
00086     //! struct used to hold data for each nodeset to be output; used by
00087     //! initialize_file to initialize the file header for increased speed
00088     struct DirichletSetData
00089     {
00090         int id;
00091         int number_nodes;
00092         std::vector< EntityHandle > nodes;
00093         std::vector< double > node_dist_factors;
00094     };
00095 
00096     //! struct used to hold data for each sideset to be output; used by
00097     //! initialize_file to initialize the file header for increased speed
00098     struct NeumannSetData
00099     {
00100         int id;
00101         int number_elements;
00102         std::vector< EntityHandle > elements;
00103         std::vector< int > side_numbers;
00104         EntityHandle mesh_set_handle;
00105     };
00106 
00107   protected:
00108     //! number of dimensions in this file
00109     // int number_dimensions();
00110 
00111     //! open a file for writing
00112     ErrorCode open_file( const char* filename );
00113 
00114     //! contains the general information about a mesh
00115     class MeshInfo
00116     {
00117       public:
00118         unsigned int num_dim;
00119         unsigned int num_nodes;
00120         unsigned int num_elements;
00121         unsigned int num_matsets;
00122         unsigned int num_dirsets;
00123         unsigned int num_neusets;
00124         Range nodes;
00125 
00126         MeshInfo()
00127             : num_dim( 0 ), num_nodes( 0 ), num_elements( 0 ), num_matsets( 0 ), num_dirsets( 0 ), num_neusets( 0 )
00128         {
00129         }
00130     };
00131 
00132   private:
00133     //! interface instance
00134     Interface* mbImpl;
00135     WriteUtilIface* mWriteIface;
00136 
00137     //! file name
00138     std::string fileName;
00139 
00140     //! Cached tags for reading.  Note that all these tags are defined when the
00141     //! core is initialized.
00142     Tag mMaterialSetTag;
00143     Tag mDirichletSetTag;
00144     Tag mNeumannSetTag;
00145     Tag mGlobalIdTag;
00146 
00147     Tag mEntityMark;  // used to say whether an entity will be exported
00148 
00149     ErrorCode gather_mesh_information( MeshInfo& mesh_info,
00150                                        std::vector< MaterialSetData >& matset_info,
00151                                        std::vector< NeumannSetData >& neuset_info,
00152                                        std::vector< DirichletSetData >& dirset_info,
00153                                        std::vector< EntityHandle >& matsets,
00154                                        std::vector< EntityHandle >& neusets,
00155                                        std::vector< EntityHandle >& dirsets );
00156 
00157     ErrorCode initialize_file( MeshInfo& mesh_info );
00158 
00159     ErrorCode write_nodes( const int num_nodes, const Range& nodes, const int dimension );
00160 
00161     ErrorCode write_matsets( MeshInfo& mesh_info,
00162                              std::vector< MaterialSetData >& matset_data,
00163                              std::vector< NeumannSetData >& neuset_data );
00164 
00165     ErrorCode get_valid_sides( Range& elems, const int sense, WriteTemplate::NeumannSetData& neuset_data );
00166 
00167     void reset_matset( std::vector< MaterialSetData >& matset_info );
00168 
00169     ErrorCode get_neuset_elems( EntityHandle neuset, int current_sense, Range& forward_elems, Range& reverse_elems );
00170 };
00171 
00172 }  // namespace moab
00173 
00174 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines