MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
test_strext_socket_lib.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include "test_strext_socket_lib.h"
#include "mbc.h"
Include dependency graph for test_strext_socket_lib.c:

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 int nodes = 0
 
static int labels = 0
 
static int accelerations = 0
 
static unsigned rot = MBC_ROT_MAT
 
static char * path = ((void*)0)
 
static char * host = ((void*)0)
 
static unsigned short int port = -1
 
static mbc_nodal_t mbcx = { { 0 } }
 
static mbc_nodal_tmbc = &mbcx
 
static double fx [6]
 
static double * f0 = ((void*)0)
 
static double * p0 = ((void*)0)
 
static int inpfile = 0
 
static int outfile = 0
 
static FILE * inputfile = ((void*)0)
 
static FILE * outputfile = ((void*)0)
 

Function Documentation

static void sh ( int  signum)
static

Definition at line 50 of file test_strext_socket_lib.c.

Referenced by test_init().

51 {
52  keep_going = 0;
53  signal(signum, SIG_DFL);
54 }
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 831 of file test_strext_socket_lib.c.

References iters, mbc_nodal_t::mbc, MBC_F_ACCELS, MBC_F_LABELS, MBC_F_REF_NODE, MBC_F_ROT, MBC_ROT_EULER_123, MBC_ROT_MAT, MBC_ROT_THETA, mbc_nodal_t::nodes, and mbc_t::verbose.

833 {
834  switch (MBC_F_ROT(mbc)) {
835  case MBC_ROT_MAT:
836  *ROT = 0;
837  break;
838 
839  case MBC_ROT_THETA:
840  *ROT = 1;
841  break;
842 
843  case MBC_ROT_EULER_123:
844  *ROT = 2;
845  break;
846 
847  default:
848  *RC_P = 1;
849  return;
850  }
851 
852  if (MBC_F_LABELS(mbc)) {
853  *RC_P = 1;
854  return;
855  }
856 
857  if (MBC_F_ACCELS(mbc)) {
858  *RC_P = 1;
859  return;
860  }
861 
862  *REFNODE = MBC_F_REF_NODE(mbc);
863  *NODES = mbc->nodes;
864  *VERB = mbc->mbc.verbose;
865 
866  *ITERS = iters;
867 
868  return;
869 }
#define MBC_F_LABELS(mbc)
Definition: mbc.h:241
mbc_t mbc
Definition: mbc.h:335
static int iters
int verbose
Definition: mbc.h:128
#define MBC_F_ACCELS(mbc)
Definition: mbc.h:242
#define MBC_F_ROT(mbc)
Definition: mbc.h:243
static mbc_nodal_t * mbc
#define MBC_F_REF_NODE(mbc)
Definition: mbc.h:240
uint32_t nodes
Definition: mbc.h:339
void test_init ( int  argc,
char *  argv[] 
)

Definition at line 108 of file test_strext_socket_lib.c.

Referenced by main().

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

Definition at line 486 of file test_strext_socket_lib.c.

Referenced by main().

487 {
488  for (steps = 0; keep_going > 0; steps++) {
489  int iter;
490  int niters;
491 
492  if (iters_random) {
493  niters = rand() % iters + 1;
494  printf(" iterations within this iter: %d\n", niters);
495 
496  } else {
497  niters = iters;
498  }
499 
500  for (iter = 0; iter < niters; iter++) {
501  /* receives motion when available
502  * errors out in case of problems
503  */
504  if (mbc_nodal_get_motion(mbc)) {
505  goto done;
506  }
507 
508  if (outfile) {
509  fprintf(outputfile, "STEP %u ITERATION %d\n", steps, iter);
510  }
511 
512  if (refnode) {
513  double *x = MBC_R_X(mbc);
514  double *R;
515  double *v = MBC_R_XP(mbc);
516  double *w = MBC_R_OMEGA(mbc);
517  if (outfile) {
518 
519  if (labels) {
520  fprintf(outputfile, "REF (%u)\n", MBC_R_K_LABEL(mbc));
521  } else {
522  fprintf(outputfile, "REF \n");
523  }
524 
525  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n", x[0], x[1], x[2]);
526 
527  switch (MBC_F_ROT(mbc)) {
528  default:
529  R = MBC_R_R(mbc);
530  fprintf(outputfile, "R %+16.8e %+16.8e %+16.8e", R[0], R[3], R[6]);
531  fprintf(outputfile, " %+16.8e %+16.8e %+16.8e", R[1], R[4], R[7]);
532  fprintf(outputfile, " %+16.8e %+16.8e %+16.8e\n", R[2], R[5], R[8]);
533  break;
534  case MBC_ROT_THETA:
535  R = MBC_R_THETA(mbc);
536  fprintf(outputfile, "T %+16.8e %+16.8e %+16.8e\n",
537  R[0], R[1], R[2]);
538  break;
539 
540  case MBC_ROT_EULER_123:
541  R = MBC_R_EULER_123(mbc);
542  fprintf(outputfile, "E %+16.8e %+16.8e %+16.8e\n",
543  R[0], R[1], R[2]);
544  break;
545  }
546 
547  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n", v[0], v[1], v[2]);
548  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n\n", w[0], w[1], w[2]);
549  }
550  else if (mbc->mbc.verbose) {
551 
552  if (labels) {
553  fprintf(stdout, "reference node (%u):\n", MBC_R_K_LABEL(mbc));
554  } else {
555  fprintf(stdout, "reference node:\n");
556  }
557  fprintf(stdout, "x={%+16.8e,%+16.8e,%+16.8e}\n", x[0], x[1], x[2]);
558  switch (MBC_F_ROT(mbc)) {
559  default:
560  R = MBC_R_R(mbc);
561  fprintf(stdout, "R={{%+16.8e,%+16.8e,%+16.8e};\n", R[0], R[3], R[6]);
562  fprintf(stdout, " {%+16.8e,%+16.8e,%+16.8e};\n", R[1], R[4], R[7]);
563  fprintf(stdout, " {%+16.8e,%+16.8e,%+16.8e}}\n", R[2], R[5], R[8]);
564  break;
565  case MBC_ROT_THETA:
566  R = MBC_R_THETA(mbc);
567  fprintf(stdout, " theta={%+16.8e,%+16.8e,%+16.8e\n}",
568  R[0], R[1], R[2]);
569  break;
570 
571  case MBC_ROT_EULER_123:
572  R = MBC_R_EULER_123(mbc);
573  fprintf(stdout, "euler123={%+16.8e,%+16.8e,%+16.8e}\n",
574  R[0], R[1], R[2]);
575  break;
576  }
577  fprintf(stdout, "v={%+16.8e,%+16.8e,%+16.8e}\n", v[0], v[1], v[2]);
578  fprintf(stdout, "w={%+16.8e,%+16.8e,%+16.8e}\n", w[0], w[1], w[2]);
579 
580  }
581  }
582  if (mbc->nodes > 0) {
583  uint32_t *n_labels = MBC_N_K_LABELS(mbc);
584  double *n_x = MBC_N_X(mbc);
585  double *n_r;
586  double *n_xp = MBC_N_XP(mbc);
587  double *n_omega = MBC_N_OMEGA(mbc);
588  unsigned n;
589 
590  if (outfile) {
591  fprintf(outputfile, "POS %u\n", mbc->nodes);
592  for (n = 0; n < mbc->nodes; n++) {
593  if (labels) {
594  fprintf(outputfile,"%d ", n_labels[n]);
595  }
596  fprintf(outputfile,"%+16.8e %+16.8e %+16.8e\n",
597  n_x[3*n], n_x[3*n + 1], n_x[3*n + 2]);
598  }
599  if (nomoments == 0) {
600  fprintf(outputfile, "ROT %u\n", mbc->nodes);
601  for (n = 0; n < mbc->nodes; n++) {
602  if (labels) {
603  fprintf(outputfile, "%d ", n_labels[n]);
604  }
605  switch (MBC_F_ROT(mbc)) {
606  default:
607  n_r = MBC_N_R(mbc);
608  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e"
609  " %+16.8e %+16.8e %+16.8e"
610  " %+16.8e %+16.8e %+16.8e\n",
611  n_r[9*n], n_r[9*n + 3], n_r[9*n + 6],
612  n_r[9*n + 1], n_r[9*n + 4], n_r[9*n + 7],
613  n_r[9*n + 2], n_r[9*n + 5], n_r[9*n + 8]);
614  break;
615 
616  case MBC_ROT_THETA:
617  n_r = MBC_N_THETA(mbc);
618  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
619  n_r[3*n], n_r[3*n + 1], n_r[3*n + 2]);
620  break;
621 
622  case MBC_ROT_EULER_123:
623  n_r = MBC_N_EULER_123(mbc);
624  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
625  n_r[3*n], n_r[3*n + 1], n_r[3*n + 2]);
626  break;
627  }
628  }
629  }
630  fprintf(outputfile, "VEL %u\n", mbc->nodes);
631  for (n = 0; n < mbc->nodes; n++) {
632  if (labels) {
633  fprintf(outputfile, "%d ", n_labels[n]);
634  }
635  fprintf(outputfile,"%+16.8e %+16.8e %+16.8e\n",
636  n_xp[3*n], n_xp[3*n + 1], n_xp[3*n + 2]);
637  }
638  if (nomoments == 0) {
639  fprintf(outputfile, "W %u\n", mbc->nodes);
640  for (n = 0; n < mbc->nodes; n++) {
641  if (labels) {
642  fprintf(outputfile, "%d ", n_labels[n]);
643  }
644  fprintf(outputfile, "%+16.8e %+16.8e %+16.8e\n",
645  n_omega[3*n], n_omega[3*n + 1], n_omega[3*n + 2]);
646  }
647  }
648  }
649  else if (mbc->mbc.verbose) {
650  for (n = 0; n < mbc->nodes; n++) {
651  if (labels) {
652  fprintf(stdout, "node #%d (%u):\n", n, n_labels[n]);
653  } else {
654  fprintf(stdout, "node #%d:\n", n);
655  }
656  fprintf(stdout, " x= %+16.8e %+16.8e %+16.8e\n",
657  n_x[3*n], n_x[3*n + 1], n_x[3*n + 2]);
658  if (nomoments == 0) {
659  switch (MBC_F_ROT(mbc)) {
660  default:
661  n_r = MBC_N_R(mbc);
662  fprintf(stdout, " R= %+16.8e %+16.8e %+16.8e\n"
663  " %+16.8e %+16.8e %+16.8e\n"
664  " %+16.8e %+16.8e %+16.8e\n",
665  n_r[9*n], n_r[9*n + 3], n_r[9*n + 6],
666  n_r[9*n + 1], n_r[9*n + 4], n_r[9*n + 7],
667  n_r[9*n + 2], n_r[9*n + 5], n_r[9*n + 8]);
668  break;
669 
670  case MBC_ROT_THETA:
671  n_r = MBC_N_THETA(mbc);
672  fprintf(stdout, " theta= %+16.8e %+16.8e %+16.8e\n",
673  n_r[3*n], n_r[3*n + 1], n_r[3*n + 2]);
674  break;
675 
676  case MBC_ROT_EULER_123:
677  n_r = MBC_N_EULER_123(mbc);
678  fprintf(stdout, " euler123= %+16.8e %+16.8e %+16.8e\n",
679  n_r[3*n], n_r[3*n + 1], n_r[3*n + 2]);
680  break;
681  }
682  }
683  fprintf(stdout, " xp= %+16.8e %+16.8e %+16.8e\n",
684  n_xp[3*n], n_xp[3*n + 1], n_xp[3*n + 2]);
685  if (nomoments == 0) {
686  fprintf(stdout, " omega= %+16.8e %+16.8e %+16.8e\n",
687  n_omega[3*n], n_omega[3*n + 1], n_omega[3*n + 2]);
688  }
689  }
690  }
691  }
692 
693  if (sleeptime) {
694  sleep(sleeptime);
695  }
696 
697  /* set forces */
698  if (inpfile && (iter == 0) && !feof(inputfile)) {
699  unsigned i;
700  unsigned n;
701  int size = 6;
702  if (fscanf(inputfile, "Step %u\n", &i) != 1) {
703  fprintf(stderr, "Step: %u. Error while reading step"
704  " number from input file\n", steps);
705  exit(EXIT_FAILURE);
706  }
707  if (i != steps) {
708  fprintf(stderr, "Error wrong step number from input file,"
709  " is %u and shoul be %u\n", i, steps);
710  exit(EXIT_FAILURE);
711  }
712  if (refnode) {
713  if (fscanf(inputfile, "REF %lg %lg %lg %lg %lg %lg\n",
714  &f0[0], &f0[1], &f0[2], &f0[3], &f0[4], &f0[5]) != 6) {
715  fprintf(stderr, "Step: %u. Error while reading Reference Node"
716  " forces from input file\n", steps);
717  exit(EXIT_FAILURE);
718  }
719  }
720 
721  if (nomoments) {
722  size = 3;
723  }
724  for (n = 0; n < mbc->nodes; n++) {
725  if (nomoments == 0) {
726  if (fscanf(inputfile, "%lg %lg %lg %lg %lg %lg\n",
727  &p0[size*n], &p0[size*n +1], &p0[size*n + 2],
728  &p0[size*n + 3], &p0[size*n +4], &p0[size*n + 5]) != 6) {
729  fprintf(stderr, "Step: %u. Error while reading Force & Moments"
730  " for Node %u from input file\n", steps, n);
731  exit(EXIT_FAILURE);
732  }
733  } else {
734  if (fscanf(inputfile, "%lg %lg %lg\n",
735  &p0[size*n], &p0[size*n + 1], &p0[size*n + 2]) != 3) {
736  fprintf(stderr, "Step: %u. Error while reading Forces for Node %u"
737  " from input file\n", steps, n);
738  exit(EXIT_FAILURE);
739  }
740  }
741  }
742  }
743  if (refnode) {
744  double *f = MBC_R_F(mbc);
745  double *m = MBC_R_M(mbc);
746 
747  if (f0 != NULL) {
748  f[0] = f0[0];
749  f[1] = f0[1];
750  f[2] = f0[2];
751 
752  m[0] = f0[3];
753  m[1] = f0[4];
754  m[2] = f0[5];
755 
756  } else {
757  f[0] = 1.;
758  f[1] = 2.;
759  f[2] = 3.;
760 
761  m[0] = 4.;
762  m[1] = 5.;
763  m[2] = 6.;
764  }
765  }
766 
767  if (mbc->nodes > 0) {
768  double *n_f = MBC_N_F(mbc);
769  double *n_m = MBC_N_M(mbc);
770  unsigned n;
771 
772  if (labels) {
773  uint32_t *k_l = MBC_N_K_LABELS(mbc);
774  uint32_t *d_l = MBC_N_D_LABELS(mbc);
775 
776  for (n = 0; n < mbc->nodes; n++) {
777  d_l[n] = k_l[n];
778  }
779  }
780 
781  if (p0) {
782  int size = 6;
783  if (nomoments) {
784  size = 3;
785  }
786  for (n = 0; n < mbc->nodes; n++) {
787  n_f[3*n] = p0[size*n];
788  n_f[3*n + 1] = p0[size*n + 1];
789  n_f[3*n + 2] = p0[size*n + 2];
790 
791  if (nomoments == 0) {
792  n_m[3*n] = p0[size*n + 3];
793  n_m[3*n + 1] = p0[size*n + 4];
794  n_m[3*n + 2] = p0[size*n + 5];
795  }
796  }
797 
798  } else {
799  for (n = 0; n < 3*mbc->nodes; n++) {
800  n_f[n] = (double)(n + 1);
801  if (nomoments == 0) {
802  n_m[n] = (double)(n + 1);
803  }
804  }
805  }
806  }
807 
808  /* sends forces
809  * second argument == 1 indicates convergence;
810  * otherwise MBDyn will send another solution
811  * and keep iterating */
812  if (mbc_nodal_put_forces(mbc, (iter == niters - 1))) {
813  goto done;
814  }
815  }
816  }
817 
818 done:;
819  /* destroy data structure and close socket */
821 
822  if (p0) {
823  free(p0);
824  }
825 }
static int inpfile
mbc_t mbc
Definition: mbc.h:335
int mbc_nodal_get_motion(mbc_nodal_t *mbc)
Get nodal motion from peer.
static int nomoments
static int iters
#define MBC_N_R(mbc)
Definition: mbc.h:365
#define MBC_N_X(mbc)
Definition: mbc.h:363
static double * f0
#define MBC_N_THETA(mbc)
Definition: mbc.h:364
#define MBC_N_D_LABELS(mbc)
Definition: mbc.h:371
int verbose
Definition: mbc.h:128
#define MBC_N_M(mbc)
Definition: mbc.h:373
#define MBC_R_OMEGA(mbc)
Definition: mbc.h:288
static double * p0
#define MBC_N_XP(mbc)
Definition: mbc.h:367
static int iters_random
static volatile sig_atomic_t keep_going
#define MBC_R_M(mbc)
Definition: mbc.h:293
static FILE * inputfile
#define MBC_R_XP(mbc)
Definition: mbc.h:287
static int labels
static FILE * outputfile
#define MBC_N_OMEGA(mbc)
Definition: mbc.h:368
static int outfile
#define MBC_N_F(mbc)
Definition: mbc.h:372
#define MBC_F_ROT(mbc)
Definition: mbc.h:243
static int sleeptime
int mbc_nodal_put_forces(mbc_nodal_t *mbc, int last)
Put forces to peer.
#define MBC_R_K_LABEL(mbc)
Definition: mbc.h:282
static mbc_nodal_t * mbc
#define MBC_R_R(mbc)
Definition: mbc.h:285
#define MBC_R_F(mbc)
Definition: mbc.h:292
static unsigned done
Definition: gust.cc:209
static unsigned steps
uint32_t nodes
Definition: mbc.h:339
#define MBC_R_X(mbc)
Definition: mbc.h:283
#define MBC_R_EULER_123(mbc)
Definition: mbc.h:286
#define MBC_N_K_LABELS(mbc)
Definition: mbc.h:362
#define MBC_R_THETA(mbc)
Definition: mbc.h:284
int mbc_nodal_destroy(mbc_nodal_t *mbc)
Destroy nodal data.
#define MBC_N_EULER_123(mbc)
Definition: mbc.h:366
static int refnode
Mat3x3 R
void tforce_ ( float *  RF,
float *  RM,
float *  NF,
float *  NM 
)

Definition at line 872 of file test_strext_socket_lib.c.

References f0, mbc_nodal_t::nodes, and p0.

873 {
874  /* set forces */
875  if (refnode) {
876  if (f0 != NULL) {
877  RF[0] = f0[0];
878  RF[1] = f0[1];
879  RF[2] = f0[2];
880 
881  RM[0] = f0[3];
882  RM[1] = f0[4];
883  RM[2] = f0[5];
884 
885  } else {
886  RF[0] = 1.;
887  RF[1] = 2.;
888  RF[2] = 3.;
889 
890  RM[0] = 4.;
891  RM[1] = 5.;
892  RM[2] = 6.;
893  }
894  }
895 
896  if (mbc->nodes > 0) {
897  unsigned n;
898 
899  if (p0) {
900  for (n = 0; n < mbc->nodes; n++) {
901  NF[3*n] = p0[6*n];
902  NF[3*n + 1] = p0[6*n + 1];
903  NF[3*n + 2] = p0[6*n + 2];
904 
905  NM[3*n] = p0[6*n + 3];
906  NM[3*n + 1] = p0[6*n + 4];
907  NM[3*n + 2] = p0[6*n + 5];
908  }
909 
910  } else {
911  for (n = 0; n < 3*mbc->nodes; n++) {
912  NF[n] = (double)(n + 1);
913  NM[n] = (double)(n + 1);
914  }
915  }
916  }
917 
918  return;
919 }
static double * f0
static double * p0
static mbc_nodal_t * mbc
uint32_t nodes
Definition: mbc.h:339
static int refnode
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 966 of file test_strext_socket_lib.c.

References MBC_F_REF_NODE, MBC_F_ROT, MBC_N_EULER_123, MBC_N_OMEGA, MBC_N_R, MBC_N_THETA, MBC_N_X, MBC_N_XP, mbc_nodal_get_motion(), MBC_R_EULER_123, MBC_R_OMEGA, MBC_R_R, MBC_R_THETA, MBC_R_X, MBC_R_XP, MBC_ROT_EULER_123, MBC_ROT_MAT, MBC_ROT_THETA, and mbc_nodal_t::nodes.

968 {
969  if (mbc_nodal_get_motion(mbc)) {
970  *RC_P = 1;
971  return;
972  }
973 
974  if (MBC_F_REF_NODE(mbc)) {
975  double *x = MBC_R_X(mbc);
976  double *r;
977  double *v = MBC_R_XP(mbc);
978  double *w = MBC_R_OMEGA(mbc);
979 
980  RX[0] = x[0];
981  RX[1] = x[1];
982  RX[2] = x[2];
983 
984  switch (MBC_F_ROT(mbc)) {
985  case MBC_ROT_MAT:
986  r = MBC_R_R(mbc);
987  RR[0] = r[0];
988  RR[1] = r[1];
989  RR[2] = r[2];
990  RR[3] = r[3];
991  RR[4] = r[4];
992  RR[5] = r[5];
993  RR[6] = r[6];
994  RR[7] = r[7];
995  RR[8] = r[8];
996  break;
997 
998  case MBC_ROT_THETA:
999  r = MBC_R_THETA(mbc);
1000  RR[0] = r[0];
1001  RR[1] = r[1];
1002  RR[2] = r[2];
1003  break;
1004 
1005  case MBC_ROT_EULER_123:
1006  r = MBC_R_EULER_123(mbc);
1007  RR[0] = r[0];
1008  RR[1] = r[1];
1009  RR[2] = r[2];
1010  break;
1011  }
1012 
1013  RXP[0] = v[0];
1014  RXP[1] = v[1];
1015  RXP[2] = v[2];
1016 
1017  ROMEGA[0] = w[0];
1018  ROMEGA[1] = w[1];
1019  ROMEGA[2] = w[2];
1020  }
1021 
1022  if (mbc->nodes > 0) {
1023  double *x = MBC_N_X(mbc);
1024  double *r;
1025  double *v = MBC_N_XP(mbc);
1026  double *w = MBC_N_OMEGA(mbc);
1027  unsigned node;
1028 
1029  for (node = 0; node < mbc->nodes; node++) {
1030  NX[3*node] = x[3*node];
1031  NX[3*node + 1] = x[3*node + 1];
1032  NX[3*node + 2] = x[3*node + 2];
1033 
1034  switch (MBC_F_ROT(mbc)) {
1035  case MBC_ROT_MAT:
1036  r = MBC_N_R(mbc);
1037  NR[9*node + 0] = r[9*node + 0];
1038  NR[9*node + 1] = r[9*node + 1];
1039  NR[9*node + 2] = r[9*node + 2];
1040  NR[9*node + 3] = r[9*node + 3];
1041  NR[9*node + 4] = r[9*node + 4];
1042  NR[9*node + 5] = r[9*node + 5];
1043  NR[9*node + 6] = r[9*node + 6];
1044  NR[9*node + 7] = r[9*node + 7];
1045  NR[9*node + 8] = r[9*node + 8];
1046  break;
1047 
1048  case MBC_ROT_THETA:
1049  r = MBC_N_THETA(mbc);
1050  NR[3*node + 0] = r[3*node + 0];
1051  NR[3*node + 1] = r[3*node + 1];
1052  NR[3*node + 2] = r[3*node + 2];
1053  break;
1054 
1055  case MBC_ROT_EULER_123:
1056  r = MBC_N_EULER_123(mbc);
1057  NR[3*node + 0] = r[3*node + 0];
1058  NR[3*node + 1] = r[3*node + 1];
1059  NR[3*node + 2] = r[3*node + 2];
1060  break;
1061  }
1062 
1063  NXP[3*node] = v[3*node];
1064  NXP[3*node + 1] = v[3*node + 1];
1065  NXP[3*node + 2] = v[3*node + 2];
1066 
1067  NOMEGA[3*node] = w[3*node];
1068  NOMEGA[3*node + 1] = w[3*node + 1];
1069  NOMEGA[3*node + 2] = w[3*node + 2];
1070  }
1071  }
1072 
1073  *RC_P = 0;
1074  return;
1075 }
int mbc_nodal_get_motion(mbc_nodal_t *mbc)
Get nodal motion from peer.
#define MBC_N_R(mbc)
Definition: mbc.h:365
#define MBC_N_X(mbc)
Definition: mbc.h:363
#define MBC_N_THETA(mbc)
Definition: mbc.h:364
#define MBC_R_OMEGA(mbc)
Definition: mbc.h:288
#define MBC_N_XP(mbc)
Definition: mbc.h:367
#define MBC_R_XP(mbc)
Definition: mbc.h:287
#define MBC_N_OMEGA(mbc)
Definition: mbc.h:368
#define MBC_F_ROT(mbc)
Definition: mbc.h:243
static mbc_nodal_t * mbc
#define MBC_R_R(mbc)
Definition: mbc.h:285
#define MBC_F_REF_NODE(mbc)
Definition: mbc.h:240
uint32_t nodes
Definition: mbc.h:339
#define MBC_R_X(mbc)
Definition: mbc.h:283
#define MBC_R_EULER_123(mbc)
Definition: mbc.h:286
#define MBC_R_THETA(mbc)
Definition: mbc.h:284
#define MBC_N_EULER_123(mbc)
Definition: mbc.h:366

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 922 of file test_strext_socket_lib.c.

References MBC_F_REF_NODE, MBC_N_F, MBC_N_M, mbc_nodal_put_forces(), MBC_R_F, MBC_R_M, and mbc_nodal_t::nodes.

924 {
925  /* set forces */
926  if (MBC_F_REF_NODE(mbc)) {
927  double *f = MBC_R_F(mbc);
928  double *m = MBC_R_M(mbc);
929 
930  f[0] = RF[0];
931  f[1] = RF[1];
932  f[2] = RF[2];
933 
934  m[0] = RM[0];
935  m[1] = RM[1];
936  m[2] = RM[2];
937  }
938 
939  if (mbc->nodes > 0) {
940  double *f = MBC_N_F(mbc);
941  double *m = MBC_N_M(mbc);
942  unsigned node;
943 
944  for (node = 0; node < mbc->nodes; node++) {
945  f[3*node] = NF[3*node];
946  f[3*node + 1] = NF[3*node + 1];
947  f[3*node + 2] = NF[3*node + 2];
948 
949  m[3*node] = NM[3*node];
950  m[3*node + 1] = NM[3*node + 1];
951  m[3*node + 2] = NM[3*node + 2];
952  }
953  }
954 
955  /* NOTE: the flag indicates convergence when not 0 */
956  if (mbc_nodal_put_forces(mbc, *CONVERGED_P)) {
957  *RC_P = 1;
958  return;
959  }
960 
961  *RC_P = 0;
962  return;
963 }
#define MBC_N_M(mbc)
Definition: mbc.h:373
#define MBC_R_M(mbc)
Definition: mbc.h:293
#define MBC_N_F(mbc)
Definition: mbc.h:372
int mbc_nodal_put_forces(mbc_nodal_t *mbc, int last)
Put forces to peer.
static mbc_nodal_t * mbc
#define MBC_F_REF_NODE(mbc)
Definition: mbc.h:240
#define MBC_R_F(mbc)
Definition: mbc.h:292
uint32_t nodes
Definition: mbc.h:339

Here is the call graph for this function:

static void usage ( void  )
static

Definition at line 57 of file test_strext_socket_lib.c.

Referenced by test_init().

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

Variable Documentation

int accelerations = 0
static

Definition at line 89 of file test_strext_socket_lib.c.

double * f0 = ((void*)0)
static
double fx[6]
static

Definition at line 99 of file test_strext_socket_lib.c.

Referenced by main(), and test_init().

char* host = ((void*)0)
static

Definition at line 93 of file test_strext_socket_lib.c.

Referenced by test_init().

int inpfile = 0
static

Definition at line 102 of file test_strext_socket_lib.c.

FILE* inputfile = ((void*)0)
static

Definition at line 104 of file test_strext_socket_lib.c.

Referenced by test_init(), and test_run().

int iters = 1
static

Definition at line 81 of file test_strext_socket_lib.c.

Referenced by main(), tdata_(), and test_run().

int iters_random = 0
static

Definition at line 82 of file test_strext_socket_lib.c.

Referenced by main().

volatile sig_atomic_t keep_going = 1
static

Definition at line 47 of file test_strext_socket_lib.c.

mbc_nodal_t* mbc = &mbcx
static

Definition at line 97 of file test_strext_socket_lib.c.

Referenced by main(), mbc_py_modal_initialize(), and mbc_py_nodal_initialize().

mbc_nodal_t mbcx = { { 0 } }
static

Definition at line 96 of file test_strext_socket_lib.c.

Referenced by main().

int nodes = 0
static
int nomoments = 0
static

Definition at line 85 of file test_strext_socket_lib.c.

int outfile = 0
static

Definition at line 103 of file test_strext_socket_lib.c.

Referenced by ReadElectric().

FILE* outputfile = ((void*)0)
static

Definition at line 105 of file test_strext_socket_lib.c.

Referenced by test_init(), and test_run().

double* p0 = ((void*)0)
static
char* path = ((void*)0)
static

Definition at line 92 of file test_strext_socket_lib.c.

Referenced by test_init().

unsigned short int port = -1
static

Definition at line 94 of file test_strext_socket_lib.c.

Referenced by test_init().

int refnode = 0
static

Definition at line 86 of file test_strext_socket_lib.c.

Referenced by main().

unsigned rot = MBC_ROT_MAT
static

Definition at line 90 of file test_strext_socket_lib.c.

Referenced by test_init().

int sleeptime = 1
static

Definition at line 80 of file test_strext_socket_lib.c.

unsigned steps
static

Definition at line 83 of file test_strext_socket_lib.c.

Referenced by main(), and test_run().