def test_fc3dnsgs(): N.setNumericsVerbose(2) FCP = N.FrictionContactProblem(3, M, q, mu) SO = N.SolverOptions(N.SICONOS_FRICTION_3D_NSGS) r = N.frictionContact3D_nsgs(FCP, reactions, velocities, SO) assert SO.dparam[1] < 1e-10 assert not r
def test_fc3dlocalac(): N.setNumericsVerbose(2) FCP = N.FrictionContactProblem(3, M, q, mu) SO = N.SolverOptions(N.SICONOS_FRICTION_3D_LOCALAC) r = N.frictionContact3D_localAlartCurnier(FCP, reactions, velocities, SO) assert SO.dparam[1] < 1e-10 assert not r
def test_fc3dfischer(): N.setNumericsVerbose(2) FCP = N.FrictionContactProblem(3,M,q,mu) SO=N.SolverOptions(N.SICONOS_FRICTION_3D_LOCALFB) r = N.frictionContact3D_localFischerBurmeister(FCP, reactions, velocities, SO) assert SO.dparam[1] < 1e-10 assert not r
def test_mlcp_enum_large_fromfile(): SO=N.SolverOptions(mlcp,N.SICONOS_MLCP_ENUM) N.mlcp_driver_init(mlcp, SO) info = N.mlcp_enum(mlcp, z, w, SO) N.mlcp_driver_reset(mlcp, SO) print("z = ", z) print("w = ", w) assert (linalg.norm(z-zsol) <= ztol) assert not info
def test_mcp_FB(): mcp=N.MCP(1,1,mcp_function,mcp_Nablafunction) z = array([0., 0.]) w = array([0., 0.]) SO=N.SolverOptions(mcp,N.SICONOS_MCP_FB) N.mcp_driver_init(mcp, SO) info = N.mcp_FischerBurmeister(mcp, z, w, SO) N.mcp_driver_reset(mcp, SO) print("z = ", z) print("w = ", w) assert (linalg.norm(z-zsol) <= ztol) assert not info
def test_lcp_pgs(): SO=N.SolverOptions(lcp,N.SICONOS_LCP_PGS) info = N.lcp_pgs(lcp,z,w,SO) print('pgs iter =', SO.iparam[1]) print('pgs error=', SO.dparam[1]) assert (linalg.norm(z-zsol) <= ztol) assert not info
def test_mcp_newton_minFBLSA(): mcp = SN.MixedComplementarityProblem2(0, 2, mcp_function, mcp_Nablafunction) z = array([0., 0.]) w = array([0., 0.]) SO = SN.SolverOptions(mcp, SN.SICONOS_MCP_NEWTON_MINFBLSA) info = SN.mcp_newton_minFBLSA(mcp, z, w, SO) print("z = ", z) print("w = ", w) assert (linalg.norm(z-zsol) <= ztol) assert not info
SO.iparam[0] = 100 SO.iparam[3] = 2 SO.iparam[4] = 10 lambdaPM = np.empty((N, 4)) signs = np.empty((N, 2)) sol = np.empty((N, 2)) sol[0, :] = xk z[4:6] = xk z[6] = hh k = 0 while t <= T: k += 1 info = SN.mcp_newton_minFBLSA(mcp, z, w, SO) #info = SN.mcp_newton_FBLSA(mcp, z, w, SO) # print('iter {:} ; solver iter = {:} ; prec = {:}'.format(k, SO.iparam[1], SO.dparam[1])) if info > 0: mcp_function(0, 4, z, w) sol[k, 0] = w[0] - z[1] sol[k, 1] = w[2] - z[3] if sol[k, 0] < -1e-7 and np.abs(z[1]) < 1e-10: z[1] = -sol[k, 0] z[0] = 1.0 if z[4] < -1e-7 and np.abs(z[3]) < 1e-10: z[3] = -sol[k, 1] z[2] = 1.0 if z[1] < -1e-7: z[1] = 0.0 z[0] = 0.0
SO.dparam[0] = 1e-12 SO.iparam[0] = 50 SO.iparam[2] = 1 SO.iparam[3] = 0 SO.iparam[4] = 10 signs = np.empty((N, 2)) sol = np.empty((N, 2)) sol[0, :] = xk k = 0 #SN.setNumericsVerbose(3) while t <= T: k += 1 info = SN.variationalInequality_box_newton_QiLSA(vi, lambda_, xkp1, SO) #print('iter {:} ; solver iter = {:} ; prec = {:}'.format(k, SO.iparam[1], SO.dparam[1])) #info = SN.mcp_newton_FBLSA(mcp, z, w, SO) if info > 0: print(lambda_) # vi_function(2, signs[k-1, :], xkp1) lambda_[0] = -np.sign(xkp1[0]) lambda_[1] = -np.sign(xkp1[1]) if np.abs(xk[0]) < 1e-10: lambda_[0] = 0.01 if np.abs(xk[1]) < 1e-10: lambda_[1] = 0.01 print('ok lambda') print(lambda_) info = SN.variationalInequality_box_newton_QiLSA(vi, lambda_, xkp1, SO) # info = SN.mcp_newton_minFBLSA(mcp, z, w, SO)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Siconos; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # Contact: Vincent ACARY, [email protected] import Siconos.Kernel as SK import Siconos.Numerics as SN import numpy as np from scipy.linalg import expm from functions import compute_dt_matrices kmax = 10 if SN.compiled_in_debug_mode() else 100 def test_TI(): h = 1.0e-4 k = 0 err = False while k < kmax: n = np.random.randint(2, kmax) m = np.random.randint(1, n) A = np.random.random((n, n)) B = np.random.random((n, m)) errInv = 1 try: Ainv = np.linalg.inv(A) Aexp = expm(A*h) Psi = Ainv.dot((Aexp-np.eye(n)).dot(B))
[ 0. ], [ 0. ], [ 0. ], [ 0. ]]) mlcp=N.MLCP(3,M,q) def test_mlcp_enum_large(): SO=N.SolverOptions(mlcp,N.SICONOS_MLCP_ENUM) N.mlcp_driver_init(mlcp, SO) info = N.mlcp_enum(mlcp, z, w, SO) N.mlcp_driver_reset(mlcp, SO) print("z = ", z) print("w = ", w) assert (linalg.norm(z-zsol) <= ztol) assert not info mlcp =0 mlcp=N.MLCP() N.mixedLinearComplementarity_newFromFilename(mlcp,"./data/diodeBridge_mlcp.dat") N.mixedLinearComplementarity_display(mlcp) def test_mlcp_enum_large_fromfile(): SO=N.SolverOptions(mlcp,N.SICONOS_MLCP_ENUM) N.mlcp_driver_init(mlcp, SO) info = N.mlcp_enum(mlcp, z, w, SO) N.mlcp_driver_reset(mlcp, SO) print("z = ", z) print("w = ", w) assert (linalg.norm(z-zsol) <= ztol) assert not info
def test_lcp_enum(): SO=N.SolverOptions(lcp,N.SICONOS_LCP_ENUM) info = N.lcp_enum(lcp, z, w, SO) assert (linalg.norm(z-zsol) <= ztol) assert not info
def test_lcp_lexicolemke(): SO=N.SolverOptions(lcp, N.SICONOS_LCP_LEMKE) info = N.lcp_lexicolemke(lcp, z, w, SO) print('lexicolemke iter =', SO.iparam[1]) assert (linalg.norm(z-zsol) <= ztol) assert not info