47 #define real mbdyn_real_type
71 #include <octave/oct.h>
72 #include <octave/parse.h>
73 #include <octave/toplev.h>
74 #include <octave/octave.h>
82 #define TRACE(msg) ((void)(std::cerr << __FILE__ << ":" << __LINE__ << ":" << __PRETTY_FUNCTION__ << ":" << msg << std::endl))
83 #define ASSERT(expr) assert(expr)
85 #define TRACE(msg) ((void)0)
90 class OctaveInterface {
92 enum OctaveCallFlags_t {
93 DEFAULT_CALL_FLAGS = 0x0,
94 PASS_DATA_MANAGER = 0x1,
95 UPDATE_OCTAVE_VARIABLES = 0x2,
96 UPDATE_MBDYN_VARIABLES = 0x4,
97 UPDATE_GLOBAL_VARIABLES = UPDATE_OCTAVE_VARIABLES | UPDATE_MBDYN_VARIABLES,
98 OPTIONAL_OUTPUT_ARGS = 0x8
103 virtual ~OctaveInterface(
void);
108 static OctaveInterface* GetInterface(
void) {
return pOctaveInterface; };
109 void UpdateOctaveVariables(
void);
110 void UpdateMBDynVariables(
void);
111 const DataManager* GetDataManager(
void)
const{
return pDM; }
113 const octave_value& GetDataManagerInterface(
void)
const {
return octDM; }
114 const octave_value& GetMBDynParserInterface(
void)
const {
return octHP; }
115 bool AddOctaveSearchPath(
const std::string&
path);
116 static bool ConvertMBDynToOctave(
const TypedValue& mbValue, octave_value& octValue);
117 static bool ConvertMBDynToOctave(
doublereal mbValue, octave_value& octValue);
118 static bool ConvertMBDynToOctave(
const Vec3& mbValue, octave_value& octValue);
119 static bool ConvertMBDynToOctave(
const Vec6& mbValue, octave_value& octValue);
120 static bool ConvertMBDynToOctave(
const Mat3x3& mbValue, octave_value& octValue);
121 static bool ConvertMBDynToOctave(
const Mat6x6& mbValue, octave_value& octValue);
122 static bool ConvertOctaveToMBDyn(
const ColumnVector& octValue,
doublereal& mbValue);
123 static bool ConvertOctaveToMBDyn(
const ColumnVector& octValue,
Vec3& mbValue);
124 static bool ConvertOctaveToMBDyn(
const ColumnVector& octValue,
Vec6& mbValue);
125 static bool ConvertOctaveToMBDyn(
const Matrix& octValue,
doublereal& mbValue);
126 static bool ConvertOctaveToMBDyn(
const Matrix& octValue,
Vec3& mbValue);
127 static bool ConvertOctaveToMBDyn(
const Matrix& octValue,
Vec6& mbValue);
128 static bool ConvertOctaveToMBDyn(
const Matrix& octValue,
Mat3x3& mbValue);
129 static bool ConvertOctaveToMBDyn(
const Matrix& octValue,
Mat6x6& mbValue);
130 static bool ConvertOctaveToMBDyn(
const octave_value& octValue,
TypedValue& mbValue);
131 static bool ConvertOctaveToMBDyn(
const octave_value& octValue,
doublereal& mbValue);
132 inline octave_value_list EvalFunction(
const std::string&
func,
const octave_value_list& args,
int nargout = 1,
int flags = DEFAULT_CALL_FLAGS);
133 inline octave_value_list EvalFunctionDerivative(
const std::string&
func,
const octave_value_list& args,
int flags = DEFAULT_CALL_FLAGS);
134 inline octave_value_list EvalFunctionDerivative(
const std::string&
func,
doublereal dVar,
int flags = DEFAULT_CALL_FLAGS);
135 inline octave_value_list EvalFunction(
const std::string&
func,
doublereal dVar,
int nargout = 1,
int flags = DEFAULT_CALL_FLAGS);
137 inline doublereal EvalScalarFunction(
const std::string&
func,
const octave_value_list& args,
int flags = DEFAULT_CALL_FLAGS);
138 inline doublereal EvalScalarFunctionDerivative(
const std::string&
func,
doublereal dVar,
int flags = DEFAULT_CALL_FLAGS);
139 inline doublereal EvalScalarFunctionDerivative(
const std::string&
func,
const octave_value_list& args,
int flags = DEFAULT_CALL_FLAGS);
141 inline void EvalMatrixFunction(
const std::string&
func, T& res,
doublereal dVar,
int flags = DEFAULT_CALL_FLAGS);
142 template <
typename T>
143 inline void EvalMatrixFunction(
const std::string&
func, T& res,
const octave_value_list& args,
int flags = DEFAULT_CALL_FLAGS);
145 inline void EvalMatrixFunctionDerivative(
const std::string&
func, T& res,
doublereal dVar,
int flags = DEFAULT_CALL_FLAGS);
147 inline void EvalMatrixFunctionDerivative(
const std::string&
func, T& res,
const octave_value_list& args,
int flags = DEFAULT_CALL_FLAGS);
148 static bool HaveADPackage(
void) {
return bHaveADPackage; };
149 void AddEmbedFileName(
const std::string& strFile);
150 bool bHaveMethod(
const octave_value& octObject,
const std::string& strClass,
const std::string& strName);
151 inline octave_value_list MakeArgList(
doublereal dVar,
const octave_value_list& args,
int iFlags)
const;
154 inline static bool ConvertOctaveToMBDyn(
const ColumnVector& octValue, T& mbValue,
int rows);
156 inline static bool ConvertOctaveToMBDyn(
const Matrix& octValue, T& mbValue,
int rows);
158 inline static bool ConvertOctaveToMBDyn(
const Matrix& octValue, T& mbValue,
int rows,
int cols);
159 bool LoadADPackage(
void);
161 inline static bool ConvertMBDynToOctave(
const T& mbValue, octave_value& octValue,
int rows);
163 inline static bool ConvertMBDynToOctave(
const T& mbValue, octave_value& octValue,
int rows,
int cols);
164 static void exit(
int);
167 typedef std::map<std::string, bool> EmbedFileNameMap_t;
168 typedef EmbedFileNameMap_t::iterator EmbedFileNameIter_t;
170 bool bEmbedFileDirty;
171 const octave_value octDM;
172 const octave_value octHP;
175 EmbedFileNameMap_t strEmbedFileNames;
176 static OctaveInterface* pOctaveInterface;
177 static int iRefCount;
178 static const std::string strADFunc;
179 static const std::string strIsMethod;
180 static bool bHaveADPackage;
183 class MBDynInterface :
public octave_object {
187 explicit MBDynInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface());
188 virtual ~MBDynInterface(
void);
189 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
191 BEGIN_METHOD_TABLE_DECLARE()
192 METHOD_DECLARE(GetVersion)
193 END_METHOD_TABLE_DECLARE()
196 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
197 DECLARE_OCTAVE_ALLOCATOR
200 OctaveInterface* GetInterface(
void)
const {
return pInterface; };
203 OctaveInterface*
const pInterface;
206 class ConstVectorHandlerInterface :
public MBDynInterface {
208 explicit ConstVectorHandlerInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
const VectorHandler* pX=0);
209 virtual ~ConstVectorHandlerInterface();
211 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
212 virtual octave_value operator()(
const octave_value_list& idx)
const;
213 virtual dim_vector dims (
void)
const;
215 BEGIN_METHOD_TABLE_DECLARE()
216 METHOD_DECLARE(dGetCoef)
217 METHOD_DECLARE(GetVec)
218 METHOD_DECLARE(iGetSize)
219 END_METHOD_TABLE_DECLARE()
222 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
223 DECLARE_OCTAVE_ALLOCATOR
229 class VectorHandlerInterface : public ConstVectorHandlerInterface {
231 explicit VectorHandlerInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
VectorHandler* X=0);
232 virtual ~VectorHandlerInterface();
234 BEGIN_METHOD_TABLE_DECLARE()
235 METHOD_DECLARE(PutCoef)
236 METHOD_DECLARE(PutVec)
237 END_METHOD_TABLE_DECLARE()
240 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
241 DECLARE_OCTAVE_ALLOCATOR
245 class OStreamInterface : public MBDynInterface {
247 explicit OStreamInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(), std::ostream* pOS = 0);
248 virtual ~OStreamInterface();
249 void Set(std::ostream* pOS){ this->pOS = pOS; }
250 std::ostream* Get()
const{
return pOS; }
252 BEGIN_METHOD_TABLE_DECLARE()
253 METHOD_DECLARE(printf)
254 END_METHOD_TABLE_DECLARE()
257 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
258 DECLARE_OCTAVE_ALLOCATOR
262 static const std::
string strsprintf;
265 class SimulationEntityInterface: public MBDynInterface {
267 explicit SimulationEntityInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface());
268 virtual ~SimulationEntityInterface();
271 BEGIN_METHOD_TABLE_DECLARE()
272 METHOD_DECLARE(iGetNumPrivData)
273 METHOD_DECLARE(iGetPrivDataIdx)
274 METHOD_DECLARE(dGetPrivData)
275 END_METHOD_TABLE_DECLARE()
278 class NodeInterface: public SimulationEntityInterface {
280 explicit NodeInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface());
281 virtual ~NodeInterface();
282 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
283 virtual const Node* Get()
const=0;
285 BEGIN_METHOD_TABLE_DECLARE()
286 METHOD_DECLARE(GetLabel)
287 METHOD_DECLARE(GetName)
288 METHOD_DECLARE(iGetFirstIndex)
289 METHOD_DECLARE(iGetFirstRowIndex)
290 METHOD_DECLARE(iGetFirstColIndex)
291 METHOD_DECLARE(dGetDofValue)
292 METHOD_DECLARE(dGetDofValuePrev)
293 END_METHOD_TABLE_DECLARE()
296 class ScalarNodeInterface: public NodeInterface {
298 explicit ScalarNodeInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
ScalarNode* pNode = 0);
299 virtual ~ScalarNodeInterface();
303 BEGIN_METHOD_TABLE_DECLARE()
305 METHOD_DECLARE(dGetX)
306 METHOD_DECLARE(SetXPrime)
307 METHOD_DECLARE(dGetXPrime)
308 END_METHOD_TABLE_DECLARE()
311 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
312 DECLARE_OCTAVE_ALLOCATOR
318 class StructDispNodeBaseInterface : public NodeInterface {
320 explicit StructDispNodeBaseInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface());
321 virtual ~StructDispNodeBaseInterface();
325 BEGIN_METHOD_TABLE_DECLARE()
326 METHOD_DECLARE(iGetFirstPositionIndex)
327 METHOD_DECLARE(iGetFirstMomentumIndex)
328 METHOD_DECLARE(GetLabel)
329 METHOD_DECLARE(GetXCurr)
330 METHOD_DECLARE(GetXPrev)
331 METHOD_DECLARE(GetVCurr)
332 METHOD_DECLARE(GetVPrev)
333 METHOD_DECLARE(GetXPPCurr)
334 METHOD_DECLARE(GetXPPPrev)
335 END_METHOD_TABLE_DECLARE()
338 octave_value GetVec3(const
Vec3& v, const octave_value_list& args) const;
339 octave_value GetMat3x3(const
Mat3x3& m, const octave_value_list& args) const;
342 class StructDispNodeInterface: public StructDispNodeBaseInterface {
344 explicit StructDispNodeInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
const StructDispNode* pNode = 0);
345 virtual ~StructDispNodeInterface();
349 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
350 DECLARE_OCTAVE_ALLOCATOR
356 class StructNodeInterface :
public StructDispNodeBaseInterface {
358 explicit StructNodeInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
const StructNode* pNode = 0);
359 virtual ~StructNodeInterface();
362 BEGIN_METHOD_TABLE_DECLARE()
363 METHOD_DECLARE(GetgCurr)
364 METHOD_DECLARE(GetgRef)
365 METHOD_DECLARE(GetgPCurr)
366 METHOD_DECLARE(GetgPRef)
367 METHOD_DECLARE(GetRCurr)
368 METHOD_DECLARE(GetRPrev)
369 METHOD_DECLARE(GetRRef)
370 METHOD_DECLARE(GetWCurr)
371 METHOD_DECLARE(GetWPrev)
372 METHOD_DECLARE(GetWRef)
373 METHOD_DECLARE(GetWPCurr)
374 METHOD_DECLARE(GetWPPrev)
375 END_METHOD_TABLE_DECLARE()
378 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
379 DECLARE_OCTAVE_ALLOCATOR
385 class DataManagerInterface : public MBDynInterface {
389 explicit DataManagerInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
const DataManager* pDM = 0);
390 virtual ~DataManagerInterface();
391 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
392 inline const DataManager* GetDataManager(
void)
const;
393 inline const Table& GetSymbolTable(
void)
const;
396 BEGIN_METHOD_TABLE_DECLARE()
397 METHOD_DECLARE(GetVariable)
398 METHOD_DECLARE(GetStructNodePos)
399 METHOD_DECLARE(GetStructNode)
400 METHOD_DECLARE(pFindNode)
401 METHOD_DECLARE(ReadNode)
402 METHOD_DECLARE(dGetTime)
403 END_METHOD_TABLE_DECLARE()
406 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
407 DECLARE_OCTAVE_ALLOCATOR
410 Node* pFindNode_(const octave_value_list& args,
Node::Type& Type) const;
411 Node::Type GetNodeType(const std::
string& strType) const;
412 NodeInterface* CreateNodeInterface(
Node* pNode,
Node::Type Type) const;
418 class MBDynParserInterface : public MBDynInterface {
422 explicit MBDynParserInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
MBDynParser*
pHP=0);
423 virtual ~MBDynParserInterface();
424 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
428 BEGIN_METHOD_TABLE_DECLARE()
429 METHOD_DECLARE(IsKeyWord)
430 METHOD_DECLARE(IsArg)
431 METHOD_DECLARE(IsStringWithDelims)
432 METHOD_DECLARE(GetReal)
433 METHOD_DECLARE(GetInt)
434 METHOD_DECLARE(GetBool)
435 METHOD_DECLARE(GetYesNoOrBool)
436 METHOD_DECLARE(GetString)
437 METHOD_DECLARE(GetStringWithDelims)
438 METHOD_DECLARE(GetValue)
439 METHOD_DECLARE(GetPosRel)
440 METHOD_DECLARE(GetRotRel)
441 METHOD_DECLARE(GetLineData)
442 METHOD_DECLARE(GetDriveCaller)
443 END_METHOD_TABLE_DECLARE()
446 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
447 DECLARE_OCTAVE_ALLOCATOR
450 const
StructDispNode* GetStructNode(const octave_value& arg)const;
451 static
bool GetDelimsFromString(const std::
string& strDelims,
HighParser::Delims& delims);
454 static const struct MBDynStringDelims {
460 class DriveCallerInterface :
public MBDynInterface {
462 explicit DriveCallerInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(),
const DriveCaller* pDC=0);
463 virtual ~DriveCallerInterface();
466 BEGIN_METHOD_TABLE_DECLARE()
468 METHOD_DECLARE(dGetP)
469 END_METHOD_TABLE_DECLARE()
472 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
473 DECLARE_OCTAVE_ALLOCATOR
482 OctaveDriveCaller(
const std::string& strFunc,
483 OctaveInterface* pInterface,
485 const octave_value_list& args);
486 virtual ~OctaveDriveCaller(
void);
489 virtual DriveCaller* pCopy(
void)
const;
492 virtual std::ostream& Restart(std::ostream& out)
const;
498 virtual bool bIsDifferentiable(
void)
const;
503 inline octave_value_list MakeArgList(
doublereal dVar)
const;
507 const std::string strFunc;
508 OctaveInterface*
const pInterface;
509 const octave_value_list args;
515 OctaveTplDriveCaller(
const std::string& strFunction, OctaveInterface* pInterface,
int iFlags,
const octave_value_list& args);
516 ~OctaveTplDriveCaller(
void);
518 virtual std::ostream& Restart(std::ostream& out)
const;
519 virtual std::ostream& Restart_int(std::ostream& out)
const;
520 virtual inline T Get(
const doublereal& dVar)
const;
521 virtual inline T Get(
void)
const;
522 virtual inline bool bIsDifferentiable(
void)
const;
523 virtual inline T GetP(
void)
const;
524 virtual inline int getNDrives(
void)
const;
527 inline octave_value_list MakeArgList(
doublereal dVar)
const;
530 const std::string strFunction;
531 OctaveInterface*
const pInterface;
533 const octave_value_list args;
538 explicit DerivativeDriveCaller(
DriveCaller* pDriveCaller);
539 virtual ~DerivativeDriveCaller(
void);
545 virtual std::ostream& Restart(std::ostream& out)
const;
551 virtual bool bIsDifferentiable(
void)
const;
561 OctaveScalarFunction(
const std::string& strFunc, OctaveInterface* pInterface,
int iFlags,
const octave_value_list& args);
562 virtual ~OctaveScalarFunction(
void);
567 inline octave_value_list MakeArgList(
doublereal dVar)
const;
570 const std::string strFunc;
571 OctaveInterface*
const pInterface;
573 const octave_value_list args;
576 class OctaveConstitutiveLawBase
579 explicit inline OctaveConstitutiveLawBase(
const std::string& strClass, OctaveInterface* pInterface,
int iFlags);
580 inline bool bHaveMethod(
const std::string& strName)
const;
581 OctaveInterface* GetInterface()
const{
return pInterface; }
582 const std::string& GetClass()
const{
return strClass; }
583 int GetFlags()
const{
return iFlags; }
586 octave_value octObject;
589 const std::string strClass;
590 OctaveInterface*
const pInterface;
592 static const std::string strGetConstLawType;
593 static const std::string strUpdate;
596 template <
class T,
class Tder>
597 class OctaveConstitutiveLaw
601 OctaveConstitutiveLaw(
const std::string& strClass, OctaveInterface* pInterface,
int iFlags);
602 virtual ~OctaveConstitutiveLaw(
void);
605 virtual std::ostream& Restart(std::ostream& out)
const;
606 virtual void Update(
const T& mbEps,
const T& mbEpsPrime);
612 class OctaveBaseDCR {
615 virtual ~OctaveBaseDCR(
void);
617 OctaveInterface* GetInterface(
void)
const {
return pInterface; };
618 const std::string& GetFunction(
void)
const {
return strFunction; };
619 int GetFlags(
void)
const {
return iFlags; };
623 mutable OctaveInterface* pInterface;
624 mutable std::string strFunction;
628 class OctaveFunctionDCR:
public OctaveBaseDCR {
631 const octave_value_list& GetArgs()
const{
return args; }
634 mutable octave_value_list args;
662 template <
class T,
class Tder>
668 OctaveBaseDCR::Read(pDM, HP);
670 typedef OctaveConstitutiveLaw<T, Tder> L;
681 OctaveElement(
unsigned uLabel,
const DofOwner *pDO,
683 virtual ~OctaveElement(
void);
686 virtual void WorkSpaceDim(
integer* piNumRows,
integer* piNumCols)
const;
697 unsigned int iGetNumPrivData(
void)
const;
698 virtual unsigned int iGetPrivDataIdx(
const char *s)
const;
699 virtual doublereal dGetPrivData(
unsigned int i)
const;
700 int iGetNumConnectedNodes(
void)
const;
701 void GetConnectedNodes(std::vector<const Node *>& connectedNodes)
const;
704 virtual unsigned int iGetNumDof(
void)
const;
707 virtual std::ostream& DescribeDof(std::ostream& out,
const char *prefix,
bool bInitial)
const;
708 virtual std::ostream& DescribeEq(std::ostream& out,
const char *prefix,
bool bInitial)
const;
713 std::ostream& Restart(std::ostream& out)
const;
714 virtual unsigned int iGetInitialNumDof(
void)
const;
716 InitialWorkSpaceDim(
integer* piNumRows,
integer* piNumCols)
const;
723 OctaveInterface* GetInterface(
void)
const {
return dcr.GetInterface(); };
724 int GetFlags(
void)
const {
return dcr.GetFlags(); };
725 const std::string& GetClass(
void)
const {
return dcr.GetFunction(); };
731 AssMatrix(
VariableSubMatrixHandler& WorkMatVar,
const Matrix& Jac,
const int32NDArray& ridx,
const int32NDArray& cidx,
bool bSparse,
bool bInitial);
732 bool bHaveMethod(
const std::string& strName)
const;
734 octave_value octObject;
735 octave_value mbdObject;
737 enum OctaveMethods_t {
738 HAVE_DEFAULT = 0x0000,
739 HAVE_JACOBIAN = 0x0001,
740 HAVE_UPDATE = 0x0002,
741 HAVE_SET_VALUE = 0x0004,
742 HAVE_PRIVATE_DOF = 0x0008,
743 HAVE_INITIAL_ASSEMBLY = 0x0010,
744 HAVE_SET_INITIAL_VALUE = 0x0020,
745 HAVE_AFTER_CONVERGENCE = 0x0040,
746 HAVE_PRIVATE_DATA = 0x0080,
747 HAVE_CONNECTED_NODES = 0x0100,
748 HAVE_OUTPUT = 0x0200,
749 HAVE_DESCRIBE_DOF = 0x0400,
750 HAVE_DESCRIBE_EQ = 0x0800,
751 HAVE_AFTER_PREDICT = 0x1000,
752 HAVE_RESTART = 0x2000
755 octave_object_ptr<ConstVectorHandlerInterface> X;
756 octave_object_ptr<ConstVectorHandlerInterface> XP;
757 octave_object_ptr<OStreamInterface> OS;
758 static const std::string strWorkSpaceDim;
759 static const std::string striGetNumDof;
760 static const std::string strAssRes;
761 static const std::string strAssJac;
762 static const std::string strUpdate;
763 static const std::string strSetValue;
764 static const std::string striGetInitialNumDof;
765 static const std::string strSetInitialValue;
766 static const std::string strInitialAssRes;
767 static const std::string strInitialAssJac;
768 static const std::string strInitialWorkSpaceDim;
769 static const std::string strGetDofType;
770 static const std::string strGetEqType;
771 static const std::string strAfterConvergence;
772 static const std::string striGetNumPrivData;
773 static const std::string striGetPrivDataIdx;
774 static const std::string strdGetPrivData;
775 static const std::string striGetNumConnectedNodes;
776 static const std::string strGetConnectedNodes;
777 static const std::string strOutput;
778 static const std::string strDescribeDof;
779 static const std::string strDescribeEq;
780 static const std::string strAfterPredict;
781 static const std::string strRestart;
784 class OctaveElementInterface:
public MBDynInterface {
786 explicit OctaveElementInterface(OctaveInterface* pInterface = OctaveInterface::GetInterface(), OctaveElement* pElem = 0);
787 virtual ~OctaveElementInterface(
void);
788 virtual void print(std::ostream& os,
bool pr_as_read_syntax =
false)
const;
791 BEGIN_METHOD_TABLE_DECLARE()
792 METHOD_DECLARE(GetLabel)
793 METHOD_DECLARE(iGetFirstIndex)
794 END_METHOD_TABLE_DECLARE()
797 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
798 DECLARE_OCTAVE_ALLOCATOR
801 OctaveElement* const pElem;
804 OctaveInterface* OctaveInterface::pOctaveInterface = 0;
805 int OctaveInterface::iRefCount = 0;
806 const std::
string OctaveInterface::strADFunc("mbdyn_derivative");
807 const std::
string OctaveInterface::strIsMethod("ismethod");
808 bool OctaveInterface::bHaveADPackage =
false;
812 bEmbedFileDirty(false),
813 octDM(new DataManagerInterface(this, pDM)),
814 octHP(new MBDynParserInterface(this,
pHP)),
818 TRACE(
"constructor");
822 ASSERT(pOctaveInterface == 0);
824 pOctaveInterface =
this;
826 const int nmax_args = 4;
827 const int nmax_char = 14;
828 char args[nmax_char] =
"octave";
829 char *argv[nmax_args] = { &args[0] } ;
832 char* p = strchr(args,
'\0') + 1;
835 strncat(p,
"-q", &args[nmax_char] - p - 2);
836 if (argc < nmax_args - 1)
838 p = strchr(p,
'\0') + 1;
841 if (pedantic_output) {
842 strncat(p,
"-V", &args[nmax_char] - p - 2);
843 if (argc < nmax_args - 1)
845 p = strchr(p,
'\0') + 1;
851 for (i = 0, pp = argv; *pp; ++pp, ++i) {
852 silent_cerr(
"octave>argv[" << i <<
"]=\"" << *pp <<
"\"" << std::endl);
856 octave_main(argc, argv, 1);
861 void OctaveInterface::exit(
int)
863 silent_cerr(
"octave interface has been uninitialized" << std::endl);
866 OctaveInterface::~OctaveInterface(
void)
870 ASSERT(
this == pOctaveInterface);
872 octave_exit = &OctaveInterface::exit;
874 #if defined(HAVE_DO_OCTAVE_ATEXIT)
876 #elif defined(HAVE_CLEAN_UP_AND_EXIT)
877 clean_up_and_exit(0,
true);
879 #warning "do_octave_atexit() and clean_up_and_exit() are not defined"
882 pOctaveInterface = 0;
886 OctaveInterface::LoadADPackage(
void)
888 octave_value_list args;
889 args.append(octave_value(
"load"));
890 args.append(octave_value(
"ad"));
892 feval(
"pkg", args, 0);
894 bHaveADPackage =
true;
896 if ((error_state != 0)) {
897 silent_cerr(
"warning: octave package for automatic forward differentiation is not available" << std::endl);
901 return bHaveADPackage;
909 if (pOctaveInterface) {
910 return pOctaveInterface;
913 return new OctaveInterface(pDM, pHP);
917 OctaveInterface::Destroy(
void)
921 if (0 == --iRefCount) {
927 OctaveInterface::UpdateOctaveVariables(
void)
929 typedef Table::VM::const_iterator iterator;
931 const Table& symbolTable = GetDataManager()->GetMathParser().GetSymbolTable();
933 for (iterator it = symbolTable.
begin(); it != symbolTable.
end(); ++it)
935 const std::string& mbName(it->first);
936 const NamedValue*
const namedValue = it->second;
938 octave_value octValue;
940 if (!ConvertMBDynToOctave(mbValue, octValue)) {
941 silent_cerr(
"octave error: data type \"" << mbValue.GetTypeName() <<
"\" of variable \"" << mbName <<
"\": not handled in switch statement " << std::endl);
946 set_global_value(mbName, octValue);
951 OctaveInterface::UpdateMBDynVariables(
void)
953 typedef Table::VM::const_iterator iterator;
955 Table& symbolTable = GetDataManager()->GetMathParser().GetSymbolTable();
957 for (iterator it = symbolTable.
begin(); it != symbolTable.
end(); ++it)
959 Var*
const varValue =
dynamic_cast<Var*
>(it->second);
961 if (!varValue || varValue->
Const()) {
965 const std::string& mbName(it->first);
968 const octave_value octValue(get_global_value(mbName));
970 if (!octValue.is_defined()) {
971 pedantic_cerr(
"octave warning: global variable " << mbName <<
" is not defined in octave" << std::endl);
977 if (!ConvertOctaveToMBDyn(octValue, mbValue)) {
978 silent_cerr(
"octave error: data type \"" << octValue.type_name() <<
"\" of variable \"" << mbName <<
"\": can not be converted into MBDyn format " << std::endl);
982 varValue->
SetVal(mbValue);
987 OctaveInterface::AddOctaveSearchPath(
const std::string&
path)
989 feval(
"addpath", octave_value(path));
991 return error_state == 0;
995 OctaveInterface::ConvertMBDynToOctave(
const TypedValue& mbValue, octave_value& octValue)
1002 octValue = mbValue.
GetInt();
1018 OctaveInterface::ConvertMBDynToOctave(
doublereal mbValue, octave_value& octValue)
1027 OctaveInterface::ConvertMBDynToOctave(
const Vec3& mbValue, octave_value& octValue)
1029 return ConvertMBDynToOctave(mbValue, octValue, 3);
1033 OctaveInterface::ConvertMBDynToOctave(
const Vec6& mbValue, octave_value& octValue)
1035 return ConvertMBDynToOctave(mbValue, octValue, 6);
1039 OctaveInterface::ConvertMBDynToOctave(
const Mat3x3& mbValue, octave_value& octValue)
1041 return ConvertMBDynToOctave(mbValue, octValue, 3, 3);
1045 OctaveInterface::ConvertMBDynToOctave(
const Mat6x6& mbValue, octave_value& octValue)
1047 return ConvertMBDynToOctave(mbValue, octValue, 6, 6);
1051 OctaveInterface::ConvertOctaveToMBDyn(
const ColumnVector& octValue,
doublereal& mbValue)
1053 if (octValue.length() != 1) {
1054 silent_cerr(
"octave error: invalid vector size " << octValue.length() <<
" expected 1" << std::endl);
1058 mbValue = octValue(0);
1064 OctaveInterface::ConvertOctaveToMBDyn(
const ColumnVector& octValue,
Vec3& mbValue)
1066 return ConvertOctaveToMBDyn(octValue, mbValue, 3);
1070 OctaveInterface::ConvertOctaveToMBDyn(
const ColumnVector& octValue,
Vec6& mbValue)
1072 return ConvertOctaveToMBDyn(octValue, mbValue, 6);
1075 template<
typename T>
1077 OctaveInterface::ConvertOctaveToMBDyn(
const ColumnVector& octValue, T& mbValue,
int rows)
1079 if (octValue.length() != rows) {
1080 silent_cerr(
"octave error: invalid vector size " << octValue.length() <<
" expected " << rows << std::endl);
1084 for (
int i = 0; i < rows; ++i) {
1085 mbValue(i + 1) = octValue(i);
1091 template<
typename T>
1093 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue, T& mbValue,
int rows)
1095 if (octValue.rows() != rows || octValue.columns() != 1) {
1096 silent_cerr(
"octave error: invalid matrix size " << octValue.rows() <<
"x" << octValue.columns() <<
" expected " << rows <<
"x1" << std::endl);
1100 for (
int i = 0; i < rows; ++i) {
1101 mbValue(i + 1) = octValue(i, 0);
1107 template<
typename T>
1109 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue, T& mbValue,
int rows,
int cols)
1111 if (octValue.rows() != rows || octValue.columns() != cols) {
1112 silent_cerr(
"octave error: invalid matrix size " << octValue.rows() <<
"x" << octValue.columns() <<
" expected " << rows <<
"x" << cols << std::endl);
1116 for (
int i = 0; i < rows; ++i) {
1117 for (
int j = 0; j < cols; ++j) {
1118 mbValue(i + 1, j + 1) = octValue(i, j);
1125 template<
typename T>
1127 OctaveInterface::ConvertMBDynToOctave(
const T& mbValue, octave_value& octValue,
int rows)
1129 ColumnVector V(rows);
1131 for (
int i = 0; i < rows; ++i) {
1132 V(i) = mbValue(i + 1);
1140 template<
typename T>
1142 OctaveInterface::ConvertMBDynToOctave(
const T& mbValue, octave_value& octValue,
int rows,
int cols)
1144 Matrix M(rows, cols);
1146 for (
int i = 0; i < rows; ++i) {
1147 for (
int j = 0; j < cols; ++j) {
1148 M(i, j) = mbValue(i + 1, j + 1);
1158 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue,
doublereal& mbValue)
1160 if (octValue.rows() != 1 || octValue.columns() != 1) {
1161 silent_cerr(
"octave error: invalid matrix size " << octValue.rows() <<
"x" << octValue.columns() <<
" expected 1x1" << std::endl);
1165 mbValue = octValue(0, 0);
1171 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue,
Vec3& mbValue)
1173 return ConvertOctaveToMBDyn(octValue, mbValue, 3);
1177 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue,
Vec6& mbValue)
1179 return ConvertOctaveToMBDyn(octValue, mbValue, 6);
1183 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue,
Mat3x3& mbValue)
1185 return ConvertOctaveToMBDyn(octValue, mbValue, 3, 3);
1189 OctaveInterface::ConvertOctaveToMBDyn(
const Matrix& octValue,
Mat6x6& mbValue)
1191 return ConvertOctaveToMBDyn(octValue, mbValue, 6, 6);
1195 OctaveInterface::ConvertOctaveToMBDyn(
const octave_value& octValue,
TypedValue& mbValue)
1197 if (!octValue.is_scalar_type()) {
1201 if (octValue.is_bool_scalar()) {
1203 }
else if (octValue.is_int32_type()) {
1204 mbValue =
TypedValue(static_cast<int32_t>(octValue.int32_scalar_value()));
1205 }
else if (octValue.is_real_scalar()) {
1206 mbValue =
TypedValue(octValue.scalar_value());
1207 }
else if (octValue.is_string()) {
1208 mbValue =
TypedValue(octValue.string_value());
1216 bool OctaveInterface::ConvertOctaveToMBDyn(
const octave_value& octValue,
doublereal& mbValue)
1218 if (!octValue.is_real_scalar()) {
1222 mbValue = octValue.scalar_value();
1228 OctaveInterface::EvalFunction(
const std::string&
func,
doublereal dVar,
int nargout,
int flags)
1230 octave_value_list args = octave_value(dVar);
1232 if (flags & PASS_DATA_MANAGER) {
1236 return EvalFunction(func, args, nargout, flags);
1240 OctaveInterface::EvalFunction(
const std::string& func,
const octave_value_list& args,
int nargout,
int flags)
1242 if ((flags & UPDATE_OCTAVE_VARIABLES) || bFirstCall) {
1243 UpdateOctaveVariables();
1248 if (!AddOctaveSearchPath(OCTAVEBINPATH)) {
1249 silent_cerr(
"OctaveInterface error: addpath(\"" << BINPATH <<
"\") failed" << std::endl);
1254 if (!AddOctaveSearchPath(OCTAVEPATH)) {
1255 silent_cerr(
"OctaveInterface error: addpath(\"" << OCTAVEPATH <<
"\") failed" << std::endl);
1262 if ( bEmbedFileDirty ) {
1263 for (EmbedFileNameIter_t pFile = strEmbedFileNames.begin();
1264 pFile != strEmbedFileNames.end(); ++pFile )
1266 if (!pFile->second) {
1267 feval(
"source", octave_value(pFile->first));
1273 pFile->second =
true;
1276 bEmbedFileDirty =
false;
1279 octave_value_list ans = feval(func, args, nargout);
1287 if (flags & OPTIONAL_OUTPUT_ARGS) {
1288 if (ans.length() > nargout) {
1289 silent_cerr(
"octave error: function \"" << func <<
"\" returned " << ans.length() <<
" output parameters\n"
1290 "expected maximum " << nargout <<
" output parameters" << std::endl);
1294 else if (ans.length() != nargout) {
1295 silent_cerr(
"octave error: function \"" << func <<
"\" returned " << ans.length() <<
" output parameters\n"
1296 "expected " << nargout <<
" output parameters" << std::endl);
1300 for (
int i = 0; i < ans.length(); ++i) {
1301 if (!ans(i).is_defined()) {
1302 silent_cerr(
"octave error: result " << i + 1 <<
" of function \"" << func <<
"\" is undefined" << std::endl);
1307 if (flags & UPDATE_MBDYN_VARIABLES) {
1308 UpdateMBDynVariables();
1315 OctaveInterface::EvalFunctionDerivative(
const std::string& func,
const octave_value_list& args,
int flags)
1317 TRACE(
"func=" << func);
1318 TRACE(
"flags=" << flags);
1320 octave_value_list derivArgs = octave_value(func);
1321 derivArgs.append(args);
1323 return EvalFunction(strADFunc, derivArgs, 2, flags);
1327 OctaveInterface::EvalFunctionDerivative(
const std::string& func,
doublereal dVar,
int flags)
1329 TRACE(
"func=" << func);
1330 TRACE(
"flags=" << flags);
1332 octave_value_list args = octave_value(dVar);
1334 if (flags & PASS_DATA_MANAGER) {
1338 return EvalFunctionDerivative(func, args, flags);
1342 OctaveInterface::EvalScalarFunction(
const std::string& func,
doublereal dVar,
int flags)
1344 return EvalScalarFunction(func, octave_value(dVar), flags);
1348 OctaveInterface::EvalScalarFunction(
const std::string& func,
const octave_value_list& args,
int flags)
1350 const octave_value_list ans = EvalFunction(func, args, 1, flags);
1352 if (!ans(0).is_real_scalar()) {
1353 silent_cerr(
"octave error: result of function \"" << func <<
"\" is not a scalar value" << std::endl);
1357 return ans(0).scalar_value();
1361 OctaveInterface::EvalScalarFunctionDerivative(
const std::string& func,
doublereal dVar,
int flags)
1363 return EvalScalarFunctionDerivative(func, octave_value(dVar), flags);
1367 OctaveInterface::EvalScalarFunctionDerivative(
const std::string& func,
const octave_value_list& args,
int flags)
1369 TRACE(
"func=" << func);
1370 TRACE(
"flags=" << flags);
1372 octave_value_list ans = EvalFunctionDerivative(func, args, flags);
1374 ASSERT(ans.length() == 2);
1376 if (!ans(1).is_real_scalar()) {
1377 silent_cerr(
"octave error: derivative of function \"" << func <<
"\" is not a scalar value" << std::endl);
1381 return ans(1).scalar_value();
1384 template <
typename T>
1386 OctaveInterface::EvalMatrixFunction(
const std::string& func, T& res,
doublereal dVar,
int flags)
1388 EvalMatrixFunction(func, res, octave_value(dVar), flags);
1391 template <
typename T>
1393 OctaveInterface::EvalMatrixFunction(
const std::string& func, T& res,
const octave_value_list& args,
int flags)
1395 const octave_value_list ans = EvalFunction(func, args, 1, flags);
1397 ASSERT(ans.length() == 1);
1399 if (!(ans(0).is_real_matrix() || ans(0).is_real_scalar())) {
1400 silent_cerr(
"octave error: result of function \"" << func <<
"\" is not a matrix value" << std::endl);
1404 const Matrix A(ans(0).matrix_value());
1406 if (!ConvertOctaveToMBDyn(A, res)) {
1407 silent_cerr(
"octave error: conversion of octave matrix failed!" << std::endl);
1412 template <
typename T>
1414 OctaveInterface::EvalMatrixFunctionDerivative(
const std::string& func, T& res,
doublereal dVar,
int flags)
1416 EvalMatrixFunctionDerivative(func, res, octave_value(dVar), flags);
1419 template<
typename T>
1421 OctaveInterface::EvalMatrixFunctionDerivative(
const std::string& func, T& res,
const octave_value_list& args,
int flags)
1423 const octave_value_list ans = EvalFunctionDerivative(func, args, flags);
1425 ASSERT(ans.length() == 2);
1427 if (!(ans(0).is_real_matrix() || ans(0).is_real_scalar())) {
1428 silent_cerr(
"octave error: result of function \"" << func <<
"\" is not a matrix value" << std::endl);
1432 if (!(ans(1).is_real_matrix() || ans(1).is_real_scalar())) {
1433 silent_cerr(
"octave error: result of derivative of function \"" << func <<
"\" is not a matrix value" << std::endl);
1437 const Matrix A(ans(1).matrix_value());
1439 if (!ConvertOctaveToMBDyn(A, res)) {
1440 silent_cerr(
"octave error: conversion of octave matrix failed!" << std::endl);
1446 OctaveInterface::AddEmbedFileName(
const std::string& strFile)
1448 strEmbedFileNames.insert(std::pair<std::string, bool>(strFile,
false));
1449 bEmbedFileDirty =
true;
1452 bool OctaveInterface::bHaveMethod(
const octave_value& octObject,
const std::string& strClass,
const std::string& strName)
1454 octave_value_list args(octObject);
1455 args.append(octave_value(strName));
1457 octave_value_list ans = EvalFunction(strIsMethod, args, 1);
1459 ASSERT(ans.length() == 1);
1461 if (!ans(0).is_bool_scalar()) {
1462 silent_cerr(
"octave error: unexpected error in function " << strIsMethod << std::endl);
1466 return ans(0).bool_value(
true);
1469 octave_value_list OctaveInterface::MakeArgList(
doublereal dVar,
const octave_value_list& args,
int iFlags)
const
1471 octave_value_list fargs = octave_value(dVar);
1474 if (iFlags & PASS_DATA_MANAGER) {
1475 fargs.append(GetDataManagerInterface());
1481 MBDynInterface::MBDynInterface(OctaveInterface* pInterface)
1482 : pInterface(pInterface)
1484 TRACE(
"constructor");
1488 MBDynInterface::~MBDynInterface(
void)
1490 TRACE(
"destructor");
1494 MBDynInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
1496 os << type_name() <<
": MBDyn version" << VERSION << std::endl;
1499 METHOD_DEFINE(MBDynInterface, GetVersion, args, nargout)
1501 octave_value octValue;
1503 if (args.length() != 0) {
1504 error(
"%s: invalid number of arguments: %ld",
1505 type_name().c_str(),
1506 long(args.length()));
1515 BEGIN_METHOD_TABLE(MBDynInterface, octave_object)
1516 METHOD_DISPATCH(MBDynInterface, GetVersion)
1519 DEFINE_OCTAVE_ALLOCATOR(MBDynInterface);
1520 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(MBDynInterface, "MBDyn", "MBDyn");
1522 ConstVectorHandlerInterface::ConstVectorHandlerInterface(OctaveInterface* pInterface, const
VectorHandler* X)
1523 :MBDynInterface(pInterface),
1526 TRACE(
"constructor");
1529 ConstVectorHandlerInterface::~ConstVectorHandlerInterface()
1531 TRACE(
"destructor");
1535 ConstVectorHandlerInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
1538 error(
"%s: not connected", type_name().c_str());
1542 for (
int i = 1; i <= pX->iGetSize(); ++i ) {
1543 os <<
'\t' << pX->dGetCoef(i) << std::endl;
1547 octave_value ConstVectorHandlerInterface::operator()(
const octave_value_list& idx)
const
1550 error(
"%s: not connected", type_name().c_str());
1551 return octave_value();
1554 if (idx.length() != 1) {
1555 error(
"%s: invalid number of indices %ld", type_name().c_str(),
long(idx.length()));
1556 return octave_value();
1559 const integer iSize = pX->iGetSize();
1563 if (idx(0).is_magic_colon()) {
1566 for (
int i = 0; i < X.length(); ++i) {
1567 X(i) = (*pX)(i + 1);
1570 if (!(idx(0).is_range()
1571 || (idx(0).is_integer_type()
1572 && (idx(0).rows() == 1 || idx(0).columns() == 1)))) {
1573 error(
"%s: invalid index type %dx%d (%s)\n"
1574 "expected integer vector",
1575 type_name().c_str(),
1578 idx(0).type_name().c_str());
1579 return octave_value();
1582 const int32NDArray iRow(idx(0).int32_array_value());
1585 return octave_value();
1588 X.resize(iRow.length());
1590 for (
int i = 0; i < iRow.length(); ++i) {
1591 if (int32_t(iRow(i)) < 1 || int32_t(iRow(i)) > iSize) {
1592 error(
"%s: index %d out of range [%d-%d]",
1593 type_name().c_str(),
1598 return octave_value();
1601 X(i) = (*pX)(int32_t(iRow(i)));
1605 return octave_value(X);
1608 dim_vector ConstVectorHandlerInterface::dims()
const
1611 error(
"%s: not connected", type_name().c_str());
1612 return dim_vector(-1, -1);
1615 return dim_vector(pX->iGetSize(), 1);
1618 METHOD_DEFINE(ConstVectorHandlerInterface, dGetCoef, args, nargout)
1621 error(
"%s: not connected", type_name().c_str());
1622 return octave_value();
1625 if ( args.length() != 1 ) {
1626 error(
"%s: invalid number of arguments %ld\n"
1627 "one argument expected",
1628 type_name().c_str(),
1629 long(args.length()));
1630 return octave_value();
1633 if ( !(args(0).is_integer_type() && args(0).is_scalar_type()) ) {
1634 error(
"%s: invalid argument type \"%s\"\n"
1635 "iRow must be an integer",
1636 type_name().c_str(),
1637 args(0).type_name().c_str());
1638 return octave_value();
1641 const integer iRow = args(0).int32_scalar_value();
1643 if ( iRow < 1 || iRow > pX->iGetSize() ) {
1644 error(
"VectorHandler: index %ld out of range [%ld-%ld]",
long(iRow), 1L,
long(pX->iGetSize()));
1645 return octave_value();
1648 return octave_value(pX->dGetCoef(iRow));
1651 METHOD_DEFINE(ConstVectorHandlerInterface, GetVec, args, nargout)
1654 error(
"%s: not connected", type_name().c_str());
1655 return octave_value();
1658 if (args.length() != 1) {
1659 error(
"%s: invalid number of arguments %ld\n"
1660 "one argument expected",
1661 type_name().c_str(),
1662 long(args.length()));
1663 return octave_value();
1666 if (!(args(0).is_integer_type() && args(0).columns() == 1)) {
1667 error(
"%s: invalid argument type \"%s\"\n"
1668 "iRow must be an integer column vector",
1669 type_name().c_str(),
1670 args(0).type_name().c_str());
1671 return octave_value();
1674 const int32NDArray iRow(args(0).int32_array_value());
1676 ColumnVector X(iRow.length());
1678 const int32_t iSize = pX->iGetSize();
1680 for (
int i = 0; i < iRow.length(); ++i) {
1681 if (int32_t(iRow(i)) < 1 || int32_t(iRow(i)) > iSize) {
1682 error(
"%s: index %d out of range [%d-%d]",
1683 type_name().c_str(),
1688 return octave_value();
1691 X(i) = pX->dGetCoef(iRow(i));
1694 return octave_value(X);
1697 METHOD_DEFINE(ConstVectorHandlerInterface, iGetSize, args, nargout)
1700 error(
"%s: not connected", type_name().c_str());
1701 return octave_value();
1704 if ( args.length() != 0 ) {
1705 error(
"%s: invalid number of arguments %ld\n"
1706 "no arguments expected",
1707 type_name().c_str(),
1708 long(args.length()));
1709 return octave_value();
1712 return octave_value(octave_int<integer>(pX->iGetSize()));
1715 BEGIN_METHOD_TABLE(ConstVectorHandlerInterface, MBDynInterface)
1716 METHOD_DISPATCH(ConstVectorHandlerInterface, dGetCoef)
1717 METHOD_DISPATCH(ConstVectorHandlerInterface, GetVec)
1718 METHOD_DISPATCH(ConstVectorHandlerInterface, iGetSize)
1721 DEFINE_OCTAVE_ALLOCATOR(ConstVectorHandlerInterface);
1722 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(ConstVectorHandlerInterface, "ConstVectorHandler", "ConstVectorHandler");
1724 VectorHandlerInterface::VectorHandlerInterface(OctaveInterface* pInterface,
VectorHandler* X)
1725 :ConstVectorHandlerInterface(pInterface, X)
1727 TRACE(
"constructor");
1730 VectorHandlerInterface::~VectorHandlerInterface()
1732 TRACE(
"destructor");
1735 METHOD_DEFINE(VectorHandlerInterface, PutCoef, args, nargout)
1738 error(
"%s: not connected", type_name().c_str());
1739 return octave_value();
1742 if ( args.length() != 2 ) {
1743 error(
"%s: invalid number of arguments %ld\n"
1744 "two arguments expected",
1745 type_name().c_str(),
1746 long(args.length()));
1748 return octave_value();
1751 if (!(args(0).is_scalar_type() && args(0).is_integer_type())) {
1752 error(
"%s: invalid argument type (%s)\n"
1753 "iRow must be an integer",
1754 type_name().c_str(),
1755 args(0).type_name().c_str());
1757 return octave_value();
1760 const integer iRow = args(0).int32_scalar_value();
1762 if ( iRow < 1 || iRow > pX->iGetSize() ) {
1763 error(
"%s: index %ld out of range [%ld-%ld]",
1764 type_name().c_str(),
1767 long(pX->iGetSize()));
1768 return octave_value();
1771 if ( !args(1).is_scalar_type() ) {
1772 error(
"%s: invalid argument type \"%s\"\n"
1773 "dCoef must be a scalar value",
1774 type_name().c_str(),
1775 args(1).type_name().c_str());
1776 return octave_value();
1779 const doublereal dCoef = args(1).scalar_value();
1781 pX->PutCoef(iRow, dCoef);
1783 return octave_value();
1786 METHOD_DEFINE(VectorHandlerInterface, PutVec, args, nargout)
1789 error(
"%s: not connected", type_name().c_str());
1790 return octave_value();
1793 if ( args.length() != 2 ) {
1794 error(
"%s: invalid number of arguments %ld\n"
1795 "two arguments expected",
1796 type_name().c_str(),
1797 long(args.length()));
1799 return octave_value();
1802 if (!(args(0).is_integer_type() && args(0).columns() == 1)) {
1803 error(
"%s: invalid argument type %ldx%ld (%s)\n"
1804 "iRow must be an integer column vector",
1805 type_name().c_str(),
1806 long(args(0).rows()),
1807 long(args(0).columns()),
1808 args(0).type_name().c_str());
1810 return octave_value();
1813 const int32NDArray iRow(args(0).int32_array_value());
1815 if (!(args(1).is_real_matrix()
1816 && args(1).columns() == 1
1817 && args(1).rows() == iRow.length())) {
1818 error(
"%s: invalid argument type %ldx%ld (%s)\n"
1819 "X must be a real column vector "
1820 "with the same number of rows like iRow",
1821 type_name().c_str(),
1822 long(args(1).rows()),
1823 long(args(1).columns()),
1824 args(1).type_name().c_str());
1826 return octave_value();
1829 const ColumnVector X(args(1).column_vector_value());
1831 ASSERT(X.length() == iRow.length());
1833 const int32_t iSize = pX->iGetSize();
1835 for (
int i = 0; i < iRow.length(); ++i) {
1836 if (int32_t(iRow(i)) < 1 || int32_t(iRow(i)) > iSize) {
1837 error(
"%s: index %d out of range [%d-%d]",
1838 type_name().c_str(),
1842 return octave_value();
1845 pX->PutCoef(iRow(i), X(i));
1848 return octave_value();
1851 BEGIN_METHOD_TABLE(VectorHandlerInterface, ConstVectorHandlerInterface)
1852 METHOD_DISPATCH(VectorHandlerInterface, PutCoef)
1853 METHOD_DISPATCH(VectorHandlerInterface, PutVec)
1856 DEFINE_OCTAVE_ALLOCATOR(VectorHandlerInterface);
1857 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(VectorHandlerInterface, "
VectorHandler", "VectorHandler");
1859 const std::
string OStreamInterface::strsprintf("sprintf");
1861 OStreamInterface::OStreamInterface(OctaveInterface* pInterface, std::ostream* pOS)
1862 : MBDynInterface(pInterface),
1868 OStreamInterface::~OStreamInterface()
1873 METHOD_DEFINE(OStreamInterface, printf, args, nargout)
1876 error(
"ostream: not connected");
1877 return octave_value();
1880 const octave_value_list ans = feval(strsprintf, args, 1);
1883 return octave_value();
1886 if (!(ans.length() >= 1 && ans(0).is_string())) {
1887 error(
"ostream: %s failed", strsprintf.c_str());
1888 return octave_value();
1891 const std::string str(ans(0).string_value());
1893 for (std::string::const_iterator p = str.begin(); p != str.end(); ++p) {
1900 return octave_value(octave_int<size_t>(str.length()));
1903 BEGIN_METHOD_TABLE(OStreamInterface, MBDynInterface)
1904 METHOD_DISPATCH(OStreamInterface, printf)
1907 DEFINE_OCTAVE_ALLOCATOR(OStreamInterface);
1908 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(OStreamInterface, "ostream", "ostream");
1911 SimulationEntityInterface::SimulationEntityInterface(OctaveInterface* pInterface)
1912 : MBDynInterface(pInterface)
1917 SimulationEntityInterface::~SimulationEntityInterface()
1922 METHOD_DEFINE(SimulationEntityInterface, iGetNumPrivData, args, nargout)
1926 if (!pSimulationEntity) {
1927 error(
"%s: not connected", type_name().c_str());
1928 return octave_value();
1931 if (args.length() != 0) {
1932 error(
"%s: invalid number of arguments\n"
1933 "expected no arguments", type_name().c_str());
1935 return octave_value();
1938 return octave_value(octave_int<unsigned int>(pSimulationEntity->
iGetNumPrivData()));
1941 METHOD_DEFINE(SimulationEntityInterface, iGetPrivDataIdx, args, nargout)
1945 if (!pSimulationEntity) {
1946 error(
"%s: not connected",
1947 type_name().c_str());
1948 return octave_value();
1951 if (args.length() != 1) {
1952 error(
"%s: invalid number of arguments\n"
1953 "expected one argument",
1954 type_name().c_str());
1956 return octave_value();
1959 if ( !args(0).is_string() ) {
1960 error(
"%s: invalid argument type (%s)\n"
1962 type_name().c_str(),
1963 args(0).type_name().c_str());
1965 return octave_value();
1968 const std::string name = args(0).string_value();
1970 return octave_value(octave_int<unsigned int>(pSimulationEntity->
iGetPrivDataIdx(name.c_str())));
1973 METHOD_DEFINE(SimulationEntityInterface, dGetPrivData, args, nargout)
1977 if (!pSimulationEntity) {
1978 error(
"%s: not connected", type_name().c_str());
1979 return octave_value();
1982 if (args.length() != 1) {
1983 error(
"%s: invalid number of arguments\n"
1984 "expected one arguments", type_name().c_str());
1986 return octave_value();
1989 if (!(args(0).is_integer_type() && args(0).is_scalar_type())) {
1990 error(
"%s: invalid argument type (%s)\n"
1991 "expected integer scalar",
1992 type_name().c_str(),
1993 args(0).type_name().c_str());
1994 return octave_value();
1997 const int32_t idx = args(0).int32_scalar_value();
1999 return octave_value(pSimulationEntity->
dGetPrivData(idx));
2002 BEGIN_METHOD_TABLE(SimulationEntityInterface, MBDynInterface)
2003 METHOD_DISPATCH(SimulationEntityInterface, iGetNumPrivData)
2004 METHOD_DISPATCH(SimulationEntityInterface, iGetPrivDataIdx)
2005 METHOD_DISPATCH(SimulationEntityInterface, dGetPrivData)
2008 NodeInterface::NodeInterface(OctaveInterface* pInterface)
2009 : SimulationEntityInterface(pInterface)
2014 NodeInterface::~NodeInterface()
2019 void NodeInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
2021 const Node*
const pNode = Get();
2024 error(
"%s: not connected", type_name().c_str());
2028 os << type_name() <<
"(" << pNode->
GetLabel() <<
"):" << pNode->
GetName() << std::endl;
2031 METHOD_DEFINE(NodeInterface, GetLabel, args, nargout)
2033 const Node*
const pNode = Get();
2036 error(
"%s: not connected", type_name().c_str());
2037 return octave_value();
2040 if (args.length() != 0) {
2041 error(
"%s: invalid number of arguments %ld\n"
2042 "no arguments expected",
2043 type_name().c_str(),
2044 long(args.length()));
2046 return octave_value();
2049 return octave_value(octave_int<unsigned int>(pNode->
GetLabel()));
2052 METHOD_DEFINE(NodeInterface, GetName, args, nargout)
2054 const Node*
const pNode = Get();
2057 error(
"%s: not connected", type_name().c_str());
2058 return octave_value();
2061 if (args.length() != 0) {
2062 error(
"%s: invalid number of arguments %ld\n"
2063 "no arguments expected",
2064 type_name().c_str(),
2065 long(args.length()));
2067 return octave_value();
2070 return octave_value(pNode->
GetName());
2073 METHOD_DEFINE(NodeInterface, iGetFirstIndex, args, nargout)
2075 const Node*
const pNode = Get();
2078 error(
"%s: not connected", type_name().c_str());
2079 return octave_value();
2082 if (args.length() != 0) {
2083 error(
"%s: invalid number of arguments %ld\n"
2084 "no arguments expected",
2085 type_name().c_str(),
2086 long(args.length()));
2088 return octave_value();
2091 return octave_value(octave_int<integer>(pNode->
iGetFirstIndex()));
2094 METHOD_DEFINE(NodeInterface, iGetFirstRowIndex, args, nargout)
2096 const Node*
const pNode = Get();
2099 error(
"%s: not connected", type_name().c_str());
2100 return octave_value();
2103 if (args.length() != 0) {
2104 error(
"%s: invalid number of arguments %ld\n"
2105 "no arguments expected",
2106 type_name().c_str(),
2107 long(args.length()));
2109 return octave_value();
2115 METHOD_DEFINE(NodeInterface, iGetFirstColIndex, args, nargout)
2117 const Node*
const pNode = Get();
2120 error(
"%s: not connected", type_name().c_str());
2121 return octave_value();
2124 if (args.length() != 0) {
2125 error(
"%s: invalid number of arguments %ld\n"
2126 "no arguments expected",
2127 type_name().c_str(),
2128 long(args.length()));
2130 return octave_value();
2136 METHOD_DEFINE(NodeInterface, dGetDofValue, args, nargout)
2138 const Node*
const pNode = Get();
2141 error(
"%s: not connected", type_name().c_str());
2142 return octave_value();
2145 if (args.length() != 2) {
2146 error(
"%s: invalid number of arguments %ld\n"
2147 "%ld arguments expected",
2148 type_name().c_str(),
2149 long(args.length()),
2152 return octave_value();
2155 if (!(args(0).is_integer_type() && args(0).is_scalar_type())) {
2156 error(
"%s: invalid argument type (%s) for argument 1\n"
2157 "integer scalar expected",
2158 type_name().c_str(),
2159 args(0).type_name().c_str());
2161 return octave_value();
2164 const int32_t iDof = args(0).int32_scalar_value();
2166 if (!(args(1).is_integer_type() && args(1).is_scalar_type())) {
2167 error(
"%s: invalid argument type (%s) for argument 2\n"
2168 "integer scalar expected",
2169 type_name().c_str(),
2170 args(1).type_name().c_str());
2172 return octave_value();
2175 const int32_t iOrder = args(1).int32_scalar_value();
2177 return octave_value(pNode->
dGetDofValue(iDof, iOrder));
2180 METHOD_DEFINE(NodeInterface, dGetDofValuePrev, args, nargout)
2182 const Node*
const pNode = Get();
2185 error(
"%s: not connected", type_name().c_str());
2186 return octave_value();
2189 if (args.length() != 2) {
2190 error(
"%s: invalid number of arguments %ld\n"
2191 "%ld arguments expected",
2192 type_name().c_str(),
2193 long(args.length()),
2196 return octave_value();
2199 if (!(args(0).is_integer_type() && args(0).is_scalar_type())) {
2200 error(
"%s: invalid argument type (%s) for argument 1\n"
2201 "integer scalar expected",
2202 type_name().c_str(),
2203 args(0).type_name().c_str());
2205 return octave_value();
2208 const int32_t iDof = args(0).int32_scalar_value();
2210 if (!(args(1).is_integer_type() && args(1).is_scalar_type())) {
2211 error(
"%s: invalid argument type (%s) for argument 2\n"
2212 "integer scalar expected",
2213 type_name().c_str(),
2214 args(1).type_name().c_str());
2216 return octave_value();
2219 const int32_t iOrder = args(1).int32_scalar_value();
2224 BEGIN_METHOD_TABLE(NodeInterface, SimulationEntityInterface)
2225 METHOD_DISPATCH(NodeInterface, GetLabel)
2226 METHOD_DISPATCH(NodeInterface, GetName)
2227 METHOD_DISPATCH(NodeInterface, iGetFirstIndex)
2228 METHOD_DISPATCH(NodeInterface, iGetFirstRowIndex)
2229 METHOD_DISPATCH(NodeInterface, iGetFirstColIndex)
2230 METHOD_DISPATCH(NodeInterface, dGetDofValue)
2231 METHOD_DISPATCH(NodeInterface, dGetDofValuePrev)
2234 ScalarNodeInterface::ScalarNodeInterface(OctaveInterface* pInterface,
ScalarNode* pNode)
2235 : NodeInterface(pInterface),
2241 ScalarNodeInterface::~ScalarNodeInterface()
2246 const ScalarNode* ScalarNodeInterface::Get()
const
2251 METHOD_DEFINE(ScalarNodeInterface, SetX, args, nargout)
2254 error(
"%s: not connected", type_name().c_str());
2255 return octave_value();
2258 if (args.length() != 1) {
2259 error(
"%s: invalid number of arguments %ld\n"
2260 "expected one argument",
2261 type_name().c_str(),
2262 long(args.length()));
2264 return octave_value();
2267 if (!args(0).is_real_scalar()) {
2268 error(
"%s: invalid argument type (%s)\n"
2269 "expected real scalar",
2270 type_name().c_str(),
2271 args(0).type_name().c_str());
2273 return octave_value();
2276 pNode->SetX(args(0).scalar_value());
2278 return octave_value();
2281 METHOD_DEFINE(ScalarNodeInterface, dGetX, args, nargout)
2284 error(
"%s: not connected", type_name().c_str());
2285 return octave_value();
2288 if (args.length() != 0) {
2289 error(
"%s: invalid number of arguments %ld\n"
2290 "expected no argument",
2291 type_name().c_str(),
2292 long(args.length()));
2294 return octave_value();
2297 return octave_value(pNode->dGetX());
2300 METHOD_DEFINE(ScalarNodeInterface, SetXPrime, args, nargout)
2303 error(
"%s: not connected", type_name().c_str());
2304 return octave_value();
2307 if (args.length() != 1) {
2308 error(
"%s: invalid number of arguments %ld\n"
2309 "expected one argument",
2310 type_name().c_str(),
2311 long(args.length()));
2313 return octave_value();
2316 if (!args(0).is_real_scalar()) {
2317 error(
"%s: invalid argument type (%s)\n"
2318 "expected real scalar",
2319 type_name().c_str(),
2320 args(0).type_name().c_str());
2322 return octave_value();
2325 pNode->SetXPrime(args(0).scalar_value());
2327 return octave_value();
2330 METHOD_DEFINE(ScalarNodeInterface, dGetXPrime, args, nargout)
2333 error(
"%s: not connected", type_name().c_str());
2334 return octave_value();
2337 if (args.length() != 0) {
2338 error(
"%s: invalid number of arguments %ld\n"
2339 "expected no argument",
2340 type_name().c_str(),
2341 long(args.length()));
2343 return octave_value();
2346 return octave_value(pNode->dGetXPrime());
2349 BEGIN_METHOD_TABLE(ScalarNodeInterface, NodeInterface)
2350 METHOD_DISPATCH(ScalarNodeInterface, SetX)
2351 METHOD_DISPATCH(ScalarNodeInterface, dGetX)
2352 METHOD_DISPATCH(ScalarNodeInterface, SetXPrime)
2353 METHOD_DISPATCH(ScalarNodeInterface, dGetXPrime)
2356 DEFINE_OCTAVE_ALLOCATOR(ScalarNodeInterface);
2357 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(ScalarNodeInterface, "
ScalarNode", "ScalarNode");
2359 StructDispNodeBaseInterface::StructDispNodeBaseInterface(OctaveInterface* pInterface)
2360 : NodeInterface(pInterface)
2362 TRACE(
"constructor");
2365 StructDispNodeBaseInterface::~StructDispNodeBaseInterface()
2367 TRACE(
"destructor");
2371 StructDispNodeBaseInterface::GetVec3(
const Vec3& V,
const octave_value_list& args)
const
2373 octave_value octValue;
2375 if (args.length() != 0) {
2376 error(
"StructNode: invalid number of arguments %ld"
2377 "no arguments expected",
long(args.length()));
2381 if (!GetInterface()->ConvertMBDynToOctave(V, octValue)) {
2382 error(
"StructNode: could not convert data");
2389 StructDispNodeBaseInterface::GetMat3x3(
const Mat3x3& M,
const octave_value_list& args)
const
2391 octave_value octValue;
2393 if (args.length() != 0) {
2394 error(
"StructNode: invalid number of arguments %ld"
2395 "no arguments expected",
long(args.length()));
2399 if (!GetInterface()->ConvertMBDynToOctave(M, octValue)) {
2400 error(
"StructNode: could not convert data");
2406 METHOD_DEFINE(StructDispNodeBaseInterface, iGetFirstPositionIndex, args, nargout)
2411 error(
"StructNode: not connected");
2412 return octave_value();
2415 if (args.length() != 0) {
2416 error(
"StructNode: invalid number of arguments %ld"
2417 "no arguments expected",
long(args.length()));
2418 return octave_value();
2424 METHOD_DEFINE(StructDispNodeBaseInterface, iGetFirstMomentumIndex, args, nargout)
2429 error(
"StructNode: not connected");
2430 return octave_value();
2433 if (args.length() != 0) {
2434 error(
"StructNode: invalid number of arguments %ld"
2435 "no arguments expected",
long(args.length()));
2436 return octave_value();
2442 METHOD_DEFINE(StructDispNodeBaseInterface, GetLabel, args, nargout)
2447 error(
"StructNode: not connected");
2448 return octave_value();
2451 if (args.length() != 0) {
2452 error(
"StructNode: invalid number of arguments %ld\n"
2453 "no arguments expected",
long(args.length()));
2454 return octave_value();
2457 return octave_value(octave_int<integer>(pNode->
GetLabel()));
2460 METHOD_DEFINE(StructDispNodeBaseInterface, GetXCurr, args, nargout)
2465 error(
"StructNode: not connected");
2466 return octave_value();
2469 return GetVec3(pNode->
GetXCurr(), args);
2472 METHOD_DEFINE(StructDispNodeBaseInterface, GetXPrev, args, nargout)
2477 error(
"StructNode: not connected");
2478 return octave_value();
2481 return GetVec3(pNode->
GetXPrev(), args);
2484 METHOD_DEFINE(StructDispNodeBaseInterface, GetVCurr, args, nargout)
2489 error(
"StructNode: not connected");
2490 return octave_value();
2493 return GetVec3(pNode->
GetVCurr(), args);
2496 METHOD_DEFINE(StructDispNodeBaseInterface, GetVPrev, args, nargout)
2501 error(
"StructNode: not connected");
2502 return octave_value();
2505 return GetVec3(pNode->
GetVPrev(), args);
2508 METHOD_DEFINE(StructDispNodeBaseInterface, GetXPPCurr, args, nargout)
2513 error(
"StructNode: not connected");
2514 return octave_value();
2518 error(
"StructNode: accelerations are not available for node %u", pNode->
GetLabel());
2519 return octave_value();
2525 METHOD_DEFINE(StructDispNodeBaseInterface, GetXPPPrev, args, nargout)
2530 error(
"StructNode: not connected");
2531 return octave_value();
2535 error(
"StructNode: accelerations are not available for node %u", pNode->
GetLabel());
2536 return octave_value();
2542 BEGIN_METHOD_TABLE(StructDispNodeBaseInterface, NodeInterface)
2543 METHOD_DISPATCH(StructDispNodeBaseInterface, iGetFirstIndex)
2544 METHOD_DISPATCH(StructDispNodeBaseInterface, iGetFirstPositionIndex)
2545 METHOD_DISPATCH(StructDispNodeBaseInterface, iGetFirstMomentumIndex)
2546 METHOD_DISPATCH(StructDispNodeBaseInterface, GetLabel)
2547 METHOD_DISPATCH(StructDispNodeBaseInterface, GetXCurr)
2548 METHOD_DISPATCH(StructDispNodeBaseInterface, GetXPrev)
2549 METHOD_DISPATCH(StructNodeInterface, GetVCurr)
2550 METHOD_DISPATCH(StructNodeInterface, GetVPrev)
2551 METHOD_DISPATCH(StructNodeInterface, GetXPPCurr)
2552 METHOD_DISPATCH(StructNodeInterface, GetXPPPrev)
2555 StructDispNodeInterface::StructDispNodeInterface(OctaveInterface* pInterface, const
StructDispNode* pNode)
2556 : StructDispNodeBaseInterface(pInterface),
2562 StructDispNodeInterface::~StructDispNodeInterface()
2572 DEFINE_OCTAVE_ALLOCATOR(StructDispNodeInterface);
2573 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(StructDispNodeInterface,
"StructDispNode",
"StructDispNode");
2575 StructNodeInterface::StructNodeInterface(OctaveInterface* pInterface,
const StructNode* pNode)
2576 : StructDispNodeBaseInterface(pInterface),
2579 TRACE(
"constructor");
2582 StructNodeInterface::~StructNodeInterface(
void)
2584 TRACE(
"destructor");
2588 StructNodeInterface::Get()
const
2593 METHOD_DEFINE(StructNodeInterface, GetgCurr, args, nargout)
2596 error(
"StructNode: not connected");
2597 return octave_value();
2600 return GetVec3(pNode->GetgCurr(), args);
2603 METHOD_DEFINE(StructNodeInterface, GetgRef, args, nargout)
2606 error(
"StructNode: not connected");
2607 return octave_value();
2610 return GetVec3(pNode->GetgRef(), args);
2613 METHOD_DEFINE(StructNodeInterface, GetgPCurr, args, nargout)
2616 error(
"StructNode: not connected");
2617 return octave_value();
2620 return GetVec3(pNode->GetgPCurr(), args);
2623 METHOD_DEFINE(StructNodeInterface, GetgPRef, args, nargout)
2626 error(
"StructNode: not connected");
2627 return octave_value();
2630 return GetVec3(pNode->GetgPRef(), args);
2633 METHOD_DEFINE(StructNodeInterface, GetRCurr, args, nargout)
2636 error(
"StructNode: not connected");
2637 return octave_value();
2640 return GetMat3x3(pNode->GetRCurr(), args);
2643 METHOD_DEFINE(StructNodeInterface, GetRPrev, args, nargout)
2646 error(
"StructNode: not connected");
2647 return octave_value();
2650 return GetMat3x3(pNode->GetRPrev(), args);
2653 METHOD_DEFINE(StructNodeInterface, GetRRef, args, nargout)
2656 error(
"StructNode: not connected");
2657 return octave_value();
2660 return GetMat3x3(pNode->GetRRef(), args);
2663 METHOD_DEFINE(StructNodeInterface, GetWCurr, args, nargout)
2666 error(
"StructNode: not connected");
2667 return octave_value();
2670 return GetVec3(pNode->GetWCurr(), args);
2673 METHOD_DEFINE(StructNodeInterface, GetWPrev, args, nargout)
2676 error(
"StructNode: not connected");
2677 return octave_value();
2680 return GetVec3(pNode->GetWPrev(), args);
2683 METHOD_DEFINE(StructNodeInterface, GetWRef, args, nargout)
2686 error(
"StructNode: not connected");
2687 return octave_value();
2690 return GetVec3(pNode->GetWRef(), args);
2693 METHOD_DEFINE(StructNodeInterface, GetWPCurr, args, nargout)
2696 error(
"StructNode: not connected");
2697 return octave_value();
2701 error(
"StructNode: accelerations are not available for node %u", pNode->
GetLabel());
2702 return octave_value();
2705 return GetVec3(pNode->GetWPCurr(), args);
2708 METHOD_DEFINE(StructNodeInterface, GetWPPrev, args, nargout)
2711 error(
"StructNode: not connected");
2712 return octave_value();
2716 error(
"StructNode: accelerations are not available for node %u", pNode->
GetLabel());
2717 return octave_value();
2720 return GetVec3(pNode->GetWPPrev(), args);
2723 BEGIN_METHOD_TABLE(StructNodeInterface, StructDispNodeBaseInterface)
2724 METHOD_DISPATCH(StructNodeInterface, GetgCurr)
2725 METHOD_DISPATCH(StructNodeInterface, GetgRef)
2726 METHOD_DISPATCH(StructNodeInterface, GetgPCurr)
2727 METHOD_DISPATCH(StructNodeInterface, GetgPRef)
2728 METHOD_DISPATCH(StructNodeInterface, GetRCurr)
2729 METHOD_DISPATCH(StructNodeInterface, GetRPrev)
2730 METHOD_DISPATCH(StructNodeInterface, GetRRef)
2731 METHOD_DISPATCH(StructNodeInterface, GetWCurr)
2732 METHOD_DISPATCH(StructNodeInterface, GetWPrev)
2733 METHOD_DISPATCH(StructNodeInterface, GetWRef)
2734 METHOD_DISPATCH(StructNodeInterface, GetWPCurr)
2735 METHOD_DISPATCH(StructNodeInterface, GetWPPrev)
2738 DEFINE_OCTAVE_ALLOCATOR(StructNodeInterface);
2739 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(StructNodeInterface, "
StructNode", "StructNode");
2741 DataManagerInterface::DataManagerInterface(OctaveInterface* pInterface, const
DataManager* pDM)
2742 :MBDynInterface(pInterface),
2745 TRACE(
"constructor");
2751 DataManagerInterface::~DataManagerInterface()
2753 TRACE(
"destructor");
2756 void DataManagerInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
2758 os <<
"DataManager" << std::endl
2759 <<
"iTotDofs=" << GetDataManager()->iGetNumDofs() << std::endl;
2762 METHOD_DEFINE(DataManagerInterface, GetVariable, args, nargout)
2764 octave_value octValue;
2766 if (args.length() != 1) {
2767 error(
"DataManager: invalid number of arguments %ld\n"
2768 "one argument expected",
long(args.length()));
2772 if (!args(0).is_string()) {
2773 error(
"DataManager: invalid argument type \"%s\"\n"
2774 "varName must be a string", args(0).type_name().c_str());
2778 const std::string varName = args(0).string_value();
2780 const NamedValue*
const pVar = GetSymbolTable().Get(varName.c_str());
2783 error(
"DataManager: variable \"%s\" not found in symbol table", varName.c_str());
2789 if (!GetInterface()->ConvertMBDynToOctave(mbValue, octValue)) {
2790 error(
"%s: failed to convert MBDyn variable %s"
2791 " of type %s value into octave value",
2792 type_name().c_str(),
2800 METHOD_DEFINE(DataManagerInterface, GetStructNodePos, args, nargout)
2802 octave_value octValue;
2804 if (args.length() != 1) {
2805 error(
"DataManager: invalid number of arguments\n"
2806 "one argument expected");
2810 if (!(args(0).is_scalar_type() && args(0).is_integer_type())) {
2811 error(
"DataManager: invalid argument type \"%s\"\n"
2812 "iNodeLabel must be an integer", args(0).type_name().c_str());
2816 integer iNodeLabel = args(0).int32_scalar_value();
2821 error(
"DataManager: invalid node label\n"
2822 "could not find node %ld",
long(iNodeLabel));
2828 if (pStructNode == 0) {
2829 error(
"DataManager: invalid node type\n"
2830 "node %ld is not a structural displacement node",
long(iNodeLabel));
2836 ColumnVector octX(3);
2838 for (
int i = 0; i < 3; ++i) {
2847 METHOD_DEFINE(DataManagerInterface, GetStructNode, args, nargout)
2849 octave_value octValue;
2851 if (args.length() != 1) {
2852 error(
"DataManager: invalid number of arguments\n"
2853 "one argument expected");
2857 if (!(args(0).is_scalar_type() && args(0).is_integer_type())) {
2858 error(
"DataManager: invalid argument type \"%s\"\n"
2859 "iNodeLabel must be an integer", args(0).type_name().c_str());
2863 integer iNodeLabel =
static_cast<int32_t
>(args(0).int32_scalar_value());
2868 error(
"DataManager: could not find node %ld",
long(iNodeLabel));
2875 octValue =
new StructNodeInterface(GetInterface(), pStructNode);
2881 if (!pStructDispNode) {
2882 error(
"%s: node %ld is not a structural node", type_name().c_str(),
long(iNodeLabel));
2886 octValue =
new StructDispNodeInterface(GetInterface(), pStructDispNode);
2891 METHOD_DEFINE(DataManagerInterface, pFindNode, args, nargout)
2895 Node*
const pNode = pFindNode_(args, Type);
2898 return octave_value();
2901 NodeInterface*
const pNodeInterface = CreateNodeInterface(pNode, Type);
2903 if (pNodeInterface == 0) {
2904 error(
"%s: unknown node type %ld", type_name().c_str(),
long(Type));
2905 return octave_value();
2908 return octave_value(pNodeInterface);
2911 METHOD_DEFINE(DataManagerInterface, ReadNode, args, nargout)
2913 if (args.length() != 2) {
2914 error(
"%s: invalid number of arguments (%ld)\n"
2915 "arguments expected: %ld",
2916 type_name().c_str(),
2917 long(args.length()),
2920 return octave_value();
2923 const MBDynParserInterface*
const pHPI =
2924 dynamic_cast<const MBDynParserInterface*
>(&args(0).get_rep());
2927 error(
"%s: invalid argument type (%s)\n"
2928 "expected MBDynParser",
2929 type_name().c_str(),
2930 args(0).type_name().c_str());
2932 return octave_value();
2938 error(
"%s: not connected", pHPI->type_name().c_str());
2939 return octave_value();
2942 if (!args(1).is_string()) {
2943 error(
"%s: invalid argument type (%s)\n"
2945 type_name().c_str(),
2946 args(1).type_name().c_str());
2948 return octave_value();
2951 const std::string strType(args(1).string_value());
2953 const Node::Type Type = GetNodeType(strType);
2956 error(
"%s: invalid node type (%s)", type_name().c_str(), strType.c_str());
2957 return octave_value();
2965 pNode =
const_cast<DataManager*
>(pDM)->ReadNode(*pHP, Type);
2967 error(
"%s: ReadNode failed", type_name().c_str());
2968 return octave_value();
2971 NodeInterface*
const pNodeInterface = CreateNodeInterface(pNode, Type);
2973 if (pNodeInterface == 0) {
2974 error(
"%s: unknown node type %ld", type_name().c_str(),
long(Type));
2975 return octave_value();
2978 return octave_value(pNodeInterface);
2981 METHOD_DEFINE(DataManagerInterface, dGetTime, args, nargout)
2983 if (args.length() != 0) {
2984 error(
"DataManager: invalid number of arguments\n"
2985 "no argument expected");
2986 return octave_value();
2989 return octave_value(GetDataManager()->dGetTime());
2992 const DataManager* DataManagerInterface::GetDataManager()
const
2994 ASSERT(GetInterface() != 0);
3000 const Table& DataManagerInterface::GetSymbolTable()
const
3002 return GetDataManager()->GetMathParser().GetSymbolTable();
3005 Node* DataManagerInterface::pFindNode_(
const octave_value_list& args,
Node::Type& Type)
const
3007 if (args.length() != 2) {
3008 error(
"%s: invalid number of arguments\n"
3009 "arguments expected 2", type_name().c_str());
3014 if (!(args(0).is_string())) {
3015 error(
"%s: invalid argument type (%s)\n"
3016 "Type must be a string",
3017 type_name().c_str(),
3018 args(0).type_name().c_str());
3023 const std::string strType(args(0).string_value());
3025 Type = GetNodeType(strType);
3028 error(
"%s: unknown node type (%s)", type_name().c_str(), strType.c_str());
3032 if (!(args(1).is_scalar_type() && args(1).is_integer_type())) {
3033 error(
"%s: invalid argument type (%s)\n"
3034 "iNodeLabel must be an integer",
3035 type_name().c_str(),
3036 args(1).type_name().c_str());
3041 const int32_t iNodeLabel = args(1).int32_scalar_value();
3043 Node* pNode = GetDataManager()->pFindNode(Type, iNodeLabel);
3046 error(
"%s: could not find node %ld", type_name().c_str(),
long(iNodeLabel));
3053 Node::Type DataManagerInterface::GetNodeType(
const std::string& strType)
const
3055 static const struct {
3068 static const int count =
sizeof(nodeTypes) /
sizeof(nodeTypes[0]);
3070 for (
int i = 0; i <
count; ++i) {
3071 if (strType == nodeTypes[i].name) {
3072 return nodeTypes[i].type;
3079 NodeInterface* DataManagerInterface::CreateNodeInterface(
Node* pNode,
Node::Type Type)
const
3086 if (pStructNode == 0) {
3088 if (pStructDispNode == 0) {
3093 return new StructDispNodeInterface(GetInterface(), pStructDispNode);
3095 return new StructNodeInterface(GetInterface(), pStructNode);
3104 ASSERT(pScalarNode != 0);
3105 return new ScalarNodeInterface(GetInterface(), pScalarNode);
3113 BEGIN_METHOD_TABLE(DataManagerInterface, MBDynInterface)
3114 METHOD_DISPATCH(DataManagerInterface, GetVariable)
3115 METHOD_DISPATCH(DataManagerInterface, GetStructNodePos)
3116 METHOD_DISPATCH(DataManagerInterface, GetStructNode)
3117 METHOD_DISPATCH(DataManagerInterface, pFindNode)
3118 METHOD_DISPATCH(DataManagerInterface, ReadNode)
3119 METHOD_DISPATCH(DataManagerInterface, dGetTime)
3122 DEFINE_OCTAVE_ALLOCATOR(DataManagerInterface);
3123 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(DataManagerInterface, "
DataManager", "DataManager");
3125 const MBDynParserInterface::MBDynStringDelims
3126 MBDynParserInterface::mbStringDelims[6] = {
3135 MBDynParserInterface::MBDynParserInterface(OctaveInterface* pInterface,
MBDynParser* pHP)
3136 :MBDynInterface(pInterface),
3142 this->pHP = &pInterface->GetDataManager()->GetMBDynParser();
3147 MBDynParserInterface::~MBDynParserInterface()
3152 void MBDynParserInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
3154 os <<
"MBDynParser";
3158 os <<
" at " << lineData.
sFileName <<
":" << lineData.iLineNumber;
3164 METHOD_DEFINE(MBDynParserInterface, IsKeyWord, args, nargout)
3167 error(
"MBDynParser: not connected");
3168 return octave_value();
3171 if (args.length() != 1) {
3172 error(
"MBDynParser: invalid number of arguments %ld\n"
3173 "expected %ld arguments",
long(args.length()), 1L);
3174 return octave_value();
3177 if (!args(0).is_string()) {
3178 error(
"MBDynParser: invalid argument type (%s)\n"
3179 "expected string", args(0).type_name().c_str());
3180 return octave_value();
3183 const std::string strKeyWord = args(0).string_value();
3188 bVal = pHP->
IsKeyWord(strKeyWord.c_str());
3190 error(
"%s: IsKeyWord failed", type_name().c_str());
3191 return octave_value();
3194 return octave_value(bVal);
3197 METHOD_DEFINE(MBDynParserInterface, IsArg, args, nargout)
3200 error(
"%s: not connected", type_name().c_str());
3201 return octave_value();
3204 if (args.length() != 0) {
3205 error(
"%s: invalid number of arguments %ld\n"
3206 "no arguments expected",
3207 type_name().c_str(),
3208 long(args.length()));
3209 return octave_value();
3212 return octave_value(pHP->
IsArg());
3215 METHOD_DEFINE(MBDynParserInterface, IsStringWithDelims, args, nargout)
3218 error(
"%s: not connected", type_name().c_str());
3219 return octave_value();
3222 if (args.length() > 1) {
3223 error(
"%s: invalid number of arguments %ld\n"
3224 "one argument expected",
3225 type_name().c_str(),
3226 long(args.length()));
3227 return octave_value();
3232 if (args.length() >= 1) {
3233 if (!args(0).is_string()) {
3234 error(
"%s: invalid argument type %s\n"
3236 type_name().c_str(),
3237 args(0).type_name().c_str());
3238 return octave_value();
3241 const std::string strDelims(args(0).string_value());
3243 if (!GetDelimsFromString(strDelims, delims)) {
3244 error(
"%s: invalid argument %s",
3245 type_name().c_str(),
3247 return octave_value();
3254 METHOD_DEFINE(MBDynParserInterface, GetReal, args, nargout)
3257 error(
"MBDynParser: not connected");
3258 return octave_value();
3263 if (args.length() > 1) {
3264 error(
"MBDynParser: invalid number of arguments %ld\n"
3265 "expected 0-1 arguments",
long(args.length()));
3266 return octave_value();
3267 }
else if (args.length() >= 1) {
3268 if (!args(0).is_real_scalar()) {
3269 error(
"MBDynParser: invalid argument type (%s)\n"
3270 "expected real scalar", args(0).type_name().c_str());
3271 return octave_value();
3273 dDefVal = args(0).scalar_value();
3281 error(
"%s: GetReal failed", type_name().c_str());
3282 return octave_value();
3285 return octave_value(dVal);
3288 METHOD_DEFINE(MBDynParserInterface, GetInt, args, nargout)
3291 error(
"%s: not connected", type_name().c_str());
3292 return octave_value();
3297 if (args.length() > 1) {
3298 error(
"%s: invalid number of arguments %ld\n"
3299 "expected 0-1 arguments",
3300 type_name().c_str(),
3301 long(args.length()));
3302 return octave_value();
3303 }
else if (args.length() >= 1) {
3304 if (!args(0).is_integer_type() && args(0).is_scalar_type()) {
3305 error(
"%s: invalid argument type (%s)\n"
3306 "expected integer scalar",
3307 type_name().c_str(),
3308 args(0).type_name().c_str());
3309 return octave_value();
3311 iDefVal = args(0).int_value();
3317 iVal = pHP->
GetInt(iDefVal);
3319 error(
"%s: GetInt failed", type_name().c_str());
3320 return octave_value();
3323 return octave_value(iVal);
3326 METHOD_DEFINE(MBDynParserInterface, GetBool, args, nargout)
3329 error(
"%s: not connected", type_name().c_str());
3330 return octave_value();
3335 if (args.length() > 1) {
3336 error(
"%s: invalid number of arguments %ld\n"
3337 "expected 0-1 arguments",
3338 type_name().c_str(),
3339 long(args.length()));
3340 return octave_value();
3341 }
else if (args.length() >= 1) {
3342 if (!args(0).is_bool_scalar()) {
3343 error(
"%s: invalid argument type (%s)\n"
3344 "expected bool scalar",
3345 type_name().c_str(),
3346 args(0).type_name().c_str());
3347 return octave_value();
3349 bDefVal = args(0).bool_value();
3357 error(
"%s: GetBool failed", type_name().c_str());
3358 return octave_value();
3361 return octave_value(bVal);
3364 METHOD_DEFINE(MBDynParserInterface, GetYesNoOrBool, args, nargout)
3367 error(
"%s: not connected", type_name().c_str());
3368 return octave_value();
3373 if (args.length() > 1) {
3374 error(
"%s: invalid number of arguments %ld\n"
3375 "expected 0-1 arguments",
3376 type_name().c_str(),
3377 long(args.length()));
3378 return octave_value();
3379 }
else if (args.length() >= 1) {
3380 if (!args(0).is_bool_scalar()) {
3381 error(
"%s: invalid argument type (%s)\n"
3382 "expected bool scalar",
3383 type_name().c_str(),
3384 args(0).type_name().c_str());
3385 return octave_value();
3387 bDefVal = args(0).bool_value();
3395 error(
"%s: GetYesNoOrBool failed", type_name().c_str());
3396 return octave_value();
3399 return octave_value(bVal);
3402 METHOD_DEFINE(MBDynParserInterface, GetString, args, nargout)
3405 error(
"%s: not connected", type_name().c_str());
3406 return octave_value();
3409 std::string strDefVal;
3411 if (args.length() > 1) {
3412 error(
"%s: invalid number of arguments %ld\n"
3413 "expected 0-1 arguments",
3414 type_name().c_str(),
3415 long(args.length()));
3416 return octave_value();
3417 }
else if (args.length() >= 1) {
3418 if (!args(0).is_string()) {
3419 error(
"%s: invalid argument type (%s)\n"
3421 type_name().c_str(),
3422 args(0).type_name().c_str());
3423 return octave_value();
3425 strDefVal = args(0).string_value();
3433 error(
"%s: GetString failed", type_name().c_str());
3434 return octave_value();
3437 return octave_value(strVal);
3440 METHOD_DEFINE(MBDynParserInterface, GetStringWithDelims, args, nargout)
3443 error(
"%s: not connected", type_name().c_str());
3444 return octave_value();
3447 std::string strDelims;
3449 if (args.length() > 2) {
3450 error(
"%s: invalid number of arguments %ld\n"
3451 "expected 0-2 arguments",
3452 type_name().c_str(),
3453 long(args.length()));
3454 return octave_value();
3459 if (args.length() >= 1) {
3460 if (!args(0).is_string()) {
3461 error(
"%s: invalid argument type (%s)\n"
3463 type_name().c_str(),
3464 args(0).type_name().c_str());
3465 return octave_value();
3468 std::string strDelims(args(0).string_value());
3470 if (!GetDelimsFromString(strDelims, delims)) {
3471 error(
"%s: invalid argument %s",
3472 type_name().c_str(),
3474 return octave_value();
3478 bool bEscape =
true;
3480 if (args.length() >= 2) {
3481 if (!args(1).is_bool_scalar()) {
3482 error(
"%s: invalid argument type (%s)\n"
3484 type_name().c_str(),
3485 args(1).type_name().c_str());
3486 return octave_value();
3489 bEscape = args(1).bool_value();
3497 error(
"%s: GetStringWithDelims failed", type_name().c_str());
3498 return octave_value();
3501 return octave_value(strVal);
3504 METHOD_DEFINE(MBDynParserInterface, GetPosRel, args, nargout)
3507 error(
"%s: not connected", type_name().c_str());
3508 return octave_value();
3511 if (args.length() != 1) {
3512 error(
"%s: invalid number of arguments\n"
3513 "expected one argument", type_name().c_str());
3515 return octave_value();
3521 return octave_value();
3529 error(
"%s: GetPosRel failed", type_name().c_str());
3530 return octave_value();
3535 if (!GetInterface()->ConvertMBDynToOctave(mbX, octX)) {
3536 error(
"%s: could not convert data", type_name().c_str());
3537 return octave_value();
3543 METHOD_DEFINE(MBDynParserInterface, GetRotRel, args, nargout)
3546 error(
"%s: not connected", type_name().c_str());
3547 return octave_value();
3550 if (args.length() != 1) {
3551 error(
"%s: invalid number of arguments\n"
3552 "expected one argument", type_name().c_str());
3554 return octave_value();
3560 return octave_value();
3568 error(
"%s: GetRotRel failed", type_name().c_str());
3569 return octave_value();
3574 if (!GetInterface()->ConvertMBDynToOctave(mbR, octR)) {
3575 error(
"%s: could not convert data", type_name().c_str());
3576 return octave_value();
3582 METHOD_DEFINE(MBDynParserInterface, GetValue, args, nargout)
3585 error(
"%s: not connected", type_name().c_str());
3586 return octave_value();
3589 if (args.length() > 1) {
3590 error(
"%s: invalid number of arguments\n"
3591 "expected 0-1 arguments", type_name().c_str());
3592 return octave_value();
3597 if (args.length() >= 1) {
3598 if (!GetInterface()->ConvertOctaveToMBDyn(args(0), mbDefValue)) {
3599 error(
"%s: could not convert octave data type %s to MBDyn",
3600 type_name().c_str(),
3601 args(0).type_name().c_str());
3602 return octave_value();
3609 mbValue = pHP->
GetValue(mbDefValue);
3611 error(
"%s: GetValue failed", type_name().c_str());
3612 return octave_value();
3615 octave_value octValue;
3617 if (!GetInterface()->ConvertMBDynToOctave(mbValue, octValue)) {
3618 error(
"%s: could not convert data type %s into octave value",
3619 type_name().c_str(),
3626 METHOD_DEFINE(MBDynParserInterface, GetLineData, args, nargout)
3629 error(
"%s: not connected", type_name().c_str());
3630 return octave_value();
3633 if (args.length() != 0) {
3634 error(
"%s: invalid number of arguments\n"
3635 "expected no argument", type_name().c_str());
3637 return octave_value();
3640 std::ostringstream os;
3644 return octave_value(os.str());
3647 const StructDispNode* MBDynParserInterface::GetStructNode(
const octave_value& arg)
const
3649 const StructDispNodeBaseInterface*
const pNodeInterface =
3650 dynamic_cast<const StructDispNodeBaseInterface*
>(&arg.get_rep());
3652 if (pNodeInterface == 0) {
3653 error(
"%s: invalid argument type (%s)\n"
3654 "expected StructNode or StructDispNode",
3655 type_name().c_str(),
3656 arg.type_name().c_str());
3664 error(
"%s: not connected", pNodeInterface->type_name().c_str());
3671 bool MBDynParserInterface::GetDelimsFromString(
const std::string& strDelims,
HighParser::Delims& delims)
3673 const int count =
sizeof(mbStringDelims) /
sizeof(mbStringDelims[0]);
3675 for (
int i = 0; i <
count; ++i) {
3676 if (strDelims == mbStringDelims[i].name) {
3677 delims = mbStringDelims[i].value;
3687 METHOD_DEFINE(MBDynParserInterface, GetDriveCaller, args, nargout)
3690 error(
"%s: not connected", type_name().c_str());
3691 return octave_value();
3694 if (args.length() != 0) {
3695 error(
"%s: invalid number of arguments\n"
3696 "expected no argument", type_name().c_str());
3698 return octave_value();
3706 error(
"%s: GetDriveCaller failed", type_name().c_str());
3707 return octave_value();
3710 DriveCallerInterface* pInterface =
new DriveCallerInterface(GetInterface(), pDC);
3712 return octave_value(pInterface);
3715 BEGIN_METHOD_TABLE(MBDynParserInterface, MBDynInterface)
3716 METHOD_DISPATCH(MBDynParserInterface, IsKeyWord)
3717 METHOD_DISPATCH(MBDynParserInterface, IsArg)
3718 METHOD_DISPATCH(MBDynParserInterface, IsStringWithDelims)
3719 METHOD_DISPATCH(MBDynParserInterface, GetReal)
3720 METHOD_DISPATCH(MBDynParserInterface, GetInt)
3721 METHOD_DISPATCH(MBDynParserInterface, GetBool)
3722 METHOD_DISPATCH(MBDynParserInterface, GetYesNoOrBool)
3723 METHOD_DISPATCH(MBDynParserInterface, GetString)
3724 METHOD_DISPATCH(MBDynParserInterface, GetStringWithDelims)
3725 METHOD_DISPATCH(MBDynParserInterface, GetValue)
3726 METHOD_DISPATCH(MBDynParserInterface, GetPosRel)
3727 METHOD_DISPATCH(MBDynParserInterface, GetRotRel)
3728 METHOD_DISPATCH(MBDynParserInterface, GetLineData)
3729 METHOD_DISPATCH(MBDynParserInterface, GetDriveCaller)
3732 DEFINE_OCTAVE_ALLOCATOR(MBDynParserInterface);
3733 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(MBDynParserInterface, "
MBDynParser", "MBDynParser");
3735 DriveCallerInterface::DriveCallerInterface(OctaveInterface* pInterface, const
DriveCaller* pDC)
3736 :MBDynInterface(pInterface), DC(pDC)
3741 DriveCallerInterface::~DriveCallerInterface()
3747 METHOD_DEFINE(DriveCallerInterface, dGet, args, nargout)
3751 if (!DC.pGetDriveCaller()) {
3752 error(
"%s: not connected", type_name().c_str());
3756 switch (args.length())
3766 if (!GetInterface()->ConvertOctaveToMBDyn(args(0), x)) {
3767 error(
"%s: invalid argument type %s", type_name().c_str(), args(0).type_name().c_str());
3775 error(
"%s: invalid number of arguments\n"
3776 "expected zero or one argument", type_name().c_str());
3782 METHOD_DEFINE(DriveCallerInterface, dGetP, args, nargout)
3786 if (!DC.pGetDriveCaller()) {
3787 error(
"%s: not connected", type_name().c_str());
3791 if (!DC.pGetDriveCaller()->bIsDifferentiable()) {
3792 error(
"%s: drive caller(%d %s) is not differentiable", type_name().c_str(), DC.pGetDriveCaller()->GetLabel(), DC.pGetDriveCaller()->GetName().c_str());
3796 switch (args.length())
3806 if (!GetInterface()->ConvertOctaveToMBDyn(args(0), x)) {
3807 error(
"%s: invalid argument type %s", type_name().c_str(), args(0).type_name().c_str());
3815 error(
"%s: invalid number of arguments\n"
3816 "expected zero or one argument", type_name().c_str());
3822 BEGIN_METHOD_TABLE(DriveCallerInterface, MBDynInterface)
3823 METHOD_DISPATCH(DriveCallerInterface, dGet)
3824 METHOD_DISPATCH(DriveCallerInterface, dGetP)
3827 DEFINE_OCTAVE_ALLOCATOR(DriveCallerInterface);
3828 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(DriveCallerInterface, "
DriveCaller", "DriveCaller");
3830 OctaveDriveCaller::OctaveDriveCaller(const std::
string& strFunc, OctaveInterface* pInterface,
int iFlags, const octave_value_list& args)
3834 pInterface(pInterface),
3837 TRACE(
"constructor");
3838 TRACE(
"strFunc=" << strFunc);
3839 TRACE(
"iFlags=" << iFlags);
3842 OctaveDriveCaller::~OctaveDriveCaller(
void)
3844 TRACE(
"destructor");
3848 OctaveDriveCaller::pCopy(
void)
const
3850 return new OctaveDriveCaller(strFunc, pInterface, iFlags, args);
3854 OctaveDriveCaller::Restart(std::ostream& out)
const
3856 return out <<
"octave, \"" << strFunc <<
"\"";
3860 OctaveDriveCaller::dGet(
const doublereal& dVar)
const
3862 return pInterface->EvalScalarFunction(strFunc, MakeArgList(dVar), iFlags);
3866 OctaveDriveCaller::dGet(
void)
const
3868 return dGet(pInterface->GetDataManager()->dGetTime());
3872 OctaveDriveCaller::bIsDifferentiable(
void)
const
3874 return pInterface->HaveADPackage();
3878 OctaveDriveCaller::dGetP(
const doublereal& dVar)
const
3880 return pInterface->EvalScalarFunctionDerivative(strFunc, MakeArgList(dVar), iFlags);
3884 OctaveDriveCaller::dGetP(
void)
const
3886 if (!bIsDifferentiable()) {
3890 return dGetP(pInterface->GetDataManager()->dGetTime());
3893 octave_value_list OctaveDriveCaller::MakeArgList(
doublereal dVar)
const
3895 return pInterface->MakeArgList(dVar, args, iFlags);
3899 OctaveTplDriveCaller<T>::OctaveTplDriveCaller(
const std::string& strFunction, OctaveInterface* pInterface,
int iFlags,
const octave_value_list& args)
3900 :strFunction(strFunction),
3901 pInterface(pInterface),
3905 TRACE(
"constructor");
3909 OctaveTplDriveCaller<T>::~OctaveTplDriveCaller(
void)
3911 TRACE(
"destructor");
3918 return new OctaveTplDriveCaller(strFunction, pInterface, iFlags, args);
3922 std::ostream& OctaveTplDriveCaller<T>::Restart(std::ostream& out)
const
3928 std::ostream& OctaveTplDriveCaller<T>::Restart_int(std::ostream& out)
const
3934 T OctaveTplDriveCaller<T>::Get(
const doublereal& dVar)
const
3937 pInterface->EvalMatrixFunction(strFunction, X, MakeArgList(dVar), iFlags);
3942 T OctaveTplDriveCaller<T>::Get(
void)
const
3944 return Get(pInterface->GetDataManager()->dGetTime());
3948 bool OctaveTplDriveCaller<T>::bIsDifferentiable(
void)
const
3950 return pInterface->HaveADPackage();
3954 T OctaveTplDriveCaller<T>::GetP(
void)
const
3956 const doublereal t = pInterface->GetDataManager()->dGetTime();
3958 pInterface->EvalMatrixFunctionDerivative(strFunction, XP, MakeArgList(t), iFlags);
3963 int OctaveTplDriveCaller<T>::getNDrives(
void)
const
3969 octave_value_list OctaveTplDriveCaller<T>::MakeArgList(
doublereal dVar)
const
3971 return pInterface->MakeArgList(dVar, args, iFlags);
3978 OctaveFunctionDCR::Read(pDM, HP);
3980 return new OctaveTplDriveCaller<T>(GetFunction(), GetInterface(), GetFlags(), GetArgs());
3983 DerivativeDriveCaller::DerivativeDriveCaller(
DriveCaller* pDriveCaller)
3986 TRACE(
"constructor");
3990 DerivativeDriveCaller::~DerivativeDriveCaller(
void)
3992 TRACE(
"destructor");
3995 DriveCaller* DerivativeDriveCaller::pCopy(
void)
const
3997 return new DerivativeDriveCaller(pDriveCaller.pGetDriveCaller()->
pCopy());
4000 std::ostream& DerivativeDriveCaller::Restart(std::ostream& out)
const
4007 return pDriveCaller.
dGetP(dVar);
4010 doublereal DerivativeDriveCaller::dGet(
void)
const
4012 return pDriveCaller.
dGetP();
4015 bool DerivativeDriveCaller::bIsDifferentiable(
void)
const
4025 doublereal DerivativeDriveCaller::dGetP(
void)
const
4030 OctaveScalarFunction::OctaveScalarFunction(
const std::string& strFunc, OctaveInterface* pInterface,
int iFlags,
const octave_value_list& args)
4032 pInterface(pInterface),
4039 OctaveScalarFunction::~OctaveScalarFunction(
void)
4046 return pInterface->EvalScalarFunction(strFunc, MakeArgList(x), iFlags);
4052 silent_cerr(
"octave scalar function \"" << strFunc <<
"\" derivative of order " << order <<
" not supported" << std::endl);
4056 return pInterface->EvalScalarFunctionDerivative(strFunc, MakeArgList(t), iFlags);
4059 octave_value_list OctaveScalarFunction::MakeArgList(
doublereal dVar)
const
4061 return pInterface->MakeArgList(dVar, args, iFlags);
4064 OctaveConstitutiveLawBase::OctaveConstitutiveLawBase(
const std::string& strClass, OctaveInterface* pInterface,
int iFlags)
4065 : strClass(strClass),
4066 pInterface(pInterface),
4072 bool OctaveConstitutiveLawBase::bHaveMethod(
const std::string& strName)
const
4074 return GetInterface()->bHaveMethod(octObject, strClass, strName);
4077 const std::string OctaveConstitutiveLawBase::strGetConstLawType(
"GetConstLawType");
4078 const std::string OctaveConstitutiveLawBase::strUpdate(
"Update");
4080 template <
class T,
class Tder>
4081 OctaveConstitutiveLaw<T, Tder>::OctaveConstitutiveLaw(
const std::string& strClass, OctaveInterface* pInterface,
int iFlags)
4082 : OctaveConstitutiveLawBase(strClass, pInterface, iFlags),
4085 octave_value_list args(GetInterface()->GetDataManagerInterface());
4086 args.append(GetInterface()->GetMBDynParserInterface());
4088 const int flags = GetFlags() | OctaveInterface::UPDATE_OCTAVE_VARIABLES;
4090 octave_value_list ans = GetInterface()->EvalFunction(GetClass(), args, 1, flags);
4092 ASSERT(ans.length() == 1);
4096 if (!octObject.is_object()) {
4097 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel() <<
"): result of constructor ("
4098 << ans(0).type_name() <<
") is not an object at line "
4099 << GetInterface()->GetMBDynParser()->GetLineData() << std::endl);
4103 if (!bHaveMethod(strGetConstLawType)) {
4104 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4105 <<
"): method " << GetClass() <<
"." << strGetConstLawType
4106 <<
" is undefined" << std::endl);
4110 if (!bHaveMethod(strUpdate)) {
4111 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4112 <<
"): method " << GetClass() <<
"." << strUpdate
4113 <<
" is undefined" << std::endl);
4118 template <
class T,
class Tder>
4119 OctaveConstitutiveLaw<T, Tder>::~OctaveConstitutiveLaw(
void) {
4123 template <
class T,
class Tder>
4133 static const struct {
4142 static const int count =
sizeof(types)/
sizeof(types[0]);
4144 octave_value_list args(octObject);
4145 const octave_value_list ans = GetInterface()->EvalFunction(strGetConstLawType, args, 1, GetFlags());
4147 ASSERT(ans.length() == 1);
4149 if (!ans(0).is_string()) {
4150 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4151 <<
"): " << GetClass() <<
"." << strGetConstLawType
4152 <<
" returned a invalid data type (" << ans(0).type_name() << std::endl
4153 <<
"expected string" << std::endl);
4158 const std::string strCLType(ans(0).string_value());
4160 for (
int i = 0; i <
count; ++i) {
4161 if (strCLType == types[i].name) {
4162 clType = types[i].value;
4167 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4168 <<
"): " << GetClass() <<
"." << strGetConstLawType
4169 <<
" returned a invalid value (" << strCLType <<
")" << std::endl);
4174 template <
class T,
class Tder>
4178 typedef OctaveConstitutiveLaw<T, Tder> cl;
4183 template <
class T,
class Tder>
4184 std::ostream& OctaveConstitutiveLaw<T, Tder>::Restart(std::ostream& out)
const {
4185 return out <<
"# octave constitutive law not implemented" << std::endl;
4188 template <
class T,
class Tder>
4189 void OctaveConstitutiveLaw<T, Tder>::Update(
const T& mbEps,
const T& mbEpsPrime) {
4191 octave_value octEps, octEpsPrime;
4193 if (!GetInterface()->ConvertMBDynToOctave(mbEps, octEps)) {
4194 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4195 <<
"): failed to convert MBDyn data type to octave_value" << std::endl);
4201 if (!GetInterface()->ConvertMBDynToOctave(mbEpsPrime, octEpsPrime)) {
4202 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4203 <<
"): failed to convert MBDyn data type to octave_value" << std::endl);
4209 octave_value_list args(octObject);
4210 args.append(octEps);
4211 args.append(octEpsPrime);
4213 const octave_value_list ans = GetInterface()->EvalFunction(strUpdate, args, 4, GetFlags());
4215 ASSERT(ans.length() == 4);
4217 if (!(ans(0).is_object() && ans(0).type_id() == octObject.type_id())) {
4218 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4219 <<
"): output argument 1 is not an instance of " << octObject.type_name() << std::endl);
4226 if (!((ans(1).is_real_matrix() || ans(1).is_real_scalar()) && ans(1).columns() == 1)) {
4227 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4228 <<
"): data type of output argument F is invalid (" << ans(1).type_name() <<
")" << std::endl
4229 <<
"expected real vector" << std::endl);
4234 const ColumnVector octF(ans(1).column_vector_value());
4236 if (!(ans(2).is_real_matrix() || ans(2).is_real_scalar())) {
4237 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4238 <<
"): data type of output argument FDE is invalid (" << ans(2).type_name() <<
")" << std::endl
4239 <<
"expected real matrix" << std::endl);
4244 const Matrix octFDE(ans(2).matrix_value());
4246 if (!(ans(3).is_real_matrix() || ans(3).is_real_scalar())) {
4247 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4248 <<
"): data type of output argument FDEPrime is invalid (" << ans(3).type_name() <<
")" << std::endl
4249 <<
"expected real matrix" << std::endl);
4254 const Matrix octFDEPrime(ans(3).matrix_value());
4256 Base_t::Epsilon = mbEps;
4257 Base_t::EpsilonPrime = mbEpsPrime;
4259 if (!GetInterface()->ConvertOctaveToMBDyn(octF, Base_t::F)) {
4260 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4261 <<
"): data type of output argument F is invalid "
4262 << octF.rows() <<
"x" << octF.columns() <<
" (" << ans(1).type_name() <<
")" << std::endl);
4267 if (!GetInterface()->ConvertOctaveToMBDyn(octFDE, Base_t::FDE)) {
4268 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4269 <<
"): data type of output argument FDE is invalid "
4270 << octFDE.rows() <<
"x" << octFDE.columns() <<
" (" << ans(2).type_name() <<
")" << std::endl);
4275 if (!GetInterface()->ConvertOctaveToMBDyn(octFDEPrime, Base_t::FDEPrime)) {
4276 silent_cerr(
"octave constitutive law(" << Base_t::GetLabel()
4277 <<
"): data type of output argument FDEPrime is invalid "
4278 << octFDEPrime.rows() <<
"x" << octFDEPrime.columns() <<
" (" << ans(3).type_name() <<
")" << std::endl);
4284 OctaveBaseDCR::OctaveBaseDCR()
4285 :pInterface(0), iFlags(OctaveInterface::DEFAULT_CALL_FLAGS)
4287 TRACE(
"constructor");
4288 TRACE(
"iFlags=" << iFlags);
4291 OctaveBaseDCR::~OctaveBaseDCR()
4293 TRACE(
"destructor");
4296 pInterface->Destroy();
4302 if (pInterface == 0) {
4303 pInterface = OctaveInterface::CreateInterface(pDM, &HP);
4308 iFlags = OctaveInterface::DEFAULT_CALL_FLAGS;
4311 iFlags |= OctaveInterface::UPDATE_OCTAVE_VARIABLES;
4315 iFlags |= OctaveInterface::UPDATE_MBDYN_VARIABLES;
4319 iFlags |= OctaveInterface::UPDATE_GLOBAL_VARIABLES;
4323 iFlags |= OctaveInterface::PASS_DATA_MANAGER;
4328 pInterface->AddEmbedFileName(sFileInfo.
sFileName);
4331 if (HP.
IsKeyWord(
"octave" "search" "path")) {
4334 pedantic_cout(
"octave: adding \"" << path <<
"\" to octave search path at line " << HP.
GetLineData() << std::endl);
4335 if (!pInterface->AddOctaveSearchPath(path)) {
4336 silent_cerr(
"octave error: addpath(\"" << path <<
"\") failed at line " << HP.
GetLineData() << std::endl);
4342 TRACE(
"strFunction=" << strFunction);
4343 TRACE(
"iFlags=" << iFlags);
4350 OctaveBaseDCR::Read(pDM, HP, bDeferred);
4354 while (iNumArgs-- > 0) {
4356 octave_value octVal;
4358 if (!GetInterface()->ConvertMBDynToOctave(mbVal, octVal)) {
4359 silent_cerr(
"octave error: could not convert MBDyn data type " << mbVal.GetTypeName() <<
" to octave" << std::endl);
4363 args.append(octVal);
4371 OctaveFunctionDCR::Read(pDM, HP, bDeferred);
4373 return new OctaveDriveCaller(GetFunction(), GetInterface(), GetFlags(), GetArgs());
4382 silent_cerr(
"DriveCaller " << pDriveCaller->
GetLabel() <<
" " << pDriveCaller->
GetName() <<
" is not differentiable at line " << HP.
GetLineData() << std::endl);
4384 delete pDriveCaller;
4389 return new DerivativeDriveCaller(pDriveCaller);
4396 OctaveFunctionDCR::Read(pDM, HP);
4397 return new OctaveScalarFunction(GetFunction(), GetInterface(), GetFlags(), GetArgs());
4401 const std::string OctaveElement::strWorkSpaceDim(
"WorkSpaceDim");
4402 const std::string OctaveElement::striGetNumDof(
"iGetNumDof");
4403 const std::string OctaveElement::strAssRes(
"AssRes");
4404 const std::string OctaveElement::strAssJac(
"AssJac");
4405 const std::string OctaveElement::strUpdate(
"Update");
4406 const std::string OctaveElement::strSetValue(
"SetValue");
4407 const std::string OctaveElement::striGetInitialNumDof(
"iGetInitialNumDof");
4408 const std::string OctaveElement::strSetInitialValue(
"SetInitialValue");
4409 const std::string OctaveElement::strInitialAssRes(
"InitialAssRes");
4410 const std::string OctaveElement::strInitialAssJac(
"InitialAssJac");
4411 const std::string OctaveElement::strInitialWorkSpaceDim(
"InitialWorkSpaceDim");
4412 const std::string OctaveElement::strGetDofType(
"GetDofType");
4413 const std::string OctaveElement::strGetEqType(
"GetEqType");
4414 const std::string OctaveElement::strAfterConvergence(
"AfterConvergence");
4415 const std::string OctaveElement::striGetNumPrivData(
"iGetNumPrivData");
4416 const std::string OctaveElement::striGetPrivDataIdx(
"iGetPrivDataIdx");
4417 const std::string OctaveElement::strdGetPrivData(
"dGetPrivData");
4418 const std::string OctaveElement::striGetNumConnectedNodes(
"iGetNumConnectedNodes");
4419 const std::string OctaveElement::strGetConnectedNodes(
"GetConnectedNodes");
4420 const std::string OctaveElement::strOutput(
"Output");
4421 const std::string OctaveElement::strDescribeDof(
"DescribeDof");
4422 const std::string OctaveElement::strDescribeEq(
"DescribeEq");
4423 const std::string OctaveElement::strAfterPredict(
"AfterPredict");
4424 const std::string OctaveElement::strRestart(
"Restart");
4426 OctaveElement::OctaveElement(
4427 unsigned uLabel,
const DofOwner *pDO,
4431 haveMethod(HAVE_DEFAULT)
4435 silent_cout(
"Module: octave\n"
4448 X =
new ConstVectorHandlerInterface(GetInterface());
4449 XP =
new ConstVectorHandlerInterface(GetInterface());
4450 mbdObject =
new OctaveElementInterface(GetInterface(),
this);
4451 OS =
new OStreamInterface(GetInterface());
4453 octave_value_list args(mbdObject);
4455 args.append(GetInterface()->GetDataManagerInterface());
4456 args.append(GetInterface()->GetMBDynParserInterface());
4458 const int flags = OctaveInterface::UPDATE_OCTAVE_VARIABLES;
4462 octave_value_list ans = GetInterface()->EvalFunction(GetClass(), args, 1, flags);
4466 ASSERT(ans.length() == 1);
4470 if (!octObject.is_object()) {
4471 silent_cerr(
"octave(" << GetLabel() <<
"): result of constructor ("
4472 << ans(0).type_name() <<
") is not an object at line "
4479 if (bHaveMethod(strAssJac)) {
4480 haveMethod |= HAVE_JACOBIAN;
4482 pedantic_cerr(
"octave waring: method " << strAssJac <<
" not found in class " << GetClass() << std::endl);
4485 if (bHaveMethod(strUpdate)) {
4486 haveMethod |= HAVE_UPDATE;
4488 pedantic_cerr(
"octave warning: method " << strUpdate <<
" not found in class " << GetClass() << std::endl);
4491 if (bHaveMethod(strAfterConvergence)) {
4492 haveMethod |= HAVE_AFTER_CONVERGENCE;
4494 pedantic_cerr(
"octave warning: method " << strAfterConvergence <<
" not found in class " << GetClass() << std::endl);
4497 if (bHaveMethod(strSetValue)) {
4498 haveMethod |= HAVE_SET_VALUE;
4500 pedantic_cerr(
"octave warning: method " << strSetValue <<
" not found in class " << GetClass() << std::endl);
4503 if (bHaveMethod(striGetNumDof)) {
4504 if (!bHaveMethod(strGetDofType)) {
4505 silent_cerr(
"octave error: method " << strGetDofType <<
" not found in class " << GetClass() << std::endl);
4509 if (!bHaveMethod(strGetEqType)) {
4510 silent_cerr(
"octave error: method " << strGetEqType <<
" not found in class " << GetClass() << std::endl);
4514 haveMethod |= HAVE_PRIVATE_DOF;
4516 if (bHaveMethod(strDescribeDof)) {
4517 haveMethod |= HAVE_DESCRIBE_DOF;
4520 if (bHaveMethod(strDescribeEq)) {
4521 haveMethod |= HAVE_DESCRIBE_EQ;
4524 pedantic_cerr(
"octave warning: method " << striGetNumDof <<
" not found in class " << GetClass() << std::endl);
4527 if (bHaveMethod(striGetNumPrivData)) {
4528 if (!bHaveMethod(striGetPrivDataIdx)) {
4529 silent_cerr(
"octave error: method " << striGetPrivDataIdx <<
" not found in class " << GetClass() << std::endl);
4533 if (!bHaveMethod(strdGetPrivData)) {
4534 silent_cerr(
"octave error: method " << strdGetPrivData <<
" not found in class " << GetClass() << std::endl);
4538 haveMethod |= HAVE_PRIVATE_DATA;
4540 pedantic_cerr(
"octave warning: method " << striGetNumPrivData <<
" not found in class " << GetClass() << std::endl);
4543 if (bHaveMethod(striGetNumConnectedNodes)) {
4544 if (!bHaveMethod(strGetConnectedNodes)) {
4545 silent_cerr(
"octave error: method " << strGetConnectedNodes <<
" not found in class " << GetClass() << std::endl);
4549 haveMethod |= HAVE_CONNECTED_NODES;
4551 pedantic_cerr(
"octave warning: method " << striGetNumConnectedNodes <<
" not found in class " << GetClass() << std::endl);
4554 if (bHaveMethod(strInitialAssRes)) {
4555 if (!bHaveMethod(strInitialAssJac)) {
4556 silent_cerr(
"octave error: method " << strInitialAssJac <<
" not found in class " << GetClass() << std::endl);
4560 if (!bHaveMethod(strInitialWorkSpaceDim)) {
4561 silent_cerr(
"octave error: method " << strInitialWorkSpaceDim <<
" not found in class " << GetClass() << std::endl);
4565 if (!bHaveMethod(striGetInitialNumDof)) {
4566 silent_cerr(
"octave error: method " << striGetInitialNumDof <<
" not found in class " << GetClass() << std::endl);
4570 haveMethod |= HAVE_INITIAL_ASSEMBLY;
4572 if (bHaveMethod(strSetInitialValue)) {
4573 haveMethod |= HAVE_SET_INITIAL_VALUE;
4575 pedantic_cerr(
"octave warning: method " << strSetInitialValue <<
" not found in class " << GetClass() << std::endl);
4578 pedantic_cerr(
"octave warning: method " << strInitialAssRes
4579 <<
" not found in class " << GetClass() << std::endl
4580 <<
" initial assembly has been disabled" << std::endl);
4583 if (bHaveMethod(strAfterPredict)) {
4584 haveMethod |= HAVE_AFTER_PREDICT;
4586 pedantic_cerr(
"octave warning: method " << strAfterPredict <<
" not found in class " << GetClass() << std::endl);
4589 if (bHaveMethod(strRestart)) {
4590 haveMethod |= HAVE_RESTART;
4592 pedantic_cerr(
"octave warning: method " << strRestart <<
" not found in class " << GetClass() << std::endl);
4595 if (bHaveMethod(strOutput)) {
4596 haveMethod |= HAVE_OUTPUT;
4598 pedantic_cerr(
"octave warning: method " << strOutput <<
" not found in class " << GetClass() << std::endl);
4602 OctaveElement::~OctaveElement(
void)
4614 if (!(haveMethod & HAVE_OUTPUT)) {
4620 octave_value_list args(octObject);
4623 GetInterface()->EvalFunction(strOutput, args, 0, GetFlags());
4629 OctaveElement::WorkSpaceDim(
integer* piNumRows,
integer* piNumCols)
const
4631 octave_value_list args(octObject);
4633 octave_value_list ans = GetInterface()->EvalFunction(strWorkSpaceDim, args, 2, GetFlags());
4635 ASSERT(ans.length() == 2);
4637 if (!(ans(0).is_scalar_type()
4638 && ans(0).is_integer_type()
4639 && ans(1).is_scalar_type()
4640 && ans(1).is_integer_type())) {
4641 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strWorkSpaceDim
4642 <<
" must return two integer values\nreturned(" << ans(0).type_name() <<
", " << ans(1).type_name() <<
")" << std::endl);
4646 *piNumRows =
static_cast<int32_t
>(ans(0).int32_scalar_value());
4647 *piNumCols =
static_cast<int32_t
>(ans(1).int32_scalar_value());
4656 if ( !(haveMethod & HAVE_JACOBIAN) ) {
4663 WorkSpaceDim(&iNumRows, &iNumCols);
4665 octave_value_list args(octObject);
4668 XP->Set(&XPrimeCurr);
4670 args.append(octave_value(dCoef));
4674 const octave_value_list ans = GetInterface()->EvalFunction(strAssJac, args, 5, GetFlags() | OctaveInterface::OPTIONAL_OUTPUT_ARGS);
4676 ASSERT(ans.length() <= 5);
4681 if (ans.length() >= 5) {
4682 if (!(ans(4).is_object() && ans(4).type_id() == octObject.type_id())) {
4683 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes <<
": output argument 5 is not an instance of " << octObject.type_name() << std::endl);
4689 return AssMatrix(WorkMatVar, ans,
false);
4698 int iNumRows, iNumCols;
4700 WorkSpaceDim(&iNumRows, &iNumCols);
4705 XP->Set(&XPrimeCurr);
4707 octave_value_list args(octObject);
4708 args.append(octave_value(dCoef));
4712 octave_value_list ans = GetInterface()->EvalFunction(strAssRes, args, 3, GetFlags() | OctaveInterface::OPTIONAL_OUTPUT_ARGS);
4717 ASSERT(ans.length() <= 3);
4719 if (ans.length() < 2) {
4720 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes <<
": expected 2-3 output arguments" << std::endl);
4724 ASSERT(ans.length() >= 2);
4725 if (!(ans(0).is_matrix_type()
4726 && ans(0).is_real_type()
4727 && ans(0).columns() == 1)) {
4728 silent_cerr(
"octave(" << GetLabel()
4729 <<
"): function " << GetClass() <<
"." << strAssRes
4730 <<
": output argument f (" << ans(0).type_name()
4731 <<
") must be a real column vector" << std::endl);
4735 const ColumnVector f = ans(0).column_vector_value();
4737 if (!(ans(1).is_integer_type()
4738 && ans(1).is_matrix_type()
4739 && ans(1).columns() == 1)) {
4740 silent_cerr(
"octave(" << GetLabel()
4741 <<
"): function " << GetClass() <<
"." << strAssRes
4742 <<
": output argument ridx (" << ans(1).type_name()
4743 <<
") must be an integer column vector" << std::endl);
4747 const int32NDArray ridx = ans(1).int32_array_value();
4749 if (ridx.length() != iNumRows || f.length() != iNumRows) {
4750 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes
4751 <<
"\nlength(f)=" << f.length()
4752 <<
" length(ridx)=" << ridx.length()
4753 <<
" is not equal to iNumRows=" << iNumRows << std::endl);
4757 const integer iNumDof = GetInterface()->GetDataManager()->iGetNumDofs();
4759 for (octave_idx_type i = 0; i < f.length(); ++i) {
4760 if (
int(ridx(i)) <= 0 ||
int(ridx(i)) > iNumDof) {
4761 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes
4762 <<
": row index " << ridx(i)
4763 <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
4767 WorkVec.
PutItem(i + 1, ridx(i), f(i));
4770 if (ans.length() >= 3) {
4771 if (!(ans(2).is_object() && ans(2).type_id() == octObject.type_id())) {
4772 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes <<
": output argument 3 is not an instance of " << octObject.type_name() << std::endl);
4782 OctaveElement::iGetNumPrivData(
void)
const
4784 if ( !(haveMethod & HAVE_PRIVATE_DATA) ) {
4788 octave_value_list args(octObject);
4790 octave_value_list ans = GetInterface()->EvalFunction(striGetNumPrivData, args, 1, GetFlags());
4792 ASSERT(ans.length() == 1);
4794 if ( !(ans(0).is_integer_type() && ans(0).is_scalar_type()) ) {
4795 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetNumPrivData
4796 <<
" returned (" << ans(0).type_name() <<
")\n"
4797 <<
"expected integer scalar" << std::endl);
4801 const int32_t
iNumPrivData = ans(0).int32_scalar_value();
4803 if ( iNumPrivData < 0 ) {
4804 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetNumPrivData
4805 <<
" returned a negative value" << std::endl);
4813 OctaveElement::iGetPrivDataIdx(
const char *s)
const
4815 if ( !(haveMethod & HAVE_PRIVATE_DATA) ) {
4820 octave_value_list args(octObject);
4821 args.append(octave_value(s));
4823 octave_value_list ans = GetInterface()->EvalFunction(striGetPrivDataIdx, args, 1, GetFlags());
4825 ASSERT(ans.length() == 1);
4827 if ( !(ans(0).is_integer_type() && ans(0).is_scalar_type()) ) {
4828 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetPrivDataIdx
4829 <<
" returned (" << ans(0).type_name() <<
")\n"
4830 <<
"expected integer scalar" << std::endl);
4834 const int32_t iPrivDataIdx = ans(0).int32_scalar_value();
4836 if ( iPrivDataIdx <= 0 ) {
4837 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetPrivDataIdx
4838 <<
" returned a negative or zero value" << std::endl);
4842 return iPrivDataIdx;
4846 OctaveElement::dGetPrivData(
unsigned int i)
const
4848 if ( !(haveMethod & HAVE_PRIVATE_DATA) ) {
4853 octave_value_list args(octObject);
4854 args.append(octave_int32(i));
4856 octave_value_list ans = GetInterface()->EvalFunction(strdGetPrivData, args, 1, GetFlags());
4858 ASSERT(ans.length() == 1);
4860 if ( !(ans(0).is_real_scalar()) ) {
4861 silent_cerr(
"octave error: method " << GetClass() <<
"." << strdGetPrivData
4862 <<
" returned (" << ans(0).type_name() <<
")\n"
4863 <<
"expected real scalar" << std::endl);
4867 return ans(0).scalar_value();
4871 OctaveElement::iGetNumConnectedNodes(
void)
const
4873 if (!(haveMethod & HAVE_CONNECTED_NODES)) {
4877 octave_value_list args(octObject);
4879 octave_value_list ans = GetInterface()->EvalFunction(striGetNumConnectedNodes, args, 1, GetFlags());
4881 ASSERT(ans.length() == 1);
4883 if ( !(ans(0).is_integer_type() && ans(0).is_scalar_type()) ) {
4884 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetNumConnectedNodes
4885 <<
" returned (" << ans(0).type_name() <<
")\n"
4886 <<
"expected integer scalar" << std::endl);
4890 const int32_t iNumConnectedNodes = ans(0).int32_scalar_value();
4892 if ( iNumConnectedNodes < 0 ) {
4893 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetNumConnectedNodes
4894 <<
" returned a negative value" << std::endl);
4898 return iNumConnectedNodes;
4902 OctaveElement::GetConnectedNodes(std::vector<const Node *>& connectedNodes)
const
4904 if (!(haveMethod & HAVE_CONNECTED_NODES)) {
4905 connectedNodes.resize(0);
4909 connectedNodes.resize(iGetNumConnectedNodes());
4911 octave_value_list args(octObject);
4913 octave_value_list ans = GetInterface()->EvalFunction(strGetConnectedNodes, args, 1, GetFlags());
4915 ASSERT(ans.length() == 1);
4917 if (!ans(0).is_cell()) {
4918 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetConnectedNodes
4919 <<
" returned (" << ans(0).type_name() <<
")\n"
4920 <<
"expected cell" << std::endl);
4924 const Cell
nodes(ans(0).cell_value());
4926 if (
size_t(
nodes.length()) != connectedNodes.size()) {
4927 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetConnectedNodes
4928 <<
" returned an object of size " <<
nodes.length()
4929 <<
" whereas " << GetClass() <<
"." << striGetNumConnectedNodes
4930 <<
" returned "<< connectedNodes.size() << std::endl);
4934 for (
size_t i = 0; i < connectedNodes.size(); ++i) {
4935 const NodeInterface* pNode =
dynamic_cast<const NodeInterface*
>(&
nodes(i).get_rep());
4938 silent_cerr(
"octave error: cell(" << i + 1 <<
") (data type " <<
nodes(i).type_name() <<
") is not a node" << std::endl);
4941 connectedNodes[i] = pNode->Get();
4950 if (!(haveMethod & HAVE_SET_VALUE)) {
4954 octave_value_list args(octObject);
4955 args.append(octave_value(
new VectorHandlerInterface(GetInterface(), &X)));
4956 args.append(octave_value(
new VectorHandlerInterface(GetInterface(), &XP)));
4958 GetInterface()->EvalFunction(strSetValue, args, 0, GetFlags());
4961 unsigned int OctaveElement::iGetNumDof(
void)
const
4963 if (!(haveMethod & HAVE_PRIVATE_DOF)) {
4967 octave_value_list args(octObject);
4969 octave_value_list ans = GetInterface()->EvalFunction(striGetNumDof, args, 1, GetFlags());
4971 ASSERT(ans.length() == 1);
4973 if (!(ans(0).is_integer_type() && ans(0).is_scalar_type())){
4974 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetNumDof
4975 <<
" returned (" << ans(0).type_name()
4976 <<
")\nmethod must return an integer" << std::endl);
4980 return static_cast<int32_t
>(ans(0).int32_scalar_value());
4985 if (!(haveMethod & HAVE_PRIVATE_DOF)) {
4990 octave_value_list args(octObject);
4991 args.append(octave_int32(i + 1));
4993 octave_value_list ans = GetInterface()->EvalFunction(strGetDofType, args, 1, GetFlags());
4995 ASSERT(ans.length() == 1);
4997 if (ans(0).is_integer_type() && ans(0).is_scalar_type()) {
4998 const int32_t order =
static_cast<int32_t
>(ans(0).int32_scalar_value());
5005 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetDofType
5006 <<
" returned an illegal value" << std::endl);
5011 if ( !ans(0).is_string() ) {
5012 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetDofType
5013 <<
" returned (" << ans(0).type_name()
5014 <<
")\nmethod must return integer or string values" << std::endl);
5018 const std::string order = ans(0).string_value();
5020 if ( order ==
"ALGEBRAIC" ) {
5022 }
else if ( order ==
"DIFFERENTIAL" ) {
5025 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetDofType
5026 <<
" returned an illegal value (" << order <<
")" << std::endl);
5033 if (!(haveMethod & HAVE_PRIVATE_DOF)) {
5038 octave_value_list args(octObject);
5039 args.append(octave_int32(i + 1));
5041 octave_value_list ans = GetInterface()->EvalFunction(strGetEqType, args, 1, GetFlags());
5043 ASSERT(ans.length() == 1);
5045 if (ans(0).is_integer_type() && ans(0).is_scalar_type()) {
5046 const int32_t order =
static_cast<int32_t
>(ans(0).int32_scalar_value());
5053 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetEqType
5054 <<
" returned an illegal value" << std::endl);
5059 if ( !ans(0).is_string() ) {
5060 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetEqType
5061 <<
" returned (" << ans(0).type_name()
5062 <<
")\nmethod must return integer or string values" << std::endl);
5066 const std::string order = ans(0).string_value();
5068 if ( order ==
"ALGEBRAIC" ) {
5070 }
else if ( order ==
"DIFFERENTIAL" ) {
5073 silent_cerr(
"octave error: method " << GetClass() <<
"." << strGetEqType
5074 <<
" returned an illegal value (" << order <<
")" << std::endl);
5079 std::ostream& OctaveElement::DescribeDof(std::ostream& out,
const char *prefix,
bool bInitial)
const
5081 if (!(haveMethod & HAVE_DESCRIBE_DOF)) {
5087 octave_value_list args(octObject);
5089 args.append(octave_value(prefix));
5090 args.append(octave_value(bInitial));
5092 GetInterface()->EvalFunction(strDescribeDof, args, 0, GetFlags());
5099 std::ostream& OctaveElement::DescribeEq(std::ostream& out,
const char *prefix,
bool bInitial)
const
5101 if (!(haveMethod & HAVE_DESCRIBE_EQ)) {
5107 octave_value_list args(octObject);
5109 args.append(octave_value(prefix));
5110 args.append(octave_value(bInitial));
5112 GetInterface()->EvalFunction(strDescribeEq, args, 0, GetFlags());
5121 if (!(haveMethod & HAVE_UPDATE)) {
5126 XP->Set(&XPrimeCurr);
5128 octave_value_list args(octObject);
5132 octave_value_list ans = GetInterface()->EvalFunction(strUpdate, args, 1, GetFlags());
5134 ASSERT(ans.length() == 1);
5136 if (!(ans(0).is_object() && ans(0).type_id() == octObject.type_id())) {
5137 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strUpdate <<
": output argument 1 is not an instance of " << octObject.type_name() << std::endl);
5149 if (!(haveMethod & HAVE_AFTER_PREDICT)) {
5154 XP->Set(&XPrimeCurr);
5156 octave_value_list args(octObject);
5160 octave_value_list ans = GetInterface()->EvalFunction(strAfterPredict, args, 1, GetFlags());
5162 ASSERT(ans.length() == 1);
5164 if (!(ans(0).is_object() && ans(0).type_id() == octObject.type_id())) {
5165 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAfterPredict <<
": output argument 1 is not an instance of " << octObject.type_name() << std::endl);
5175 void OctaveElement::AfterConvergence(
const VectorHandler& X,
5178 if ( !(haveMethod & HAVE_AFTER_CONVERGENCE) ) {
5185 octave_value_list args(octObject);
5186 args.append(this->X);
5187 args.append(this->XP);
5189 octave_value_list ans = GetInterface()->EvalFunction(strAfterConvergence, args, 1, GetFlags());
5194 ASSERT(ans.length() == 1);
5196 if ( !ans(0).is_object() ) {
5197 silent_cerr(
"octave error: return value of " << strAfterConvergence <<
" ("
5198 << ans(0).type_name() <<
") is not an object" << std::endl);
5206 OctaveElement::Restart(std::ostream& out)
const
5208 if (!(haveMethod & HAVE_RESTART)) {
5209 out <<
"# OctaveElement(" << GetClass() <<
"): not implemented" << std::endl;
5215 octave_value_list args(octObject);
5218 GetInterface()->EvalFunction(strRestart, args, 0, GetFlags());
5226 OctaveElement::iGetInitialNumDof(
void)
const
5228 if (!(haveMethod & HAVE_INITIAL_ASSEMBLY)) {
5232 octave_value_list args(octObject);
5234 octave_value_list ans = GetInterface()->EvalFunction(striGetInitialNumDof, args, 1, GetFlags());
5236 ASSERT(ans.length() == 1);
5238 if (!(ans(0).is_integer_type() && ans(0).is_scalar_type())){
5239 silent_cerr(
"octave error: method " << GetClass() <<
"." << striGetInitialNumDof
5240 <<
" returned (" << ans(0).type_name()
5241 <<
")\nmethod must return an integer" << std::endl);
5245 return static_cast<int32_t
>(ans(0).int32_scalar_value());
5249 OctaveElement::InitialWorkSpaceDim(
5253 if (!(haveMethod & HAVE_INITIAL_ASSEMBLY)) {
5259 octave_value_list args(octObject);
5261 octave_value_list ans = GetInterface()->EvalFunction(strInitialWorkSpaceDim, args, 2, GetFlags());
5263 ASSERT(ans.length() == 2);
5265 if (!(ans(0).is_integer_type()
5266 && ans(0).is_scalar_type()
5267 && ans(1).is_integer_type()
5268 && ans(1).is_scalar_type())) {
5269 silent_cerr(
"octave error: method " << GetClass() <<
"." << strInitialWorkSpaceDim
5270 <<
" must return two integer values\n"
5271 <<
"returned (" << ans(0).type_name() <<
", " << ans(1).type_name() <<
")" << std::endl);
5275 *piNumRows =
static_cast<int32_t
>(ans(0).int32_scalar_value());
5276 *piNumCols =
static_cast<int32_t
>(ans(1).int32_scalar_value());
5280 OctaveElement::InitialAssJac(
5284 if (!(haveMethod & HAVE_INITIAL_ASSEMBLY)) {
5289 octave_value_list args(octObject);
5295 const octave_value_list ans = GetInterface()->EvalFunction(strInitialAssJac, args, 4, GetFlags() | OctaveInterface::OPTIONAL_OUTPUT_ARGS);
5297 ASSERT(ans.length() <= 4);
5301 return AssMatrix(WorkMatVar, ans,
true);
5305 OctaveElement::InitialAssRes(
5309 if ( !(haveMethod & HAVE_INITIAL_ASSEMBLY) ) {
5314 int iNumRows, iNumCols;
5316 InitialWorkSpaceDim(&iNumRows, &iNumCols);
5322 octave_value_list args(octObject);
5325 octave_value_list ans = GetInterface()->EvalFunction(strInitialAssRes, args, 2, GetFlags());
5329 ASSERT(ans.length() == 2);
5331 if (!(ans(0).is_matrix_type()
5332 && ans(0).is_real_type()
5333 && ans(0).columns() == 1)) {
5334 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strInitialAssRes
5335 <<
" output argument f (" << ans(0).type_name() <<
") must be a real column vector" << std::endl);
5339 const ColumnVector f = ans(0).column_vector_value();
5341 if (!(ans(1).is_integer_type()
5342 && ans(1).is_matrix_type()
5343 && ans(1).columns() == 1)) {
5344 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strInitialAssRes
5345 <<
": output argument ridx (" << ans(1).type_name() <<
") must be an integer column vector" << std::endl);
5349 const int32NDArray ridx = ans(1).int32_array_value();
5351 if (ridx.length() != iNumRows || f.length() != iNumRows) {
5352 silent_cerr(
"octave(" << GetLabel()
5353 <<
"): function " << GetClass() <<
"." << strInitialAssRes
5354 <<
": length(f)=" << f.length()
5355 <<
" length(ridx)=" << ridx.length()
5356 <<
" is not equal to iNumRows=" << iNumRows << std::endl);
5360 const integer iNumDof = GetInterface()->GetDataManager()->iGetNumDofs();
5362 for (octave_idx_type i = 0; i < f.length(); ++i) {
5363 if (
int(ridx(i)) <= 0 ||
int(ridx(i)) > iNumDof) {
5364 silent_cerr(
"octave(" << GetLabel() <<
"): function " << GetClass() <<
"." << strAssRes <<
": row index " << ridx(i) <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
5368 WorkVec.
PutItem(i + 1, ridx(i), f(i));
5376 if (!(haveMethod & HAVE_SET_INITIAL_VALUE)) {
5380 octave_value_list args(octObject);
5381 args.append(octave_value(
new VectorHandlerInterface(GetInterface(), &X)));
5383 GetInterface()->EvalFunction(strSetInitialValue, args, 0, GetFlags());
5386 bool OctaveElement::bHaveMethod(
const std::string& strName)
const
5388 return GetInterface()->bHaveMethod(octObject, GetClass(), strName);
5394 const std::string& strFunction = bInitial ? strInitialAssJac : strAssJac;
5396 ASSERT(ans.length() <= 5);
5398 if (ans.length() < 3) {
5399 silent_cerr(
"octave(" << GetLabel()
5400 <<
"): function " << GetClass() <<
"." << strFunction
5401 <<
" returned " << ans.length() <<
" output arguments\n"
5402 <<
"expected 3-4 output arguments" << std::endl);
5407 ASSERT(ans.length() >= 3);
5409 if (!ans(0).is_real_matrix()) {
5410 silent_cerr(
"octave(" << GetLabel()
5411 <<
"): function " << GetClass() <<
"." << strFunction
5412 <<
" output argument Jac (" << ans(0).type_name()
5413 <<
") must be a real matrix" << std::endl);
5417 const Matrix Jac = ans(0).matrix_value();
5419 if (!(ans(1).is_integer_type() && ans(1).is_matrix_type())) {
5420 silent_cerr(
"octave(" << GetLabel()
5421 <<
"): function " << GetClass() <<
"." << strFunction
5422 <<
" output argument ridx (" << ans(1).type_name()
5423 <<
") must be a vector of integer values" << std::endl);
5427 const int32NDArray ridx = ans(1).int32_array_value();
5429 if (!(ans(2).is_integer_type() && ans(2).is_matrix_type())) {
5430 silent_cerr(
"octave(" << GetLabel()
5431 <<
"): function " << GetClass() <<
"." << strFunction
5432 <<
" output argument cidx (" << ans(2).type_name()
5433 <<
") must be a vector of integer values" << std::endl);
5437 const int32NDArray cidx = ans(2).int32_array_value();
5439 bool bSparse =
false;
5441 if (ans.length() >= 4) {
5442 if (!ans(3).is_bool_scalar()) {
5443 silent_cerr(
"octave(" << GetLabel()
5444 <<
"): invalid data type (" << ans(3).type_name() <<
")\n"
5445 <<
"expected bool scalar" << std::endl);
5449 bSparse = ans(3).bool_value();
5452 return AssMatrix(WorkMatVar, Jac, ridx, cidx, bSparse, bInitial);
5456 OctaveElement::AssMatrix(
VariableSubMatrixHandler& WorkMatVar,
const Matrix& Jac,
const int32NDArray& ridx,
const int32NDArray& cidx,
bool bSparse,
bool bInitial)
5458 const std::string& strFunction = bInitial ? strInitialAssJac : strAssJac;
5460 const integer iNumRows = Jac.rows();
5461 const integer iNumCols = Jac.cols();
5463 const integer iNumDof = GetInterface()->GetDataManager()->iGetNumDofs();
5467 || ridx.length() != iNumRows
5468 || cidx.length() != iNumRows) {
5469 silent_cerr(
"octave(" << GetLabel() <<
"):"
5470 <<
" rows(Jac)=" << Jac.rows()
5471 <<
" columns(Jac)= " << Jac.columns()
5472 <<
" length(ridx)= " << ridx.length()
5473 <<
" length(cidx)=" << cidx.length()
5474 <<
" are not consistent for a sparse submatrix" << std::endl);
5481 for (
int i = 0; i < iNumRows; ++i) {
5482 if (int32_t(ridx(i)) <= 0 || int32_t(ridx(i)) > iNumDof) {
5483 silent_cerr(
"octave(" << GetLabel() <<
"):"
5484 <<
" function " << GetClass() <<
"." << strFunction
5485 <<
": row index " << ridx(i)
5486 <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
5490 if (int32_t(cidx(i)) <= 0 || int32_t(cidx(i)) > iNumDof) {
5491 silent_cerr(
"octave(" << GetLabel() <<
"):"
5492 <<
" function " << GetClass() <<
"." << strFunction
5493 <<
": column index " << cidx(i)
5494 <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
5498 WorkMat.
PutItem(i + 1, ridx(i), cidx(i), Jac(i, 0));
5505 if (ridx.length() != iNumRows
5506 || cidx.length() != iNumCols) {
5507 silent_cerr(
"octave(" << GetLabel() <<
"):"
5508 <<
" rows(Jac)=" << Jac.rows()
5509 <<
" columns(Jac)= " << Jac.columns()
5510 <<
" length(ridx)= " << ridx.length()
5511 <<
" length(cidx)=" << cidx.length()
5512 <<
" are not consistent for a full submatrix" << std::endl);
5516 for (
int i = 0; i < iNumRows; ++i) {
5517 if (int32_t(ridx(i)) <= 0 || int32_t(ridx(i)) > iNumDof) {
5518 silent_cerr(
"octave(" << GetLabel() <<
"):"
5519 <<
" function " << GetClass() <<
"." << strFunction
5520 <<
": row index " << ridx(i)
5521 <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
5528 for (
int j = 0; j < iNumCols; ++j) {
5529 if (int32_t(cidx(j)) <= 0 || int32_t(cidx(j)) > iNumDof) {
5530 silent_cerr(
"octave(" << GetLabel() <<
"):"
5531 <<
" function " << GetClass() <<
"." << strFunction
5532 <<
": column index " << cidx(j)
5533 <<
" out of range [1:" << iNumDof <<
"]" << std::endl);
5540 for (
int i = 0; i < iNumRows; ++i) {
5541 for (
int j = 0; j < iNumCols; ++j) {
5542 WorkMat.
PutCoef(i + 1, j + 1, Jac(i, j));
5550 OctaveElementInterface::OctaveElementInterface(OctaveInterface* pInterface, OctaveElement* pElem)
5551 : MBDynInterface(pInterface),
5557 OctaveElementInterface::~OctaveElementInterface()
5563 OctaveElementInterface::print(std::ostream& os,
bool pr_as_read_syntax)
const
5565 os <<
"MBDynElement(" << (pElem ? pElem->GetLabel() : (unsigned)(-1)) <<
")" << std::endl;
5568 METHOD_DEFINE(OctaveElementInterface, GetLabel, args, nargout)
5570 if (args.length() != 0) {
5571 error(
"OctaveElement: invalid number of arguments %ld\n"
5572 "expected no arguments",
long(args.length()));
5573 return octave_value();
5576 return octave_value(octave_int<unsigned int>(pElem->GetLabel()));
5579 METHOD_DEFINE(OctaveElementInterface, iGetFirstIndex, args, nargout)
5581 if (args.length() != 0) {
5582 error(
"OctaveElement: invalid number of arguments %ld\n"
5583 "expected no arguments",
long(args.length()));
5584 return octave_value();
5587 return octave_value(octave_int<integer>(pElem->iGetFirstIndex()));
5590 BEGIN_METHOD_TABLE(OctaveElementInterface, MBDynInterface)
5591 METHOD_DISPATCH(OctaveElementInterface, GetLabel)
5592 METHOD_DISPATCH(OctaveElementInterface, iGetFirstIndex)
5595 DEFINE_OCTAVE_ALLOCATOR(OctaveElementInterface);
5596 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(OctaveElementInterface, "MBDynElement", "MBDynElement");
5600 #endif // USE_OCTAVE
5606 using namespace oct;
5614 OctaveTDCR<doublereal>*
const rf1D =
new OctaveTDCR<doublereal>;
5615 if (!
SetDC1D(
"octave", rf1D)) {
5620 OctaveTDCR<Vec3>*
const rf3D =
new OctaveTDCR<Vec3>;
5621 if (!
SetDC3D(
"octave", rf3D)) {
5626 OctaveTDCR<Vec6>*
const rf6D =
new OctaveTDCR<Vec6>;
5627 if (!
SetDC6D(
"octave", rf6D)) {
5632 OctaveTDCR<Mat3x3>*
const rf3x3D =
new OctaveTDCR<Mat3x3>;
5638 OctaveTDCR<Mat6x6>*
const rf6x6D =
new OctaveTDCR<Mat6x6>;
5644 rf =
new DerivativeDCR;
5651 if (!
SetSF(
"octave", rsf)) {
5657 if (!
SetUDE(
"octave", urf)) {
5663 if (!
SetCL1D(
"octave", rfcl1D)) {
5669 if (!
SetCL3D(
"octave", rfcl3D)) {
5675 if (!
SetCL6D(
"octave", rfcl6D)) {
5680 pedantic_cerr(
"warning: MBDyn has been configured without octave support\n"
5681 "warning: module-octave is not available in this version of MBDyn" << std::endl);
5689 #ifndef STATIC_MODULES
5695 silent_cerr(
"octave: "
5696 "module_init(" << module_name <<
") "
5697 "failed" << std::endl);
5704 #endif // ! STATIC_MODULES
flag fReadOutput(MBDynParser &HP, const T &t) const
Mat3x3 GetRotRel(const ReferenceFrame &rf)
virtual const doublereal & dGetDofValue(int iDof, int iOrder=0) const =0
void PutColIndex(integer iSubCol, integer iCol)
bool SetDriveCallerData(const char *name, DriveCallerRead *rf)
#define MBDYN_EXCEPT_ARGS
TypedValue::Type GetType(void) const
virtual void ResizeReset(integer)
virtual integer GetInt(integer iDefval=0)
FullSubMatrixHandler & SetFull(void)
bool SetDC3x3D(const char *name, TplDriveCallerRead< Mat3x3 > *rf)
virtual TypedValue GetVal(void) const =0
int error(const char *test, int value)
virtual const Vec3 & GetXPrev(void) const
virtual bool GetBool(bool bDefval=false)
bool SetDC6D(const char *name, TplDriveCallerRead< Vec6 > *rf)
virtual unsigned int iGetPrivDataIdx(const char *s) const
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
static const unsigned int iNumPrivData
virtual const doublereal & dGetDofValuePrev(int iDof, int iOrder=0) const =0
void ResizeReset(integer iNewRow, integer iNewCol)
std::vector< Hint * > Hints
const char *const GetTypeName(void) const
virtual void PutItem(integer iSubRow, integer iRow, const doublereal &dCoef)
virtual bool GetYesNoOrBool(bool bDefval=false)
virtual TypedValue GetValue(const TypedValue &v)
virtual doublereal dGetP(const doublereal &dVar) const
VM::const_iterator end(void) const
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
void PutItem(integer iSubIt, integer iRow, integer iCol, const doublereal &dCoef)
virtual bool bIsDifferentiable(void) const
Vec3 GetPosRel(const ReferenceFrame &rf)
virtual ConstLawType::Type GetConstLawType(void) const =0
virtual bool IsKeyWord(const char *sKeyWord)
bool SetDC3D(const char *name, TplDriveCallerRead< Vec3 > *rf)
std::ostream & Loadable(void) const
virtual const Vec3 & GetVPrev(void) const
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
bool SetDC1D(const char *name, TplDriveCallerRead< doublereal > *rf)
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
virtual integer iGetFirstRowIndex(void) const
virtual integer iGetFirstMomentumIndex(void) const =0
virtual integer iGetFirstPositionIndex(void) const
const std::string & GetString(void) const
#define ASSERT(expression)
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual const Vec3 & GetXCurr(void) const
virtual void ResizeReset(integer, integer)
virtual DriveCaller * pCopy(void) const =0
virtual doublereal dGetPrivData(unsigned int i) const
virtual unsigned int iGetNumPrivData(void) const
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
virtual std::string GetString(const std::string &sDefVal)
bool SetSF(const std::string &s, const ScalarFunctionRead *rf)
virtual bool IsStringWithDelims(enum Delims Del=DEFAULTDELIM)
void PutRowIndex(integer iSubRow, integer iRow)
bool mbdyn_octave_set(void)
std::ostream & GetLogFile(void) const
bool SetUDE(const std::string &s, UserDefinedElemRead *rude)
virtual const Vec3 & GetVCurr(void) const
DriveCaller * GetDriveCaller(bool bDeferred=false)
bool SetDC6x6D(const char *name, TplDriveCallerRead< Mat6x6 > *rf)
virtual const Vec3 & GetXPPCurr(void) const
virtual const Vec3 & GetXPPPrev(void) const
SparseSubMatrixHandler & SetSparse(void)
virtual integer iGetFirstIndex(void) const
const std::string & GetName(void) const
virtual doublereal Get(const doublereal &d)
VM::const_iterator begin(void) const
virtual HighParser::ErrOut GetLineData(void) const
void SetVal(const bool &b)
static std::stack< const HighParser * > pHP
unsigned int GetLabel(void) const
virtual bool bComputeAccelerations(void) const
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
bool UseText(int out) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)
virtual integer iGetFirstColIndex(void) const