Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makemblock.cpp
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 /*
54 Main routine for grid split-- read the input
55 mesh file, write out the .mblock files.
56 
57 Orion Sky Lawlor, olawlor@acm.org, 6/7/2001
58 */
59 #include <stdio.h>
60 #include "makeflo.h"
61 
62 void checkError(const char *errCode) {
63  if (errCode==NULL) return; //No problem
64  fprintf(stderr,"FATAL ERROR! %s\n",errCode);
65  exit(1);
66 }
67 
68 void printUsage(const char *why)
69 {
70  printf("Usage: makemblock \n"
71  " <.grd, or .msh mesh; and .inp and .bc file> \n"
72  " <# output chunks> <output file prefix>\n"
73  " Makemblock reads a mesh (first parameter) and boundary condition\n"
74  "(.inp) list, partitions the mesh into the requested number of\n"
75  "chunks, and writes out mblock input files.\n"
76  " The mesh formats supported are:\n"
77  "<*.grd> A Gridgen ASCII double-precision mesh description\n"
78  "<*.msh> A double-precision binary Rocflo mesh file\n"
79  "<*.hdf> A double-precision 3D HDF mesh file\n"
80  "<*.mblk> A double-precision 3D Mblock mesh file\n"
81  " When the mesh consists of multiple files, give only the name of\n"
82  "the first file (e.g., 'tstflo_001.hdf'). The number of blocks and\n"
83  "numeric format will be automatically determined.\n"
84  "Part of the Charm++ Tools. Version " MAKEFLO_VERSION "\n"
85  );
86  if (why!=NULL)
87  printf("Exiting> %s\n",why);
88  exit(1);
89 }
90 
92 
93 int main(int argc,char *argv[])
94 {
95 //Parse the command line arguments
96  if (argc<4) printUsage("Not enough command-line arguments");
97  int curArg=1;
98 
99  while (argv[curArg][0]=='-') {
100  if (0==strcmp(argv[curArg],"-2D")) {
101  parameters.skipAxis=2; //Don't bother about the z axis.
102  curArg++;
103  }
104  else if (0==strcmp(argv[curArg],"-top")) {
105  parameters.topologyOnly=1; //Only write .bblk
106  curArg++;
107  }
108  else
109  printUsage("Unrecongized parameter");
110  }
111 
112  if (curArg+3!=argc) printUsage("Too many arguments");
113  const char *inMesh=argv[curArg+0];
114  string inpFile=replaceExtention(argv[curArg+0],".inp");
115  int nPieces=atoi(argv[curArg+1]);
116  const char *outMesh=argv[curArg+2];
117 
118  vector<block *> blocks;
119 
120 //Read the blocks of the mesh
121  { //<- scoping block so r's destructor gets called
122  blockReader r(blocks);
123  checkError(r.read(inMesh));
124  printf("Mesh file read successfully.\n");
125  }
126 
127 //Read the boundary conditions
128  checkError(readBoundaries(blocks,inpFile.c_str()));
129  printf("Boundary conditions read successfully.\n");
130 
131 //Split the blocks (for greater parallelism)
132  checkError(splitBlocks(blocks,nPieces));
133  printf("Split blocks for %d PEs (%d blocks generated).\n",nPieces,blocks.size());
134 
135 //Build the block faces & associate all shared nodes
136  buildFaces(blocks,false);
137  printf("Nodes matched successfully.\n");
138 
139 //Write out the blocks
140  checkError(writeMblock(blocks,outMesh));
141  printf("Block files written successfully\n");
142  return 0;
143 }
144 
145 
146 
147 
148 
149 
150 
int skipAxis
Definition: makeflo.h:92
const char * writeMblock(vector< block * > &blocks, const char *outMblock)
int topologyOnly
Definition: makeflo.h:93
void printUsage(const char *why)
Definition: makeflo.cpp:68
string replaceExtention(const string &a, const string &newSuffix)
void checkError(const char *errCode)
Definition: makeflo.cpp:62
const char * splitBlocks(vector< block * > &blocks, int nPieces)
Definition: split.cpp:205
bool blocks
Input data is block-structured grid.
Definition: hdf2pltV2.C:51
int main(int argc, char *argv[])
Definition: blastest.C:94
const char * read(const char *gridFile)
Definition: read.cpp:140
makefloParam parameters
Definition: makeflo.cpp:101
#define MAKEFLO_VERSION
Definition: makeflo.h:65
const char * readBoundaries(vector< block * > &blocks, const char *inMesh)
Definition: readinp.cpp:135
void buildFaces(vector< block * > &blocks, bool buildTypeTwo)
Definition: buildface.cpp:123