Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
surftest2.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: surftest2.C,v 1.3 2008/12/06 08:43:24 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include "surfbasic.h"
27 
28 #include <cstdio>
29 #include <iostream>
30 #include <fstream>
31 #include <vector>
32 #include <algorithm>
33 #include <cstring>
34 #include <cassert>
35 
36 using namespace std;
37 
38 // ==== Routines for creating mesh information
39 void init_structured_mesh( double coors[][3], int nrow, int ncol,
40  int rank, int nproc, int check=1) {
41  // consider the processors as a 2*(nproc/2) grid
42  int proc_col=nproc;
43  if (nproc%2 ==0) {
44  proc_col=nproc/2;
45  }
46  else {
47  proc_col=nproc;
48  }
49  int row=rank/proc_col, col=rank%proc_col;
50 
51  const double width=300./(nrow-1), length=300./(ncol-1);
52 
53  double x0 = col*300, y0=row*300, y1=y0;
54  for (int i=0; i<nrow; ++i) {
55  double x1 = x0;
56  for (int j=0; j<ncol; ++j) {
57  if ( check<0)
58  assert( coors[i*ncol+j][0]==x1 && coors[i*ncol+j][1]==y1 &&
59  coors[i*ncol+j][2]==0.5);
60  else {
61  coors[i*ncol+j][0]=x1*check;
62  coors[i*ncol+j][1]=y1*check;
63  coors[i*ncol+j][2]=0.5;
64  }
65  x1 += length;
66  }
67  y1 += width;
68  }
69 }
70 
71 void init_unstructure_mesh( double coors[][3], int elmts[][4], int nrow,
72  int ncol, int rank, int nproc, int check=1) {
73  // consider the processors as a 2*(nproc/2) grid
74  int proc_col=nproc;
75  if (nproc%2 ==0) {
76  proc_col=nproc/2;
77  }
78  else {
79  proc_col=nproc;
80  }
81 
82  int row=rank/proc_col, col=rank%proc_col;
83 
84  const double width=300./(nrow-1), length=300./(ncol-1);
85 
86  double x0 = col*300, y0=row*300, y1=y0;
87  for (int i=0; i<nrow; ++i) {
88  double x1 = x0;
89  for (int j=0; j<ncol; ++j) {
90  if ( check<0)
91  assert( coors[i*ncol+j][0]==x1 && coors[i*ncol+j][1]==y1 &&
92  coors[i*ncol+j][2]==0.0);
93  else {
94  coors[i*ncol+j][0]=x1*check;
95  coors[i*ncol+j][1]=y1*check;
96  coors[i*ncol+j][2]=0.0;
97  }
98  x1 += length;
99  }
100  y1 += width;
101  }
102 
103  // computes elmts
104  for (int i=0; i<nrow-1; ++i) {
105  for (int j=0; j<ncol-1; ++j) {
106  if ( check<0) {
107  assert( elmts[i*(ncol-1)+j][0]==i*ncol+j+1 &&
108  elmts[i*(ncol-1)+j][1]==i*ncol+j+ncol+1 &&
109  elmts[i*(ncol-1)+j][2]==i*ncol+j+ncol+2 &&
110  elmts[i*(ncol-1)+j][3]==i*ncol+j+2);
111  }
112  else {
113  elmts[i*(ncol-1)+j][0]=check*i*ncol+j+1;
114  elmts[i*(ncol-1)+j][1]=check*i*ncol+j+ncol+1;
115  elmts[i*(ncol-1)+j][2]=check*i*ncol+j+ncol+2;
116  elmts[i*(ncol-1)+j][3]=check*i*ncol+j+2;
117  }
118  }
119  }
120 }
121 
122 int get_comm_rank( MPI_Comm comm) {
123  int rank;
124  int ierr = MPI_Comm_rank( comm, &rank); COM_assertion( ierr == 0);
125  return rank;
126 }
127 
128 int get_comm_size( MPI_Comm comm) {
129  int size;
130  int ierr = MPI_Comm_size( comm, &size); COM_assertion( ierr == 0);
131  return size;
132 }
133 
134 int main(int argc, char *argv[]) {
135  const int nproc=4;
136  const int nrow=40, ncol=30;
137  const int num_nodes=nrow*ncol;
138  const int num_elmts=(nrow-1)*(ncol-1);
139 
140  double coors_s[nproc][num_nodes][3];
141  int elmts[nproc][num_elmts][4];
142 
143  MPI_Init( &argc, &argv);
144  COM_init( &argc, &argv);
145 
146  MPI_Comm comm = MPI_COMM_WORLD;
147  const int comm_rank=get_comm_rank( comm);
148  const int comm_size=get_comm_size( comm);
149 
150  int vb = (argc>1) ? atoi(argv[1]) : 1;
151  if ( comm_rank == 0) COM_set_verbose(vb );
152 
153  COM_load_module("Rocout", "OUT");
154 
155  if ( comm_rank == 0) cout << "Creating window \"unstr\"" << endl;
156  COM_new_window("unstr");
157  COM_new_attribute("unstr.normals", 'n', COM_DOUBLE, 3, "m");
158 
159  for ( int pid=0; pid<nproc; ++pid) if (pid%comm_size==comm_rank) {
160  init_unstructure_mesh( coors_s[pid], elmts[pid],
161  nrow, ncol, pid, nproc);
162  COM_set_size( "unstr.nc", pid+1, num_nodes);
163  COM_set_array( "unstr.nc", pid+1, &coors_s[pid][0][0]);
164  COM_set_size( "unstr.:q4:", pid+1, num_elmts);
165  COM_set_array( "unstr.:q4:", pid+1, &elmts[pid][0][0]);
166  }
167  COM_resize_array( "unstr.atts");
168  COM_window_init_done( "unstr");
169 
170  int mesh = COM_get_attribute_handle_const( "unstr.mesh");
171  int normals = COM_get_attribute_handle( "unstr.normals");
172 
173  COM_load_module( "Rocsurf", "SURF");
174  int SURF_init = COM_get_function_handle( "SURF.initialize");
175  COM_call_function( SURF_init, &mesh);
176 
177  int SURF_normal = COM_get_function_handle( "SURF.compute_normals");
178  COM_call_function( SURF_normal, &mesh, &normals);
179 
180  if ( comm_rank==0)
181  cout << "Output normals into file..." << endl;
182  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
183  int unstr_all = COM_get_attribute_handle( "unstr.all");
184 
185  COM_call_function( OUT_write, "unstr_all", &unstr_all, "unstr", "000");
186  COM_delete_window( "unstr");
187 
188  // Test structured mesh
189  double coors_f[nproc][nrow*ncol][3];
190 
191  if ( comm_rank == 0) cout << "Creating window \"str\"" << endl;
192  COM_new_window( "str");
193  COM_new_attribute("str.normals", 'n', COM_DOUBLE, 3, "m/s");
194 
195  for ( int pid=0; pid<nproc; ++pid) if (pid%comm_size==comm_rank) {
196  init_structured_mesh(coors_f[pid], nrow, ncol, pid, nproc);
197 
198  COM_set_size("str.nc", pid+1, nrow*ncol);
199  COM_set_array("str.nc", pid+1, &coors_f[pid][0][0]);
200  int dims[2] = { ncol, nrow}; // Use Fortran convention
201  COM_set_array("str.:st2:", pid+1, &dims[0]);
202  }
203 
204  COM_resize_array( "str.atts");
205  COM_window_init_done( "str");
206 
207  mesh = COM_get_attribute_handle( "str.mesh");
208  normals = COM_get_attribute_handle( "str.normals");
209 
210  COM_call_function( SURF_init, &mesh);
211  COM_call_function( SURF_normal, &mesh, &normals);
212 
213 
214  if ( comm_rank==0)
215  cout << "Output normals into file..." << endl;
216  int str_all = COM_get_attribute_handle( "str.all");
217 
218  COM_call_function( OUT_write, "str_all", &str_all, "str", "000");
219  COM_delete_window( "str");
220 
221  // COM_unload_module("Rocout"); // Unload Rocout
222 
223  COM_finalize();
224  MPI_Finalize();
225 }
226 
227 
228 
229 
230 
231 
double coors_f[total_npanes][nrow *ncol][3]
Definition: ex1.C:100
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
const int ncol
Definition: ex1.C:95
void init_structured_mesh(double coors[][3], int nrow, int ncol, int rank, int nproc, int check=1)
Definition: surftest2.C:39
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
int get_comm_rank(MPI_Comm comm)
Definition: pcommpartest.C:32
void COM_set_size(const char *wa_str, int pane_id, int size, int ng=0)
Set sizes of for a specific attribute.
Definition: roccom_c++.h:136
This file contains the prototypes for Roccom API.
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
double length(Vector3D *const v, int n)
const int num_nodes
Definition: ex1.C:96
void COM_finalize()
Definition: roccom_c++.h:59
void COM_load_module(const char *libname, const char *winname)
Definition: roccom_c++.h:75
int get_comm_size(MPI_Comm comm)
Definition: pcommpartest.C:37
blockLoc i
Definition: read.cpp:79
int elmts[total_npanes][num_elmts][4]
Definition: ex1.C:109
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
void COM_set_array(const char *wa_str, int pane_id, void *addr, int strd=0, int cap=0)
Associates an array with an attribute for a specific pane.
Definition: roccom_c++.h:156
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
int main(int argc, char *argv[])
Definition: blastest.C:94
const int num_elmts
Definition: ex1.C:97
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
const int nrow
Definition: ex1.C:95
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
Definition: roccom_c++.h:118
static int rank
Definition: advectest.C:66
double coors_s[total_npanes][num_nodes][3]
Definition: ex1.C:99
void COM_resize_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=-1, int cap=0)
Resize an attribute on a specific pane and return the address by setting addr.
Definition: roccom_c++.h:200
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
void init_unstructure_mesh(double coors[18][3], int elmts[4][8])