<commit_before>from __future__ import print_function

from SofaPython import SofaNumpy 
from Compliant import easy, tool

import math
import numpy as np

from Compliant import mapping, easy

try:
    from SofaTest import gtest
except:
    class gtest(object):
        @staticmethod
        def assert_true(x, msg):
            assert x, msg

        @staticmethod
        def finish():
            import sys
            sys.exit(0)

def particle(node, position):
    '''construct a particle under given node'''
    dofs = node.createObject('MechanicalObject', position = tool.cat(position),
                             showObject = True, drawMode = 1, name = 'dofs', size = 1)
    mass = node.createObject('UniformMass', name = 'mass', totalMass = 1)
    return dofs



class Solver(easy.Solver):

    def factor(self, sys):
        gtest.assert_true( (sys.H == np.identity(6)).all(), "H error" )
        gtest.assert_true( (sys.J == np.array([-1, 0, 0, 1, 0, 0])).all(), "J error" )
        gtest.assert_true( (sys.C == np.identity(1)).all(), "C error" )
        gtest.assert_true( (sys.P == np.diag([0, 0, 0, 1, 1, 1])).all(), "P error" )
        
    def solve(self, res, sys, rhs):
        # wtf rhs is already projected?
        gtest.assert_true( (rhs == np.array([0, 0, 0,
                                             0, 1, 0,
                                             0])).all(), "dynamics rhs error" )
        gtest.finish()
        
    def correct(self, res, sys, rhs, damping):
        gtest.assert_true( (rhs == np.zeros(7)).all(), "correction rhs error")

        
        
def createScene(node):
    node.createObject('RequiredPlugin', pluginName = 'Compliant')
    
    node.createObject('CompliantAttachButtonSetting')
    node.createObject('CompliantImplicitSolver')

    solver = Solver(node)
    
    n1 = node.createChild('p1')

    d1 = particle(n1, [-0.5, 0, 0])
    n1.createObject("FixedConstraint", fixAll = True)
        
    n2 = node.createChild('p2')
    d2 = particle(n2, [0.5, 0, 0])
    
    n3 = node.createChild('child')
    d3 = n3.createObject('MechanicalObject', template = 'Vec1', name = 'dofs', size = 1)<commit_msg>[Compliant] cleaned up python test<commit_after>from __future__ import print_function

from SofaPython import SofaNumpy 
from Compliant import easy, tool

import math
import numpy as np

from Compliant import mapping, easy
from SofaTest import gtest



def particle(node, position):
    '''construct a particle under given node'''
    dofs = node.createObject('MechanicalObject', position = tool.cat(position),
                             showObject = True, drawMode = 1, name = 'dofs', size = 1)
    mass = node.createObject('UniformMass', name = 'mass', totalMass = 1)
    return dofs



class Solver(easy.Solver):

    def factor(self, sys):
        gtest.assert_true( (sys.H == np.identity(6)).all(), "H error" )
        gtest.assert_true( (sys.J == np.array([-1, 0, 0, 1, 0, 0])).all(), "J error" )
        gtest.assert_true( (sys.C == np.identity(1)).all(), "C error" )
        gtest.assert_true( (sys.P == np.diag([0, 0, 0, 1, 1, 1])).all(), "P error" )
        
    def solve(self, res, sys, rhs):
        # wtf rhs is already projected?
        gtest.assert_true( (rhs == np.array([0, 0, 0,
                                             0, 1, 0,
                                             0])).all(), "dynamics rhs error" )
        gtest.finish()
        
    def correct(self, res, sys, rhs, damping):
        gtest.assert_true( (rhs == np.zeros(7)).all(), "correction rhs error")

        
        
def createScene(node):
    node.createObject('CompliantImplicitSolver')

    solver = Solver(node)
    
    n1 = node.createChild('p1')

    d1 = particle(n1, [-0.5, 0, 0])
    n1.createObject("FixedConstraint", fixAll = True)
        
    n2 = node.createChild('p2')
    d2 = particle(n2, [0.5, 0, 0])
    
    n3 = node.createChild('child')
    d3 = n3.createObject('MechanicalObject', template = 'Vec1', name = 'dofs', size = 1)
{'fraction_non_alphanumeric': 0.14235764235764237, 'fraction_numerical': 0.023726273726273728, 'mean_word_length': 2.323651452282158, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2406994', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1272, 'n_words': 342}