Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Surfdiver.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: Surfdiver.C,v 1.11 2009/10/08 15:36:00 mtcampbe Exp $
24 
25 #include <iostream>
26 #include <cstring>
27 #include <cstdlib>
28 
29 #include "roccom.h"
30 #include "basic_actions.h"
31 #include "FluidAgent.h"
32 #include "SolidAgent.h"
33 
34 using namespace std;
35 
36 extern void _load_rocface(FluidAgent *fagent, SolidAgent *sagent, const RocmanControl_parameters *param);
37 
38 void read_file( const char *fname, const string &wname, double alpha)
39 {
40  char *lastdot=strrchr( const_cast<char *>(fname), '.');
41 
42  COM_new_window( wname.c_str(), MPI_COMM_SELF);
43 
44  // Read in HDF files or a Rocin control file
45  if(man_verbose > 2)
46  std::cout << "Reading file " << fname << " " << wname << std::endl;
47 
48  // Read in HDF format
49  //COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocin, "IN");
50  //COM_LOAD_MODULE_STATIC_DYNAMIC( Rocin, "IN");
51 
52  int IN_read;
53  // Read in HDF format using Rocin::read_window or ::read_by_control_file
54  if ( strcmp( lastdot, ".hdf")==0)
55  IN_read = COM_get_function_handle( "IN.read_window");
56  else
57  IN_read = COM_get_function_handle( "IN.read_by_control_file");
58 
59  // Pass MPI_COMM_NULL to Rocin so that the rank becomes a wildcard.
60  MPI_Comm comm_null = MPI_COMM_NULL;
61  std::string bufwin("bufwin");
62  COM_call_function( IN_read, fname, bufwin.c_str(), &comm_null);
63 
64  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
65 
66  // Check whether bcflag exists. If so, retain only the panes with flag<=1.
67  int bcflag = COM_get_attribute_handle((bufwin+".bcflag").c_str());
68  if (bcflag > 0) {
69  // Read in bcflags.
70  COM_call_function( IN_obtain, &bcflag, &bcflag);
71 
72  // Obtain the IDs of the panes of the window
73  int npanes, *pane_ids;
74  COM_get_panes( bufwin.c_str(), &npanes, &pane_ids);
75 
76  // Loop through the panes to remove those with bcflag >1.
77  for ( int i=0; i<npanes; ++i) {
78  int *flag;
79  COM_get_array( (bufwin+".bcflag").c_str(), pane_ids[i], &flag);
80  if ( flag==NULL || *flag>1)
81  COM_delete_pane( bufwin.c_str(), pane_ids[i]);
82  }
83 
84  // remove buffers.
85  COM_free_buffer( &pane_ids);
86  }
87 
88  // Remove all attributes except for the mesh
89  COM_delete_attribute( (bufwin+".atts").c_str());
90 
91  // Read in the mesh.
92  int buf_mesh = COM_get_attribute_handle((bufwin+".mesh").c_str());
93  COM_call_function( IN_obtain, &buf_mesh, &buf_mesh);
94  //COM_UNLOAD_MODULE_STATIC_DYNAMIC( Rocin, "IN");
95 
96  if(man_verbose > 2)
97  std::cout << "Obtained window " << wname << " from file " << fname << std::endl;
98 
99  // Change the memory layout to contiguous.
100  COM_clone_attribute( (wname+".mesh").c_str(), (bufwin+".mesh").c_str(), 0);
101  COM_delete_window( bufwin.c_str());
102 }
103 
105  Action( 0, (const char**)NULL, NULL, NULL, (char *)"SurfDiver"),
106  fagent(fag), sagent(sag)
107 {
108  outdir = "Rocman/"+fagent->get_rocmod_name()+sagent->get_rocmod_name()+"/";
109 }
110 
111 void SurfDiver::init(double t)
112 {
115 
118 
120  RFC_readcntr = COM_get_function_handle( "RFC.read_control_file");
121  RFC_overlay = COM_get_function_handle( "RFC.overlay");
122  RFC_write = COM_get_function_handle( "RFC.write_overlay");
123  RFC_transfer = COM_get_function_handle("RFC.least_squares_transfer");
124  RFC_interpolate = COM_get_function_handle("RFC.interpolate");
125  RFC_read = COM_get_function_handle( "RFC.read_overlay");
126 }
127 
128 void SurfDiver::run( double t, double dt, double alpha) {
129  MAN_DEBUG(1, ("[%d] Rocstar: SurfDiver::run() with t:%e dt:%e.\n", fagent->get_comm_rank(), t, dt));
130 
131  MPI_Comm comm = fagent->get_communicator();
132 
133  // dump meshes
134  MAN_DEBUG(1, ("[%d] Rocstar: SurfDiver::run() dumping output files for time %e.\n", fagent->get_comm_rank(), t));
137 
138  MPI_Barrier(comm);
139 
140  // run sequentially
141  if (fagent->get_comm_rank() == 0) {
142 
143  MPI_Comm oldcomm = COM_get_default_communicator();
144  COM_set_default_communicator( MPI_COMM_NULL);
145  // need to turn off profiling as it may hang for npes > 1
147 
148  // read meshes
149 
150  std::string time_str;
151  fagent->get_time_string(t, time_str);
152  std::string fluid_file = fagent->get_rocmod_name()+"/Rocout/ifluid_in_"+time_str+".txt";
153  std::string solid_file = sagent->get_rocmod_name()+"/Rocout/isolid_in_"+time_str+".txt";
154 
155  std::string fluid_wname = outdir+"ifluid";
156  std::string solid_wname = outdir+"isolid";
157 
158  read_file( fluid_file.c_str(), fluid_wname.c_str(), 1.);
159  COM_window_init_done( fluid_wname);
160 
161  read_file( solid_file.c_str(), solid_wname.c_str(), 1.);
162  COM_window_init_done( solid_wname);
163 
164  int fluid_mesh1 = COM_get_attribute_handle( (fluid_wname+".mesh").c_str());
165  int solid_mesh1 = COM_get_attribute_handle( (solid_wname+".mesh").c_str());
166 
167  const char *format = "HDF";
168 
169  // mesh overlay
170  MAN_DEBUG(2,("Starting mesh overlay..."));
171  COM_call_function( RFC_overlay, &fluid_mesh1, &solid_mesh1);
172 
173  // output overlay mesh
174  COM_call_function( RFC_write, &fluid_mesh1, &solid_mesh1,
175  fluid_wname.c_str(), solid_wname.c_str(), format);
176 
179  } // end of PE 0
180 
181  MPI_Barrier(comm);
182 
183  // reload overlay
184  std::string fluid_dir = outdir+"ifluid";
185  std::string solid_dir = outdir+"isolid";
186 
187  MAN_DEBUG(2,("Reload partitioned mesh overlay... "));
188  COM_call_function( RFC_read, &fluid_mesh, &solid_mesh, &comm, fluid_dir.c_str(), solid_dir.c_str(), "HDF");
189 }
190 
191 //
192 void compute_overlay( FluidAgent *fagent, SolidAgent *sagent, double t) {
193  MAN_DEBUG(1, ("[%d] Rocstar: compute_overlay with t:%e .\n", fagent->get_comm_rank(), t));
194 
195  MPI_Comm comm = fagent->get_communicator();
196 
197  MPI_Barrier(comm);
198 
199  // run sequentially
200  if (fagent->get_comm_rank() == 0) {
201 
202  MPI_Comm oldcomm = COM_get_default_communicator();
203  COM_set_default_communicator( MPI_COMM_NULL);
204  // need to turn off profiling as it may hang for npes > 1
206 
207  // read meshes
208 
209  std::string time_str;
210  fagent->get_time_string(t, time_str);
211  std::string fluid_file = fagent->get_rocmod_name()+"/Rocout/ifluid_"+time_str+".txt";
212  std::string solid_file = sagent->get_rocmod_name()+"/Rocout/isolid_"+time_str+".txt";
213 
214  std::string outdir = "Rocman/"+fagent->get_rocmod_name()+sagent->get_rocmod_name()+"/";
215  std::string fluid_wname = outdir+"ifluid";
216  std::string solid_wname = outdir+"isolid";
217 
218  // load two meshes
219  read_file( fluid_file.c_str(), fluid_wname.c_str(), 1.);
220  COM_window_init_done( fluid_wname);
221 
222  read_file( solid_file.c_str(), solid_wname.c_str(), 1.);
223  COM_window_init_done( solid_wname);
224 
225  int fluid_mesh1 = COM_get_attribute_handle( (fluid_wname+".mesh").c_str());
226  int solid_mesh1 = COM_get_attribute_handle( (solid_wname+".mesh").c_str());
227 
228  const char *format = "HDF";
229 
230  // call Rocblas to get deformed data HERE
231  int s_x_hdl = COM_get_attribute_handle( sagent->solidBuf + ".x");
232  int s_uhat_hdl = COM_get_attribute_handle( sagent->solidBuf + ".uhat");
233  int s_y_hdl = COM_get_attribute_handle( sagent->solidBuf + ".nc");
234 
235  // get deformed
236  COM_call_function( RocBlas::add, &s_x_hdl, &s_uhat_hdl, &s_y_hdl);
237 
238  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
239  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
240 
241  // mesh overlay
242  MAN_DEBUG(2,("Starting mesh overlay... "));
243  COM_call_function( RFC_overlay, &fluid_mesh1, &solid_mesh1);
244 
245  // output overlay mesh
246  COM_call_function( RFC_write, &fluid_mesh1, &solid_mesh1,
247  fluid_wname.c_str(), solid_wname.c_str(), format);
248 
251  } // end of PE 0
252 
253  MPI_Barrier(comm);
254 
255 }
256 
257 void SurfDiverAfterRemeshing::run( double t, double dt, double alpha)
258 {
260 }
261 
262 
263 
264 
265 
266 
267 
FluidAgent * fagent
virtual void output_restart_files(double t)
Definition: SolidAgent.C:362
virtual void output_restart_files(double t)
Definition: FluidAgent.C:466
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_SELF
int RFC_interpolate
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
void read_file(const char *fname, const string &wname, double alpha)
Definition: autosurfer.C:39
std::string solid_mesh_str
int RFC_transfer
void COM_set_default_communicator(MPI_Comm comm)
Definition: roccom_c++.h:67
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.
SurfDiver(FluidAgent *fag, SolidAgent *sag)
Definition: Surfdiver.C:104
SolidAgent * sagent
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_delete_attribute(const char *wa_str)
Delete an existing attribute.
Definition: roccom_c++.h:128
Definition: Action.h:32
int man_verbose
void get_time_string(double t, std::string &s)
Definition: Agent.C:578
std::string outdir
void init(double t)
Definition: Surfdiver.C:111
static int add
Definition: RocBlas.h:35
Coupling * get_coupling()
Definition: Agent.h:213
std::string fluidBufNG
Definition: FluidAgent.h:78
std::string get_rocmod_name() const
Definition: Agent.h:221
std::string solidBuf
Definition: SolidAgent.h:68
blockLoc i
Definition: read.cpp:79
virtual void run(double t, double dt, double alpha)
Definition: Surfdiver.C:128
virtual void run(double t, double dt, double alpha)
Definition: Surfdiver.C:257
void _load_rocface(FluidAgent *fagent, SolidAgent *sagent, const RocmanControl_parameters *param)
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
std::string fluid_mesh_str
void COM_clone_attribute(const char *wname, const char *attr, int wg=1, const char *ptnname=0, int val=0)
Clone the subset of panes of another window of which the given pane attribute has value val...
Definition: roccom_c++.h:234
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
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
int RFC_readcntr
void COM_delete_pane(const char *str, int pid)
Definition: roccom_c++.h:110
#define MAN_DEBUG(l, x)
Definition: rocman.h:98
int get_comm_rank() const
Definition: Agent.h:224
const RocmanControl_parameters * get_rocmancontrol_param()
Definition: Coupling.h:184
void compute_overlay(FluidAgent *fagent, SolidAgent *sagent, double t)
Definition: Surfdiver.C:192
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
void COM_free_buffer(int **buf)
Definition: roccom_c++.h:397
MPI_Comm get_communicator() const
Definition: Agent.h:220
MPI_Comm COM_get_default_communicator()
Definition: roccom_c++.h:69
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428