MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbcxx.cc
Go to the documentation of this file.
1 /*
2  * MBDyn (C) is a multibody analysis code.
3  * http://www.mbdyn.org
4  *
5  * Copyright (C) 1996-2017
6  *
7  * Pierangelo Masarati <masarati@aero.polimi.it>
8  * Paolo Mantegazza <mantegazza@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
32 
33 #ifdef USE_SOCKET
34 
35 #include <stdlib.h>
36 #include <assert.h>
37 #include <cstring>
38 #include "mbcxx.h"
39 
41 MBCBase::GetRot(void) const
42 {
43  assert(GetStatus() >= INITIALIZED);
45 }
46 
47 bool
48 MBCBase::bRefNode(void) const
49 {
50  assert(GetStatus() >= INITIALIZED);
51  return MBC_F_REF_NODE(GetRefNodePtr());
52 }
53 
55 MBCBase::GetRefNodeRot(void) const {
56  assert(GetStatus() >= INITIALIZED);
58 }
59 
60 bool
61 MBCBase::bAccelerations(void) const
62 {
63  assert(GetStatus() >= INITIALIZED);
64  return MBC_F_ACCELS(GetRefNodePtr());
65 }
66 
67 bool
68 MBCBase::bLabels(void) const
69 {
70  assert(GetStatus() >= INITIALIZED);
71  return MBC_F_LABELS(GetRefNodePtr());
72 }
73 
74 void
76 {
77  GetBasePtr()->timeout = t;
78 }
79 
80 void
81 MBCBase::SetVerbose(bool bv)
82 {
83  GetBasePtr()->verbose = bv;
84 }
85 
86 void
88 {
89  GetBasePtr()->data_and_next = bd;
90 }
91 
92 bool
93 MBCBase::bVerbose(void) const
94 {
95  return GetBasePtr()->verbose;
96 }
97 
98 bool
99 MBCBase::bDataAndNext(void) const
100 {
101  return GetBasePtr()->data_and_next;
102 }
103 
105 MBCBase::GetStatus(void) const
106 {
107  return m_status;
108 }
109 
110 void
112 {
113  m_status = s;
114 }
115 
116 MBCBase::MBCBase(void)
117 : m_status(NOT_READY)
118 {
119 }
120 
121 MBCBase::~MBCBase(void)
122 {
123 }
124 
125 int
126 MBCBase::Init(const char *const path)
127 {
128  if (GetStatus() != INITIALIZED) return -1;
129  int rc = mbc_unix_init(GetBasePtr(), path);
130  if (rc == 0) SetStatus(SOCKET_READY);
131  return rc;
132 }
133 
134 int
135 MBCBase::Init(const char *const host, short unsigned port)
136 {
137  if (GetStatus() != INITIALIZED) return -1;
138  int rc = mbc_inet_init(GetBasePtr(), host, port);
139  if (rc == 0) SetStatus(SOCKET_READY);
140  return rc;
141 }
142 
143 int
144 MBCBase::GetCmd(void) const
145 {
146  return GetBasePtr()->cmd;
147 }
148 
149 uint32_t
151 {
152  assert(GetStatus() == READY);
153  return MBC_R_K_LABEL(GetRefNodePtr());
154 }
155 
156 uint32_t
157 MBCBase::KinematicsLabel(void) const
158 {
159  assert(GetStatus() == READY);
160  assert(bLabels());
161  return MBC_R_K_LABEL(GetRefNodePtr());
162 }
163 
164 const double *const
165 MBCBase::GetRefNodeX(void) const
166 {
167  assert(GetStatus() == READY);
168  assert(bRefNode());
169  return MBC_R_X(GetRefNodePtr());
170 }
171 
172 const double *const
173 MBCBase::GetRefNodeR(void) const
174 {
175  assert(GetStatus() == READY);
176  assert(bRefNode());
177  assert(GetRefNodeRot() == MAT);
178  return MBC_R_R(GetRefNodePtr());
179 }
180 
181 const double *const
182 MBCBase::GetRefNodeTheta(void) const
183 {
184  assert(GetStatus() == READY);
185  assert(bRefNode());
186  assert(GetRefNodeRot() == THETA);
187  return MBC_R_THETA(GetRefNodePtr());
188 }
189 
190 const double *const
191 MBCBase::GetRefNodeEuler123(void) const
192 {
193  assert(GetStatus() == READY);
194  assert(bRefNode());
195  assert(GetRefNodeRot() == EULER_123);
196  return MBC_R_EULER_123(GetRefNodePtr());
197 }
198 
199 const double *const
200 MBCBase::GetRefNodeXP(void) const
201 {
202  assert(GetStatus() == READY);
203  assert(bRefNode());
204  return MBC_R_XP(GetRefNodePtr());
205 }
206 
207 const double *const
208 MBCBase::GetRefNodeOmega(void) const
209 {
210  assert(GetStatus() == READY);
211  assert(bRefNode());
212  assert(GetRefNodeRot() != NONE);
213  return MBC_R_OMEGA(GetRefNodePtr());
214 }
215 
216 const double *const
217 MBCBase::GetRefNodeXPP(void) const
218 {
219  assert(GetStatus() == READY);
220  assert(bRefNode());
221  assert(bAccelerations());
222  return MBC_R_XPP(GetRefNodePtr());
223 }
224 
225 const double *const
226 MBCBase::GetRefNodeOmegaP(void) const
227 {
228  assert(GetStatus() == READY);
229  assert(bRefNode());
230  assert(GetRefNodeRot() != NONE);
231  assert(bAccelerations());
232  return MBC_R_OMEGAP(GetRefNodePtr());
233 }
234 
235 const double&
236 MBCBase::X(uint8_t idx) const
237 {
238  assert(GetStatus() == READY);
239  assert(bRefNode());
240  if (idx < 1 || idx > 3) throw;
241  return (MBC_R_X(GetRefNodePtr()))[idx - 1];
242 }
243 
244 const double&
245 MBCBase::R(uint8_t ir, uint8_t ic) const
246 {
247  assert(GetStatus() == READY);
248  assert(bRefNode());
249  assert(GetRefNodeRot() == MAT);
250  if (ir < 1 || ir > 3 || ic < 1 || ic > 3) throw;
251  return (MBC_R_R(GetRefNodePtr()))[3*(ic - 1) + ir - 1];
252 }
253 
254 const double&
255 MBCBase::Theta(uint8_t idx) const
256 {
257  assert(GetStatus() == READY);
258  assert(bRefNode());
259  assert(GetRefNodeRot() == THETA);
260  if (idx < 1 || idx > 3) throw;
261  return (MBC_R_THETA(GetRefNodePtr()))[idx - 1];
262 }
263 
264 const double&
265 MBCBase::Euler123(uint8_t idx) const
266 {
267  assert(GetStatus() == READY);
268  assert(bRefNode());
269  assert(GetRefNodeRot() == EULER_123);
270  if (idx < 1 || idx > 3) throw;
271  return (MBC_R_EULER_123(GetRefNodePtr()))[idx - 1];
272 }
273 
274 const double&
275 MBCBase::XP(uint8_t idx) const
276 {
277  assert(GetStatus() == READY);
278  assert(bRefNode());
279  if (idx < 1 || idx > 3) throw;
280  return (MBC_R_XP(GetRefNodePtr()))[idx - 1];
281 }
282 
283 const double&
284 MBCBase::Omega(uint8_t idx) const
285 {
286  assert(GetStatus() == READY);
287  assert(bRefNode());
288  assert(GetRefNodeRot() != NONE);
289  if (idx < 1 || idx > 3) throw;
290  return (MBC_R_OMEGA(GetRefNodePtr()))[idx - 1];
291 }
292 
293 const double&
294 MBCBase::XPP(uint8_t idx) const
295 {
296  assert(GetStatus() == READY);
297  assert(bRefNode());
298  assert(bAccelerations());
299  if (idx < 1 || idx > 3) throw;
300  return (MBC_R_XPP(GetRefNodePtr()))[idx - 1];
301 }
302 
303 const double&
304 MBCBase::OmegaP(uint8_t idx) const
305 {
306  assert(GetStatus() == READY);
307  assert(bRefNode());
308  assert(GetRefNodeRot() != NONE);
309  assert(bAccelerations());
310  if (idx < 1 || idx > 3) throw;
311  return (MBC_R_OMEGAP(GetRefNodePtr()))[idx - 1];
312 }
313 
314 uint32_t
316 {
317  assert(GetStatus() == READY);
318  assert(bRefNode());
319  return MBC_R_D_LABEL(GetRefNodePtr());
320 }
321 
322 const uint32_t&
323 MBCBase::DynamicsLabel(void) const
324 {
325  assert(GetStatus() == READY);
326  assert(bRefNode());
327  return MBC_R_D_LABEL(GetRefNodePtr());
328 }
329 
330 uint32_t&
332 {
333  assert(GetStatus() == READY);
334  assert(bRefNode());
335  return MBC_R_D_LABEL(GetRefNodePtr());
336 }
337 
338 const double *
339 MBCBase::GetRefNodeF(void) const
340 {
341  assert(GetStatus() == READY);
342  assert(bRefNode());
343  return MBC_R_F(GetRefNodePtr());
344 }
345 
346 const double *
347 MBCBase::GetRefNodeM(void) const
348 {
349  assert(GetStatus() == READY);
350  assert(bRefNode());
351  assert(GetRefNodeRot() != NONE);
352  return MBC_R_M(GetRefNodePtr());
353 }
354 
355 const double&
356 MBCBase::F(uint8_t idx) const
357 {
358  assert(GetStatus() == READY);
359  assert(bRefNode());
360  if (idx < 1 || idx > 3) throw;
361  return (MBC_R_F(GetRefNodePtr()))[idx - 1];
362 }
363 
364 double&
365 MBCBase::F(uint8_t idx)
366 {
367  assert(GetStatus() == READY);
368  assert(bRefNode());
369  if (idx < 1 || idx > 3) throw;
370  return (MBC_R_F(GetRefNodePtr()))[idx - 1];
371 }
372 
373 const double&
374 MBCBase::M(uint8_t idx) const
375 {
376  assert(GetStatus() == READY);
377  assert(bRefNode());
378  assert(GetRefNodeRot() != NONE);
379  if (idx < 1 || idx > 3) throw;
380  return (MBC_R_M(GetRefNodePtr()))[idx - 1];
381 }
382 
383 double&
384 MBCBase::M(uint8_t idx)
385 {
386  assert(GetStatus() == READY);
387  assert(bRefNode());
388  assert(GetRefNodeRot() != NONE);
389  if (idx < 1 || idx > 3) throw;
390  return (MBC_R_M(GetRefNodePtr()))[idx - 1];
391 }
392 
393 mbc_t *
394 MBCNodal::GetBasePtr(void) const
395 {
396  return (mbc_t*)&mbc;
397 }
398 
400 MBCNodal::GetRefNodePtr(void) const
401 {
402  return (mbc_refnode_stub_t *)&mbc;
403 }
404 
405 MBCNodal::MBCNodal(void)
406 {
407  memset(&mbc, 0, sizeof(mbc));
408 }
409 
410 MBCNodal::MBCNodal(MBCBase::Rot refnode_rot, unsigned nodes,
411  bool labels, MBCBase::Rot rot, bool accels)
412 {
413  if (Initialize(refnode_rot, nodes, labels, rot, accels)) {
414  throw;
415  }
416 }
417 
419 {
420  Close();
421 }
422 
424 MBCNodal::GetType(void) const
425 {
426  return NODAL;
427 }
428 
429 int
430 MBCNodal::Initialize(MBCBase::Rot refnode_rot, unsigned nodes,
431  bool labels, MBCBase::Rot rot, bool accels)
432 {
433  if (GetStatus() != NOT_READY) return -1;
434  memset(&mbc, 0, sizeof(mbc));
435  int rc = mbc_nodal_init(&mbc, refnode_rot, nodes, labels,
436  unsigned(rot) | MBC_U_ROT_2_REF_NODE_ROT(unsigned(refnode_rot)),
437  accels);
438  if (rc == 0) const_cast<MBCNodal *>(this)->SetStatus(INITIALIZED);
439  return rc;
440 }
441 
442 int
443 MBCNodal::Negotiate(void) const
444 {
445  if (GetStatus() != SOCKET_READY) return -1;
446  int rc = mbc_nodal_negotiate_request(&mbc);
447  if (rc == 0) const_cast<MBCNodal *>(this)->SetStatus(READY);
448  return rc;
449 }
450 
451 int
452 MBCNodal::PutForces(bool bConverged) const
453 {
454  if (GetStatus() != READY) return -1;
455  return mbc_nodal_put_forces(&mbc, bConverged);
456 }
457 
458 int
459 MBCNodal::GetMotion(void) const
460 {
461  if (GetStatus() != READY) return -1;
462  return mbc_nodal_get_motion(&mbc);
463 }
464 
465 int
466 MBCNodal::Close(void) const
467 {
468  int rc = -1;
469  if (GetStatus() == READY) {
470  rc = mbc_nodal_destroy(&mbc);
471  const_cast<MBCNodal *>(this)->SetStatus(CLOSED);
472  }
473  return rc;
474 }
475 
476 uint32_t
477 MBCNodal::KinematicsLabel(void) const
478 {
479  return MBCBase::KinematicsLabel();
480 }
481 
482 const double&
483 MBCNodal::X(uint8_t idx) const
484 {
485  return MBCBase::X(idx);
486 }
487 
488 const double&
489 MBCNodal::R(uint8_t ir, uint8_t ic) const
490 {
491  return MBCBase::R(ir, ic);
492 }
493 
494 const double&
495 MBCNodal::Theta(uint8_t idx) const
496 {
497  return MBCBase::Theta(idx);
498 }
499 
500 const double&
501 MBCNodal::Euler123(uint8_t idx) const
502 {
503  return MBCBase::Euler123(idx);
504 }
505 
506 const double&
507 MBCNodal::XP(uint8_t idx) const
508 {
509  return MBCBase::XP(idx);
510 }
511 
512 const double&
513 MBCNodal::Omega(uint8_t idx) const
514 {
515  return MBCBase::Omega(idx);
516 }
517 
518 const double&
519 MBCNodal::XPP(uint8_t idx) const
520 {
521  return MBCBase::XPP(idx);
522 }
523 
524 const double&
525 MBCNodal::OmegaP(uint8_t idx) const
526 {
527  return MBCBase::OmegaP(idx);
528 }
529 
530 const uint32_t&
531 MBCNodal::DynamicsLabel(void) const
532 {
533  return MBCBase::DynamicsLabel();
534 }
535 
536 uint32_t&
538 {
539  return MBCBase::DynamicsLabel();
540 }
541 
542 const double&
543 MBCNodal::F(uint8_t idx) const
544 {
545  return MBCBase::F(idx);
546 }
547 
548 double&
549 MBCNodal::F(uint8_t idx)
550 {
551  return MBCBase::F(idx);
552 }
553 
554 const double&
555 MBCNodal::M(uint8_t idx) const
556 {
557  return MBCBase::M(idx);
558 }
559 
560 double&
561 MBCNodal::M(uint8_t idx)
562 {
563  return MBCBase::M(idx);
564 }
565 
566 uint32_t
567 MBCNodal::GetNodes(void) const
568 {
569  assert(GetStatus() >= INITIALIZED);
570  return mbc.nodes;
571 }
572 
573 uint32_t *
575 {
576  assert(GetStatus() == READY);
577  assert(bLabels());
578  return MBC_N_K_LABELS(&mbc);
579 }
580 
581 const double *const
582 MBCNodal::GetX(void) const
583 {
584  assert(GetStatus() == READY);
585  return MBC_N_X(&mbc);
586 }
587 
588 const double *const
589 MBCNodal::GetR(void) const
590 {
591  assert(GetStatus() == READY);
592  assert(GetRot() == MAT);
593  return MBC_N_R(&mbc);
594 }
595 
596 const double *const
597 MBCNodal::GetTheta(void) const
598 {
599  assert(GetStatus() == READY);
600  assert(GetRot() == THETA);
601  return MBC_N_THETA(&mbc);
602 }
603 
604 const double *const
605 MBCNodal::GetEuler123(void) const
606 {
607  assert(GetStatus() == READY);
608  assert(GetRot() == EULER_123);
609  return MBC_N_EULER_123(&mbc);
610 }
611 
612 const double *const
613 MBCNodal::GetXP(void) const
614 {
615  assert(GetStatus() == READY);
616  return MBC_N_XP(&mbc);
617 }
618 
619 const double *const
620 MBCNodal::GetOmega(void) const
621 {
622  assert(GetStatus() == READY);
623  assert(GetRot() != NONE);
624  return MBC_N_OMEGA(&mbc);
625 }
626 
627 const double *const
628 MBCNodal::GetXPP(void) const
629 {
630  assert(GetStatus() == READY);
631  assert(bAccelerations());
632  return MBC_N_XPP(&mbc);
633 }
634 
635 const double *const
636 MBCNodal::GetOmegaP(void) const
637 {
638  assert(GetStatus() == READY);
639  assert(GetRot() != NONE);
640  assert(bAccelerations());
641  return MBC_N_OMEGAP(&mbc);
642 }
643 
644 const double&
645 MBCNodal::X(uint32_t n, uint8_t idx) const
646 {
647  assert(GetStatus() == READY);
648  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
649  return (MBC_N_X(&mbc))[3*(n - 1) + idx - 1];
650 }
651 
652 const double&
653 MBCNodal::R(uint32_t n, uint8_t ir, uint8_t ic) const
654 {
655  assert(GetStatus() == READY);
656  assert(GetRot() == MAT);
657  if (ir < 1 || ir > 3 || ic < 1 || ic > 3 || n < 1 || n > GetNodes()) throw;
658  return (MBC_N_R(&mbc))[9*(n - 1) + 3*(ic - 1) + ir - 1];
659 }
660 
661 const double&
662 MBCNodal::Theta(uint32_t n, uint8_t idx) const
663 {
664  assert(GetStatus() == READY);
665  assert(GetRot() == THETA);
666  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
667  return (MBC_N_THETA(&mbc))[3*(n - 1) + idx - 1];
668 }
669 
670 const double&
671 MBCNodal::Euler123(uint32_t n, uint8_t idx) const
672 {
673  assert(GetStatus() == READY);
674  assert(GetRot() == EULER_123);
675  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
676  return (MBC_N_EULER_123(&mbc))[3*(n - 1) + idx - 1];
677 }
678 
679 const double&
680 MBCNodal::XP(uint32_t n, uint8_t idx) const
681 {
682  assert(GetStatus() == READY);
683  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
684  return (MBC_N_XP(&mbc))[3*(n - 1) + idx - 1];
685 }
686 
687 const double&
688 MBCNodal::Omega(uint32_t n, uint8_t idx) const
689 {
690  assert(GetStatus() == READY);
691  assert(GetRot() != NONE);
692  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
693  return (MBC_N_OMEGA(&mbc))[3*(n - 1) + idx - 1];
694 }
695 
696 const double&
697 MBCNodal::XPP(uint32_t n, uint8_t idx) const
698 {
699  assert(GetStatus() == READY);
700  assert(bAccelerations());
701  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
702  return (MBC_N_XPP(&mbc))[3*(n - 1) + idx - 1];
703 }
704 
705 const double&
706 MBCNodal::OmegaP(uint32_t n, uint8_t idx) const
707 {
708  assert(GetStatus() == READY);
709  assert(GetRot() != NONE);
710  assert(bAccelerations());
711  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
712  return (MBC_N_OMEGAP(&mbc))[3*(n - 1) + idx - 1];
713 }
714 
715 uint32_t
716 MBCNodal::GetKinematicsLabel(uint32_t n) const
717 {
718  assert(GetStatus() == READY);
719  assert(bLabels());
720  if (n < 1 || n > GetNodes()) throw;
721  return (MBC_N_K_LABELS(&mbc))[n - 1];
722 }
723 
724 uint32_t
725 MBCNodal::KinematicsLabel(uint32_t n) const
726 {
727  assert(GetStatus() == READY);
728  assert(bLabels());
729  if (n < 1 || n > GetNodes()) throw;
730  return (MBC_N_K_LABELS(&mbc))[n - 1];
731 }
732 
733 const double *const
734 MBCNodal::GetX(uint32_t n) const
735 {
736  assert(GetStatus() == READY);
737  return &(MBC_N_X(&mbc)[3*(n - 1)]);
738 }
739 
740 const double *const
741 MBCNodal::GetR(uint32_t n) const
742 {
743  assert(GetStatus() == READY);
744  assert(GetRot() == MAT);
745  return &(MBC_N_R(&mbc)[9*(n - 1)]);
746 }
747 
748 const double *const
749 MBCNodal::GetTheta(uint32_t n) const
750 {
751  assert(GetStatus() == READY);
752  assert(GetRot() == THETA);
753  return &(MBC_N_THETA(&mbc)[3*(n - 1)]);
754 }
755 
756 const double *const
757 MBCNodal::GetEuler123(uint32_t n) const
758 {
759  assert(GetStatus() == READY);
760  assert(GetRot() == EULER_123);
761  return &(MBC_N_EULER_123(&mbc)[3*(n - 1)]);
762 }
763 
764 const double *const
765 MBCNodal::GetXP(uint32_t n) const
766 {
767  assert(GetStatus() == READY);
768  return &(MBC_N_XP(&mbc)[3*(n - 1)]);
769 }
770 
771 const double *const
772 MBCNodal::GetOmega(uint32_t n) const
773 {
774  assert(GetStatus() == READY);
775  assert(GetRot() != NONE);
776  return &(MBC_N_OMEGA(&mbc)[3*(n - 1)]);
777 }
778 
779 const double *const
780 MBCNodal::GetXPP(uint32_t n) const
781 {
782  assert(GetStatus() == READY);
783  assert(bAccelerations());
784  return &(MBC_N_XPP(&mbc)[3*(n - 1)]);
785 }
786 
787 const double *const
788 MBCNodal::GetOmegaP(uint32_t n) const
789 {
790  assert(GetStatus() == READY);
791  assert(GetRot() != NONE);
792  assert(bAccelerations());
793  return &(MBC_N_OMEGAP(&mbc)[3*(n - 1)]);
794 }
795 
796 uint32_t *
797 MBCNodal::GetDynamicsLabel(void) const
798 {
799  assert(GetStatus() == READY);
800  assert(bLabels());
801  return MBC_N_D_LABELS(&mbc);
802 }
803 
804 const uint32_t&
805 MBCNodal::DynamicsLabel(uint32_t n) const
806 {
807  assert(GetStatus() == READY);
808  assert(bLabels());
809  if (n < 1 || n > GetNodes()) throw;
810  return (MBC_N_D_LABELS(&mbc))[n - 1];
811 }
812 
813 uint32_t&
814 MBCNodal::DynamicsLabel(uint32_t n)
815 {
816  assert(GetStatus() == READY);
817  assert(bLabels());
818  if (n < 1 || n > GetNodes()) throw;
819  return (MBC_N_D_LABELS(&mbc))[n - 1];
820 }
821 
822 const double *
823 MBCNodal::GetF(void) const
824 {
825  assert(GetStatus() == READY);
826  return MBC_N_F(&mbc);
827 }
828 
829 const double *
830 MBCNodal::GetM(void) const
831 {
832  assert(GetStatus() == READY);
833  assert(GetRot() != NONE);
834  return MBC_N_M(&mbc);
835 }
836 
837 const double *
838 MBCNodal::GetF(uint32_t n) const
839 {
840  assert(GetStatus() == READY);
841  if (n < 1 || n > GetNodes()) throw;
842  return &(MBC_N_F(&mbc))[3*(n - 1)];
843 }
844 
845 const double *
846 MBCNodal::GetM(uint32_t n) const
847 {
848  assert(GetStatus() == READY);
849  assert(GetRot() != NONE);
850  if (n < 1 || n > GetNodes()) throw;
851  return &(MBC_N_M(&mbc))[3*(n - 1)];
852 }
853 
854 const double&
855 MBCNodal::F(uint32_t n, uint8_t idx) const
856 {
857  assert(GetStatus() == READY);
858  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
859  return (MBC_N_F(&mbc))[3*(n - 1) + idx - 1];
860 }
861 
862 double&
863 MBCNodal::F(uint32_t n, uint8_t idx)
864 {
865  assert(GetStatus() == READY);
866  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
867  return (MBC_N_F(&mbc))[3*(n - 1) + idx - 1];
868 }
869 
870 const double&
871 MBCNodal::M(uint32_t n, uint8_t idx) const
872 {
873  assert(GetStatus() == READY);
874  assert(GetRot() != NONE);
875  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
876  return (MBC_N_M(&mbc))[3*(n - 1) + idx - 1];
877 }
878 
879 double&
880 MBCNodal::M(uint32_t n, uint8_t idx)
881 {
882  assert(GetStatus() == READY);
883  assert(GetRot() != NONE);
884  if (idx < 1 || idx > 3 || n < 1 || n > GetNodes()) throw;
885  return (MBC_N_M(&mbc))[3*(n - 1) + idx - 1];
886 }
887 
888 mbc_t *
889 MBCModal::GetBasePtr(void) const
890 {
891  return (mbc_t*)&mbc;
892 }
893 
895 MBCModal::GetRefNodePtr(void) const
896 {
897  return (mbc_refnode_stub_t *)&mbc;
898 }
899 
900 MBCModal::MBCModal(void)
901 {
902  memset(&mbc, 0, sizeof(mbc));
903 }
904 
905 MBCModal::MBCModal(MBCBase::Rot refnode_rot, unsigned modes)
906 {
907  if (Initialize(refnode_rot, modes)) {
908  throw;
909  }
910 }
911 
913 {
914  Close();
915 }
916 
918 MBCModal::GetType(void) const
919 {
920  return MODAL;
921 }
922 
923 int
924 MBCModal::Initialize(MBCBase::Rot refnode_rot, unsigned modes)
925 {
926  if (GetStatus() != NOT_READY) return -1;
927  memset(&mbc, 0, sizeof(mbc));
928  int rc = mbc_modal_init(&mbc, refnode_rot, modes);
929  if (rc == 0) const_cast<MBCModal *>(this)->SetStatus(INITIALIZED);
930  return rc;
931 }
932 
933 int
934 MBCModal::Negotiate(void) const
935 {
936  if (GetStatus() != SOCKET_READY) return -1;
937  int rc = mbc_modal_negotiate_request(&mbc);
938  if (rc == 0) const_cast<MBCModal *>(this)->SetStatus(READY);
939  return rc;
940 }
941 
942 int
943 MBCModal::PutForces(bool bConverged) const
944 {
945  if (GetStatus() != READY) return -1;
946  return mbc_modal_put_forces(&mbc, bConverged);
947 }
948 
949 int
950 MBCModal::GetMotion(void) const
951 {
952  if (GetStatus() != READY) return -1;
953  return mbc_modal_get_motion(&mbc);
954 }
955 
956 int
957 MBCModal::Close(void) const
958 {
959  int rc = -1;
960  if (GetStatus() == READY) {
961  rc = mbc_modal_destroy(&mbc);
962  const_cast<MBCModal *>(this)->SetStatus(CLOSED);
963  }
964  return rc;
965 }
966 
967 uint32_t
968 MBCModal::KinematicsLabel(void) const
969 {
970  return MBCBase::KinematicsLabel();
971 }
972 
973 const double&
974 MBCModal::X(uint8_t idx) const
975 {
976  return MBCBase::X(idx);
977 }
978 
979 const double&
980 MBCModal::R(uint8_t ir, uint8_t ic) const
981 {
982  return MBCBase::R(ir, ic);
983 }
984 
985 const double&
986 MBCModal::Theta(uint8_t idx) const
987 {
988  return MBCBase::Theta(idx);
989 }
990 
991 const double&
992 MBCModal::Euler123(uint8_t idx) const
993 {
994  return MBCBase::Euler123(idx);
995 }
996 
997 const double&
998 MBCModal::XP(uint8_t idx) const
999 {
1000  return MBCBase::XP(idx);
1001 }
1002 
1003 const double&
1004 MBCModal::Omega(uint8_t idx) const
1005 {
1006  return MBCBase::Omega(idx);
1007 }
1008 
1009 const double&
1010 MBCModal::XPP(uint8_t idx) const
1011 {
1012  return MBCBase::XPP(idx);
1013 }
1014 
1015 const double&
1016 MBCModal::OmegaP(uint8_t idx) const
1017 {
1018  return MBCBase::OmegaP(idx);
1019 }
1020 
1021 const uint32_t&
1022 MBCModal::DynamicsLabel(void) const
1023 {
1024  return MBCBase::DynamicsLabel();
1025 }
1026 
1027 uint32_t&
1029 {
1030  return MBCBase::DynamicsLabel();
1031 }
1032 
1033 const double&
1034 MBCModal::F(uint8_t idx) const
1035 {
1036  return MBCBase::F(idx);
1037 }
1038 
1039 double&
1040 MBCModal::F(uint8_t idx)
1041 {
1042  return MBCBase::F(idx);
1043 }
1044 
1045 const double&
1046 MBCModal::M(uint8_t idx) const
1047 {
1048  return MBCBase::M(idx);
1049 }
1050 
1051 double&
1052 MBCModal::M(uint8_t idx)
1053 {
1054  return MBCBase::M(idx);
1055 }
1056 
1057 uint32_t
1058 MBCModal::GetModes(void) const
1059 {
1060  assert(GetStatus() == READY);
1061  return mbc.modes;
1062 }
1063 
1064 const double *const
1065 MBCModal::GetQ(void) const
1066 {
1067  assert(GetStatus() == READY);
1068  return MBC_Q(&mbc);
1069 }
1070 
1071 const double *const
1072 MBCModal::GetQP(void) const
1073 {
1074  assert(GetStatus() == READY);
1075  return MBC_QP(&mbc);
1076 }
1077 
1078 const double&
1079 MBCModal::Q(uint32_t m) const
1080 {
1081  assert(GetStatus() == READY);
1082  if (m < 1 || m > GetModes()) throw;
1083  return (MBC_Q(&mbc))[m - 1];
1084 }
1085 
1086 const double&
1087 MBCModal::QP(uint32_t m) const
1088 {
1089  assert(GetStatus() == READY);
1090  if (m < 1 || m > GetModes()) throw;
1091  return (MBC_QP(&mbc))[m - 1];
1092 }
1093 
1094 const double *
1095 MBCModal::GetP(void) const
1096 {
1097  assert(GetStatus() == READY);
1098  return MBC_P(&mbc);
1099 }
1100 
1101 const double&
1102 MBCModal::P(uint32_t m) const
1103 {
1104  assert(GetStatus() == READY);
1105  if (m < 1 || m > GetModes()) throw;
1106  return (MBC_P(&mbc))[m - 1];
1107 }
1108 
1109 double&
1110 MBCModal::P(uint32_t m)
1111 {
1112  assert(GetStatus() == READY);
1113  if (m < 1 || m > GetModes()) throw;
1114  return (MBC_P(&mbc))[m - 1];
1115 }
1116 
1117 #endif // USE_SOCKET
const double *const GetRefNodeOmegaP(void) const
virtual int GetMotion(void) const
void SetDataAndNext(bool bd)
#define MBC_F_LABELS(mbc)
Definition: mbc.h:241
Status
Definition: mbcxx.h:78
virtual int PutForces(bool bConverged) const
const double & Theta(uint8_t idx) const
bool bAccelerations(void) const
const double & R(uint8_t ir, uint8_t ic) const
int mbc_nodal_get_motion(mbc_nodal_t *mbc)
Get nodal motion from peer.
virtual mbc_refnode_stub_t * GetRefNodePtr(void) const =0
const double & XPP(uint8_t idx) const
const double *const GetRefNodeXP(void) const
const double *const GetOmegaP(void) const
uint32_t KinematicsLabel(void) const
const double *const GetRefNodeEuler123(void) const
Status GetStatus(void) const
#define MBC_N_R(mbc)
Definition: mbc.h:365
#define MBC_N_X(mbc)
Definition: mbc.h:363
virtual ~MBCBase(void)
#define MBC_P(mbc)
Definition: mbc.h:518
int mbc_modal_destroy(mbc_modal_t *mbc)
Destroy modal data.
mbc_modal_t mbc
Definition: mbcxx.h:230
const double & M(uint8_t idx) const
const double & OmegaP(uint8_t idx) const
int mbc_nodal_init(mbc_nodal_t *mbc, unsigned refnode, unsigned nodes, unsigned labels, unsigned rot, unsigned accels)
Initialize nodal data.
const double & X(uint8_t idx) const
#define MBC_N_THETA(mbc)
Definition: mbc.h:364
int Close(void) const
bool bVerbose(void) const
#define MBC_N_D_LABELS(mbc)
Definition: mbc.h:371
uint32_t KinematicsLabel(void) const
const double *const GetRefNodeOmega(void) const
int verbose
Definition: mbc.h:128
int Close(void) const
#define MBC_N_M(mbc)
Definition: mbc.h:373
#define MBC_R_OMEGA(mbc)
Definition: mbc.h:288
virtual mbc_refnode_stub_t * GetRefNodePtr(void) const
virtual ~MBCNodal(void)
#define MBC_N_XP(mbc)
Definition: mbc.h:367
#define MBC_QP(mbc)
Definition: mbc.h:517
const double & Theta(uint8_t idx) const
const double & Omega(uint8_t idx) const
const uint32_t & DynamicsLabel(void) const
const double *const GetX(void) const
MBCBase::Type GetType(void) const
static unsigned rot
void SetStatus(Status s)
const double & X(uint8_t idx) const
const double *const GetXPP(void) const
#define MBC_F_ACCELS(mbc)
Definition: mbc.h:242
mbc_nodal_t mbc
Definition: mbcxx.h:140
uint32_t GetRefNodeKinematicsLabel(void) const
char data_and_next
Definition: mbc.h:125
const double & R(uint8_t ir, uint8_t ic) const
const double & QP(uint32_t m) const
void SetVerbose(bool bv)
MBCNodal(void)
const double & R(uint8_t ir, uint8_t ic) const
const double & Euler123(uint8_t idx) const
const double & XPP(uint8_t idx) const
const double *const GetEuler123(void) const
const double & XP(uint8_t idx) const
int Initialize(MBCBase::Rot refnode_rot, unsigned nodes, bool labels, MBCBase::Rot rot, bool accels)
const double * GetP(void) const
const double & OmegaP(uint8_t idx) const
#define MBC_R_M(mbc)
Definition: mbc.h:293
virtual mbc_t * GetBasePtr(void) const
uint32_t * GetDynamicsLabel(void) const
const double & Q(uint32_t m) const
#define MBC_R_XP(mbc)
Definition: mbc.h:287
const double *const GetQP(void) const
#define MBC_N_OMEGAP(mbc)
Definition: mbc.h:370
#define MBC_Q(mbc)
Definition: mbc.h:516
MBCBase(void)
uint32_t GetModes(void) const
static int labels
const double *const GetRefNodeR(void) const
virtual mbc_t * GetBasePtr(void) const
#define MBC_R_D_LABEL(mbc)
Definition: mbc.h:291
virtual mbc_refnode_stub_t * GetRefNodePtr(void) const
int mbc_modal_negotiate_request(mbc_modal_t *mbc)
Negotiate modal data.
Type
Definition: mbcxx.h:50
bool bRefNode(void) const
const double *const GetR(void) const
#define MBC_N_OMEGA(mbc)
Definition: mbc.h:368
bool bLabels(void) const
uint32_t GetNodes(void) const
const double & F(uint8_t idx) const
#define MBC_R_XPP(mbc)
Definition: mbc.h:289
const double *const GetTheta(void) const
MBCBase::Rot GetRot(void) const
const uint32_t & DynamicsLabel(void) const
const double & F(uint8_t idx) const
uint32_t modes
Definition: mbc.h:514
const char * host
Definition: autopilot.c:142
MBCModal(void)
const double & M(uint8_t idx) const
#define MBC_N_F(mbc)
Definition: mbc.h:372
Rot
Definition: mbcxx.h:55
const double & XPP(uint8_t idx) const
const double & X(uint8_t idx) const
MBCBase::Rot GetRefNodeRot(void) const
int mbc_modal_init(mbc_modal_t *mbc, int refnode, unsigned modes)
Initialize modal data.
virtual mbc_t * GetBasePtr(void) const =0
uint32_t * GetKinematicsLabel(void) const
#define MBC_F_ROT(mbc)
Definition: mbc.h:243
Connection data structure (partially opaque)
Definition: mbc.h:103
int Init(const char *const path)
int timeout
Definition: mbc.h:137
const double *const GetOmega(void) const
const double & Omega(uint8_t idx) const
const double * GetF(void) const
#define MBC_R_OMEGAP(mbc)
Definition: mbc.h:290
const double *const GetQ(void) const
const double & Omega(uint8_t idx) const
virtual int Negotiate(void) const
int mbc_nodal_put_forces(mbc_nodal_t *mbc, int last)
Put forces to peer.
enum MBCBase::Status m_status
bool bDataAndNext(void) const
#define MBC_R_K_LABEL(mbc)
Definition: mbc.h:282
const double *const GetRefNodeX(void) const
static int nodes
const double *const GetRefNodeTheta(void) const
#define MBC_R_R(mbc)
Definition: mbc.h:285
#define MBC_N_XPP(mbc)
Definition: mbc.h:369
#define MBC_F_REF_NODE(mbc)
Definition: mbc.h:240
virtual int Negotiate(void) const
int mbc_unix_init(mbc_t *mbc, const char *path)
Initialize communication using "unix" socket.
const double *const GetXP(void) const
MBCBase::Type GetType(void) const
#define MBC_R_F(mbc)
Definition: mbc.h:292
int mbc_nodal_negotiate_request(mbc_nodal_t *mbc)
Negotiate nodal data.
uint32_t GetRefNodeDynamicsLabel(void) const
const double * GetM(void) const
const uint32_t & DynamicsLabel(void) const
const double * GetRefNodeF(void) const
#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.
uint32_t nodes
Definition: mbc.h:339
const double & Euler123(uint8_t idx) const
int mbc_modal_get_motion(mbc_modal_t *mbc)
Get modal motion from peer.
const double & M(uint8_t idx) const
#define MBC_R_X(mbc)
Definition: mbc.h:283
const double & OmegaP(uint8_t idx) const
const double & P(uint32_t m) const
const double & F(uint8_t idx) const
const double * GetRefNodeM(void) const
const double *const GetRefNodeXPP(void) const
virtual int GetMotion(void) const
#define MBC_R_EULER_123(mbc)
Definition: mbc.h:286
#define MBC_F_ROT_REF_NODE(mbc)
Definition: mbc.h:249
unsigned short int port
Definition: autopilot.c:143
virtual ~MBCModal(void)
virtual int PutForces(bool bConverged) const
const double & XP(uint8_t idx) const
#define MBC_N_K_LABELS(mbc)
Definition: mbc.h:362
#define MBC_R_THETA(mbc)
Definition: mbc.h:284
uint8_t cmd
Definition: mbc.h:117
int mbc_nodal_destroy(mbc_nodal_t *mbc)
Destroy nodal data.
uint32_t KinematicsLabel(void) const
#define MBC_N_EULER_123(mbc)
Definition: mbc.h:366
void SetTimeout(int t)
const double & Theta(uint8_t idx) const
const double & Euler123(uint8_t idx) const
int Initialize(MBCBase::Rot refnode_rot, unsigned modes)
int GetCmd(void) const
const char * path
Definition: autopilot.c:141
int mbc_modal_put_forces(mbc_modal_t *mbc, int last)
Put forces to peer.
const double & XP(uint8_t idx) const