MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
test_strext_socket_lib.h File Reference
#include <stdint.h>
Include dependency graph for test_strext_socket_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void test_init (int argc, char *argv[])
 
void test_run (void)
 
void mainf_ (int32_t *rc_p)
 

Function Documentation

void mainf_ ( int32_t *  rc_p)

Referenced by main().

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

Definition at line 108 of file test_strext_socket_lib.c.

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.

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)

Here is the call graph for this function:

void test_run ( void  )

Definition at line 486 of file test_strext_socket_lib.c.

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().

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

Here is the call graph for this function: