Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reptrans.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: reptrans.C,v 1.9 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include <iostream>
27 #include <cstring>
28 #include <cstdlib>
29 #include "../Rocsurf/test/IM_Reader.h"
30 
31 COM_EXTERN_MODULE( Rocface);
35 
36 bool is_local_solid( int pid, int comm_rank, int comm_size) {
37  return ( pid % comm_size == comm_rank);
38 }
39 
40 bool is_local_fluid( int pid, int comm_rank, int comm_size) {
41  return ( (pid/100) % comm_size == comm_rank);
42 }
43 
44 using namespace std;
45 
46 int main(int argc, char *argv[]) {
47  MPI_Init( &argc, &argv);
48  COM_init( &argc, &argv);
49 
50  MPI_Comm comm = MPI_COMM_WORLD;
51  int size, rank;
52  MPI_Comm_size( comm, &size);
53  MPI_Comm_rank( comm, &rank);
54 
55  if ( argc < 4) {
56  if ( rank==0) {
57  std::cout << "Usage: " << argv[0] << " #iter #startiter scheme\n"
58  << "Schemes: 0: interpolation\n\t 1: weighted residual"
59  << "\n\t 2: virtual surface" << std::endl;
60  }
61  exit(-1);
62  }
63 
65 
68 
69  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
71 
72  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
73  int IN_read = COM_get_function_handle( "IN.read_window");
74  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
75  int BLAS_copy = COM_get_function_handle( "BLAS.copy");
76  int BLAS_add_scalar = COM_get_function_handle( "BLAS.add_scalar");
77  int BLAS_sub = COM_get_function_handle( "BLAS.sub");
78  int BLAS_nrm2 = COM_get_function_handle( "BLAS.nrm2");
79 
80  int RFC_read = COM_get_function_handle( "RFC.read_overlay_sdv");
81  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
82  int RFC_interpolate = COM_get_function_handle( "RFC.interpolate");
83  int RFC_set_verbose = COM_get_function_handle( "RFC.set_verbose");
84 
85  // Read in the meshes and common refinement
86  const string wnames[2] = {string("solid"), string("fluid")};
87 
88  double nrms_buf[3];
89  for ( int k=0; k<2; ++k) {
90  COM_new_window( wnames[k].c_str());
91  IM_Reader(comm).read_mesh((wnames[k]+".im").c_str(), wnames[k],
93 
94  COM_new_attribute( (wnames[k]+".fs").c_str(), 'n', COM_DOUBLE, 3, "m");
95  COM_new_attribute( (wnames[k]+".errors").c_str(), 'n', COM_DOUBLE, 3, "m");
96 
97  COM_resize_array( (wnames[k]+".fs").c_str());
98  COM_resize_array( (wnames[k]+".errors").c_str());
99 
100  COM_new_attribute( (wnames[k]+".nrms").c_str(), 'w', COM_DOUBLE, 3, "m");
101  COM_set_array( (wnames[k]+".nrms").c_str(), 0, nrms_buf);
102  COM_window_init_done( wnames[k].c_str());
103  }
104 
105  int w1_mesh = COM_get_attribute_handle( (wnames[0]+".mesh").c_str());
106  int w2_mesh = COM_get_attribute_handle( (wnames[1]+".mesh").c_str());
107 
108  COM_call_function( RFC_read, &w1_mesh, &w2_mesh, &comm);
109 
110  // Initialize the values to be transferred
111  int w1_nc = COM_get_attribute_handle( (wnames[0]+".nc").c_str());
112  int w1_fs = COM_get_attribute_handle( (wnames[0]+".fs").c_str());
113  int w1_fs1 = COM_get_attribute_handle( (wnames[0]+".1-fs").c_str());
114  int w1_err = COM_get_attribute_handle( (wnames[0]+".errors").c_str());
115  int w1_err1 = COM_get_attribute_handle( (wnames[0]+".1-errors").c_str());
116  int w1_nrms = COM_get_attribute_handle( (wnames[0]+".nrms").c_str());
117 
118  double *nrms=NULL;
119  COM_get_array( (wnames[0]+".nrms").c_str(), 0, &(void*&)nrms);
120  COM_assertion( nrms);
121 
122  int w2_nc = COM_get_attribute_handle( (wnames[1]+".nc").c_str());
123  int w2_fs = COM_get_attribute_handle( (wnames[1]+".fs").c_str());
124 
125  int niter=atoi(argv[1]);
126 
127  int initial = 0;
128  char buf[10];
129 
130  if ( argc>2) {
131  initial = atoi(argv[2]);
132  if (initial<0) initial = 0;
133  }
134  std::sprintf( buf, "%05d", initial);
135 
136  if (initial == 0) {
137  double one=1.0;
138  // Initialize the values of solid.fs
139  COM_call_function( BLAS_copy, &w1_nc, &w1_fs);
140  COM_call_function( BLAS_add_scalar, &w1_fs1, &one, &w1_fs1);
141 
142  COM_call_function( BLAS_copy, &w2_nc, &w2_fs);
143 
144  COM_call_function( OUT_write, (wnames[0]+buf).c_str(),
145  &w1_fs, wnames[0].c_str(), buf);
146  COM_call_function( OUT_write, (wnames[1]+buf).c_str(),
147  &w2_fs, wnames[1].c_str(), buf);
148  }
149  else {
150  COM_call_function( IN_read, (wnames[0]+buf).c_str(),
151  &w1_fs, wnames[0].c_str(), buf);
152  COM_call_function( IN_obtain, &w1_mesh, &w1_mesh);
153  COM_call_function( IN_obtain, &w1_fs, &w1_fs);
154 
155  COM_call_function( IN_read, (wnames[1]+buf).c_str(),
156  &w2_fs, wnames[1].c_str(), buf);
157  COM_call_function( IN_obtain, &w2_mesh, &w2_mesh);
158  COM_call_function( IN_obtain, &w2_fs, &w2_fs);
159  }
160 
161  COM_set_profiling_barrier( RFC_transfer, comm);
162  COM_set_profiling_barrier( RFC_interpolate, comm);
163  COM_set_profiling( 1);
164 
165  int scheme=0;
166  if ( argc>3) {
167  scheme = atoi(argv[3]);
168  }
169  std::sprintf( buf, "%05d", initial);
170 
171  int nextdump=1;
172 
173  for ( int i=initial+1; i<=niter; ++i) {
174  int verbose=(i==nextdump), noop=0, two=2;
175  double half=0.5, tol=1.e-15;
176 
177 
178  COM_call_function( RFC_set_verbose, &noop);
179  if ( scheme>0) {
180  COM_call_function( RFC_transfer, &w1_fs, &w2_fs, &half, &two, &tol);
181  COM_call_function( RFC_set_verbose, &verbose);
182  COM_call_function( RFC_transfer, &w2_fs, &w1_fs, &half, &two, &tol);
183  }
184  else {
185  COM_call_function( RFC_interpolate, &w1_fs, &w2_fs);
186  COM_call_function( RFC_set_verbose, &verbose);
187  COM_call_function( RFC_interpolate, &w2_fs, &w1_fs);
188  }
189 
190  if ( i==niter || i==nextdump) {
191  double neg1=-1;
192  // Compute errors in 2-norm
193  COM_call_function( BLAS_sub, &w1_fs, &w1_nc, &w1_err);
194  COM_call_function( BLAS_add_scalar, &w1_err1, &neg1, &w1_err1);
195  COM_call_function( BLAS_nrm2, &w1_err, &w1_nrms);
196  if(verbose)
197  std::cout << "Error norms are: " << nrms[0] << ' ' << nrms[1]
198  << ' ' << nrms[2] << std::endl;
199 
200  std::sprintf( buf, "%05d", i+1);
201  COM_call_function( OUT_write, (wnames[0]+buf).c_str(),
202  &w1_fs, wnames[0].c_str(), buf);
203  COM_call_function( OUT_write, (wnames[1]+buf).c_str(),
204  &w2_fs, wnames[1].c_str(), buf);
205  nextdump+=nextdump;
206  }
207  }
208 
209  COM_print_profile( "", "");
210 
211  COM_finalize();
212  MPI_Finalize();
213 }
214 
215 
216 
217 
218 
219 
#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
j indices k indices k
Definition: Indexing.h:6
bool is_local_fluid(int pid, int comm_rank, int comm_size)
Definition: reptrans.C:40
bool is_local_solid(int pid, int comm_rank, int comm_size)
Definition: reptrans.C:36
This file contains the prototypes for Roccom API.
void COM_get_array(const char *wa_str, int pane_id, void **addr, int *strd, int *cap)
Get the address for an attribute on a specific pane.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
static const int scheme
void COM_finalize()
Definition: roccom_c++.h:59
int read_mesh(const char *fname, const std::string &wname, Func_ptr is_local)
Definition: IM_Reader.h:102
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
Definition: Rocin.h:64
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
void COM_set_profiling_barrier(int hdl, MPI_Comm comm)
Definition: roccom_c++.h:554
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_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
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
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
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
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
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116