Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interpolate.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: Interpolate.C,v 1.39 2008/12/06 08:45:22 mtcampbe Exp $
24 
25 #include "rocman.h"
26 #include "FluidAgent.h"
27 #include "BurnAgent.h"
28 #include "Interpolate.h"
29 
31  Action(0, (const char**)NULL, NULL, NULL, (char *)"InterpolateBase"),
32  agent(ag), bkagent(bkag), conditional(cond)
33 {
34  // register to Agent for create_attribute() and backup() callback
36 
37  int i;
38  for (i=0; i<4; i++) attr_hdls[i] = -1;
39  for (i=0; i<3; i++) bkup_hdls[i] = -1;
40  on = 1;
41 }
42 
43 void InterpolateBase::init(double t)
44 {
45  MAN_DEBUG(3, ("%s::init called.\n", name()));
46  // INIT_INTERP_HANDLES() in "man_basic.f90"
49  attr_hdls[2] = COM_get_attribute_handle(attr[2]); // alp
50  attr_hdls[3] = COM_get_attribute_handle(attr[3]); // grad
51  for (int i=0; i<4; i++) {
52  // init to 0
53  if (get_io(i) == OUT) {
54  double zero = 0.0;
56  }
57  }
58  if ( attr_hdls[1] <= 0 && attr_hdls[2] <= 0)
59  std::cout << "Rocstar Warning: Could not find attribute " << attr[2] << std::endl;
60  else if (attr_hdls[2] <= 0) {
61  std::cout << "Rocstar Error: Could not find attribute " << attr[2] << std::endl;
62  COM_assertion_msg(0, "ERROR: Abort!");
63  }
64 
65  // backup handles
67  bkup_hdls[1] = get_attribute_handle(1); // old
68  bkup_hdls[2] = COM_get_attribute_handle(attr[3]); // grad
69 }
70 
72 {
73  MAN_DEBUG(3, ("Rocstar: InterpolateBase::backup (%s) called with dt_old:%e.\n", attr[0], agent->get_old_dt()));
74 
75  // BACKUP() in "man_basic.f90"
76  if (bkup_hdls[0] > 0 && bkup_hdls[1] > 0) {
77  // Compute gradient
78  if ( bkup_hdls[2] > 0) {
79  double dt_old = agent->get_old_dt();
80  if (dt_old > 0.) {
83  }
84  else {
85  double v = 0.0;
87  }
88  }
90  }
91 }
92 
93 // INTERPOLATE_LINEAR
94 void InterpolateBase::extrapolate_Linear(double dt, double dt_old, double time_old, int a_old, double time_new, int a_new, double time_out, int a_out, int a_grad)
95 {
96 
97  //printf("extrapolate_Linear: %f %d %f %d %f %d %d\n", time_old, a_old, time_new, a_new, time_out, a_out, a_grad);
98 
99  if (time_out == time_new) {
100  COM_call_function( RocBlas::copy, &a_new, &a_out);
101  }
102  else if (a_old <= 0) {
103  printf("Rocstar Error: Could not find the old attribute correspond to the attribute with handle %d\n", a_out);
104  COM_assertion_msg(0, "ERROR: Abort!");
105  }
106  else if (time_out == time_old) {
107  COM_call_function( RocBlas::copy, &a_old, &a_out);
108  }
109  else {
110  // See the interpolation section in developers' guide for the algorithm
111  COM_call_function( RocBlas::sub, &a_new, &a_old, &a_out);
112  double a;
113  if (time_old == 0.)
114  a = time_out-1.;
115  else if (time_old == -0.5) {
116  if (a_grad != -100 && a_grad>0) {
117  double time = (dt_old+dt)/2.0;
118  COM_call_function( RocBlas::div_scalar, &a_out, &time, &a_out);
119  COM_call_function( RocBlas::limit1, &a_grad, &a_out, &a_out);
120  a = (time_out - 0.5)*dt;
121  }
122  else
123  a = 2.*(time_out - 0.5)*dt/(dt_old+dt);
124  }
125  else if (time_old == -1) {
126  COM_assertion_msg(0, "ERROR: Abort!");
127  }
128  else {
129  printf("Rocstar Error: Unsupported interpolation mode with old time stamp %f\n", time_old);
130  COM_assertion_msg(0, "ERROR: Abort!");
131  }
132  COM_call_function( RocBlas::axpy_scalar, &a, &a_out, &a_new, &a_out);
133  }
134 }
135 
136 
137 Extrapolate_Linear::Extrapolate_Linear(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf, int cond): InterpolateBase(ag, bkag, cond)
138 {
139  action_name = (char *)"Extrapolate_Linear";
140  // INIT_INTERP_HANDLES() in "man_basic.f90"
141  std::string atts[4];
142  atts[0] = attr;
143  atts[1] = attr + "_old";
144  atts[2] = attr + alpsuf;
145  atts[3] = attr + "_grad";
146 
147  set_attr(4, atts);
148 
149  // Define I/O of the arguments.
150  int io[] = {IN, IN, OUT, IN};
151  set_io( 4, io);
152 }
153 
155 {
156  // check condition
157  attr_hdls[2] = COM_get_attribute_handle(attr[2]); // alp
158  if (conditional) {
159  if (attr_hdls[2] <= 0) return;
160  }
161 
163 }
164 
165 void Extrapolate_Linear::run(double t, double dt, double alpha)
166 {
167  if (attr_hdls[2] <= 0) return;
168 
169  MAN_DEBUG(3, ("Extrapolate_Linear::run (%s) called with t:%e dt:%e alpha:%e.\n", attr[0], t, dt, alpha));
170 
171  COM_assertion_msg(alpha>=-1.e-6 && alpha <= 1+1.e-6, "ERROR: Abort!");
172 
173  int order = agent->get_coupling()->get_rocmancontrol_param()->order;
174  if (order == 0 || agent->get_coupling()->new_start(t)) {
176  return;
177  }
178 
179  if (agent->get_coupling()->get_ipc() <= 1 && attr_hdls[3] <= 0) {
181  return;
182  }
183  double base = 0.0;
184  // linear interpolation.
185  extrapolate_Linear(dt, agent->get_old_dt(), base, attr_hdls[1], base+1.0, attr_hdls[0], alpha, attr_hdls[2], attr_hdls[3]);
186 }
187 
188 Extrapolate_Central::Extrapolate_Central(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf, int cond): InterpolateBase(ag, bkag, cond)
189 {
190  action_name = (char *)"Extrapolate_Central";
191  // INIT_INTERP_HANDLES() in "man_basic.f90"
192  std::string atts[4];
193  atts[0] = attr;
194  atts[1] = attr + "_old";
195  atts[2] = attr + alpsuf;
196  atts[3] = attr + "_grad";
197 
198  set_attr(4, atts);
199 
200  // Define I/O of the arguments.
201  int io[] = {IN, IN, OUT, IN};
202  set_io( 4, io);
203 
204 /*
205  // register attributes
206  std::string surf_win = agent->get_surface_window();
207  std::string::size_type pos = attr.find(".");
208  std::string wname, aname;
209  if ( pos == std::string::npos) {
210  COM_assertion_msg(0, "ERROR: Here!");
211  }
212  else {
213  wname = attr.substr( 0, pos);
214  aname = attr.substr( pos, attr.size()-pos);
215  }
216 
217  agent->register_use_attribute( wname, aname, ((BurnAgent*)agent)->parentWin, aname); // attr
218  agent->register_clone_attribute( conditional, wname, aname+"_old", surf_win, aname+"_alp"); // attr_old
219  agent->register_clone_attribute( conditional, wname, aname+"_grad", surf_win, aname+"_alp"); // attr_grad
220 */
221 }
222 
224 {
225  // check condition
226  // first check if window exists
227  std::string attribute = attr[0];
228  std::string::size_type pos = attribute.find(".");
229  COM_assertion_msg(pos != std::string::npos, "ERROR: Here!");
230  std::string wname = attribute.substr( 0, pos);
231  if (COM_get_window_handle(wname) <= 0) return;
232 
233  // check if attribute exists
234  attr_hdls[2] = COM_get_attribute_handle(attr[2]); // alp
235  if (conditional) {
236  if (attr_hdls[2] <= 0) return;
237  }
238 
240 }
241 
242 void Extrapolate_Central::run(double t, double dt, double alpha)
243 {
244  if (attr_hdls[2] <= 0) return;
245 
246  MAN_DEBUG(3, ("Extrapolate_Central::run (%s) called with t:%e dt:%e alpha:%e.\n", attr[0], t, dt, alpha));
247 
248  COM_assertion_msg(alpha>=0.0, "ERROR: Extrapolate_Central called with invalid alpha!");
249 
250  COM_assertion_msg(alpha>=-1.e-6 && alpha <= 1+1.e-6, "ERROR: Abort!");
251 
252  int order = agent->get_coupling()->get_rocmancontrol_param()->order;
253  if (order == 0 || agent->get_coupling()->new_start(t)) {
255  return;
256  }
257 
258  if (agent->get_coupling()->get_ipc() <= 1 && attr_hdls[3] <= 0) {
260  return;
261  }
262  double base = -0.5;
263  // linear interpolation.
264  extrapolate_Linear(dt, agent->get_old_dt(), base, attr_hdls[1], base+1.0, attr_hdls[0], alpha, attr_hdls[2], attr_hdls[3]);
265 }
266 
267 
268 Interpolate_Linear::Interpolate_Linear(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf): InterpolateBase(ag, bkag)
269 {
270  action_name = (char *)"Interpolate_Linear";
271  // INIT_INTERP_HANDLES() in "man_basic.f90"
272  std::string atts[4];
273  atts[0] = attr;
274  atts[1] = attr + "_old";
275  atts[2] = attr + alpsuf;
276  atts[3] = attr + "_grad";
277 
278  set_attr(4, atts);
279 
280  // Define I/O of the arguments.
281  int io[] = {IN, IN, OUT, IN};
282  set_io( 4, io);
283 }
284 
285 void Interpolate_Linear::run(double t, double dt, double alpha)
286 {
287  if (attr_hdls[2] <= 0) return;
288 
289  MAN_DEBUG(3, ("Interpolate_Linear::run (%s) called with t:%e dt:%e alpha:%e.\n", attr[0], t, dt, alpha));
290 
291  COM_assertion_msg(alpha>=0.0, "ERROR: Interpolate_Linear called with invalid alpha!");
292 
293  COM_assertion_msg(alpha>=-1.e-6 && alpha <= 1+1.e-6, "ERROR: Abort!");
294 
295  int order = agent->get_coupling()->get_rocmancontrol_param()->order;
296  if (order == 0 || agent->get_coupling()->new_start(t)) {
298  return;
299  }
300 
301  double base = 0.0;
302  // linear interpolation.
303  extrapolate_Linear(dt, agent->get_old_dt(), base, attr_hdls[1], base+1.0, attr_hdls[0], alpha, attr_hdls[2], attr_hdls[3]);
304 }
305 
306 
307 Interpolate_Constant::Interpolate_Constant(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf): InterpolateBase(ag, bkag)
308 {
309  action_name = (char *)"Interpolate_Constant";
310 
311  std::string atts[4];
312  atts[0] = attr;
313  atts[1] = attr + "_old";
314  atts[2] = attr + alpsuf;
315  atts[3] = attr + "_grad";
316  set_attr(4, atts);
317 
318  // Define I/O of the arguments.
319  int io[] = {IN, IN, OUT, IN};
320  set_io( 4, io);
321 
322  // register attributes
323  std::string::size_type pos = attr.find(".");
324  std::string wname, aname;
325  if ( pos == std::string::npos) {
326  COM_assertion_msg(0, "ERROR: Here!");
327  }
328  else {
329  wname = attr.substr( 0, pos);
330  aname = attr.substr( pos, attr.size()-pos);
331  }
332  std::string surf_win = agent->get_surface_window();
333 
334 }
335 
336 void Interpolate_Constant::run(double t_dummy, double dt_dummy, double alpha)
337 {
338  if (attr_hdls[2] <= 0) return;
339 
340  MAN_DEBUG(3, ("Interpolate_Constant::run (bc) called with alpha:%e.\n", alpha));
341 
343 }
344 
345 Interpolate_Central::Interpolate_Central(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf): InterpolateBase(ag, bkag)
346 {
347  action_name = (char *)"Interpolate_Central";
348  // INIT_INTERP_HANDLES() in "man_basic.f90"
349  std::string atts[4];
350  atts[0] = attr;
351  atts[1] = attr + "_old";
352  atts[2] = attr + alpsuf;
353  atts[3] = attr + "_grad";
354 
355  set_attr(4, atts);
356 
357  // Define I/O of the arguments.
358  int io[] = {IN, IN, OUT, IN};
359  set_io( 4, io);
360 
361 /*
362  // register attributes
363  std::string surf_win = agent->get_surface_window();
364  std::string::size_type pos = attr.find(".");
365  std::string wname, aname;
366  if ( pos == std::string::npos) {
367  COM_assertion_msg(0, "ERROR: Here!");
368  }
369  else {
370  wname = attr.substr( 0, pos);
371  aname = attr.substr( pos, attr.size()-pos);
372  }
373 
374  if (attr_action[0] == 'n')
375  agent->register_new_attribute( wname, aname, 'e', COM_DOUBLE, 1, "kg/(m^2 s)");
376 
377  if (attr_action[1] == 'n')
378  agent->register_new_attribute( wname, aname+"_old", 'e', COM_DOUBLE, 1, "kg/(m^2 s)");
379  else if (attr_action[1] == 'c')
380  agent->register_clone_attribute( 0, wname, aname+"_old", surf_win, aname); // attr_old
381 
382  if (attr_action[2] == 'c')
383  agent->register_clone_attribute( 0, wname, aname+alpsuf, surf_win, aname); // attr_grad
384 
385  if (attr_action[3] == 'n')
386  agent->register_new_attribute( wname, aname+"_grad", 'e', COM_DOUBLE, 1, "kg/(m^2 s)");
387  else if (attr_action[3] == 'c')
388  agent->register_clone_attribute( 0, wname, aname+"_grad", surf_win, aname); // attr_grad
389 */
390 }
391 
392 void Interpolate_Central::run(double t, double dt, double alpha)
393 {
394  if (attr_hdls[2] <= 0) return;
395 
396  MAN_DEBUG(3, ("Interpolate_Central::run (%s) called with t:%e dt:%e alpha:%e.\n", attr[0], t, dt, alpha));
397 
398  COM_assertion_msg(alpha>=0.0, "ERROR: Extrapolate_Central called with invalid alpha!");
399 
400  COM_assertion_msg(alpha>=-1.e-6 && alpha <= 1+1.e-6, "ERROR: Abort!");
401 
402  int order = agent->get_coupling()->get_rocmancontrol_param()->order;
403  if (order == 0 || agent->get_coupling()->new_start(t)) {
405  return;
406  }
407 
408  double base = -0.5;
409 
410  // linear interpolation.
411  extrapolate_Linear(dt, agent->get_old_dt(), base, attr_hdls[1], base+1.0, attr_hdls[0], alpha, attr_hdls[2], attr_hdls[3]);
412 }
413 
414 
415 
416 
417 
418 
419 
420 
InterpolateBase(Agent *ag, Agent *bkag, int cond=0)
Definition: Interpolate.C:30
virtual char * name()
Definition: Action.h:53
double get_old_dt() const
Definition: Agent.h:226
static int limit1
Definition: RocBlas.h:37
static int axpy_scalar
Definition: RocBlas.h:45
#define COM_assertion_msg(EX, msg)
int get_ipc() const
Definition: Coupling.h:160
Interpolate_Central(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf="_alp")
Definition: Interpolate.C:345
int get_attribute_handle(int i)
Definition: Action.C:93
int bkup_hdls[3]
Definition: Interpolate.h:45
static int copy
Definition: RocBlas.h:34
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
int get_attribute_handle_const(int i)
Definition: Action.C:110
static int copy_scalar
Definition: RocBlas.h:43
Definition: Action.h:32
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
std::string get_surface_window() const
Definition: Agent.h:217
char * action_name
Definition: Action.h:36
Definition: Agent.h:110
char ** attr
Definition: Action.h:37
Coupling * get_coupling()
Definition: Agent.h:213
Extrapolate_Central(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf="_alp", int cond=0)
Definition: Interpolate.C:188
void set_io(int n, const int *io)
Definition: Action.h:70
blockLoc i
Definition: read.cpp:79
Interpolate_Constant(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf="_alp")
Definition: Interpolate.C:307
void run(double t, double dt, double alpha)
Definition: Interpolate.C:392
void run(double t, double dt, double alpha)
Definition: Interpolate.C:285
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int new_start(double t) const
Definition: Coupling.C:170
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
int COM_get_window_handle(const char *wname)
Definition: roccom_c++.h:404
void run(double t, double dt, double alpha)
Definition: Interpolate.C:336
void run(double t, double dt, double alpha)
Definition: Interpolate.C:165
virtual void init(double t)
Definition: Interpolate.C:154
void register_interpolate(InterpolateBase *ip)
Definition: Agent.C:625
virtual void init(double t)
Definition: Interpolate.C:43
unsigned long time()
Get the value of a system timer with a millisecond precision.
Definition: CImg.h:4605
int attr_hdls[4]
Definition: Interpolate.h:44
#define MAN_DEBUG(l, x)
Definition: rocman.h:98
void set_attr(int n, const std::string at[], int *id=NULL)
Definition: Action.C:66
Extrapolate_Linear(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf="_alp", int cond=0)
Definition: Interpolate.C:137
const RocmanControl_parameters * get_rocmancontrol_param()
Definition: Coupling.h:184
virtual void init(double t)
Definition: Interpolate.C:223
Interpolate_Linear(Agent *ag, Agent *bkag, const std::string attr, const std::string alpsuf="_alp")
Definition: Interpolate.C:268
static int sub
Definition: RocBlas.h:36
Agent * bkagent
Definition: Interpolate.h:43
static int div_scalar
Definition: RocBlas.h:46
void extrapolate_Linear(double dt, double dt_old, double time_old, int a_old, double time_new, int a_new, double time_out, int a_out, int a_gra=-100)
Definition: Interpolate.C:94
int get_io(int i)
Definition: Action.h:74
void run(double t, double dt, double alpha)
Definition: Interpolate.C:242