57 signal(signum, SIG_DFL);
64 return "EDGE is initializing; MBDyn waits";
67 return "EDGE is busy; MBDyn waits";
70 return "EDGE waits (is ready to read kinematics); MBDyn iterates";
73 return "EDGE is computing; MBDyn waits before reading forces";
76 return "EDGE converged; MBDyn advances one step";
79 return "EDGE wants to end simulation";
97 if (f == NULL && errno == ENOENT) {
98 fprintf(stderr,
"test_modalext_edge: file \"%s\" missing\n", flag);
102 fgets(buf,
sizeof(buf), f);
103 if (strcmp(buf,
"UPDATE,N,0,0,1\n") != 0) {
104 size_t len = strlen(buf);
106 fprintf(stderr,
"test_modalext_edge: expecting \"UPDATE,N,0,0,1\", got \"%s\" from file \"%s\"\n", buf, flag);
110 fgets(buf,
sizeof(buf), f);
111 if (strcmp(buf,
"FLAG,I,1,1,0\n") != 0) {
112 size_t len = strlen(buf);
114 fprintf(stderr,
"test_modalext_edge: expecting \"FLAG,I,1,1,0\", got \"%s\" from file \"%s\"\n", buf, flag);
118 rc = fread((
void *)&c, 1, 1, f);
121 fprintf(stderr,
"test_modalext_edge: got %c (%s) from file \"%s\"\n", c,
cmd2str(c -
'0'), flag);
138 fprintf(stderr,
"test_modalext_edge: sleeping %d s\n", sleeptime);
150 char ftmpname[] =
"mbedgeXXXXXX";
154 int filedes = mkstemp(ftmpname);
155 f = fdopen(filedes,
"w");
158 #endif // HAVE_MKSTEMP
160 f = fopen(flag,
"w");
164 int save_errno = errno;
165 fprintf(stderr,
"unable to open flag file \"%s\" for writing (%d: %s)\n",
166 flag, save_errno, strerror(save_errno));
170 fprintf(f,
"UPDATE,N,0,0,1\n");
171 fprintf(f,
"FLAG,I,1,1,0\n");
172 fprintf(f,
"%d", cmd);
177 if (rename(ftmpname, flag) == -1) {
184 int save_errno = errno;
185 fprintf(stderr,
"unable to rename flag file \"%s\" (errno=%d: %s)\n",
186 flag, save_errno, strerror(save_errno));
202 f = fopen(rdata,
"w");
204 int save_errno = errno;
206 fprintf(stderr,
"unable to open rigid data file \"%s\" (%d: %s)\n",
207 rdata, save_errno, strerror(save_errno));
212 "* rigid-body forces and moments\n"
213 "body_forces,R,1,6,0\n");
214 for (i = 0; i < 6; i++) {
215 fprintf(f,
"%e ", fm[i]);
229 f = fopen(mdata,
"w");
231 int save_errno = errno;
233 fprintf(stderr,
"unable to open modal data file \"%s\" (%d: %s)\n",
234 mdata, save_errno, strerror(save_errno));
240 "modal_force_flow,R,%d,1,0\n",
242 for (i = 0; i < modes; i++) {
243 fprintf(f,
"%e ", fg[i]);
252 do_rigid0(
const char *rflag,
const char *rdata,
double *fm)
258 f = fopen(rflag,
"r");
260 int save_errno = errno;
261 if (save_errno == ENOENT) {
265 fprintf(stderr,
"unable to open rigid flag file \"%s\" (%d: %s)\n",
266 rflag, save_errno, strerror(save_errno));
274 for (i = 0; i < 6; i++) {
285 do_modal0(
const char *mflag,
const char *mdata,
int modes,
double **fgp)
291 f = fopen(mflag,
"r");
293 int save_errno = errno;
294 if (save_errno == ENOENT) {
298 fprintf(stderr,
"unable to open modal flag file \"%s\" (%d: %s)\n",
299 mflag, save_errno, strerror(save_errno));
307 *fgp = (
double *)malloc(
sizeof(
double)*modes);
308 for (i = 0; i < modes; i++) {
309 (*fgp)[i] = ((double)i)/10.0;
320 int niters,
int *iterp,
int cmd,
335 f = fopen(rdata,
"r");
337 int save_errno = errno;
339 fprintf(stderr,
"unable to open rigid data file \"%s\" (%d: %s)\n",
340 rdata, save_errno, strerror(save_errno));
344 while (fgets(buf,
sizeof(buf), f) != NULL) {
345 fprintf(stderr,
">> rdata:%s", buf);
360 int niters,
int *iterp,
int cmd,
361 int modes,
double *fg)
375 f = fopen(mdata,
"r");
377 int save_errno = errno;
379 fprintf(stderr,
"unable to open modal data file \"%s\" (%d: %s)\n",
380 mdata, save_errno, strerror(save_errno));
384 while (fgets(buf,
sizeof(buf), f) != NULL) {
385 fprintf(stderr,
">> mdata:%s", buf);
402 "usage: test_modalext_edge [options]\n"
403 "\t-c [random:]<c>\t\tnumber of iterations\n"
404 "\t-m [flag|data]=<file>\tmodal file names (set both)\n"
405 "\t-M <modes>\t\tmodes number\n"
406 "\t-n\t\t\tuse \"rename\" when writing flag files\n"
407 "\t-o {rm|mr}\tprocess rigid,modal (rm) or modal,rigid (mr)\n"
408 "\t-r [flag|data]=<file>\trigid-body file names (set both)\n"
409 "\t-s <sleeptime>\t\tsleep time between tries\n"
410 "\t-v\t\t\tverbose\n" );
429 int opt =
getopt(argc, argv,
"c:m:M:no:r:s:v");
437 if (strncasecmp(
optarg,
"random:",
sizeof(
"random:") -1) == 0) {
439 iters = atoi(&
optarg[
sizeof(
"random:") -1]);
443 fprintf(stderr,
"iterations: %d\n", iters);
446 fprintf(stderr,
"test_modalext_edge: "
447 "invalid sleep time %s\n",
454 if (strncasecmp(
optarg,
"flag=",
sizeof(
"flag=") - 1) == 0) {
455 mflag = &
optarg[
sizeof(
"flag=") - 1];
457 }
else if (strncasecmp(
optarg,
"data=",
sizeof(
"data=") - 1) == 0) {
458 mdata = &
optarg[
sizeof(
"data=") - 1];
461 fprintf(stderr,
"test_modalext_edge: "
462 "unknown modal file \"%s\"\n",
471 fprintf(stderr,
"test_modalext_edge: "
472 "invalid mode number %s\n",
481 #else // ! HAVE_MKSTEMP
482 fprintf(stderr,
"test_modalext_edge: "
483 "'-n' meaningless\n");
484 #endif // ! HAVE_MKSTEMP
488 if (strcmp(
optarg,
"rm") == 0) {
491 }
else if (strcmp(
optarg,
"mr") == 0) {
495 fprintf(stderr,
"test_modalext_edge: "
496 "invalid order \"%s\"\n",
503 if (strncasecmp(
optarg,
"flag=",
sizeof(
"flag=") - 1) == 0) {
504 rflag = &
optarg[
sizeof(
"flag=") - 1];
506 }
else if (strncasecmp(
optarg,
"data=",
sizeof(
"data=") - 1) == 0) {
507 rdata = &
optarg[
sizeof(
"data=") - 1];
510 fprintf(stderr,
"test_modalext_edge: "
511 "unknown rigid file \"%s\"\n",
520 fprintf(stderr,
"test_modalext_edge: "
521 "invalid iters %s\n",
537 if (mflag == NULL && mdata != NULL) {
538 fprintf(stderr,
"test_modalext_edge: "
539 "need modal flag file "
540 "along with modal data file \"%s\"\n",
545 if (mflag != NULL && mdata == NULL) {
546 fprintf(stderr,
"test_modalext_edge: "
547 "need modal data file "
548 "along with modal flag file \"%s\"\n",
553 if (rflag == NULL && rdata != NULL) {
554 fprintf(stderr,
"test_modalext_edge: "
555 "need rigid flag file "
556 "along with rigid data file \"%s\"\n",
561 if (rflag != NULL && rdata == NULL) {
562 fprintf(stderr,
"test_modalext_edge: "
563 "need rigid data file "
564 "along with rigid flag file \"%s\"\n",
569 if (mflag == NULL && rflag == NULL) {
570 fprintf(stderr,
"test_modalext_edge: "
571 "need at least rigid or modal files\n");
590 for (steps = 0; keep_going > 0; steps++) {
595 niters = rand() % iters + 1;
596 fprintf(stderr,
" iterations within this iter: %d\n", niters);
602 for (iter = 0; iter < niters; iter++) {
605 if (iter == niters - 1) {
611 do_rigid(rflag, rdata, niters, &iter, cmd, fm);
612 do_modal(mflag, mdata, niters, &iter, cmd, modes, fg);
616 do_modal(mflag, mdata, niters, &iter, cmd, modes, fg);
617 do_rigid(rflag, rdata, niters, &iter, cmd, fm);
int do_rigid(const char *rflag, const char *rdata, int niters, int *iterp, int cmd, double *fm)
int mbsleep(const mbsleep_t *t)
int main(int argc, char *argv[])
static int put_mdata(const char *mdata, int modes, double *fg)
static int put_flag(const char *flag, int cmd)
int do_modal(const char *mflag, const char *mdata, int niters, int *iterp, int cmd, int modes, double *fg)
static void sh(int signum)
static int do_modal0(const char *mflag, const char *mdata, int modes, double **fgp)
mbsleep_t mbsleep_init(long t)
static const char * cmd2str(int cmd)
static int put_rdata(const char *rdata, double fm[6])
volatile sig_atomic_t keep_going
static std::stack< cleanup * > c
int getopt(int argc, char *const argv[], const char *opts)
static int do_rigid0(const char *rflag, const char *rdata, double *fm)
static int check_flag(const char *flag, int sleeptime)
static doublereal buf[BUFSIZE]