Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makeflo.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 .flo file.
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: makeflo [ -splitaxis <-1, 0, 1, or 2)> ]\n"
71  " [ -splitrcb ] [ -splithalf ]\n"
72  " [ -multilevel <maximum level> ]\n"
73  " <.grd, .grdb, .msh, or .hdf; and .inp and .bc file> \n"
74  " <# PEs> <.flo or .top output file> <.msh or .hdf output file>\n"
75  "\n"
76  " Makeflo reads a mesh (first parameter) and boundary condition\n"
77  "(.inp) list and description (.bc), partitions the mesh into the\n"
78  "requested number of processors, and writes out a rocflo control\n"
79  "file (.flo or .top) and the partitioned mesh (last parameter).\n"
80  " The mesh formats supported are:\n"
81  "<*.grd> A Gridgen ASCII double-precision mesh description\n"
82  "<*.msh> A double-precision binary Rocflo mesh file\n"
83  "<*.hdf> A double-precision 3D HDF mesh file\n"
84  " When the mesh consists of multiple files, give only the name of\n"
85  "the first file (e.g., 'tstflo_001.hdf'). The number of blocks and\n"
86  "numeric format will be automatically determined.\n"
87  "\n"
88  "Options:\n"
89  " -splitaxis <-1, 0, 1, or 2)>: axis to split along. \n"
90  " -splitrcb: split using recursive bisection.\n"
91  " -multilevel <maximum level>: number of multigrid levels to create \n"
92  " -splithalf: split every block in half, <# PEs> is ignored.\n"
93  "\n"
94  "Part of the CSAR Tools. Version " MAKEFLO_VERSION "\n"
95  );
96  if (why!=NULL)
97  printf("Exiting> %s\n",why);
98  exit(1);
99 }
100 
102 
103 int main(int argc,char *argv[])
104 {
105 //Parse the command line arguments
106  if (argc<5) printUsage("Not enough command-line arguments");
107  int curArg=1;
108  while (argv[curArg][0]=='-')
109  {//Parse a flag argument
110  const char *flag=argv[curArg++];
111  if (0==strcmp(flag,"-h") ||
112  0==strcmp(flag,"-?") ||
113  0==strcmp(flag,"--help"))
114  printUsage(NULL);
115  else if (0==strcmp(flag,"-splitaxis")) {
116  if (1!=sscanf(argv[curArg++],"%d",&parameters.splitAxis))
117  printUsage("Must pass 0,1, or 2 to -splitaxis");
118  }
119  else if (0==strcmp(flag,"-splitrcb")) {
120  parameters.splitRCB=1;
121  }
122  else if (0==strcmp(flag,"-splithalf")) {
123  parameters.splithalf=1;
124  }
125  else if (0==strcmp(flag,"-multilevel")) {
126  int level=0;
127  if ((1!=sscanf(argv[curArg++],"%d",&level))||(level<=0))
128  printUsage("Must pass a positive integer to -multilevel");
129  parameters.setLevel(level);
130  }
131  else printUsage("Unrecognized flag");
132  }
133  if (curArg+4!=argc) printUsage("Too many arguments");
134  const char *inMesh=argv[curArg+0];
135  string inpFile=replaceExtention(argv[curArg+0],".inp");
136  int nPieces=atoi(argv[curArg+1]);
137  const char *floFile=argv[curArg+2];
138  const char *outMesh=argv[curArg+3];
139 
140  bool forFlo;
141  const char *bcExt="?";
142  if (endsWith(floFile,".flo")) {
143  forFlo=true;
144  bcExt=".bc";
145  }
146  else if (endsWith(floFile,".top")) {
147  forFlo=false;
148  bcExt=".bcmp";
149  }
150  else {
151  printf("UNRECOGNIZED TOPOLOGY NAME: '%s'\n",floFile);
152  exit(1);
153  }
154  string bcFile=replaceExtention(argv[curArg+0],bcExt);
155 
156  vector<block *> blocks;
157 
158 //Read the blocks of the mesh
159  { //<- scoping block so r's destructor gets called
160  blockReader r(blocks);
161  checkError(r.read(inMesh));
162  printf("Mesh file read successfully.\n");
163  }
164 
165 // Check the quality of the mesh
166  for (unsigned int i=0;i<blocks.size();i++)
167  checkQuality(*blocks[i]);
168 
169 //Read the boundary conditions
170  checkError(readBoundaries(blocks,inpFile.c_str()));
171  printf("Boundary conditions read successfully.\n");
172 
173  if (parameters.splithalf) {
174  // split in half for every block
175  nPieces = blocks.size()*2;
176  printf("Split every block in half for %d pieces.\n", nPieces);
177  }
178 
179 //Split the blocks (for greater parallelism)
180  checkError(splitBlocks(blocks,nPieces));
181  printf("Split blocks for %d PEs (%d blocks generated).\n",
182  nPieces,(int)blocks.size());
183 
184 //Build the block faces & associate all shared nodes
185  buildFaces(blocks,forFlo);
186  printf("Nodes matched successfully.\n");
187 
188 //Write out the block patches to the topology file
189  if (forFlo) {
190  checkError(writeFlo(blocks,nPieces,bcFile.c_str(),floFile));
191  printf(".flo file written successfully\n");
192  } else /*forTop*/ {
193  checkError(writeTop(blocks,bcFile.c_str(),floFile));
194  printf(".top file written successfully\n");
195  }
196 
197 //Write out the blocks themselves
198  checkError(writeBlocks(blocks,outMesh));
199  printf("Program finished successfully\n");
200  return 0;
201 }
202 
203 
204 
205 
206 
207 
208 
int splithalf
Definition: makeflo.h:97
void setLevel(int n)
Definition: makeflo.h:111
int splitAxis
Definition: makeflo.h:95
const char * writeBlocks(vector< block * > &blocks, const char *outMesh)
Definition: write.cpp:147
void printUsage(const char *why)
Definition: makeflo.cpp:68
bool endsWith(const char *a, const char *suffix)
string replaceExtention(const string &a, const string &newSuffix)
const char * writeTop(vector< block * > &blocks, const char *inBcs, const char *out)
Definition: writetop.cpp:252
void checkQuality(const block &b)
Definition: volume.cpp:74
void checkError(const char *errCode)
Definition: makeflo.cpp:62
blockLoc i
Definition: read.cpp:79
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
const char * writeFlo(vector< block * > &blocks, int nPEs, const char *inBcs, const char *out)
Definition: writeflo.cpp:230
int splitRCB
Definition: makeflo.h:96
void buildFaces(vector< block * > &blocks, bool buildTypeTwo)
Definition: buildface.cpp:123