Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying non-constant torques and forces #2

Closed
pcsong33 opened this issue Jul 2, 2020 · 2 comments
Closed

Applying non-constant torques and forces #2

pcsong33 opened this issue Jul 2, 2020 · 2 comments

Comments

@pcsong33
Copy link

pcsong33 commented Jul 2, 2020

Hello,
Is there a way to apply non-constant forces / torques to a rod? For example, I am trying to apply torque to a rod for a certain duration of time, rather than to have the torque act on the rod for the whole duration of the simulation.

@armantekinalp
Copy link
Contributor

armantekinalp commented Jul 2, 2020

Hello,

Yes you can apply torque in a certain time interval. For that I suggest you to write your own forcing class. Below I am also adding an example code for you.

class MyNewTorqueClass(NoForces):
    def __init__(self, torque_mag: float, torque_direction, time_start: float, time_end: float):

        self.torque_mag = torque_mag 
        self.torque_direction = torque_direction # defined in global frame, shape(3,1)
        self.time_start = time_start
        self.time_end = time_end

   def apply_forces(self, system, time: np.float = 0.0):
        return

   def apply_torques(self, system, time: np.float = 0.0):
       
        if time > self.time_start and time < self.time_end:
               torque_vector = self.torque_mag * self.torque_direction 
        else:
               torque_vector = np.array([0., 0., 0.]).reshape(3,1)

        system.external_torques += _batch_matvec(
            system.director_collection, torque_vector
        )

There are couple of example forcing classes in elastica/external_forces.py, check them out as well. Let me know if you have more questions.

@pcsong33
Copy link
Author

pcsong33 commented Jul 6, 2020

Thank you for your help!

@pcsong33 pcsong33 closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants