52 signal(signum, SIG_DFL);
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"
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"
75 "\t-x\t\tdata_and_next\n");
96 static unsigned short int port = -1;
98 static double fx[6], *
f0 = NULL;
99 static double *
p0 = NULL;
114 int opt =
getopt(argc, argv,
"ac:f:H:i:lnN:o:p:rR:s:t:vx");
126 if (strncasecmp(
optarg,
"random:",
sizeof(
"random:") -1) == 0) {
128 iters = atoi(&
optarg[
sizeof(
"random:") -1]);
132 printf(
"iterations: %d\n", iters);
135 fprintf(stderr,
"test_strext_socket: "
136 "invalid iterations %s\n",
146 fprintf(stderr,
"test_strext_socket: "
147 "-i already provided\n");
152 fprintf(stderr,
"test_strext_socket: "
153 "-f already provided\n");
160 for (i = 0; i < 6; i++) {
162 const char fm[] =
"fm";
163 const char xyz[] =
"xyz";
165 f0[i] = strtod(s, &next);
167 fprintf(stderr,
"test_strext_socket: "
168 "unable to parse %c%c\n",
174 if (next[0] !=
',') {
175 fprintf(stderr,
"test_strext_socket: "
176 "unable to parse %c%c\n",
184 if (next[0] !=
'\0') {
185 fprintf(stderr,
"test_strext_socket: "
186 "extra cruft past %c%c\n",
195 if (strncasecmp(
optarg,
"inet://",
sizeof(
"inet://") - 1) == 0) {
200 ptr = strchr(
host,
':');
206 l = strtol(ptr, &next, 10);
207 if (next == ptr || next[0] !=
'\0') {
213 port = (
unsigned short)l;
215 }
else if (strncasecmp(
optarg,
"local://",
sizeof(
"local://") - 1) == 0) {
217 if (
path[0] !=
'/') {
231 fprintf(stderr,
"test_strext_socket: "
232 "-i error -f already provided\n");
237 fprintf(stderr,
"test_strext_socket: "
238 "-i error -p already provided\n");
243 fprintf(stderr,
"test_strext_socket: "
244 "-i already provided\n");
249 fprintf(stderr,
"test_strext_socket: "
250 "-i empty argument\n");
256 fprintf(stderr,
"test_strext_socket: "
257 "-i unable to open input file %s\n",
optarg);
262 fprintf(stderr,
"test_strext_socket: "
273 p0 = (
double *)calloc(
sizeof(
double), size*
nodes);
275 fprintf(stderr,
"test_strext_socket: "
276 "malloc for nodal force values failed\n");
290 fprintf(stderr,
"-n must occur before -p\n");
298 fprintf(stderr,
"test_strext_socket: "
299 "-N cannot follow -p\n");
305 fprintf(stderr,
"test_strext_socket: "
306 "invalid node number %s\n",
315 fprintf(stderr,
"test_strext_socket: "
316 "-o empty argument\n");
322 fprintf(stderr,
"unable to open output file %s\n",
optarg);
334 fprintf(stderr,
"test_strext_socket: "
335 "-p already provided\n");
340 fprintf(stderr,
"test_strext_socket: "
350 p0 = (
double *)calloc(
sizeof(
double), size*
nodes);
352 fprintf(stderr,
"test_strext_socket: "
353 "malloc for nodal force values failed\n");
358 for (i = 0; i < size*
nodes; i++) {
360 char fm[
sizeof(
"fm")] =
"fm";
361 const char xyz[] =
"xyz";
367 p0[i] = strtod(s, &next);
369 fprintf(stderr,
"test_strext_socket: "
370 "unable to parse %c%d%c\n",
371 fm[(i/3)%2], i/size, xyz[i%3]);
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]);
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]);
401 if (strcasecmp(
optarg,
"mat") == 0) {
404 }
else if (strcasecmp(
optarg,
"theta") == 0) {
407 }
else if (strcasecmp(
optarg,
"euler123") == 0) {
411 fprintf(stderr,
"test_strext_socket: "
412 "unknown orientation format \"%s\"\n",
421 fprintf(stderr,
"test_strext_socket: "
422 "invalid iters %s\n",
429 if (strcasecmp(
optarg,
"forever") == 0) {
461 fprintf(stderr,
"test_strext_socket: "
462 "MBCNodal::Initialize() failed\n");
503 niters = rand() % iters + 1;
504 printf(
" iterations within this iter: %d\n", niters);
510 for (iter = 0; iter < niters; iter++) {
531 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
532 mbc->
X(1), mbc->
X(2), mbc->
X(3));
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));
544 fprintf(
outputfile,
"T %+16.8e %+16.8e %+16.8e\n",
549 fprintf(
outputfile,
"E %+16.8e %+16.8e %+16.8e\n",
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",
564 fprintf(stdout,
"reference node:\n");
566 fprintf(stdout,
"x={%+16.8e,%+16.8e,%+16.8e}\n",
567 mbc->
X(1), mbc->
X(2), mbc->
X(3));
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));
578 fprintf(stdout,
" theta={%+16.8e,%+16.8e,%+16.8e\n}",
583 fprintf(stdout,
"euler123={%+16.8e,%+16.8e,%+16.8e}\n",
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",
596 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
600 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
601 mbc->
X(n, 1), mbc->
X(n, 2), mbc->
X(n, 3));
603 if (nomoments == 0) {
605 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
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));
621 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
626 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
633 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
637 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
638 mbc->
XP(n, 1), mbc->
XP(n, 2), mbc->
XP(n, 3));
640 if (nomoments == 0) {
642 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
646 fprintf(
outputfile,
"%+16.8e %+16.8e %+16.8e\n",
652 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
656 fprintf(stdout,
"node #%d:\n", n - 1);
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) {
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));
672 fprintf(stdout,
" theta= %+16.8e %+16.8e %+16.8e\n",
677 fprintf(stdout,
" euler123= %+16.8e %+16.8e %+16.8e\n",
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",
697 if (inpfile && (iter == 0) && !feof(
inputfile)) {
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);
706 fprintf(stderr,
"Error wrong step number from input file,"
707 " is %u and shoul be %u\n", i,
steps);
711 if (fscanf(
inputfile,
"REF %lg %lg %lg %lg %lg %lg\n",
713 fprintf(stderr,
"Step: %u. Error while reading Reference Node"
714 " forces from input file\n",
steps);
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);
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);
764 for (
unsigned n = 1; n <= mbc->
GetNodes(); n++) {
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];
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];
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;
800 if (mbc->
PutForces((iter == niters - 1))) {
819 tdata_(int32_t *REFNODE, int32_t *NODES, int32_t *ROT, int32_t *ITERS, int32_t *VERB,
886 for (
unsigned n = 0; n < mbc->
GetNodes(); n++) {
888 NF[3*n + 1] =
p0[6*n + 1];
889 NF[3*n + 2] =
p0[6*n + 2];
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];
897 for (
unsigned n = 0; n < 3*mbc->
GetNodes(); n++) {
898 NF[n] = (double)(n + 1);
899 NM[n] = (double)(n + 1);
909 int32_t *CONVERGED_P, int32_t *RC_P)
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];
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];
945 trecv_(
float *RX,
float *RR,
float *RXP,
float *ROMEGA,
946 float *NX,
float *NR,
float *NXP,
float *NOMEGA, int32_t *RC_P)
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);
972 RR[0] = mbc->
Theta(1);
973 RR[1] = mbc->
Theta(2);
974 RR[2] = mbc->
Theta(3);
992 ROMEGA[0] = mbc->
Omega(1);
993 ROMEGA[1] = mbc->
Omega(2);
994 ROMEGA[2] = mbc->
Omega(3);
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);
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);
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);
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);
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);
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);
const double & Theta(uint8_t idx) const
bool bAccelerations(void) const
static volatile sig_atomic_t keep_going
uint32_t KinematicsLabel(void) const
void tforce_(float *RF, float *RM, float *NF, float *NM)
const double & X(uint8_t idx) const
bool bVerbose(void) const
void tdata_(int32_t *REFNODE, int32_t *NODES, int32_t *ROT, int32_t *ITERS, int32_t *VERB, int32_t *RC_P)
const double & R(uint8_t ir, uint8_t ic) const
const double & XP(uint8_t idx) const
int Initialize(MBCBase::Rot refnode_rot, unsigned nodes, bool labels, MBCBase::Rot rot, bool accels)
static MBCBase::Rot refnoderot
void test_init(int argc, char *argv[])
bool bRefNode(void) const
uint32_t GetNodes(void) const
MBCBase::Rot GetRot(void) const
const uint32_t & DynamicsLabel(void) const
MBCBase::Rot GetRefNodeRot(void) const
int Init(const char *const path)
static void sh(int signum)
const double & Omega(uint8_t idx) const
int getopt(int argc, char *const argv[], const char *opts)
static unsigned short int port
virtual int Negotiate(void) const
const double & M(uint8_t idx) const
const double & F(uint8_t idx) const
virtual int GetMotion(void) const
void trecv_(float *RX, float *RR, float *RXP, float *ROMEGA, float *NX, float *NR, float *NXP, float *NOMEGA, int32_t *RC_P)
virtual int PutForces(bool bConverged) const
void tsend_(float *RF, float *RM, float *NF, float *NM, int32_t *CONVERGED_P, int32_t *RC_P)
const double & Euler123(uint8_t idx) const