<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from scipy.linalg import lu_factor, lu_solve
#import scipy as sp
""" This module contains the different solvers used by the program.
"""

class Solver(object):

    """Parent class for the solvers used"""

    def __init__(self, model, **kwargs):
        """Initialize solver

        :model: TODO
        :**kwargs: Additional options:

            - :output: list of keywords specifying the different results that need to be
              computed after the solution is found.
              Accepted values are:
                - 'reactions'
                - 'internal forces'
                - 'stresses'
                - 'strains'
                - 'energy'


        """
        self._model = model
        # The variable 'output' stores the different results that need
        # to be computed after the solution is found.
        # FIXME: implement this
        deffault_output = ['displacements', 'forces']
        self._output_request = kwargs.get('output', None)

class StaticSolver(Solver):

    """Linear Static solver used to solve the most typical problems"""

    def __init__(self, model, **kwargs):
        """Initialize the solver instance

        Optional parameters:
        nlg: boolean, consider geometrical nonlinearities (Default False)

        """
        Solver.__init__(self, model, **kwargs)

    def solve(self):
        """Solves the problem
        :returns: numpy array

        """
        # Assemble the stiffness matrix of the system
        K = self._model._assemble_global_K()
        # Assemble the vector of applied loads
        P = self._model._generate_loading_vector()
        # Apply Dirichlet boundary conditions
        # Get the dof corresponding to Dirichlet border conditions
        dirich_ind = self._model._dof_dirichlet
        V = self._model._generate_displacement_vector()
        # Calculate forces generated by the BC
        P_dirich = np.dot(K[dirich_ind,:], V)
        P_new = P[:]
        P_new[dirich_ind] = P[dirich_ind] - P_dirich
        # Matrix to multiply the global stiffness matrix and put zeros on the
        # rows and columns corresponding to the Dirichlet BC.
        T = np.eye(len(K))
        # Put a zero on the respective Dirichlet DOF
        for index in dirich_ind:
            T[index,index] = 0.

        # Generate the new augumented stiffness matrix
        K_new = np.dot(T, K)

        for index in dirich_ind:
            K_new[index,index] = 1.
            P_new[index] = V[index]

        # LU decomposition
        LU, piv = lu_factor(K_new)
        # Solve the augumented system
        V_res = lu_solve((LU, piv), P_new, trans=0)

        # Obtain reactions at the DOF constrained with Dirichlet BCs
        P_react = np.dot(K, V_res)[dirich_ind]

        # Copy the data of the model<commit_msg>Small change in the inclusion of Dirichlet BC<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from scipy.linalg import lu_factor, lu_solve
#import scipy as sp
""" This module contains the different solvers used by the program.
"""

class Solver(object):

    """Parent class for the solvers used"""

    def __init__(self, model, **kwargs):
        """Initialize solver

        :model: TODO
        :**kwargs: Additional options:

            - :output: list of keywords specifying the different results that need to be
              computed after the solution is found.
              Accepted values are:
                - 'reactions'
                - 'internal forces'
                - 'stresses'
                - 'strains'
                - 'energy'


        """
        self._model = model
        # The variable 'output' stores the different results that need
        # to be computed after the solution is found.
        # FIXME: implement this
        deffault_output = ['displacements', 'forces']
        self._output_request = kwargs.get('output', None)

class StaticSolver(Solver):

    """Linear Static solver used to solve the most typical problems"""

    def __init__(self, model, **kwargs):
        """Initialize the solver instance

        Optional parameters:
        nlg: boolean, consider geometrical nonlinearities (Default False)

        """
        Solver.__init__(self, model, **kwargs)

    def solve(self):
        """Solves the problem
        :returns: numpy array

        """
        # Assemble the stiffness matrix of the system
        K = self._model._assemble_global_K()
        # Assemble the vector of applied loads
        P = self._model._generate_loading_vector()
        # Apply Dirichlet boundary conditions
        # Get the dof corresponding to Dirichlet border conditions
        dirich_ind = self._model._dof_dirichlet
        V = self._model._generate_displacement_vector()
        # Calculate forces generated by the BC
        P_dirich = np.dot(K[dirich_ind,:], V)
        P_new = P[:]
        P_new[dirich_ind] = P[dirich_ind] - P_dirich

        # Matrix to multiply the global stiffness matrix and put zeros on the
        # rows and columns corresponding to the Dirichlet BC.
        #T = np.eye(len(K))
        # Put a zero on the respective Dirichlet DOF
        #for index in dirich_ind:
        #    T[index,index] = 0.

        # Generate the new augumented stiffness matrix
        #K_new = np.dot(T, K)
        K_new = np.copy(K)
        K_new[dirich_ind,:] = 0.
        K_new[:,dirich_ind] = 0.

        for index in dirich_ind:
            K_new[index,index] = 1.
            P_new[index] = V[index]

        # LU decomposition
        LU, piv = lu_factor(K_new)
        # Solve the augumented system
        V_res = lu_solve((LU, piv), P_new, trans=0)

        # Obtain reactions at the DOF constrained with Dirichlet BCs
        P_react = np.dot(K, V_res)[dirich_ind]

        # Copy the data of the model
{'fraction_non_alphanumeric': 0.08673469387755102, 'fraction_numerical': 0.0017006802721088435, 'mean_word_length': 2.139882541377469, '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': '6369667', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1592, 'n_words': 558}