MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
test_strext_socket_lib_cxx.cc File Reference
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <signal.h>
#include <unistd.h>
#include "mbcxx.h"
Include dependency graph for test_strext_socket_lib_cxx.cc:

Go to the source code of this file.

Functions

static void sh (int signum)
 
static void usage (void)
 
void test_init (int argc, char *argv[])
 
void test_run (void)
 
void tdata_ (int32_t *REFNODE, int32_t *NODES, int32_t *ROT, int32_t *ITERS, int32_t *VERB, int32_t *RC_P)
 
void tforce_ (float *RF, float *RM, float *NF, float *NM)
 
void tsend_ (float *RF, float *RM, float *NF, float *NM, int32_t *CONVERGED_P, int32_t *RC_P)
 
void trecv_ (float *RX, float *RR, float *RXP, float *ROMEGA, float *NX, float *NR, float *NXP, float *NOMEGA, int32_t *RC_P)
 

Variables

static volatile sig_atomic_t keep_going = 1
 
static int sleeptime = 1
 
static int iters = 1
 
static int iters_random = 0
 
static unsigned steps
 
static int nomoments = 0
 
static int refnode = 0
 
static MBCBase::Rot refnoderot = MBCBase::NONE
 
static int nodes = 0
 
static int labels = 0
 
static int accelerations = 0
 
static MBCBase::Rot rot = MBCBase::MAT
 
static MBCNodalmbc
 
static char * path
 
static char * host
 
static unsigned short int port = -1
 
static double fx [6]
 
static double * f0 = NULL
 
static double * p0 = NULL
 
static int timeout
 
static int verbose
 
static int data_and_next
 
static int inpfile = 0
 
static int outfile = 0
 
static FILE * inputfile = NULL
 
static FILE * outputfile = NULL
 

Function Documentation

static void sh ( int  signum)
static

Definition at line 49 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

50 {
51  keep_going = 0;
52  signal(signum, SIG_DFL);
53 }
static volatile sig_atomic_t keep_going
void tdata_ ( int32_t *  REFNODE,
int32_t *  NODES,
int32_t *  ROT,
int32_t *  ITERS,
int32_t *  VERB,
int32_t *  RC_P 
)

Definition at line 819 of file test_strext_socket_lib_cxx.cc.

References MBCBase::bAccelerations(), MBCBase::bLabels(), MBCBase::bRefNode(), MBCBase::bVerbose(), MBCNodal::GetNodes(), MBCBase::GetRot(), iters, MBC_ROT_EULER_123, MBC_ROT_MAT, and MBC_ROT_THETA.

821 {
822  switch (mbc->GetRot()) {
823  case MBC_ROT_MAT:
824  *ROT = 0;
825  break;
826 
827  case MBC_ROT_THETA:
828  *ROT = 1;
829  break;
830 
831  case MBC_ROT_EULER_123:
832  *ROT = 2;
833  break;
834 
835  default:
836  *RC_P = 1;
837  return;
838  }
839 
840  if (mbc->bLabels()) {
841  *RC_P = 1;
842  return;
843  }
844 
845  if (mbc->bAccelerations()) {
846  *RC_P = 1;
847  return;
848  }
849 
850  *REFNODE = mbc->bRefNode();
851  *NODES = mbc->GetNodes();
852  *VERB = mbc->bVerbose();
853 
854  *ITERS = iters;
855 
856  return;
857 }
bool bAccelerations(void) const
bool bVerbose(void) const
bool bRefNode(void) const
bool bLabels(void) const
uint32_t GetNodes(void) const
MBCBase::Rot GetRot(void) const
static MBCNodal * mbc
static int iters

Here is the call graph for this function:

void test_init ( int  argc,
char *  argv[] 
)

Definition at line 111 of file test_strext_socket_lib_cxx.cc.

References mbc_t::data_and_next, MBCBase::EULER_123, f0, fx, getopt(), host, MBCBase::Init(), MBCNodal::Initialize(), inputfile, MBCBase::MAT, mbc_nodal_t::mbc, mbc_inet_init(), mbc_nodal_init(), mbc_nodal_negotiate_request(), MBC_ROT_EULER_123, MBC_ROT_MAT, MBC_ROT_THETA, MBC_U_ROT_2_REF_NODE_ROT, mbc_unix_init(), MBCNodal::Negotiate(), nodes, MBCBase::NONE, optarg, outputfile, p0, path, port, refnoderot, rot, sh(), MBCBase::THETA, mbc_t::timeout, usage(), mbc_t::verbose, and xyz.

112 {
113  while (1) {
114  int opt = getopt(argc, argv, "ac:f:H:i:lnN:o:p:rR:s:t:vx");
115 
116  if (opt == EOF) {
117  break;
118  }
119 
120  switch (opt) {
121  case 'a':
122  accelerations = 1;
123  break;
124 
125  case 'c':
126  if (strncasecmp(optarg, "random:", sizeof("random:") -1) == 0) {
127  iters_random = 1;
128  iters = atoi(&optarg[sizeof("random:") -1]);
129 
130  } else {
131  iters = atoi(optarg);
132  printf("iterations: %d\n", iters);
133  }
134  if (iters < 1) {
135  fprintf(stderr, "test_strext_socket: "
136  "invalid iterations %s\n",
137  optarg);
138  usage();
139  }
140  break;
141 
142  case 'f': {
143  char *s;
144  int i;
145  if (inpfile) {
146  fprintf(stderr, "test_strext_socket: "
147  "-i already provided\n");
148  usage();
149  }
150 
151  if (f0 != NULL) {
152  fprintf(stderr, "test_strext_socket: "
153  "-f already provided\n");
154  usage();
155  }
156 
157  f0 = fx;
158 
159  s = optarg;
160  for (i = 0; i < 6; i++) {
161  char *next;
162  const char fm[] = "fm";
163  const char xyz[] = "xyz";
164 
165  f0[i] = strtod(s, &next);
166  if (next == s) {
167  fprintf(stderr, "test_strext_socket: "
168  "unable to parse %c%c\n",
169  fm[i/3], xyz[i%3]);
170  usage();
171  }
172 
173  if (i < 5) {
174  if (next[0] != ',') {
175  fprintf(stderr, "test_strext_socket: "
176  "unable to parse %c%c\n",
177  fm[i/3], xyz[i%3]);
178  usage();
179  }
180 
181  s = &next[1];
182 
183  } else {
184  if (next[0] != '\0') {
185  fprintf(stderr, "test_strext_socket: "
186  "extra cruft past %c%c\n",
187  fm[i/3], xyz[i%3]);
188  usage();
189  }
190  }
191  }
192  } break;
193 
194  case 'H':
195  if (strncasecmp(optarg, "inet://", sizeof("inet://") - 1) == 0) {
196  char *ptr, *next;
197  long l;
198 
199  host = optarg + sizeof("inet://") - 1;
200  ptr = strchr(host, ':');
201  if (ptr == NULL) {
202  usage();
203  }
204  *ptr = '\0';
205  ptr++;
206  l = strtol(ptr, &next, 10);
207  if (next == ptr || next[0] != '\0') {
208  usage();
209  }
210  if (l <= 0) {
211  usage();
212  }
213  port = (unsigned short)l;
214 
215  } else if (strncasecmp(optarg, "local://", sizeof("local://") - 1) == 0) {
216  path = optarg + sizeof("local://") - 1;
217  if (path[0] != '/') {
218  usage();
219  }
220 
221  } else {
222  usage();
223  }
224  break;
225 
226  case 'i' : {
227 
228  int size = 6;
229 
230  if (f0 != NULL) {
231  fprintf(stderr, "test_strext_socket: "
232  "-i error -f already provided\n");
233  usage();
234  }
235 
236  if (p0 != NULL) {
237  fprintf(stderr, "test_strext_socket: "
238  "-i error -p already provided\n");
239  usage();
240  }
241 
242  if (inputfile != NULL) {
243  fprintf(stderr, "test_strext_socket: "
244  "-i already provided\n");
245  usage();
246  }
247 
248  if (optarg == NULL) {
249  fprintf(stderr, "test_strext_socket: "
250  "-i empty argument\n");
251  usage();
252  }
253 
254  inputfile = fopen(optarg, "r");
255  if (inputfile == NULL) {
256  fprintf(stderr, "test_strext_socket: "
257  "-i unable to open input file %s\n", optarg);
258  usage();
259  }
260 
261  if (nodes <= 0) {
262  fprintf(stderr, "test_strext_socket: "
263  "-o requires -N\n");
264  usage();
265  }
266 
267  if (nomoments) {
268  size = 3;
269  }
270 
271  f0 = fx;
272 
273  p0 = (double *)calloc(sizeof(double), size*nodes);
274  if (p0 == NULL) {
275  fprintf(stderr, "test_strext_socket: "
276  "malloc for nodal force values failed\n");
277  exit(EXIT_FAILURE);
278  }
279 
280 
281  inpfile = 1;
282  } break;
283 
284  case 'l':
285  labels = 1;
286  break;
287 
288  case 'n':
289  if (p0 != NULL) {
290  fprintf(stderr, "-n must occur before -p\n");
291  usage();
292  }
293  nomoments = 1;
294  break;
295 
296  case 'N':
297  if (p0 != NULL) {
298  fprintf(stderr, "test_strext_socket: "
299  "-N cannot follow -p\n");
300  usage();
301  }
302 
303  nodes = atoi(optarg);
304  if (nodes <= 0) {
305  fprintf(stderr, "test_strext_socket: "
306  "invalid node number %s\n",
307  optarg);
308  usage();
309  }
310  break;
311 
312  case 'o':
313 
314  if (optarg == NULL) {
315  fprintf(stderr, "test_strext_socket: "
316  "-o empty argument\n");
317  usage();
318  }
319 
320  outputfile = fopen(optarg, "w");
321  if (outputfile == NULL) {
322  fprintf(stderr, "unable to open output file %s\n", optarg);
323  usage();
324  }
325 
326  outfile = 1;
327  break;
328 
329  case 'p': {
330  char *s;
331  int i, size = 6;
332 
333  if (p0 != NULL) {
334  fprintf(stderr, "test_strext_socket: "
335  "-p already provided\n");
336  usage();
337  }
338 
339  if (nodes <= 0) {
340  fprintf(stderr, "test_strext_socket: "
341  "-p requires -N\n");
342  usage();
343  }
344 
345  if (nomoments) {
346  size = 3;
347  }
348 
349 
350  p0 = (double *)calloc(sizeof(double), size*nodes);
351  if (p0 == NULL) {
352  fprintf(stderr, "test_strext_socket: "
353  "malloc for nodal force values failed\n");
354  exit(EXIT_FAILURE);
355  }
356 
357  s = optarg;
358  for (i = 0; i < size*nodes; i++) {
359  char *next;
360  char fm[sizeof("fm")] = "fm";
361  const char xyz[] = "xyz";
362 
363  if (nomoments) {
364  fm[1] = 'f';
365  }
366 
367  p0[i] = strtod(s, &next);
368  if (next == s) {
369  fprintf(stderr, "test_strext_socket: "
370  "unable to parse %c%d%c\n",
371  fm[(i/3)%2], i/size, xyz[i%3]);
372  usage();
373  }
374 
375  if (i < size*nodes - 1) {
376  if (next[0] != ',') {
377  fprintf(stderr, "test_strext_socket: "
378  "unable to parse %c%d%c\n",
379  fm[(i/3)%2], i/size, xyz[i%3]);
380  usage();
381  }
382 
383  s = &next[1];
384 
385  } else {
386  if (next[0] != '\0') {
387  fprintf(stderr, "test_strext_socket: "
388  "extra cruft past %c%d%c\n",
389  fm[(i/3)%2], i/size, xyz[i%3]);
390  usage();
391  }
392  }
393  }
394  } break;
395 
396  case 'r':
397  refnode = 1;
398  break;
399 
400  case 'R':
401  if (strcasecmp(optarg, "mat") == 0) {
402  rot = MBCBase::MAT;
403 
404  } else if (strcasecmp(optarg, "theta") == 0) {
406 
407  } else if (strcasecmp(optarg, "euler123") == 0) {
409 
410  } else {
411  fprintf(stderr, "test_strext_socket: "
412  "unknown orientation format \"%s\"\n",
413  optarg);
414  usage();
415  }
416  break;
417 
418  case 's':
419  sleeptime = atoi(optarg);
420  if (sleeptime < 0) {
421  fprintf(stderr, "test_strext_socket: "
422  "invalid iters %s\n",
423  optarg);
424  usage();
425  }
426  break;
427 
428  case 't':
429  if (strcasecmp(optarg, "forever") == 0) {
430  timeout = -1;
431  } else {
432  timeout = atoi(optarg);
433  }
434  break;
435 
436  case 'v':
437  verbose = 1;
438  break;
439 
440  case 'x':
441  data_and_next = 1;
442  break;
443 
444  default:
445  usage();
446  }
447  }
448 
449  if (refnode && refnoderot == MBCBase::NONE) {
450  refnoderot = rot;
451  }
452 
453  if (nomoments) {
454  rot = MBCBase::NONE;
455  }
456 
457  /* initialize data structure:
458  */
459  mbc = new MBCNodal;
460  if (mbc->Initialize(refnoderot, nodes, labels, rot, accelerations)) {
461  fprintf(stderr, "test_strext_socket: "
462  "MBCNodal::Initialize() failed\n");
463  usage();
464  }
465 
466  if (path) {
467  /* initialize UNIX socket (path) */
468  if (mbc->Init(path)) {
469  exit(EXIT_FAILURE);
470  }
471 
472  } else if (host) {
473  /* initialize INET socket (host, port) */
474  if (mbc->Init(host, port)) {
475  exit(EXIT_FAILURE);
476  }
477 
478  } else {
479  usage();
480  }
481 
482  /* "negotiate" configuration with MBDyn
483  * errors out if configurations are inconsistent */
484  if (mbc->Negotiate()) {
485  exit(EXIT_FAILURE);
486  }
487 
488  signal(SIGTERM, sh);
489  signal(SIGINT, sh);
490 }
static double fx[6]
static int timeout
static const char xyz[]
Definition: drvdisp.cc:194
static double * f0
static int labels
static int iters_random
static int verbose
static int nodes
static int sleeptime
static int refnode
int Initialize(MBCBase::Rot refnode_rot, unsigned nodes, bool labels, MBCBase::Rot rot, bool accels)
static MBCBase::Rot refnoderot
static FILE * inputfile
static FILE * outputfile
static char * path
static MBCNodal * mbc
int Init(const char *const path)
static void sh(int signum)
static char * host
static MBCBase::Rot rot
static int data_and_next
static int accelerations
int getopt(int argc, char *const argv[], const char *opts)
Definition: getopt.c:93
static unsigned short int port
virtual int Negotiate(void) const
static int inpfile
static void usage(void)
static int outfile
char * optarg
Definition: getopt.c:74
static int nomoments
struct s2s_t * next
Definition: s2s.h:86
static double * p0
static int iters

Here is the call graph for this function:

void test_run ( void  )

Definition at line 496 of file test_strext_socket_lib_cxx.cc.

References MBCBase::bLabels(), MBCBase::bVerbose(), done, MBCNodal::DynamicsLabel(), MBCNodal::Euler123(), MBCBase::EULER_123, MBCNodal::F(), f0, MBCNodal::GetMotion(), MBCNodal::GetNodes(), MBCBase::GetRefNodeRot(), MBCBase::GetRot(), inputfile, iters, MBCNodal::KinematicsLabel(), MBCNodal::M(), mbc, mbc_nodal_t::mbc, MBC_F_ROT, MBC_N_D_LABELS, MBC_N_EULER_123, MBC_N_F, MBC_N_K_LABELS, MBC_N_M, MBC_N_OMEGA, MBC_N_R, MBC_N_THETA, MBC_N_X, MBC_N_XP, mbc_nodal_destroy(), mbc_nodal_get_motion(), mbc_nodal_put_forces(), MBC_R_EULER_123, MBC_R_F, MBC_R_K_LABEL, MBC_R_M, MBC_R_OMEGA, MBC_R_R, MBC_R_THETA, MBC_R_X, MBC_R_XP, MBC_ROT_EULER_123, MBC_ROT_THETA, mbc_nodal_t::nodes, MBCNodal::Omega(), outputfile, p0, MBCNodal::PutForces(), R, MBCNodal::R(), steps, MBCBase::THETA, MBCNodal::Theta(), mbc_t::verbose, MBCNodal::X(), and MBCNodal::XP().

497 {
498  for (steps = 0; keep_going > 0; steps++) {
499  int iter;
500  int niters;
501 
502  if (iters_random) {
503  niters = rand() % iters + 1;
504  printf(" iterations within this iter: %d\n", niters);
505 
506  } else {
507  niters = iters;
508  }
509 
510  for (iter = 0; iter < niters; iter++) {
511  /* receives motion when available
512  * errors out in case of problems
513  */
514  if (mbc->GetMotion()) {
515  goto done;
516  }
517 
518  if (outfile) {
519  fprintf(outputfile, "STEP %u ITERATION %d\n", steps, iter);
520  }
521 
522  if (refnode) {
523  if (outfile) {
524  if (labels) {
525  fprintf(outputfile, "REF (%u)\n",
526  mbc->KinematicsLabel());
527  } else {
528  fprintf(outputfile, "REF \n");
529  }
530 
531  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
532  mbc->X(1), mbc->X(2), mbc->X(3));
533 
534  switch (mbc->GetRefNodeRot()) {
535  default:
536  fprintf(outputfile, "R %+16.8e %+16.8e %+16.8e",
537  mbc->R(1, 1), mbc->R(1, 2), mbc->R(1, 3));
538  fprintf(outputfile, " %+16.8e %+16.8e %+16.8e",
539  mbc->R(2, 1), mbc->R(2, 2), mbc->R(2, 3));
540  fprintf(outputfile, " %+16.8e %+16.8e %+16.8e\n",
541  mbc->R(3, 1), mbc->R(3, 2), mbc->R(3, 3));
542  break;
543  case MBCBase::THETA:
544  fprintf(outputfile, "T %+16.8e %+16.8e %+16.8e\n",
545  mbc->Theta(1), mbc->Theta(2), mbc->Theta(3));
546  break;
547 
548  case MBCBase::EULER_123:
549  fprintf(outputfile, "E %+16.8e %+16.8e %+16.8e\n",
550  mbc->Euler123(1), mbc->Euler123(2), mbc->Euler123(3));
551  break;
552  }
553 
554  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
555  mbc->XP(1), mbc->XP(2), mbc->XP(3));
556  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n\n",
557  mbc->Omega(1), mbc->Omega(2), mbc->Omega(3));
558 
559  } else if (mbc->bVerbose()) {
560 
561  if (mbc->bLabels()) {
562  fprintf(stdout, "reference node (%u):\n", mbc->KinematicsLabel());
563  } else {
564  fprintf(stdout, "reference node:\n");
565  }
566  fprintf(stdout, "x={%+16.8e,%+16.8e,%+16.8e}\n",
567  mbc->X(1), mbc->X(2), mbc->X(3));
568  switch (mbc->GetRefNodeRot()) {
569  default:
570  fprintf(stdout, "R={{%+16.8e,%+16.8e,%+16.8e};\n",
571  mbc->R(1, 1), mbc->R(1, 2), mbc->R(1, 3));
572  fprintf(stdout, " {%+16.8e,%+16.8e,%+16.8e};\n",
573  mbc->R(2, 1), mbc->R(2, 2), mbc->R(2, 3));
574  fprintf(stdout, " {%+16.8e,%+16.8e,%+16.8e}}\n",
575  mbc->R(3, 1), mbc->R(3, 2), mbc->R(3, 3));
576  break;
577  case MBCBase::THETA:
578  fprintf(stdout, " theta={%+16.8e,%+16.8e,%+16.8e\n}",
579  mbc->Theta(1), mbc->Theta(2), mbc->Theta(3));
580  break;
581 
582  case MBCBase::EULER_123:
583  fprintf(stdout, "euler123={%+16.8e,%+16.8e,%+16.8e}\n",
584  mbc->Euler123(1), mbc->Euler123(2), mbc->Euler123(3));
585  break;
586  }
587  fprintf(stdout, "v={%+16.8e,%+16.8e,%+16.8e}\n",
588  mbc->XP(1), mbc->XP(2), mbc->XP(3));
589  fprintf(stdout, "w={%+16.8e,%+16.8e,%+16.8e}\n",
590  mbc->Omega(1), mbc->Omega(2), mbc->Omega(3));
591  }
592  }
593  if (mbc->GetNodes() > 0) {
594  if (outfile) {
595  fprintf(outputfile, "POS %u\n", mbc->GetNodes());
596  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
597  if (labels) {
598  fprintf(outputfile,"%d ", mbc->KinematicsLabel(n));
599  }
600  fprintf(outputfile,"%+16.8e %+16.8e %+16.8e\n",
601  mbc->X(n, 1), mbc->X(n, 2), mbc->X(n, 3));
602  }
603  if (nomoments == 0) {
604  fprintf(outputfile, "ROT %u\n", mbc->GetNodes());
605  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
606  if (labels) {
607  fprintf(outputfile, "%d ", mbc->KinematicsLabel(n));
608  }
609  switch (mbc->GetRot()) {
610  default:
611  fprintf(outputfile,
612  "%+16.8e %+16.8e %+16.8e "
613  "%+16.8e %+16.8e %+16.8e "
614  "%+16.8e %+16.8e %+16.8e\n",
615  mbc->R(n, 1, 1), mbc->R(n, 1, 2), mbc->R(n, 1, 3),
616  mbc->R(n, 2, 1), mbc->R(n, 2, 2), mbc->R(n, 2, 3),
617  mbc->R(n, 3, 1), mbc->R(n, 3, 2), mbc->R(n, 3, 3));
618  break;
619 
620  case MBCBase::THETA:
621  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
622  mbc->Theta(n, 1), mbc->Theta(n, 2), mbc->Theta(n, 3));
623  break;
624 
625  case MBCBase::EULER_123:
626  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
627  mbc->Euler123(n, 1), mbc->Euler123(n, 2), mbc->Euler123(n, 3));
628  break;
629  }
630  }
631  }
632  fprintf(outputfile, "VEL %u\n", mbc->GetNodes());
633  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
634  if (labels) {
635  fprintf(outputfile, "%d ", mbc->KinematicsLabel(n));
636  }
637  fprintf(outputfile,"%+16.8e %+16.8e %+16.8e\n",
638  mbc->XP(n, 1), mbc->XP(n, 2), mbc->XP(n, 3));
639  }
640  if (nomoments == 0) {
641  fprintf(outputfile, "W %u\n", mbc->GetNodes());
642  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
643  if (labels) {
644  fprintf(outputfile, "%d ", mbc->KinematicsLabel(n));
645  }
646  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
647  mbc->Omega(n, 1), mbc->Omega(n, 2), mbc->Omega(n, 3));
648  }
649  }
650 
651  } else if (mbc->bVerbose()) {
652  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
653  if (labels) {
654  fprintf(stdout, "node #%d (%u):\n", n - 1, mbc->KinematicsLabel(n));
655  } else {
656  fprintf(stdout, "node #%d:\n", n - 1);
657  }
658  fprintf(stdout, " x= %+16.8e %+16.8e %+16.8e\n",
659  mbc->X(n, 1), mbc->X(n, 2), mbc->X(n, 3));
660  if (nomoments == 0) {
661  switch (mbc->GetRot()) {
662  default:
663  fprintf(stdout, " R= %+16.8e %+16.8e %+16.8e\n"
664  " %+16.8e %+16.8e %+16.8e\n"
665  " %+16.8e %+16.8e %+16.8e\n",
666  mbc->R(n, 1, 1), mbc->R(n, 1, 2), mbc->R(n, 1, 3),
667  mbc->R(n, 2, 1), mbc->R(n, 2, 2), mbc->R(n, 2, 3),
668  mbc->R(n, 3, 1), mbc->R(n, 3, 2), mbc->R(n, 3, 3));
669  break;
670 
671  case MBCBase::THETA:
672  fprintf(stdout, " theta= %+16.8e %+16.8e %+16.8e\n",
673  mbc->Theta(n, 1), mbc->Theta(n, 2), mbc->Theta(n, 3));
674  break;
675 
676  case MBCBase::EULER_123:
677  fprintf(stdout, " euler123= %+16.8e %+16.8e %+16.8e\n",
678  mbc->Euler123(n, 1), mbc->Euler123(n, 2), mbc->Euler123(n, 3));
679  break;
680  }
681  }
682  fprintf(stdout, " xp= %+16.8e %+16.8e %+16.8e\n",
683  mbc->XP(n, 1), mbc->XP(n, 2), mbc->XP(n, 3));
684  if (nomoments == 0) {
685  fprintf(stdout, " omega= %+16.8e %+16.8e %+16.8e\n",
686  mbc->Omega(n, 1), mbc->Omega(n, 2), mbc->Omega(n, 3));
687  }
688  }
689  }
690  }
691 
692  if (sleeptime) {
693  sleep(sleeptime);
694  }
695 
696  /* set forces */
697  if (inpfile && (iter == 0) && !feof(inputfile)) {
698  unsigned i;
699  int size = 6;
700  if (fscanf(inputfile, "Step %u\n", &i) != 1) {
701  fprintf(stderr, "Step: %u. Error while reading step"
702  " number from input file\n", steps);
703  exit(EXIT_FAILURE);
704  }
705  if (i != steps) {
706  fprintf(stderr, "Error wrong step number from input file,"
707  " is %u and shoul be %u\n", i, steps);
708  exit(EXIT_FAILURE);
709  }
710  if (refnode) {
711  if (fscanf(inputfile, "REF %lg %lg %lg %lg %lg %lg\n",
712  &f0[0], &f0[1], &f0[2], &f0[3], &f0[4], &f0[5]) != 6) {
713  fprintf(stderr, "Step: %u. Error while reading Reference Node"
714  " forces from input file\n", steps);
715  exit(EXIT_FAILURE);
716  }
717  }
718 
719  if (nomoments) {
720  size = 3;
721  }
722  for (unsigned n = 0; n < mbc->GetNodes(); n++) {
723  if (nomoments == 0) {
724  if (fscanf(inputfile, "%lg %lg %lg %lg %lg %lg\n",
725  &p0[size*n], &p0[size*n +1], &p0[size*n + 2],
726  &p0[size*n + 3], &p0[size*n +4], &p0[size*n + 5]) != 6) {
727  fprintf(stderr, "Step: %u. Error while reading Force & Moments"
728  " for Node %u from input file\n", steps, n);
729  exit(EXIT_FAILURE);
730  }
731  } else {
732  if (fscanf(inputfile, "%lg %lg %lg\n",
733  &p0[size*n], &p0[size*n + 1], &p0[size*n + 2]) != 3) {
734  fprintf(stderr, "Step: %u. Error while reading Forces for Node %u"
735  " from input file\n", steps, n);
736  exit(EXIT_FAILURE);
737  }
738  }
739  }
740  }
741  if (refnode) {
742  if (f0 != NULL) {
743  mbc->F(1) = f0[0];
744  mbc->F(2) = f0[1];
745  mbc->F(3) = f0[2];
746 
747  mbc->M(1) = f0[3];
748  mbc->M(2) = f0[4];
749  mbc->M(3) = f0[5];
750 
751  } else {
752  mbc->F(1) = 1.;
753  mbc->F(2) = 2.;
754  mbc->F(3) = 3.;
755 
756  mbc->M(1) = 4.;
757  mbc->M(2) = 5.;
758  mbc->M(3) = 6.;
759  }
760  }
761 
762  if (mbc->GetNodes() > 0) {
763  if (labels) {
764  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
766  }
767  }
768 
769  if (p0) {
770  int size = 6;
771  if (nomoments) {
772  size = 3;
773  }
774  for (unsigned n = 1; n <= mbc->GetNodes(); n++) {
775  mbc->F(n, 1) = p0[size*(n - 1)];
776  mbc->F(n, 2) = p0[size*(n - 1) + 1];
777  mbc->F(n, 3) = p0[size*(n - 1) + 2];
778 
779  if (nomoments == 0) {
780  mbc->M(n, 1) = p0[size*(n - 1) + 3];
781  mbc->M(n, 2) = p0[size*(n - 1) + 4];
782  mbc->M(n, 3) = p0[size*(n - 1) + 5];
783  }
784  }
785 
786  } else {
787  for (unsigned n = 1; n <= 3*mbc->GetNodes(); n++) {
788  mbc->F((n - 1)/3 + 1, (n - 1)%3 + 1) = (double)n;
789  if (nomoments == 0) {
790  mbc->M((n - 1)/3 + 1, (n - 1)%3 + 1) = (double)n;
791  }
792  }
793  }
794  }
795 
796  /* sends forces
797  * second argument == 1 indicates convergence;
798  * otherwise MBDyn will send another solution
799  * and keep iterating */
800  if (mbc->PutForces((iter == niters - 1))) {
801  goto done;
802  }
803  }
804  }
805 
806 done:;
807  /* destroy data structure and close socket */
808  delete mbc;
809 
810  if (p0) {
811  free(p0);
812  }
813 }
const double & Theta(uint8_t idx) const
static volatile sig_atomic_t keep_going
uint32_t KinematicsLabel(void) const
static double * f0
const double & X(uint8_t idx) const
static int labels
bool bVerbose(void) const
static int iters_random
static int sleeptime
static int refnode
const double & R(uint8_t ir, uint8_t ic) const
const double & XP(uint8_t idx) const
static FILE * inputfile
static FILE * outputfile
bool bLabels(void) const
uint32_t GetNodes(void) const
MBCBase::Rot GetRot(void) const
const uint32_t & DynamicsLabel(void) const
static MBCNodal * mbc
MBCBase::Rot GetRefNodeRot(void) const
const double & Omega(uint8_t idx) const
static unsigned steps
static int inpfile
static unsigned done
Definition: gust.cc:209
static int outfile
const double & M(uint8_t idx) const
const double & F(uint8_t idx) const
virtual int GetMotion(void) const
virtual int PutForces(bool bConverged) const
static int nomoments
static double * p0
const double & Euler123(uint8_t idx) const
static int iters

Here is the call graph for this function:

void tforce_ ( float *  RF,
float *  RM,
float *  NF,
float *  NM 
)

Definition at line 860 of file test_strext_socket_lib_cxx.cc.

References f0, MBCNodal::GetNodes(), and p0.

861 {
862  /* set forces */
863  if (refnode) {
864  if (f0 != NULL) {
865  RF[0] = f0[0];
866  RF[1] = f0[1];
867  RF[2] = f0[2];
868 
869  RM[0] = f0[3];
870  RM[1] = f0[4];
871  RM[2] = f0[5];
872 
873  } else {
874  RF[0] = 1.;
875  RF[1] = 2.;
876  RF[2] = 3.;
877 
878  RM[0] = 4.;
879  RM[1] = 5.;
880  RM[2] = 6.;
881  }
882  }
883 
884  if (mbc->GetNodes() > 0) {
885  if (p0) {
886  for (unsigned n = 0; n < mbc->GetNodes(); n++) {
887  NF[3*n] = p0[6*n];
888  NF[3*n + 1] = p0[6*n + 1];
889  NF[3*n + 2] = p0[6*n + 2];
890 
891  NM[3*n] = p0[6*n + 3];
892  NM[3*n + 1] = p0[6*n + 4];
893  NM[3*n + 2] = p0[6*n + 5];
894  }
895 
896  } else {
897  for (unsigned n = 0; n < 3*mbc->GetNodes(); n++) {
898  NF[n] = (double)(n + 1);
899  NM[n] = (double)(n + 1);
900  }
901  }
902  }
903 
904  return;
905 }
static double * f0
static int refnode
uint32_t GetNodes(void) const
static MBCNodal * mbc
static double * p0

Here is the call graph for this function:

void trecv_ ( float *  RX,
float *  RR,
float *  RXP,
float *  ROMEGA,
float *  NX,
float *  NR,
float *  NXP,
float *  NOMEGA,
int32_t *  RC_P 
)

Definition at line 945 of file test_strext_socket_lib_cxx.cc.

References MBCBase::bRefNode(), MBCNodal::Euler123(), MBCBase::EULER_123, MBCNodal::GetMotion(), MBCNodal::GetNodes(), MBCBase::GetRot(), MBCBase::MAT, MBCNodal::Omega(), MBCNodal::R(), MBCBase::THETA, MBCNodal::Theta(), MBCNodal::X(), and MBCNodal::XP().

947 {
948  if (mbc->GetMotion()) {
949  *RC_P = 1;
950  return;
951  }
952 
953  if (mbc->bRefNode()) {
954  RX[0] = mbc->X(1);
955  RX[1] = mbc->X(2);
956  RX[2] = mbc->X(3);
957 
958  switch (mbc->GetRot()) {
959  case MBCBase::MAT:
960  RR[0] = mbc->R(1, 1);
961  RR[1] = mbc->R(2, 1);
962  RR[2] = mbc->R(3, 1);
963  RR[3] = mbc->R(1, 2);
964  RR[4] = mbc->R(2, 2);
965  RR[5] = mbc->R(3, 2);
966  RR[6] = mbc->R(1, 3);
967  RR[7] = mbc->R(2, 3);
968  RR[8] = mbc->R(3, 3);
969  break;
970 
971  case MBCBase::THETA:
972  RR[0] = mbc->Theta(1);
973  RR[1] = mbc->Theta(2);
974  RR[2] = mbc->Theta(3);
975  break;
976 
977  case MBCBase::EULER_123:
978  RR[0] = mbc->Euler123(1);
979  RR[1] = mbc->Euler123(2);
980  RR[2] = mbc->Euler123(3);
981  break;
982 
983  default:
984  *RC_P = 1;
985  return;
986  }
987 
988  RXP[0] = mbc->XP(1);
989  RXP[1] = mbc->XP(2);
990  RXP[2] = mbc->XP(3);
991 
992  ROMEGA[0] = mbc->Omega(1);
993  ROMEGA[1] = mbc->Omega(2);
994  ROMEGA[2] = mbc->Omega(3);
995  }
996 
997  if (mbc->GetNodes() > 0) {
998  for (unsigned node = 1; node <= mbc->GetNodes(); node++) {
999  NX[3*(node - 1)] = mbc->X(node, 1);
1000  NX[3*(node - 1) + 1] = mbc->X(node, 2);
1001  NX[3*(node - 1) + 2] = mbc->X(node, 3);
1002 
1003  switch (mbc->GetRot()) {
1004  case MBCBase::MAT:
1005  NR[9*(node - 1)] = mbc->R(node, 1, 1);
1006  NR[9*(node - 1) + 1] = mbc->R(node, 2, 1);
1007  NR[9*(node - 1) + 2] = mbc->R(node, 3, 1);
1008  NR[9*(node - 1) + 3] = mbc->R(node, 1, 2);
1009  NR[9*(node - 1) + 4] = mbc->R(node, 2, 2);
1010  NR[9*(node - 1) + 5] = mbc->R(node, 3, 2);
1011  NR[9*(node - 1) + 6] = mbc->R(node, 1, 3);
1012  NR[9*(node - 1) + 7] = mbc->R(node, 2, 3);
1013  NR[9*(node - 1) + 8] = mbc->R(node, 3, 3);
1014  break;
1015 
1016  case MBCBase::THETA:
1017  NR[3*(node - 1)] = mbc->Theta(1);
1018  NR[3*(node - 1) + 1] = mbc->Theta(2);
1019  NR[3*(node - 1) + 2] = mbc->Theta(3);
1020  break;
1021 
1022  case MBCBase::EULER_123:
1023  NR[3*(node - 1)] = mbc->Euler123(1);
1024  NR[3*(node - 1) + 1] = mbc->Euler123(2);
1025  NR[3*(node - 1) + 2] = mbc->Euler123(3);
1026  break;
1027 
1028  default:
1029  *RC_P = 1;
1030  return;
1031  }
1032 
1033  NXP[3*(node - 1)] = mbc->XP(node, 1);
1034  NXP[3*(node - 1) + 1] = mbc->XP(node, 2);
1035  NXP[3*(node - 1) + 2] = mbc->XP(node, 3);
1036 
1037  NOMEGA[3*(node - 1)] = mbc->Omega(node, 1);
1038  NOMEGA[3*(node - 1) + 1] = mbc->Omega(node, 2);
1039  NOMEGA[3*(node - 1) + 2] = mbc->Omega(node, 3);
1040  }
1041  }
1042 
1043  *RC_P = 0;
1044  return;
1045 }
const double & Theta(uint8_t idx) const
const double & X(uint8_t idx) const
const double & R(uint8_t ir, uint8_t ic) const
const double & XP(uint8_t idx) const
bool bRefNode(void) const
uint32_t GetNodes(void) const
MBCBase::Rot GetRot(void) const
static MBCNodal * mbc
const double & Omega(uint8_t idx) const
virtual int GetMotion(void) const
const double & Euler123(uint8_t idx) const

Here is the call graph for this function:

void tsend_ ( float *  RF,
float *  RM,
float *  NF,
float *  NM,
int32_t *  CONVERGED_P,
int32_t *  RC_P 
)

Definition at line 908 of file test_strext_socket_lib_cxx.cc.

References MBCBase::bRefNode(), MBCNodal::F(), MBCNodal::GetNodes(), MBCNodal::M(), and MBCNodal::PutForces().

910 {
911  /* set forces */
912  if (mbc->bRefNode()) {
913  mbc->F(1) = RF[0];
914  mbc->F(2) = RF[1];
915  mbc->F(3) = RF[2];
916 
917  mbc->M(1) = RM[0];
918  mbc->M(2) = RM[1];
919  mbc->M(3) = RM[2];
920  }
921 
922  if (mbc->GetNodes() > 0) {
923  for (unsigned node = 1; node <= mbc->GetNodes(); node++) {
924  mbc->F(node, 1) = NF[3*(node - 1)];
925  mbc->F(node, 2) = NF[3*(node - 1) + 1];
926  mbc->F(node, 3) = NF[3*(node - 1) + 2];
927 
928  mbc->M(node, 1) = NM[3*(node - 1)];
929  mbc->M(node, 2) = NM[3*(node - 1) + 1];
930  mbc->M(node, 3) = NM[3*(node - 1) + 2];
931  }
932  }
933 
934  /* NOTE: the flag indicates convergence when not 0 */
935  if (mbc->PutForces(*CONVERGED_P)) {
936  *RC_P = 1;
937  return;
938  }
939 
940  *RC_P = 0;
941  return;
942 }
bool bRefNode(void) const
uint32_t GetNodes(void) const
static MBCNodal * mbc
const double & M(uint8_t idx) const
const double & F(uint8_t idx) const
virtual int PutForces(bool bConverged) const

Here is the call graph for this function:

static void usage ( void  )
static

Definition at line 56 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

57 {
58  fprintf(stderr,
59  "usage: testsocket [options]\n"
60  "\t-a\t\tuse accelerations\n"
61  "\t-c [random:]<c>\tnumber of iterations\n"
62  "\t-f {fx,fy,fz,mx,my,mz} reference node force/moment\n"
63  "\t-H <url>\tURL (local://path | inet://host:port)\n"
64  "\t-l\t\tlabels\n"
65  "\t-i <filename>\tinput file\n"
66  "\t-n\t\tonly forces, no moments\n"
67  "\t-N <nodes>\tnodes number\n"
68  "\t-o <filename>\t output file\n"
69  "\t-p {f0x,f0y,f0z,m0x,m0y,m0z,...}\tnodal forces (need -N first)\n"
70  "\t-r\t\tuse reference node data\n"
71  "\t-R {mat|theta|euler123}\torientation format\n"
72  "\t-s <sleeptime>\tsleep time between tries\n"
73  "\t-t <timeout>\thow long to wait for connection\n"
74  "\t-v\t\tverbose\n"
75  "\t-x\t\tdata_and_next\n");
76  exit(EXIT_FAILURE);
77 }

Variable Documentation

int accelerations = 0
static

Definition at line 89 of file test_strext_socket_lib_cxx.cc.

int data_and_next
static
double * f0 = NULL
static

Definition at line 98 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init(), test_run(), and tforce_().

double fx[6]
static

Definition at line 98 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

char* host
static

Definition at line 95 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

int inpfile = 0
static

Definition at line 105 of file test_strext_socket_lib_cxx.cc.

FILE* inputfile = NULL
static

Definition at line 107 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init(), and test_run().

int iters = 1
static

Definition at line 80 of file test_strext_socket_lib_cxx.cc.

Referenced by tdata_(), and test_run().

int iters_random = 0
static

Definition at line 81 of file test_strext_socket_lib_cxx.cc.

volatile sig_atomic_t keep_going = 1
static

Definition at line 46 of file test_strext_socket_lib_cxx.cc.

int labels = 0
static

Definition at line 88 of file test_strext_socket_lib_cxx.cc.

MBCNodal* mbc
static

Definition at line 92 of file test_strext_socket_lib_cxx.cc.

Referenced by test_run().

int nodes = 0
static

Definition at line 87 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

int nomoments = 0
static

Definition at line 84 of file test_strext_socket_lib_cxx.cc.

int outfile = 0
static

Definition at line 106 of file test_strext_socket_lib_cxx.cc.

FILE* outputfile = NULL
static

Definition at line 108 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init(), and test_run().

double* p0 = NULL
static

Definition at line 99 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init(), test_run(), and tforce_().

char* path
static

Definition at line 94 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

unsigned short int port = -1
static

Definition at line 96 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

int refnode = 0
static

Definition at line 85 of file test_strext_socket_lib_cxx.cc.

MBCBase::Rot refnoderot = MBCBase::NONE
static

Definition at line 86 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

MBCBase::Rot rot = MBCBase::MAT
static

Definition at line 90 of file test_strext_socket_lib_cxx.cc.

Referenced by test_init().

int sleeptime = 1
static

Definition at line 79 of file test_strext_socket_lib_cxx.cc.

unsigned steps
static

Definition at line 82 of file test_strext_socket_lib_cxx.cc.

Referenced by test_run().

int verbose
static

Definition at line 102 of file test_strext_socket_lib_cxx.cc.