Package mbdyn :: Package bindings :: Module main :: Class WraptMBDyn
[hide private]

Class WraptMBDyn

source code

The MBDyn service for Python. WraptMBDyn can run only if it receives a MBDyn input file. In case the input file is not in the current directory, the path has to be given by working_dir. Like in MBDyn, the output file can be omitted. By defaults the results file are not written, so the simulation is going faster and this is the user duty to choose what he wants to save. The mbdyn module offers an interface for those functionalities. This behavior can be turned off by write_mbdyn_files.

WraptMBDyn performs 4 calls that are empty, because they do not deal with its work, but they are use for an interface. They are:

The first user of those calls is Simulation but the user could develop what he wants.

The MBDyn object tree is available once the init method has been called. Then the integration can be completely performed by run_full or until a particular time run_until. An demonstration of use for the file 'cantilever1' from the MBDyn tutorial saved in the directory 'input_file':
   >>> from mbdyn import *
   >>> wm = WraptMBDyn("cantilever1", "input_file")
   >>> wm.init()
   ..
   >>> wm
   [elts,
   nodes]
   >>> wm.write_mbdyn_files(True)
   >>> wm.run_until(3.)
   MBDyn progress:  49% [###########################                             ] 
   >>> wm.solver.current_time
   2.999000072479248
   >>> wm.run_full()
   MBDyn progress: 100% [########################################################] 
   End of simulation at time  6.0  after  6000  steps
   total iterations:  6075
   total Jacobians:  6075
   total error:  0.002095883945
   CPU time consumed:  6.98  seconds
Nevertheless run_until is interesting only for an operation not run at each time step, else a reference to update should be supplied.

Instance Methods [hide private]
 
__init__(self, input_file=None, working_dir='.', output_file=None, write_output_files=False) source code
 
_get_output_file(self)
Return the output file name for MBDyn
source code
 
create_swig_mbdyn(self, input_file, working_dir='.', output_file=None)
Create MBDyn in its SWIG version
source code
 
write_mbdyn_files(self, boolean)
Tell if the MBDyn result files, in ASCII, need to be written or not, by default there are not.
source code
 
init(self)
Start the communication with MBDyn objects.
source code
 
_get_items(self)
Scan the reference frames, nodes and elements from the DataManager and create a tree of objects.
source code
 
_get_item_groups(self)
Create all the groups existing in MBDyn.
source code
 
_fill_item_groups(self)
Fill the created groups of MBDyn object references.
source code
 
_set_group_as_attributes(self)
Create the interface tree for nodes and elements.
source code
 
_try_get_frames(self)
Create the reference frames tree in case the input file has some.
source code
 
__repr__(self)
Return the representation of the object tree
source code
 
do_as_init(self)
Not used on WraptMBDyn called during the init method.
source code
 
update(self)
Called before starting a new MBDyn time step.
source code
 
save(self)
This is not the job of WraptMBDyn but called before to start the integration and at the end of each time step
source code
 
final_action(self)
The final call at the end of the integration.
source code
 
_check_status(self)
Check if the first step has been run, else restart the progress bar
source code
 
run_full(self)
Run the simulation until the end
source code
 
run_until(self, t_stop)
Run until the stop time.
source code
 
_run_first_step(self)
Run the MBDyn first step.
source code
 
run_one_step(self)
Run one MBDyn integration step.
source code
 
_output_final_message(self)
Output the MBDyn final message.
source code
Method Details [hide private]

write_mbdyn_files(self, boolean)

source code 
Tell if the MBDyn result files, in ASCII, need to be written or not, by default there are not. The simulation will run faster but the saving process will have to be handled by the user script or mbdyn.

init(self)

source code 
Start the communication with MBDyn objects. First the MBDyn solver is created, which corresponds to the main function of 'mbdyn.cc'. The important solver attributes for the interface are:
  • current_time
  • time_step
  • final_time
current_time and time_step are updated at each step. The solver will run the input file parsing and thus fill the DataManager. The tree for navigating the MBDyn objects is then created in _get_items. Finally, the customizable do_as_init method is called during that step.

_get_items(self)

source code 
Scan the reference frames, nodes and elements from the DataManager and create a tree of objects. The process is organised as follow:
  1. Get the all groups for nodes and elements, this step is done by _get_item_groups.
  2. Fill those groups with a general class for nodes and elements, defined in mbdyn.bindings.basic_objects. _fill_item_groups do that part.
  3. Every group try to convert the top reference into a more a more specific one. This part is contained in try_to_convert of Groups.
  4. Nodes and elements can now be accessed on the instance by _set_group_as_attributes
  5. The simulation may have reference frames, it will be tested in _try_get_frames

_get_item_groups(self)

source code 
Create all the groups existing in MBDyn. For each possible group of nodes or elements, ask to the DataManager the number of items. If there is at least one, the corresponding group defined in mbdyn.bindings.groups is created.

_fill_item_groups(self)

source code 
Fill the created groups of MBDyn object references. The two classes used are Node and Element from mbdyn.bindings.basic_objects

_set_group_as_attributes(self)

source code 
Create the interface tree for nodes and elements. Each created group of nodes or elements gets its attribute name set on its corresponding Groups, nodes or elts. Those last ones are as well set on the WraptMBDyn.

_try_get_frames(self)

source code 
Create the reference frames tree in case the input file has some. This method manipulates the MBDynParser for getting the ReferenceFrame references and fill the FramesList

update(self)

source code 
Called before starting a new MBDyn time step. This method is empty for WraptMBDyn but is of use in case the user wants to do change the MBDyn objects at run time.

final_action(self)

source code 
The final call at the end of the integration. For WraptMBDyn, nothing is done in that step but it may be of use for the class manipulating the service.

run_until(self, t_stop)

source code 
Run until the stop time. Note that this method has to be used with care. If the stop time is over the final time, the integration will anyway continue.

_run_first_step(self)

source code 
Run the MBDyn first step. The reason of that method is in the MBDyn source code, the first step is run separately.

run_one_step(self)

source code 
Run one MBDyn integration step. The update method is called before a new time step. The save method is called after a time step. The final_action is called when the integration is finished.

_output_final_message(self)

source code 
Output the MBDyn final message. This step could not be any more done in C++ because the progress bar needed to be stopped before writing a message.