AbstractCoupledModel.hpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /**
  2. * @file artis/kernel/AbstractCoupledModel.hpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2019 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP
  22. #define __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP
  23. #include <artis/kernel/AbstractModel.hpp>
  24. #include <artis/kernel/Externals.hpp>
  25. #include <artis/kernel/Internals.hpp>
  26. #include <artis/kernel/States.hpp>
  27. #include <artis/utils/DateTime.hpp>
  28. #include <artis/utils/Trace.hpp>
  29. #include <functional>
  30. #include <vector>
  31. namespace artis {
  32. namespace kernel {
  33. template<typename T, typename U, typename V, typename W>
  34. class Simulator;
  35. template<typename T, typename U, typename V, typename W>
  36. class AbstractCoupledModel : public AbstractModel<U, V>,
  37. public States<T, U, V>,
  38. public Internals<T, U, V>,
  39. public Externals<T, U, V> {
  40. typedef AbstractModel<U, V> type;
  41. typedef std::map<int, type*> Submodels;
  42. typedef std::map<int,
  43. std::vector<type*> > Setsubmodels;
  44. typedef std::map<int, std::pair<type*,
  45. int> > SubModelInternals;
  46. using Externals<T, U, V>::restore;
  47. using Internals<T, U, V>::restore;
  48. using States<T, U, V>::restore;
  49. using Externals<T, U, V>::save;
  50. using Internals<T, U, V>::save;
  51. using States<T, U, V>::save;
  52. #ifdef WITH_TRACE
  53. friend class Simulator<T, U, V, W>;
  54. #endif
  55. public:
  56. struct Var {
  57. unsigned int index;
  58. type* model;
  59. int sub_index;
  60. std::string var_name;
  61. std::string sub_var_name;
  62. Var(unsigned int index, std::string var_name,
  63. type* model, int sub_index, std::string sub_var_name)
  64. :
  65. index(index), model(model), sub_index(sub_index),
  66. var_name(var_name), sub_var_name(sub_var_name) { }
  67. };
  68. AbstractCoupledModel(const type* parent = 0)
  69. :type(parent)
  70. {
  71. #ifdef WITH_TRACE
  72. utils::Trace<utils::DoubleTime>::trace()
  73. << utils::TraceElement<utils::DoubleTime>(
  74. true,
  75. boost::core::demangle(typeid(T).name()),
  76. utils::DoubleTime::null,
  77. utils::CONSTRUCT);
  78. utils::Trace<utils::DoubleTime>::trace().flush();
  79. #endif
  80. }
  81. virtual ~AbstractCoupledModel()
  82. {
  83. #ifdef WITH_TRACE
  84. trace_element(true, utils::DoubleTime::null, utils::DESTRUCT);
  85. #endif
  86. }
  87. virtual void after(typename U::type t)
  88. {
  89. #ifdef WITH_TRACE
  90. trace_element(true, t, utils::AFTER_COMPUTE);
  91. trace_internals(true, t, utils::AFTER_COMPUTE);
  92. #else
  93. (void) t;
  94. #endif
  95. }
  96. virtual const Node<U>* atomic(unsigned int index) const
  97. {
  98. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  99. submodel_internals.find(index);
  100. if (it == submodel_internals.end()) {
  101. return this;
  102. } else {
  103. return it->second.first->atomic(it->second.second);
  104. }
  105. }
  106. virtual void before(typename U::type t)
  107. {
  108. #ifdef WITH_TRACE
  109. trace_element(true, t, utils::BEFORE_COMPUTE);
  110. trace_internals(true, t, utils::BEFORE_COMPUTE);
  111. trace_externals(true, t, utils::BEFORE_COMPUTE);
  112. #else
  113. (void) t;
  114. #endif
  115. }
  116. virtual void build(W& /* parameters */) { }
  117. virtual void build(W& /* parameters */, const std::string& /* json */) { }
  118. virtual bool check(typename U::type t) const { return Externals<T, U, V>::check(t); }
  119. virtual void compute(typename U::type t, bool update) = 0;
  120. virtual const Any& get(typename U::type t, unsigned int index) const
  121. {
  122. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  123. submodel_internals.find(index);
  124. if (it == submodel_internals.end()) {
  125. if (type::last_time != t) {
  126. throw utils::InvalidGet("Variable not computed");
  127. }
  128. return Internals<T, U, V>::get(index);
  129. } else {
  130. return it->second.first->get(t, it->second.second);
  131. }
  132. }
  133. template<typename Z, typename K>
  134. Z get(typename U::type t, unsigned int index) const
  135. {
  136. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  137. submodel_internals.find(index);
  138. if (it == submodel_internals.end()) {
  139. if (type::last_time != t) {
  140. throw utils::InvalidGet("Variable not computed");
  141. }
  142. const Any& value = Internals<T, U, V>::get(index);
  143. return static_cast < const T* >(this)->*(value.get<T, Z>());
  144. } else {
  145. const Any& value = it->second.first->get(t, it->second.second);
  146. const Node<U>* object = it->second.first->atomic(
  147. it->second.second);
  148. return static_cast < const K* >(object)->*(value.get<K, Z>());
  149. }
  150. }
  151. virtual std::string get(const ValueTypeID& value_type, typename U::type t,
  152. unsigned int index) const
  153. {
  154. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  155. submodel_internals.find(index);
  156. if (it == submodel_internals.end()) {
  157. Any value = Internals<T, U, V>::get(index);
  158. switch (value_type) {
  159. case DOUBLE:
  160. return std::to_string(
  161. static_cast < const T* >(this)->*(value.get<T,
  162. double>()));
  163. case INT:
  164. return std::to_string(
  165. static_cast < const T* >(this)->*(value.get<T, int>()));
  166. case BOOL:
  167. return std::to_string(
  168. static_cast < const T* >(this)->*(value.get<T, bool>()));
  169. default:
  170. return "NA";
  171. }
  172. } else {
  173. return it->second.first->get(value_type, t, it->second.second);
  174. }
  175. }
  176. virtual void init(typename U::type t, const V& parameters) = 0;
  177. virtual bool is_atomic() const { return false; }
  178. bool is_computed(typename U::type t, unsigned int index) const
  179. {
  180. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  181. submodel_internals.find(index);
  182. if (it == submodel_internals.end()) {
  183. return false;
  184. } else {
  185. return it->second.first->is_computed(t, it->second.second);
  186. }
  187. }
  188. bool is_stable(typename U::type t) const
  189. {
  190. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  191. submodel_internals.begin();
  192. bool stable = true;
  193. while (it != submodel_internals.end() and stable) {
  194. stable = it->second.first->is_stable(t);
  195. ++it;
  196. }
  197. return stable;
  198. }
  199. virtual bool is_updated() const { return Externals<T, U, V>::updated; }
  200. virtual const Node<U>* get_submodel(unsigned int index) const
  201. {
  202. typename AbstractCoupledModel::Submodels::const_iterator it =
  203. submodels.find(index);
  204. if (it != submodels.end()) {
  205. return it->second;
  206. } else {
  207. return 0;
  208. }
  209. }
  210. virtual const Node<U>* get_submodel(unsigned int index,
  211. unsigned int rank) const
  212. {
  213. typename AbstractCoupledModel::Setsubmodels::const_iterator it =
  214. setsubmodels.find(index);
  215. if (it != setsubmodels.end() and it->second.size() > rank) {
  216. return it->second.at(rank);
  217. } else {
  218. return 0;
  219. }
  220. }
  221. virtual std::string path_index(const AbstractModel<U, V>* child,
  222. int& index) const
  223. {
  224. typename Setsubmodels::const_iterator it = setsubmodels.begin();
  225. bool found = false;
  226. index = -1;
  227. while (not found and it != setsubmodels.end()) {
  228. typename std::vector<type*>::const_iterator itm =
  229. it->second.begin();
  230. index = 0;
  231. while (not found and itm != it->second.end()) {
  232. found = *itm == child;
  233. if (not found) {
  234. ++index;
  235. ++itm;
  236. }
  237. }
  238. index = found ? index : -1;
  239. ++it;
  240. }
  241. if (type::parent) {
  242. int i;
  243. std::string p = type::parent->path_index(this, i);
  244. if (i >= 0) {
  245. return p +
  246. "/[" + std::to_string(i) + "]" +
  247. boost::core::demangle(typeid(*this).name());
  248. } else {
  249. return p + "/" + boost::core::demangle(typeid(*this).name());
  250. }
  251. } else {
  252. return boost::core::demangle(typeid(*this).name());
  253. }
  254. }
  255. virtual void restore(const context::State<U>& state)
  256. {
  257. typename AbstractCoupledModel::Submodels::const_iterator it =
  258. submodels.begin();
  259. while (it != submodels.end()) {
  260. it->second->restore(state.get_substate(it->first));
  261. ++it;
  262. }
  263. States<T, U, V>::restore(this, state);
  264. Internals<T, U, V>::restore(this, state);
  265. Externals<T, U, V>::restore(this, state);
  266. }
  267. virtual void save(context::State<U>& state) const
  268. {
  269. typename AbstractCoupledModel::Submodels::const_iterator it =
  270. submodels.begin();
  271. while (it != submodels.end()) {
  272. context::State<U> substate;
  273. it->second->save(substate);
  274. state.add_substate(it->first, substate);
  275. ++it;
  276. }
  277. States<T, U, V>::save(this, state);
  278. Internals<T, U, V>::save(this, state);
  279. Externals<T, U, V>::save(this, state);
  280. }
  281. virtual void stable() { Externals<T, U, V>::updated = false; }
  282. void submodel(unsigned int index, type* model)
  283. {
  284. if (model) {
  285. submodels[index] = model;
  286. model->set_parent(this);
  287. } else {
  288. submodels[index] = 0;
  289. }
  290. }
  291. virtual void trace_element(typename U::type t,
  292. utils::TraceType type = utils::NONE,
  293. std::string comment = "") const { trace_element(false, t, type, comment); }
  294. virtual void trace_internals(typename U::type t,
  295. utils::TraceType type) const { trace_internals(false, t, type); }
  296. virtual void trace_externals(typename U::type t,
  297. utils::TraceType type = utils::NONE) const { trace_externals(false, t, type); }
  298. virtual void trace_model(typename U::type t,
  299. utils::TraceType type = utils::NONE) const { trace_model(false, t, type); }
  300. private:
  301. void trace_element(bool from_kernel, typename U::type t,
  302. utils::TraceType type = utils::NONE,
  303. std::string comment = "") const
  304. {
  305. utils::Trace<utils::DoubleTime>::trace()
  306. << utils::TraceElement<utils::DoubleTime>(
  307. from_kernel,
  308. AbstractCoupledModel<T, U, V, W>::path(this),
  309. t, type)
  310. << comment;
  311. utils::Trace<utils::DoubleTime>::trace().flush();
  312. }
  313. void trace_internals(bool from_kernel, typename U::type t,
  314. utils::TraceType type) const
  315. {
  316. for (size_t i = 0; i < Internals<T, U, V>::size(); ++i) {
  317. if (not Internals<T, U, V>::get(i).is_null()) {
  318. utils::Trace<utils::DoubleTime>::trace()
  319. << utils::TraceElement<utils::DoubleTime>(
  320. from_kernel,
  321. AbstractCoupledModel<T, U, V, W>::path(this),
  322. t, type)
  323. << utils::KernelInfo(
  324. Internals<T, U, V>::name(i), true,
  325. Internals<T, U, V>::get(i).to_string(
  326. dynamic_cast < const T* >(this))
  327. );
  328. utils::Trace<utils::DoubleTime>::trace().flush();
  329. }
  330. }
  331. }
  332. void trace_externals(bool from_kernel, typename U::type t,
  333. utils::TraceType type = utils::NONE) const
  334. {
  335. for (size_t i = 0; i < Externals<T, U, V>::size(); ++i) {
  336. if (not Externals<T, U, V>::get(i).is_null()) {
  337. utils::Trace<utils::DoubleTime>::trace()
  338. << utils::TraceElement<utils::DoubleTime>(
  339. from_kernel,
  340. AbstractCoupledModel<T, U, V, W>::path(this),
  341. t, type)
  342. << utils::KernelInfo(
  343. Externals<T, U, V>::name(i), false,
  344. Externals<T, U, V>::get(i).to_string(
  345. dynamic_cast < const T* >(this))
  346. );
  347. utils::Trace<utils::DoubleTime>::trace().flush();
  348. }
  349. }
  350. }
  351. void trace_model(bool from_kernel, typename U::type t,
  352. utils::TraceType type = utils::NONE) const
  353. {
  354. trace_element(from_kernel, t, type);
  355. trace_internals(from_kernel, t, type);
  356. trace_externals(from_kernel, t, type);
  357. // typename AbstractCoupledModel::Submodels::const_iterator it =
  358. // submodels.begin();
  359. // while (it != submodels.end()) {
  360. // it->second->trace_model(from_kernel, t, type);
  361. // ++it;
  362. // }
  363. }
  364. protected:
  365. void link_internal_(unsigned int index, std::string var_name,
  366. type* model, int sub_index, std::string sub_var_name)
  367. {
  368. #ifndef WITH_TRACE
  369. (void) var_name;
  370. (void) sub_var_name;
  371. #endif
  372. submodel_internals[index] =
  373. std::pair<type*, int>(model, sub_index);
  374. #ifdef WITH_TRACE
  375. utils::Trace<utils::DoubleTime>::trace()
  376. << utils::TraceElement<utils::DoubleTime>(
  377. true,
  378. AbstractCoupledModel<T, U, V, W>::path(this),
  379. utils::DoubleTime::null,
  380. utils::INTERNAL_LINK)
  381. << utils::KernelInfo(
  382. var_name,
  383. AbstractCoupledModel<T, U, V, W>::path(model),
  384. sub_var_name);
  385. utils::Trace<utils::DoubleTime>::trace().flush();
  386. #endif
  387. }
  388. void I_(std::initializer_list<Var> internals)
  389. {
  390. for (typename std::initializer_list<Var>::iterator it =
  391. internals.begin(); it != internals.end(); ++it) {
  392. submodel_internals[it->index] =
  393. std::pair<type*, int>(it->model, it->sub_index);
  394. #ifdef WITH_TRACE
  395. utils::Trace<utils::DoubleTime>::trace()
  396. << utils::TraceElement<utils::DoubleTime>(
  397. true,
  398. AbstractCoupledModel<T, U, V, W>::path(this),
  399. utils::DoubleTime::null,
  400. utils::INTERNAL_LINK)
  401. << utils::KernelInfo(
  402. it->var_name,
  403. AbstractCoupledModel<T, U, V, W>::path(it->model),
  404. it->sub_var_name);
  405. utils::Trace<utils::DoubleTime>::trace().flush();
  406. #endif
  407. }
  408. }
  409. void SM_(std::initializer_list<std::pair<unsigned int,
  410. type*> > models)
  411. {
  412. for (typename std::initializer_list<std::pair<unsigned int,
  413. type*> >::iterator it =
  414. models.begin(); it != models.end(); ++it) {
  415. submodels[it->first] = it->second;
  416. it->second->set_parent(this);
  417. #ifdef WITH_TRACE
  418. utils::Trace<utils::DoubleTime>::trace()
  419. << utils::TraceElement<utils::DoubleTime>(
  420. true,
  421. AbstractCoupledModel<T, U, V, W>::path(this),
  422. utils::DoubleTime::null,
  423. utils::SUBMODEL_ADD)
  424. << utils::KernelInfo(
  425. AbstractCoupledModel<T, U, V, W>::path(it->second));
  426. utils::Trace<utils::DoubleTime>::trace().flush();
  427. #endif
  428. }
  429. }
  430. void setsubmodel(unsigned int index, type* model)
  431. {
  432. if (setsubmodels.find(index) == setsubmodels.end()) {
  433. setsubmodels[index] = std::vector<type*>();
  434. }
  435. setsubmodels[index].push_back(model);
  436. model->set_parent(this);
  437. #ifdef WITH_TRACE
  438. utils::Trace<utils::DoubleTime>::trace()
  439. << utils::TraceElement<utils::DoubleTime>(
  440. true,
  441. AbstractCoupledModel<T, U, V, W>::path(this),
  442. utils::DoubleTime::null,
  443. utils::SUBMODEL_ADD)
  444. << utils::KernelInfo(
  445. AbstractCoupledModel<T, U, V, W>::path(model));
  446. utils::Trace<utils::DoubleTime>::trace().flush();
  447. #endif
  448. }
  449. private:
  450. SubModelInternals submodel_internals;
  451. Submodels submodels;
  452. Setsubmodels setsubmodels;
  453. };
  454. #define InternalS(index, var, sub_index) link_internal_(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
  455. #define ITEM_S(index, var, sub_index) Var(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
  456. #define UNWRAP_ITEM_S(...) ITEM_S __VA_ARGS__
  457. #define LIST_S_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15), UNWRAP_ITEM_S(L16) }
  458. #define LIST_S_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15) }
  459. #define LIST_S_14(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14) }
  460. #define LIST_S_13(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13) }
  461. #define LIST_S_12(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12) }
  462. #define LIST_S_11(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11) }
  463. #define LIST_S_10(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10) }
  464. #define LIST_S_9(L1, L2, L3, L4, L5, L6, L7, L8, L9) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9) }
  465. #define LIST_S_8(L1, L2, L3, L4, L5, L6, L7, L8) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8) }
  466. #define LIST_S_7(L1, L2, L3, L4, L5, L6, L7) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7) }
  467. #define LIST_S_6(L1, L2, L3, L4, L5, L6) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6) }
  468. #define LIST_S_5(L1, L2, L3, L4, L5) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5) }
  469. #define LIST_S_4(L1, L2, L3, L4) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4) }
  470. #define LIST_S_3(L1, L2, L3) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3) }
  471. #define LIST_S_2(L1, L2) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2) }
  472. #define LIST_S_1(L1) { UNWRAP_ITEM_S(L1) }
  473. #define LIST_S_(N) LIST_S_##N
  474. #define LIST_S_EVAL(N) LIST_S_(N)
  475. #define UNWRAP_S_2(...) EXPAND( LIST_S_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  476. //#define UNWRAP_S_2(...) GET_MACRO(__VA_ARGS__, LIST_S_16, LIST_S_15, LIST_S_14, LIST_S_13, LIST_S_12, LIST_S_11, LIST_S_10, LIST_S_9, LIST_S_8, LIST_S_7, LIST_S_6, LIST_S_5, LIST_S_4, LIST_S_3, LIST_S_2, LIST_S_1)(__VA_ARGS__)
  477. #define InternalsS(L) I_(UNWRAP_S_2 L)
  478. #define ITEM_Sub(index, model) { index, model }
  479. #define UNWRAP_ITEM_Sub(...) ITEM_Sub __VA_ARGS__
  480. #define LIST_Sub_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14), UNWRAP_ITEM_Sub(L15), UNWRAP_ITEM_Sub(L16) }
  481. #define LIST_Sub_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14), UNWRAP_ITEM_Sub(L15) }
  482. #define LIST_Sub_14(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14) }
  483. #define LIST_Sub_13(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13) }
  484. #define LIST_Sub_12(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12) }
  485. #define LIST_Sub_11(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11) }
  486. #define LIST_Sub_10(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10) }
  487. #define LIST_Sub_9(L1, L2, L3, L4, L5, L6, L7, L8, L9) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9) }
  488. #define LIST_Sub_8(L1, L2, L3, L4, L5, L6, L7, L8) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8) }
  489. #define LIST_Sub_7(L1, L2, L3, L4, L5, L6, L7) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7) }
  490. #define LIST_Sub_6(L1, L2, L3, L4, L5, L6) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6) }
  491. #define LIST_Sub_5(L1, L2, L3, L4, L5) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5) }
  492. #define LIST_Sub_4(L1, L2, L3, L4) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4) }
  493. #define LIST_Sub_3(L1, L2, L3) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3) }
  494. #define LIST_Sub_2(L1, L2) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2) }
  495. #define LIST_Sub_1(L1) { UNWRAP_ITEM_Sub(L1) }
  496. #define LIST_Sub_(N) LIST_Sub_##N
  497. #define LIST_Sub_EVAL(N) LIST_Sub_(N)
  498. #define UNWRAP_Sub_2(...) EXPAND( LIST_Sub_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  499. //#define UNWRAP_Sub_2(...) GET_MACRO(__VA_ARGS__, LIST_Sub_16, LIST_Sub_15, LIST_Sub_14, LIST_Sub_13, LIST_Sub_12, LIST_Sub_11, LIST_Sub_10, LIST_Sub_9, LIST_Sub_8, LIST_Sub_7, LIST_Sub_6, LIST_Sub_5, LIST_Sub_4, LIST_Sub_3, LIST_Sub_2, LIST_Sub_1)(__VA_ARGS__)
  500. #define Submodels(L) SM_(UNWRAP_Sub_2 L)
  501. }
  502. }
  503. #endif