1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//-----------------------------------C++-------------------------------------//
// File: src/algs/meshkit/AssyGen.hpp
//
// Brief: AssyGen class definition:
//        Creates reactor assembly geometry (ACIS or OCC format) and cubit mesh script as specified in a user defined input
//         class, AssyGen
//---------------------------------------------------------------------------// 

#ifndef MESHKIT_ASSYGEN_HPP
#define MESHKIT_ASSYGEN_HPP

#include <cassert>
#include <string>
#include <vector>
#include <set>

#include "meshkit/Types.hpp"
#include "meshkit/Error.hpp"
#include "meshkit/MeshScheme.hpp"
#include "meshkit/ModelEnt.hpp"
#include "meshkit/MKCore.hpp"
#include "meshkit/SizingFunction.hpp"
#include "meshkit/RegisterMeshOp.hpp"

#include "meshkit/LocalSet.hpp"
#include "meshkit/LocalTag.hpp"
#include "meshkit/Matrix.hpp"

#include "meshkit/iMesh.hpp"
//#include "meshkit/iGeom.hpp"
#include "iGeom.h"
#include "MBCN.h"

#include "meshkit/SimpleArray.hpp"

#include "meshkit/vectortemplate.hpp"
#include "meshkit/matrixtemplate.hpp"
#include "meshkit/pincell.hpp"
#include "meshkit/parser.hpp"
#include "meshkit/clock.hpp"

namespace MeshKit {

#define DEFAULT_TEST_FILE  "assygen_default"
#define TEST_FILE_NAME "assygen_default"

//#define CHECK( STR ) if (err != iBase_SUCCESS) return Print_Error( STR, err, geom, __FILE__, __LINE__ )

  enum ErrorStates {PINCELLS, INVALIDINPUT, EMAT, EGEOMTYPE, EGEOMENGINE, ENEGATIVE, EALIAS, EPIN, EUNEQUAL};

  class MKCore;

  class AssyGen : public MeshScheme
  {
  public:
    /* \brief Constructor
     *
     * Create a new AssyGen instance
     * \param impl the iGeom instance handle for the Geom
     */
    AssyGen(MKCore *mk, const MEntVector &me_vec);

    /* \brief Destructor
     */
    virtual ~AssyGen();

    enum ErrorStates {PINCELLS, INVALIDINPUT, EMAT, EGEOMTYPE, EGEOMENGINE, ENEGATIVE, EALIAS, EPIN, EUNEQUAL};

    /**\brief Get class name */
    static const char* name();

    /**\brief Function returning whether this scheme can mesh entities of t
     *        the specified dimension.
     *\param dim entity dimension
     */
    static bool can_mesh(iBase_EntityType dim);

    /** \brief Function returning whether this scheme can mesh the specified entity
     *
     * Used by MeshOpFactory to find scheme for an entity.
     * \param me ModelEnt being queried
     * \return If true, this scheme can mesh the specified ModelEnt
     */
    static bool can_mesh(ModelEnt *me);

    /**\brief Get list of mesh entity types that can be generated.
     *\return array terminated with \c moab::MBMAXTYPE
     */
    static const moab::EntityType* output_types();

    /** \brief Return the mesh entity types operated on by this scheme
     * \return array terminated with \c moab::MBMAXTYPE
     */
    virtual const moab::EntityType* mesh_types_arr() const;

    /** \brief Re-implemented here so we can check topological dimension of model_ent
     * \param model_ent ModelEnt being added
     */
    virtual bool add_modelent(ModelEnt *model_ent);

    //! Setup is a no-op, but must be provided since it's pure virtual
    virtual void setup_this();

    //! The only setup/execute function we need, since meshing vertices is trivial
    virtual void execute_this();

    /** \brief Prepare input/output files for reading/writing
     *  command line args and testdir for default test case
     */
    void PrepareIO (int argc, char *argv[], std::string TestDir);

    /** \brief Read the common.inp file
     *  common.inp is hardcoded name
     */
    void ReadCommonInp ();

    /** \brief Read the command based text input file
     *  input file
     */
    void ReadInputPhase1 ();

    /** \brief Keep reading input file and create
     *  input file
     */
    void ReadAndCreate ();

    /** \brief Create assygen input files
     *  based on material sets specified in master assygen input file
     */
    void CreateAssyGenInputFiles();

    /** \brief Name the surface created
     *  material name from input file, surface entity, name tag
     */
    void Name_Faces( const std::string sMatName, const iBase_EntityHandle body,<--- Function parameter 'sMatName' should be passed by reference.
		     iBase_TagHandle this_tag);

    /** \brief Move the assembly to the center
     *  direction
     */
    void Center_Assm( char&);

    /** \brief Section assembly
     *  direction, offset, reverse/forward
     */
    void Section_Assm ( char&, double&, const std::string);

    /** \brief Rotate assembly
     *  direction, angle
     */
    void Rotate_Assm ( char&, double&);

    /** \brief Move assembly
     *  X, Y, Z distance
     */
    void Move_Assm ( double&, double&, double&);

    /** \brief Create hexagonal assembly
     *  data from input file
     */
    void Create_HexAssm( std::string &);

    /** \brief Create cartesian or rectangular assembly
     *  data from input file 
     */
    void Create_CartAssm( std::string &);

    /** \brief Create outermost ducts
     *  data from input file 
     */
    void CreateOuterCovering();

    /** \brief Merge and impring the geometry creaed
     *  geometry created
     */
    void Imprint_Merge ();

    /** \brief Subtract the pins from innermost duct
     *  geometry entities
     */
    void Subtract_Pins ();

    /** \brief Get the top surface from 3D assembly geometry
     *  pins, ducts
     */
    void Create2DSurf();

    /** \brief Read pincell data
     *  input file
     */
    void ReadPinCellData( int i);

    /** \brief Create pincell i, pincell intersects the assembly
     *  i and location
     */
    void CreatePinCell_Intersect( int i, double dX,
				  double dY, double dZ);

    /** \brief Create pincell i
     *  i and location
     */
    void CreatePinCell( int i, double dX,
			double dY, double dZ);  

    /** \brief Write cubit journal file 
     *  information read from text based input file
     */
    void CreateCubitJournal();

    /** \brief Computes the location of the pincells in the assembly
     *  pin-number and location of the pincell
     */
    void ComputePinCentroid( int, CMatrix<std::string>, int, int,
                             double&, double&, double&);

  private:
    // iGeom Impl for calling geometry creation/manipulation operations
    iGeom *igeomImpl;

    // number of sides in the geometry
    int m_nSides;
  
    // file Input
    std::ifstream m_FileInput, m_FileCommon;
    
    // journal file Output
    std::ofstream m_FileOutput, m_SchemesFile, m_AssmInfo;

    // string for file names
    std::string m_szSmooth, m_szAssmInfo, m_szLogFile, m_szCommonFile, m_szFile, m_szInFile, m_szGeomFile,m_szJouFile, m_szSchFile;

    // matrix for holding pincell arrangement
    CMatrix<std::string> m_Assembly; 

    // matrix for holding verts coordinates used in tet-meshing
    CMatrix<double> m_dMTopSurfCoords; 

    // vector for duct specification 
    CMatrix<double> m_dMAssmPitch, m_dMAssmPitchX, m_dMAssmPitchY, m_dMXYAssm, m_dMZAssm;
  
    // vector for material names
    CVector<std::string> m_szAssmMat, m_szAssmMatAlias;
    CMatrix<std::string> m_szMMAlias;  

    // vector holding a pincell
    CVector<CPincell> m_Pincell; 

    CVector<double> m_dAxialSize, m_dBLMatBias;

    // string for geomtype, engine, meshtype
    std::string m_szEngine;
    std::string m_szGeomType;       
    std::string m_szMeshType;
    std::string m_szSideset; 
    std::vector<std::string> m_szDuctMats;
    // integers for vectors sizes, err etc
    int m_nAssemblyMat, m_nDimensions, m_nPincells , m_nAssmVol, m_nPin, m_nPinX, m_nPinY, err, m_nLineNumber, m_nPlanar,
      m_nNeumannSetId, m_nMaterialSetId, m_nDuct, m_nDuctNum, m_nJouFlag, m_nAssyGenInputFiles,  m_nTotalPincells;

    // doubles for pincell pitch, pi and mesh sizes resp.
    double m_dPitch, pi, m_dRadialSize, m_dTetMeshSize, m_dMergeTol, m_dZstart, m_dZend;
 
    // igeom related
    SimpleArray<iBase_EntityHandle> assms, in_pins;
    //iGeom_Instance geom;
    iBase_EntitySetHandle root_set;

 
    // error handlers
    void IOErrorHandler (ErrorStates) const;
    friend class CPincell;

    struct superblocks{
        int m_nSuperBlockId;
        std::string m_szSuperBlockAlias;
        int m_nNumSBContents;
        CVector<int> m_nSBContents;
    };

    int m_nSuperBlocks;
    CVector<superblocks> sb;
    int tmpSB;

    // parsing related
    std::string szInputString;
    std::string szComment;
    int MAXCHARS, MAXLINES;

    std::vector< std::vector<iBase_EntityHandle> > cp_inpins;

    CVector<std::string> m_szBLAssmMat;
    CVector<int> m_nListMatSet, m_nListNeuSet, m_nBLMatIntervals;

    int m_edgeInterval;
    int m_nStartpinid;
    std::string m_szInfo;
    std::string m_szMeshScheme;
    std::string pin_name;
    int m_nHblock;
    bool m_bCreateMatFiles;
    bool save_exodus;
    bool have_common;
    int com_run_count;
    int m_nBLAssemblyMat;
    std::string m_szInnerDuct;
  };

  inline const char* AssyGen::name()
  {
    return "AssyGen";
  }

  inline bool AssyGen::can_mesh(iBase_EntityType)
  {
    return false;
  }

  inline bool AssyGen::can_mesh(ModelEnt *)
  {
    return true;
  }

  inline const moab::EntityType* AssyGen::mesh_types_arr() const
  {
    return output_types();
  }

} // namespace MeshKit
#endif