MOAB: Mesh Oriented datABase  (version 5.2.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, const bool overwrite, const FileOptions& opts,
00064                           const EntityHandle* output_list, const int num_sets,
00065                           const std::vector< std::string >& qa_list, const Tag* tag_list = NULL, int num_tags = 0,
00066                           int export_dimension = 3 );
00067 
00068     //! struct used to hold data for each block to be output; used by
00069     //! initialize_file to initialize the file header for increased speed
00070     struct MaterialSetData
00071     {
00072         int id;
00073         int number_elements;
00074         int number_nodes_per_element;
00075         int number_attributes;
00076         ExoIIElementType element_type;
00077         EntityType moab_type;
00078         Range* elements;
00079     };
00080 
00081     //! struct used to hold data for each nodeset to be output; used by
00082     //! initialize_file to initialize the file header for increased speed
00083     struct DirichletSetData
00084     {
00085         int id;
00086         int number_nodes;
00087         std::vector< EntityHandle > nodes;
00088         std::vector< double > node_dist_factors;
00089     };
00090 
00091     //! struct used to hold data for each sideset to be output; used by
00092     //! initialize_file to initialize the file header for increased speed
00093     struct NeumannSetData
00094     {
00095         int id;
00096         int number_elements;
00097         std::vector< EntityHandle > elements;
00098         std::vector< int > side_numbers;
00099         EntityHandle mesh_set_handle;
00100     };
00101 
00102   protected:
00103     //! number of dimensions in this file
00104     // int number_dimensions();
00105 
00106     //! open a file for writing
00107     ErrorCode open_file( const char* filename );
00108 
00109     //! contains the general information about a mesh
00110     class MeshInfo
00111     {
00112       public:
00113         unsigned int num_dim;
00114         unsigned int num_nodes;
00115         unsigned int num_elements;
00116         unsigned int num_matsets;
00117         unsigned int num_dirsets;
00118         unsigned int num_neusets;
00119         Range nodes;
00120 
00121         MeshInfo()
00122             : num_dim( 0 ), num_nodes( 0 ), num_elements( 0 ), num_matsets( 0 ), num_dirsets( 0 ), num_neusets( 0 )
00123         {
00124         }
00125     };
00126 
00127   private:
00128     //! interface instance
00129     Interface* mbImpl;
00130     WriteUtilIface* mWriteIface;
00131 
00132     //! file name
00133     std::string fileName;
00134 
00135     //! Cached tags for reading.  Note that all these tags are defined when the
00136     //! core is initialized.
00137     Tag mMaterialSetTag;
00138     Tag mDirichletSetTag;
00139     Tag mNeumannSetTag;
00140     Tag mGlobalIdTag;
00141 
00142     Tag mEntityMark;  // used to say whether an entity will be exported
00143 
00144     ErrorCode gather_mesh_information( MeshInfo& mesh_info, std::vector< MaterialSetData >& matset_info,
00145                                        std::vector< NeumannSetData >& neuset_info,
00146                                        std::vector< DirichletSetData >& dirset_info,
00147                                        std::vector< EntityHandle >& matsets, std::vector< EntityHandle >& neusets,
00148                                        std::vector< EntityHandle >& dirsets );
00149 
00150     ErrorCode initialize_file( MeshInfo& mesh_info );
00151 
00152     ErrorCode write_nodes( const int num_nodes, const Range& nodes, const int dimension );
00153 
00154     ErrorCode write_matsets( MeshInfo& mesh_info, std::vector< MaterialSetData >& matset_data,
00155                              std::vector< NeumannSetData >& neuset_data );
00156 
00157     ErrorCode get_valid_sides( Range& elems, const int sense, WriteTemplate::NeumannSetData& neuset_data );
00158 
00159     void reset_matset( std::vector< MaterialSetData >& matset_info );
00160 
00161     ErrorCode get_neuset_elems( EntityHandle neuset, int current_sense, Range& forward_elems, Range& reverse_elems );
00162 };
00163 
00164 }  // namespace moab
00165 
00166 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines