<commit_before>import numpy as np
import matplotlib.pyplot as pp
import copy
from scipy import interpolate
from helpers import *

EL_RIM = 1
EL_SPOKE = 2
N_RIM = 1
N_HUB = 2
N_REF = 3

class FEMSolution:
    el_rim = 1
    el_spoke = 2

    def get_polar_displacements(self, node_id):
        'Convert nodal displacements to polar form'

        # Allow array input for node_id and/or dof
        if not hasattr(node_id, '__iter__'):
            node_id = [node_id]

        u_rad = np.array([])
        u_tan = np.array([])

        for n in node_id:

            x = np.array([self.x_nodes[n], self.y_nodes[n], self.z_nodes[n]])
            n_tan = np.cross(np.array([0,0,1]),x)

            u_rim = self.nodal_disp[6*n + np.arange(3)]

            u_rad = np.append(u_rad, u_rim.dot(x) / np.sqrt(x.dot(x)))
            u_tan = np.append(u_tan, u_rim.dot(n_tan) / np.sqrt(n_tan.dot(n_tan)))

        u_rad = np.array(u_rad)
        u_tan = np.array(u_tan)

        return u_rad, u_tan

    def get_deformed_coords(self, node_id, scale_rad, scale_tan):
        'Get coordinates of nodes in scaled deformed configuration.'

        # Allow array input for node_id and/or dof
        if not hasattr(node_id, '__iter__'):
            node_id = [node_id]

        x_def = np.array([])
        y_def = np.array([])
        z_def = np.array([]) # TODO

        u_rad, u_tan = self.get_polar_displacements(node_id)

        for n in range(len(node_id)):
            n_id = node_id[n]

            x = np.array([self.x_nodes[n_id], self.y_nodes[n_id], self.z_nodes[n_id]])
            n_tan = np.cross(np.array([0, 0, 1]), x)

            u = scale_rad*u_rad * x/np.sqrt(x.dot(x)) + scale_tan*u_tan * n_tan

            x_def = np.append(x_def, x[0] + u[0])
            y_def = np.append(y_def, x[1] + u[1])

        return x_def, y_def

    def plot_deformed_wheel(self, scale_rad=0.1, scale_tan=0.0):

        rim_nodes = np.where(self.type_nodes == N_RIM)[0]

        print len(rim_nodes)

        u_rad, u_tan = self.get_polar_displacements(rim_nodes)
<commit_msg>corrected rim node numbering<commit_after>import numpy as np
import matplotlib.pyplot as pp
import copy
from scipy import interpolate
from helpers import *

EL_RIM = 1
EL_SPOKE = 2
N_RIM = 1
N_HUB = 2
N_REF = 3

class FEMSolution:
    el_rim = 1
    el_spoke = 2

    def get_polar_displacements(self, node_id):
        'Convert nodal displacements to polar form'

        # Allow array input for node_id and/or dof
        if not hasattr(node_id, '__iter__'):
            node_id = [node_id]

        u_rad = np.array([])
        u_tan = np.array([])

        for n in node_id:

            x = np.array([self.x_nodes[n], self.y_nodes[n], self.z_nodes[n]])
            n_tan = np.cross(np.array([0,0,1]),x)

            u_rim = self.nodal_disp[6*n + np.arange(3)]

            u_rad = np.append(u_rad, u_rim.dot(x) / np.sqrt(x.dot(x)))
            u_tan = np.append(u_tan, u_rim.dot(n_tan) / np.sqrt(n_tan.dot(n_tan)))

        u_rad = np.array(u_rad)
        u_tan = np.array(u_tan)

        return u_rad, u_tan

    def get_deformed_coords(self, node_id, scale_rad, scale_tan):
        'Get coordinates of nodes in scaled deformed configuration.'

        # Allow array input for node_id and/or dof
        if not hasattr(node_id, '__iter__'):
            node_id = [node_id]

        x_def = np.array([])
        y_def = np.array([])
        z_def = np.array([]) # TODO

        u_rad, u_tan = self.get_polar_displacements(node_id)

        for n in range(len(node_id)):
            n_id = node_id[n]

            x = np.array([self.x_nodes[n_id], self.y_nodes[n_id], self.z_nodes[n_id]])
            n_tan = np.cross(np.array([0, 0, 1]), x)

            u = scale_rad*u_rad * x/np.sqrt(x.dot(x)) + scale_tan*u_tan * n_tan

            x_def = np.append(x_def, x[0] + u[0])
            y_def = np.append(y_def, x[1] + u[1])

        return x_def, y_def

    def plot_deformed_wheel(self, scale_rad=0.1, scale_tan=0.0):

        rim_nodes = np.where(self.type_nodes == N_RIM)[0]

        u_rad, u_tan = self.get_polar_displacements(rim_nodes)

{'fraction_non_alphanumeric': 0.12612612612612611, 'fraction_numerical': 0.01168736303871439, 'mean_word_length': 2.3155770782889427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622592', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1571, 'n_words': 333}