53 signal(signum, SIG_DFL);
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"
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"
76 "\t-x\t\tdata_and_next\n");
94 static unsigned short int port = -1;
99 static double fx[6], *
f0 = NULL;
100 static double *
p0 = NULL;
111 int opt =
getopt(argc, argv,
"ac:f:H:i:lnN:o:p:rR:s:t:vx");
123 if (strncasecmp(
optarg,
"random:",
sizeof(
"random:") -1) == 0) {
125 iters = atoi(&
optarg[
sizeof(
"random:") -1]);
129 printf(
"iterations: %d\n", iters);
132 fprintf(stderr,
"test_strext_socket: "
133 "invalid iterations %s\n",
143 fprintf(stderr,
"test_strext_socket: "
144 "-i already provided\n");
149 fprintf(stderr,
"test_strext_socket: "
150 "-f already provided\n");
157 for (i = 0; i < 6; i++) {
159 const char fm[] =
"fm";
160 const char xyz[] =
"xyz";
162 f0[i] = strtod(s, &next);
164 fprintf(stderr,
"test_strext_socket: "
165 "unable to parse %c%c\n",
171 if (next[0] !=
',') {
172 fprintf(stderr,
"test_strext_socket: "
173 "unable to parse %c%c\n",
181 if (next[0] !=
'\0') {
182 fprintf(stderr,
"test_strext_socket: "
183 "extra cruft past %c%c\n",
192 if (strncasecmp(
optarg,
"inet://",
sizeof(
"inet://") - 1) == 0) {
197 ptr = strchr(
host,
':');
203 l = strtol(ptr, &next, 10);
204 if (next == ptr || next[0] !=
'\0') {
210 port = (
unsigned short)l;
212 }
else if (strncasecmp(
optarg,
"local://",
sizeof(
"local://") - 1) == 0) {
214 if (
path[0] !=
'/') {
228 fprintf(stderr,
"test_strext_socket: "
229 "-i error -f already provided\n");
234 fprintf(stderr,
"test_strext_socket: "
235 "-i error -p already provided\n");
240 fprintf(stderr,
"test_strext_socket: "
241 "-i already provided\n");
246 fprintf(stderr,
"test_strext_socket: "
247 "-i empty argument\n");
253 fprintf(stderr,
"test_strext_socket: "
254 "-i unable to open input file %s\n",
optarg);
259 fprintf(stderr,
"test_strext_socket: "
270 p0 = (
double *)calloc(
sizeof(
double), size*
nodes);
272 fprintf(stderr,
"test_strext_socket: "
273 "malloc for nodal force values failed\n");
287 fprintf(stderr,
"-n must occur before -p\n");
295 fprintf(stderr,
"test_strext_socket: "
296 "-N cannot follow -p\n");
302 fprintf(stderr,
"test_strext_socket: "
303 "invalid node number %s\n",
312 fprintf(stderr,
"test_strext_socket: "
313 "-o empty argument\n");
319 fprintf(stderr,
"unable to open output file %s\n",
optarg);
331 fprintf(stderr,
"test_strext_socket: "
332 "-p already provided\n");
337 fprintf(stderr,
"test_strext_socket: "
347 p0 = (
double *)calloc(
sizeof(
double), size*
nodes);
349 fprintf(stderr,
"test_strext_socket: "
350 "malloc for nodal force values failed\n");
355 for (i = 0; i < size*
nodes; i++) {
357 char fm[
sizeof(
"fm")] =
"fm";
358 const char xyz[] =
"xyz";
364 p0[i] = strtod(s, &next);
366 fprintf(stderr,
"test_strext_socket: "
367 "unable to parse %c%d%c\n",
368 fm[(i/3)%2], i/size, xyz[i%3]);
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]);
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]);
398 if (strcasecmp(
optarg,
"mat") == 0) {
401 }
else if (strcasecmp(
optarg,
"theta") == 0) {
404 }
else if (strcasecmp(
optarg,
"euler123") == 0) {
408 fprintf(stderr,
"test_strext_socket: "
409 "unknown orientation format \"%s\"\n",
418 fprintf(stderr,
"test_strext_socket: "
419 "invalid iters %s\n",
426 if (strcasecmp(
optarg,
"forever") == 0) {
493 niters = rand() % iters + 1;
494 printf(
" iterations within this iter: %d\n", niters);
500 for (iter = 0; iter < niters; iter++) {
525 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n", x[0], x[1], x[2]);
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]);
536 fprintf(
outputfile,
"T %+16.8e %+16.8e %+16.8e\n",
542 fprintf(
outputfile,
"E %+16.8e %+16.8e %+16.8e\n",
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]);
553 fprintf(stdout,
"reference node (%u):\n",
MBC_R_K_LABEL(mbc));
555 fprintf(stdout,
"reference node:\n");
557 fprintf(stdout,
"x={%+16.8e,%+16.8e,%+16.8e}\n", x[0], x[1], x[2]);
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]);
567 fprintf(stdout,
" theta={%+16.8e,%+16.8e,%+16.8e\n}",
573 fprintf(stdout,
"euler123={%+16.8e,%+16.8e,%+16.8e}\n",
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]);
582 if (mbc->
nodes > 0) {
592 for (n = 0; n < mbc->
nodes; n++) {
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]);
599 if (nomoments == 0) {
601 for (n = 0; n < mbc->
nodes; n++) {
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]);
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]);
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]);
631 for (n = 0; n < mbc->
nodes; n++) {
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]);
638 if (nomoments == 0) {
640 for (n = 0; n < mbc->
nodes; n++) {
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]);
650 for (n = 0; n < mbc->
nodes; n++) {
652 fprintf(stdout,
"node #%d (%u):\n", n, n_labels[n]);
654 fprintf(stdout,
"node #%d:\n", n);
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) {
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]);
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]);
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]);
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]);
698 if (inpfile && (iter == 0) && !feof(
inputfile)) {
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);
708 fprintf(stderr,
"Error wrong step number from input file,"
709 " is %u and shoul be %u\n", i,
steps);
713 if (fscanf(
inputfile,
"REF %lg %lg %lg %lg %lg %lg\n",
715 fprintf(stderr,
"Step: %u. Error while reading Reference Node"
716 " forces from input file\n",
steps);
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);
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);
767 if (mbc->
nodes > 0) {
776 for (n = 0; n < mbc->
nodes; n++) {
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];
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];
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);
831 tdata_(int32_t *REFNODE, int32_t *NODES, int32_t *ROT, int32_t *ITERS, int32_t *VERB,
896 if (mbc->
nodes > 0) {
900 for (n = 0; n < mbc->
nodes; n++) {
902 NF[3*n + 1] =
p0[6*n + 1];
903 NF[3*n + 2] =
p0[6*n + 2];
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];
911 for (n = 0; n < 3*mbc->
nodes; n++) {
912 NF[n] = (double)(n + 1);
913 NM[n] = (double)(n + 1);
923 int32_t *CONVERGED_P, int32_t *RC_P)
939 if (mbc->
nodes > 0) {
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];
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];
966 trecv_(
float *RX,
float *RR,
float *RXP,
float *ROMEGA,
967 float *NX,
float *NR,
float *NXP,
float *NOMEGA, int32_t *RC_P)
1022 if (mbc->
nodes > 0) {
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];
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];
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];
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];
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];
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];
#define MBC_F_LABELS(mbc)
int mbc_nodal_get_motion(mbc_nodal_t *mbc)
Get nodal motion from peer.
static unsigned short int port
void tdata_(int32_t *REFNODE, int32_t *NODES, int32_t *ROT, int32_t *ITERS, int32_t *VERB, int32_t *RC_P)
int mbc_nodal_init(mbc_nodal_t *mbc, unsigned refnode, unsigned nodes, unsigned labels, unsigned rot, unsigned accels)
Initialize nodal data.
#define MBC_N_D_LABELS(mbc)
static volatile sig_atomic_t keep_going
#define MBC_F_ACCELS(mbc)
void trecv_(float *RX, float *RR, float *RXP, float *ROMEGA, float *NX, float *NR, float *NXP, float *NOMEGA, int32_t *RC_P)
Connection data structure (partially opaque)
int mbc_nodal_put_forces(mbc_nodal_t *mbc, int last)
Put forces to peer.
#define MBC_R_K_LABEL(mbc)
int getopt(int argc, char *const argv[], const char *opts)
#define MBC_F_REF_NODE(mbc)
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)
int mbc_inet_init(mbc_t *mbc, const char *host, short unsigned port)
Initialize communication using "inet" socket.
Nodal stuff (partially opaque).
void tforce_(float *RF, float *RM, float *NF, float *NM)
#define MBC_R_EULER_123(mbc)
void test_init(int argc, char *argv[])
#define MBC_N_K_LABELS(mbc)
int mbc_nodal_destroy(mbc_nodal_t *mbc)
Destroy nodal data.
static void sh(int signum)
#define MBC_N_EULER_123(mbc)
void tsend_(float *RF, float *RM, float *NF, float *NM, int32_t *CONVERGED_P, int32_t *RC_P)