1811 bool bSendAfterPredict;
1812 ReadExtForce(pDM, HP, uLabel, pEFH, bSendAfterPredict, iCoupling);
1819 bool bLabels(
false);
1821 bool bOutputAccelerations(
false);
1822 bool bUseReferenceNodeForces(
true);
1823 bool bRotateReferenceNodeForces(
true);
1825 bool bGotLabels(
false);
1826 bool bGotRot(
false);
1827 bool bGotAccels(
false);
1828 bool bGotUseRefForces(
false);
1830 while (HP.
IsArg()) {
1832 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1833 "use of \"no labels\" deprecated in favor of \"labels, { yes | no }\" at line "
1837 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1838 "\"no labels\" already specified at line "
1848 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1849 "\"labels\" already specified at line "
1855 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1856 "\"labels\" must be either \"yes\" or \"no\" at line "
1862 }
else if (HP.
IsKeyWord(
"orientation")) {
1864 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1865 "\"orientation\" already specified at line "
1873 }
else if (HP.
IsKeyWord(
"orientation" "vector")) {
1876 }
else if (HP.
IsKeyWord(
"orientation" "matrix")) {
1879 }
else if (HP.
IsKeyWord(
"euler" "123")) {
1883 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1884 "unknown \"orientation\" format at line "
1891 }
else if (HP.
IsKeyWord(
"accelerations")) {
1893 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1894 "\"accelerations\" already specified at line "
1899 if (!HP.
GetYesNo(bOutputAccelerations)) {
1900 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1901 "\"accelerations\" must be either \"yes\" or \"no\" at line "
1907 }
else if (HP.
IsKeyWord(
"use" "reference" "node" "forces")) {
1908 if (pRefNode == 0) {
1909 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1910 "\"use reference node forces\" only meaningful when reference node is used at line "
1915 if (bGotUseRefForces) {
1916 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1917 "\"use reference node forces\" already specified at line "
1922 if (!HP.
GetYesNo(bUseReferenceNodeForces)) {
1923 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1924 "\"use reference node forces\" must be either \"yes\" or \"no\" at line "
1928 bGotUseRefForces =
true;
1930 if (bUseReferenceNodeForces && HP.
IsKeyWord(
"rotate" "reference" "node" "forces")) {
1931 if (!HP.
GetYesNo(bRotateReferenceNodeForces)) {
1932 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1933 "\"rotate reference node forces\" must be either \"yes\" or \"no\" at line "
1945 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1946 "\"points number\" keyword expected "
1951 int nPoints = HP.
GetInt();
1953 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): illegal points number " << nPoints <<
1958 std::vector<const StructDispNode *> Nodes(nPoints);
1959 std::vector<Vec3> Offsets(nPoints, ::
Zero3);
1960 std::vector<uint32_t> Labels;
1962 Labels.resize(nPoints);
1964 bool bMembrane(
false);
1965 std::vector<StructMembraneMappingExtForce::NodeConnData> NodesConn;
1967 std::map<unsigned, bool> Got;
1969 for (
unsigned n = 0, p = 0; p < unsigned(nPoints); n++) {
1973 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1974 "StructNode(" << uL <<
") out of order "
1987 for (
unsigned n = 0; n < 4; n++) {
1989 if ((n%2) && pNn == ncd.
pNode[n - 1]) {
1990 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
1991 "nodes #" << n <<
" and #" << n - 1 <<
" are the same in \"membrane\" mapping for StructNode(" << uL <<
") at line " << HP.
GetLineData() << std::endl);
2003 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2004 "invalid h1 in \"membrane\" mapping for StructNode(" << uL <<
") at line " << HP.
GetLineData() << std::endl);
2012 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2013 "invalid (negative) point label " << l
2022 if (p ==
unsigned(nPoints)) {
2023 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2024 "second point in \"membrane\" mapping for StructNode(" << uL <<
") exceeds points number " << nPoints <<
" at line " << HP.
GetLineData() << std::endl);
2033 if (h2 == 0. || h1*h2 > 0.) {
2034 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2035 "invalid h2 in \"membrane\" mapping for StructNode(" << uL <<
") at line " << HP.
GetLineData() << std::endl);
2043 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2044 "invalid (negative) point label " << l
2055 if (p ==
unsigned(nPoints)) {
2056 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2057 "point " << p <<
" offset from StructNode(" << pNode->
GetLabel() <<
") exceeds expected value " << nPoints
2065 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2066 "invalid (negative) point label " << l
2079 NodesConn.push_back(ncd);
2085 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2086 "unable to parse echo file name "
2092 std::ofstream out(s);
2094 out.setf(std::ios::scientific);
2096 bool bGotSurface(
false);
2097 bool bGotOutput(
false);
2098 bool bGotOrder(
false);
2099 bool bGotBaseNode(
false);
2100 bool bGotWeight(
false);
2102 bool bGotPrecision(
false);
2113 std::string surface;
2118 bool bWeightInf(
false);
2122 if (bGotPrecision) {
2123 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2124 "\"precision\" already specified "
2128 bGotPrecision =
true;
2130 int iPrecision = HP.
GetInt();
2131 if (iPrecision <= 0) {
2132 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2133 "invalid echo precision " << iPrecision
2138 out.precision(iPrecision);
2142 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2143 "\"surface\" already specified "
2150 if (surface.empty()) {
2151 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2152 "invalid \"surface\" "
2159 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2160 "\"output\" already specified "
2167 if (output.empty()) {
2168 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2169 "invalid \"output\" "
2176 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2177 "\"order\" already specified "
2184 if (order < 1 || order > 3) {
2185 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2186 "invalid order=" << order <<
", must be 1 <= order <= 3 "
2193 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2194 "\"basenode\" already specified "
2198 bGotBaseNode =
true;
2201 if (basenode <= 0) {
2202 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2203 "invalid basenode=" << basenode <<
", must be > 0 "
2210 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2211 "\"weight\" already specified "
2223 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2224 "invalid weight=" << weight <<
", must be >= -2 or \"inf\" "
2235 time_t t = std::time(NULL);
2236 const char *user = std::getenv(
"USER");
2237 const char *
host = std::getenv(
"HOSTNAME");
2238 if (user == 0) user =
"nobody";
2239 if (host == 0) host =
"unknown";
2242 <<
"# Generated by MBDyn StructMappingExtForce(" << uLabel <<
")" << std::endl
2243 <<
"# " << user <<
"@" << host << std::endl
2244 <<
"# " << std::ctime(&t)
2245 <<
"# labels: " << (bLabels ?
"on" :
"off") << std::endl;
2249 xRef = pRefNode->GetXCurr();
2250 RRef = pRefNode->GetRCurr();
2253 <<
"# reference: " << pRefNode->GetLabel() << std::endl
2254 <<
"# position: " << xRef << std::endl
2259 <<
"# points: " << nPoints << std::endl;
2262 out <<
"# surface: " << surface << std::endl;
2266 out <<
"# output: " << output << std::endl;
2270 out <<
"# order: " << order << std::endl;
2274 out <<
"# basenode: " << basenode << std::endl;
2279 out <<
"# weight: inf" << std::endl;
2281 out <<
"# weight: " << weight << std::endl;
2285 for (
unsigned n = 0, p = 0; p < unsigned(nPoints); p++) {
2286 if (p > 0 && Nodes[p] != Nodes[p - 1]) {
2291 out << Labels[p] <<
" ";
2295 const StructNode *pNode(dynamic_cast<const StructNode *>(Nodes[p]));
2297 x = RRef.MulTV(pNode->
GetXCurr() + pNode->GetRCurr()*Offsets[p] - xRef);
2301 if (NodesConn[n].pNode[0] != 0) {
2302 Vec3 e1(NodesConn[n].pNode[1]->GetXCurr() - NodesConn[n].pNode[0]->GetXCurr());
2303 Vec3 e2(NodesConn[n].pNode[3]->GetXCurr() - NodesConn[n].pNode[2]->GetXCurr());
2304 Vec3 e3(e1.Cross(e2));
2307 if (Nodes[p + 1] == Nodes[p]) {
2308 h = e3*NodesConn[n].h1;
2311 h = e3*NodesConn[n].h2;
2315 x = RRef.MulTV(Nodes[p]->GetXCurr() + h - xRef);
2317 out << x << std::endl;
2326 std::vector<uint32_t> MappedLabels;
2327 if (HP.
IsKeyWord(
"mapped" "points" "number")) {
2328 int nMappedPoints = 0;
2333 nMappedPoints = HP.
GetInt();
2334 if (nMappedPoints <= 0) {
2335 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2336 "invalid mapped points number " << nMappedPoints
2346 ASSERT((nMappedPoints%3) == 0);
2347 ASSERT(nCols == 3*nPoints);
2351 MappedLabels.resize(nMappedPoints);
2352 if (HP.
IsKeyWord(
"mapped" "labels" "file")) {
2354 if (sFileName == 0) {
2355 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2356 "unable to read mapped labels file name "
2361 std::ifstream in(sFileName);
2363 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2364 "unable to open mapped labels file "
2365 "\"" << sFileName <<
"\" "
2374 }
while (c !=
'\n');
2379 for (
unsigned l = 0; l < unsigned(nMappedPoints); l++) {
2383 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2384 "unable to read mapped label #" << l <<
"/" << nMappedPoints
2385 <<
" from mapped labels file \"" << sFileName <<
"\"" << std::endl);
2389 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2390 "invalid (negative) mapped label #" << l <<
"/" << nMappedPoints
2391 <<
" from mapped labels file \"" << sFileName <<
"\"" << std::endl);
2394 MappedLabels[l] = i;
2398 for (
unsigned l = 0; l < unsigned(nMappedPoints); l++) {
2401 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2402 "invalid (negative) mapped label #" << l <<
"/" << nMappedPoints
2406 MappedLabels[l] = i;
2411 for (
unsigned l = 1; l < unsigned(nMappedPoints); l++) {
2412 for (
unsigned c = 0; c < l; c++) {
2413 if (MappedLabels[l] == MappedLabels[c]) {
2415 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2416 "duplicate mapped label " << MappedLabels[l] <<
": "
2417 "#" << l <<
"==#" << c << std::endl);
2423 silent_cerr(
"StructMappingExtForce(" << uLabel <<
"): "
2424 << duplicate <<
" duplicate mapped labels"
2436 bUseReferenceNodeForces, bRotateReferenceNodeForces,
2437 Nodes, Offsets, Labels, NodesConn,
2440 bLabels, bOutputAccelerations, uRRot,
2441 pEFH, bSendAfterPredict, iCoupling, fOut));
2446 bUseReferenceNodeForces, bRotateReferenceNodeForces,
2447 Nodes, Offsets, Labels,
2450 bLabels, bOutputAccelerations, uRRot,
2451 pEFH, bSendAfterPredict, iCoupling, fOut));
flag fReadOutput(MBDynParser &HP, const T &t) const
const Vec3 Zero3(0., 0., 0.)
static void output(const LoadableElem *pEl, OutputHandler &OH)
#define MBDYN_EXCEPT_ARGS
virtual integer GetInt(integer iDefval=0)
doublereal Norm(void) const
const StructDispNode * pNode[4]
const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.)
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
Vec3 GetPosRel(const ReferenceFrame &rf)
virtual bool IsKeyWord(const char *sKeyWord)
Vec3 MatR2EulerAngles123(const Mat3x3 &R)
#define ASSERT(expression)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual const Vec3 & GetXCurr(void) const
static std::stack< cleanup * > c
virtual bool GetYesNo(bool &bRet)
virtual HighParser::ErrOut GetLineData(void) const
unsigned int GetLabel(void) const
Node * ReadNode(MBDynParser &HP, Node::Type type) const
void ReadExtForce(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, ExtFileHandlerBase *&pEFH, bool &bSendAfterPredict, int &iCoupling)
SpMapMatrixHandler * ReadSparseMappingMatrix(MBDynParser &HP, integer &nRows, integer &nCols)
virtual doublereal GetReal(const doublereal &dDefval=0.0)