Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ex2.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: ex2.C,v 1.21 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include "Tuple.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 
37 COM_EXTERN_MODULE( Rocface);
39 
40 using namespace std;
42 
43 int main(int argc, char **argv) {
44  COM_init( &argc, &argv);
45 
46  if ( argc < 5) {
47  std::cout << "Usage: " << argv[0] << " br, bc, gr, gc" << std::endl;
48  exit(-1);
49  }
50 
51  MPI_Comm comm = MPI_COMM_WORLD;
52  const int comm_rank=0;
53  const int comm_size=1;
54 
55  const int b_row=atoi(argv[1]), b_col=atoi(argv[2]);
56  const int g_row=atoi(argv[3]), g_col=atoi(argv[4]);
57 
58  const double g_row_max=double(g_row-1.)/2., g_col_max=double(g_col-1.)/2.;
59  const double b_row_max=double(b_row-1.)/2., b_col_max=double(b_col-1.)/2.;
60 
61  vector<Point_3> g_pnts(g_row*g_col);
62  vector<Four_tuple<int> > g_elems((g_row-1)*(g_col-1));
63 
64  vector<Point_3> b_pnts(b_row*b_col);
65  vector<Four_tuple<int> > b_elems((b_row-1)*(b_col-1));
66 
67  const double pi_by_2 = asin(1.);
68  for (int i=0; i<g_row; ++i)
69  for (int j=0; j<g_col; ++j) {
70  double sin_1 = sin((i+g_row_max)/(g_row-1)*pi_by_2);
71  double sin_2 = sin((j+g_col_max)/(g_col-1)*pi_by_2);
72  double cos_1 = cos((i+g_row_max)/(g_row-1)*pi_by_2);
73  double cos_2 = cos((j+g_col_max)/(g_col-1)*pi_by_2);
74 
75  g_pnts[i*g_col+j] = Point_3( cos_1*sin_2, cos_2, sin_1*sin_2);
76  }
77 
78  for (int i=0; i<g_row-1; ++i)
79  for (int j=0; j<g_col-1; ++j)
80  g_elems[i*(g_col-1)+j] = Four_tuple<int>(i*g_col+j+1, (i+1)*g_col+j+1,
81  (i+1)*g_col+j+2, i*g_col+j+2);
82 
83  for (int i=0; i<b_row; ++i)
84  for (int j=0; j<b_col; ++j) {
85  double sin_1 = sin((i+b_row_max)/(b_row-1)*pi_by_2);
86  double sin_2 = sin((j+b_col_max)/(b_col-1)*pi_by_2);
87  double cos_1 = cos((i+b_row_max)/(b_row-1)*pi_by_2);
88  double cos_2 = cos((j+b_col_max)/(b_col-1)*pi_by_2);
89 
90 
91  b_pnts[i*b_col+j] = Point_3( cos_1*sin_2, cos_2, sin_1*sin_2);
92  }
93 
94  for (int i=0; i<b_row-1; ++i)
95  for (int j=0; j<b_col-1; ++j)
96  b_elems[i*(b_col-1)+j] = Four_tuple<int>(i*b_col+j+1, (i+1)*b_col+j+1,
97  (i+1)*b_col+j+2, i*b_col+j+2);
98 
99  vector<Point_3> g_coor = g_pnts, b_coor = b_pnts;
100 
101  COM_set_verbose( 1);
102  COM_set_profiling( 1);
103 
104  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
105 
106  COM_new_window("quad1");
107  COM_new_attribute("quad1.coor", 'n', COM_DOUBLE, 3, "m");
108  if ( comm_rank==0) {
109  COM_set_size( "quad1.nc", 1, b_pnts.size());
110  COM_set_array( "quad1.nc", 1, &b_pnts[0]);
111  COM_set_size( "quad1.:q4:", 1, b_elems.size());
112  COM_set_array( "quad1.:q4:", 1, &b_elems[0]);
113  COM_set_array( "quad1.coor", 1, &b_coor[0]);
114  }
115  COM_window_init_done( "quad1");
116 
117  COM_new_window("quad2");
118  COM_new_attribute("quad2.coor", 'n', COM_DOUBLE, 3, "m");
119  if ( comm_rank==0) {
120  COM_set_size( "quad2.nc", 1, g_pnts.size());
121  COM_set_array( "quad2.nc", 1, &g_pnts[0]);
122  COM_set_size( "quad2.:q4:", 1, g_elems.size());
123  COM_set_array( "quad2.:q4:", 1, &g_elems[0]);
124  COM_set_array("quad2.coor", 1, &g_coor[0]);
125  }
126  COM_window_init_done( "quad2");
127 
128  int quad1_mesh = COM_get_attribute_handle( "quad1.mesh");
129  int quad2_mesh = COM_get_attribute_handle( "quad2.mesh");
130  int RFC_clear = COM_get_function_handle( "RFC.clear_overlay");
131  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
132 
133  const char *format="HDF";
134  if ( comm_size==1) {
135  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
136 
137  COM_call_function( RFC_overlay, &quad1_mesh, &quad2_mesh);
138 
139  COM_call_function( RFC_write, &quad1_mesh, &quad2_mesh,
140  "quad1", "quad2", format);
141  COM_call_function( RFC_clear, "quad1", "quad2");
142  }
143 
144  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
145  COM_call_function( RFC_read, &quad1_mesh, &quad2_mesh, &comm,
146  "quad1", "quad2", format);
147 
148  if ( argc > 5) {
149  char prefix1[100], prefix2[100];
150 
151  std::sprintf(prefix1, "quad1_coor%d", comm_rank);
152  std::sprintf(prefix2, "quad2_coor%d", comm_rank);
153 
155  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
156  int OUT_set = COM_get_function_handle( "OUT.set_option");
157  int quad1_coor = COM_get_attribute_handle( "quad1.coor");
158  int quad2_coor = COM_get_attribute_handle( "quad2.coor");
159 
160  COM_call_function( OUT_write, prefix1, &quad1_coor, "quad1", "000");
161  COM_call_function( OUT_write, prefix2, &quad2_coor, "quad2", "000");
162 
163  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
164  COM_call_function( RFC_transfer, &quad1_coor, &quad2_coor);
165  COM_call_function( RFC_transfer, &quad2_coor, &quad1_coor);
166 
167  COM_call_function( OUT_set, "mode", "a");
168  COM_call_function( OUT_write, prefix1, &quad1_coor, "quad1", "001");
169  COM_call_function( OUT_write, prefix2, &quad2_coor, "quad2", "001");
170 
171  COM_call_function( RFC_clear, "quad1", "quad2");
172  // COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocout, "OUT");
173  }
174 
175  COM_delete_window( "quad1");
176  COM_delete_window( "quad2");
177 
178  COM_print_profile( "", "");
179 
180  COM_finalize();
181 }
182 
183 
184 
185 
186 
187 
A structure used to represent element faces.
Definition: Pane_boundary.C:60
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
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
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
CImg< _cimg_Tfloat > asin(const CImg< T > &instance)
Definition: CImg.h:6056
void COM_finalize()
Definition: roccom_c++.h:59
NT & sin
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
#define USE_RFC_NAME_SPACE
Definition: rfc_basic.h:31
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_profiling(int i)
Definition: roccom_c++.h:550
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 main(int argc, char *argv[])
Definition: blastest.C:94
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
SURF::Point_3< Real > Point_3
Definition: rfc_basic.h:41
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
NT & cos
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116