#include <rod_structure.h>
Public Member Functions | |
Rod (int length, int set_rod_no) | |
Rod (std::string path, int set_rod_no) | |
Rod | set_units () |
Rod | compute_rest_energy () |
Rod | do_timestep (RngStream rng[]) |
Rod | add_force (float force[4], int node_index) |
Rod | pin_node (bool pin_state, int node_index) |
Rod | load_header (std::string filename) |
Rod | load_contents (std::string filename) |
Rod | write_frame_to_file () |
Rod | write_array (float *array_ptr, int array_len, float unit_scale_factor) |
Rod | write_mat_params_array (float *array_ptr, int array_len, float stretch_scale_factor, float twist_scale_factor, float length_scale_factor) |
Rod | change_filename (std::string new_filename) |
Rod | equilibrate_rod (RngStream rng[]) |
Rod | translate_rod (float *r, float translation_vec[3]) |
Rod | rotate_rod (float euler_angles[3]) |
Rod | scale_rod (float scale) |
Rod | get_centroid (float *r, float centroid[3]) |
Rod | get_min_max (float *r, OUT float min[3], float max[3]) |
Rod | get_p (int index, OUT float p[3], bool equil) |
rod::Rod::Rod | ( | int | length, |
int | set_rod_no | ||
) |
Rod –— Create a rod of a known length. The rod_no is an arbitrary identifier. Note that this creates a rod without initialising the contents of the arrays.
rod::Rod::Rod | ( | std::string | path, |
int | set_rod_no | ||
) |
Create a rod from a file. This won't do anything other than create the object - it won't even set up any arrays, because it doesn't know how long they'll have to be. After this, you have to call load_header and load_contents, which actually do the dirty work.When we initialize from a file, we don't allocate arrays until we've loaded the file.
Rod rod::Rod::add_force | ( | float | force[4], |
int | node_index | ||
) |
Add a constant force that acts upon the rod every timestep. Parameters: force[4], a 4-element array that specifies a 3-D force vector, with the last element being a torque instead. Node_index: the index of the node to apply these forces on. Note: to remove the force, you must call this function again with 0s, or it will continue appyling the force.
Referenced by ffea_test::euler_beam().
Rod rod::Rod::change_filename | ( | std::string | new_filename | ) |
Close the previous file and create a new file, assigning that to the rod variable *file_ptr. This will also copy the contents of the previous file into this one.
Check if output file exists
Get contents of current file
Create new file
Update member variables (filename, pointer etc)
Referenced by ffea_test::euler_beam(), and World::rod_from_block().
Rod rod::Rod::compute_rest_energy | ( | ) |
Updates ---—— Do a timestep. This function contains two loops. Both are over the nodes. The first loop populates the contents of the energy arrays, which int we use to work out delta E. The second one uses those energies to compute dynamics and applies those dynamics to the position arrays.
Referenced by ffea_test::connection_propagation(), equilibrate_rod(), ffea_test::euler_beam(), World::run(), and ffea_test::twist_bend_coil().
Run the simulation for an arbitrary amount of time. If you start a rod exactly in its equilibrium state, chances are it's not going to be equilibrated, which can throw off some tests. It runs for a totally arbitrary 1e-7 seconds and does not save the trajectory from the equilibration.
Rod rod::Rod::get_centroid | ( | float * | r, |
float | centroid[3] | ||
) |
Get a centroid for the current frame of the rod. Note: you must supply an array (either current_r or equil_r).
Referenced by World::get_system_centroid().
Referenced by World::get_system_dimensions().
Rod rod::Rod::load_contents | ( | std::string | filename | ) |
Load the current state of the rod. This function expects that load_header has already been called. This populates all of the already-initialised arrays containing the state of the rod. Note that it only contains the current state of the rod - the FFEA_rod python class is the only one that loads the rod trajectory.
Make sure this method isn't called before loading header info
Get the line number of the last frame
Check that we got the last frame
Seek back to the start of the file
Find the last frame from the line number we got earlier
Convert each string into a vector<string>
Then convert that into a vector<float>
Check we're not going to overflow and ruin someone's life when we write into the array
Set our rod data arrays to the raw .data() from the vector.
Referenced by ffea_test::euler_beam(), World::rod_from_block(), and ffea_test::twist_bend_coil().
Rod rod::Rod::load_header | ( | std::string | filename | ) |
IO -— Load the header info from a .rodtraj file (that's everything before the —END HEADER— line). Not all the info is read, some of it is for clarity. This populates some rod variables:
This string denotes where the header info ends
Check that we can load our input file
Iterate through file up to rod connections marker.
Use this to prevent rods with bad header info from being initialized
Check that format is valid FFEA_rod
Extract data from lines and deposit it into object
Read in the contents
Set this variable so other methods know we've read the header
Warn the user if there is a file version mismatch
Now that we know the rod length, we can allocate the memory
poiseuille
Referenced by ffea_test::euler_beam(), World::rod_from_block(), and ffea_test::twist_bend_coil().
Rod rod::Rod::pin_node | ( | bool | pin_state, |
int | node_index | ||
) |
Rod rod::Rod::rotate_rod | ( | float | euler_angles[3] | ) |
Rotates the rod by the euler angles alpha, beta and gamma (or x, y and z if you prefer. This will update all the node positions AND the material frames will rotate as well. The rotations happen relative to each centroid, so if current_r and equil_r have different centroids, they will be rotated about different points.
Put rod centroid on 0,0,0
Construct rotation matrix from euler angles
Apply rotation matrix
do not try to improve this
Move centroids back
Referenced by World::rod_from_block().
Rod rod::Rod::scale_rod | ( | float | scale | ) |
Scale the rod by a float. No return values, it just updates the arrays current_r and equil_r. It doesn't modify m, that'll be normalized away anyway.
Referenced by World::rod_from_block().
Rod rod::Rod::set_units | ( | ) |
The contents of the rod, by default, are specified in SI units. Although it's possible to do everything in SI, you'll get more precision out of FFEA units. This function will convert all the units into FFEA units. When the file is written, the units are converted back automagically. The units are specified in mesoDimensions.h.
Translate our units into the units specified in FFEA's mesoDimensions header file
And now the rod itself
Return a pointer to the object itself instead of void. Allows for method chaining!
Referenced by ffea_test::euler_beam(), World::rod_from_block(), and ffea_test::twist_bend_coil().
Rod rod::Rod::translate_rod | ( | float * | r, |
float | translation_vec[3] | ||
) |
Translate every node in the rod by a given translation vector, translation_vec. The parameter float* r is the pointer to any array of node positions, e.g. this->current_r or this->equil_r. No return values, it just updates those arrays
Referenced by World::init(), World::rod_from_block(), and rotate_rod().
Rod rod::Rod::write_array | ( | float * | array_ptr, |
int | array_len, | ||
float | unit_scale_factor | ||
) |
Write a single array to a file in the CSV format. Parameters:
Referenced by write_frame_to_file().
Rod rod::Rod::write_frame_to_file | ( | ) |
Write the current state of the rod to a file specified by the pointer file_ptr. This will convert from MesoDimensions to SI units, so if your values are already in SI units, they'll be wrong.
Referenced by ffea_test::euler_beam(), World::init(), World::print_trajectory_and_measurement_files(), and ffea_test::twist_bend_coil().
Rod rod::Rod::write_mat_params_array | ( | float * | array_ptr, |
int | array_len, | ||
float | stretch_scale_factor, | ||
float | twist_scale_factor, | ||
float | length_scale_factor | ||
) |
This function is almost identical to the one above, but it appllies different scale factors for objects in the array,
Referenced by write_frame_to_file().
float* rod::Rod::applied_forces |
Contents of the bending modulus matrix for each node, as a 1-d array. Given as [a_1_1, a_1_2, a_2,1, a_2_2, a_1_1...].
Referenced by add_force(), do_timestep(), and load_header().
float* rod::Rod::B_matrix |
Stretch, twist, radius, stretch, twist, radius...
Referenced by ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_node_energy(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float rod::Rod::bending_response_factor |
If this is true, the rod will skip writing a frame of the trajectory (this is normally done so that the trajectory starts with correct box positioning) Unit conversion factors - the input files are in SI, but internally it uses FFEA's units as determined in dimensions.h
Referenced by set_units(), and write_frame_to_file().
bool rod::Rod::computed_rest_energy = false |
If version number unknown, assume latest
float* rod::Rod::current_m |
Current configuration of the rod nodes.
Referenced by ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_node_energy(), load_contents(), load_header(), rod::Rod_blob_interface::position_rod_ends(), rod::Rod_blob_interface::position_rod_from_blob(), rotate_rod(), set_units(), ffea_test::twist_bend_coil(), and write_frame_to_file().
float* rod::Rod::current_r |
Equilibrium configuration of the material frame.
Referenced by ffea_test::connection_orientation_test(), ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_attachment_node(), rod::Rod_blob_interface::get_node_energy(), get_p(), load_contents(), load_header(), rod::Rod_blob_interface::position_blob_from_rod(), rod::Rod_blob_interface::position_rod_ends(), rod::Rod_blob_interface::position_rod_from_blob(), World::rod_from_block(), rotate_rod(), scale_rod(), set_units(), and write_frame_to_file().
float* rod::Rod::equil_m |
Equilibrium configuration of the rod nodes.
Referenced by ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_attachment_material_axis(), rod::Rod_blob_interface::get_node_energy(), load_contents(), load_header(), rod::Rod_blob_interface::position_rod_from_blob(), rotate_rod(), set_units(), and write_frame_to_file().
float* rod::Rod::equil_r |
these will have to be changed when I end up implementing per-element radius, to be computed on-the-fly instead most likely Each set of rod data is stored in a single, c-style array that goes {x,y,z,x,y,z...}
Referenced by ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_attachment_material_axis(), rod::Rod_blob_interface::get_node_energy(), get_p(), load_contents(), load_header(), rod::Rod_blob_interface::position_rod_from_blob(), World::rod_from_block(), rotate_rod(), scale_rod(), set_units(), and write_frame_to_file().
FILE* rod::Rod::file_ptr |
Referenced by change_filename(), load_header(), write_array(), write_frame_to_file(), and write_mat_params_array().
int rod::Rod::frame_no = 0 |
Referenced by do_timestep(), and write_frame_to_file().
bool rod::Rod::interface_at_end = false |
if this is true, the positioning of the start node is being handled by a rod-blob interface, so its energies will be ignored.
Referenced by rod::Rod_blob_interface::Rod_blob_interface().
bool rod::Rod::interface_at_start = false |
This array is the length of the number of nodes in the rod, and it contains a boolean stating whether that node is pinned (true) or not (false).
Referenced by rod::Rod_blob_interface::Rod_blob_interface().
float rod::Rod::kT = 0 |
Referenced by do_timestep(), ffea_test::euler_beam(), load_header(), World::read_and_build_system(), and ffea_test::twist_bend_coil().
int rod::Rod::length |
Rod metadata
Referenced by ffea_test::connection_propagation(), do_timestep(), rod::Rod_blob_interface::get_attachment_material_axis(), get_centroid(), get_min_max(), load_contents(), load_header(), rod::Rod_blob_interface::position_blob_from_rod(), rod::Rod_blob_interface::position_rod_ends(), rod::Rod_blob_interface::position_rod_from_blob(), rotate_rod(), scale_rod(), set_units(), translate_rod(), and write_frame_to_file().
int rod::Rod::line_start = 0 |
Each rod will be created with a unique ID
Referenced by load_contents(), and load_header().
float* rod::Rod::material_params |
int rod::Rod::num_elements |
The length of an array in the rod (3x the number of elements - x, y and z)
Referenced by ffea_test::connection_propagation(), do_timestep(), ffea_test::euler_beam(), rod::Rod_blob_interface::get_attachment_node(), get_centroid(), rod::Rod_blob_interface::get_node_energy(), World::get_system_centroid(), load_header(), rod::Rod_blob_interface::position_blob_from_rod(), rod::Rod_blob_interface::position_rod_from_blob(), and ffea_test::twist_bend_coil().
int rod::Rod::num_rods |
The number of elements in the rod
Referenced by load_header().
float rod::Rod::perturbation_amount = 0.01 |
Boltzmann's constant x temperature.
Referenced by ffea_test::connection_propagation(), rod::Rod_blob_interface::do_connection_timestep(), do_timestep(), and load_header().
float* rod::Rod::perturbed_x_energy_negative |
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::perturbed_x_energy_positive |
Current configuration of the material frame.
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::perturbed_y_energy_negative |
Stretch, bend, twist, stretch, bend, twist...
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::perturbed_y_energy_positive |
Energies associated with the perturbations we do in order to get dE. Given as [stretch, bend, twist, stretch, bend, twist...]
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::perturbed_z_energy_negative |
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::perturbed_z_energy_positive |
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
bool* rod::Rod::pinned_nodes |
Another [x,y,z,x,y,z...] array, this one containing the force vectors acting on each node in the rod.
Referenced by ffea_test::connection_propagation(), do_timestep(), ffea_test::euler_beam(), load_header(), and ffea_test::twist_bend_coil().
bool rod::Rod::restarting = false |
if this is true, the positioning of the end node is being handled by a rod-blob interface, so its energies will be ignored.
Referenced by World::print_trajectory_and_measurement_files(), and World::rod_from_block().
std::string rod::Rod::rod_filename |
Referenced by change_filename(), and load_header().
int rod::Rod::rod_no |
When the system is set up in ffeatools, this will be set
Referenced by Rod(), World::rod_from_block(), and write_frame_to_file().
double rod::Rod::rod_version = 999.999 |
Keeps track of whether the header file has been read
Referenced by load_contents(), and load_header().
float rod::Rod::rotational_friction |
Referenced by do_timestep().
float rod::Rod::spring_constant_factor |
Referenced by set_units(), and write_frame_to_file().
int rod::Rod::step_no = 0 |
Referenced by do_timestep().
float rod::Rod::timestep = 0.002 |
float rod::Rod::translational_friction |
Amount by which nodes are perturbed during numerical differentiation. May want to override with a local value depending on the scale of the simulation.
Referenced by do_timestep().
float rod::Rod::twist_constant_factor |
Referenced by set_units(), and write_frame_to_file().
float* rod::Rod::twisted_energy_negative |
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float* rod::Rod::twisted_energy_positive |
Referenced by do_timestep(), load_contents(), load_header(), set_units(), and write_frame_to_file().
float rod::Rod::viscosity = 1 |
Global simulation parameters - eventually we may read this stuff in from the .ffea file
Referenced by do_timestep(), load_header(), World::read_and_build_system(), and ffea_test::twist_bend_coil().
float rod::Rod::viscosity_constant_factor |
Referenced by load_header().