This manual was written with the intent of giving a quick reference to the suer who is using BAM v2. It does not pretend to be complete. The descriptions given here come from the MBDyn official input manual, the BAM v2 mailing lists, and the available video tutorials.
61 | To install BlenderAndMBDyn v2 (BAM) from the Blender interface go to menu File->User Preferences and at the bottom of the panel which appear click the Install from file button.
62 | The procedure is fairly straightfoward but a few details should be taken into consideration:
63 |
64 |
It is recommmended to use Blender 2.72 or newer and a recent MBDyn version;
65 |
Before reinstalling BAM, it should first be uninstalled from Blender which should also be restarted;
66 |
The software is still in development and any bug reports are welcomed on the Github page.
70 | The simplest way to learn the basics of the BAM v2 tool is to watch a few of the video tutorials.
71 | The important ones are listed here:
72 |
73 |
Crank and slider; construct, simulate, drive through the keyboard while simulating, animate while simulating, and analyze a Crank and Slider model in MBDyn.
74 |
Double pendulum; construct, simulate, and analyze a double pendulum.
75 |
Chain; construct, simulate, and analyze a four link chain.
81 | The elements section is the basis of the BAM software. You may create an element by clicking on the button and choosing from the list. If you currently have a Blender mesh object selected, it will become that element. Usually, one will start by creating a Body. Another common element which needs to be inserted is the Gravity element. The button will expand the menu to also show filtering options of the element list. The button will allow one to edit an element or see a list of its users. Double clicking on a name in the list allows to change the said name. In case of a name conflict when creating a new element, a number will be added to the end of the chosen name.
82 |
88 | A body represents a mass in the multibody model. It requires a mass value, which can be set as a variable name by ticking the checkbox. It also requires a 3x3 matrix of inertia.
89 |
90 | If no Blender mesh object is selected when creating a body, a new one will be created at the location of the cursor. Upon accepting the body creation dialog, the user is invited by the "Object specifications" dialog to modify numerically the position and orientation of the body. This is optional and, in any case, any modifications brough by the user to the associated Blender mesh object will be also applied to the body.
91 |
94 | The body element describes a lumped rigid body connected to a 6 degree of freedom
95 | structural node. The inertia matrix is always referred to the center of mass of the mass that is being added.
96 |
134 | The structural force element allows to apply a force to the selected element. It can be ither absolute or follower. And absolute force will always have the same position and orientation while the follower force will follow the object to which it is applied. The force value is defined by a driver.
135 |
187 | The clamp element is used to rigidly fixed a node in space. Use this element to create a solid ground to which moving ovjects may be attached later on.
188 |
194 | This joint implements a configuration dependent force that is exchanged between two points associated
195 | to two nodes with an offset. The force may depend, by way of a generic 3D constitutive law, on the
196 | relative position and velocity of the two points, expressed in the reference frame of node 1.
197 | The constitutive law is attached to the reference frame of node 1 (TODO: selected last?), so the sequence of the connections
198 | may matter in case of anisotropic constitutive laws, if the relative orientation of the two nodes changes
199 | during the analysis.
200 |
201 |
321 | The Gravity element is used to add a gravity force to the simulation. Many times one will want to define it as a constant drive with a value of 9.81 m/s^2. The gravity element does not get linked with any Blender mesh object. Any type of gravity may be defined by combining the required vector input with a chosen driver.
322 |
346 | The dummy structural node has been added to ease the visualization of the kinematics of arbitrary points
347 | of the system during the simulation. It does not provide any degrees of freedom, and it must be attached
348 | to another node.
349 |
350 |
421 | The user is encouraged to use such variables to simplify the creation of the model. A typical example would be to define variables of mass, length, height, and depth of a body to then be able to easily change later on the properties of that body. The values can be changed without having to manually edit all the matrices associated to that body. It becomes even more useful when one would want to scale a complete model by a factor. Mathematical operations can be done to create new variables from previously defined ones.
422 |
458 | This tab allows to create a new simulator/simulation. Only one simulation needs to be created. It can be ran multiple times. After having updated the multibody model, one can simply select the desired simulator and click the Run simulation button followed by the Animated objects button to see the new updated results.
459 |
460 |
It is recommended to initially chose a high value of steps between objects when importing the animated results because MBDyn typically has a large number of timesteps and importing all of them in Blender may take a long time.
461 |
470 | This panel allows to set the core preferences of MBDyn and the multibody simulation. By ticking the MBDyn path box, one will be able to give the path to the MBDyn executable to be used.
471 |
472 | The General_data, Output_data, and job_control allow to impose settings in a similar fashion as explained in the MBDyn manual. TODO: insert link to manual ?
473 |
474 | The default_output drop-down menu selector allows to create a set of output values that ought to be printed to the output files when the simulation is ran.
475 |
491 | Every time a "deformable"
492 | entity requires a constitutive law, a template constitutive law is read.
493 | The "deformable" elements at present are:
494 | - rod and genel spring and related elements (1D);
495 | - deformable hinge and deformable displacement joint elements (3D);
496 | - deformable joint and beam elements (6D).
497 | Constitutive laws are also used in non-structural components, to allow some degree of generality in
498 | defining input/output relationships. Some constitutive laws are meaningful only when related to some
499 | precise dimensionality. In some special cases, general purpose (genel) elements use 1D constitutive laws
500 | to express an arbitrary dependence of some value on a scalar state of the system. Table 2.7 shows the
501 | availability of each constitutive law.
502 | The meaning of the input and output parameters of a constitutive law is dictated by the entity that
503 | uses it. In general, the user should refer to the element the constitutive law is being instantiated for in
504 | order to understand what the input and the output parameters are supposed to be.
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
--------------------------------------------------------------------------------
/help/info.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/simulator.py:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------------------------
2 | # BlenderAndMBDyn
3 | # Copyright (C) 2015 G. Douglas Baldwin - http://www.baldwintechnology.com
4 | # --------------------------------------------------------------------------
5 | # ***** BEGIN GPL LICENSE BLOCK *****
6 | #
7 | # This file is part of BlenderAndMBDyn.
8 | #
9 | # BlenderAndMBDyn is free software: you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation, either version 3 of the License, or
12 | # (at your option) any later version.
13 | #
14 | # BlenderAndMBDyn is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 | #
19 | # You should have received a copy of the GNU General Public License
20 | # along with BlenderAndMBDyn. If not, see .
21 | #
22 | # ***** END GPL LICENCE BLOCK *****
23 | # --------------------------------------------------------------------------
24 |
25 | if "bpy" in locals():
26 | import imp
27 | for x in [base, menu, common, user_defined_common]:
28 | imp.reload(x)
29 | else:
30 | from . import base
31 | from . import menu
32 | from . import common
33 | from . import user_defined_common
34 | from .base import bpy, BPY, root_dot, database, Operator, Entity, Bundle
35 | from .common import FORMAT, safe_name, write_vector, write_orientation, StreamSender, StreamReceiver
36 | from .menu import default_klasses, simulator_tree
37 | from mathutils import Matrix
38 | import subprocess
39 | from tempfile import TemporaryFile
40 | import os
41 | from time import sleep
42 | import sys
43 | from signal import SIGTERM
44 | import math
45 | from mathutils import Vector, Euler, Quaternion
46 |
47 | aerodynamic_types = [
48 | "Aerodynamic body",
49 | "Aerodynamic beam2",
50 | "Aerodynamic beam3",
51 | "Generic aerodynamic force",
52 | "Induced velocity"]
53 | beam_types = [
54 | "Beam segment",
55 | "Three node beam"]
56 | force_types = [
57 | "Structural force",
58 | "Structural internal force",
59 | "Structural couple",
60 | "Structural internal couple",
61 | "Total force",
62 | "Total internal force"]
63 | genel_types = [
64 | "Swashplate"]
65 | joint_types = [
66 | "Axial rotation",
67 | "Clamp",
68 | "Distance",
69 | "Deformable displacement joint",
70 | "Deformable hinge",
71 | "Deformable joint",
72 | "In line",
73 | "In plane",
74 | "Revolute hinge",
75 | "Rod",
76 | "Spherical hinge",
77 | "Total joint",
78 | "Viscous body"]
79 | output_types = [
80 | "Stream animation",
81 | "Stream output"]
82 | environment_types = [
83 | "Air properties",
84 | "Gravity"]
85 | node_types = [
86 | "Rigid offset",
87 | "Dummy node",
88 | "Feedback node"]
89 |
90 | rigid_body_types = ["Body"]
91 |
92 | structural_static_types = aerodynamic_types + joint_types + ["Rotor"] + beam_types + force_types
93 |
94 | structural_dynamic_types = rigid_body_types
95 |
96 | class Base(Operator):
97 | bl_label = "Simulators"
98 | @classmethod
99 | def poll(cls, context):
100 | return True
101 | @classmethod
102 | def make_list(self, ListItem):
103 | bpy.types.Scene.simulator_uilist = bpy.props.CollectionProperty(type = ListItem)
104 | def update(self, context):
105 | if database.simulator and self.simulator_index < len(database.simulator):
106 | exec("bpy.ops." + root_dot + "save('INVOKE_DEFAULT')")
107 | bpy.types.Scene.simulator_index = bpy.props.IntProperty(default=-1, update=update)
108 | @classmethod
109 | def delete_list(self):
110 | del bpy.types.Scene.simulator_uilist
111 | del bpy.types.Scene.simulator_index
112 | @classmethod
113 | def get_uilist(self, context):
114 | return context.scene.simulator_index, context.scene.simulator_uilist
115 | def set_index(self, context, value):
116 | context.scene.simulator_index = value
117 | def prereqs(self, context):
118 | pass
119 | def draw_panel_post(self, context, layout):
120 | if context.scene.dirty_simulator:
121 | layout.label("Choose a simulator")
122 | else:
123 | layout.operator(root_dot + "simulate")
124 | if context.scene.clean_log:
125 | layout.operator(root_dot + "write_keyframes")
126 |
127 | klasses = default_klasses(simulator_tree, Base)
128 |
129 | class InitialValue(Entity):
130 | def write_input_file(self, context, directory):
131 | def write_structural_node(f, structural_type, node, frame):
132 | f.write("\tstructural: " + ", ".join([safe_name(node.name), structural_type]))
133 | frame_label = frame.safe_name() if frame else "global"
134 | location, orientation = node.matrix_world.translation, node.matrix_world.to_quaternion().to_matrix()
135 | if frame:
136 | orientation = frame.objects[0].matrix_world.to_quaternion().to_matrix().transposed()*orientation
137 | location = orientation * (location - frame.objects[0].matrix_world.translation)
138 | f.write(",\n\t\treference, " + frame_label)
139 | write_vector(f, location)
140 | f.write(",\n\t\treference, " + frame_label)
141 | write_orientation(f, orientation, "\t\t")
142 | f.write(",\n\t\treference, " + frame_label + ", null" +
143 | ",\n\t\treference, " + frame_label + ", null;\n")
144 | with open(os.path.join(directory, context.scene.name + ".mbd"), "w") as f:
145 | f.write("# MBDyn v1.7 input file generated using BlenderAndMBDyn v2.0\n\n")
146 | frame_for, frames, parent_of = dict(), list(), dict()
147 | reference_frames = database.input_card.filter("Reference frame")
148 | for frame in reference_frames:
149 | frame_for.update({ob : frame for ob in frame.objects[1:]})
150 | frames.append(frame)
151 | parent_of.update({frame : parent for parent in reference_frames if frame.objects[0] in parent.objects[1:]})
152 | frames_to_write = list()
153 | while frames:
154 | frame = frames.pop()
155 | if frame in parent_of and parent_of[frame] in frames:
156 | frames.appendleft(frame)
157 | else:
158 | frames_to_write.append(frame)
159 | if frames_to_write:
160 | f.write("# Frame labels:\n")
161 | for i, frame in enumerate(sorted(frames_to_write, key=lambda x: x.name)):
162 | f.write("\tset: const integer " + safe_name(frame.name) + " = " + str(i) + ";\n")
163 | else:
164 | f.write("# Frame labels: none\n")
165 | nodes = set()
166 | dummy_dict = dict()
167 | structural_dynamic_nodes = set()
168 | structural_static_nodes = set()
169 | structural_dummy_nodes = set()
170 | database.rigid_dict = {e.objects[0] : e.objects[1] for e in database.element.filter("Rigid offset") + database.element.filter(user_defined_common.offset_types)}
171 | names = [e.name for e in database.all_entities()]
172 | for e in (e for e in database.element + database.drive if hasattr(e, "objects")):
173 | ob = database.rigid_dict[e.objects[0]] if e.objects[0] in database.rigid_dict else e.objects[0]
174 | if ob.name in names:
175 | ob.name = "Node"
176 | nodes |= set([ob])
177 | if e.type in structural_dynamic_types + user_defined_common.structural_dynamic_types:
178 | structural_dynamic_nodes |= set([ob])
179 | elif e.type in structural_static_types + user_defined_common.structural_static_types:
180 | structural_static_nodes |= set([ob])
181 | elif e.type == "Dummy":
182 | structural_dummy_nodes |= set([ob])
183 | dummy_dict[ob] = e.objects[1]
184 | structural_static_nodes -= structural_dynamic_nodes | structural_dummy_nodes
185 | database.node.clear()
186 | database.node.extend(sorted(nodes, key=lambda x: x.name))
187 | if database.node:
188 | f.write("\n# Node labels:\n")
189 | for i, node in enumerate(database.node):
190 | f.write("\tset: const integer " + safe_name(node.name) + " = " + str(i) + ";\n")
191 | else:
192 | f.write("\n# Node labels: none\n")
193 | if database.element:
194 | f.write("\n# Element labels:\n")
195 | for i, element in enumerate(sorted(database.element, key=lambda x: x.name)):
196 | f.write("\tset: const integer " + element.safe_name() + " = " + str(i) + ";\n")
197 | else:
198 | f.write("\n# Element labels: none\n")
199 | if database.drive:
200 | f.write("\n# Drive labels:\n")
201 | for i, drive in enumerate(sorted(database.drive, key=lambda x: x.name)):
202 | f.write("\tset: const integer " + drive.safe_name() + " = " + str(i) + ";\n")
203 | else:
204 | f.write("\n# Drive labels: none\n")
205 | if database.driver:
206 | f.write("\n# Driver labels:\n")
207 | for i, driver in enumerate(sorted(database.driver, key=lambda x: x.name)):
208 | f.write("\tset: const integer " + driver.safe_name() + " = " + str(i) + ";\n")
209 | else:
210 | f.write("\n# Driver labels: none\n")
211 | if database.constitutive:
212 | f.write("\n# Constitutive labels:\n")
213 | for i, constitutive in enumerate(sorted(database.constitutive, key=lambda x: x.name)):
214 | f.write("\tset: const integer " + constitutive.safe_name() + " = " + str(i) + ";\n")
215 | else:
216 | f.write("\n# Constitutive labels: none\n")
217 | set_cards = database.input_card.filter("Set")
218 | if set_cards:
219 | f.write("\n# Parameters:\n")
220 | for set_card in set_cards:
221 | set_card.write(f)
222 | else:
223 | f.write("\n# Parameters: none\n")
224 | module_load_cards = database.input_card.filter("Module load")
225 | if module_load_cards:
226 | f.write("\n# Modules:\n")
227 | for module_load_card in module_load_cards:
228 | module_load_card.write(f)
229 | else:
230 | f.write("\n# Modules: none\n")
231 | structural_node_count = len(structural_static_nodes | structural_dynamic_nodes | structural_dummy_nodes)
232 | joint_count = len([e for e in database.element if e.type in joint_types])
233 | output_count = len([e for e in database.element if e.type in output_types])
234 | force_count = len([e for e in database.element if e.type in force_types])
235 | rigid_body_count = len([e for e in database.element if e.type in rigid_body_types])
236 | aerodynamic_element_count = len([e for e in database.element if e.type in aerodynamic_types])
237 | rotor_count = len([e for e in database.element if e.type in ["Rotor"]])
238 | genel_count = len([e for e in database.element if e.type in genel_types])
239 | beam_count = len([e for e in database.element if e.type in beam_types and not hasattr(e, "consumer")])
240 | air_properties = bool([e for e in database.element if e.type in ["Air properties"]])
241 | gravity = bool([e for e in database.element if e.type in ["Gravity"]])
242 | loadable_element_count = len([e for e in database.element if e.type in user_defined_common.loadable_element_types])
243 | file_driver_count = len(database.driver)
244 | bailout_upper = False
245 | upper_bailout_time = 0.0
246 | # electric_node_count = len([e for e in database.ns_node if e.type in ["Electric"]])
247 | # abstract_node_count = len([e for e in database.ns_node if e.type in ["Abstract"]])
248 | # hydraulic_node_count = len([e for e in database.ns_node if e.type in ["Hydraulic"]])
249 | # parameter_node_count = len([e for e in database.ns_node if e.type in ["Parameter"]])
250 | f.write(
251 | "\nbegin: data" +
252 | ";\n\tproblem: initial value" +
253 | ";\nend: data" +
254 | ";\n\nbegin: initial value" +
255 | ";\n\tinitial time: " + (BPY.FORMAT(self.initial_time) if self.initial_time is not None else "0") +
256 | ";\n\tfinal time: " + (BPY.FORMAT(self.final_time) if self.final_time is not None else "forever") +
257 | ";\n")
258 | for a in [self.general_data, self.method, self.nonlinear_solver, self.eigenanalysis, self.abort_after, self.linear_solver, self.dummy_steps, self.output_data, self.real_time]:
259 | if a is not None:
260 | a.write(f)
261 | f.write("end: initial value;\n" +
262 | "\nbegin: control data;\n")
263 | for a in [self.assembly, self.job_control, self.default_output, self.default_aerodynamic_output, self.default_beam_output]:
264 | if a is not None:
265 | a.write(f)
266 | if structural_node_count:
267 | f.write("\tstructural nodes: " + str(structural_node_count) + ";\n")
268 | """
269 | if electric_node_count:
270 | f.write("\telectric nodes: " + str(electric_node_count) + ";\n")
271 | if abstract_node_count:
272 | f.write("\tabstract nodes: " + str(abstract_node_count) + ";\n")
273 | if hydraulic_node_count:
274 | f.write("\thydraulic nodes: " + str(hydraulic_node_count) + ";\n")
275 | """
276 | if joint_count:
277 | f.write("\tjoints: " + str(joint_count) + ";\n")
278 | if output_count:
279 | f.write("\toutput elements: " + str(output_count) + ";\n")
280 | if force_count:
281 | f.write("\tforces: " + str(force_count) + ";\n")
282 | if genel_count:
283 | f.write("\tgenels: " + str(genel_count) + ";\n")
284 | if beam_count:
285 | f.write("\tbeams: " + str(beam_count) + ";\n")
286 | if rigid_body_count:
287 | f.write("\trigid bodies: " + str(rigid_body_count) + ";\n")
288 | if air_properties:
289 | f.write("\tair properties;\n")
290 | if gravity:
291 | f.write("\tgravity;\n")
292 | if aerodynamic_element_count:
293 | f.write("\taerodynamic elements: " + str(aerodynamic_element_count) + ";\n")
294 | if rotor_count:
295 | f.write("\trotors: " + str(rotor_count) + ";\n")
296 | if file_driver_count:
297 | f.write("\tfile drivers: " + str(file_driver_count) + ";\n")
298 | if loadable_element_count:
299 | f.write("\tloadable elements: " + str(loadable_element_count) + ";\n")
300 | f.write("end: control data;\n")
301 | if frames_to_write:
302 | f.write("\n# Frames:\n")
303 | for frame in frames_to_write:
304 | frame.write(f, parent_of[frame] if frame in parent_of else None)
305 | if database.node:
306 | f.write("\nbegin: nodes;\n")
307 | for node in structural_static_nodes:
308 | write_structural_node(f, "static", node, frame_for[node] if node in frame_for else None)
309 | for node in structural_dynamic_nodes:
310 | write_structural_node(f, "dynamic", node, frame_for[node] if node in frame_for else None)
311 | for node in structural_dummy_nodes:
312 | base_node = dummy_dict[node]
313 | rot = base_node.matrix_world.to_quaternion().to_matrix()
314 | globalV = node.matrix_world.translation - base_node.matrix_world.translation
315 | localV = rot*globalV
316 | rotT = node.matrix_world.to_quaternion().to_matrix()
317 | f.write("\tstructural: " + str(database.node.index(node)) + ", dummy,\n\t\t" +
318 | str(database.node.index(base_node)) + ", offset,\n\t\t\t")
319 | write_vector(f, localV, prepend=False)
320 | write_orientation(f, rot*rotT, "\t\t\t")
321 | f.write(";\n")
322 | """
323 | for i, ns_node in enumerate(self.ns_node):
324 | if ns_node.type == "Electric":
325 | f.write("\telectric: " + str(i) + ", value, " + str(ns_node._args[0]))
326 | if ns_node._args[1]: f.write(", derivative, " + str(ns_node._args[2]))
327 | f.write(";\n")
328 | if ns_node.type == "Abstract":
329 | f.write("\tabstract: " + str(i) + ", value, " + str(ns_node._args[0]))
330 | if ns_node._args[1]: f.write(", differential, " + str(ns_node._args[2]))
331 | f.write(";\n")
332 | if ns_node.type == "Hydraulic":
333 | f.write("\thydraulic: " + str(i) + ", value, " + str(ns_node._args[0]) + ";\n")
334 | """
335 | f.write("end: nodes;\n")
336 | if file_driver_count:
337 | f.write("\nbegin: drivers;\n")
338 | for driver in database.driver:
339 | driver.write(f)
340 | f.write("end: drivers;\n")
341 | if database.function:
342 | f.write("\n# Functions:\n")
343 | for function in sorted(database.function, key=lambda x: x.name):
344 | function.write(f)
345 | if database.drive:
346 | f.write("\n# Drives:\n")
347 | for drive in database.drive:
348 | if drive.dimension == "1D":
349 | f.write("\tdrive caller: " + ", ".join([drive.safe_name(), drive.string()]) + ";\n")
350 | else:
351 | dim_name = {"3D": "\"3\"", "6D": "\"6\"", "3x3": "\"3x3\"", "6x6": "\"6x6\""}[drive.dimension]
352 | f.write("\ttemplate drive caller: " + ", ".join([drive.safe_name(), dim_name, drive.string()]) + ";\n")
353 | if database.constitutive:
354 | f.write("\n# Constitutives:\n")
355 | for constitutive in database.constitutive:
356 | f.write("\tconstitutive law: " + ", ".join([constitutive.safe_name(), constitutive.dimension[0], constitutive.string()]) + ";\n")
357 | if database.element:
358 | f.write("\nbegin: elements;\n")
359 | try:
360 | for element_type in aerodynamic_types + beam_types + ["Body"] + force_types + genel_types + joint_types + ["Rotor"] + environment_types + user_defined_common.loadable_element_types + ["Driven"] + output_types:
361 | for element in database.element:
362 | if element.type == element_type:
363 | element.write(f)
364 | except Exception as e:
365 | print(e)
366 | f.write(str(e) + "\n")
367 | f.write("end: elements;\n")
368 | del database.rigid_dict
369 | del dummy_dict
370 |
371 | class InitialValueOperator(Base):
372 | bl_label = "Initial value"
373 | mbdyn_path = bpy.props.PointerProperty(type=BPY.Str)
374 | initial_time = bpy.props.PointerProperty(type=BPY.Float)
375 | final_time = bpy.props.PointerProperty(type=BPY.Float)
376 | general_data = bpy.props.PointerProperty(type=BPY.Definition)
377 | method = bpy.props.PointerProperty(type=BPY.Definition)
378 | nonlinear_solver = bpy.props.PointerProperty(type=BPY.Definition)
379 | eigenanalysis = bpy.props.PointerProperty(type=BPY.Definition)
380 | abort_after = bpy.props.PointerProperty(type=BPY.Definition)
381 | linear_solver = bpy.props.PointerProperty(type=BPY.Definition)
382 | dummy_steps = bpy.props.PointerProperty(type=BPY.Definition)
383 | output_data = bpy.props.PointerProperty(type=BPY.Definition)
384 | real_time = bpy.props.PointerProperty(type=BPY.Definition)
385 | assembly = bpy.props.PointerProperty(type=BPY.Definition)
386 | job_control = bpy.props.PointerProperty(type=BPY.Definition)
387 | default_output = bpy.props.PointerProperty(type=BPY.Definition)
388 | default_aerodynamic_output = bpy.props.PointerProperty(type=BPY.Definition)
389 | default_beam_output = bpy.props.PointerProperty(type=BPY.Definition)
390 | def prereqs(self, context):
391 | self.mbdyn_path.assign(BPY.mbdyn_path)
392 | self.final_time.select, self.final_time.value = True, 10.0
393 | self.general_data.type = "General data"
394 | self.general_data.mandatory = True
395 | self.general_data_exists(context)
396 | self.method.type = "Method"
397 | self.nonlinear_solver.type = "Nonlinear solver"
398 | self.eigenanalysis.type = "Eigenanalysis"
399 | self.abort_after.type = "Abort after"
400 | self.linear_solver.type = "Linear solver"
401 | self.dummy_steps.type = "Dummy steps"
402 | self.output_data.type = "Output data"
403 | self.output_data.mandatory = True
404 | self.output_data_exists(context)
405 | self.real_time.type = "Real time"
406 | self.assembly.type = "Assembly"
407 | self.job_control.type = "Job control"
408 | self.job_control.mandatory = True
409 | self.job_control_exists(context)
410 | self.default_output.type = "Default output"
411 | self.default_output.mandatory = True
412 | self.default_output_exists(context)
413 | self.default_aerodynamic_output.type = "Default aerodynamic output"
414 | self.default_beam_output.type = "Default beam output"
415 | def assign(self, context):
416 | self.mbdyn_path.assign(self.entity.mbdyn_path)
417 | self.initial_time.assign(self.entity.initial_time)
418 | self.final_time.assign(self.entity.final_time)
419 | self.general_data.assign(self.entity.general_data)
420 | self.method.assign(self.entity.method)
421 | self.nonlinear_solver.assign(self.entity.nonlinear_solver)
422 | self.eigenanalysis.assign(self.entity.eigenanalysis)
423 | self.abort_after.assign(self.entity.abort_after)
424 | self.linear_solver.assign(self.entity.linear_solver)
425 | self.dummy_steps.assign(self.entity.dummy_steps)
426 | self.output_data.assign(self.entity.output_data)
427 | self.real_time.assign(self.entity.real_time)
428 | self.assembly.assign(self.entity.assembly)
429 | self.job_control.assign(self.entity.job_control)
430 | self.default_output.assign(self.entity.default_output)
431 | self.default_aerodynamic_output.assign(self.entity.default_aerodynamic_output)
432 | self.default_beam_output.assign(self.entity.default_beam_output)
433 | def store(self, context):
434 | self.entity.mbdyn_path = BPY.mbdyn_path = self.mbdyn_path.store()
435 | self.entity.initial_time = self.initial_time.store()
436 | self.entity.final_time = self.final_time.store()
437 | self.entity.general_data = self.general_data.store()
438 | self.entity.method = self.method.store()
439 | self.entity.nonlinear_solver = self.nonlinear_solver.store()
440 | self.entity.eigenanalysis = self.eigenanalysis.store()
441 | self.entity.abort_after = self.abort_after.store()
442 | self.entity.linear_solver = self.linear_solver.store()
443 | self.entity.dummy_steps = self.dummy_steps.store()
444 | self.entity.output_data = self.output_data.store()
445 | self.entity.real_time = self.real_time.store()
446 | self.entity.assembly = self.assembly.store()
447 | self.entity.job_control = self.job_control.store()
448 | self.entity.default_output = self.default_output.store()
449 | self.entity.default_aerodynamic_output = self.default_aerodynamic_output.store()
450 | self.entity.default_beam_output = self.default_beam_output.store()
451 | def pre_finished(self, context):
452 | exec("bpy.ops." + root_dot + "save('INVOKE_DEFAULT')")
453 | def draw(self, context):
454 | layout = self.layout
455 | self.mbdyn_path.draw(layout, "MBDyn path", "Set")
456 | self.initial_time.draw(layout, "Initial time")
457 | self.final_time.draw(layout, "Final time")
458 | self.general_data.draw(layout, "General data")
459 | self.method.draw(layout, "Method", "Set")
460 | self.nonlinear_solver.draw(layout, "Nonlinear solver", "Set")
461 | self.eigenanalysis.draw(layout, "Eigenanalysis", "Set")
462 | self.abort_after.draw(layout, "Abort after", "Set")
463 | self.linear_solver.draw(layout, "Linear solver", "Set")
464 | self.dummy_steps.draw(layout, "Dummy steps", "Set")
465 | self.output_data.draw(layout, "Output data", "Set")
466 | self.real_time.draw(layout, "Real time", "Set")
467 | self.assembly.draw(layout, "Assembly", "Set")
468 | self.job_control.draw(layout, "Job control", "Set")
469 | self.default_output.draw(layout, "Default output", "Set")
470 | self.default_aerodynamic_output.draw(layout, "Default aerodynamic output", "Set")
471 | self.default_beam_output.draw(layout, "Default beam output", "Set")
472 | def check(self, context):
473 | return (True in [x.check(context) for x in [self.mbdyn_path, self.initial_time, self.final_time, self.general_data, self.method, self.nonlinear_solver, self.eigenanalysis, self.abort_after, self.linear_solver, self.dummy_steps, self.output_data, self.real_time, self.assembly, self.default_output, self.default_aerodynamic_output, self.default_beam_output]])
474 | def create_entity(self):
475 | return InitialValue(self.name)
476 |
477 | klasses[InitialValueOperator.bl_label] = InitialValueOperator
478 |
479 | class Save(bpy.types.Operator, Base):
480 | bl_idname = root_dot + "save"
481 | bl_options = {'REGISTER', 'INTERNAL'}
482 | bl_label = "Save Blender File"
483 | filter_glob = bpy.props.StringProperty(
484 | default="*.blend",
485 | options={'HIDDEN'},
486 | )
487 | filepath = bpy.props.StringProperty()
488 | def invoke(self, context, event):
489 | if not context.blend_data.filepath:
490 | self.filepath = "untitled.blend"
491 | context.window_manager.fileselect_add(self)
492 | return {'RUNNING_MODAL'}
493 | self.filepath = context.blend_data.filepath
494 | return self.execute(context)
495 | def execute(self, context):
496 | directory = os.path.splitext(self.filepath)[0]
497 | if not os.path.exists(directory):
498 | os.mkdir(directory)
499 | database.simulator[context.scene.simulator_index].write_input_file(context, directory)
500 | bpy.ops.object.select_all(action='DESELECT')
501 | for node in database.node:
502 | node.select = True
503 | bpy.ops.wm.save_mainfile(filepath=self.filepath)
504 | context.scene.dirty_simulator = False
505 | context.scene.clean_log = False
506 | return{'FINISHED'}
507 | BPY.klasses.append(Save)
508 |
509 | class Simulate(bpy.types.Operator, Base):
510 | bl_idname = root_dot + "simulate"
511 | bl_options = {'REGISTER', 'INTERNAL'}
512 | bl_label = "Run simulation"
513 | bl_description = "Run MBDyn for the input file"
514 | def modal(self, context, event):
515 | if not (event.type in ['ESC', 'TIMER'] or (hasattr(self, "channels") and event.type in self.channels)):
516 | return {'PASS_THROUGH'}
517 | if event.type == 'ESC':
518 | return self.close(context)
519 | #self.report({'INFO'}, self.process.stdout.read().decode())
520 | if hasattr(self, "sender") and event.type in self.channels:
521 | i, dv = self.channels[event.type]
522 | self.values[i] += dv
523 | try:
524 | self.sender.send(self.values)
525 | except BrokenPipeError:
526 | return self.close(context)
527 | if hasattr(self, "receiver"):
528 | data = self.receiver.get_data()
529 | for i, node in enumerate(self.nodes):
530 | node.location = Vector(data[12*i : 12*i+3])
531 | node.rotation_euler = Matrix([data[12*i+3 : 12*i+6], data[12*i+6 : 12*i+9], data[12*i+9 : 12*i+12]]).to_euler(node.rotation_euler.order)
532 | if self.process.poll() == None:
533 | if self.platform != "win32":
534 | output = subprocess.check_output(("tail", "-n", "1", self.out_file))
535 | if output and 2 < len(output.split()):
536 | percent = 100.*(1.-(self.t_final - float(output.split()[2]))/self.t_range)
537 | context.window_manager.progress_update(percent)
538 | return {'PASS_THROUGH'}
539 | else:
540 | return self.close(context)
541 | def close(self, context):
542 | wm = context.window_manager
543 | wm.event_timer_remove(self.timer)
544 | if hasattr(self, "nodes"):
545 | for preserved, node in zip(self.preserve, self.nodes):
546 | node.location, node.rotation_euler = preserved
547 | del self.nodes
548 | try:
549 | stdout, stderr = self.process.communicate(timeout=1)
550 | except subprocess.TimeoutExpired:
551 | self.process.terminate()
552 | stdout, stderr = self.process.communicate()
553 | del self.process
554 | if stdout:
555 | self.report({'INFO'}, stdout.decode())
556 | if stderr:
557 | self.report({'INFO'}, stderr.decode())
558 | if hasattr(self, "receiver"):
559 | self.receiver.close()
560 | if hasattr(self, "sender"):
561 | self.sender.close()
562 | context.scene.clean_log = True
563 | context.scene.mbdyn_default_orientation = database.simulator[context.scene.simulator_index].job_control.default_orientation
564 | BPY.plot_data.clear()
565 | wm.progress_end()
566 | return {'FINISHED'}
567 | def execute(self, context):
568 | sim = database.simulator[context.scene.simulator_index]
569 | directory = os.path.splitext(context.blend_data.filepath)[0]
570 | command = [sim.mbdyn_path if sim.mbdyn_path is not None else "mbdyn", "-s", "-f", os.path.join(directory, context.scene.name + ".mbd")]
571 | self.report({'INFO'}, " ".join(command))
572 | animation = database.element.filter("Stream animation")
573 | events = database.driver.filter("Event stream")
574 | drives = database.drive.filter("Event drive")
575 | if drives:
576 | self.values = [d.initial_value for d in drives]
577 | self.channels = {d.increment : (i, 1) for i, d in enumerate(drives)}
578 | self.channels.update({d.decrement : (i, -1) for i, d in enumerate(drives)})
579 | self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
580 | if events:
581 | host_name, port_number = events[0].host_name, events[0].port_number
582 | self.sender = StreamSender(host_name=host_name, port_number=port_number)
583 | self.sender.send(self.values)
584 | if animation:
585 | host_name, port_number, self.nodes = animation[0].host_name, animation[0].port_number, animation[0].objects if hasattr(animation[0], "objects") else database.node
586 | self.preserve = [(n.location.copy(), n.rotation_euler.copy()) for n in self.nodes]
587 | initial_data = list()
588 | for v, e in self.preserve:
589 | initial_data.extend(v.to_tuple())
590 | for row in e.to_matrix():
591 | initial_data.extend(row)
592 | self.receiver = StreamReceiver('d'*12*len(self.nodes), initial_data, host_name=host_name, port_number=port_number)
593 | if self.receiver.socket:
594 | self.receiver.start()
595 | else:
596 | self.report({'INFO'}, "Animation stream socket failed to connect")
597 | del self.receiver
598 | self.out_file = os.path.join(directory, context.scene.name + ".out")
599 | self.t_final = sim.final_time if sim.final_time is not None else float("inf")
600 | self.t_range = self.t_final - (sim.initial_time if sim.initial_time is not None else 0.0)
601 | while not os.path.exists(self.out_file):
602 | sleep(0.5)
603 | wm = context.window_manager
604 | wm.progress_begin(0., 100.)
605 | self.timer = wm.event_timer_add(1./24., context.window)
606 | wm.modal_handler_add(self)
607 | self.platform = sys.platform
608 | return{'RUNNING_MODAL'}
609 | BPY.klasses.append(Simulate)
610 |
611 | class FileWrapper:
612 | def __init__(self, file):
613 | self.file = file
614 | self.pos = 0
615 | self.size = self.file.seek(0, 2)
616 | self.file.seek(0, 0)
617 | def __next__(self):
618 | line = next(self.file)
619 | self.pos += len(line)
620 | return line
621 | def __iter__(self):
622 | line = next(self.file)
623 | while line:
624 | self.pos += len(line)
625 | yield line
626 | line = next(self.file)
627 | def close(self):
628 | self.file.close()
629 | def seek(self, *args, **kwargs):
630 | self.file.seek(*args, **kwargs)
631 |
632 | class WriteKeyframes(bpy.types.Operator, Base):
633 | bl_idname = root_dot + "write_keyframes"
634 | bl_options = {'REGISTER', 'INTERNAL'}
635 | bl_label = "Write keyframes"
636 | bl_description = "Import each node's location and orientation into Blender keyframes starting at the next frame"
637 | steps = bpy.props.IntProperty(name="MBDyn steps between Blender keyframes", default=1, min=1)
638 | rate = bpy.props.IntProperty(name="Keyframes per MBDyn second", default=15, min=1)
639 | def invoke(self, context, event):
640 | return context.window_manager.invoke_props_dialog(self)
641 | def insert_keyframe(self, label, fields):
642 | database.node[label].location = fields[:3]
643 | if self.orientation == "orientation matrix":
644 | euler = Matrix([fields[3:6], fields[6:9], fields[9:12]]).to_euler()
645 | database.node[label].rotation_euler = euler[0], euler[1], euler[2]
646 | elif self.orientation == "euler321":
647 | database.node[label].rotation_euler = Euler((math.radians(fields[5]), math.radians(fields[4]), math.radians(fields[3])), 'XYZ')
648 | elif self.orientation == "euler123":
649 | database.node[label].rotation_euler = Euler((math.radians(fields[3]), math.radians(fields[4]), math.radians(fields[5])), 'ZYX').to_quaternion().to_euler('XYZ')
650 | #database.node[label].rotation_mode = 'ZYX'
651 | elif self.orientation == "orientation vector":
652 | #database.node[label].rotation_axis_angle = [math.sqrt(sum([x*x for x in fields[3:6]]))] + fields[3:6]
653 | database.node[label].rotation_euler = Quaternion(fields[3:6], math.sqrt(sum([x*x for x in fields[3:6]]))).to_euler('XYZ')
654 | for data_path in "location rotation_euler".split():
655 | database.node[label].keyframe_insert(data_path)
656 | def execute(self, context):
657 | self.orientation = database.simulator[context.scene.simulator_index].job_control.default_orientation
658 | if self.orientation == "euler313":
659 | self.report({'ERROR'}, "euler313 cannot be imported. Simulate in another format, selected from Job Control -> Default Orientation")
660 | scene = context.scene
661 | frame_initial = scene.frame_current
662 | wm = context.window_manager
663 | wm.progress_begin(0., 100.)
664 | directory = os.path.splitext(context.blend_data.filepath)[0]
665 | dt = 1.0 / self.rate
666 | keytime = - float("inf")
667 | parser = lambda l: (int(l[0]), [float(x) for x in l[1:]])
668 | with open(os.path.join(directory, scene.name + ".out")) as f_out, open(os.path.join(directory, scene.name + ".mov")) as f_mov:
669 | label, fields = parser(f_mov.readline().split())
670 | fw_out = FileWrapper(f_out)
671 | for step, time in map(lambda l: (int(l[1]), float(l[2])), map(str.split, filter(lambda ln: ln.startswith("Step"), fw_out))):
672 | is_a_keyframe = dt < time - keytime
673 | if is_a_keyframe:
674 | keytime = time
675 | scene.frame_current += 1
676 | wm.progress_update(100. * float(fw_out.pos) / float(fw_out.size))
677 | labels = list()
678 | while f_mov and label not in labels:
679 | if is_a_keyframe:
680 | self.insert_keyframe(label, fields)
681 | labels.append(label)
682 | split_line = f_mov.readline().split()
683 | if split_line:
684 | label, fields = parser(split_line)
685 | for node in database.node:
686 | node.rotation_mode = 'XYZ'
687 | scene.frame_current = frame_initial + 1
688 | wm.progress_end()
689 | return{'FINISHED'}
690 | def draw(self, context):
691 | layout = self.layout
692 | #layout.label("File has " + str(int(self.N/(self.i+1))) + " timesteps.")
693 | layout.prop(self, "rate")
694 | BPY.klasses.append(WriteKeyframes)
695 |
696 | bundle = Bundle(simulator_tree, Base, klasses, database.simulator)
697 |
--------------------------------------------------------------------------------